OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2010 The Android Open Source Project | 3 * Copyright 2010 The Android Open Source Project |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #include "Test.h" | 10 #include "Test.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 } | 21 } |
22 if (len != strlen(buffer)) { | 22 if (len != strlen(buffer)) { |
23 return false; | 23 return false; |
24 } | 24 } |
25 return memcmp(data->bytes() + offset, buffer, len) == 0; | 25 return memcmp(data->bytes() + offset, buffer, len) == 0; |
26 } | 26 } |
27 | 27 |
28 void append_cmap_sections(const SkTDArray<SkUnichar>& glyphToUnicode, | 28 void append_cmap_sections(const SkTDArray<SkUnichar>& glyphToUnicode, |
29 const SkPDFGlyphSet* subset, | 29 const SkPDFGlyphSet* subset, |
30 SkDynamicMemoryWStream* cmap, | 30 SkDynamicMemoryWStream* cmap, |
| 31 bool multiByteGlyphs, |
31 uint16_t firstGlypthID, | 32 uint16_t firstGlypthID, |
32 uint16_t lastGlypthID); | 33 uint16_t lastGlypthID); |
33 | 34 |
34 static void TestToUnicode(skiatest::Reporter* reporter) { | 35 static void TestToUnicode(skiatest::Reporter* reporter) { |
35 SkTDArray<SkUnichar> glyphToUnicode; | 36 SkTDArray<SkUnichar> glyphToUnicode; |
36 SkTDArray<uint16_t> glyphsInSubset; | 37 SkTDArray<uint16_t> glyphsInSubset; |
37 SkPDFGlyphSet subset; | 38 SkPDFGlyphSet subset; |
38 | 39 |
39 glyphToUnicode.push(0); // 0 | 40 glyphToUnicode.push(0); // 0 |
40 glyphToUnicode.push(0); // 1 | 41 glyphToUnicode.push(0); // 1 |
(...skipping 26 matching lines...) Expand all Loading... |
67 glyphToUnicode.push(0x1010); | 68 glyphToUnicode.push(0x1010); |
68 glyphsInSubset.push(0xFF); | 69 glyphsInSubset.push(0xFF); |
69 glyphToUnicode.push(0x1011); | 70 glyphToUnicode.push(0x1011); |
70 glyphsInSubset.push(0x100); | 71 glyphsInSubset.push(0x100); |
71 glyphToUnicode.push(0x1012); | 72 glyphToUnicode.push(0x1012); |
72 glyphsInSubset.push(0x101); | 73 glyphsInSubset.push(0x101); |
73 glyphToUnicode.push(0x1013); | 74 glyphToUnicode.push(0x1013); |
74 | 75 |
75 SkDynamicMemoryWStream buffer; | 76 SkDynamicMemoryWStream buffer; |
76 subset.set(glyphsInSubset.begin(), glyphsInSubset.count()); | 77 subset.set(glyphsInSubset.begin(), glyphsInSubset.count()); |
77 append_cmap_sections(glyphToUnicode, &subset, &buffer, 0, 0xFFFF); | 78 append_cmap_sections(glyphToUnicode, &subset, &buffer, true, 0, 0xFFFF); |
78 | 79 |
79 char expectedResult[] = | 80 char expectedResult[] = |
80 "4 beginbfchar\n\ | 81 "4 beginbfchar\n\ |
81 <0003> <0020>\n\ | 82 <0003> <0020>\n\ |
82 <0004> <0025>\n\ | 83 <0004> <0025>\n\ |
83 <0008> <002F>\n\ | 84 <0008> <002F>\n\ |
84 <0009> <0033>\n\ | 85 <0009> <0033>\n\ |
85 endbfchar\n\ | 86 endbfchar\n\ |
86 4 beginbfrange\n\ | 87 4 beginbfrange\n\ |
87 <0005> <0007> <0027>\n\ | 88 <0005> <0007> <0027>\n\ |
88 <000B> <000D> <0035>\n\ | 89 <000B> <000D> <0035>\n\ |
89 <00FE> <00FF> <1010>\n\ | 90 <00FE> <00FF> <1010>\n\ |
90 <0100> <0101> <1012>\n\ | 91 <0100> <0101> <1012>\n\ |
91 endbfrange\n"; | 92 endbfrange\n"; |
92 | 93 |
93 REPORTER_ASSERT(reporter, stream_equals(buffer, 0, expectedResult, | 94 REPORTER_ASSERT(reporter, stream_equals(buffer, 0, expectedResult, |
94 buffer.getOffset())); | 95 buffer.getOffset())); |
95 | 96 |
96 // Remove characters and ranges. | 97 // Remove characters and ranges. |
97 buffer.reset(); | 98 buffer.reset(); |
98 | 99 |
99 append_cmap_sections(glyphToUnicode, &subset, &buffer, 8, 0x00FF); | 100 append_cmap_sections(glyphToUnicode, &subset, &buffer, true, 8, 0x00FF); |
100 | 101 |
101 char expectedResultChop1[] = | 102 char expectedResultChop1[] = |
102 "2 beginbfchar\n\ | 103 "2 beginbfchar\n\ |
103 <0008> <002F>\n\ | 104 <0008> <002F>\n\ |
104 <0009> <0033>\n\ | 105 <0009> <0033>\n\ |
105 endbfchar\n\ | 106 endbfchar\n\ |
106 2 beginbfrange\n\ | 107 2 beginbfrange\n\ |
107 <000B> <000D> <0035>\n\ | 108 <000B> <000D> <0035>\n\ |
108 <00FE> <00FF> <1010>\n\ | 109 <00FE> <00FF> <1010>\n\ |
109 endbfrange\n"; | 110 endbfrange\n"; |
110 | 111 |
111 REPORTER_ASSERT(reporter, stream_equals(buffer, 0, expectedResultChop1, | 112 REPORTER_ASSERT(reporter, stream_equals(buffer, 0, expectedResultChop1, |
112 buffer.getOffset())); | 113 buffer.getOffset())); |
113 | 114 |
114 // Remove characters from range to downdrade it to one char. | 115 // Remove characters from range to downdrade it to one char. |
115 buffer.reset(); | 116 buffer.reset(); |
116 | 117 |
117 append_cmap_sections(glyphToUnicode, &subset, &buffer, 0x00D, 0x00FE); | 118 append_cmap_sections(glyphToUnicode, &subset, &buffer, true, 0x00D, 0x00FE); |
118 | 119 |
119 char expectedResultChop2[] = | 120 char expectedResultChop2[] = |
120 "2 beginbfchar\n\ | 121 "2 beginbfchar\n\ |
121 <000D> <0037>\n\ | 122 <000D> <0037>\n\ |
122 <00FE> <1010>\n\ | 123 <00FE> <1010>\n\ |
123 endbfchar\n"; | 124 endbfchar\n"; |
124 | 125 |
125 REPORTER_ASSERT(reporter, stream_equals(buffer, 0, expectedResultChop2, | 126 REPORTER_ASSERT(reporter, stream_equals(buffer, 0, expectedResultChop2, |
126 buffer.getOffset())); | 127 buffer.getOffset())); |
127 | 128 |
| 129 buffer.reset(); |
| 130 |
| 131 append_cmap_sections(glyphToUnicode, NULL, &buffer, false, 0xFC, 0x110); |
| 132 |
| 133 char expectedResultSingleBytes[] = |
| 134 "2 beginbfchar\n\ |
| 135 <0001> <0000>\n\ |
| 136 <0002> <0000>\n\ |
| 137 endbfchar\n\ |
| 138 1 beginbfrange\n\ |
| 139 <0003> <0006> <1010>\n\ |
| 140 endbfrange\n"; |
| 141 |
| 142 REPORTER_ASSERT(reporter, stream_equals(buffer, 0, |
| 143 expectedResultSingleBytes, |
| 144 buffer.getOffset())); |
| 145 |
128 glyphToUnicode.reset(); | 146 glyphToUnicode.reset(); |
129 glyphsInSubset.reset(); | 147 glyphsInSubset.reset(); |
130 SkPDFGlyphSet subset2; | 148 SkPDFGlyphSet subset2; |
131 | 149 |
132 // Test mapping: | 150 // Test mapping: |
133 // I n s t a l | 151 // I n s t a l |
134 // Glyph id 2c 51 56 57 44 4f | 152 // Glyph id 2c 51 56 57 44 4f |
135 // Unicode 49 6e 73 74 61 6c | 153 // Unicode 49 6e 73 74 61 6c |
136 for (size_t i = 0; i < 100; ++i) { | 154 for (size_t i = 0; i < 100; ++i) { |
137 glyphToUnicode.push(i + 29); | 155 glyphToUnicode.push(i + 29); |
138 } | 156 } |
139 | 157 |
140 glyphsInSubset.push(0x2C); | 158 glyphsInSubset.push(0x2C); |
141 glyphsInSubset.push(0x44); | 159 glyphsInSubset.push(0x44); |
142 glyphsInSubset.push(0x4F); | 160 glyphsInSubset.push(0x4F); |
143 glyphsInSubset.push(0x51); | 161 glyphsInSubset.push(0x51); |
144 glyphsInSubset.push(0x56); | 162 glyphsInSubset.push(0x56); |
145 glyphsInSubset.push(0x57); | 163 glyphsInSubset.push(0x57); |
146 | 164 |
147 SkDynamicMemoryWStream buffer2; | 165 SkDynamicMemoryWStream buffer2; |
148 subset2.set(glyphsInSubset.begin(), glyphsInSubset.count()); | 166 subset2.set(glyphsInSubset.begin(), glyphsInSubset.count()); |
149 append_cmap_sections(glyphToUnicode, &subset2, &buffer2, 0, 0xffff); | 167 append_cmap_sections(glyphToUnicode, &subset2, &buffer2, true, 0, 0xffff); |
150 | 168 |
151 char expectedResult2[] = | 169 char expectedResult2[] = |
152 "4 beginbfchar\n\ | 170 "4 beginbfchar\n\ |
153 <002C> <0049>\n\ | 171 <002C> <0049>\n\ |
154 <0044> <0061>\n\ | 172 <0044> <0061>\n\ |
155 <004F> <006C>\n\ | 173 <004F> <006C>\n\ |
156 <0051> <006E>\n\ | 174 <0051> <006E>\n\ |
157 endbfchar\n\ | 175 endbfchar\n\ |
158 1 beginbfrange\n\ | 176 1 beginbfrange\n\ |
159 <0056> <0057> <0073>\n\ | 177 <0056> <0057> <0073>\n\ |
160 endbfrange\n"; | 178 endbfrange\n"; |
161 | 179 |
162 REPORTER_ASSERT(reporter, stream_equals(buffer2, 0, expectedResult2, | 180 REPORTER_ASSERT(reporter, stream_equals(buffer2, 0, expectedResult2, |
163 buffer2.getOffset())); | 181 buffer2.getOffset())); |
164 } | 182 } |
165 | 183 |
166 #include "TestClassDef.h" | 184 #include "TestClassDef.h" |
167 DEFINE_TESTCLASS("ToUnicode", ToUnicodeTestClass, TestToUnicode) | 185 DEFINE_TESTCLASS("ToUnicode", ToUnicodeTestClass, TestToUnicode) |
OLD | NEW |