Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V2 bar #261

Merged
merged 2 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
87 changes: 87 additions & 0 deletions internal/examples/barcodegrid/v2/main.go
Original file line number Diff line number Diff line change
@@ -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))
}
15 changes: 2 additions & 13 deletions internal/examples/imagegrid/v2/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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)

Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
Binary file modified internal/examples/pdfs/barcodegrid.pdf
Binary file not shown.
Binary file added internal/examples/pdfs/barcodegridv2.pdf
Binary file not shown.
Binary file modified internal/examples/pdfs/imagegrid.pdf
Binary file not shown.
Binary file modified internal/examples/pdfs/imagegridv2.pdf
Binary file not shown.
20 changes: 6 additions & 14 deletions pkg/v2/code/barcode/barcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,33 @@ 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]
}
prop.MakeValid()

return &barcode{
_type: types.Barcode,
code: code,
prop: prop,
code: code,
prop: prop,
}
}

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,
}

Expand Down
20 changes: 6 additions & 14 deletions pkg/v2/code/matrixcode/matrixcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,33 @@ 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]
}
prop.MakeValid()

return &matrixCode{
_type: types.MatrixCode,
code: code,
prop: prop,
code: code,
prop: prop,
}
}

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,
}

Expand Down
20 changes: 6 additions & 14 deletions pkg/v2/code/qrcode/qrcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,33 @@ 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]
}
prop.MakeValid()

return &qrCode{
_type: types.QrCode,
code: code,
prop: prop,
code: code,
prop: prop,
}
}

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,
}

Expand Down
11 changes: 4 additions & 7 deletions pkg/v2/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pkg/v2/document_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading