diff --git a/cmd/main.go b/cmd/main.go index 0b2c2de1..cddb014e 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -9,11 +9,11 @@ import ( "github.com/johnfercher/maroto/pkg/v2/code/barcode" "github.com/johnfercher/maroto/pkg/v2/code/matrixcode" "github.com/johnfercher/maroto/pkg/v2/code/qrcode" - "github.com/johnfercher/maroto/pkg/v2/col" "github.com/johnfercher/maroto/pkg/v2/domain" + "github.com/johnfercher/maroto/pkg/v2/grid/col" + "github.com/johnfercher/maroto/pkg/v2/grid/row" "github.com/johnfercher/maroto/pkg/v2/image" "github.com/johnfercher/maroto/pkg/v2/providers" - "github.com/johnfercher/maroto/pkg/v2/row" "github.com/johnfercher/maroto/pkg/v2/signature" "github.com/johnfercher/maroto/pkg/v2/size" "github.com/johnfercher/maroto/pkg/v2/text" diff --git a/internal/examples/barcodegrid/main.go b/internal/examples/barcodegrid/v1/main.go similarity index 100% rename from internal/examples/barcodegrid/main.go rename to internal/examples/barcodegrid/v1/main.go diff --git a/internal/examples/barcodegrid/v2/main.go b/internal/examples/barcodegrid/v2/main.go new file mode 100644 index 00000000..77a18327 --- /dev/null +++ b/internal/examples/barcodegrid/v2/main.go @@ -0,0 +1,87 @@ +package main + +import ( + "fmt" + v2 "github.com/johnfercher/maroto/pkg/v2" + "github.com/johnfercher/maroto/pkg/v2/code/barcode" + "github.com/johnfercher/maroto/pkg/v2/grid/col" + "github.com/johnfercher/maroto/pkg/v2/grid/row" + "github.com/johnfercher/maroto/pkg/v2/providers" + "github.com/johnfercher/maroto/pkg/v2/size" + "os" + "time" + + "github.com/johnfercher/maroto/pkg/props" +) + +func main() { + begin := time.Now() + provider := providers.NewGofpdf(size.A4) + maroto := v2.NewMaroto(provider, "internal/examples/pdfs/barcodegridv2.pdf") + m := v2.NewMarotoMetrified(maroto) + + c1 := col.New(2).Add(barcode.New("https://github.com/johnfercher/maroto", props.Barcode{ + Percent: 50, + })) + c2 := col.New(4).Add(barcode.New("https://github.com/johnfercher/maroto", props.Barcode{ + Percent: 75, + })) + c3 := col.New(6).Add(barcode.New("https://github.com/johnfercher/maroto", props.Barcode{ + Percent: 100, + })) + + r1 := row.New(40).Add(c1, c2, c3) + + c4 := col.New(2).Add(barcode.New("https://github.com/johnfercher/maroto", props.Barcode{ + Center: true, + Percent: 50, + })) + c5 := col.New(4).Add(barcode.New("https://github.com/johnfercher/maroto", props.Barcode{ + Center: true, + Percent: 75, + })) + c6 := col.New(6).Add(barcode.New("https://github.com/johnfercher/maroto", props.Barcode{ + Center: true, + Percent: 100, + })) + + r2 := row.New(40).Add(c4, c5, c6) + + c7 := col.New(6).Add(barcode.New("https://github.com/johnfercher/maroto", props.Barcode{ + Percent: 50, + })) + c8 := col.New(4).Add(barcode.New("https://github.com/johnfercher/maroto", props.Barcode{ + Percent: 75, + })) + c9 := col.New(2).Add(barcode.New("https://github.com/johnfercher/maroto", props.Barcode{ + Percent: 100, + })) + + r3 := row.New(40).Add(c7, c8, c9) + + c10 := col.New(6).Add(barcode.New("https://github.com/johnfercher/maroto", props.Barcode{ + Center: true, + Percent: 50, + })) + c11 := col.New(4).Add(barcode.New("https://github.com/johnfercher/maroto", props.Barcode{ + Center: true, + Percent: 75, + })) + c12 := col.New(2).Add(barcode.New("https://github.com/johnfercher/maroto", props.Barcode{ + Center: true, + Percent: 100, + })) + + r4 := row.New(40).Add(c10, c11, c12) + + m.Add(r1, r2, r3, r4) + + err := m.Generate() + if err != nil { + fmt.Println("Could not save PDF:", err) + os.Exit(1) + } + + end := time.Now() + fmt.Println(end.Sub(begin)) +} diff --git a/internal/examples/imagegrid/v2/main.go b/internal/examples/imagegrid/v2/main.go index ae94feca..1249a157 100644 --- a/internal/examples/imagegrid/v2/main.go +++ b/internal/examples/imagegrid/v2/main.go @@ -4,10 +4,10 @@ import ( "fmt" "github.com/johnfercher/maroto/pkg/props" v2 "github.com/johnfercher/maroto/pkg/v2" - "github.com/johnfercher/maroto/pkg/v2/col" + "github.com/johnfercher/maroto/pkg/v2/grid/col" + "github.com/johnfercher/maroto/pkg/v2/grid/row" "github.com/johnfercher/maroto/pkg/v2/image" "github.com/johnfercher/maroto/pkg/v2/providers" - "github.com/johnfercher/maroto/pkg/v2/row" "github.com/johnfercher/maroto/pkg/v2/size" "os" ) @@ -21,12 +21,10 @@ func main() { Center: true, Percent: 80, })) - c2 := col.New(4).Add(image.NewFromFile("internal/assets/images/biplane.jpg", props.Rect{ Center: true, Percent: 80, })) - c3 := col.New(6).Add(image.NewFromFile("internal/assets/images/biplane.jpg", props.Rect{ Center: true, Percent: 80, @@ -40,13 +38,11 @@ func main() { Percent: 50, Left: 10, })) - c5 := col.New(4).Add(image.NewFromFile("internal/assets/images/biplane.jpg", props.Rect{ Center: false, Percent: 50, Top: 10, })) - c6 := col.New(6).Add(image.NewFromFile("internal/assets/images/biplane.jpg", props.Rect{ Center: false, Percent: 50, @@ -61,12 +57,10 @@ func main() { Center: true, Percent: 80, })) - c8 := col.New(4).Add(image.NewFromFile("internal/assets/images/biplane.jpg", props.Rect{ Center: true, Percent: 80, })) - r3 := row.New(40).Add(c7, c8) m.Add(r3) @@ -76,13 +70,11 @@ func main() { Top: 5, Left: 10, })) - c10 := col.New(4).Add(image.NewFromFile("internal/assets/images/frontpage.png", props.Rect{ Center: false, Percent: 80, Top: 5, })) - c11 := col.New(2).Add(image.NewFromFile("internal/assets/images/frontpage.png", props.Rect{ Center: false, Percent: 80, @@ -96,12 +88,10 @@ func main() { Center: true, Percent: 50, })) - c13 := col.New(4).Add(image.NewFromFile("internal/assets/images/frontpage.png", props.Rect{ Center: true, Percent: 50, })) - c14 := col.New(2).Add(image.NewFromFile("internal/assets/images/frontpage.png", props.Rect{ Center: true, Percent: 50, @@ -114,7 +104,6 @@ func main() { Center: true, Percent: 80, })) - c16 := col.New(6).Add(image.NewFromFile("internal/assets/images/frontpage.png", props.Rect{ Center: true, Percent: 80, diff --git a/internal/examples/pdfs/barcodegrid.pdf b/internal/examples/pdfs/barcodegrid.pdf index 375fff84..cf9fd2f5 100644 Binary files a/internal/examples/pdfs/barcodegrid.pdf and b/internal/examples/pdfs/barcodegrid.pdf differ diff --git a/internal/examples/pdfs/barcodegridv2.pdf b/internal/examples/pdfs/barcodegridv2.pdf new file mode 100644 index 00000000..f151056d Binary files /dev/null and b/internal/examples/pdfs/barcodegridv2.pdf differ diff --git a/internal/examples/pdfs/imagegrid.pdf b/internal/examples/pdfs/imagegrid.pdf index ffdd3202..41427ba0 100644 Binary files a/internal/examples/pdfs/imagegrid.pdf and b/internal/examples/pdfs/imagegrid.pdf differ diff --git a/internal/examples/pdfs/imagegridv2.pdf b/internal/examples/pdfs/imagegridv2.pdf index 77e5c3f6..0b327718 100644 Binary files a/internal/examples/pdfs/imagegridv2.pdf and b/internal/examples/pdfs/imagegridv2.pdf differ diff --git a/pkg/v2/code/barcode/barcode.go b/pkg/v2/code/barcode/barcode.go index b25888af..fab1e836 100644 --- a/pkg/v2/code/barcode/barcode.go +++ b/pkg/v2/code/barcode/barcode.go @@ -5,17 +5,14 @@ import ( "github.com/johnfercher/maroto/internal" "github.com/johnfercher/maroto/pkg/props" "github.com/johnfercher/maroto/pkg/v2/domain" - "github.com/johnfercher/maroto/pkg/v2/types" ) type barcode struct { - code string - _type types.DocumentType - components []domain.Node - prop props.Barcode + code string + prop props.Barcode } -func New(code string, barcodeProps ...props.Barcode) domain.Component { +func New(code string, barcodeProps ...props.Barcode) domain.Node { prop := props.Barcode{} if len(barcodeProps) > 0 { prop = barcodeProps[0] @@ -23,9 +20,8 @@ func New(code string, barcodeProps ...props.Barcode) domain.Component { prop.MakeValid() return &barcode{ - _type: types.Barcode, - code: code, - prop: prop, + code: code, + prop: prop, } } @@ -33,13 +29,9 @@ func (b *barcode) Render(provider domain.Provider, cell internal.Cell) { provider.AddBarCode(b.code, cell, b.prop) } -func (b *barcode) GetType() string { - return b._type.String() -} - func (b *barcode) GetStructure() *tree.Node[domain.Structure] { str := domain.Structure{ - Type: string(b._type), + Type: "barcode", Value: b.code, } diff --git a/pkg/v2/code/matrixcode/matrixcode.go b/pkg/v2/code/matrixcode/matrixcode.go index f65e421f..bc0a7416 100644 --- a/pkg/v2/code/matrixcode/matrixcode.go +++ b/pkg/v2/code/matrixcode/matrixcode.go @@ -5,17 +5,14 @@ import ( "github.com/johnfercher/maroto/internal" "github.com/johnfercher/maroto/pkg/props" "github.com/johnfercher/maroto/pkg/v2/domain" - "github.com/johnfercher/maroto/pkg/v2/types" ) type matrixCode struct { - code string - _type types.DocumentType - components []domain.Node - prop props.Rect + code string + prop props.Rect } -func New(code string, barcodeProps ...props.Rect) domain.Component { +func New(code string, barcodeProps ...props.Rect) domain.Node { prop := props.Rect{} if len(barcodeProps) > 0 { prop = barcodeProps[0] @@ -23,9 +20,8 @@ func New(code string, barcodeProps ...props.Rect) domain.Component { prop.MakeValid() return &matrixCode{ - _type: types.MatrixCode, - code: code, - prop: prop, + code: code, + prop: prop, } } @@ -33,13 +29,9 @@ func (m *matrixCode) Render(provider domain.Provider, cell internal.Cell) { provider.AddMatrixCode(m.code, cell, m.prop) } -func (m *matrixCode) GetType() string { - return m._type.String() -} - func (m *matrixCode) GetStructure() *tree.Node[domain.Structure] { str := domain.Structure{ - Type: string(m._type), + Type: "matrixcode", Value: m.code, } diff --git a/pkg/v2/code/qrcode/qrcode.go b/pkg/v2/code/qrcode/qrcode.go index 9371d843..fa1d2f98 100644 --- a/pkg/v2/code/qrcode/qrcode.go +++ b/pkg/v2/code/qrcode/qrcode.go @@ -5,17 +5,14 @@ import ( "github.com/johnfercher/maroto/internal" "github.com/johnfercher/maroto/pkg/props" "github.com/johnfercher/maroto/pkg/v2/domain" - "github.com/johnfercher/maroto/pkg/v2/types" ) type qrCode struct { - code string - _type types.DocumentType - components []domain.Node - prop props.Rect + code string + prop props.Rect } -func New(code string, barcodeProps ...props.Rect) domain.Component { +func New(code string, barcodeProps ...props.Rect) domain.Node { prop := props.Rect{} if len(barcodeProps) > 0 { prop = barcodeProps[0] @@ -23,9 +20,8 @@ func New(code string, barcodeProps ...props.Rect) domain.Component { prop.MakeValid() return &qrCode{ - _type: types.QrCode, - code: code, - prop: prop, + code: code, + prop: prop, } } @@ -33,13 +29,9 @@ func (q *qrCode) Render(provider domain.Provider, cell internal.Cell) { provider.AddQrCode(q.code, cell, q.prop) } -func (q *qrCode) GetType() string { - return q._type.String() -} - func (q *qrCode) GetStructure() *tree.Node[domain.Structure] { str := domain.Structure{ - Type: string(q._type), + Type: "qrcode", Value: q.code, } diff --git a/pkg/v2/document.go b/pkg/v2/document.go index 882b8928..8530ced5 100644 --- a/pkg/v2/document.go +++ b/pkg/v2/document.go @@ -4,18 +4,16 @@ import ( "github.com/johnfercher/go-tree/tree" "github.com/johnfercher/maroto/internal" "github.com/johnfercher/maroto/pkg/color" - "github.com/johnfercher/maroto/pkg/v2/col" "github.com/johnfercher/maroto/pkg/v2/context" "github.com/johnfercher/maroto/pkg/v2/domain" - "github.com/johnfercher/maroto/pkg/v2/page" - "github.com/johnfercher/maroto/pkg/v2/row" - "github.com/johnfercher/maroto/pkg/v2/types" + "github.com/johnfercher/maroto/pkg/v2/grid/col" + "github.com/johnfercher/maroto/pkg/v2/grid/page" + "github.com/johnfercher/maroto/pkg/v2/grid/row" ) type document struct { file string cell internal.Cell - _type types.DocumentType provider domain.Provider pages []domain.Page rows []domain.Row @@ -29,7 +27,6 @@ func NewMaroto(provider domain.Provider, file string) *document { return &document{ file: file, provider: provider, - _type: types.Document, cell: context.NewRootContext(width, height, context.Margins{ Left: left, Top: top, @@ -91,7 +88,7 @@ func (d *document) Generate() error { func (d *document) GetStructure() *tree.Node[domain.Structure] { str := domain.Structure{ - Type: string(d._type), + Type: "document", Value: d.file, } node := tree.NewNode(str) diff --git a/pkg/v2/document_test.go b/pkg/v2/document_test.go index b4274a31..a287a442 100644 --- a/pkg/v2/document_test.go +++ b/pkg/v2/document_test.go @@ -7,9 +7,9 @@ import ( "github.com/johnfercher/maroto/pkg/v2/code/barcode" "github.com/johnfercher/maroto/pkg/v2/code/matrixcode" "github.com/johnfercher/maroto/pkg/v2/code/qrcode" - "github.com/johnfercher/maroto/pkg/v2/col" + "github.com/johnfercher/maroto/pkg/v2/grid/col" + "github.com/johnfercher/maroto/pkg/v2/grid/row" "github.com/johnfercher/maroto/pkg/v2/image" - "github.com/johnfercher/maroto/pkg/v2/row" "github.com/johnfercher/maroto/pkg/v2/signature" "github.com/johnfercher/maroto/pkg/v2/text" "github.com/stretchr/testify/assert" diff --git a/pkg/v2/domain/domain.go b/pkg/v2/domain/domain.go index 1d378069..cc2c522e 100644 --- a/pkg/v2/domain/domain.go +++ b/pkg/v2/domain/domain.go @@ -22,11 +22,6 @@ type Node interface { GetStructure() *tree.Node[Structure] } -type Component interface { - Node - GetType() string // Just to differentiate from Node -} - type Page interface { Node Add(rows ...Row) Page @@ -42,7 +37,7 @@ type Row interface { type Col interface { Node - Add(component ...Component) Col + Add(nodes ...Node) Col AddInner(rows ...Row) Col GetSize() int } diff --git a/pkg/v2/col/col.go b/pkg/v2/grid/col/col.go similarity index 66% rename from pkg/v2/col/col.go rename to pkg/v2/grid/col/col.go index 2ef8bcd2..0d334ee7 100644 --- a/pkg/v2/col/col.go +++ b/pkg/v2/grid/col/col.go @@ -5,7 +5,6 @@ import ( "github.com/johnfercher/go-tree/tree" "github.com/johnfercher/maroto/internal" "github.com/johnfercher/maroto/pkg/v2/domain" - "github.com/johnfercher/maroto/pkg/v2/types" ) const ( @@ -13,25 +12,19 @@ const ( ) type col struct { - size int - _type types.DocumentType - components []domain.Component - rows []domain.Row + size int + nodes []domain.Node + rows []domain.Row } func New(size int) domain.Col { return &col{ - _type: types.Col, - size: size, + size: size, } } -func (c *col) GetType() string { - return c._type.String() -} - -func (c *col) Add(components ...domain.Component) domain.Col { - c.components = append(c.components, components...) +func (c *col) Add(node ...domain.Node) domain.Col { + c.nodes = append(c.nodes, node...) return c } @@ -46,13 +39,13 @@ func (c *col) GetSize() int { func (c *col) GetStructure() *tree.Node[domain.Structure] { str := domain.Structure{ - Type: string(c._type), + Type: "col", Value: fmt.Sprintf("%d", c.size), } node := tree.NewNode(str) - for _, c := range c.components { + for _, c := range c.nodes { inner := c.GetStructure() node.AddNext(inner) } @@ -63,7 +56,7 @@ func (c *col) GetStructure() *tree.Node[domain.Structure] { func (c *col) Render(provider domain.Provider, cell internal.Cell) { c.render(provider, cell) - for _, component := range c.components { + for _, component := range c.nodes { component.Render(provider, cell) } diff --git a/pkg/v2/col/col_test.go b/pkg/v2/grid/col/col_test.go similarity index 98% rename from pkg/v2/col/col_test.go rename to pkg/v2/grid/col/col_test.go index c9e2e241..631c87e5 100644 --- a/pkg/v2/col/col_test.go +++ b/pkg/v2/grid/col/col_test.go @@ -326,7 +326,7 @@ func TestCol_Render(t *testing.T) { // assert }) - t.Run("should render child components with width matching col width", func(t *testing.T) { + t.Run("should render child nodes with width matching col width", func(t *testing.T) { // arrange col := New(12) child := text.New("test") diff --git a/pkg/v2/page/page.go b/pkg/v2/grid/page/page.go similarity index 81% rename from pkg/v2/page/page.go rename to pkg/v2/grid/page/page.go index 568c601e..dbffaab6 100644 --- a/pkg/v2/page/page.go +++ b/pkg/v2/grid/page/page.go @@ -4,19 +4,15 @@ import ( "github.com/johnfercher/go-tree/tree" "github.com/johnfercher/maroto/internal" "github.com/johnfercher/maroto/pkg/v2/domain" - "github.com/johnfercher/maroto/pkg/v2/types" ) type page struct { number int - _type types.DocumentType rows []domain.Row } func New() domain.Page { - return &page{ - _type: types.Page, - } + return &page{} } func (p *page) Render(provider domain.Provider, cell internal.Cell) { @@ -27,10 +23,6 @@ func (p *page) Render(provider domain.Provider, cell internal.Cell) { } } -func (p *page) GetType() string { - return p._type.String() -} - func (p *page) SetNumber(number int) { p.number = number } @@ -46,7 +38,7 @@ func (p *page) Add(rows ...domain.Row) domain.Page { func (p *page) GetStructure() *tree.Node[domain.Structure] { str := domain.Structure{ - Type: string(p._type), + Type: "page", } node := tree.NewNode(str) diff --git a/pkg/v2/row/row.go b/pkg/v2/grid/row/row.go similarity index 88% rename from pkg/v2/row/row.go rename to pkg/v2/grid/row/row.go index 98621ba8..04fb276a 100644 --- a/pkg/v2/row/row.go +++ b/pkg/v2/grid/row/row.go @@ -6,12 +6,10 @@ import ( "github.com/johnfercher/maroto/internal" "github.com/johnfercher/maroto/pkg/color" "github.com/johnfercher/maroto/pkg/v2/domain" - "github.com/johnfercher/maroto/pkg/v2/types" ) type row struct { height float64 - _type types.DocumentType cols []domain.Col color color.Color } @@ -32,19 +30,14 @@ func New(height float64, c ...color.Color) domain.Row { } return &row{ - _type: types.Row, height: height, color: cx, } } -func (r *row) GetType() string { - return r._type.String() -} - func (r *row) GetStructure() *tree.Node[domain.Structure] { str := domain.Structure{ - Type: string(r._type), + Type: "row", Value: fmt.Sprintf("%2.f", r.height), } diff --git a/pkg/v2/image/base64image.go b/pkg/v2/image/base64image.go index 6769c0ca..11fc353a 100644 --- a/pkg/v2/image/base64image.go +++ b/pkg/v2/image/base64image.go @@ -6,18 +6,15 @@ import ( "github.com/johnfercher/maroto/pkg/consts" "github.com/johnfercher/maroto/pkg/props" "github.com/johnfercher/maroto/pkg/v2/domain" - "github.com/johnfercher/maroto/pkg/v2/types" ) type base64Image struct { - base64 string - extension consts.Extension - _type types.DocumentType - components []domain.Node - prop props.Rect + base64 string + extension consts.Extension + prop props.Rect } -func NewFromBase64(path string, extension consts.Extension, imageProps ...props.Rect) domain.Component { +func NewFromBase64(path string, extension consts.Extension, imageProps ...props.Rect) domain.Node { prop := props.Rect{} if len(imageProps) > 0 { prop = imageProps[0] @@ -25,7 +22,6 @@ func NewFromBase64(path string, extension consts.Extension, imageProps ...props. prop.MakeValid() return &base64Image{ - _type: types.Image, base64: path, prop: prop, extension: extension, @@ -36,10 +32,6 @@ func (b *base64Image) Render(provider domain.Provider, cell internal.Cell) { provider.AddImageFromBase64(b.base64, cell, b.prop, b.extension) } -func (b *base64Image) GetType() string { - return b._type.String() -} - func (b *base64Image) GetStructure() *tree.Node[domain.Structure] { trimLength := 10 if len(b.base64) < trimLength { @@ -47,7 +39,7 @@ func (b *base64Image) GetStructure() *tree.Node[domain.Structure] { } str := domain.Structure{ - Type: string(b._type), + Type: "base64image", Value: b.base64[:trimLength], } diff --git a/pkg/v2/image/fileimage.go b/pkg/v2/image/fileimage.go index a2dfdbf0..bbd8d0cf 100644 --- a/pkg/v2/image/fileimage.go +++ b/pkg/v2/image/fileimage.go @@ -5,17 +5,14 @@ import ( "github.com/johnfercher/maroto/internal" "github.com/johnfercher/maroto/pkg/props" "github.com/johnfercher/maroto/pkg/v2/domain" - "github.com/johnfercher/maroto/pkg/v2/types" ) type fileImage struct { - path string - _type types.DocumentType - components []domain.Node - prop props.Rect + path string + prop props.Rect } -func NewFromFile(path string, imageProps ...props.Rect) domain.Component { +func NewFromFile(path string, imageProps ...props.Rect) domain.Node { prop := props.Rect{} if len(imageProps) > 0 { prop = imageProps[0] @@ -23,9 +20,8 @@ func NewFromFile(path string, imageProps ...props.Rect) domain.Component { prop.MakeValid() return &fileImage{ - _type: types.Image, - path: path, - prop: prop, + path: path, + prop: prop, } } @@ -33,13 +29,9 @@ func (f *fileImage) Render(provider domain.Provider, cell internal.Cell) { provider.AddImageFromFile(f.path, cell, f.prop) } -func (f *fileImage) GetType() string { - return f._type.String() -} - func (f *fileImage) GetStructure() *tree.Node[domain.Structure] { str := domain.Structure{ - Type: string(f._type), + Type: "fileimage", Value: f.path, } diff --git a/pkg/v2/signature/signature.go b/pkg/v2/signature/signature.go index 7a978029..1240b669 100644 --- a/pkg/v2/signature/signature.go +++ b/pkg/v2/signature/signature.go @@ -6,17 +6,14 @@ import ( "github.com/johnfercher/maroto/pkg/consts" "github.com/johnfercher/maroto/pkg/props" "github.com/johnfercher/maroto/pkg/v2/domain" - "github.com/johnfercher/maroto/pkg/v2/types" ) type signature struct { - value string - _type types.DocumentType - components []domain.Node - prop props.Font + value string + prop props.Font } -func New(value string, textProps ...props.Font) domain.Component { +func New(value string, textProps ...props.Font) domain.Node { prop := props.Font{} if len(textProps) > 0 { prop = textProps[0] @@ -24,7 +21,6 @@ func New(value string, textProps ...props.Font) domain.Component { prop.MakeValid(consts.Arial) return &signature{ - _type: types.Signature, value: value, prop: prop, } @@ -34,13 +30,9 @@ func (s *signature) Render(provider domain.Provider, cell internal.Cell) { provider.AddSignature(s.value, cell, s.prop.ToTextProp(consts.Center, 0.0, false, 0)) } -func (s *signature) GetType() string { - return s._type.String() -} - func (s *signature) GetStructure() *tree.Node[domain.Structure] { str := domain.Structure{ - Type: string(s._type), + Type: "signature", Value: s.value, } diff --git a/pkg/v2/text/text.go b/pkg/v2/text/text.go index 9a5ed91b..a4fc175a 100644 --- a/pkg/v2/text/text.go +++ b/pkg/v2/text/text.go @@ -7,17 +7,14 @@ import ( "github.com/johnfercher/maroto/pkg/consts" "github.com/johnfercher/maroto/pkg/props" "github.com/johnfercher/maroto/pkg/v2/domain" - "github.com/johnfercher/maroto/pkg/v2/types" ) type text struct { - value string - _type types.DocumentType - components []domain.Node - prop props.Text + value string + prop props.Text } -func New(value string, prop ...props.Text) domain.Component { +func New(value string, prop ...props.Text) domain.Node { textProp := props.Text{ Color: color.Color{ Red: 0, @@ -32,19 +29,14 @@ func New(value string, prop ...props.Text) domain.Component { textProp.MakeValid(consts.Arial) return &text{ - _type: types.Text, value: value, prop: textProp, } } -func (t *text) GetType() string { - return t._type.String() -} - func (t *text) GetStructure() *tree.Node[domain.Structure] { str := domain.Structure{ - Type: string(t._type), + Type: "text", Value: t.value, } diff --git a/pkg/v2/types/types.go b/pkg/v2/types/types.go deleted file mode 100644 index df25b5d8..00000000 --- a/pkg/v2/types/types.go +++ /dev/null @@ -1,38 +0,0 @@ -package types - -import "slices" - -const ( - Document = "document" - Row = "row" - Page = "page" - Col = "col" - Image = "image" - Text = "text" - Signature = "signature" - Barcode = "barcode" - QrCode = "qrcode" - MatrixCode = "matrixcode" -) - -type DocumentType string - -func (t DocumentType) String() string { - return string(t) -} - -func (t DocumentType) Accept(dt string) bool { - if val, ok := buildAcceptedMap()[t.String()]; ok { - return slices.Contains(val, dt) - } - return false -} - -func buildAcceptedMap() map[string][]string { - return map[string][]string{ - Document: {Row, Page}, - Page: {Row}, - Row: {Col}, - Col: {Row, Image, Text, Signature, Barcode, QrCode, MatrixCode}, - } -} diff --git a/v2.html b/v2.html new file mode 100644 index 00000000..2c2c975a --- /dev/null +++ b/v2.html @@ -0,0 +1,147 @@ + + + + + + Document + + + + + + + +
+
+ + barcode + +
+
+ + qrcode + +
+
+ + matrixcode + +
+
+
+
+ + internal/assets/images/biplane.jpg + +
+
+ + iVBORw0KGgoAAAANSUhE + +
+
+
+
+ + Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ac condimentum sem. + +
+
+ + Fulano de Tal + +
+
+
+
+
+
+
+ + barcode + +
+
+ + qrcode + +
+
+ + matrixcode + +
+
+
+
+ + internal/assets/images/biplane.jpg + +
+
+ + iVBORw0KGgoAAAANSUhE + +
+
+
+
+ + Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ac condimentum sem. + +
+
+ + Fulano de Tal + +
+
+
+
+
+
+
+ + barcode + +
+
+ + qrcode + +
+
+ + matrixcode + +
+
+
+
+ + internal/assets/images/biplane.jpg + +
+
+ + iVBORw0KGgoAAAANSUhE + +
+
+
+
+ + Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ac condimentum sem. + +
+
+ + Fulano de Tal + +
+
+
+
+
+ + \ No newline at end of file diff --git a/v2.pdf b/v2.pdf new file mode 100644 index 00000000..a0194cef Binary files /dev/null and b/v2.pdf differ