aboutsummaryrefslogtreecommitdiff
path: root/generic/Image.c
diff options
context:
space:
mode:
authorlecoanet2006-10-17 11:51:47 +0000
committerlecoanet2006-10-17 11:51:47 +0000
commit4a2766f42d4c9367c113b4347d71ce12a3f9653e (patch)
tree45d493f16d3d393e12da4cd0b0b3ba6140a56644 /generic/Image.c
parent8242e7e37564f1e2fd59d6f54a1e84197c9ffe69 (diff)
downloadtkzinc-4a2766f42d4c9367c113b4347d71ce12a3f9653e.zip
tkzinc-4a2766f42d4c9367c113b4347d71ce12a3f9653e.tar.gz
tkzinc-4a2766f42d4c9367c113b4347d71ce12a3f9653e.tar.bz2
tkzinc-4a2766f42d4c9367c113b4347d71ce12a3f9653e.tar.xz
Make use of the ZPixmap format instead of XYPixmap when dealing
with X Images. Ported to Mac Os (without X11).
Diffstat (limited to 'generic/Image.c')
-rw-r--r--generic/Image.c43
1 files changed, 32 insertions, 11 deletions
diff --git a/generic/Image.c b/generic/Image.c
index 823d49c..2c7244d 100644
--- a/generic/Image.c
+++ b/generic/Image.c
@@ -262,7 +262,7 @@ ZnGetImage(ZnWInfo *wi,
Tk_SizeOfBitmap(wi->dpy, pmap, &bits->width, &bits->height);
mask = XGetImage(wi->dpy, pmap, 0, 0, (unsigned int) bits->width,
- (unsigned int) bits->height, 1L, XYPixmap);
+ (unsigned int) bits->height, 1L, ZPixmap);
bits->depth = 1;
bits->rowstride = mask->bytes_per_line;
bits->bpixels = ZnMalloc((unsigned int) (bits->height * bits->rowstride));
@@ -1135,6 +1135,8 @@ SuckGlyphsFromServer(ZnWInfo *wi,
{
Pixmap offscreen = 0;
XImage *image = NULL;
+ XColor *white, *black;
+ unsigned long pixel;
GC xgc = 0;
unsigned int height, length, pixwidth;
unsigned int i, j, use_max_width;
@@ -1225,6 +1227,14 @@ SuckGlyphsFromServer(ZnWInfo *wi,
tgvip++;
}
+ //
+ // If max_char_width is still not known, perhaps because of a bogus
+ // font with character width not documented, set the width to an
+ // arbitrary value.
+ if (!txf->max_char_width) {
+ txf->max_char_width = 1;
+ }
+
if (use_max_width) {
tex_width = ce->max_tex_size;
}
@@ -1251,7 +1261,9 @@ SuckGlyphsFromServer(ZnWInfo *wi,
if (!txf->teximage) {
goto FreeAndReturn;
}
+#ifndef MAC_OSX_TK
memset(txf->teximage, 0, tex_height * tex_width);
+#endif
maxSpanLength = (txf->max_char_width + 7) / 8;
/* Be careful determining the width of the pixmap; the X protocol allows
@@ -1263,13 +1275,15 @@ SuckGlyphsFromServer(ZnWInfo *wi,
}
pixwidth = glyphsPerGrab * 8 * maxSpanLength;
offscreen = Tk_GetPixmap(wi->dpy, RootWindowOfScreen(wi->screen),
- (int) pixwidth, (int) height, 1);
+ (int) pixwidth, (int) height, Tk_Depth(wi->win));
xgc = XCreateGC(wi->dpy, offscreen, 0, NULL);
- XSetForeground(wi->dpy, xgc, WhitePixelOfScreen(wi->screen));
- XSetBackground(wi->dpy, xgc, WhitePixelOfScreen(wi->screen));
+ white = Tk_GetColor(wi->interp, wi->win, "white");
+ black = Tk_GetColor(wi->interp, wi->win, "black");
+ XSetForeground(wi->dpy, xgc, white->pixel);
+ XSetBackground(wi->dpy, xgc, white->pixel);
XFillRectangle(wi->dpy, offscreen, xgc, 0, 0, pixwidth, height);
- XSetForeground(wi->dpy, xgc, BlackPixelOfScreen(wi->screen));
+ XSetForeground(wi->dpy, xgc, black->pixel);
XSetFont(wi->dpy, xgc, Tk_FontId(txf->tkfont));
numToGrab = 0;
@@ -1285,12 +1299,12 @@ SuckGlyphsFromServer(ZnWInfo *wi,
if (txf->glyph[i].width != 0) {
Tk_DrawChars(wi->dpy, offscreen, xgc, txf->tkfont, cur, next - cur,
(int) (8*maxSpanLength*numToGrab), txf->ascent);
- grabList[numToGrab] = i;
+ grabList[numToGrab] = i;
numToGrab++;
}
if ((numToGrab >= glyphsPerGrab) || (i == txf->num_glyphs - 1)) {
- image = XGetImage(wi->dpy, offscreen, 0, 0, pixwidth, height, 1, XYPixmap);
+ image = XGetImage(wi->dpy, offscreen, 0, 0, pixwidth, height, ~0, ZPixmap);
for (j = 0; j < numToGrab; j++) {
glyph = grabList[j];
@@ -1310,9 +1324,14 @@ SuckGlyphsFromServer(ZnWInfo *wi,
each pixel from the image which is not that efficient. We
could either do tighter packing in the pixmap or more
efficient extraction from the image. Oh well. */
- if (XGetPixel(image, (int) (j*maxSpanLength*8) + x, y) == BlackPixelOfScreen(wi->screen)) {
+ pixel = XGetPixel(image, (int) (j*maxSpanLength*8) + x, y);
+#ifdef MAC_OSX_TK
+ *to = 255 - (pixel & 0xFF);
+#else
+ if (pixel == black->pixel) {
*to = 255;
- }
+ }
+#endif
}
to += tex_width - width;
}
@@ -1322,10 +1341,10 @@ SuckGlyphsFromServer(ZnWInfo *wi,
numToGrab = 0;
/* do we need to clear the offscreen pixmap to get more? */
if (i < txf->num_glyphs - 1) {
- XSetForeground(wi->dpy, xgc, WhitePixelOfScreen(wi->screen));
+ XSetForeground(wi->dpy, xgc, white->pixel);
XFillRectangle(wi->dpy, offscreen, xgc, 0, 0,
8 * maxSpanLength * glyphsPerGrab, height);
- XSetForeground(wi->dpy, xgc, BlackPixelOfScreen(wi->screen));
+ XSetForeground(wi->dpy, xgc, black->pixel);
}
}
@@ -1333,6 +1352,8 @@ SuckGlyphsFromServer(ZnWInfo *wi,
i++;
}
+ Tk_FreeColor(black);
+ Tk_FreeColor(white);
XFreeGC(wi->dpy, xgc);
Tk_FreePixmap(wi->dpy, offscreen);
return;