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

Side by Side Diff: tests/ToUnicode.cpp

Issue 23519006: pdf: write only ToUnicode mappings needed by the font, trimming anything out of [firstChar, lastCha… (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 3 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 | Annotate | Revision Log
« src/pdf/SkPDFFont.cpp ('K') | « src/pdf/SkPDFFont.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 /* 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 return false; 20 return false;
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 uint16_t firstGlypthID,
32 uint16_t lastGlypthID);
31 33
32 static void TestToUnicode(skiatest::Reporter* reporter) { 34 static void TestToUnicode(skiatest::Reporter* reporter) {
33 SkTDArray<SkUnichar> glyphToUnicode; 35 SkTDArray<SkUnichar> glyphToUnicode;
34 SkTDArray<uint16_t> glyphsInSubset; 36 SkTDArray<uint16_t> glyphsInSubset;
35 SkPDFGlyphSet subset; 37 SkPDFGlyphSet subset;
36 38
37 glyphToUnicode.push(0); // 0 39 glyphToUnicode.push(0); // 0
38 glyphToUnicode.push(0); // 1 40 glyphToUnicode.push(0); // 1
39 glyphToUnicode.push(0); // 2 41 glyphToUnicode.push(0); // 2
40 glyphsInSubset.push(3); 42 glyphsInSubset.push(3);
(...skipping 22 matching lines...) Expand all
63 glyphToUnicode.push(0x1010); 65 glyphToUnicode.push(0x1010);
64 glyphsInSubset.push(0xFF); 66 glyphsInSubset.push(0xFF);
65 glyphToUnicode.push(0x1011); 67 glyphToUnicode.push(0x1011);
66 glyphsInSubset.push(0x100); 68 glyphsInSubset.push(0x100);
67 glyphToUnicode.push(0x1012); 69 glyphToUnicode.push(0x1012);
68 glyphsInSubset.push(0x101); 70 glyphsInSubset.push(0x101);
69 glyphToUnicode.push(0x1013); 71 glyphToUnicode.push(0x1013);
70 72
71 SkDynamicMemoryWStream buffer; 73 SkDynamicMemoryWStream buffer;
72 subset.set(glyphsInSubset.begin(), glyphsInSubset.count()); 74 subset.set(glyphsInSubset.begin(), glyphsInSubset.count());
73 append_cmap_sections(glyphToUnicode, &subset, &buffer); 75 append_cmap_sections(glyphToUnicode, &subset, &buffer, 0, 0xFFFF);
74 76
75 char expectedResult[] = 77 char expectedResult[] =
76 "4 beginbfchar\n\ 78 "4 beginbfchar\n\
77 <0003> <0020>\n\ 79 <0003> <0020>\n\
78 <0004> <0025>\n\ 80 <0004> <0025>\n\
79 <0008> <002F>\n\ 81 <0008> <002F>\n\
80 <0009> <0033>\n\ 82 <0009> <0033>\n\
81 endbfchar\n\ 83 endbfchar\n\
82 4 beginbfrange\n\ 84 4 beginbfrange\n\
83 <0005> <0007> <0027>\n\ 85 <0005> <0007> <0027>\n\
84 <000B> <000C> <0035>\n\ 86 <000B> <000C> <0035>\n\
85 <00FE> <00FF> <1010>\n\ 87 <00FE> <00FF> <1010>\n\
86 <0100> <0101> <1012>\n\ 88 <0100> <0101> <1012>\n\
87 endbfrange\n"; 89 endbfrange\n";
88 90
89 REPORTER_ASSERT(reporter, stream_equals(buffer, 0, expectedResult, 91 REPORTER_ASSERT(reporter, stream_equals(buffer, 0, expectedResult,
90 buffer.getOffset())); 92 buffer.getOffset()));
91 93
94 // Remove characters and ranges.
95 buffer.reset();
96
97 append_cmap_sections(glyphToUnicode, &subset, &buffer, 8, 0x00FF);
98
99 char expectedResultChop1[] =
100 "2 beginbfchar\n\
101 <0008> <002F>\n\
102 <0009> <0033>\n\
103 endbfchar\n\
104 2 beginbfrange\n\
105 <000B> <000C> <0035>\n\
106 <00FE> <00FF> <1010>\n\
107 endbfrange\n";
108
109 REPORTER_ASSERT(reporter, stream_equals(buffer, 0, expectedResultChop1,
110 buffer.getOffset()));
111
112 // Remove characters from range to downdrade it to one char.
113 buffer.reset();
114
115 append_cmap_sections(glyphToUnicode, &subset, &buffer, 0x00C, 0x00FE);
116
117 char expectedResultChop2[] =
118 "2 beginbfchar\n\
119 <000C> <0035>\n\
120 <00FE> <1010>\n\
121 endbfchar\n";
122
123 REPORTER_ASSERT(reporter, stream_equals(buffer, 0, expectedResultChop2,
124 buffer.getOffset()));
125
92 glyphToUnicode.reset(); 126 glyphToUnicode.reset();
93 glyphsInSubset.reset(); 127 glyphsInSubset.reset();
94 SkPDFGlyphSet subset2; 128 SkPDFGlyphSet subset2;
95 129
96 // Test mapping: 130 // Test mapping:
97 // I n s t a l 131 // I n s t a l
98 // Glyph id 2c 51 56 57 44 4f 132 // Glyph id 2c 51 56 57 44 4f
99 // Unicode 49 6e 73 74 61 6c 133 // Unicode 49 6e 73 74 61 6c
100 for (size_t i = 0; i < 100; ++i) { 134 for (size_t i = 0; i < 100; ++i) {
101 glyphToUnicode.push(i + 29); 135 glyphToUnicode.push(i + 29);
102 } 136 }
103 137
104 glyphsInSubset.push(0x2C); 138 glyphsInSubset.push(0x2C);
105 glyphsInSubset.push(0x44); 139 glyphsInSubset.push(0x44);
106 glyphsInSubset.push(0x4F); 140 glyphsInSubset.push(0x4F);
107 glyphsInSubset.push(0x51); 141 glyphsInSubset.push(0x51);
108 glyphsInSubset.push(0x56); 142 glyphsInSubset.push(0x56);
109 glyphsInSubset.push(0x57); 143 glyphsInSubset.push(0x57);
110 144
111 SkDynamicMemoryWStream buffer2; 145 SkDynamicMemoryWStream buffer2;
112 subset2.set(glyphsInSubset.begin(), glyphsInSubset.count()); 146 subset2.set(glyphsInSubset.begin(), glyphsInSubset.count());
113 append_cmap_sections(glyphToUnicode, &subset2, &buffer2); 147 append_cmap_sections(glyphToUnicode, &subset2, &buffer2, 0, 0xffff);
114 148
115 char expectedResult2[] = 149 char expectedResult2[] =
116 "4 beginbfchar\n\ 150 "4 beginbfchar\n\
117 <002C> <0049>\n\ 151 <002C> <0049>\n\
118 <0044> <0061>\n\ 152 <0044> <0061>\n\
119 <004F> <006C>\n\ 153 <004F> <006C>\n\
120 <0051> <006E>\n\ 154 <0051> <006E>\n\
121 endbfchar\n\ 155 endbfchar\n\
122 1 beginbfrange\n\ 156 1 beginbfrange\n\
123 <0056> <0057> <0073>\n\ 157 <0056> <0057> <0073>\n\
124 endbfrange\n"; 158 endbfrange\n";
125 159
126 REPORTER_ASSERT(reporter, stream_equals(buffer2, 0, expectedResult2, 160 REPORTER_ASSERT(reporter, stream_equals(buffer2, 0, expectedResult2,
127 buffer2.getOffset())); 161 buffer2.getOffset()));
128 } 162 }
129 163
130 #include "TestClassDef.h" 164 #include "TestClassDef.h"
131 DEFINE_TESTCLASS("ToUnicode", ToUnicodeTestClass, TestToUnicode) 165 DEFINE_TESTCLASS("ToUnicode", ToUnicodeTestClass, TestToUnicode)
OLDNEW
« src/pdf/SkPDFFont.cpp ('K') | « src/pdf/SkPDFFont.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698