/*
**********************************************************************
- * Copyright (C) 2003-2008, International Business Machines
+ * Copyright (C) 2003-2013, International Business Machines
* Corporation and others. All Rights Reserved.
**********************************************************************
*/
struct FontTableCacheEntry
{
- LETag tag;
- const void *table;
+ LETag tag;
+ const void *table;
+ size_t length;
};
FontTableCache::FontTableCache()
for (int i = 0; i < fTableCacheSize; i += 1) {
fTableCache[i].tag = 0;
fTableCache[i].table = NULL;
+ fTableCache[i].length = 0;
}
}
fTableCache[i].tag = 0;
fTableCache[i].table = NULL;
+ fTableCache[i].length = 0;
}
fTableCacheCurr = 0;
DELETE_ARRAY(table);
}
-const void *FontTableCache::find(LETag tableTag) const
+const void *FontTableCache::find(LETag tableTag, size_t &length) const
{
for (int i = 0; i < fTableCacheCurr; i += 1) {
if (fTableCache[i].tag == tableTag) {
- return fTableCache[i].table;
+ length = fTableCache[i].length;
+ return fTableCache[i].table;
}
}
- const void *table = readFontTable(tableTag);
+ const void *table = readFontTable(tableTag, length);
- ((FontTableCache *) this)->add(tableTag, table);
+ ((FontTableCache *) this)->add(tableTag, table, length);
return table;
}
-void FontTableCache::add(LETag tableTag, const void *table)
+void FontTableCache::add(LETag tableTag, const void *table, size_t length)
{
if (fTableCacheCurr >= fTableCacheSize) {
le_int32 newSize = fTableCacheSize + TABLE_CACHE_GROW;
for (le_int32 i = fTableCacheSize; i < newSize; i += 1) {
fTableCache[i].tag = 0;
fTableCache[i].table = NULL;
+ fTableCache[i].length = 0;
}
fTableCacheSize = newSize;
fTableCache[fTableCacheCurr].tag = tableTag;
fTableCache[fTableCacheCurr].table = table;
+ fTableCache[fTableCacheCurr].length = length;
fTableCacheCurr += 1;
}
/*
**********************************************************************
- * Copyright (C) 2003-2008, International Business Machines
+ * Copyright (C) 2003-2013, International Business Machines
* Corporation and others. All Rights Reserved.
**********************************************************************
*/
virtual ~FontTableCache();
- const void *find(LETag tableTag) const;
+ const void *find(LETag tableTag, size_t &length) const;
protected:
- virtual const void *readFontTable(LETag tableTag) const = 0;
+ virtual const void *readFontTable(LETag tableTag, size_t &length) const = 0;
virtual void freeFontTable(const void *table) const;
private:
- void add(LETag tableTag, const void *table);
+ void add(LETag tableTag, const void *table, size_t length);
FontTableCacheEntry *fTableCache;
le_int32 fTableCacheCurr;
## Makefile.in for ICU - test/letest
-## Copyright (c) 2001-2011, International Business Machines Corporation and
+## Copyright (c) 2001-2013, International Business Machines Corporation and
## others. All Rights Reserved.
## Source directory information
invoke:
ICU_DATA=$${ICU_DATA:-$(top_builddir)/data/} TZ=PST8PDT $(INVOKE) $(INVOCATION)
+gen-data: $(GENTARGET)
+ ICU_DATA=$${ICU_DATA:-$(top_builddir)/data/} TZ=PST8PDT $(INVOKE) ./$(GENTARGET) $(top_srcdir)/test/testdata/letest.xml $(srcdir)/gendata.xml
+
ifeq (,$(MAKECMDGOALS))
-include $(DEPS)
else
/*
*******************************************************************************
*
- * Copyright (C) 1999-2008, International Business Machines
+ * Copyright (C) 1999-2013, International Business Machines
* Corporation and others. All Rights Reserved.
*
*******************************************************************************
#include "sfnt.h"
#include <string.h>
+#include <stdio.h>
+
+#if 0
+static const char *letagToStr(LETag tag, char *str) {
+ str[0]= 0xFF & (tag>>24);
+ str[1]= 0xFF & (tag>>16);
+ str[2]= 0xFF & (tag>>8);
+ str[3]= 0xFF & (tag>>0);
+ str[4]= 0;
+ return str;
+}
+#endif
//
// Finds the high bit by binary searching
// open the font file
fFile = fopen(fileName, "rb");
+ //printf("Open Font: %s\n", fileName);
if (fFile == NULL) {
+ printf("%s:%d: %s: FNF\n", __FILE__, __LINE__, fileName);
status = LE_FONT_FILE_NOT_FOUND_ERROR;
return;
}
fDirectory = (const SFNTDirectory *) NEW_ARRAY(char, dirSize);
if (fDirectory == NULL) {
+ printf("%s:%d: %s: malloc err\n", __FILE__, __LINE__, fileName);
status = LE_MEMORY_ALLOCATION_ERROR;
goto error_exit;
}
if (headTable == NULL) {
status = LE_MISSING_FONT_TABLE_ERROR;
+ printf("%s:%d: %s: missing head table\n", __FILE__, __LINE__, fileName);
goto error_exit;
}
hheaTable = (HHEATable *) readFontTable(hheaTag);
if (hheaTable == NULL) {
+ printf("%s:%d: %s: missing hhea table\n", __FILE__, __LINE__, fileName);
status = LE_MISSING_FONT_TABLE_ERROR;
goto error_exit;
}
fCMAPMapper = findUnicodeMapper();
if (fCMAPMapper == NULL) {
+ printf("%s:%d: %s: can't load cmap\n", __FILE__, __LINE__, fileName);
status = LE_MISSING_FONT_TABLE_ERROR;
goto error_exit;
}
const void *PortableFontInstance::getFontTable(LETag tableTag) const
{
- return FontTableCache::find(tableTag);
+ size_t ignored;
+ return getFontTable(tableTag, ignored);
}
-const void *PortableFontInstance::readFontTable(LETag tableTag) const
+const void *PortableFontInstance::getFontTable(LETag tableTag, size_t &length) const
+{
+ return FontTableCache::find(tableTag, length);
+}
+
+const void *PortableFontInstance::readFontTable(LETag tableTag, size_t &length) const
{
le_uint32 len;
- return readTable(tableTag, &len);
+ const void *data= readTable(tableTag, &len);
+ length = len;
+ //char tag5[5];
+ //printf("Read %s, result %p #%d\n", letagToStr(tableTag,tag5), data,len);
+ return data;
}
CMAPMapper *PortableFontInstance::findUnicodeMapper()
return fFontChecksum;
}
+le_uint32 PortableFontInstance::getRawChecksum() const
+{
+ // how big is it?
+ // fseek(fFile, 0L, SEEK_END);
+ // long size = ftell(fFile);
+ le_int32 chksum = 0;
+ // now, calculate
+ fseek(fFile, 0L, SEEK_SET);
+ int r;
+ int count =0;
+ while((r = fgetc(fFile)) != EOF) {
+ chksum += r;
+ count ++;
+ }
+ return (le_uint32) chksum; // cast to signed
+}
+
le_int32 PortableFontInstance::getAscent() const
{
return fAscent;
/*
*******************************************************************************
*
- * Copyright (C) 1999-2008, International Business Machines
+ * Copyright (C) 1999-2013, International Business Machines
* Corporation and others. All Rights Reserved.
*
*******************************************************************************
CMAPMapper *findUnicodeMapper();
protected:
- const void *readFontTable(LETag tableTag) const;
+ const void *readFontTable(LETag tableTag) const { size_t ignored; return readFontTable(tableTag, ignored); }
+ const void *readFontTable(LETag tableTag, size_t &length) const;
public:
PortableFontInstance(const char *fileName, float pointSize, LEErrorCode &status);
virtual ~PortableFontInstance();
virtual const void *getFontTable(LETag tableTag) const;
+ virtual const void *getFontTable(LETag tableTag, size_t &length) const;
virtual const char *getNameString(le_uint16 nameID, le_uint16 platform, le_uint16 encoding, le_uint16 language) const;
virtual le_uint32 getFontChecksum() const;
+ virtual le_uint32 getRawChecksum() const;
+
virtual le_int32 getAscent() const;
virtual le_int32 getDescent() const;
/***************************************************************************
*
-* Copyright (C) 1998-2003, International Business Machines
+* Copyright (C) 1998-2013, International Business Machines
* Corporation and others. All Rights Reserved.
*
************************************************************************/
#include "sfnt.h"
#include "cmaps.h"
+#include <stdio.h>
#define SWAPU16(code) ((LEUnicode16) SWAPW(code))
#define SWAPU32(code) ((LEUnicode32) SWAPL(code))
le_uint16 i;
le_uint16 nSubtables = SWAPW(cmap->numberSubtables);
const CMAPEncodingSubtable *subtable = NULL;
- le_uint32 offset1 = 0, offset10 = 0;
-
- for (i = 0; i < nSubtables; i += 1) {
+ le_bool found = FALSE;
+ le_uint16 foundPlatformID = 0xFFFF;
+ le_uint16 foundPlatformSpecificID = 0xFFFF;
+ le_uint32 foundOffset = 0;
+ le_uint16 foundTable = 0xFFFF;
+ // first pass, look for MS table. (preferred?)
+ for (i = 0; i < nSubtables && !found; i += 1) {
const CMAPEncodingSubtableHeader *esh = &cmap->encodingSubtableHeaders[i];
- if (SWAPW(esh->platformID) == 3) {
- switch (SWAPW(esh->platformSpecificID)) {
- case 1:
- offset1 = SWAPL(esh->encodingOffset);
+ le_uint16 platformID = SWAPW(esh->platformID);
+ le_uint16 platformSpecificID = SWAPW(esh->platformSpecificID);
+ if (platformID == 3) { // microsoft
+ switch (platformSpecificID) {
+ case 1: // Unicode BMP (UCS-2)
+ case 10: // Unicode UCS-4
+ foundOffset = SWAPL(esh->encodingOffset);
+ foundPlatformID = platformID;
+ foundPlatformSpecificID = platformSpecificID;
+ found = TRUE;
+ foundTable = i;
break;
- case 10:
- offset10 = SWAPL(esh->encodingOffset);
- break;
+ //default:
+ // printf("%s:%d: microsoft (3) platform specific ID %d (wanted 1 or 10) for subtable %d/%d\n", __FILE__, __LINE__, (SWAPW(esh->platformSpecificID)), i, nSubtables);
}
+ } else {
+ //printf("%s:%d: platform ID %d (wanted 3, microsoft) for subtable %d/%d\n", __FILE__, __LINE__, (SWAPW(esh->platformID)), i, nSubtables);
+ }
+ }
+
+ // second pass, allow non MS table
+ // first pass, look for MS table. (preferred?)
+ for (i = 0; i < nSubtables && !found; i += 1) {
+ const CMAPEncodingSubtableHeader *esh = &cmap->encodingSubtableHeaders[i];
+ le_uint16 platformID = SWAPW(esh->platformID);
+ le_uint16 platformSpecificID = SWAPW(esh->platformSpecificID);
+ //printf("%s:%d: table %d/%d has platform:specific %d:%d\n", __FILE__, __LINE__, i, nSubtables, platformID, platformSpecificID);
+ switch(platformID) {
+ case 0: // Unicode platform
+ switch(platformSpecificID) {
+ case 0:
+ case 1:
+ case 2:
+ case 3:
+ foundOffset = SWAPL(esh->encodingOffset);
+ foundPlatformID = platformID;
+ foundPlatformSpecificID = platformSpecificID;
+ foundTable = i;
+ found = TRUE;
+ break;
+
+ default: printf("Error: table %d (psid %d) is unknown. Skipping.\n", i, platformSpecificID); break;
+ }
+ break;
+
+ //default:
+ //printf("Skipping platform id %d\n", platformID);
}
}
- if (offset10 != 0)
+ if (found)
{
- subtable = (const CMAPEncodingSubtable *) ((const char *) cmap + offset10);
- } else if (offset1 != 0) {
- subtable = (const CMAPEncodingSubtable *) ((const char *) cmap + offset1);
+ subtable = (const CMAPEncodingSubtable *) ((const char *) cmap + foundOffset);
+ //printf("%s:%d: using subtable #%d/%d type %d:%d\n", __FILE__, __LINE__, foundTable, nSubtables, foundPlatformID, foundPlatformSpecificID);
} else {
- return NULL;
+ printf("%s:%d: could not find subtable.\n", __FILE__, __LINE__);
+ return NULL;
}
- switch (SWAPW(subtable->format)) {
+ le_uint16 tableFormat = SWAPW(subtable->format);
+ //printf("%s:%d: table format %d\n", __FILE__, __LINE__, tableFormat);
+
+ switch (tableFormat) {
case 4:
return new CMAPFormat4Mapper(cmap, (const CMAPFormat4Encoding *) subtable);
break;
}
+ printf("%s:%d: Unknown format %x.\n", __FILE__, __LINE__, (SWAPW(subtable->format)));
return NULL;
}
/*
*******************************************************************************
*
- * Copyright (C) 1999-2008, International Business Machines
+ * Copyright (C) 1999-2013, International Business Machines
* Corporation and others. All Rights Reserved.
*
*******************************************************************************
#include "unicode/unistr.h"
#include "unicode/uscript.h"
#include "unicode/ubidi.h"
+#include "unicode/ustring.h"
#include "layout/LETypes.h"
#include "layout/LEScripts.h"
U_NAMESPACE_USE
+static LEErrorCode overallStatus = LE_NO_ERROR;
struct TestInput
{
const char *fontName;
le_bool rightToLeft;
};
+/* Returns the path to icu/source/test/testdata/ */
+const char *getSourceTestData() {
+ const char *srcDataDir = NULL;
+#ifdef U_TOPSRCDIR
+ srcDataDir = U_TOPSRCDIR U_FILE_SEP_STRING "test" U_FILE_SEP_STRING "testdata" U_FILE_SEP_STRING;
+#else
+ srcDataDir = ".."U_FILE_SEP_STRING".."U_FILE_SEP_STRING"test"U_FILE_SEP_STRING"testdata"U_FILE_SEP_STRING;
+ FILE *f = fopen(".."U_FILE_SEP_STRING".."U_FILE_SEP_STRING"test"U_FILE_SEP_STRING"testdata"U_FILE_SEP_STRING"rbbitst.txt", "r");
+
+ if (f != NULL) {
+ /* We're in icu/source/test/letest/ */
+ fclose(f);
+ } else {
+ /* We're in icu/source/test/letest/(Debug|Release) */
+ srcDataDir = ".."U_FILE_SEP_STRING".."U_FILE_SEP_STRING".."U_FILE_SEP_STRING"test"U_FILE_SEP_STRING"testdata"U_FILE_SEP_STRING;
+ }
+#endif
+
+ return srcDataDir;
+}
+
+const char *getPath(char buffer[2048], const char *filename) {
+ const char *testDataDirectory = getSourceTestData();
+
+ strcpy(buffer, testDataDirectory);
+ strcat(buffer, filename);
+
+ return buffer;
+}
+
/*
* FIXME: should use the output file name and the current date.
*/
fprintf(file, " </%s>\n", tag);
}
-int main(int /*argc*/, char *argv[])
+int main(int argc, char *argv[])
{
UErrorCode status = U_ZERO_ERROR;
+ const char *gendataFile = "gendata.xml";
FILE *outputFile = fopen(argv[1], "w");
+ if(argc>2) {
+ gendataFile = argv[2];
+ }
time_t now = time(NULL);
struct tm *local = localtime(&now);
const char *tmFormat = "%m/%d/%Y %I:%M:%S %p %Z";
char tmString[64];
-
+ le_uint32 count = 0;
strftime(tmString, 64, tmFormat, local);
fprintf(outputFile, header, local->tm_year + 1900, tmString);
UXMLParser *parser = UXMLParser::createParser(status);
- UXMLElement *root = parser->parseFile("gendata.xml", status);
+ UXMLElement *root = parser->parseFile(gendataFile, status);
if (root == NULL) {
- printf("Error: Could not open gendata.xml\n");
+ printf("Error: Could not open %s\n", gendataFile);
delete parser;
return -1;
+ } else if(U_FAILURE(status)) {
+ printf("Error reading %s: %s\n", gendataFile, u_errorName(status));
+ return -2;
+ } else {
+ printf("Reading %s\n", gendataFile);
}
UnicodeString test_case = UNICODE_STRING_SIMPLE("test-case");
char *id = getCString(testCase->getAttribute(id_attr));
char *script = getCString(testCase->getAttribute(script_attr));
char *lang = getCString(testCase->getAttribute(lang_attr));
+ ++count;
+ printf("\n ID %s\n", id);
LEFontInstance *font = NULL;
const UXMLElement *element;
int32_t ec = 0;
int32_t charCount = 0;
- int32_t typoFlags = 3; // kerning + ligatures...
+ int32_t typoFlags = LayoutEngine::kTypoFlagKern | LayoutEngine::kTypoFlagLiga; // kerning + ligatures...
UScriptCode scriptCode;
le_int32 languageCode = -1;
UnicodeString text;
if (tag.compare(test_font) == 0) {
char *fontName = getCString(element->getAttribute(name_attr));
const char *version = NULL;
- PortableFontInstance *pfi = new PortableFontInstance(fontName, 12, leStatus);
+ char buf[2048];
+ PortableFontInstance *pfi = new PortableFontInstance(getPath(buf,fontName), 12, leStatus);
if (LE_FAILURE(leStatus)) {
- printf("Error: could not open font: %s\n", fontName);
+ printf("Error: could not open font: %s (path: %s)\n", fontName, buf);
freeCString(fontName);
goto free_c_strings;
}
+ printf(" Generating: %s, %s, %s, %s\n", id, script, lang, fontName);
+
version = pfi->getNameString(NAME_VERSION_STRING, PLATFORM_MACINTOSH, MACINTOSH_ROMAN, MACINTOSH_ENGLISH);
// The standard recommends that the Macintosh Roman/English name string be present, but
const LEUnicode16 *uversion = pfi->getUnicodeNameString(NAME_VERSION_STRING, PLATFORM_MICROSOFT, MICROSOFT_UNICODE_BMP, MICROSOFT_ENGLISH);
if (uversion != NULL) {
- fprintf(outputFile, " <test-font name=\"%s\" version=\"%S\" checksum=\"0x%8.8X\"/>\n\n",
- fontName, uversion, pfi->getFontChecksum());
+ char uversion_utf8[300];
+ UErrorCode status2 = U_ZERO_ERROR;
+ u_strToUTF8(uversion_utf8, 300, NULL, uversion, -1, &status2);
+ if(U_FAILURE(status2)) {
+ uversion_utf8[0]=0;
+ }
+ fprintf(outputFile, " <test-font name=\"%s\" version=\"%s\" checksum=\"0x%8.8X\" rchecksum=\"0x%8.8X\"/>\n\n",
+ fontName, uversion_utf8, pfi->getFontChecksum(), pfi->getRawChecksum());
pfi->deleteNameString(uversion);
+ } else {
+ fprintf(outputFile, " <test-font name=\"%s\" version=\"unknown-0x%8.8X\" checksum=\"0x%8.8X\" rchecksum=\"0x%8.8X\"/>\n\n",
+ fontName, pfi->getFontChecksum(), pfi->getFontChecksum(), pfi->getRawChecksum());
}
} else {
- fprintf(outputFile, " <test-font name=\"%s\" version=\"%s\" checksum=\"0x%8.8X\"/>\n\n",
- fontName, version, pfi->getFontChecksum());
+ fprintf(outputFile, " <test-font name=\"%s\" version=\"%s\" checksum=\"0x%8.8X\" rchecksum=\"0x%8.8X\"/>\n\n",
+ fontName, version, pfi->getFontChecksum(), pfi->getRawChecksum());
pfi->deleteNameString(version);
}
+ fflush(outputFile);
freeCString(fontName);
utf8 = getUTF8String(&text);
fprintf(outputFile, " <test-text>%s</test-text>\n\n", utf8);
+ fflush(outputFile);
freeCString(utf8);
} else {
// an unknown tag...
engine->getCharIndices(indices, leStatus);
engine->getGlyphPositions(positions, leStatus);
- dumpLongs(outputFile, "result-glyphs", (le_int32 *) glyphs, glyphCount);
-
- dumpLongs(outputFile, "result-indices", indices, glyphCount);
-
- dumpFloats(outputFile, "result-positions", positions, glyphCount * 2 + 2);
+ if(LE_FAILURE(leStatus)) {
+ fprintf(stderr,"ERROR: LO returned error: %s\n", u_errorName((UErrorCode)leStatus));
+ overallStatus = leStatus;
+ fprintf(outputFile, "<!-- ERROR: %d -->\n", leStatus);
+ fflush(outputFile);
+ leStatus = LE_NO_ERROR;
+ } else {
+ dumpLongs(outputFile, "result-glyphs", (le_int32 *) glyphs, glyphCount);
+
+ dumpLongs(outputFile, "result-indices", indices, glyphCount);
+
+ dumpFloats(outputFile, "result-positions", positions, glyphCount * 2 + 2);
+ fflush(outputFile);
- fprintf(outputFile, " </test-case>\n\n");
+ }
DELETE_ARRAY(positions);
DELETE_ARRAY(indices);
delete engine;
delete_font:
+ fprintf(outputFile, " </test-case>\n\n");
+ fflush(outputFile);
+
delete font;
free_c_strings:
fprintf(outputFile, "</layout-tests>\n");
- fclose(outputFile);
+ if(count==0) {
+ fprintf(stderr, "No cases processed!\n");
+ return 1;
+ }
+
+
+ if(LE_FAILURE(overallStatus)) {
+ fprintf(outputFile, "<!-- !!! FAILED. %d -->\n", overallStatus);
+ fprintf(stderr, "!!! FAILED. %d\n", overallStatus);
+ fclose(outputFile);
+ return 0;
+ // return 1;
+ } else {
+ printf("Generated.\n");
+ fclose(outputFile);
+ return 0;
+ }
}
const char *getSourceTestData() {
const char *srcDataDir = NULL;
#ifdef U_TOPSRCDIR
- srcDataDir = U_TOPSRCDIR U_FILE_SEP_STRING "test" U_FILE_SEP_STRING "testdata" U_FILE_SEP_STRING;
+ srcDataDir = U_TOPSRCDIR U_FILE_SEP_STRING "test" U_FILE_SEP_STRING "testdata" U_FILE_SEP_STRING;
#else
srcDataDir = ".."U_FILE_SEP_STRING".."U_FILE_SEP_STRING"test"U_FILE_SEP_STRING"testdata"U_FILE_SEP_STRING;
FILE *f = fopen(".."U_FILE_SEP_STRING".."U_FILE_SEP_STRING"test"U_FILE_SEP_STRING"testdata"U_FILE_SEP_STRING"rbbitst.txt", "r");