2001-10-03 21:48:10 +00:00
|
|
|
/*
|
|
|
|
*******************************************************************************
|
|
|
|
*
|
2003-06-03 20:58:22 +00:00
|
|
|
* Copyright (C) 1999-2003, International Business Machines
|
2001-10-03 21:48:10 +00:00
|
|
|
* Corporation and others. All Rights Reserved.
|
|
|
|
*
|
|
|
|
*******************************************************************************
|
|
|
|
* file name: letest.cpp
|
|
|
|
*
|
|
|
|
* created on: 11/06/2000
|
|
|
|
* created by: Eric R. Mader
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "math.h"
|
|
|
|
|
2003-02-05 00:12:26 +00:00
|
|
|
#include "LETypes.h"
|
|
|
|
#include "LayoutEngine.h"
|
2001-10-03 21:48:10 +00:00
|
|
|
#include "PortableFontInstance.h"
|
|
|
|
|
|
|
|
#include "letest.h"
|
|
|
|
|
2001-10-16 00:39:01 +00:00
|
|
|
U_NAMESPACE_USE
|
|
|
|
|
2003-02-05 00:12:26 +00:00
|
|
|
le_bool compareResults(le_int32 testNumber, TestResult *expected, TestResult *actual)
|
2001-10-03 21:48:10 +00:00
|
|
|
{
|
2002-04-02 02:55:31 +00:00
|
|
|
/* NOTE: we'll stop on the first failure 'cause once there's one error, it may cascade... */
|
|
|
|
if (actual->glyphCount != expected->glyphCount) {
|
|
|
|
printf("incorrect glyph count: exptected %d, got %d\n", expected->glyphCount, actual->glyphCount);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2003-02-05 00:12:26 +00:00
|
|
|
le_int32 i;
|
2002-04-02 02:55:31 +00:00
|
|
|
|
|
|
|
for (i = 0; i < actual->glyphCount; i += 1) {
|
|
|
|
if (actual->glyphs[i] != expected->glyphs[i]) {
|
|
|
|
printf("incorrect id for glyph %d: expected %4X, got %4X\n", i, expected->glyphs[i], actual->glyphs[i]);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < actual->glyphCount; i += 1) {
|
|
|
|
if (actual->indices[i] != expected->indices[i]) {
|
|
|
|
printf("incorrect index for glyph %d: expected %8X, got %8X\n", i, expected->indices[i], actual->indices[i]);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i <= actual->glyphCount; i += 1) {
|
|
|
|
double xError = fabs(actual->positions[i * 2] - expected->positions[i * 2]);
|
|
|
|
|
|
|
|
if (xError > 0.0001) {
|
|
|
|
printf("incorrect x position for glyph %d: expected %f, got %f\n", i, expected->positions[i * 2], actual->positions[i * 2]);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
double yError = fabs(actual->positions[i * 2 + 1] - expected->positions[i * 2 + 1]);
|
|
|
|
|
|
|
|
if (yError < 0) {
|
|
|
|
yError = -yError;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (yError > 0.0001) {
|
|
|
|
printf("incorrect y position for glyph %d: expected %f, got %f\n", i, expected->positions[i * 2 + 1], actual->positions[i * 2 + 1]);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2001-10-03 21:48:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2003-02-05 00:12:26 +00:00
|
|
|
le_int32 failures = 0;
|
2001-10-03 21:48:10 +00:00
|
|
|
|
2003-02-05 00:12:26 +00:00
|
|
|
for (le_int32 test = 0; test < testCount; test += 1) {
|
2003-03-03 22:54:57 +00:00
|
|
|
LEErrorCode fontStatus = LE_NO_ERROR;
|
2001-10-03 21:48:10 +00:00
|
|
|
|
|
|
|
printf("Test %d, font = %s... ", test, testInputs[test].fontName);
|
|
|
|
|
2002-04-02 02:55:31 +00:00
|
|
|
PortableFontInstance fontInstance(testInputs[test].fontName, 12, fontStatus);
|
2001-10-03 21:48:10 +00:00
|
|
|
|
|
|
|
if (LE_FAILURE(fontStatus)) {
|
|
|
|
printf("could not open font.\n");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2003-02-05 00:12:26 +00:00
|
|
|
LEErrorCode success = LE_NO_ERROR;
|
|
|
|
LayoutEngine *engine = LayoutEngine::layoutEngineFactory(&fontInstance, testInputs[test].scriptCode, -1, success);
|
|
|
|
le_int32 textLength = testInputs[test].textLength;
|
|
|
|
le_bool result;
|
2002-04-02 02:55:31 +00:00
|
|
|
TestResult actual;
|
2001-10-03 21:48:10 +00:00
|
|
|
|
|
|
|
if (LE_FAILURE(success)) {
|
|
|
|
// would be nice to print the script name here, but
|
2003-02-05 00:12:26 +00:00
|
|
|
// don't want to maintain a table, and don't want to
|
|
|
|
// require ICU just for the script name...
|
2001-10-03 21:48:10 +00:00
|
|
|
printf("could not create a LayoutEngine.\n");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
actual.glyphCount = engine->layoutChars(testInputs[test].text, 0, textLength, textLength, testInputs[test].rightToLeft, 0, 0, success);
|
|
|
|
|
2003-02-05 00:12:26 +00:00
|
|
|
actual.glyphs = new LEGlyphID[actual.glyphCount];
|
|
|
|
actual.indices = new le_int32[actual.glyphCount];
|
2002-04-02 02:55:31 +00:00
|
|
|
actual.positions = new float[actual.glyphCount * 2 + 2];
|
2001-10-03 21:48:10 +00:00
|
|
|
|
2002-04-02 02:55:31 +00:00
|
|
|
engine->getGlyphs(actual.glyphs, success);
|
|
|
|
engine->getCharIndices(actual.indices, success);
|
|
|
|
engine->getGlyphPositions(actual.positions, success);
|
2001-10-03 21:48:10 +00:00
|
|
|
|
2002-04-02 02:55:31 +00:00
|
|
|
result = compareResults(test, &testResults[test], &actual);
|
2001-10-03 21:48:10 +00:00
|
|
|
|
2002-04-02 02:55:31 +00:00
|
|
|
if (result) {
|
|
|
|
printf("passed.\n");
|
|
|
|
} else {
|
|
|
|
failures += 1;
|
|
|
|
printf("failed.\n");
|
|
|
|
}
|
2001-10-03 21:48:10 +00:00
|
|
|
|
2002-04-02 02:55:31 +00:00
|
|
|
delete[] actual.positions;
|
|
|
|
delete[] actual.indices;
|
|
|
|
delete[] actual.glyphs;
|
2003-02-05 00:12:26 +00:00
|
|
|
delete engine;
|
2002-04-02 02:55:31 +00:00
|
|
|
}
|
2001-10-03 21:48:10 +00:00
|
|
|
|
2002-04-02 02:55:31 +00:00
|
|
|
return failures;
|
2001-10-03 21:48:10 +00:00
|
|
|
}
|