Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(68)

Side by Side Diff: tests/ToUnicodeTest.cpp

Issue 1278403006: SkPDF: clean up overuse of SK_SUPPORT_PDF (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-08-11 (Tuesday) 16:25:36 EDT Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tests/Test.h ('k') | tests/skpdf_opaquesrcmodetosrcover.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2010 The Android Open Source Project
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "SkData.h"
9 #include "SkPDFFont.h"
10 #include "SkPDFTypes.h"
11 #include "SkStream.h"
12 #include "Test.h"
13
14 #if SK_SUPPORT_PDF
15
16 static bool stream_equals(const SkDynamicMemoryWStream& stream, size_t offset,
17 const char* buffer, size_t len) {
18 SkAutoDataUnref data(stream.copyToData());
19 if (offset + len > data->size()) {
20 return false;
21 }
22 if (len != strlen(buffer)) {
23 return false;
24 }
25 return memcmp(data->bytes() + offset, buffer, len) == 0;
26 }
27
28 void append_cmap_sections(const SkTDArray<SkUnichar>& glyphToUnicode,
29 const SkPDFGlyphSet* subset,
30 SkDynamicMemoryWStream* cmap,
31 bool multiByteGlyphs,
32 uint16_t firstGlypthID,
33 uint16_t lastGlypthID);
34
35 DEF_TEST(ToUnicode, reporter) {
36 SkTDArray<SkUnichar> glyphToUnicode;
37 SkTDArray<uint16_t> glyphsInSubset;
38 SkPDFGlyphSet subset;
39
40 glyphToUnicode.push(0); // 0
41 glyphToUnicode.push(0); // 1
42 glyphToUnicode.push(0); // 2
43 glyphsInSubset.push(3);
44 glyphToUnicode.push(0x20); // 3
45 glyphsInSubset.push(4);
46 glyphToUnicode.push(0x25); // 4
47 glyphsInSubset.push(5);
48 glyphToUnicode.push(0x27); // 5
49 glyphsInSubset.push(6);
50 glyphToUnicode.push(0x28); // 6
51 glyphsInSubset.push(7);
52 glyphToUnicode.push(0x29); // 7
53 glyphsInSubset.push(8);
54 glyphToUnicode.push(0x2F); // 8
55 glyphsInSubset.push(9);
56 glyphToUnicode.push(0x33); // 9
57 glyphToUnicode.push(0); // 10
58 glyphsInSubset.push(11);
59 glyphToUnicode.push(0x35); // 11
60 glyphsInSubset.push(12);
61 glyphToUnicode.push(0x36); // 12
62 glyphsInSubset.push(13);
63 glyphToUnicode.push(0x37); // 13
64 for (uint16_t i = 14; i < 0xFE; ++i) {
65 glyphToUnicode.push(0); // Zero from index 0x9 to 0xFD
66 }
67 glyphsInSubset.push(0xFE);
68 glyphToUnicode.push(0x1010);
69 glyphsInSubset.push(0xFF);
70 glyphToUnicode.push(0x1011);
71 glyphsInSubset.push(0x100);
72 glyphToUnicode.push(0x1012);
73 glyphsInSubset.push(0x101);
74 glyphToUnicode.push(0x1013);
75
76 SkDynamicMemoryWStream buffer;
77 subset.set(glyphsInSubset.begin(), glyphsInSubset.count());
78 append_cmap_sections(glyphToUnicode, &subset, &buffer, true, 0, 0xFFFF);
79
80 char expectedResult[] =
81 "4 beginbfchar\n\
82 <0003> <0020>\n\
83 <0004> <0025>\n\
84 <0008> <002F>\n\
85 <0009> <0033>\n\
86 endbfchar\n\
87 4 beginbfrange\n\
88 <0005> <0007> <0027>\n\
89 <000B> <000D> <0035>\n\
90 <00FE> <00FF> <1010>\n\
91 <0100> <0101> <1012>\n\
92 endbfrange\n";
93
94 REPORTER_ASSERT(reporter, stream_equals(buffer, 0, expectedResult,
95 buffer.getOffset()));
96
97 // Remove characters and ranges.
98 buffer.reset();
99
100 append_cmap_sections(glyphToUnicode, &subset, &buffer, true, 8, 0x00FF);
101
102 char expectedResultChop1[] =
103 "2 beginbfchar\n\
104 <0008> <002F>\n\
105 <0009> <0033>\n\
106 endbfchar\n\
107 2 beginbfrange\n\
108 <000B> <000D> <0035>\n\
109 <00FE> <00FF> <1010>\n\
110 endbfrange\n";
111
112 REPORTER_ASSERT(reporter, stream_equals(buffer, 0, expectedResultChop1,
113 buffer.getOffset()));
114
115 // Remove characters from range to downdrade it to one char.
116 buffer.reset();
117
118 append_cmap_sections(glyphToUnicode, &subset, &buffer, true, 0x00D, 0x00FE);
119
120 char expectedResultChop2[] =
121 "2 beginbfchar\n\
122 <000D> <0037>\n\
123 <00FE> <1010>\n\
124 endbfchar\n";
125
126 REPORTER_ASSERT(reporter, stream_equals(buffer, 0, expectedResultChop2,
127 buffer.getOffset()));
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
146 glyphToUnicode.reset();
147 glyphsInSubset.reset();
148 SkPDFGlyphSet subset2;
149
150 // Test mapping:
151 // I n s t a l
152 // Glyph id 2c 51 56 57 44 4f
153 // Unicode 49 6e 73 74 61 6c
154 for (SkUnichar i = 0; i < 100; ++i) {
155 glyphToUnicode.push(i + 29);
156 }
157
158 glyphsInSubset.push(0x2C);
159 glyphsInSubset.push(0x44);
160 glyphsInSubset.push(0x4F);
161 glyphsInSubset.push(0x51);
162 glyphsInSubset.push(0x56);
163 glyphsInSubset.push(0x57);
164
165 SkDynamicMemoryWStream buffer2;
166 subset2.set(glyphsInSubset.begin(), glyphsInSubset.count());
167 append_cmap_sections(glyphToUnicode, &subset2, &buffer2, true, 0, 0xffff);
168
169 char expectedResult2[] =
170 "4 beginbfchar\n\
171 <002C> <0049>\n\
172 <0044> <0061>\n\
173 <004F> <006C>\n\
174 <0051> <006E>\n\
175 endbfchar\n\
176 1 beginbfrange\n\
177 <0056> <0057> <0073>\n\
178 endbfrange\n";
179
180 REPORTER_ASSERT(reporter, stream_equals(buffer2, 0, expectedResult2,
181 buffer2.getOffset()));
182 }
183 #endif // SK_SUPPORT_PDF
OLDNEW
« no previous file with comments | « tests/Test.h ('k') | tests/skpdf_opaquesrcmodetosrcover.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698