freetype-devel
[Top][All Lists]
Advanced

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

Re: [ft-devel] How to get the position of a glyph without rendering it


From: mpsuzuki
Subject: Re: [ft-devel] How to get the position of a glyph without rendering it
Date: Thu, 9 Dec 2010 17:27:37 +0900

Dear Albert,

Again I'm quite sorry for lated response about my homework.

I did a small experiment to calculate the 'transformed'
metric before invoking FT_Render_Glyph(), and the result
was similar to the metric calculated by FT_Render_Glyph().

The modification to your sample code is like this.
x3, y3, w3, h3 are calculated before FT_Render_Glyph(),
by using transformed outline. The calculation is roughly
copied from the internal function ft_smooth_render_generic().
The result is almost same with the metric calculated by
FT_Render_Glyph(). Is this what you wanted to do?

-1 19 19
19 20 20
19 19 19
19 19 19

Regards,
mpsuzuki

--- acid-main.cpp.orig  2010-12-05 03:20:30.748926821 +0900
+++ acid-main.cpp       2010-12-09 17:21:41.077465614 +0900
@@ -5,6 +5,12 @@
 #include FT_SIZES_H
 #include FT_GLYPH_H
 
+
+#define FT_PIX_FLOOR( x )     ( (x) & ~63 )
+#define FT_PIX_ROUND( x )     FT_PIX_FLOOR( (x) + 32 )
+#define FT_PIX_CEIL( x )      FT_PIX_FLOOR( (x) + 63 )
+
+
 static void eerror(const char *msg, FT_Error e)
 {
        printf("%s 0x%0x\n", msg, e);
@@ -54,6 +59,32 @@
        int w = glyphMetrics->width / 64.0;
        int h = glyphMetrics->height / 64.0;
 
+        int x3, y3, w3, h3;
+        {
+                FT_BBox  cbox;
+                FT_Outline_Get_CBox(&face->glyph->outline, &cbox);
+                cbox.xMin = FT_PIX_FLOOR( cbox.xMin );
+                cbox.yMin = FT_PIX_FLOOR( cbox.yMin );
+                cbox.xMax = FT_PIX_CEIL( cbox.xMax );
+                cbox.yMax = FT_PIX_CEIL( cbox.yMax );
+
+                FT_UInt width  = (FT_UInt)( ( cbox.xMax - cbox.xMin ) >> 6 );
+                FT_UInt height = (FT_UInt)( ( cbox.yMax - cbox.yMin ) >> 6 );
+                /* XXX: subpixel rendering requires additional works for 
width/height */
+
+                FT_Int  x_shift = (FT_Int) cbox.xMin;
+                FT_Int  y_shift = (FT_Int) cbox.yMin;
+                FT_Int  x_left  = (FT_Int)( cbox.xMin >> 6 );
+                FT_Int  y_top   = (FT_Int)( cbox.yMax >> 6 );
+
+                FT_Int  bitmap_left = (FT_Int)x_left;
+                FT_Int  bitmap_top  = (FT_Int)y_top;
+                x3 = -bitmap_left;
+                y3 =  bitmap_top;
+                w3 =  width;
+                h3 =  height;
+        }
+
        if (e = FT_Render_Glyph(slot, ft_render_mode_normal))
                eerror("5", e);
 
@@ -62,8 +93,8 @@
        int w2 = slot->bitmap.width;
        int h2 = slot->bitmap.rows;
        
-       printf("%d %d\n", x, x2);
-       printf("%d %d\n", y, y2);
-       printf("%d %d\n", w, w2);
-       printf("%d %d\n", h, h2);
+       printf("%d %d %d\n", x, x2, x3);
+       printf("%d %d %d\n", y, y2, y3);
+       printf("%d %d %d\n", w, w2, w3);
+       printf("%d %d %d\n", h, h2, h3);
 }





On Sun, 5 Dec 2010 04:32:46 +0900
address@hidden wrote:

>Dear Albert,
>
>I'm quite sorry that I slipped to reply to this issue.
>
>Reading your sample, I understand your question is asking
>why face->glyph->metrics and face->glyph->bitmap{_left,top},
>{.width,.rows} are inconsistent after FT_Set_Transform().
>
>http://freetype.sourceforge.net/freetype2/docs/reference/ft2-base_interface.html#FT_Set_Transform
>
>has a note:
>       Note that this also transforms the `face.glyph.advance' field,
>       but not the values in `face.glyph.metrics'.
>
>So I think this is the designed behaviour of FreeType2, but
>yet I don't have good answer how to solve your problem.
>Could you give me more time to consider about this issue?
>
>Regards,
>mpsuzuki
>
>On Sat, 4 Dec 2010 18:07:36 +0000
>Albert Astals Cid <address@hidden> wrote:
>
>>A Dimecres, 20 d'octubre de 2010, Albert Astals Cid va escriure:
>>> > Hi,
>>> > 
>>> > On Wed, 20 Oct 2010 01:29:29 +0100
>>> > 
>>> > Albert Astals Cid <address@hidden> wrote:
>>> > >That code works fine for most of the fonts i tried but now i have
>>> > >encountered a case in which
>>> > >
>>> > > round(-glyphMetrics->horiBearingX / 64.0);
>>> > >
>>> > >is -2 and
>>> > >
>>> > > -slot->bitmap_left;
>>> > >
>>> > >is 26
>>> > 
>>> > Could you tell me any sample fonts to reproduce
>>> > this issue?
>>> > 
>>> > I think, the metric infos available before rendering
>>> > come from metric tables, and the metric infos available
>>> > after the rendering come from glyf table, so there
>>> > can be incompatible values (rather, broken font may
>>> > have different values).
>>> 
>>> Here some sample code and the font.
>>
>>Did you have any change to look at my code/font?
>>
>>Thanks,
>>  Albert
>>
>>> 
>>> Any help more than welcome,
>>>   Albert
>>> 
>>> > Regards,
>>> > mpsuzuki
>
>_______________________________________________
>Freetype-devel mailing list
>address@hidden
>http://lists.nongnu.org/mailman/listinfo/freetype-devel

Attachment: mps-calc-transformed-metric-before-rendering.diff
Description: Text Data


reply via email to

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