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

Side by Side Diff: tests/PDFGlyphsToUnicodeTest.cpp

Issue 2221163002: SkPDF: SkPDFFont organization changes. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2016-08-09 (Tuesday) 15:24:15 EDT Created 4 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 | « src/pdf/SkPDFMakeToUnicodeCmap.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "SkData.h" 8 #include "SkData.h"
9 #include "SkPDFFont.h" 9 #include "SkPDFFont.h"
10 #include "SkPDFTypes.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 bool stream_equals(const SkDynamicMemoryWStream& stream, size_t offset, 14 static bool stream_equals(const SkDynamicMemoryWStream& stream, size_t offset,
15 const char* buffer, size_t len) { 15 const char* buffer, size_t len) {
16 sk_sp<SkData> data(stream.copyToData()); 16 sk_sp<SkData> data(stream.copyToData());
17 if (offset + len > data->size()) { 17 if (offset + len > data->size()) {
18 return false; 18 return false;
19 } 19 }
20 if (len != strlen(buffer)) { 20 if (len != strlen(buffer)) {
21 return false; 21 return false;
22 } 22 }
23 return memcmp(data->bytes() + offset, buffer, len) == 0; 23 return memcmp(data->bytes() + offset, buffer, len) == 0;
24 } 24 }
25 25
26 void append_cmap_sections(const SkTDArray<SkUnichar>& glyphToUnicode,
27 const SkPDFGlyphSet* subset,
28 SkDynamicMemoryWStream* cmap,
29 bool multiByteGlyphs,
30 uint16_t firstGlypthID,
31 uint16_t lastGlypthID);
32
33 DEF_TEST(ToUnicode, reporter) { 26 DEF_TEST(ToUnicode, reporter) {
34 SkTDArray<SkUnichar> glyphToUnicode; 27 SkTDArray<SkUnichar> glyphToUnicode;
35 SkTDArray<uint16_t> glyphsInSubset; 28 SkTDArray<uint16_t> glyphsInSubset;
36 SkPDFGlyphSet subset; 29 SkPDFGlyphSet subset;
37 30
38 glyphToUnicode.push(0); // 0 31 glyphToUnicode.push(0); // 0
39 glyphToUnicode.push(0); // 1 32 glyphToUnicode.push(0); // 1
40 glyphToUnicode.push(0); // 2 33 glyphToUnicode.push(0); // 2
41 glyphsInSubset.push(3); 34 glyphsInSubset.push(3);
42 glyphToUnicode.push(0x20); // 3 35 glyphToUnicode.push(0x20); // 3
(...skipping 23 matching lines...) Expand all
66 glyphToUnicode.push(0x1010); 59 glyphToUnicode.push(0x1010);
67 glyphsInSubset.push(0xFF); 60 glyphsInSubset.push(0xFF);
68 glyphToUnicode.push(0x1011); 61 glyphToUnicode.push(0x1011);
69 glyphsInSubset.push(0x100); 62 glyphsInSubset.push(0x100);
70 glyphToUnicode.push(0x1012); 63 glyphToUnicode.push(0x1012);
71 glyphsInSubset.push(0x101); 64 glyphsInSubset.push(0x101);
72 glyphToUnicode.push(0x1013); 65 glyphToUnicode.push(0x1013);
73 66
74 SkDynamicMemoryWStream buffer; 67 SkDynamicMemoryWStream buffer;
75 subset.set(glyphsInSubset.begin(), glyphsInSubset.count()); 68 subset.set(glyphsInSubset.begin(), glyphsInSubset.count());
76 append_cmap_sections(glyphToUnicode, &subset, &buffer, true, 0, 0xFFFF); 69 SkPDFAppendCmapSections(glyphToUnicode, &subset, &buffer, true, 0, 0xFFFF);
77 70
78 char expectedResult[] = 71 char expectedResult[] =
79 "4 beginbfchar\n\ 72 "4 beginbfchar\n\
80 <0003> <0020>\n\ 73 <0003> <0020>\n\
81 <0004> <0025>\n\ 74 <0004> <0025>\n\
82 <0008> <002F>\n\ 75 <0008> <002F>\n\
83 <0009> <0033>\n\ 76 <0009> <0033>\n\
84 endbfchar\n\ 77 endbfchar\n\
85 4 beginbfrange\n\ 78 4 beginbfrange\n\
86 <0005> <0007> <0027>\n\ 79 <0005> <0007> <0027>\n\
87 <000B> <000D> <0035>\n\ 80 <000B> <000D> <0035>\n\
88 <00FE> <00FF> <1010>\n\ 81 <00FE> <00FF> <1010>\n\
89 <0100> <0101> <1012>\n\ 82 <0100> <0101> <1012>\n\
90 endbfrange\n"; 83 endbfrange\n";
91 84
92 REPORTER_ASSERT(reporter, stream_equals(buffer, 0, expectedResult, 85 REPORTER_ASSERT(reporter, stream_equals(buffer, 0, expectedResult,
93 buffer.getOffset())); 86 buffer.getOffset()));
94 87
95 // Remove characters and ranges. 88 // Remove characters and ranges.
96 buffer.reset(); 89 buffer.reset();
97 90
98 append_cmap_sections(glyphToUnicode, &subset, &buffer, true, 8, 0x00FF); 91 SkPDFAppendCmapSections(glyphToUnicode, &subset, &buffer, true, 8, 0x00FF);
99 92
100 char expectedResultChop1[] = 93 char expectedResultChop1[] =
101 "2 beginbfchar\n\ 94 "2 beginbfchar\n\
102 <0008> <002F>\n\ 95 <0008> <002F>\n\
103 <0009> <0033>\n\ 96 <0009> <0033>\n\
104 endbfchar\n\ 97 endbfchar\n\
105 2 beginbfrange\n\ 98 2 beginbfrange\n\
106 <000B> <000D> <0035>\n\ 99 <000B> <000D> <0035>\n\
107 <00FE> <00FF> <1010>\n\ 100 <00FE> <00FF> <1010>\n\
108 endbfrange\n"; 101 endbfrange\n";
109 102
110 REPORTER_ASSERT(reporter, stream_equals(buffer, 0, expectedResultChop1, 103 REPORTER_ASSERT(reporter, stream_equals(buffer, 0, expectedResultChop1,
111 buffer.getOffset())); 104 buffer.getOffset()));
112 105
113 // Remove characters from range to downdrade it to one char. 106 // Remove characters from range to downdrade it to one char.
114 buffer.reset(); 107 buffer.reset();
115 108
116 append_cmap_sections(glyphToUnicode, &subset, &buffer, true, 0x00D, 0x00FE); 109 SkPDFAppendCmapSections(glyphToUnicode, &subset, &buffer, true, 0x00D, 0x00F E);
117 110
118 char expectedResultChop2[] = 111 char expectedResultChop2[] =
119 "2 beginbfchar\n\ 112 "2 beginbfchar\n\
120 <000D> <0037>\n\ 113 <000D> <0037>\n\
121 <00FE> <1010>\n\ 114 <00FE> <1010>\n\
122 endbfchar\n"; 115 endbfchar\n";
123 116
124 REPORTER_ASSERT(reporter, stream_equals(buffer, 0, expectedResultChop2, 117 REPORTER_ASSERT(reporter, stream_equals(buffer, 0, expectedResultChop2,
125 buffer.getOffset())); 118 buffer.getOffset()));
126 119
127 buffer.reset(); 120 buffer.reset();
128 121
129 append_cmap_sections(glyphToUnicode, nullptr, &buffer, false, 0xFC, 0x110); 122 SkPDFAppendCmapSections(glyphToUnicode, nullptr, &buffer, false, 0xFC, 0x110 );
130 123
131 char expectedResultSingleBytes[] = 124 char expectedResultSingleBytes[] =
132 "2 beginbfchar\n\ 125 "2 beginbfchar\n\
133 <0001> <0000>\n\ 126 <0001> <0000>\n\
134 <0002> <0000>\n\ 127 <0002> <0000>\n\
135 endbfchar\n\ 128 endbfchar\n\
136 1 beginbfrange\n\ 129 1 beginbfrange\n\
137 <0003> <0006> <1010>\n\ 130 <0003> <0006> <1010>\n\
138 endbfrange\n"; 131 endbfrange\n";
139 132
(...skipping 15 matching lines...) Expand all
155 148
156 glyphsInSubset.push(0x2C); 149 glyphsInSubset.push(0x2C);
157 glyphsInSubset.push(0x44); 150 glyphsInSubset.push(0x44);
158 glyphsInSubset.push(0x4F); 151 glyphsInSubset.push(0x4F);
159 glyphsInSubset.push(0x51); 152 glyphsInSubset.push(0x51);
160 glyphsInSubset.push(0x56); 153 glyphsInSubset.push(0x56);
161 glyphsInSubset.push(0x57); 154 glyphsInSubset.push(0x57);
162 155
163 SkDynamicMemoryWStream buffer2; 156 SkDynamicMemoryWStream buffer2;
164 subset2.set(glyphsInSubset.begin(), glyphsInSubset.count()); 157 subset2.set(glyphsInSubset.begin(), glyphsInSubset.count());
165 append_cmap_sections(glyphToUnicode, &subset2, &buffer2, true, 0, 0xffff); 158 SkPDFAppendCmapSections(glyphToUnicode, &subset2, &buffer2, true, 0, 0xffff) ;
166 159
167 char expectedResult2[] = 160 char expectedResult2[] =
168 "4 beginbfchar\n\ 161 "4 beginbfchar\n\
169 <002C> <0049>\n\ 162 <002C> <0049>\n\
170 <0044> <0061>\n\ 163 <0044> <0061>\n\
171 <004F> <006C>\n\ 164 <004F> <006C>\n\
172 <0051> <006E>\n\ 165 <0051> <006E>\n\
173 endbfchar\n\ 166 endbfchar\n\
174 1 beginbfrange\n\ 167 1 beginbfrange\n\
175 <0056> <0057> <0073>\n\ 168 <0056> <0057> <0073>\n\
176 endbfrange\n"; 169 endbfrange\n";
177 170
178 REPORTER_ASSERT(reporter, stream_equals(buffer2, 0, expectedResult2, 171 REPORTER_ASSERT(reporter, stream_equals(buffer2, 0, expectedResult2,
179 buffer2.getOffset())); 172 buffer2.getOffset()));
180 } 173 }
OLDNEW
« no previous file with comments | « src/pdf/SkPDFMakeToUnicodeCmap.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698