Skip to content
Open
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
19 changes: 14 additions & 5 deletions docs/assets/examples/textgrid/v2/main.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package main

import (
"github.com/johnfercher/maroto/v2/pkg/consts/fontstyle"
"log"

"github.com/johnfercher/maroto/v2/pkg/consts/align"
"github.com/johnfercher/maroto/v2/pkg/consts/breakline"
"github.com/johnfercher/maroto/v2/pkg/consts/fontfamily"
"github.com/johnfercher/maroto/v2/pkg/consts/fontstyle"
"github.com/johnfercher/maroto/v2/pkg/core"

"github.com/johnfercher/maroto/v2"

"github.com/johnfercher/maroto/v2/pkg/consts/breakline"

"github.com/johnfercher/maroto/v2/pkg/components/col"
"github.com/johnfercher/maroto/v2/pkg/components/text"

"github.com/johnfercher/maroto/v2/pkg/consts/align"

"github.com/johnfercher/maroto/v2/pkg/config"
"github.com/johnfercher/maroto/v2/pkg/props"
)
Expand Down Expand Up @@ -109,5 +109,14 @@ func GetMaroto() core.Maroto {
m.AddAutoRow(
text.NewCol(12, longText+" "+longText+" "+longText, props.Text{VerticalPadding: 10, Left: 3, Right: 3, Align: align.Justify, BreakLineStrategy: breakline.EmptySpaceStrategy}),
)

text := text.New("", props.Text{VerticalPadding: 1, Top: 2, Bottom: 2}).
AddSubText(longText+longText+longText+longText, props.SubText{Color: &props.BlueColor, Family: fontfamily.Arial}).
AddSubText(longText, props.SubText{Color: &props.RedColor, Family: fontfamily.Courier, Size: 10}).
AddSubText(longText, props.SubText{Color: &props.GreenColor, Family: fontfamily.ZapBats, Size: 15}).
AddSubText(longText, props.SubText{Color: &props.BlackColor, Family: fontfamily.Helvetica, Size: 10, Style: fontstyle.Bold})

m.AddAutoRow(col.New(12).Add(text))

return m
}
Binary file modified docs/assets/pdf/textgridv2.pdf
Binary file not shown.
8 changes: 4 additions & 4 deletions docs/assets/text/textgridv2.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
generate -> avg: 7.17ms, executions: [7.17ms]
add_row -> avg: 2722.17ns, executions: [14.71μs, 0.38μs, 0.17μs, 0.17μs, 0.12μs, 0.79μs]
add_rows -> avg: 104.00ns, executions: [208.00ns, 83.00ns, 83.00ns, 167.00ns, 0.00ns, 83.00ns]
file_size -> 30.71Kb
generate -> avg: 30.69ms, executions: [30.69ms]
add_row -> avg: 1599.50ns, executions: [3.06μs, 1.25μs, 0.86μs, 0.71μs, 0.73μs, 2.98μs]
add_rows -> avg: 479.17ns, executions: [661.00ns, 581.00ns, 251.00ns, 551.00ns, 190.00ns, 641.00ns]
file_size -> 36.00Kb
8 changes: 6 additions & 2 deletions internal/providers/gofpdf/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,12 @@
g.text.Add(text, cell, prop)
}

func (g *provider) GetLinesQuantity(text string, textProp *props.Text, colWidth float64) int {
return g.text.GetLinesQuantity(text, textProp, colWidth)
func (g *provider) AddCustomText(cell *entity.Cell, textPs *props.Text, subs ...*entity.SubText) {
g.text.AddCustomText(cell, textPs, subs...)
}

func (g *provider) GetTextHeight(textProp *props.Text, colWidth float64, text ...*entity.SubText) float64 {
return g.text.GetTextHeight(textProp, colWidth, text...)

Check warning on line 58 in internal/providers/gofpdf/provider.go

View check run for this annotation

Codecov / codecov/patch

internal/providers/gofpdf/provider.go#L57-L58

Added lines #L57 - L58 were not covered by tests
}

func (g *provider) GetFontHeight(prop *props.Font) float64 {
Expand Down
22 changes: 22 additions & 0 deletions internal/providers/gofpdf/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/google/uuid"
"github.com/johnfercher/maroto/v2/pkg/consts/barcode"
"github.com/johnfercher/maroto/v2/pkg/props"

"github.com/johnfercher/maroto/v2/internal/fixture"
"github.com/johnfercher/maroto/v2/internal/merror"
Expand Down Expand Up @@ -57,6 +58,27 @@ func TestProvider_AddText(t *testing.T) {
text.AssertNumberOfCalls(t, "Add", 1)
}

func TestProvider_AddCustomText(t *testing.T) {
// Arrange
cell := &entity.Cell{}
prop := fixture.TextProp()
sub := entity.SubText{Value: "text", Props: props.NewSubText(&prop)}

text := mocks.NewText(t)
text.EXPECT().AddCustomText(cell, &prop, &sub)

dep := &gofpdf.Dependencies{
Text: text,
}
sut := gofpdf.New(dep)

// Act
sut.AddCustomText(cell, &prop, &sub)

// Assert
text.AssertNumberOfCalls(t, "AddCustomText", 1)
}

func TestProvider_GetTextHeight(t *testing.T) {
// Arrange
fontHeightToReturn := 10.0
Expand Down
Loading