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" |
11 #include "SkData.h" | 11 #include "SkData.h" |
12 #include "SkPDFTypes.h" | 12 #include "SkPDFTypes.h" |
13 #include "SkPDFFont.h" | 13 #include "SkPDFFont.h" |
14 #include "SkStream.h" | 14 #include "SkStream.h" |
15 | 15 |
16 static bool stream_equals(const SkDynamicMemoryWStream& stream, size_t offset, | 16 static bool stream_equals(const SkDynamicMemoryWStream& stream, size_t offset, |
17 const char* buffer, size_t len) { | 17 const char* buffer, size_t len) { |
18 SkAutoDataUnref data(stream.copyToData()); | 18 SkAutoDataUnref data(stream.copyToData()); |
19 if (offset + len > data->size()) { | 19 if (offset + len > data->size()) { |
20 printf("A %i %i\n", (int)(offset + len), (int)data->size()); | |
vandebo (ex-Chrome)
2013/09/09 20:00:29
Remove debug lines
| |
21 printf("%s\n%s\n", data->bytes() + offset, buffer); | |
20 return false; | 22 return false; |
21 } | 23 } |
22 if (len != strlen(buffer)) { | 24 if (len != strlen(buffer)) { |
25 printf("B %i %i\n", (int)len, (int)strlen(buffer)); | |
26 printf("%s\n%s\n", data->bytes() + offset, buffer); | |
23 return false; | 27 return false; |
24 } | 28 } |
29 if (memcmp(data->bytes() + offset, buffer, len) != 0) { | |
30 printf("C %i %i\n", (int)len, (int)strlen(buffer)); | |
31 printf("%s\n%s\n", data->bytes() + offset, buffer); | |
32 } | |
33 | |
25 return memcmp(data->bytes() + offset, buffer, len) == 0; | 34 return memcmp(data->bytes() + offset, buffer, len) == 0; |
26 } | 35 } |
27 | 36 |
28 void append_cmap_sections(const SkTDArray<SkUnichar>& glyphToUnicode, | 37 void append_cmap_sections(const SkTDArray<SkUnichar>& glyphToUnicode, |
29 const SkPDFGlyphSet* subset, | 38 const SkPDFGlyphSet* subset, |
30 SkDynamicMemoryWStream* cmap); | 39 SkDynamicMemoryWStream* cmap, |
40 uint16_t firstGlypthID, | |
41 uint16_t lastGlypthID); | |
31 | 42 |
32 static void TestToUnicode(skiatest::Reporter* reporter) { | 43 static void TestToUnicode(skiatest::Reporter* reporter) { |
33 SkTDArray<SkUnichar> glyphToUnicode; | 44 SkTDArray<SkUnichar> glyphToUnicode; |
34 SkTDArray<uint16_t> glyphsInSubset; | 45 SkTDArray<uint16_t> glyphsInSubset; |
35 SkPDFGlyphSet subset; | 46 SkPDFGlyphSet subset; |
36 | 47 |
37 glyphToUnicode.push(0); // 0 | 48 glyphToUnicode.push(0); // 0 |
38 glyphToUnicode.push(0); // 1 | 49 glyphToUnicode.push(0); // 1 |
39 glyphToUnicode.push(0); // 2 | 50 glyphToUnicode.push(0); // 2 |
40 glyphsInSubset.push(3); | 51 glyphsInSubset.push(3); |
41 glyphToUnicode.push(0x20); // 3 | 52 glyphToUnicode.push(0x20); // 3 |
42 glyphsInSubset.push(4); | 53 glyphsInSubset.push(4); |
43 glyphToUnicode.push(0x25); // 4 | 54 glyphToUnicode.push(0x25); // 4 |
44 glyphsInSubset.push(5); | 55 glyphsInSubset.push(5); |
45 glyphToUnicode.push(0x27); // 5 | 56 glyphToUnicode.push(0x27); // 5 |
46 glyphsInSubset.push(6); | 57 glyphsInSubset.push(6); |
47 glyphToUnicode.push(0x28); // 6 | 58 glyphToUnicode.push(0x28); // 6 |
48 glyphsInSubset.push(7); | 59 glyphsInSubset.push(7); |
49 glyphToUnicode.push(0x29); // 7 | 60 glyphToUnicode.push(0x29); // 7 |
50 glyphsInSubset.push(8); | 61 glyphsInSubset.push(8); |
51 glyphToUnicode.push(0x2F); // 8 | 62 glyphToUnicode.push(0x2F); // 8 |
52 glyphsInSubset.push(9); | 63 glyphsInSubset.push(9); |
53 glyphToUnicode.push(0x33); // 9 | 64 glyphToUnicode.push(0x33); // 9 |
54 glyphToUnicode.push(0); // 10 | 65 glyphToUnicode.push(0); // 10 |
55 glyphsInSubset.push(11); | 66 glyphsInSubset.push(11); |
56 glyphToUnicode.push(0x35); // 11 | 67 glyphToUnicode.push(0x35); // 11 |
57 glyphsInSubset.push(12); | 68 glyphsInSubset.push(12); |
58 glyphToUnicode.push(0x36); // 12 | 69 glyphToUnicode.push(0x36); // 12 |
59 for (uint16_t i = 13; i < 0xFE; ++i) { | 70 glyphsInSubset.push(13); |
71 glyphToUnicode.push(0x37); // 13 | |
72 for (uint16_t i = 14; i < 0xFE; ++i) { | |
60 glyphToUnicode.push(0); // Zero from index 0x9 to 0xFD | 73 glyphToUnicode.push(0); // Zero from index 0x9 to 0xFD |
61 } | 74 } |
62 glyphsInSubset.push(0xFE); | 75 glyphsInSubset.push(0xFE); |
63 glyphToUnicode.push(0x1010); | 76 glyphToUnicode.push(0x1010); |
64 glyphsInSubset.push(0xFF); | 77 glyphsInSubset.push(0xFF); |
65 glyphToUnicode.push(0x1011); | 78 glyphToUnicode.push(0x1011); |
66 glyphsInSubset.push(0x100); | 79 glyphsInSubset.push(0x100); |
67 glyphToUnicode.push(0x1012); | 80 glyphToUnicode.push(0x1012); |
68 glyphsInSubset.push(0x101); | 81 glyphsInSubset.push(0x101); |
69 glyphToUnicode.push(0x1013); | 82 glyphToUnicode.push(0x1013); |
70 | 83 |
71 SkDynamicMemoryWStream buffer; | 84 SkDynamicMemoryWStream buffer; |
72 subset.set(glyphsInSubset.begin(), glyphsInSubset.count()); | 85 subset.set(glyphsInSubset.begin(), glyphsInSubset.count()); |
73 append_cmap_sections(glyphToUnicode, &subset, &buffer); | 86 append_cmap_sections(glyphToUnicode, &subset, &buffer, 0, 0xFFFF); |
74 | 87 |
75 char expectedResult[] = | 88 char expectedResult[] = |
76 "4 beginbfchar\n\ | 89 "4 beginbfchar\n\ |
77 <0003> <0020>\n\ | 90 <0003> <0020>\n\ |
78 <0004> <0025>\n\ | 91 <0004> <0025>\n\ |
79 <0008> <002F>\n\ | 92 <0008> <002F>\n\ |
80 <0009> <0033>\n\ | 93 <0009> <0033>\n\ |
81 endbfchar\n\ | 94 endbfchar\n\ |
82 4 beginbfrange\n\ | 95 4 beginbfrange\n\ |
83 <0005> <0007> <0027>\n\ | 96 <0005> <0007> <0027>\n\ |
84 <000B> <000C> <0035>\n\ | 97 <000B> <000D> <0035>\n\ |
85 <00FE> <00FF> <1010>\n\ | 98 <00FE> <00FF> <1010>\n\ |
86 <0100> <0101> <1012>\n\ | 99 <0100> <0101> <1012>\n\ |
87 endbfrange\n"; | 100 endbfrange\n"; |
88 | 101 |
89 REPORTER_ASSERT(reporter, stream_equals(buffer, 0, expectedResult, | 102 REPORTER_ASSERT(reporter, stream_equals(buffer, 0, expectedResult, |
90 buffer.getOffset())); | 103 buffer.getOffset())); |
91 | 104 |
105 // Remove characters and ranges. | |
106 buffer.reset(); | |
107 | |
108 append_cmap_sections(glyphToUnicode, &subset, &buffer, 8, 0x00FF); | |
109 | |
110 char expectedResultChop1[] = | |
111 "2 beginbfchar\n\ | |
112 <0008> <002F>\n\ | |
113 <0009> <0033>\n\ | |
114 endbfchar\n\ | |
115 2 beginbfrange\n\ | |
116 <000B> <000D> <0035>\n\ | |
117 <00FE> <00FF> <1010>\n\ | |
118 endbfrange\n"; | |
119 | |
120 REPORTER_ASSERT(reporter, stream_equals(buffer, 0, expectedResultChop1, | |
121 buffer.getOffset())); | |
122 | |
123 // Remove characters from range to downdrade it to one char. | |
124 buffer.reset(); | |
125 | |
126 append_cmap_sections(glyphToUnicode, &subset, &buffer, 0x00D, 0x00FE); | |
127 | |
128 char expectedResultChop2[] = | |
129 "2 beginbfchar\n\ | |
130 <000D> <0037>\n\ | |
131 <00FE> <1010>\n\ | |
132 endbfchar\n"; | |
133 | |
134 REPORTER_ASSERT(reporter, stream_equals(buffer, 0, expectedResultChop2, | |
135 buffer.getOffset())); | |
136 | |
92 glyphToUnicode.reset(); | 137 glyphToUnicode.reset(); |
93 glyphsInSubset.reset(); | 138 glyphsInSubset.reset(); |
94 SkPDFGlyphSet subset2; | 139 SkPDFGlyphSet subset2; |
95 | 140 |
96 // Test mapping: | 141 // Test mapping: |
97 // I n s t a l | 142 // I n s t a l |
98 // Glyph id 2c 51 56 57 44 4f | 143 // Glyph id 2c 51 56 57 44 4f |
99 // Unicode 49 6e 73 74 61 6c | 144 // Unicode 49 6e 73 74 61 6c |
100 for (size_t i = 0; i < 100; ++i) { | 145 for (size_t i = 0; i < 100; ++i) { |
101 glyphToUnicode.push(i + 29); | 146 glyphToUnicode.push(i + 29); |
102 } | 147 } |
103 | 148 |
104 glyphsInSubset.push(0x2C); | 149 glyphsInSubset.push(0x2C); |
105 glyphsInSubset.push(0x44); | 150 glyphsInSubset.push(0x44); |
106 glyphsInSubset.push(0x4F); | 151 glyphsInSubset.push(0x4F); |
107 glyphsInSubset.push(0x51); | 152 glyphsInSubset.push(0x51); |
108 glyphsInSubset.push(0x56); | 153 glyphsInSubset.push(0x56); |
109 glyphsInSubset.push(0x57); | 154 glyphsInSubset.push(0x57); |
110 | 155 |
111 SkDynamicMemoryWStream buffer2; | 156 SkDynamicMemoryWStream buffer2; |
112 subset2.set(glyphsInSubset.begin(), glyphsInSubset.count()); | 157 subset2.set(glyphsInSubset.begin(), glyphsInSubset.count()); |
113 append_cmap_sections(glyphToUnicode, &subset2, &buffer2); | 158 append_cmap_sections(glyphToUnicode, &subset2, &buffer2, 0, 0xffff); |
114 | 159 |
115 char expectedResult2[] = | 160 char expectedResult2[] = |
116 "4 beginbfchar\n\ | 161 "4 beginbfchar\n\ |
117 <002C> <0049>\n\ | 162 <002C> <0049>\n\ |
118 <0044> <0061>\n\ | 163 <0044> <0061>\n\ |
119 <004F> <006C>\n\ | 164 <004F> <006C>\n\ |
120 <0051> <006E>\n\ | 165 <0051> <006E>\n\ |
121 endbfchar\n\ | 166 endbfchar\n\ |
122 1 beginbfrange\n\ | 167 1 beginbfrange\n\ |
123 <0056> <0057> <0073>\n\ | 168 <0056> <0057> <0073>\n\ |
124 endbfrange\n"; | 169 endbfrange\n"; |
125 | 170 |
126 REPORTER_ASSERT(reporter, stream_equals(buffer2, 0, expectedResult2, | 171 REPORTER_ASSERT(reporter, stream_equals(buffer2, 0, expectedResult2, |
127 buffer2.getOffset())); | 172 buffer2.getOffset())); |
128 } | 173 } |
129 | 174 |
130 #include "TestClassDef.h" | 175 #include "TestClassDef.h" |
131 DEFINE_TESTCLASS("ToUnicode", ToUnicodeTestClass, TestToUnicode) | 176 DEFINE_TESTCLASS("ToUnicode", ToUnicodeTestClass, TestToUnicode) |
OLD | NEW |