freetype
[Top][All Lists]
Advanced

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

Re: [Freetype] freetype newbie


From: Olivier Couet
Subject: Re: [Freetype] freetype newbie
Date: Thu, 15 Aug 2002 09:40:30 +0200 (CEST)

 Hi Graham,

 I just went through the same sort of problems you encounter now. The doc
is helpful but a very simple example is missing. The standard demo
programs work well (so like that we know the the FT_ library is working,
after having fight with for some times we can have doubts :-)), but they
are a bit too complex to be use as starting point to write an application.
I finally succeed to render some text thanks to people (Michael, and
Derek) in this mailing list. 

So here are the point I encountered difficulties with. As you do not use
AA I suppose you render your glyph with something like:

FT_GlyphSlot slot = face->glyph;
error = FT_Get_Glyph ( slot, &glyph );
FT_Glyph_To_Bitmap( &glyph, ft_render_mode_mono, 0, 1 );


Then the important values to render it are:

FT_BitmapGlyph bitmap = (FT_BitmapGlyph)glyph;
FT_Bitmap*     source = &bitmap->bitmap;

Width   = source->width;
Height  = source->rows;
Pitch   = source->pitch;
Bitmap  = source->buffer;
Descent = int(TTCeil(slot->metrics.height - slot->metrics.horiBearingY) >> 6);
Ascent  = source->rows - c->fDescent;
Xoff    = int(slot->metrics.horiBearingX >> 6);


Then the rendering in the X11 bitmap:

char d = 0, *s = Bitmap;
char* row=s;
for (int y = 0; y < (int)Height; y++) {
int n = 0;
s = row;
for (int x = 0; x < (int)Width; x++) {
   if (n == 0) d = *s++;
   if (TESTBIT(d,7-n))
      XPutPixel(xim, bx + c->fXoff + x, by - c->fAscent + y, fore);
      if (++n == (int) 8) n = 0;
   }
   row += Pitch;
}


I work in C++. I have also:

inline long TTCeil(Long_t x) { return (x + 63) & -64; }

and

#define BIT(n)       (1 << (n))
#define TESTBIT(n,i) ((bool)(((n) & BIT(i)) != 0))

I hope that will help you and that I have not forget anything.

 Cheers,        Olivier

--
Org:    CERN - European Laboratory for Particle Physics.
Mail:   1211 Geneve 23 - Switzerland                                    
E-Mail: address@hidden                      Phone: +41 22 7676522
WWW:    http://cern.ch/Olivier.Couet/              Fax:   +41 22 7677155

On Wed, 14 Aug 2002 address@hidden wrote:

> 
> Hi!  I'm another FreeType newbie.  I've looked at the tutorials
> (which seem to be written for an older version of FT.. they don't
> compile!) and I've managed to write a small program that draws one
> character to a bitmap.  I use my own code to save the bitmap to a
> file.
> 
> Anyways, I'm pretty sure I'm doing it wrong.  I'm using monochrome
> rendering (no AA, 1 bit / pixel).  It only works when my buffer and
> device size is square, and my font height = font width.  If I try to
> use a non-square buffer, or if I try to use font height != font
> width, I only get part of the character rendered, like it's being
> clipped wrong or something.
> 
> So, the million-dollar question:  Is there a download somewhere for a
> relatively short .c file containing a main() function that renders a
> simple piece of text to a monochrome bitmap, and nothing more?  I
> mean a file I can just download and compile, without fiddling.  I'm
> surprised I haven't been able to find one.  It took hours just for me
> to figure out how to do it incorrectly :)  Please, somebody, hook me
> up with such a main().  I would be super-greatful.
> 
> - Graham Fyffe
> 
> 
> 
> _______________________________________________
> Freetype mailing list
> address@hidden
> http://www.freetype.org/mailman/listinfo/freetype
> 




reply via email to

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