os/textandloc/fontservices/textshaperplugin/IcuSource/layout/ClassDefinitionTables.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/textandloc/fontservices/textshaperplugin/IcuSource/layout/ClassDefinitionTables.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,120 @@
1.4 +/*
1.5 + *
1.6 + * (C) Copyright IBM Corp. 1998-2004 - All Rights Reserved
1.7 + *
1.8 + */
1.9 +
1.10 +#include "LETypes.h"
1.11 +#include "OpenTypeTables.h"
1.12 +#include "OpenTypeUtilities.h"
1.13 +#include "ClassDefinitionTables.h"
1.14 +#include "LESwaps.h"
1.15 +
1.16 +U_NAMESPACE_BEGIN
1.17 +
1.18 +le_int32 ClassDefinitionTable::getGlyphClass(LEGlyphID glyphID) const
1.19 +{
1.20 + switch(SWAPW(classFormat)) {
1.21 + case 0:
1.22 + return 0;
1.23 +
1.24 + case 1:
1.25 + {
1.26 + const ClassDefFormat1Table *f1Table = (const ClassDefFormat1Table *) this;
1.27 +
1.28 + return f1Table->getGlyphClass(glyphID);
1.29 + }
1.30 +
1.31 + case 2:
1.32 + {
1.33 + const ClassDefFormat2Table *f2Table = (const ClassDefFormat2Table *) this;
1.34 +
1.35 + return f2Table->getGlyphClass(glyphID);
1.36 + }
1.37 +
1.38 + default:
1.39 + return 0;
1.40 + }
1.41 +}
1.42 +
1.43 +le_bool ClassDefinitionTable::hasGlyphClass(le_int32 glyphClass) const
1.44 +{
1.45 + switch(SWAPW(classFormat)) {
1.46 + case 0:
1.47 + return 0;
1.48 +
1.49 + case 1:
1.50 + {
1.51 + const ClassDefFormat1Table *f1Table = (const ClassDefFormat1Table *) this;
1.52 +
1.53 + return f1Table->hasGlyphClass(glyphClass);
1.54 + }
1.55 +
1.56 + case 2:
1.57 + {
1.58 + const ClassDefFormat2Table *f2Table = (const ClassDefFormat2Table *) this;
1.59 +
1.60 + return f2Table->hasGlyphClass(glyphClass);
1.61 + }
1.62 +
1.63 + default:
1.64 + return 0;
1.65 + }
1.66 +}
1.67 +
1.68 +le_int32 ClassDefFormat1Table::getGlyphClass(LEGlyphID glyphID) const
1.69 +{
1.70 + TTGlyphID ttGlyphID = (TTGlyphID) LE_GET_GLYPH(glyphID);
1.71 + TTGlyphID firstGlyph = SWAPW(startGlyph);
1.72 + TTGlyphID lastGlyph = firstGlyph + SWAPW(glyphCount);
1.73 +
1.74 + if (ttGlyphID > firstGlyph && ttGlyphID < lastGlyph) {
1.75 + return SWAPW(classValueArray[ttGlyphID - firstGlyph]);
1.76 + }
1.77 +
1.78 + return 0;
1.79 +}
1.80 +
1.81 +le_bool ClassDefFormat1Table::hasGlyphClass(le_int32 glyphClass) const
1.82 +{
1.83 + le_uint16 count = SWAPW(glyphCount);
1.84 + int i;
1.85 +
1.86 + for (i = 0; i < count; i += 1) {
1.87 + if (SWAPW(classValueArray[i]) == glyphClass) {
1.88 + return TRUE;
1.89 + }
1.90 + }
1.91 +
1.92 + return FALSE;
1.93 +}
1.94 +
1.95 +le_int32 ClassDefFormat2Table::getGlyphClass(LEGlyphID glyphID) const
1.96 +{
1.97 + TTGlyphID ttGlyph = (TTGlyphID) LE_GET_GLYPH(glyphID);
1.98 + le_uint16 rangeCount = SWAPW(classRangeCount);
1.99 + le_int32 rangeIndex =
1.100 + OpenTypeUtilities::getGlyphRangeIndex(ttGlyph, classRangeRecordArray, rangeCount);
1.101 +
1.102 + if (rangeIndex < 0) {
1.103 + return 0;
1.104 + }
1.105 +
1.106 + return SWAPW(classRangeRecordArray[rangeIndex].rangeValue);
1.107 +}
1.108 +
1.109 +le_bool ClassDefFormat2Table::hasGlyphClass(le_int32 glyphClass) const
1.110 +{
1.111 + le_uint16 rangeCount = SWAPW(classRangeCount);
1.112 + int i;
1.113 +
1.114 + for (i = 0; i < rangeCount; i += 1) {
1.115 + if (SWAPW(classRangeRecordArray[i].rangeValue) == glyphClass) {
1.116 + return TRUE;
1.117 + }
1.118 + }
1.119 +
1.120 + return FALSE;
1.121 +}
1.122 +
1.123 +U_NAMESPACE_END