[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] BUG: Inconsistent font behavior between Windows and Linux
Attached is a C version of font_test.py. It takes a font size as its
only argument. Running the program for both pitch 21 and 210 I get the
same results as I get for font_test.py.
Lenard
Lenard Lindstrom wrote:
I can't account for why the numbers match at a pitch of 210, but not
21. I did find the place in SDL_ttf where the dpi is set to the
FreeType default of 72. And the post to the FreeType mailing list I
referred to earlier,
http://lists.nongnu.org/archive/html/freetype-devel/2002-08/msg00020.html,
does imply that font size, in pixels, is affected by some operating
system provided value. But then this could involve values passed to
FreeType or FreeType as a display driver. On Windows there are no
explicit Windows api calls, just C library calls. So I don't know what
I imply any more. Maybe a C only version of font_test.py will clear
some things up.
Lenard
Brian Fisher wrote:
Lenard, are you saying you think it still may be a dpi problem?
cause I think if dpi was the problem in this case, the discrepancy
would scale with font size. But as there is no discrepancy between
the platforms when the font size is 210 (i.e. charlies gentoo matches
your windows box), it seems to me that dpi (or any font scaling
really) is not different, and therefore not the cause here
I really think SDL_ttf is fixing the freetype scaling so it doesn't
vary with platform. It would just make sense.
did I misunderstand or am I missing something there?
On Thu, Sep 4, 2008 at 1:38 PM, Lenard Lindstrom <len-l@xxxxxxxxx
<mailto:len-l@xxxxxxxxx>> wrote:
As for display point size, that may be the case with Windows, but
what about Unix.
#include "SDL/SDL.h"
#include "SDL/SDL_ttf.h"
#include <stdio.h>
#include <stdlib.h>
static int err_tst(int result)
{
if (result != 0)
{
printf("*** %s\n", SDL_GetError());
return 1;
}
return 0;
}
static void print_size(TTF_Font* font, char *text)
{
int w = -1, h = -1;
TTF_SizeText(font, text, &w, &h);
printf("(%i, %i)\n", w, h);
}
static void print_metrics(TTF_Font* font, char *text)
{
int minx = -1, maxx = -1, miny = -1, maxy = -1, advance = -1;
int add_comma = 0;
printf("[");
while (*text != '\0')
{
if (add_comma)
{
printf(", ");
}
add_comma = 1;
if (TTF_GlyphMetrics(font, (unsigned short) *text, &minx, &maxx,
&miny, &maxy, &advance) == -1)
{
printf("None");
}
else
{
printf("(%i, %i, %i, %i, %i)", minx, maxx, miny, maxy, advance);
}
++text;
}
printf("]\n");
}
static int print_render(TTF_Font* font, char* astring, unsigned char rgba[3])
{
SDL_Surface* surf = 0;
const char *type;
SDL_Color foreg;
foreg.r = rgba[0];
foreg.g = rgba[1];
foreg.b = rgba[2];
surf = TTF_RenderText_Blended(font, astring, foreg);
if (surf == 0)
{
return 1;
}
type = (surf->flags & SDL_HWSURFACE) ? "HW" : "SW";
printf("<Surface(%dx%dx%d %s)>\n", surf->w, surf->h,
surf->format->BitsPerPixel, type);
SDL_FreeSurface(surf);
return 0;
}
int main(int argc, char *argv[])
{
int fontsize = atoi(argv[1]);
TTF_Font* f = 0;
int retcode = 1;
unsigned char black[] = {0, 0, 0};
int w = -1, h = -1;
// pygame.font.init()
if (err_tst(TTF_Init()))
{
goto quit_0;
}
// f = pygame.font.Font("acknowtt.ttf", 21)
if (fontsize <= 1)
{
fontsize = 1;
}
f = TTF_OpenFont("acknowtt.ttf", fontsize);
if (err_tst(f == 0))
{
goto quit_1;
}
// print f.size("6")
print_size(f, "6");
// print f.size("7")
print_size(f, "7");
// print
printf("\n");
// print f.render("66", True, (0,0,0,255))
if (print_render(f, "66", black))
{
goto quit_2;
}
// print f.render("67", True, (0,0,0,255))
if (print_render(f, "67", black))
{
goto quit_2;
}
// print
printf("\n");
// print f.metrics("66")
print_metrics(f, "66");
// print f.metrics("67")
print_metrics(f, "67");
retcode = 0;
quit_2:
TTF_CloseFont(f);
quit_1:
TTF_Quit();
quit_0:
return retcode;
}