XFree86/src/xfstt/RasterScale.cpp
// get font extent
//### is there a way to avoid going through all glyphs and interpret them?
//### we need max/min-width, max/min-left, max/min-right, max/min-height, ...
//### would it have advantages to delay the scan line conversion?
get font extent
is there a way to avoid going through all glyphs and interpret them.
get font extent is there a way to avoid going through all glyphs and interpret them .
void Rasterizer::getFontExtent( FontExtent* fe)
{
	if( status == NOT_READY)
		applyTransformation();
	if( status == FONT_DONE)
		return;
	if (ttFont->os2Table) {
		int i = ttFont->os2Table->winAscent;
		fe->yWinAscent = ((yy * i) << xxexp) >> 11;
		i = ttFont->os2Table->winDescent;
		fe->yWinDescent = ((yy * i) << xxexp) >> 11;
	} else {
		int i = ttFont->hheaTable->yAscent;
		fe->yWinAscent = ((yy * i) << xxexp) >> 11;
		i = -ttFont->hheaTable->yDescent;
		fe->yWinDescent = ((yy * i) << xxexp) >> 11;
	}
	fe->xLeftMin	=
	fe->xRightMin	=
	fe->xAdvanceMin	=
	fe->yAdvanceMin	=
	fe->yAscentMin	=
	fe->yDescentMin	=
	fe->xBlackboxMin=
	fe->yBlackboxMin= INT_MAX;
	fe->xLeftMax	=
	fe->xRightMax	=
	fe->xAdvanceMax	=
	fe->yAdvanceMax	=
	fe->yAscentMax	=
	fe->yDescentMax	=
	fe->xBlackboxMax=
	fe->yBlackboxMax= INT_MIN;
	if( format < 0) {
		fe->xBlackboxMax = ttFont->getMaxWidth( mppemx);
		dX = (((fe->xBlackboxMax-1) | ((8<<~format)-1)) + 1) >> 3;
	}
	U32 buflen	= fe->buflen;
	U8* endbmp	= fe->buffer + buflen;
	CharInfo* ci	= (CharInfo*)fe->buffer;
	fe->bmpFormat	= MSB_BIT_FIRST | MSB_BYTE_FIRST;
	fe->numGlyphs	= ttFont->maxpTable->numGlyphs;
	fe->bitmaps	= (U8*)&ci[ fe->numGlyphs];
	U8* buffer	= fe->bitmaps;
	if( buffer >= endbmp) {
		return;
	}
	for( int glyphNo = 0; glyphNo < fe->numGlyphs; ++glyphNo, ++ci) {
		GlyphMetrics* gm = &ci->gm;
		ci->length	= putGlyphBitmap( glyphNo, buffer, endbmp, gm);
		ci->offset	= buffer - fe->bitmaps;
		buffer		+= ci->length;
#define MINMAX(x,y,z)	if( z < fe->x) fe->x = z;	\
			if( z > fe->y) fe->y = z;
		MINMAX( xBlackboxMin,	xBlackboxMax,	gm->xBlackbox);
		MINMAX( yBlackboxMin,	yBlackboxMax,	gm->yBlackbox);
		MINMAX( xLeftMin,	xLeftMax,	-gm->xOrigin);
		MINMAX( xRightMin,	xRightMax,	gm->xBlackbox-gm->xOrigin);
		MINMAX( yAscentMin,	yAscentMax,	gm->yBlackbox-gm->yOrigin);
		MINMAX( yDescentMin,	yDescentMax,	gm->yOrigin);
		MINMAX( xAdvanceMin,	xAdvanceMax,	gm->xAdvance);
		MINMAX( yAdvanceMin,	yAdvanceMax,	gm->yAdvance);
	}
	fe->bmplen = buffer - fe->bitmaps;
	status = FONT_DONE;
}
void Rasterizer :: getFontExtent ( FontExtent * fe ) { if ( status == NOT_READY ) applyTransformation ( ) ; if ( status == FONT_DONE ) return ; if ( ttFont -> os2Table ) { int i = ttFont -> os2Table -> winAscent ; fe -> yWinAscent = ( ( yy * i ) << xxexp ) >> 11 ; i = ttFont -> os2Table -> winDescent ; fe -> yWinDescent = ( ( yy * i ) << xxexp ) >> 11 ; } else { int i = ttFont -> hheaTable -> yAscent ; fe -> yWinAscent = ( ( yy * i ) << xxexp ) >> 11 ; i = - ttFont -> hheaTable -> yDescent ; fe -> yWinDescent = ( ( yy * i ) << xxexp ) >> 11 ; } fe -> xLeftMin = fe -> xRightMin = fe -> xAdvanceMin = fe -> yAdvanceMin = fe -> yAscentMin = fe -> yDescentMin = fe -> xBlackboxMin = fe -> yBlackboxMin = INT_MAX ; fe -> xLeftMax = fe -> xRightMax = fe -> xAdvanceMax = fe -> yAdvanceMax = fe -> yAscentMax = fe -> yDescentMax = fe -> xBlackboxMax = fe -> yBlackboxMax = INT_MIN ; if ( format < 0 ) { fe -> xBlackboxMax = ttFont -> getMaxWidth ( mppemx ) ; dX = ( ( ( fe -> xBlackboxMax - 1 ) | ( ( 8 << ~ format ) - 1 ) ) + 1 ) >> 3 ; } U32 buflen = fe -> buflen ; U8 * endbmp = fe -> buffer + buflen ; CharInfo * ci = ( CharInfo * ) fe -> buffer ; fe -> bmpFormat = MSB_BIT_FIRST | MSB_BYTE_FIRST ; fe -> numGlyphs = ttFont -> maxpTable -> numGlyphs ; fe -> bitmaps = ( U8 * ) & ci [ fe -> numGlyphs ] ; U8 * buffer = fe -> bitmaps ; if ( buffer >= endbmp ) { return ; } for ( int glyphNo = 0 ; glyphNo < fe -> numGlyphs ; ++ glyphNo , ++ ci ) { GlyphMetrics * gm = & ci -> gm ; ci -> length = putGlyphBitmap ( glyphNo , buffer , endbmp , gm ) ; ci -> offset = buffer - fe -> bitmaps ; buffer += ci -> length ; #define MINMAX ( x , y , z ) 	if( z < fe->x) fe->x = z;	\
			if( z > fe->y) fe->y = z; MINMAX ( xBlackboxMin , xBlackboxMax , gm -> xBlackbox ) ; MINMAX ( yBlackboxMin , yBlackboxMax , gm -> yBlackbox ) ; MINMAX ( xLeftMin , xLeftMax , - gm -> xOrigin ) ; MINMAX ( xRightMin , xRightMax , gm -> xBlackbox - gm -> xOrigin ) ; MINMAX ( yAscentMin , yAscentMax , gm -> yBlackbox - gm -> yOrigin ) ; MINMAX ( yDescentMin , yDescentMax , gm -> yOrigin ) ; MINMAX ( xAdvanceMin , xAdvanceMax , gm -> xAdvance ) ; MINMAX ( yAdvanceMin , yAdvanceMax , gm -> yAdvance ) ; } fe -> bmplen = buffer - fe -> bitmaps ; status = FONT_DONE ; }
get font extent
 is there a way to avoid going through all glyphs and interpret them?
get font extent is there a way to avoid going through all glyphs and interpret them?
// fixed xBlackbox for all glyphs //### not even enough room for charinfo!!! what to do???