Example #1
0
void
bitmapComputeFontInkBounds(FontPtr pFont)
{
    BitmapFontPtr  bitmapFont = (BitmapFontPtr) pFont->fontPrivate;
    int         nchars;
    int         r,
                c;
    CharInfoPtr cit;
    xCharInfo  *ci;
    int         offset;
    xCharInfo  *minbounds,
               *maxbounds;
    int         i;

    if (!bitmapFont->ink_metrics) {
	if (bitmapFont->bitmapExtra) {
	    bitmapFont->bitmapExtra->info.ink_minbounds = bitmapFont->bitmapExtra->info.minbounds;
	    bitmapFont->bitmapExtra->info.ink_maxbounds = bitmapFont->bitmapExtra->info.maxbounds;
	}
	pFont->info.ink_minbounds = pFont->info.minbounds;
	pFont->info.ink_maxbounds = pFont->info.maxbounds;
    } else {
	if (bitmapFont->bitmapExtra) {
	    minbounds = &bitmapFont->bitmapExtra->info.ink_minbounds;
	    maxbounds = &bitmapFont->bitmapExtra->info.ink_maxbounds;
	} else {
	    minbounds = &pFont->info.ink_minbounds;
	    maxbounds = &pFont->info.ink_maxbounds;
	}
	*minbounds = initMinMetrics;
	*maxbounds = initMaxMetrics;
	nchars = bitmapFont->num_chars;
	for (i = 0, ci = bitmapFont->ink_metrics; i < nchars; i++, ci++) {
	    COMPUTE_MINMAX(ci);
	    minbounds->attributes &= ci->attributes;
	    maxbounds->attributes |= ci->attributes;
	}
	if (bitmapFont->bitmapExtra) {
	    minbounds = &pFont->info.ink_minbounds;
	    maxbounds = &pFont->info.ink_maxbounds;
	    *minbounds = initMinMetrics;
	    *maxbounds = initMaxMetrics;
            i=0;
	    for (r = pFont->info.firstRow; r <= pFont->info.lastRow; r++) {
		for (c = pFont->info.firstCol; c <= pFont->info.lastCol; c++) {
		    cit = ACCESSENCODING(bitmapFont->encoding, i);
		    if (cit) {
			offset = cit - bitmapFont->metrics;
			ci = &bitmapFont->ink_metrics[offset];
			COMPUTE_MINMAX(ci);
			minbounds->attributes &= ci->attributes;
			maxbounds->attributes |= ci->attributes;
		    }
                    i++;
		}
	    }
	}
    }
}
int
bitmapGetGlyphs(FontPtr pFont, unsigned long count, unsigned char *chars,
		FontEncoding charEncoding,
		unsigned long *glyphCount, 	/* RETURN */
		CharInfoPtr *glyphs) 		/* RETURN */
{
    BitmapFontPtr  bitmapFont;
    unsigned int firstCol;
    register unsigned int numCols;
    unsigned int firstRow;
    unsigned int numRows;
    CharInfoPtr *glyphsBase;
    register unsigned int c;
    register CharInfoPtr pci;
    unsigned int r;
    CharInfoPtr **encoding;
    CharInfoPtr pDefault;

    bitmapFont = (BitmapFontPtr) pFont->fontPrivate;
    encoding = bitmapFont->encoding;
    pDefault = bitmapFont->pDefault;
    firstCol = pFont->info.firstCol;
    numCols = pFont->info.lastCol - firstCol + 1;
    glyphsBase = glyphs;
    switch (charEncoding) {

    case Linear8Bit:
    case TwoD8Bit:
	if (pFont->info.firstRow > 0) {
            if (pDefault)
                while (count--)
                    *glyphs++ = pDefault;
	    break;
        }
	if (pFont->info.allExist && pDefault) {
	    while (count--) {
		c = (*chars++) - firstCol;
		if (c < numCols)
		    *glyphs++ = ACCESSENCODING(encoding,c);
		else
		    *glyphs++ = pDefault;
	    }
	} else {
	    while (count--) {
		c = (*chars++) - firstCol;
		if (c < numCols && (pci = ACCESSENCODING(encoding,c)))
		    *glyphs++ = pci;
		else if (pDefault)
		    *glyphs++ = pDefault;
	    }
	}
	break;
    case Linear16Bit:
	if (pFont->info.allExist && pDefault) {
	    while (count--) {
		c = *chars++ << 8;
		c = (c | *chars++) - firstCol;
		if (c < numCols)
		    *glyphs++ = ACCESSENCODING(encoding,c);
		else
		    *glyphs++ = pDefault;
	    }
	} else {
	    while (count--) {
		c = *chars++ << 8;
		c = (c | *chars++) - firstCol;
		if (c < numCols && (pci = ACCESSENCODING(encoding,c)))
		    *glyphs++ = pci;
		else if (pDefault)
		    *glyphs++ = pDefault;
	    }
	}
	break;

    case TwoD16Bit:
	firstRow = pFont->info.firstRow;
	numRows = pFont->info.lastRow - firstRow + 1;
	while (count--) {
	    r = (*chars++) - firstRow;
	    c = (*chars++) - firstCol;
	    if (r < numRows && c < numCols &&
		    (pci = ACCESSENCODING(encoding, r * numCols + c)))
		*glyphs++ = pci;
	    else if (pDefault)
		*glyphs++ = pDefault;
	}
	break;
    }
    *glyphCount = glyphs - glyphsBase;
    return Successful;
}
Example #3
0
void
bitmapComputeFontBounds(FontPtr pFont)
{
    BitmapFontPtr  bitmapFont = (BitmapFontPtr) pFont->fontPrivate;
    int         nchars;
    int         r,
                c;
    CharInfoPtr ci;
    int         maxOverlap;
    int         overlap;
    xCharInfo  *minbounds,
               *maxbounds;
    int         i;
    int		numneg = 0, numpos = 0;

    if (bitmapFont->bitmapExtra) {
	minbounds = &bitmapFont->bitmapExtra->info.minbounds;
	maxbounds = &bitmapFont->bitmapExtra->info.maxbounds;
    } else {
	minbounds = &pFont->info.minbounds;
	maxbounds = &pFont->info.maxbounds;
    }
    *minbounds = initMinMetrics;
    *maxbounds = initMaxMetrics;
    maxOverlap = MINSHORT;
    nchars = bitmapFont->num_chars;
    for (i = 0, ci = bitmapFont->metrics; i < nchars; i++, ci++) {
	COMPUTE_MINMAX(&ci->metrics);
	if (ci->metrics.characterWidth < 0)
	    numneg++;
	else
	    numpos++;
	minbounds->attributes &= ci->metrics.attributes;
	maxbounds->attributes |= ci->metrics.attributes;
	overlap = ci->metrics.rightSideBearing - ci->metrics.characterWidth;
	if (maxOverlap < overlap)
	    maxOverlap = overlap;
    }
    if (bitmapFont->bitmapExtra) {
	if (numneg > numpos)
	    bitmapFont->bitmapExtra->info.drawDirection = RightToLeft;
	else
	    bitmapFont->bitmapExtra->info.drawDirection = LeftToRight;
	bitmapFont->bitmapExtra->info.maxOverlap = maxOverlap;
	minbounds = &pFont->info.minbounds;
	maxbounds = &pFont->info.maxbounds;
	*minbounds = initMinMetrics;
	*maxbounds = initMaxMetrics;
        i = 0;
	maxOverlap = MINSHORT;
	for (r = pFont->info.firstRow; r <= pFont->info.lastRow; r++) {
	    for (c = pFont->info.firstCol; c <= pFont->info.lastCol; c++) {
		ci = ACCESSENCODING(bitmapFont->encoding, i);
		if (ci) {
		    COMPUTE_MINMAX(&ci->metrics);
		    if (ci->metrics.characterWidth < 0)
			numneg++;
		    else
			numpos++;
		    minbounds->attributes &= ci->metrics.attributes;
		    maxbounds->attributes |= ci->metrics.attributes;
		    overlap = ci->metrics.rightSideBearing -
			ci->metrics.characterWidth;
		    if (maxOverlap < overlap)
			maxOverlap = overlap;
		}
                i++;
	    }
	}
    }
    if (numneg > numpos)
	pFont->info.drawDirection = RightToLeft;
    else
	pFont->info.drawDirection = LeftToRight;
    pFont->info.maxOverlap = maxOverlap;
}