PangoFT2, outline mode



  Hi,

I wanto to use PangoFT2 to get the outlines of glyphs
so that I can send them to a PostScript file for
printing. I know that this is not exactly the ideal
way to print anything, but there is currently no
ideal way so I resort to this one. Now the problem
is that getting the outlines is easy, only I don't
understand how they are scaled. I am using GTK 2.0.4
and Pango 1.0.4, since that is what is shipped with
the newest SuSE 8.1. I am aware that all libraries
used in this context have been updated since then,
but I can only expect my users to update to the 
newest system, not newer then newest. 

What I do is create a PangoContext like this:

 PangoContext *context = pango_ft2_get_context ( 72, 72 );

Various higher resolution just made the numbers
bigger (and the outlines better), but it's ok in
this mail. I then create a layout, assign it some
text, dissect the layout into lines and finally
runs. Then I get the font and the glyphs like this:

 PangoLayoutRun *run = (PangoLayoutRun*) runs_list->data;
 PangoItem *item = run->item;
 PangoGlyphString *glyphs = run->glyphs;
 PangoAnalysis *analysis = &item->analysis;
 PangoFont *font = analysis->font;
 FT_Face ft_face = pango_ft2_font_get_face(font);
            
 int num_glyphs = glyphs->num_glyphs;
 for (int glyph_idx = 0; glyph_idx < num_glyphs; glyph_idx++)
 {
   PangoGlyphGeometry geometry = glyphs->glyphs[glyph_idx].geometry;
   int pos_x = xx + geometry.x_offset;
   int pos_y = yy - geometry.y_offset;
   xx += geometry.width;

and then finally draw the glyph by calling a subroutines
which in turn calls FT_Outline_Decompose()
                
   draw_bezier_outline( NULL, ft_face,
    (FT_UInt)(glyphs->glyphs[glyph_idx].glyph), ...
  }

The glyph itself is loaded with the FT_LOAD_NO_BITMAP
parameter so that I always get outlines, not bitmaps.

In the above code for a given standard font and the
letter '-' (chosen for simplicity) the geometry.width
parameter is set to 8192, which is just 8pt * PANGO_SCALE.
This number will grow with higher resolutions, of course.

My problem is that the coordinates of the outlines of the
letter '-' do not range from 0 to 8192, rather they
range from 64 to 448. Since the glyph has some space 
around it, the ratio between the geometry.width to the
width of the outline is around 8192/480 = ~17 Since I
need to have the exact calculation formula so that
I can correctly move the "cursor" to the next glyph,
I wonder where the ~17 comes from. I read that FT renders
glyph outlines scaled 26.6 times, but that didn't lead
me to the right conclusion either.
Just for further investigation, I set the dpi in the
FT2 to 600, which resulted in 68608/4000 = ~17, so
there seems to be a rule. 

Where does the scale factor of 17 come from?

  Thanks and sorry for the longish mail,

     Robert

-- 
Robert Roebling, MD <robert roebling medizin uni-ulm de>



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