mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-08 06:53:45 +00:00
ICU-10107 Improve test generation
X-SVN-Rev: 33530
This commit is contained in:
parent
a73a199d84
commit
f56d218cb7
8 changed files with 245 additions and 56 deletions
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
**********************************************************************
|
||||
* Copyright (C) 2003-2008, International Business Machines
|
||||
* Copyright (C) 2003-2013, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
**********************************************************************
|
||||
*/
|
||||
|
@ -15,8 +15,9 @@
|
|||
|
||||
struct FontTableCacheEntry
|
||||
{
|
||||
LETag tag;
|
||||
const void *table;
|
||||
LETag tag;
|
||||
const void *table;
|
||||
size_t length;
|
||||
};
|
||||
|
||||
FontTableCache::FontTableCache()
|
||||
|
@ -32,6 +33,7 @@ FontTableCache::FontTableCache()
|
|||
for (int i = 0; i < fTableCacheSize; i += 1) {
|
||||
fTableCache[i].tag = 0;
|
||||
fTableCache[i].table = NULL;
|
||||
fTableCache[i].length = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,6 +44,7 @@ FontTableCache::~FontTableCache()
|
|||
|
||||
fTableCache[i].tag = 0;
|
||||
fTableCache[i].table = NULL;
|
||||
fTableCache[i].length = 0;
|
||||
}
|
||||
|
||||
fTableCacheCurr = 0;
|
||||
|
@ -54,22 +57,23 @@ void FontTableCache::freeFontTable(const void *table) const
|
|||
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;
|
||||
|
@ -79,6 +83,7 @@ void FontTableCache::add(LETag tableTag, const void *table)
|
|||
for (le_int32 i = fTableCacheSize; i < newSize; i += 1) {
|
||||
fTableCache[i].tag = 0;
|
||||
fTableCache[i].table = NULL;
|
||||
fTableCache[i].length = 0;
|
||||
}
|
||||
|
||||
fTableCacheSize = newSize;
|
||||
|
@ -86,6 +91,7 @@ void FontTableCache::add(LETag tableTag, const void *table)
|
|||
|
||||
fTableCache[fTableCacheCurr].tag = tableTag;
|
||||
fTableCache[fTableCacheCurr].table = table;
|
||||
fTableCache[fTableCacheCurr].length = length;
|
||||
|
||||
fTableCacheCurr += 1;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
**********************************************************************
|
||||
* Copyright (C) 2003-2008, International Business Machines
|
||||
* Copyright (C) 2003-2013, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
**********************************************************************
|
||||
*/
|
||||
|
@ -22,15 +22,15 @@ public:
|
|||
|
||||
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;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
## 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
|
||||
|
@ -90,6 +90,9 @@ $(GENTARGET) : $(COMMONOBJECTS) $(GENOBJECTS)
|
|||
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
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
*******************************************************************************
|
||||
*
|
||||
* Copyright (C) 1999-2008, International Business Machines
|
||||
* Copyright (C) 1999-2013, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
*
|
||||
*******************************************************************************
|
||||
|
@ -23,6 +23,18 @@
|
|||
#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
|
||||
|
@ -74,8 +86,10 @@ PortableFontInstance::PortableFontInstance(const char *fileName, float pointSize
|
|||
|
||||
// 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;
|
||||
}
|
||||
|
@ -96,6 +110,7 @@ PortableFontInstance::PortableFontInstance(const char *fileName, float pointSize
|
|||
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;
|
||||
}
|
||||
|
@ -116,6 +131,7 @@ PortableFontInstance::PortableFontInstance(const char *fileName, float pointSize
|
|||
|
||||
if (headTable == NULL) {
|
||||
status = LE_MISSING_FONT_TABLE_ERROR;
|
||||
printf("%s:%d: %s: missing head table\n", __FILE__, __LINE__, fileName);
|
||||
goto error_exit;
|
||||
}
|
||||
|
||||
|
@ -142,6 +158,7 @@ PortableFontInstance::PortableFontInstance(const char *fileName, float pointSize
|
|||
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;
|
||||
}
|
||||
|
@ -157,6 +174,7 @@ PortableFontInstance::PortableFontInstance(const char *fileName, float pointSize
|
|||
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;
|
||||
}
|
||||
|
@ -232,14 +250,24 @@ const void *PortableFontInstance::readTable(LETag tag, le_uint32 *length) const
|
|||
|
||||
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()
|
||||
|
@ -381,6 +409,23 @@ le_uint32 PortableFontInstance::getFontChecksum() const
|
|||
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;
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/*
|
||||
*******************************************************************************
|
||||
*
|
||||
* Copyright (C) 1999-2008, International Business Machines
|
||||
* Copyright (C) 1999-2013, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
*
|
||||
*******************************************************************************
|
||||
|
@ -63,7 +63,8 @@ private:
|
|||
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);
|
||||
|
@ -71,6 +72,7 @@ public:
|
|||
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;
|
||||
|
||||
|
@ -84,6 +86,8 @@ public:
|
|||
|
||||
virtual le_uint32 getFontChecksum() const;
|
||||
|
||||
virtual le_uint32 getRawChecksum() const;
|
||||
|
||||
virtual le_int32 getAscent() const;
|
||||
|
||||
virtual le_int32 getDescent() const;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/***************************************************************************
|
||||
*
|
||||
* Copyright (C) 1998-2003, International Business Machines
|
||||
* Copyright (C) 1998-2013, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
*
|
||||
************************************************************************/
|
||||
|
@ -10,6 +10,7 @@
|
|||
|
||||
#include "sfnt.h"
|
||||
#include "cmaps.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#define SWAPU16(code) ((LEUnicode16) SWAPW(code))
|
||||
#define SWAPU32(code) ((LEUnicode32) SWAPL(code))
|
||||
|
@ -55,35 +56,80 @@ CMAPMapper *CMAPMapper::createUnicodeMapper(const CMAPTable *cmap)
|
|||
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);
|
||||
|
||||
|
@ -98,6 +144,7 @@ CMAPMapper *CMAPMapper::createUnicodeMapper(const CMAPTable *cmap)
|
|||
break;
|
||||
}
|
||||
|
||||
printf("%s:%d: Unknown format %x.\n", __FILE__, __LINE__, (SWAPW(subtable->format)));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
*******************************************************************************
|
||||
*
|
||||
* Copyright (C) 1999-2008, International Business Machines
|
||||
* Copyright (C) 1999-2013, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
*
|
||||
*******************************************************************************
|
||||
|
@ -19,6 +19,7 @@
|
|||
#include "unicode/unistr.h"
|
||||
#include "unicode/uscript.h"
|
||||
#include "unicode/ubidi.h"
|
||||
#include "unicode/ustring.h"
|
||||
|
||||
#include "layout/LETypes.h"
|
||||
#include "layout/LEScripts.h"
|
||||
|
@ -34,6 +35,7 @@
|
|||
|
||||
U_NAMESPACE_USE
|
||||
|
||||
static LEErrorCode overallStatus = LE_NO_ERROR;
|
||||
struct TestInput
|
||||
{
|
||||
const char *fontName;
|
||||
|
@ -43,6 +45,36 @@ struct TestInput
|
|||
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.
|
||||
*/
|
||||
|
@ -109,25 +141,34 @@ void dumpFloats(FILE *file, const char *tag, float *floats, le_int32 count) {
|
|||
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");
|
||||
|
@ -150,11 +191,13 @@ int main(int /*argc*/, char *argv[])
|
|||
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;
|
||||
|
@ -191,14 +234,17 @@ int main(int /*argc*/, char *argv[])
|
|||
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
|
||||
|
@ -207,17 +253,27 @@ int main(int /*argc*/, char *argv[])
|
|||
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);
|
||||
|
||||
|
@ -230,6 +286,7 @@ int main(int /*argc*/, char *argv[])
|
|||
|
||||
utf8 = getUTF8String(&text);
|
||||
fprintf(outputFile, " <test-text>%s</test-text>\n\n", utf8);
|
||||
fflush(outputFile);
|
||||
freeCString(utf8);
|
||||
} else {
|
||||
// an unknown tag...
|
||||
|
@ -264,13 +321,21 @@ int main(int /*argc*/, char *argv[])
|
|||
engine->getCharIndices(indices, leStatus);
|
||||
engine->getGlyphPositions(positions, leStatus);
|
||||
|
||||
dumpLongs(outputFile, "result-glyphs", (le_int32 *) glyphs, glyphCount);
|
||||
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);
|
||||
|
||||
dumpLongs(outputFile, "result-indices", indices, glyphCount);
|
||||
|
||||
dumpFloats(outputFile, "result-positions", positions, glyphCount * 2 + 2);
|
||||
|
||||
fprintf(outputFile, " </test-case>\n\n");
|
||||
}
|
||||
|
||||
DELETE_ARRAY(positions);
|
||||
DELETE_ARRAY(indices);
|
||||
|
@ -279,6 +344,9 @@ int main(int /*argc*/, char *argv[])
|
|||
delete engine;
|
||||
|
||||
delete_font:
|
||||
fprintf(outputFile, " </test-case>\n\n");
|
||||
fflush(outputFile);
|
||||
|
||||
delete font;
|
||||
|
||||
free_c_strings:
|
||||
|
@ -293,5 +361,21 @@ 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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -413,7 +413,7 @@ static void checkFontVersion(PortableFontInstance *fontInstance, const char *tes
|
|||
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");
|
||||
|
|
Loading…
Add table
Reference in a new issue