A text primitive consists of the string contents and alignment specification, along with a transformation mapping from the local vector space of the text to the vector space in which it is embedded.
Text T2 TextAlignment String
Ideally the SVG rendered should be like the one below in file text.svg
.
Note that we use font-size="1"
to establish a baseline font-size, and then we use em units in other places to specify a relative font size.
-- FIXME implement
renderText (Text tr _ str) = undefined
Below are things we need to render the text. We ignore TextAlignment
data for now. str
is self evident (it is the text we need to render).
As for tr
:
-
We need the translation of the origin of the text primitive in the final vector space. This can be easily obtained by
transl tr
. Then we apply that on a<g>
node as shown in filetext.svg
below:<g transform="translate(50 50)">
-
We need the matrix for rotation, which corresponds to the amount of by which the y-axis has rotated in the final vector space. In the example program above we rotate by
1/7
, which is roughly 51 degrees. However I could only get the expected end result by usingrotate(-51)
ormatrix(0.62 -0.77 0.77 0.62 0 0)
as shown in filetext.svg
below. -
We need the final font size. Font size is effectively a measure of the height of the font, because we cannot control the width, which varies from glyph to glyph. You might think we can apply scaling in the matrix above and get away with a font size of 1, but I tried it and it doesnt work in many situations. So we need to somehow calculate the size of the font. I am not sure whether we can get this out of
tr
, but my intuition suggests that it is the scaling factor along the font's vertical axis in the final vector space.
"You might think we can apply scaling in the matrix above and get away with a font size of 1, but I tried it and it doesnt work in many situations." --> could you be more specific?