freetype
[Top][All Lists]
Advanced

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

Re: How can I detect start of polygon among outlines?


From: David Turner
Subject: Re: How can I detect start of polygon among outlines?
Date: Mon, 03 Jul 2000 09:31:10 +0200

Hi Ang,

> 
> Hi FreeTypers,
> 
> I've wrote something to convert the TT font outlines into points for
> vectorized drawing using Freetype2, now I would like to perform
> tessellation on these points. To do tessellation I need to identify
> the start of a polygon. Currently I assume each Move_To starts a
> contour. If a contour goes in clockwise direction, it starts a
> polygon. If the next contour goes in anti-clockwise direction, it
> forms a hole inside the current polygon and so on. For example:
> 
> 'C' is made up of one polygon with one contour.
> 'A' is made up of one polygon with two contours.
> 'B' is made up of one polygon with three contours.
> 'i' is made up of two polygon, each with one contour.
> '%' is made up of one polygon with one contour, and
>     two polygons with two contours each.
> 
> Is there a way to detect the start of a polygon easily/efficiently
> instead of detecting clockwise vs anti-clockwise direction of the
> contour points?
> 
First of all, the clockwise / anti-clockwise direction trick doesn't
work with all fonts. TrueType and Type 1 fonts use reverse conventions
for the inside/outside rotation. There exist fonts that do not respect
the convention of their respective format. You may also end up with
individual glyphs that are reversed compared to the rest of the same
face (usually they are "mirrored" version of another glyph, through
compositing). In theory, a badly designed fonts could even have a
glyph with two contours used with opposite conventions !!

If you want to be correct all the time, you first need to determine
the convention used in a specific glyph. See the experimental code
(#if 0) in "src/base/ftglyph.c" named "Get_Direction" or something
like that. It computes the convention by looking at the points on
the edges of the bounding box..

Then, I don't think there is any easy way if you want to be correct
100% of the time. You can however find an approximation that will work
well with nearly all glyphs in fonts, given that they're not generally
as "abstract" as shapes..

For example, you can seek if a contour is contained entirely within
another contour's bbox. If this is the case, and their conventions
are opposite, you can pretty be sure to have a "hole" here..

That's all I can say for now, I'd appreciate any comment on this
topic, by the way..

Hope this helps,

- David

> Regards,
> Ang Bodhi



reply via email to

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