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.
Based on Brent's suggestion I tried using the transormation matrices and
directly applying them. That did not work very well at first, but I did notice
that the transformation matrix changes depending on the eventual height and
width of my SVG, that I specify using
-w
and-h
CLI switches. Here are a fewexamples for SVG mentioned above, at different
Could somebody help me see if there is way of deriving the
1x
from the10x
or the
20x
transforms. That would be very helpful for what I am describing inthe next section.
Based on the data above, I tweaked my SVG output to something like this for a 400x400 size output
Note that I made the following tweaks:
applied to the
unitY
matrix1x
matrix, withonly the translation vector tweaked to conform to the final vector space.