feature/character-breakline-strategy#561
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
internal/providers/gofpdf/text.go (1)
96-102:⚠️ Potential issue | 🟡 MinorKeep
GetLinesQuantityconsistent withAddfor fit-case inputs.At Line 101, counting only via
getLines(...)can return0for empty/whitespace-only strings, whileAddrenders a single line when the text width fits (Line 75). This can still desync auto-row height vs rendered output.💡 Proposed fix
func (s *Text) GetLinesQuantity(text string, textProp *props.Text, colWidth float64) int { s.font.SetFont(textProp.Family, textProp.Style, textProp.Size) textTranslated := s.textToUnicode(text, textProp) - return len(s.getLines(textTranslated, textProp.BreakLineStrategy, colWidth)) + if s.pdf.GetStringWidth(textTranslated) <= colWidth { + return 1 + } + + return len(s.getLines(textTranslated, textProp.BreakLineStrategy, colWidth)) }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@internal/providers/gofpdf/text.go` around lines 96 - 102, GetLinesQuantity currently returns len(s.getLines(...)) which can be 0 for empty or whitespace-only inputs whereas Add will render a single line when the text fits; update GetLinesQuantity (after calling s.textToUnicode and s.getLines) to handle the fit-case: if the computed lines slice is empty but the (trimmed or original) text width fits within colWidth (use the same width-measure logic as Add after s.font.SetFont), return 1; otherwise return the length of the lines slice. Ensure you reuse s.textToUnicode, s.font.SetFont and s.getLines logic so behavior stays consistent with Add.
🧹 Nitpick comments (1)
internal/providers/gofpdf/text_test.go (1)
27-88: Add a regression subtest for empty/whitespace-only fit-case line counting.A small case asserting
GetLinesQuantitymatchesAddbehavior for fit-path empty/space-only text would lock in the render/height consistency goal.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@internal/providers/gofpdf/text_test.go` around lines 27 - 88, Add a regression subtest in TestGetLinesHeight that verifies GetLinesQuantity handles empty or whitespace-only strings the same way the Add rendering path does: create a props.Text (valid font), set up mocks for font.SetFont and pdf.UnicodeTranslatorFromDescriptor and any expected pdf.GetStringWidth calls for spaces, then call text.GetLinesQuantity with inputs like "" and " " and assert the returned line count equals what the Add/renderer would produce for those inputs (use the same NewText constructor: gofpdf.NewText(pdf, mocks.NewMath(t), font) and call GetLinesQuantity to compare). Ensure the test name explains it's for empty/whitespace-only fit-case regression and mark it t.Parallel().
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@internal/providers/gofpdf/text.go`:
- Around line 96-102: GetLinesQuantity currently returns len(s.getLines(...))
which can be 0 for empty or whitespace-only inputs whereas Add will render a
single line when the text fits; update GetLinesQuantity (after calling
s.textToUnicode and s.getLines) to handle the fit-case: if the computed lines
slice is empty but the (trimmed or original) text width fits within colWidth
(use the same width-measure logic as Add after s.font.SetFont), return 1;
otherwise return the length of the lines slice. Ensure you reuse
s.textToUnicode, s.font.SetFont and s.getLines logic so behavior stays
consistent with Add.
---
Nitpick comments:
In `@internal/providers/gofpdf/text_test.go`:
- Around line 27-88: Add a regression subtest in TestGetLinesHeight that
verifies GetLinesQuantity handles empty or whitespace-only strings the same way
the Add rendering path does: create a props.Text (valid font), set up mocks for
font.SetFont and pdf.UnicodeTranslatorFromDescriptor and any expected
pdf.GetStringWidth calls for spaces, then call text.GetLinesQuantity with inputs
like "" and " " and assert the returned line count equals what the
Add/renderer would produce for those inputs (use the same NewText constructor:
gofpdf.NewText(pdf, mocks.NewMath(t), font) and call GetLinesQuantity to
compare). Ensure the test name explains it's for empty/whitespace-only fit-case
regression and mark it t.Parallel().
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: e0aae567-68e2-4437-9af1-7933b34e8bdd
⛔ Files ignored due to path filters (1)
docs/assets/pdf/textgridv2.pdfis excluded by!**/*.pdf
📒 Files selected for processing (9)
README.mddocs/assets/examples/textgrid/v2/main.godocs/assets/text/textgridv2.txtdocs/v2/features/text.mdinternal/providers/gofpdf/text.gointernal/providers/gofpdf/text_test.gopkg/components/text/example_test.gopkg/consts/breakline/breakline.gotest/maroto/examples/textgrid.json
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
Description
This PR adds
breakline.CharacterStrategy, a new break line strategy that wraps text at character boundaries without appending a dash.This is useful for languages and content where breaking by spaces is not appropriate, but adding hyphens is also undesirable.
The implementation also makes line splitting consistent between rendering and height calculation by reusing the same strategy path in
AddandGetLinesQuantity, including Unicode-translated text. This avoids mismatches between rendered output and auto-row sizing.In addition, this PR updates the text documentation, README, Go examples, and the
textgridexample assets to show howCharacterStrategybehaves compared withDashStrategy.Related Issue
N/A
Checklist
func (<first letter of struct> *struct) method() {}name style.when,shouldnaming pattern.m := mocks.NewConstructor(t).m.EXPECT().MethodName()method to mock methods.example_test.go.make dodwith none issues pointed out bygolangci-lint