Update contrib.
2 *******************************************************************************
4 * Copyright (C) 1999-2003, International Business Machines
5 * Corporation and others. All Rights Reserved.
7 *******************************************************************************
8 * file name: letest.cpp
10 * created on: 11/06/2000
11 * created by: Eric R. Mader
17 #include "LayoutEngine.h"
18 #include "PortableFontInstance.h"
24 le_bool compareResults(le_int32 testNumber, TestResult *expected, TestResult *actual)
26 /* NOTE: we'll stop on the first failure 'cause once there's one error, it may cascade... */
27 if (actual->glyphCount != expected->glyphCount) {
28 printf("incorrect glyph count: exptected %d, got %d\n", expected->glyphCount, actual->glyphCount);
34 for (i = 0; i < actual->glyphCount; i += 1) {
35 if (actual->glyphs[i] != expected->glyphs[i]) {
36 printf("incorrect id for glyph %d: expected %4X, got %4X\n", i, expected->glyphs[i], actual->glyphs[i]);
41 for (i = 0; i < actual->glyphCount; i += 1) {
42 if (actual->indices[i] != expected->indices[i]) {
43 printf("incorrect index for glyph %d: expected %8X, got %8X\n", i, expected->indices[i], actual->indices[i]);
48 for (i = 0; i <= actual->glyphCount; i += 1) {
49 double xError = fabs(actual->positions[i * 2] - expected->positions[i * 2]);
51 if (xError > 0.0001) {
52 printf("incorrect x position for glyph %d: expected %f, got %f\n", i, expected->positions[i * 2], actual->positions[i * 2]);
56 double yError = fabs(actual->positions[i * 2 + 1] - expected->positions[i * 2 + 1]);
62 if (yError > 0.0001) {
63 printf("incorrect y position for glyph %d: expected %f, got %f\n", i, expected->positions[i * 2 + 1], actual->positions[i * 2 + 1]);
73 le_int32 failures = 0;
75 for (le_int32 test = 0; test < testCount; test += 1) {
76 LEErrorCode fontStatus = LE_NO_ERROR;
78 printf("Test %d, font = %s... ", test, testInputs[test].fontName);
80 PortableFontInstance fontInstance(testInputs[test].fontName, 12, fontStatus);
82 if (LE_FAILURE(fontStatus)) {
83 printf("could not open font.\n");
87 LEErrorCode success = LE_NO_ERROR;
88 LayoutEngine *engine = LayoutEngine::layoutEngineFactory(&fontInstance, testInputs[test].scriptCode, -1, success);
89 le_int32 textLength = testInputs[test].textLength;
93 if (LE_FAILURE(success)) {
94 // would be nice to print the script name here, but
95 // don't want to maintain a table, and don't want to
96 // require ICU just for the script name...
97 printf("could not create a LayoutEngine.\n");
101 actual.glyphCount = engine->layoutChars(testInputs[test].text, 0, textLength, textLength, testInputs[test].rightToLeft, 0, 0, success);
103 actual.glyphs = new LEGlyphID[actual.glyphCount];
104 actual.indices = new le_int32[actual.glyphCount];
105 actual.positions = new float[actual.glyphCount * 2 + 2];
107 engine->getGlyphs(actual.glyphs, success);
108 engine->getCharIndices(actual.indices, success);
109 engine->getGlyphPositions(actual.positions, success);
111 result = compareResults(test, &testResults[test], &actual);
120 delete[] actual.positions;
121 delete[] actual.indices;
122 delete[] actual.glyphs;