Fix text offset calculation

This commit is contained in:
Nathan McRae
2025-08-19 20:15:57 -07:00
parent 99cc71e330
commit 2fabfa3415

View File

@@ -94,9 +94,9 @@ svgTextID idMaybe text { x: x, y: y } angle style dimension =
XMLFragment $ "<text " <> idText <> " xml:space=\"preserve\" style=\"font-size:" <> (toString style.sizePx) <> "px;line-height:131%;font-family:'" <> style.typeface <> "';fill:#000000;stroke:#000000;stroke-width:0.0999998;stroke-linecap:round;stop-color:#000000;fill-opacity:1\" " XMLFragment $ "<text " <> idText <> " xml:space=\"preserve\" style=\"font-size:" <> (toString style.sizePx) <> "px;line-height:131%;font-family:'" <> style.typeface <> "';fill:#000000;stroke:#000000;stroke-width:0.0999998;stroke-linecap:round;stop-color:#000000;fill-opacity:1\" "
<> "transform=\"translate(" <> (toString centerX) <> ", " <> (toString centerY) <> ") rotate(" <> (toString (angle * 180.0 / pi)) <> ")\">" <> text <> "</text>" <> "transform=\"translate(" <> (toString centerX) <> ", " <> (toString centerY) <> ") rotate(" <> (toString (angle * 180.0 / pi)) <> ")\">" <> text <> "</text>"
where where
offset = rotate angle {x: dimension.widthPx, y: dimension.heightPx} offset = rotate angle {x: dimension.widthPx / 4.0, y: -dimension.heightPx / 8.0}
centerX = x - offset.x / 4.0 centerX = x - offset.x
centerY = y - offset.y / 4.0 centerY = y - offset.y
idText = case idMaybe of idText = case idMaybe of
Maybe.Nothing -> "" Maybe.Nothing -> ""
Maybe.Just id -> "id=\"" <> id <> "\"" Maybe.Just id -> "id=\"" <> id <> "\""