[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[ft] Total width of text
From: |
Leonardo M . Ramé |
Subject: |
[ft] Total width of text |
Date: |
Wed, 13 Apr 2011 12:23:19 -0300 |
User-agent: |
Mutt/1.5.21+22 (8d0281f79b21) (2010-12-30) |
Hi, I'm trying to place text over a bitmap using the function below.
If you take a look at the function, there's a "baseline" variable, in
charge of adjusting the top position of the character bitmap. If I don't
do this, all character ar aligned to the top "pen_y" point. I don't know
if this is the recommended way to align text. Please tell me if you know
a better way.
Also, I want to create a box filled in a color between the image and the
text. For example, the image in grayscale, then a red box with black text.
My question is, how can I get the measures (in pixels) of the box
containing all the text, not just each character.
+---------------------+
| |
| <---------| This is the image in background layer
| |
| +-----------------+ | | I want to know the width
| | This is my text | | <---| and heigth of the box
| +-----------------+ | | containing the text.
| |
+---------------------+
Here's the code I'm using:
FT_Set_Pixel_Sizes(face, 0, lFontHeight);
FT_GlyphSlot slot = face->glyph;
int pen_x, pen_y, n, baseline, original_y;
original_y = 0.02 * ARows * (ACols / ARows);
pen_x = 0.02 * ACols;
pen_y = original_y;
int lColor;
unsigned long lPos;
for ( n = 0; n < text.length(); n++ )
{
/* load glyph image into the slot (erase previous one) */
error = FT_Load_Char( face, text[n], FT_LOAD_RENDER);
if ( error )
continue; /* ignore errors */
if(text[n] == '\n')
{
pen_x = 0.02 * ACols;
pen_y += lFontHeight;
continue;
}
baseline = (pen_y - slot->bitmap_top) + (original_y);
/* now, draw to our target surface */
for(unsigned long x = 0; x < ACols; x++)
for(unsigned long y = 0; y < ARows; y++)
{
if((x >= 0 && x < slot->bitmap.width) && (y >= 0 && y <
slot->bitmap.rows))
{
lPos = (x + pen_x) + ((y + baseline) * ACols);
lColor = slot->bitmap.buffer[x + y * slot->bitmap.width];
if(lColor != 0)
APixelData[lPos] = 10000;
else
APixelData[lPos] = 65535;
}
else
if((x >=0 && x < 400) && (y >= 0 && y < lFontHeight ))
{
lPos = (x + pen_x) + ((y + baseline) * ACols);
if(((y + baseline) <= (pen_y + slot->bitmap.rows)))
APixelData[lPos] = 5535;
}
}
/* increment pen position */
pen_x += slot->advance.x >> 6;
}
Thanks in advance,
--
Leonardo M. Ramé
Medical IT - Griensu S.A.
Av. Colón 636 - Piso 8 Of. A
X5000EPT -- Córdoba
Tel.: +54(351)4246924 +54(351)4247788 +54(351)4247979 int. 19
Cel.: +54(351)156629292
- [ft] Total width of text,
Leonardo M . Ramé <=