comparison src/share/native/sun/font/layout/StateTableProcessor2.cpp @ 5725:6784c9903db7

8004986: Better handling of glyph table 8004987: Improve font layout 8004994: Improve checking of glyph table Reviewed-by: bae, mschoene, jgodinez Contributed-by: steven.loomis@oracle.com
author prr
date Mon, 25 Feb 2013 09:52:53 -0800
parents 8a95f38503fe
children 245c2dce7225
comparison
equal deleted inserted replaced
0:a510d2b00ca1 1:94eb2e9a1add
36 #include "SubtableProcessor2.h" 36 #include "SubtableProcessor2.h"
37 #include "StateTableProcessor2.h" 37 #include "StateTableProcessor2.h"
38 #include "LEGlyphStorage.h" 38 #include "LEGlyphStorage.h"
39 #include "LESwaps.h" 39 #include "LESwaps.h"
40 #include "LookupTables.h" 40 #include "LookupTables.h"
41 #include <stdio.h>
42 41
43 U_NAMESPACE_BEGIN 42 U_NAMESPACE_BEGIN
44 43
45 StateTableProcessor2::StateTableProcessor2() 44 StateTableProcessor2::StateTableProcessor2()
46 { 45 {
69 { 68 {
70 // Start at state 0 69 // Start at state 0
71 // XXX: How do we know when to start at state 1? 70 // XXX: How do we know when to start at state 1?
72 le_uint16 currentState = 0; 71 le_uint16 currentState = 0;
73 le_int32 glyphCount = glyphStorage.getGlyphCount(); 72 le_int32 glyphCount = glyphStorage.getGlyphCount();
73
74 LE_STATE_PATIENCE_INIT();
74 75
75 le_int32 currGlyph = 0; 76 le_int32 currGlyph = 0;
76 if ((coverage & scfReverse2) != 0) { // process glyphs in descending order 77 if ((coverage & scfReverse2) != 0) { // process glyphs in descending order
77 currGlyph = glyphCount - 1; 78 currGlyph = glyphCount - 1;
78 dir = -1; 79 dir = -1;
84 switch (format) { 85 switch (format) {
85 case ltfSimpleArray: { 86 case ltfSimpleArray: {
86 #ifdef TEST_FORMAT 87 #ifdef TEST_FORMAT
87 SimpleArrayLookupTable *lookupTable0 = (SimpleArrayLookupTable *) classTable; 88 SimpleArrayLookupTable *lookupTable0 = (SimpleArrayLookupTable *) classTable;
88 while ((dir == 1 && currGlyph <= glyphCount) || (dir == -1 && currGlyph >= -1)) { 89 while ((dir == 1 && currGlyph <= glyphCount) || (dir == -1 && currGlyph >= -1)) {
90 if(LE_STATE_PATIENCE_DECR()) {
91 LE_DEBUG_BAD_FONT("patience exceeded - state table not moving")
92 break; // patience exceeded.
93 }
89 LookupValue classCode = classCodeOOB; 94 LookupValue classCode = classCodeOOB;
90 if (currGlyph == glyphCount || currGlyph == -1) { 95 if (currGlyph == glyphCount || currGlyph == -1) {
91 // XXX: How do we handle EOT vs. EOL? 96 // XXX: How do we handle EOT vs. EOL?
92 classCode = classCodeEOT; 97 classCode = classCodeEOT;
93 } else { 98 } else {
99 } else { 104 } else {
100 classCode = SWAPW(lookupTable0->valueArray[gid]); 105 classCode = SWAPW(lookupTable0->valueArray[gid]);
101 } 106 }
102 } 107 }
103 EntryTableIndex2 entryTableIndex = SWAPW(stateArray[classCode + currentState * nClasses]); 108 EntryTableIndex2 entryTableIndex = SWAPW(stateArray[classCode + currentState * nClasses]);
109 LE_STATE_PATIENCE_CURR(le_int32, currGlyph);
104 currentState = processStateEntry(glyphStorage, currGlyph, entryTableIndex); // return a zero-based index instead of a byte offset 110 currentState = processStateEntry(glyphStorage, currGlyph, entryTableIndex); // return a zero-based index instead of a byte offset
111 LE_STATE_PATIENCE_INCR(currGlyph);
105 } 112 }
106 #endif 113 #endif
107 break; 114 break;
108 } 115 }
109 case ltfSegmentSingle: { 116 case ltfSegmentSingle: {
110 SegmentSingleLookupTable *lookupTable2 = (SegmentSingleLookupTable *) classTable; 117 SegmentSingleLookupTable *lookupTable2 = (SegmentSingleLookupTable *) classTable;
111 while ((dir == 1 && currGlyph <= glyphCount) || (dir == -1 && currGlyph >= -1)) { 118 while ((dir == 1 && currGlyph <= glyphCount) || (dir == -1 && currGlyph >= -1)) {
119 if(LE_STATE_PATIENCE_DECR()) {
120 LE_DEBUG_BAD_FONT("patience exceeded - state table not moving")
121 break; // patience exceeded.
122 }
112 LookupValue classCode = classCodeOOB; 123 LookupValue classCode = classCodeOOB;
113 if (currGlyph == glyphCount || currGlyph == -1) { 124 if (currGlyph == glyphCount || currGlyph == -1) {
114 // XXX: How do we handle EOT vs. EOL? 125 // XXX: How do we handle EOT vs. EOL?
115 classCode = classCodeEOT; 126 classCode = classCodeEOT;
116 } else { 127 } else {
125 classCode = SWAPW(segment->value); 136 classCode = SWAPW(segment->value);
126 } 137 }
127 } 138 }
128 } 139 }
129 EntryTableIndex2 entryTableIndex = SWAPW(stateArray[classCode + currentState * nClasses]); 140 EntryTableIndex2 entryTableIndex = SWAPW(stateArray[classCode + currentState * nClasses]);
141 LE_STATE_PATIENCE_CURR(le_int32, currGlyph);
130 currentState = processStateEntry(glyphStorage, currGlyph, entryTableIndex); 142 currentState = processStateEntry(glyphStorage, currGlyph, entryTableIndex);
143 LE_STATE_PATIENCE_INCR(currGlyph);
131 } 144 }
132 break; 145 break;
133 } 146 }
134 case ltfSegmentArray: { 147 case ltfSegmentArray: {
135 printf("Lookup Table Format4: specific interpretation needed!\n"); 148 //printf("Lookup Table Format4: specific interpretation needed!\n");
136 break; 149 break;
137 } 150 }
138 case ltfSingleTable: { 151 case ltfSingleTable: {
139 SingleTableLookupTable *lookupTable6 = (SingleTableLookupTable *) classTable; 152 SingleTableLookupTable *lookupTable6 = (SingleTableLookupTable *) classTable;
140 while ((dir == 1 && currGlyph <= glyphCount) || (dir == -1 && currGlyph >= -1)) { 153 while ((dir == 1 && currGlyph <= glyphCount) || (dir == -1 && currGlyph >= -1)) {
141 LookupValue classCode = classCodeOOB; 154 if(LE_STATE_PATIENCE_DECR()) {
142 if (currGlyph == glyphCount || currGlyph == -1) { 155 LE_DEBUG_BAD_FONT("patience exceeded - state table not moving")
143 // XXX: How do we handle EOT vs. EOL? 156 break; // patience exceeded.
144 classCode = classCodeEOT; 157 }
158 LookupValue classCode = classCodeOOB;
159 if (currGlyph == glyphCount || currGlyph == -1) {
160 // XXX: How do we handle EOT vs. EOL?
161 classCode = classCodeEOT;
162 } else if(currGlyph > glyphCount) {
163 // note if > glyphCount, we've run off the end (bad font)
164 currGlyph = glyphCount;
165 classCode = classCodeEOT;
145 } else { 166 } else {
146 LEGlyphID gid = glyphStorage[currGlyph]; 167 LEGlyphID gid = glyphStorage[currGlyph];
147 TTGlyphID glyphCode = (TTGlyphID) LE_GET_GLYPH(gid); 168 TTGlyphID glyphCode = (TTGlyphID) LE_GET_GLYPH(gid);
148 169
149 if (glyphCode == 0xFFFF) { 170 if (glyphCode == 0xFFFF) {
154 classCode = SWAPW(segment->value); 175 classCode = SWAPW(segment->value);
155 } 176 }
156 } 177 }
157 } 178 }
158 EntryTableIndex2 entryTableIndex = SWAPW(stateArray[classCode + currentState * nClasses]); 179 EntryTableIndex2 entryTableIndex = SWAPW(stateArray[classCode + currentState * nClasses]);
180 LE_STATE_PATIENCE_CURR(le_int32, currGlyph);
159 currentState = processStateEntry(glyphStorage, currGlyph, entryTableIndex); 181 currentState = processStateEntry(glyphStorage, currGlyph, entryTableIndex);
182 LE_STATE_PATIENCE_INCR(currGlyph);
160 } 183 }
161 break; 184 break;
162 } 185 }
163 case ltfTrimmedArray: { 186 case ltfTrimmedArray: {
164 TrimmedArrayLookupTable *lookupTable8 = (TrimmedArrayLookupTable *) classTable; 187 TrimmedArrayLookupTable *lookupTable8 = (TrimmedArrayLookupTable *) classTable;
165 TTGlyphID firstGlyph = SWAPW(lookupTable8->firstGlyph); 188 TTGlyphID firstGlyph = SWAPW(lookupTable8->firstGlyph);
166 TTGlyphID lastGlyph = firstGlyph + SWAPW(lookupTable8->glyphCount); 189 TTGlyphID lastGlyph = firstGlyph + SWAPW(lookupTable8->glyphCount);
167 190
168 while ((dir == 1 && currGlyph <= glyphCount) || (dir == -1 && currGlyph >= -1)) { 191 while ((dir == 1 && currGlyph <= glyphCount) || (dir == -1 && currGlyph >= -1)) {
192 if(LE_STATE_PATIENCE_DECR()) {
193 LE_DEBUG_BAD_FONT("patience exceeded - state table not moving")
194 break; // patience exceeded.
195 }
196
169 LookupValue classCode = classCodeOOB; 197 LookupValue classCode = classCodeOOB;
170 if (currGlyph == glyphCount || currGlyph == -1) { 198 if (currGlyph == glyphCount || currGlyph == -1) {
171 // XXX: How do we handle EOT vs. EOL? 199 // XXX: How do we handle EOT vs. EOL?
172 classCode = classCodeEOT; 200 classCode = classCodeEOT;
173 } else { 201 } else {
177 } else if ((glyphCode >= firstGlyph) && (glyphCode < lastGlyph)) { 205 } else if ((glyphCode >= firstGlyph) && (glyphCode < lastGlyph)) {
178 classCode = SWAPW(lookupTable8->valueArray[glyphCode - firstGlyph]); 206 classCode = SWAPW(lookupTable8->valueArray[glyphCode - firstGlyph]);
179 } 207 }
180 } 208 }
181 EntryTableIndex2 entryTableIndex = SWAPW(stateArray[classCode + currentState * nClasses]); 209 EntryTableIndex2 entryTableIndex = SWAPW(stateArray[classCode + currentState * nClasses]);
210 LE_STATE_PATIENCE_CURR(le_int32, currGlyph);
182 currentState = processStateEntry(glyphStorage, currGlyph, entryTableIndex); 211 currentState = processStateEntry(glyphStorage, currGlyph, entryTableIndex);
212 LE_STATE_PATIENCE_INCR(currGlyph);
183 } 213 }
184 break; 214 break;
185 } 215 }
186 default: 216 default:
187 break; 217 break;