SVG as text experiments
SVG can describe paths, but also text. For this we need to embed a font in the SVG file for the case the font is not present on the clients computer. The font in an SVG file has the same structure as SVG font files. The latter were proposed as a font format, but depreciated in favour of OpenType fonts, which is a pity, because besides PostScript Type 3 fonts is the only font format that has a textual form. This is probably too much of open source for font foundries.
The font tag is a very simple structure:
- font with properties id, horiz-adv-x (default width)
- font-face with properties font-family, font-weight, font-stretch, units-per-em, panose-1 (deprecated appearance list for fonts), ascent, descent, x-height, cap-height (all for alignment), bbox (of the biggest character), underline-thickness, underline-position, unicode-range
- missing-glyph with properties horiz-adv-x and d (path)
- glyph with properties glyph-name, unicode, horiz-adv-x and d (path)
The paths are the same as for fill and stroke. Do we have all information from our Type 3 fonts to recreate the SVG font? FontInfo has full name, weight, UnderlinePosition and UnderlineThickness and we have the FontBBox and can use FontMatrix to build UnitsPerEm. For the paths, we can try for each glyph to ignore setcachedevice and paint and hope it makes a sensible path (Type 3 fonts could have arbitrary code, something we cannot reproduce on SVG).
Now we don't have measurement: ascent, descent, x-height, cap-height. We can try 2 things: we try to ignore to specify it, or we use some default values, to have at least a ballpoint. For example, for Courier, Helvetica and Times the values would be
- units-per-em: 2048
- ascent: 1638
- descent: -410
- x-height: 866 (Courier), 1071 (Helvetica), 916 (Times)
- cap-height: 1170 (Courier), 1470 (Helvetica), 1356 (Times)
At runtime, we do not know what kind of fond it is and are somewhere in the dark. I will choose the median values for x-height and cap-height.
We will add a device property textmode (default 0).
Then we implement a show() method in rpnSVGdevice and modify the show operator so that if textmode is set and the device supports it, it calls directly the show mode.
The show() method in rpnSVGdevice builds also the SVG font if necessary.
Unfortunately, as it does not work, we will not use it. The only application that reads still the SVG font tag is an old Opera browser on my MacBook.
What can we do? We can define an external TrueType font.
This works, as long as the TrueType font is in the same folder as the SVG file. But can we embed the font, too? We can get it as Data URI. With a little help of Stackoverflow
We have a working model for SVG. But now we need always 2 fonts. Is there a way to use the TrueType fonts directly? We do not include this page in the code base and try first if we cannot read Truetype fonts directly.