aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--generic/Image.c39
1 files changed, 23 insertions, 16 deletions
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;
}