freetype
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [ft] Using SVG Font Glyph Data In FreeType


From: Michiel Kamermans
Subject: Re: [ft] Using SVG Font Glyph Data In FreeType
Date: Thu, 08 Apr 2010 05:08:04 -0700
User-agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-GB; rv:1.9.1.5) Gecko/20091204 Thunderbird/3.0

Hi Tom, Werner, Andy,

If you're looking for sample code that reads SVG, I don't think that's 
something FreeType does. The FreeType side is relatively easy, and Werner has 
shown you sample code for that. The SVG side is not trivial; it requires XML 
parsing and should probably be done with a library for SVG (but I don't know 
what library to recommend).

Depending on how he built his SVG, this should essentially be trivial. As long as his SVG consists of paths rather than predefined shapes like rectangles and circles (which, given glyph outlines, I wouldn't think he uses), these elements have the wonderfully names "d" attribute, which contains a normal human readable string of path construction instructions. For instance:

<path d="M 10 10 L 30 20 Q 20 40 50 50"/>

In this string, "M" signifies "move to .../...", "L" is "line to .../...", and "Q" is "quadratic bezier curve over .../... to .../..." (there's also "C" for cubic bezier, and there may be a "Z" at the end of the string to signify 'close this path by doing a lineto back to the original starting point').

These string segments should be almost trivially simple to map to FreeType, since the basic instructions are the same for pretty much all things related to fonts: move, line, curve (if you're lucky, 2nd and 3rd order, if not, it's just 3rd order with a need to model 2nd order curves as 3rd order).

If I understand Andy correctly, he'd like to map these primitive outline commands to the corresponding FreeType rules (the FT_outline_Functs structures) and then hand off the set of rules for FreeType to work its magic on. I've had a look at http://freetype.sourceforge.net/freetype2/docs/tutorial/example3.cpp but it seems incomplete for the purpose of what he wants to do, as it seems to demonstrate how to deal with a purely line data shape, rather than one consisting of curve data. The shape as used in the example code uses only on-curve vectors, rather than structs that allow specification of on-curve coordinates, and off-curve bezier control points.

Andy, if I might ask, where did you get your glyph SVG data from in the first place? Are you extracting them from fonts, or are these vector outlines made in (for instance) Inkscape that you want to pass to FreeType for text rendering?

If the first, is there a reason for not simply using the fonts you extracted the glyphs from? If the latter, would it not make more sense to do your outline definition in something like FontForge instead, and build an actual font that FreeType can use? Of course, option number three is you're doing dynamic glyph definitions, using them in dynamically generated images with text... but in that case it might be far more sensible to build the entire graphic as an SVG image instead.

- Mike "Pomax" Kamermans
nihongoresources.com








reply via email to

[Prev in Thread] Current Thread [Next in Thread]