From 5c4e21d6aca73e1b6f8e1bfffd47d0e424869d48 Mon Sep 17 00:00:00 2001 From: Masaaki Goshima Date: Sat, 22 Feb 2020 12:56:07 +0900 Subject: [PATCH] Fix text layout --- graphviz_test.go | 4 ++-- gvc/image_renderer.go | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/graphviz_test.go b/graphviz_test.go index 5a816af..6e80c1d 100644 --- a/graphviz_test.go +++ b/graphviz_test.go @@ -37,7 +37,7 @@ func TestGraphviz_Image(t *testing.T) { if err := g.Render(graph, graphviz.PNG, &buf); err != nil { t.Fatalf("%+v", err) } - if len(buf.Bytes()) != 4638 { + if len(buf.Bytes()) != 4625 { t.Fatalf("failed to encode png: bytes length is %d", len(buf.Bytes())) } }) @@ -61,7 +61,7 @@ func TestGraphviz_Image(t *testing.T) { if err := g.Render(graph, graphviz.JPG, &buf); err != nil { t.Fatalf("%+v", err) } - if len(buf.Bytes()) != 3281 { + if len(buf.Bytes()) != 3283 { t.Fatalf("failed to encode jpg: bytes length is %d", len(buf.Bytes())) } }) diff --git a/gvc/image_renderer.go b/gvc/image_renderer.go index b1797ba..363d046 100644 --- a/gvc/image_renderer.go +++ b/gvc/image_renderer.go @@ -110,9 +110,17 @@ func (r *ImageRenderer) TextSpan(job *Job, p Pointf, span *TextSpan) error { if err != nil { return err } + switch span.Just() { + case 'r': + p.X -= span.Size().X + case 'l': + p.X -= 0.0 + case 'n': + p.X -= (span.Size().X / 2.0) + } r.ctx.SetFontFace(face) y := p.Y + span.YOffsetCenterLine() + span.YOffsetLayout() - r.ctx.DrawStringAnchored(span.Str(), p.X, -y, 0.5, 0) + r.ctx.DrawStringAnchored(span.Str(), p.X, -y, 0, 0) return nil }