freetype
[Top][All Lists]
Advanced

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

RE: [Freetype] How to draw a bitmap


From: Giuliano Pochini
Subject: RE: [Freetype] How to draw a bitmap
Date: Wed, 12 Jun 2002 10:24:28 +0200 (CEST)

On 12-Jun-2002 §º¥K¤¯ wrote:
> I use ft2 version to get FT_GlyphSlot and use FT_Render_Glyph to get a
> bitmap pointer.
> I can read the bitmap rows,width and pitch.
> It has a buffer data let me to draw it.
> How should I draw the bitmap image.


With something like this:



/*
  FT_Bitmap bm;

  bm.rows=WIDTH;
  bm.width=HEIGHT;
  bm.pitch=HEIGTH;
  bm.buffer=malloc(bm.rows*bm.pitch); memset(bm.buffer, 0, bm.rows*bm.pitch);
  bm.num_grays=256;
  bm.pixel_mode=ft_pixel_mode_grays;

  Print(FTlib, bm, font, str, X, Y);
*/



int Print(FT_Library lib, FT_Bitmap bm, FT_Face font, const char *s, int x, int 
y){
FT_UInt gi;
int bx, by;
int xd, yd;
int n;

  n=0;
  while (*s) {
    gi=FT_Get_Char_Index(font, *s);
    if (FT_Load_Glyph(font, gi, FT_LOAD_DEFAULT))
      return(0);
    if (FT_Render_Glyph(font->glyph, ft_render_mode_normal))
      return(0);
    for (by=0, yd=y-font->glyph->bitmap_top; by<font->glyph->bitmap.rows && 
yd<bm.rows; by++, yd++) {
      for (bx=0, xd=x+font->glyph->bitmap_left; bx<font->glyph->bitmap.width && 
xd<bm.width; bx++, xd++) {
        
*(bm.buffer+bm.pitch*yd+xd)=*(font->glyph->bitmap.buffer+font->glyph->bitmap.pitch*by+bx);
      }
    }
    n++;
    x+=font->glyph->advance.x >> 6;
    y+=font->glyph->advance.y >> 6;
    s++;
  }
  return(n);
}



Bye.




reply via email to

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