X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/73c04bcfe1096173b00431f0cdc742894b15eef0..e4f10fab0c078f399c9deef476d9c9b73b47dff8:/icuSources/test/letest/PortableFontInstance.cpp diff --git a/icuSources/test/letest/PortableFontInstance.cpp b/icuSources/test/letest/PortableFontInstance.cpp index c96b6ed7..14e3f520 100644 --- a/icuSources/test/letest/PortableFontInstance.cpp +++ b/icuSources/test/letest/PortableFontInstance.cpp @@ -1,7 +1,7 @@ /* ******************************************************************************* * - * Copyright (C) 1999-2006, International Business Machines + * Copyright (C) 1999-2008, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************* @@ -121,7 +121,7 @@ PortableFontInstance::PortableFontInstance(const char *fileName, float pointSize fUnitsPerEM = SWAPW(headTable->unitsPerEm); fFontChecksum = SWAPL(headTable->checksumAdjustment); - deleteTable(headTable); + freeFontTable(headTable); //nameTable = (NAMETable *) readFontTable(nameTag); @@ -137,7 +137,7 @@ PortableFontInstance::PortableFontInstance(const char *fileName, float pointSize // goto error_exit; //} - //deleteTable(nameTable); + //freeFontTable(nameTable); hheaTable = (HHEATable *) readFontTable(hheaTag); @@ -152,7 +152,7 @@ PortableFontInstance::PortableFontInstance(const char *fileName, float pointSize fNumLongHorMetrics = SWAPW(hheaTable->numOfLongHorMetrics); - deleteTable((void *) hheaTable); + freeFontTable((void *) hheaTable); fCMAPMapper = findUnicodeMapper(); @@ -174,8 +174,8 @@ PortableFontInstance::~PortableFontInstance() if (fFile != NULL) { fclose(fFile); - deleteTable(fHMTXTable); - deleteTable(fNAMETable); + freeFontTable(fHMTXTable); + freeFontTable(fNAMETable); delete fCMAPMapper; @@ -183,11 +183,6 @@ PortableFontInstance::~PortableFontInstance() } } -void PortableFontInstance::deleteTable(const void *table) const -{ - DELETE_ARRAY(table); -} - const DirectoryEntry *PortableFontInstance::findTable(LETag tag) const { if (fDirectory != NULL) { @@ -276,7 +271,7 @@ const char *PortableFontInstance::getNameString(le_uint16 nameID, le_uint16 plat for(le_int32 i = 0; i < fNameCount; i += 1) { const NameRecord *nameRecord = &fNAMETable->nameRecords[i]; - if (SWAPW(nameRecord->platformID) == platformID && SWAPW(nameRecord->encodingID == encodingID) && + if (SWAPW(nameRecord->platformID) == platformID && SWAPW(nameRecord->encodingID) == encodingID && SWAPW(nameRecord->languageID) == languageID && SWAPW(nameRecord->nameID) == nameID) { char *name = ((char *) fNAMETable) + fNameStringOffset + SWAPW(nameRecord->offset); le_uint16 length = SWAPW(nameRecord->length); @@ -292,11 +287,52 @@ const char *PortableFontInstance::getNameString(le_uint16 nameID, le_uint16 plat return NULL; } +const LEUnicode16 *PortableFontInstance::getUnicodeNameString(le_uint16 nameID, le_uint16 platformID, le_uint16 encodingID, le_uint16 languageID) const +{ + if (fNAMETable == NULL) { + LETag nameTag = LE_NAME_TABLE_TAG; + PortableFontInstance *realThis = (PortableFontInstance *) this; + + realThis->fNAMETable = (const NAMETable *) readFontTable(nameTag); + + if (realThis->fNAMETable != NULL) { + realThis->fNameCount = SWAPW(realThis->fNAMETable->count); + realThis->fNameStringOffset = SWAPW(realThis->fNAMETable->stringOffset); + } + } + + for(le_int32 i = 0; i < fNameCount; i += 1) { + const NameRecord *nameRecord = &fNAMETable->nameRecords[i]; + + if (SWAPW(nameRecord->platformID) == platformID && SWAPW(nameRecord->encodingID) == encodingID && + SWAPW(nameRecord->languageID) == languageID && SWAPW(nameRecord->nameID) == nameID) { + LEUnicode16 *name = (LEUnicode16 *) (((char *) fNAMETable) + fNameStringOffset + SWAPW(nameRecord->offset)); + le_uint16 length = SWAPW(nameRecord->length) / 2; + LEUnicode16 *result = NEW_ARRAY(LEUnicode16, length + 2); + + for (le_int32 c = 0; c < length; c += 1) { + result[c] = SWAPW(name[c]); + } + + result[length] = 0; + + return result; + } + } + + return NULL; +} + void PortableFontInstance::deleteNameString(const char *name) const { DELETE_ARRAY(name); } +void PortableFontInstance::deleteNameString(const LEUnicode16 *name) const +{ + DELETE_ARRAY(name); +} + void PortableFontInstance::getGlyphAdvance(LEGlyphID glyph, LEPoint &advance) const { TTGlyphID ttGlyph = (TTGlyphID) LE_GET_GLYPH(glyph); @@ -309,7 +345,7 @@ void PortableFontInstance::getGlyphAdvance(LEGlyphID glyph, LEPoint &advance) co if (maxpTable != NULL) { realThis->fNumGlyphs = SWAPW(maxpTable->numGlyphs); - deleteTable(maxpTable); + freeFontTable(maxpTable); } realThis->fHMTXTable = (const HMTXTable *) readFontTable(hmtxTag);