Skip to content

Commit

Permalink
Fix text anchor #25
Browse files Browse the repository at this point in the history
  • Loading branch information
sammycage authored Mar 9, 2021
1 parent cd38130 commit 2d6d80e
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions source/svgtextelement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,12 @@ void SVGTextElement::render(RenderContext& context) const
}

state.bbox = path.boundingBox();
TextAnchor anchor = state.style.textAnchor();
if(anchor == TextAnchorMiddle)
state.matrix.translate(-state.bbox.width * 0.5, 0);
else if(anchor == TextAnchorEnd)
state.matrix.translate(-state.bbox.width, 0);

if(state.style.hasStroke())
{
double strokeWidth = state.style.strokeWidth(state);
Expand All @@ -183,12 +189,6 @@ void SVGTextElement::render(RenderContext& context) const
state.bbox.height += strokeWidth;
}

TextAnchor anchor = state.style.textAnchor();
if(anchor == TextAnchorMiddle)
state.matrix.translate(-state.bbox.width * 0.5, 0);
else if(anchor == TextAnchorEnd)
state.matrix.translate(-state.bbox.width, 0);

if(context.mode() == RenderModeBounding)
return;

Expand Down

0 comments on commit 2d6d80e

Please sign in to comment.