Some months ago I created an extension to import SVG files into Sketchup. It works quite nice for the import of ‘normal 2D geometry’ (edges and faces on the groundplane (Z=0)). One of the outstanding issues that I still had with this extension was related to the import of SVG texts, and how they translate into 3D-text objects in Sketchup. A first problem was the absence of a font baseline in the Sketchup Ruby API, which led to unalligned text nodes on a single line of text. This is solved now.
The other outstanding issue with texts is related to the text sizes. In SVG textsize can be defined via multiple ‘units’ (pt, px, pc, em). All values expressed in these ‘units’ are converted into a kind of ‘virtual units’ (based on pixels). SVG is - by nature - ‘scaleable’, and thus ‘unit-less’.
Whatever units (if any) that are specified in the SVG files, NONE of these quantities resulted in a correct scaling of the fonts when the SVG file was imported into Sketchup. This became clear, after I drawed ‘bounding boxes’ surrounding the textblocks in a 2D SVG editor, then exporting the SVG with the 2D Editor, and finally running the SVG Importer in Sketchup.
The bounding boxes were correctly sized, but the ‘embedded’ texts in these bounding boxes did not correspond with the bounding box size (i.e. mostly the texts were oversized). The exported SVG was however correctly specified, since all other SVG client applications (browsers, online editors, …) showed all textblocks that fitted perfectly within the corresponding bounding boxes.
So, the Sketchup Importer didn’t work correctly for texts, and required an extra scaling transformation. Initially, I assumed that a scaling factor of 0.7500 did the job, but after creating texts with multiple fonts, it appeared that the applicable scaling factors varied between 0.40627 and 1.62120. So, a generic scaling by 0.75000 wasn’t the solution. Further analysis indicated that all glyphs and all sizes of a specific font always had the same scaling factor, also when shown on multiple displays with different form factors and resolutions.
As a last resort, I finally dived into the typography parameters of the ttf.-files for the various fonts on my pc. After a deep analysis and multiple tests, I found that the scaling factor that is apparently used by Sketchup for rendering its 3D texts (on Windows) is equal to the quotient of the sTypoAscender and the unitsPerEm values in the .ttf-file. The first value resides in the OS/2 and Windows Metrics Table (OS/2), and the second value is stored in the Font Header Table (head).
Unfortunately, it’s (way) beyond my skills to retrieve these values from the ttf-files, and make them available for further processing in my Ruby script. I’ve done the above analysis, so, I hope that somebody with experience in programming can help me with this problem. In case that any person who is willing to help, would need any further information about my analysis so far, please don’t hesitate to ask (but unsure whether I will be able to provide detailed answers that surpass my very limited technical capabilities…).