OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2010 The Android Open Source Project | 2 * Copyright 2010 The Android Open Source Project |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
| 8 #include "SkBitSet.h" |
8 #include "SkData.h" | 9 #include "SkData.h" |
9 #include "SkPDFFont.h" | |
10 #include "SkPDFMakeToUnicodeCmap.h" | 10 #include "SkPDFMakeToUnicodeCmap.h" |
11 #include "SkStream.h" | 11 #include "SkStream.h" |
12 #include "Test.h" | 12 #include "Test.h" |
13 | 13 |
| 14 static const int kMaximumGlyphCount = SK_MaxU16 + 1; |
| 15 |
14 static bool stream_equals(const SkDynamicMemoryWStream& stream, size_t offset, | 16 static bool stream_equals(const SkDynamicMemoryWStream& stream, size_t offset, |
15 const char* buffer, size_t len) { | 17 const char* buffer, size_t len) { |
16 sk_sp<SkData> data(stream.copyToData()); | 18 sk_sp<SkData> data(stream.copyToData()); |
17 if (offset + len > data->size()) { | 19 if (offset + len > data->size()) { |
18 return false; | 20 return false; |
19 } | 21 } |
20 if (len != strlen(buffer)) { | 22 if (len != strlen(buffer)) { |
21 return false; | 23 return false; |
22 } | 24 } |
23 return memcmp(data->bytes() + offset, buffer, len) == 0; | 25 return memcmp(data->bytes() + offset, buffer, len) == 0; |
24 } | 26 } |
25 | 27 |
26 DEF_TEST(ToUnicode, reporter) { | 28 DEF_TEST(ToUnicode, reporter) { |
27 SkTDArray<SkUnichar> glyphToUnicode; | 29 SkTDArray<SkUnichar> glyphToUnicode; |
28 SkTDArray<uint16_t> glyphsInSubset; | 30 SkTDArray<uint16_t> glyphsInSubset; |
29 SkPDFGlyphSet subset; | 31 SkBitSet subset(kMaximumGlyphCount); |
30 | 32 |
31 glyphToUnicode.push(0); // 0 | 33 glyphToUnicode.push(0); // 0 |
32 glyphToUnicode.push(0); // 1 | 34 glyphToUnicode.push(0); // 1 |
33 glyphToUnicode.push(0); // 2 | 35 glyphToUnicode.push(0); // 2 |
34 glyphsInSubset.push(3); | 36 glyphsInSubset.push(3); |
35 glyphToUnicode.push(0x20); // 3 | 37 glyphToUnicode.push(0x20); // 3 |
36 glyphsInSubset.push(4); | 38 glyphsInSubset.push(4); |
37 glyphToUnicode.push(0x25); // 4 | 39 glyphToUnicode.push(0x25); // 4 |
38 glyphsInSubset.push(5); | 40 glyphsInSubset.push(5); |
39 glyphToUnicode.push(0x27); // 5 | 41 glyphToUnicode.push(0x27); // 5 |
(...skipping 18 matching lines...) Expand all Loading... |
58 glyphsInSubset.push(0xFE); | 60 glyphsInSubset.push(0xFE); |
59 glyphToUnicode.push(0x1010); | 61 glyphToUnicode.push(0x1010); |
60 glyphsInSubset.push(0xFF); | 62 glyphsInSubset.push(0xFF); |
61 glyphToUnicode.push(0x1011); | 63 glyphToUnicode.push(0x1011); |
62 glyphsInSubset.push(0x100); | 64 glyphsInSubset.push(0x100); |
63 glyphToUnicode.push(0x1012); | 65 glyphToUnicode.push(0x1012); |
64 glyphsInSubset.push(0x101); | 66 glyphsInSubset.push(0x101); |
65 glyphToUnicode.push(0x1013); | 67 glyphToUnicode.push(0x1013); |
66 | 68 |
67 SkDynamicMemoryWStream buffer; | 69 SkDynamicMemoryWStream buffer; |
68 subset.set(glyphsInSubset.begin(), glyphsInSubset.count()); | 70 subset.setAll(glyphsInSubset.begin(), glyphsInSubset.count()); |
69 SkPDFAppendCmapSections(glyphToUnicode, &subset, &buffer, true, 0, 0xFFFF); | 71 SkPDFAppendCmapSections(glyphToUnicode, &subset, &buffer, true, 0, 0xFFFF); |
70 | 72 |
71 char expectedResult[] = | 73 char expectedResult[] = |
72 "4 beginbfchar\n\ | 74 "4 beginbfchar\n\ |
73 <0003> <0020>\n\ | 75 <0003> <0020>\n\ |
74 <0004> <0025>\n\ | 76 <0004> <0025>\n\ |
75 <0008> <002F>\n\ | 77 <0008> <002F>\n\ |
76 <0009> <0033>\n\ | 78 <0009> <0033>\n\ |
77 endbfchar\n\ | 79 endbfchar\n\ |
78 4 beginbfrange\n\ | 80 4 beginbfrange\n\ |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 1 beginbfrange\n\ | 131 1 beginbfrange\n\ |
130 <0003> <0006> <1010>\n\ | 132 <0003> <0006> <1010>\n\ |
131 endbfrange\n"; | 133 endbfrange\n"; |
132 | 134 |
133 REPORTER_ASSERT(reporter, stream_equals(buffer, 0, | 135 REPORTER_ASSERT(reporter, stream_equals(buffer, 0, |
134 expectedResultSingleBytes, | 136 expectedResultSingleBytes, |
135 buffer.getOffset())); | 137 buffer.getOffset())); |
136 | 138 |
137 glyphToUnicode.reset(); | 139 glyphToUnicode.reset(); |
138 glyphsInSubset.reset(); | 140 glyphsInSubset.reset(); |
139 SkPDFGlyphSet subset2; | 141 SkBitSet subset2(kMaximumGlyphCount); |
140 | 142 |
141 // Test mapping: | 143 // Test mapping: |
142 // I n s t a l | 144 // I n s t a l |
143 // Glyph id 2c 51 56 57 44 4f | 145 // Glyph id 2c 51 56 57 44 4f |
144 // Unicode 49 6e 73 74 61 6c | 146 // Unicode 49 6e 73 74 61 6c |
145 for (SkUnichar i = 0; i < 100; ++i) { | 147 for (SkUnichar i = 0; i < 100; ++i) { |
146 glyphToUnicode.push(i + 29); | 148 glyphToUnicode.push(i + 29); |
147 } | 149 } |
148 | 150 |
149 glyphsInSubset.push(0x2C); | 151 glyphsInSubset.push(0x2C); |
150 glyphsInSubset.push(0x44); | 152 glyphsInSubset.push(0x44); |
151 glyphsInSubset.push(0x4F); | 153 glyphsInSubset.push(0x4F); |
152 glyphsInSubset.push(0x51); | 154 glyphsInSubset.push(0x51); |
153 glyphsInSubset.push(0x56); | 155 glyphsInSubset.push(0x56); |
154 glyphsInSubset.push(0x57); | 156 glyphsInSubset.push(0x57); |
155 | 157 |
156 SkDynamicMemoryWStream buffer2; | 158 SkDynamicMemoryWStream buffer2; |
157 subset2.set(glyphsInSubset.begin(), glyphsInSubset.count()); | 159 subset2.setAll(glyphsInSubset.begin(), glyphsInSubset.count()); |
158 SkPDFAppendCmapSections(glyphToUnicode, &subset2, &buffer2, true, 0, 0xffff)
; | 160 SkPDFAppendCmapSections(glyphToUnicode, &subset2, &buffer2, true, 0, 0xffff)
; |
159 | 161 |
160 char expectedResult2[] = | 162 char expectedResult2[] = |
161 "4 beginbfchar\n\ | 163 "4 beginbfchar\n\ |
162 <002C> <0049>\n\ | 164 <002C> <0049>\n\ |
163 <0044> <0061>\n\ | 165 <0044> <0061>\n\ |
164 <004F> <006C>\n\ | 166 <004F> <006C>\n\ |
165 <0051> <006E>\n\ | 167 <0051> <006E>\n\ |
166 endbfchar\n\ | 168 endbfchar\n\ |
167 1 beginbfrange\n\ | 169 1 beginbfrange\n\ |
168 <0056> <0057> <0073>\n\ | 170 <0056> <0057> <0073>\n\ |
169 endbfrange\n"; | 171 endbfrange\n"; |
170 | 172 |
171 REPORTER_ASSERT(reporter, stream_equals(buffer2, 0, expectedResult2, | 173 REPORTER_ASSERT(reporter, stream_equals(buffer2, 0, expectedResult2, |
172 buffer2.getOffset())); | 174 buffer2.getOffset())); |
173 } | 175 } |
OLD | NEW |