From e2562cab66633a4ad7631286b4bb711495acb9d3 Mon Sep 17 00:00:00 2001 From: lecoanet Date: Fri, 16 May 2003 14:08:24 +0000 Subject: * Fixed a bug on MAX_CHAR preventing display of accented letters (the most useful ones. * (ZnImageTex): Alpha can be safely (?) loaded both for perl/tk and tk. This is valid only under GL. * (SuckGlyphsFromServer): Trapped a potential problem with some fonts reporting zero width. Improved error report. The maximum width was computed on M and W. If those characters were missing, a zero pixmap allocation occured. Now the max width is computed on the real characters. --- generic/Image.c | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) (limited to 'generic/Image.c') diff --git a/generic/Image.c b/generic/Image.c index 87a9456..e15d2d4 100644 --- a/generic/Image.c +++ b/generic/Image.c @@ -635,11 +635,7 @@ ZnImageTex(ZnImage image, *bp2++ = obptr[0]; /* r */ *bp2++ = obptr[green_off]; /* g */ *bp2++ = obptr[blue_off]; /* b */ -#ifdef PTK *bp2++ = obptr[alpha_off]; /* alpha */ -#else - *bp2++ = 255; -#endif obptr += block.pixelSize; } /*for (x = width; x < t_width; x++) { @@ -693,13 +689,13 @@ ZnImageTex(ZnImage image, #ifdef GL -/* Copyright (c) Mark J. Kilgard, 1997. */ +/* This code is adapted from a work Copyright (c) Mark J. Kilgard, 1997. */ /* This program is freely distributable without licensing fees and is provided without guarantee or warrantee expressed or implied. This program is -not- in the public domain. */ -#define MAX_CHAR (256-32-1) +#define MAX_CHAR 255 #define MIN_CHAR 32 #define MAX_GLYPHS_PER_GRAB 256 @@ -793,7 +789,7 @@ getMetric(FontInfoPtr font, tgi->yoffset = 0; } tgi->dummy = 0; - /* printf("\'%c\' %d\n", c, glyph->advance);*/ + /*printf("\'%c\' %X %d\n", c, c, glyph->advance);*/ tgi->advance = glyph->advance; } @@ -863,11 +859,12 @@ SuckGlyphsFromServer(ZnWInfo *wi, unsigned int numToGrab, thisglyph; FontInfoPtr myfontinfo = NULL; Tk_FontMetrics fm; - + Tk_GetFontMetrics(font, &fm); num_chars = (MAX_CHAR-MIN_CHAR)+1; myfontinfo = ZnMalloc(sizeof(FontInfo) + num_chars * sizeof(PerGlyphInfo)); if (!myfontinfo) { + ZnWarning("Out of memory, "); return NULL; } @@ -878,15 +875,23 @@ SuckGlyphsFromServer(ZnWInfo *wi, myfontinfo->descent = fm.descent; /* - * Try to guess a good approximation for the largest character - * in the font. This guess may be quite wrong for symbol fonts - * and for non european languages. + * Compute the max character size is the font. This may be + * a bit heavy hammer style but it avoid guessing on characters + * not available in the font. */ - *str = 'W'; - Tk_MeasureChars(font, str, 1, 0, TK_AT_LEAST_ONE, &width); - *str = 'M'; - Tk_MeasureChars(font, str, 1, 0, TK_AT_LEAST_ONE, &length); - width = MAX(width, length); + width = 0; + for (i = 0; i < myfontinfo->num_glyphs; i++) { + *str = i + myfontinfo->min_char; + Tk_MeasureChars(font, str, 1, 0, TK_AT_LEAST_ONE, &length); + width = MAX(width, length); + } + if (width == 0) { + /* + * Something weird with the font, abort! + */ + ZnWarning("NULL character width, "); + goto FreeFontInfoAndReturn; + } height = myfontinfo->ascent + myfontinfo->descent; maxSpanLength = (width + 7) / 8; @@ -936,6 +941,7 @@ SuckGlyphsFromServer(ZnWInfo *wi, spanLength = (charWidth + 7) / 8; bitmapData = ZnMalloc(height * spanLength * sizeof(char)); if (bitmapData == NULL) { + ZnWarning("Out of memory, "); goto FreeFontAndReturn; } memset(bitmapData, 0, height * spanLength * sizeof(char)); @@ -981,6 +987,7 @@ SuckGlyphsFromServer(ZnWInfo *wi, if (myfontinfo->glyph[i].bitmap) ZnFree(myfontinfo->glyph[i].bitmap); } + FreeFontInfoAndReturn: ZnFree(myfontinfo); return NULL; } -- cgit v1.1