Skip to content

Commit 41fee60

Browse files
committed
Align text bullets with bulletRenderX
1 parent 2dbf30c commit 41fee60

2 files changed

Lines changed: 48 additions & 4 deletions

File tree

ltml/std_paragraph_bullet.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,7 @@ func (p *StdParagraph) bulletRenderSize(w Writer, bullet *BulletStyle, lineHeigh
232232
}
233233

234234
func (p *StdParagraph) textBulletX(w Writer, bullet *BulletStyle, layout paragraphBulletLayout) float64 {
235-
if !IsRTL(p) {
236-
return layout.slotX
237-
}
238-
return layout.slotX + max(layout.slotWidth-p.bulletTextWidth(w, bullet), 0)
235+
return p.bulletRenderX(bullet, layout.slotX, layout.slotWidth, p.bulletTextWidth(w, bullet))
239236
}
240237

241238
func (p *StdParagraph) bulletTextWidth(w Writer, bullet *BulletStyle) float64 {

ltml/std_paragraph_text_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,53 @@ func TestStdParagraph_DrawContent_PlacesTextBulletInRTLSlot(t *testing.T) {
323323
}
324324
}
325325

326+
func TestStdParagraph_DrawContent_AlignsTextBulletWithinLTRSlot(t *testing.T) {
327+
tests := []struct {
328+
name string
329+
alignX string
330+
wantX func(*StdParagraph, *labelTestWriter, *BulletStyle) float64
331+
}{
332+
{
333+
name: "center",
334+
alignX: "center",
335+
wantX: func(p *StdParagraph, w *labelTestWriter, b *BulletStyle) float64 {
336+
return ContentLeft(p) + max((b.Width()-p.bulletTextWidth(w, b))/2, 0)
337+
},
338+
},
339+
{
340+
name: "end",
341+
alignX: "end",
342+
wantX: func(p *StdParagraph, w *labelTestWriter, b *BulletStyle) float64 {
343+
return ContentLeft(p) + max(b.Width()-p.bulletTextWidth(w, b), 0)
344+
},
345+
},
346+
}
347+
348+
for _, tc := range tests {
349+
t.Run(tc.name, func(t *testing.T) {
350+
p := &StdParagraph{}
351+
p.font = &FontStyle{id: "body", entries: []fontEntry{{name: "Helvetica"}}, size: 12}
352+
p.paragraphStyle = &ParagraphStyle{}
353+
p.bullets = []*BulletStyle{{text: "1.", width: 40, font: p.font, alignX: tc.alignX}}
354+
p.SetLeft(10)
355+
p.SetTop(20)
356+
p.SetWidth(140)
357+
p.AddText("Hello world")
358+
359+
w := &labelTestWriter{t: t, fonts: defaultTestFonts(t), lineSpacing: 1.0}
360+
if err := p.DrawContent(w); err != nil {
361+
t.Fatal(err)
362+
}
363+
if len(w.moves) < 3 {
364+
t.Fatalf("move count = %d, want at least 3", len(w.moves))
365+
}
366+
if got, want := w.moves[1][0], tc.wantX(p, w, p.Bullet()); math.Abs(got-want) > 0.001 {
367+
t.Fatalf("bullet x = %v, want %v", got, want)
368+
}
369+
})
370+
}
371+
}
372+
326373
func TestStdParagraph_SetAttrs_ParsesMultipleBulletReferences(t *testing.T) {
327374
scope := &Scope{}
328375
first := &BulletStyle{id: "first", text: "*", width: 12}

0 commit comments

Comments
 (0)