freetype
[Top][All Lists]
Advanced

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

RE: [Freetype] aligning glyphs from different fonts


From: Turner David
Subject: RE: [Freetype] aligning glyphs from different fonts
Date: Mon, 23 Feb 2004 17:01:20 +0100

Hello,

> I want to draw glyphs from several different font faces to a bitmap
> image (sample bitmap rendering code below).  I pass in x and y to the
> function code below to place the glyph in the bitmap.  I would like
> the fonts to have a common vertical origin, so that glyphs from one
> face appear to be on the same line as glyphs from the other.
> 

You should basically use an algorithm like the following:

  let Y be the top row of your target bitmap. growing Y numbers
  correspond to downwards movement.

  for each line of text, you need to:

    - compute the maximum ascender, descender & line_gap for all
      font sizes used in the line. (note: the maximum descender
      in absolute value !).

    - Y+max_ascender corresponds to the baseline you'll need to
      use

    - the "top" of the next line is taken by adding max_descender+max_linegap,
      i.e.:

     Y = 0
     foreach line 
     {
        ... compute max_ascent, max_descent, max_linegap

        baseline = Y + max_ascent

        ... draw glyphs

        Y = baseline + max_descent + max_linegap
     }

This should be sufficient. Note that things get slightly more
complex if you want to perform device-independent text layout.
I won't help you there.

Note also that the reason you need to use the max_linegap is
because you don't know what max font sizes will be used on the
next line.

Hope this helps,

- David Turner
- The FreeType Project  (www.freetype.org)



> Right now I am working with two font files (ftdump info below).  The
> font files share many of the same properties: type, direction, and EM
> size.  The differ, however, in their ascender, descender and
> text_height, mainly in their descender and text_height.  The glyphs
> from the font with the large height and low descender are appearing
> too low in the rendered bitmap with respect to the glyphs from the
> other font.  Currently, I'm passing in a fixed y and incrementing x by
> advance.x; I assume I need to modify y by one of the global font
> metrics.
> 
> Pointers to docs or examples appreciated.
> 
> Thanks,
> John Hunter
> 
> 
> freetype-2.1.3
> 
> sample code
>   error = FT_Glyph_To_Bitmap(&self->glyphs[glyph->glyph_num],
>                            FT_RENDER_MODE_NORMAL,
>                            0,  //no additional translation
>                            0  //don't destroy image
>                            );
> 
>   //handle error
>   FT_BitmapGlyph bitmap = 
> (FT_BitmapGlyph)self->glyphs[glyph->glyph_num];
> 
>   draw_bitmap( &bitmap->bitmap, 
>              &self->image,
>              x + bitmap->left,
>              y-bitmap->top);
> 
> 
> ftdump
> hunter:~/src/ft2demos-2.1.3/bin> ./ftdump ~/src/ttf/cmmi10.ttf
> There is 1 face in this file.
>  
> ----- Face number: 0 -----
>  
> font name entries
>    family:     cmmi10
>    style:      Regular
>    postscript: Cmmi10
>  
> font type entries
>    FreeType driver: truetype
>    sfnt wrapped:    yes
>    type:            scalable
>    direction:       horizontal
>    fixed width:     no
>    glyph names:     yes
>    EM size:         2048
>    global BBox:     (-70,-512):(2146,1536)
>    ascent:          1444
>    descent:         -440
>    text height:     2167
>  
> charmaps
>    0: platform: 1, encoding: 0
>    1: platform: 3, encoding: 1
> hunter:~/src/ft2demos-2.1.3/bin> ./ftdump ~/src/ttf/cmex10.ttf
> There is 1 face in this file.
>  
> ----- Face number: 0 -----
>  
> font name entries
>    family:     cmex10
>    style:      Regular
>    postscript: Cmex10
>  
> font type entries
>    FreeType driver: truetype
>    sfnt wrapped:    yes
>    type:            scalable
>    direction:       horizontal
>    fixed width:     no
>    glyph names:     yes
>    EM size:         2048
>    global BBox:     (-49,-6062):(2978,1581)
>    ascent:          1581
>    descent:         -6082
>    text height:     8812
>  
> charmaps
>    0: platform: 1, encoding: 0
>    1: platform: 3, encoding: 1
> hunter:~/src/ft2demos-2.1.3/bin>
> 
> _______________________________________________
> Freetype mailing list
> address@hidden
> http://www.freetype.org/mailman/listinfo/freetype
> 

--
This message and any attachments (the "message") is intended solely for the
addressees and is confidential. If you receive this message in error, please
delete it and immediately notify the sender.
Any use not in accordance with its purpose, any dissemination or disclosure,
either whole or partial, is prohibited except formal approval.
The E-Mail transmission can not guarantee the integrity of this message.
NDS TECHNOLOGIES FRANCE will not therefore be liable for the message if 
modified.





reply via email to

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