-
-
Notifications
You must be signed in to change notification settings - Fork 188
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
feature/Support for multiple styles in same text #447
base: master
Are you sure you want to change the base?
Changes from all commits
2a10589
8026555
1f1d7e4
abc1387
eb538ab
396d4b9
87e8755
a1394eb
993fa10
dea25f4
d1679ef
90dd958
9959c34
67c0a49
eebd7e5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,11 +4,14 @@ import ( | |
"log" | ||
|
||
"github.com/johnfercher/maroto/v2/pkg/core" | ||
"github.com/johnfercher/maroto/v2/pkg/core/entity" | ||
|
||
"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/row" | ||
"github.com/johnfercher/maroto/v2/pkg/components/text" | ||
|
||
"github.com/johnfercher/maroto/v2/pkg/consts/align" | ||
|
@@ -88,5 +91,11 @@ func GetMaroto() core.Maroto { | |
|
||
m.AddRows(text.NewRow(10, "text with hyperlink", props.Text{Hyperlink: &google})) | ||
|
||
subText1 := entity.NewSubText("This is a text", props.SubText{Color: &props.BlueColor}) | ||
subText2 := entity.NewSubText(" with multiple", props.SubText{Size: 7}) | ||
subText3 := entity.NewSubText(" styles", props.SubText{Color: &props.RedColor}) | ||
|
||
customText := col.New(12).Add(text.NewCustomText([]*entity.SubText{subText1, subText2, subText3})) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we could change the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree, this way is better. The only issue is that |
||
m.AddRows(row.New(10).Add(customText)) | ||
return m | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
generate -> avg: 21.04ms, executions: [21.04ms] | ||
add_row -> avg: 675.40ns, executions: [2.01μs, 0.50μs, 0.30μs, 0.30μs, 0.26μs] | ||
add_rows -> avg: 260.40ns, executions: [331.00ns, 301.00ns, 100.00ns, 470.00ns, 100.00ns] | ||
file_size -> 8.74Kb | ||
generate -> avg: 11.28ms, executions: [11.28ms] | ||
add_row -> avg: 420.80ns, executions: [1.14μs, 0.30μs, 0.27μs, 0.21μs, 0.18μs] | ||
add_rows -> avg: 131.83ns, executions: [230.00ns, 190.00ns, 60.00ns, 221.00ns, 40.00ns, 50.00ns] | ||
file_size -> 15.78Kb |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,10 @@ func (g *provider) AddText(text string, cell *entity.Cell, prop *props.Text) { | |
g.text.Add(text, cell, prop) | ||
} | ||
|
||
func (g *provider) AddCustomText(subs []*entity.SubText, cell *entity.Cell, textPs *props.Text) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment here. |
||
g.text.AddCustomText(subs, cell, textPs) | ||
} | ||
|
||
func (g *provider) GetTextHeight(prop *props.Font) float64 { | ||
return g.font.GetHeight(prop.Family, prop.Style, prop.Size) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe NewSubText should be in text package also as NewCustomText.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to do it this way, but the provider depends on the subText structure and if I declare the subtext in the Text package, it generates a cyclical dependency.
I think this would be possible if we remove the dependency that the provider has on subtext, but I don't know how to do this in a nice way