Feature. Text rotation#564
Conversation
Add horizontal and vertical pivot options for text rotation. Default pivots are set to Center and Middle. Update tests to cover various pivot configurations and ensure accurate positioning for multi-line text.
Add new example demonstrating text rotation with pivot customization. Update documentation to describe `Rotation` and `RotationPivot` options comprehensively, including usage notes.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughSummary by CodeRabbit
WalkthroughAdds text rotation support: new rotation props and pivot constants, provider/interface methods for measuring string width, rotated bounding-box math and pivot-aware positioning in rendering, mock/test updates, example, and documentation updates. Changes
Sequence Diagram(s)sequenceDiagram
participant Component as Text Component
participant Provider as GoFPDF Provider
participant PDF as PDF Context
Component->>Provider: Add(text, props {Rotation, RotationPivot})
activate Provider
Provider->>Provider: Determine wrapped lines\nGetStringWidth for measurement
Provider->>Provider: Compute block width/height\nCompute alignment & pivot offsets
Provider->>Provider: Calculate rotated bounding-box\nAdjust start Y if needed
Provider->>PDF: TransformBegin()
Provider->>PDF: TransformRotate(angle, pivotX, pivotY)
Provider->>PDF: Text(x, y) for each line
Provider->>PDF: TransformEnd()
deactivate Provider
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@pkg/components/text/text.go`:
- Around line 72-85: contentWidth can be negative if t.prop.Left + t.prop.Right
> cell.Width which yields invalid heights when rotation math runs; before
calling provider.GetLinesQuantity/GetStringWidth and before using contentWidth
in the rotation block, clamp contentWidth to zero (or math.Max(0, contentWidth))
and use that non-negative value for subsequent calculations (affecting the call
to provider.GetLinesQuantity, the stringWidth clamp and the rotation height math
that updates textHeight); update references to contentWidth,
provider.GetLinesQuantity, provider.GetStringWidth and the rotation block that
computes textHeight to use the guarded value.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: fd2ca0d7-df9a-41f5-9e0d-90457dffb08b
📒 Files selected for processing (14)
docs/v2/features/text.mdinternal/providers/gofpdf/provider.gointernal/providers/gofpdf/text.gointernal/providers/gofpdf/text_test.gomocks/Provider.gomocks/Text.gopkg/components/text/example_test.gopkg/components/text/text.gopkg/components/text/text_test.gopkg/consts/rotationpivot/rotationpivot.gopkg/core/components.gopkg/core/provider.gopkg/props/text.gopkg/props/text_test.go
Description
Adds
Rotation(degrees, positive = CCW, negative = CW) andRotationPivot(Horizontal×Verticalaxes) toprops.Text. Cell auto-expands vertically to fit the rotated bounding box; default Center+Middle pivot keeps single-linebehavior identical to before.
Notable details:
Text.GetHeightreturns the rotated bbox height (w·|sinθ| + h·|cosθ|) so the layout reserves room.Provider.GetStringWidthletsGetHeightuse the actual rendered width instead ofcell.Width(avoids ~3× over-allocation for short text).Addhoists line-splitting above the rotation transform so multi-line blocks rotate as one around the correcttextHeight-based pivot.upExtentis computed from the four rotated corners — covers all 9 pivot combos for any angle/sign.ToMapomits the new keys when default → existing snapshots untouched.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