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: Andy Kellett
Subject: Re: [ft] Using SVG Font Glyph Data In FreeType
Date: Thu, 08 Apr 2010 09:05:47 -0400
User-agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1.9) Gecko/20100317 Thunderbird/3.0.4

Hi,

Yes, you described it quite accurately :) While I can do the SVG path conversions/handling myself, the real problem (and while it probbably wasnt described as clearly myself) is telling freetype how to handle the curves etc. that I am reading frm the SVG.

I have already loaded, parsed and broken down the SVG path data into sections, rendering the article with placeholders etc. An example of some of the SVG font data (using standard path commands) is:

<glyph unicode="s" horiz-adv-x="556"
d="M511,197C511,424,207,412,207,549C207,599,236,626,285,626C346,626,355,571,355,517L502,517C512,668,439,734,292,734C108,734,54,644,54,531C54,316,358,308,358,178C358,129,333,96,282,96C199,96,196,154,196,223L45,223C37,98,72,-12,259,-12C374,-12,511,10,511,197 Z" />
<glyph unicode="&#8220;" horiz-adv-x="444"
d="M395,722L299,722L226,525L360,525L395,722M217,722L121,722L48,525L182,525L217,722 Z" />
<glyph unicode="&#8221;" horiz-adv-x="444"
d="M48,525L144,525L217,722L83,722L48,525M226,525L322,525L395,722L261,722L226,525 Z" />
<glyph unicode="&#8250;" horiz-adv-x="222"
d="M124,464L9,464L95,267L7,75L123,75L215,267L124,464 Z" />

The struct I found in the documentation seemed to be the way to go to instruct how to tell FreeType what to do with a curve, what to do with a bezier, as all the examples assume that you have a 2d array of coordinates, and a simple square-like object.

The glyph data originates from a tool the guys use to construct an article/catalogue layout, which is then exported as an SVG file and distributed with the app. Because they use many different styles, fonts, types and shapes, the SVG contains the multiple fonts used and puts the glyphs of the used characters from that font into it, including the custom shapes they use for different symbols. Once these are out there, its much easier to update the SVG files than to redistribute a download to thousands of customers just to add a font.

Id rather have freetype handle the fonts rather than manually making a bitmap, and then scaling/resizing the image with a traditional image scale (which looks crappy). It would also be much quicker.

Are there any examples to manually building a glyph/character that consists of curves, straights and filled and so forth? If I knew the syntax for how to construct a mixed array of coordinate types to do this, then writing the SVG conversion would be trivial. I had just assumed that people used SVG fonts in freetype commonly, as most of the big libraries do it. Thanks.

Kind Regards,

Andy 'FishGuy876' Kellett
FishGuy876 of Brainstorm < http://brainstorm.untergrund.net >
--

Email: address@hidden
ICQ: 9701389 AOL: FishGuy876 Yahoo: FishGuy876
URL: http://www.cvgm.net - Old/Newskool Computer Music

On 4/8/2010 8:08 AM, Michiel Kamermans wrote:
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






_______________________________________________
Freetype mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/freetype





reply via email to

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