+ /* If this glyph is white space, return -1. */
+ if (flag == 0) return -1;
+
+ return consumed;
+}
+
+static
+cache_bitmap*
+get_bitmap_with_cache(bdffont *fontp, int index)
+{
+ int bitmap_size, bitmap_real_size;
+ font_char *pch;
+ cache_bitmap* pcb;
+ unsigned char *pbmp;
+ glyph_struct glyph;
+
+ pch = get_cached_font_char(fontp, index);
+ if (pch)
+ {
+ pcb = pch->pcbmp;
+ if (pcb) return pcb;
+ }
+
+ bitmap_size = ((fontp->urx - fontp->llx) / 8 + 3) * (fontp->ury - fontp->lly)
+ + 256;
+ glyph.bitmap = (unsigned char*) alloca(sizeof(unsigned char) * bitmap_size);
+
+ bitmap_real_size = w32_get_bdf_glyph(fontp, index, bitmap_size, &glyph);
+
+ if (bitmap_real_size == 0)
+ return NULL;
+
+ pch = get_cached_font_char(fontp, index);
+ if (!pch) return NULL;
+
+ if (bitmap_real_size > 0)
+ {
+ pbmp = (unsigned char*) HeapAlloc(hbdf_bmp_heap, 0,
+ bitmap_real_size);
+ if (!pbmp) return NULL;
+ memcpy(pbmp, glyph.bitmap, bitmap_real_size);
+ }
+ else
+ pbmp = NULL; /* white space character */
+
+ pcb = pcached_bitmap_latest;
+ if (pcb->psrc)
+ clear_cached_bitmap_slots();
+
+ pcb->psrc = pch;
+ pcb->metric = glyph.metric;
+ pcb->pbmp = pbmp;
+ pcb->bitmap_size = glyph.bitmap_size;
+ pcb->row_byte_size = glyph.row_byte_size;
+
+ pch->pcbmp = pcb;
+
+ pcached_bitmap_latest++;
+ if (FONT_CACHE_SLOT_OVER_P(pcached_bitmap_latest))
+ pcached_bitmap_latest = cached_bitmap_slots;
+
+ return pcb;
+}
+
+static HBITMAP
+create_offscreen_bitmap(HDC hdc, int width, int height, unsigned char **bitsp)
+{
+ struct {
+ BITMAPINFOHEADER h;
+ RGBQUAD c[2];
+ } info;
+
+ memset(&info, 0, sizeof(info));
+ info.h.biSize = sizeof(BITMAPINFOHEADER);
+ info.h.biWidth = width;
+ info.h.biHeight = -height;
+ info.h.biPlanes = 1;
+ info.h.biBitCount = 1;
+ info.h.biCompression = BI_RGB;
+ info.c[1].rgbRed = info.c[1].rgbGreen = info.c[1].rgbBlue = 255;
+
+ return CreateDIBSection(hdc, (LPBITMAPINFO)&info,
+ DIB_RGB_COLORS, bitsp, NULL, 0);
+}
+
+glyph_metric *
+w32_BDF_TextMetric(bdffont *fontp, unsigned char *text, int dim)
+{
+ int index;
+ cache_bitmap *pcb;
+
+ if (dim == 1)
+ index = *text;
+ else
+ index = MAKELENDSHORT(text[1], text[0]);
+
+ pcb = get_bitmap_with_cache(fontp, index);
+ if (!pcb)
+ return NULL;
+
+ return &(pcb->metric);