-
-
Notifications
You must be signed in to change notification settings - Fork 257
feature/character-breakline-strategy #561
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
Open
joeyave
wants to merge
6
commits into
johnfercher:master
Choose a base branch
from
joeyave:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1ef820e
feat: add character strategy for line breaking
joeyave c7fc9ac
feat(text): document character break line strategy
joeyave baee9e2
Merge branch 'johnfercher:master' into master
joeyave 382c7db
feat(text): add preserve line break rendering
joeyave 680cc12
feat(richtext): add mixed-style text support
joeyave 0e07553
chore(deps): update dependencies in go.mod and go.sum
joeyave File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,148 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "log" | ||
|
|
||
| "github.com/johnfercher/maroto/v2" | ||
| "github.com/johnfercher/maroto/v2/pkg/components/richtext" | ||
| "github.com/johnfercher/maroto/v2/pkg/components/text" | ||
| "github.com/johnfercher/maroto/v2/pkg/config" | ||
| "github.com/johnfercher/maroto/v2/pkg/consts/align" | ||
| "github.com/johnfercher/maroto/v2/pkg/consts/fontstyle" | ||
| "github.com/johnfercher/maroto/v2/pkg/core" | ||
| "github.com/johnfercher/maroto/v2/pkg/props" | ||
| ) | ||
|
|
||
| func main() { | ||
| m := GetMaroto() | ||
| document, err := m.Generate() | ||
| if err != nil { | ||
| log.Fatal(err.Error()) | ||
| } | ||
|
|
||
| err = document.Save("docs/assets/pdf/richtextgridv2.pdf") | ||
| if err != nil { | ||
| log.Fatal(err.Error()) | ||
| } | ||
|
|
||
| err = document.GetReport().Save("docs/assets/text/richtextgridv2.txt") | ||
| if err != nil { | ||
| log.Fatal(err.Error()) | ||
| } | ||
| } | ||
|
|
||
| func GetMaroto() core.Maroto { | ||
| cfg := config.NewBuilder(). | ||
| WithDebug(true). | ||
| Build() | ||
|
|
||
| mrt := maroto.New(cfg) | ||
| m := maroto.NewMetricsDecorator(mrt) | ||
|
|
||
| m.AddRows(text.NewRow(10, "Bold word in a sentence", props.Text{ | ||
| Top: 3, | ||
| Left: 2, | ||
| Bottom: 2, | ||
| Style: fontstyle.Bold, | ||
| Size: 9, | ||
| })) | ||
| m.AddAutoRow( | ||
| richtext.NewCol(12, | ||
| richtext.NewChunk("This sentence has a ", props.Text{Top: 2, Left: 2, Bottom: 2}), | ||
| richtext.NewChunk("bold", props.Text{Style: fontstyle.Bold}), | ||
| richtext.NewChunk(" word in the middle."), | ||
| ), | ||
| ) | ||
|
|
||
| m.AddRows(text.NewRow(10, "Mixed styles and colors", props.Text{ | ||
| Top: 3, | ||
| Left: 2, | ||
| Bottom: 2, | ||
| Style: fontstyle.Bold, | ||
| Size: 9, | ||
| })) | ||
| m.AddAutoRow( | ||
| richtext.NewCol(12, | ||
| richtext.NewChunk("Normal, ", props.Text{Top: 2, Left: 2, Bottom: 2}), | ||
| richtext.NewChunk("bold, ", props.Text{Style: fontstyle.Bold}), | ||
| richtext.NewChunk("italic, ", props.Text{Style: fontstyle.Italic}), | ||
| richtext.NewChunk("red", props.Text{Style: fontstyle.Bold, Color: &props.RedColor}), | ||
| richtext.NewChunk(", "), | ||
| richtext.NewChunk("green", props.Text{Style: fontstyle.Bold, Color: &props.GreenColor}), | ||
| richtext.NewChunk(", and "), | ||
| richtext.NewChunk("blue", props.Text{Style: fontstyle.Bold, Color: &props.BlueColor}), | ||
| richtext.NewChunk(" in one flowing paragraph."), | ||
| ), | ||
| ) | ||
|
|
||
| m.AddRows(text.NewRow(10, "Mixed font sizes", props.Text{ | ||
| Top: 3, | ||
| Left: 2, | ||
| Bottom: 2, | ||
| Style: fontstyle.Bold, | ||
| Size: 9, | ||
| })) | ||
| m.AddAutoRow( | ||
| richtext.NewCol(12, | ||
| richtext.NewChunk("Small ", props.Text{Top: 2, Left: 2, Bottom: 2, Size: 8}), | ||
| richtext.NewChunk("Medium ", props.Text{Size: 12}), | ||
| richtext.NewChunk("Large ", props.Text{Size: 16, Style: fontstyle.Bold}), | ||
| richtext.NewChunk("back to small.", props.Text{Size: 8}), | ||
| ), | ||
| ) | ||
|
|
||
| m.AddRows(text.NewRow(10, "Word wrapping across styles", props.Text{ | ||
| Top: 3, | ||
| Left: 2, | ||
| Bottom: 2, | ||
| Style: fontstyle.Bold, | ||
| Size: 9, | ||
| })) | ||
| m.AddAutoRow( | ||
| richtext.NewCol(12, | ||
| richtext.NewChunk("This is a longer paragraph that demonstrates how ", props.Text{ | ||
| Top: 2, | ||
| Left: 2, | ||
| Right: 2, | ||
| }), | ||
| richtext.NewChunk("rich text", props.Text{Style: fontstyle.Bold}), | ||
| richtext.NewChunk(" handles "), | ||
| richtext.NewChunk("word wrapping", props.Text{Style: fontstyle.Italic}), | ||
| richtext.NewChunk(" across multiple lines while "), | ||
| richtext.NewChunk("preserving each chunk style", props.Text{Style: fontstyle.Bold, Color: &props.RedColor}), | ||
| richtext.NewChunk(" inside the same paragraph."), | ||
| ), | ||
| ) | ||
|
|
||
| m.AddRows(text.NewRow(10, "Alignment and line breaks", props.Text{ | ||
| Top: 3, | ||
| Left: 2, | ||
| Bottom: 2, | ||
| Style: fontstyle.Bold, | ||
| Size: 9, | ||
| })) | ||
| m.AddAutoRow( | ||
| richtext.NewCol(6, | ||
| richtext.NewChunk("Centered rich text\nwith explicit line breaks", props.Text{ | ||
| Top: 2, | ||
| Left: 2, | ||
| Right: 2, | ||
| Align: align.Center, | ||
| PreserveLineBreaks: true, | ||
| }), | ||
| richtext.NewChunk(" and "), | ||
| richtext.NewChunk("bold emphasis", props.Text{Style: fontstyle.Bold}), | ||
| richtext.NewChunk("."), | ||
| ), | ||
| richtext.NewCol(6, | ||
| richtext.NewChunk("Justified text keeps the paragraph flowing while distributing the available width between words.", props.Text{ | ||
| Top: 2, | ||
| Left: 2, | ||
| Right: 2, | ||
| Align: align.Justify, | ||
| }), | ||
| ), | ||
| ) | ||
|
|
||
| return m | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/johnfercher/maroto/v2/pkg/test" | ||
| ) | ||
|
|
||
| func TestGetMaroto(t *testing.T) { | ||
| t.Parallel() | ||
| // Act | ||
| sut := GetMaroto() | ||
|
|
||
| // Assert | ||
| test.New(t).Assert(sut.GetStructure()).Equals("examples/richtextgrid.json") | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| generate -> avg: 14.22ms, executions: [14.22ms] | ||
| add_rows -> avg: 3716.60ns, executions: [17.92μs, 0.21μs, 0.21μs, 0.08μs, 0.17μs] | ||
| file_size -> 51.02Kb |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| generate -> avg: 7.76ms, executions: [7.76ms] | ||
| add_row -> avg: 3375.17ns, executions: [18.38μs, 0.42μs, 0.21μs, 0.17μs, 0.21μs, 0.88μs] | ||
| add_rows -> avg: 138.83ns, executions: [208.00ns, 125.00ns, 83.00ns, 209.00ns, 42.00ns, 166.00ns] | ||
| file_size -> 33.35Kb | ||
| generate -> avg: 10.22ms, executions: [10.22ms] | ||
| add_row -> avg: 2702.57ns, executions: [16.88μs, 0.38μs, 0.17μs, 0.17μs, 0.21μs, 0.88μs, 0.25μs] | ||
| add_rows -> avg: 114.38ns, executions: [166.00ns, 83.00ns, 41.00ns, 167.00ns, 83.00ns, 125.00ns, 125.00ns, 125.00ns] | ||
| file_size -> 37.60Kb |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| # Rich Text | ||
|
|
||
| The Rich Text component renders multiple styled chunks inside a single flowing paragraph. It is useful when one sentence needs partial emphasis such as bold words, mixed colors, italic fragments, or different font sizes without splitting the content across multiple columns. | ||
|
|
||
| `richtext` keeps wrapping behavior across chunk boundaries, so the paragraph still behaves like one text block instead of several disconnected components. | ||
|
|
||
| ## GoDoc | ||
| * [constructor : New](https://pkg.go.dev/github.com/johnfercher/maroto/v2/pkg/components/richtext#New) | ||
| * [constructor : NewCol](https://pkg.go.dev/github.com/johnfercher/maroto/v2/pkg/components/richtext#NewCol) | ||
| * [constructor : NewRow](https://pkg.go.dev/github.com/johnfercher/maroto/v2/pkg/components/richtext#NewRow) | ||
| * [constructor : NewAutoRow](https://pkg.go.dev/github.com/johnfercher/maroto/v2/pkg/components/richtext#NewAutoRow) | ||
| * [constructor : NewChunk](https://pkg.go.dev/github.com/johnfercher/maroto/v2/pkg/components/richtext#NewChunk) | ||
| * [type : Chunk](https://pkg.go.dev/github.com/johnfercher/maroto/v2/pkg/components/richtext#Chunk) | ||
|
|
||
| ## Code Example | ||
| [filename](../../assets/examples/richtextgrid/v2/main.go ':include :type=code') | ||
|
|
||
| ## PDF Generated | ||
| assets/pdf/richtextgridv2.pdf | ||
| ``` | ||
|
|
||
| ## Time Execution | ||
| [filename](../../assets/text/richtextgridv2.txt ':include :type=code') | ||
|
|
||
| ## Test File | ||
| [filename](https://raw.githubusercontent.com/johnfercher/maroto/master/test/maroto/examples/richtextgrid.json ':include :type=code') | ||
|
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. 🧹 Nitpick | 🔵 Trivial Avoid linking fixtures from Using 🤖 Prompt for AI Agents |
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Use a clearer section title:
Execution Time.Time Executionreads awkwardly in user-facing docs.✏️ Suggested doc tweak
📝 Committable suggestion
🤖 Prompt for AI Agents