Skip to content

Commit

Permalink
Merge pull request #16 from goccy/feature/fix-text-layout
Browse files Browse the repository at this point in the history
Fix text layout
  • Loading branch information
goccy authored Feb 22, 2020
2 parents c8837f2 + 5c4e21d commit fe87c3f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions graphviz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
}
})
Expand All @@ -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()))
}
})
Expand Down
10 changes: 9 additions & 1 deletion gvc/image_renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit fe87c3f

Please sign in to comment.