[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[ft] Text extent with different renderers
From: |
AlannY |
Subject: |
[ft] Text extent with different renderers |
Date: |
Mon, 27 Apr 2009 12:45:21 +0400 |
User-agent: |
Thunderbird 2.0.0.21 (Windows/20090302) |
Hi there.
I need to get width and height of single character with known font and
size (in my test suite: Arial 12). On Linux, I'm using FreeType and on
Windows I'm using Windows GDI for this.
But, this 2 systems give me 2 different results. For example, in Arial
12px font the character "T" (without quotes) have dimension of 9x15 in
FreeType and 9x18 in GDI.
I think, that I'm doing something wrong with GDI or (!) FreeType. Below
a short test program of fetching character dimension in FreeType and GDI.
Please, help. I want to get equal results or (!) explain me why I can't
get it ;-) Thank you.
==================================================
Example in FreeType:
#define DPI 96
int font_size = 12;
FT_New_Face (freetype_library, "/path/to/Arial.ttf", 0, &face);
FT_Set_Char_Size (face, font_size*64, font_size*64, DPI, DPI);
glyph_index = FT_Get_Char_Index (face, 'T');
FT_Load_Glyph (face, glyph_index, FT_LOAD_DEFAULT);
/* here we get 9x15 */
printf ("%dx%d\n", (int)(face->glyph->metrics.horiAdvance/64),
(int)(face->glyph->metrics.vertAdvance/64));
==================================================
And code on GDI:
int font_size = 12;
hdc = GetDC (NULL);
font = CreateFontW (-(font_size*GetDeviceCaps (hdc, LOGPIXELSY))/72, 0,
0, 0, 0, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_ROMAN, L"Arial");
SelectObject (hdc, font);
/* get text extent */
GetTextExtentPoint32W (hdc, L"T", 1, &size);
/* here we get 9x18 */
wprintf (L"%dx%d\n", size.cx, size.cy);
- [ft] Text extent with different renderers,
AlannY <=