// **************************************************************************** // // Function Name: RTrueTypeFont::CountSfntTables( ) // // Description: // // Returns: long // // Exceptions: None // // **************************************************************************** // long RTrueTypeFont::CountSfntTables( Handle sfnt ) { short state = GetFontState( sfnt ); short tables = ((sfnt_OffsetTable*)*sfnt)->numOffsets; SetFontState( sfnt, state ); return tables; }
// **************************************************************************** // // Function Name: RTrueTypeFont::SetFontState( ) // // Description: Returns the glyph index for the given character code // // Returns: glyph index or 0 // // Exceptions: None // // **************************************************************************** // long RTrueTypeFont::GetCharGlyphIndex( Handle sfnt, unsigned short charCode ) { short state = GetFontState( sfnt ); sfnt_char2IndexDirectory* table = (sfnt_char2IndexDirectory *)GetSfntTablePtr( sfnt, tag_CharToIndexMap ); short i; long mapOffset = 0; long glyphIndex = 0; // missing character glyph sfnt_platformEntry* plat; sfnt_mappingTable* mapping; if ( table == NULL ) return 0; plat = table->platform; // You can change this section to look for other scripts for ( i = table->numTables - 1; i >= 0; --i ) { if ( plat->platformID == plat_Macintosh && plat->specificID == smRoman ) { mapOffset = plat->offset; break; } ++plat; } if ( mapOffset ) { mapping = (sfnt_mappingTable*)((char*)table + mapOffset); switch ( mapping->format ) { case 0: { Byte* glyphs = (Byte*)(mapping + 1); glyphIndex = glyphs[charCode]; } break; case 6: { short* glyphs = (short*)(mapping + 1); short first = *glyphs++; short count = *glyphs++; charCode -= first; if (charCode < count) glyphIndex = glyphs[charCode]; } break; default: glyphIndex = 0; } } else glyphIndex = 0; SetFontState( sfnt, state ); return glyphIndex; }
// **************************************************************************** // // Function Name: RTrueTypeFont::GetSfntTag( ) // // Description: // // Returns: Tag // // Exceptions: None // // **************************************************************************** // fontTableTag RTrueTypeFont::GetSfntTag( Handle sfnt, long index ) { fontTableTag tag = 0; short state = GetFontState( sfnt ); if ( index < ((sfnt_OffsetTable*)*sfnt)->numOffsets ) tag = ((sfnt_OffsetTable*)*sfnt)->table[index].tableTag; SetFontState( sfnt, state ); return tag; }
void MythUIText::Reset() { if (m_Message != m_DefaultMessage) { SetText(m_DefaultMessage); SetRedraw(); } SetFontState("default"); MythUIType::Reset(); }
// **************************************************************************** // // Function Name: RTrueTypeFont::GetSfntTableInfo( ) // // Description: // // Returns: Mac OS error // // Exceptions: None // // **************************************************************************** // OSErr RTrueTypeFont::GetSfntTableInfo( Handle sfnt, fontTableTag tag, FontTableInfo* fTable ) { short state = GetFontState( sfnt ); sfnt_OffsetTable* dir = (sfnt_OffsetTable*)*sfnt; sfnt_DirectoryEntry* table = dir->table; short count = dir->numOffsets; OSErr error = noErr; for ( ; --count >= 0; table++ ) if ( table->tableTag == tag ) { fTable->offset = table->offset; fTable->length = table->length; fTable->checkSum = table->checkSum; break; } if ( count < 0 ) error = fontNotOutlineErr; SetFontState( sfnt, state ); return error; }
// **************************************************************************** // // Function Name: RTrueTypeFont::GetGlyphOutline( ) // // Description: // // Returns: Nothing // // Exceptions: Memory, Font // // **************************************************************************** // void RTrueTypeFont::GetGlyphOutline( Handle sfnt, long glyphIndex, GlyphOutline* pOutline, Matrix xform ) { short state = GetFontState( sfnt ); short upem, sideBearing, adjustToLsb; short* glyph; sfnt_FontHeader* head; sfnt_HorizontalHeader* hhea; sfnt_HorizontalMetrics* hori; long length; long longMetrics; try { ::HLock( sfnt ); head = (sfnt_FontHeader *)GetSfntTablePtr( sfnt, tag_FontHeader ); hhea = (sfnt_HorizontalHeader *)GetSfntTablePtr( sfnt, tag_HoriHeader ); hori = (sfnt_HorizontalMetrics *)GetSfntTablePtr( sfnt, tag_HorizontalMetrics ); if ( head == NULL || hhea == NULL || hori == NULL ) throw fontNotOutlineErr; upem = head->unitsPerEm; longMetrics = hhea->numberLongMetrics; if ( glyphIndex < longMetrics ) { pOutline->advance.x = ::FixRatio( hori[glyphIndex].advance, upem ); sideBearing = hori[glyphIndex].sideBearing; } else { short *lsb = (short *)&hori[longMetrics]; // first entry after[AW,LSB] array pOutline->advance.x = ::FixRatio( hori[longMetrics-1].advance, upem ); sideBearing = hori[glyphIndex - longMetrics].sideBearing; } pOutline->advance.y = 0; pOutline->origin.x = pOutline->origin.y = 0; if ( (glyph = (short *)GetSfntGlyphPtr(sfnt, glyphIndex, &length)) == 0 ) throw fontNotOutlineErr; if ( length == 0 ) { pOutline->contourCount = pOutline->pointCount = 0; SetFontState( sfnt, state ); return; } pOutline->contourCount = *glyph++; adjustToLsb = *glyph - sideBearing; // xmin - lsb glyph += 4; // skip bounds rect if ( pOutline->contourCount == 0 ) pOutline->pointCount = 0; else if ( pOutline->contourCount == -1 ) { short flags, index, newMatrix; pOutline->contourCount = pOutline->pointCount = 0; mySetHandleSize( (Handle)pOutline->endPoints, 0 ); mySetHandleSize( (Handle)pOutline->onCurve, 0 ); mySetHandleSize( (Handle)pOutline->x, 0 ); mySetHandleSize( (Handle)pOutline->y, 0 ); do { Matrix compXform; short arg1, arg2; flags = *glyph++; index = *glyph++; newMatrix = false; if ( flags & ARG_1_AND_2_ARE_WORDS ) { arg1 = *glyph++; arg2 = *glyph++; } else { char* byteP = (char*)glyph; if ( flags & ARGS_ARE_XY_VALUES ) { // offsets are signed arg1 = *byteP++; arg2 = *byteP; } else { // anchor points are unsigned arg1 = (unsigned char)*byteP++; arg2 = (unsigned char)*byteP; } ++glyph; } #if IMPLEMENT_SCALED_COMPONENTS if ( flags & (WE_HAVE_A_SCALE | WE_HAVE_AN_X_AND_Y_SCALE | WE_HAVE_A_TWO_BY_TWO) ) { Matrix subXform; MakeIdentityMatrix( subXform ); if ( flags & WE_HAVE_A_TWO_BY_TWO ) { compXform[0][0] = (Fixed)*glyph++ << 2; compXform[0][1] = (Fixed)*glyph++ << 2; compXform[1][0] = (Fixed)*glyph++ << 2; compXform[1][1] = (Fixed)*glyph++ << 2; } else if ( flags & WE_HAVE_AN_X_AND_Y_SCALE ) { compXform[0][0] = (Fixed)*glyph++ << 2; compXform[1][1] = (Fixed)*glyph++ << 2; } else compXform[0][0] = compXform[1][1] = (Fixed)*glyph++ << 2; PostMulMatrix (compXform, xform ); newMatrix = true; } #endif { GlyphOutline out; InitGlyphOutline( &out ); GetGlyphOutline( sfnt, index, &out, newMatrix ? compXform : xform ); { Fixed dx, dy; if ( flags & ARGS_ARE_XY_VALUES ) { dx = ::FixRatio(arg1, upem); dy = -::FixRatio(arg2, upem); } else { dx = (*pOutline->x)[arg1] - (*out.x)[arg2]; dy = (*pOutline->y)[arg1] - (*out.y)[arg2]; } MoveGlyphOutline( &out, dx, dy ); } AppendGlyphOutline( pOutline, &out ); KillGlyphOutline( &out ); } } while ( flags & MORE_COMPONENTS ); } else if ( pOutline->contourCount > 0 ) { // Load in the end points. { long size = pOutline->contourCount * sizeof(short); mySetHandleSize( (Handle)pOutline->endPoints, size ); BlockMove( (Ptr)glyph, (Ptr)*pOutline->endPoints, size ); glyph += pOutline->contourCount; } pOutline->pointCount = (*pOutline->endPoints)[pOutline->contourCount - 1] + 1; mySetHandleSize( (Handle)pOutline->onCurve, pOutline->pointCount * sizeof(char) ); mySetHandleSize( (Handle)pOutline->x, pOutline->pointCount * sizeof(Fixed) ); mySetHandleSize( (Handle)pOutline->y, pOutline->pointCount * sizeof(Fixed) ); // Skip the word for instruction count + the instructions. // Then load in the onCurve bytes. { Byte* p = (Byte*)glyph + sizeof(short) + *glyph; Byte* onCurve = *pOutline->onCurve; Byte* stop = onCurve + pOutline->pointCount; Byte flag; while ( onCurve < stop ) { *onCurve++ = flag = GetUnsignedByte( p ); if ( flag & REPEAT_FLAGS ) { short count = GetUnsignedByte( p ); for ( --count; count >= 0; --count ) *onCurve++ = flag; } } // Lets do X { short coord = adjustToLsb; Fixed* x = *pOutline->x; onCurve = *pOutline->onCurve; while ( onCurve < stop ) { if ( (flag = *onCurve++) & XSHORT ) { if ( flag & SHORT_X_IS_POS ) coord += GetUnsignedByte( p ); else coord -= GetUnsignedByte( p ); } else if ( !(flag & NEXT_X_IS_ZERO) ) { coord += (short)(*p++) << 8; coord += (Byte)*p++; } *x = ::FixRatio( coord, upem ); x++; } } // Lets do Y { short coord = 0; Fixed* y = *pOutline->y; onCurve = *pOutline->onCurve; while ( onCurve < stop ) { if ( (flag = *onCurve) & YSHORT ) { if ( flag & SHORT_Y_IS_POS ) coord += GetUnsignedByte( p ); else coord -= GetUnsignedByte( p ); } else if ( !(flag & NEXT_Y_IS_ZERO) ) { coord += (short)(*p++) << 8; coord += (Byte)*p++; } *y = -::FixRatio( coord, upem ); y++; // Filter off the extra bits *onCurve++ = flag & ONCURVE; } } } } else throw fontNotOutlineErr; } catch ( OSErr osErr ) { SetFontState( sfnt, state ); switch ( osErr ) { case memFullErr : // out of memeory SetFontState( sfnt, state ); throw kMemory; break; case fontNotOutlineErr : // bad font SetFontState( sfnt, state ); throw kResource; break; default: TpsAssertAlways( "Bad exception" ); throw; break; } } catch ( ... ) { SetFontState( sfnt, state ); throw; } SetFontState( sfnt, state ); }