OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
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 "SkPDFMakeToUnicodeCmap.h" | 8 #include "SkPDFMakeToUnicodeCmap.h" |
9 #include "SkPDFUtils.h" | 9 #include "SkPDFUtils.h" |
10 #include "SkUtils.h" | 10 #include "SkUtils.h" |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 // overlap, but succeeding maps supersede preceding maps." | 142 // overlap, but succeeding maps supersede preceding maps." |
143 // | 143 // |
144 // In case of searching text in PDF, bfrange will have higher precedence so | 144 // In case of searching text in PDF, bfrange will have higher precedence so |
145 // typing char id 0x0014 in search box will get glyph id 0x0004 first. However, | 145 // typing char id 0x0014 in search box will get glyph id 0x0004 first. However, |
146 // the spec does not mention how will this kind of conflict being resolved. | 146 // the spec does not mention how will this kind of conflict being resolved. |
147 // | 147 // |
148 // For the worst case (having 65536 continuous unicode and we use every other | 148 // For the worst case (having 65536 continuous unicode and we use every other |
149 // one of them), the possible savings by aggressive optimization is 416KB | 149 // one of them), the possible savings by aggressive optimization is 416KB |
150 // pre-compressed and does not provide enough motivation for implementation. | 150 // pre-compressed and does not provide enough motivation for implementation. |
151 void SkPDFAppendCmapSections(const SkTDArray<SkUnichar>& glyphToUnicode, | 151 void SkPDFAppendCmapSections(const SkTDArray<SkUnichar>& glyphToUnicode, |
152 const SkPDFGlyphSet* subset, | 152 const SkBitSet* subset, |
153 SkDynamicMemoryWStream* cmap, | 153 SkDynamicMemoryWStream* cmap, |
154 bool multiByteGlyphs, | 154 bool multiByteGlyphs, |
155 SkGlyphID firstGlyphID, | 155 SkGlyphID firstGlyphID, |
156 SkGlyphID lastGlyphID) { | 156 SkGlyphID lastGlyphID) { |
157 if (glyphToUnicode.isEmpty()) { | 157 if (glyphToUnicode.isEmpty()) { |
158 return; | 158 return; |
159 } | 159 } |
160 int glyphOffset = 0; | 160 int glyphOffset = 0; |
161 if (!multiByteGlyphs) { | 161 if (!multiByteGlyphs) { |
162 glyphOffset = firstGlyphID - 1; | 162 glyphOffset = firstGlyphID - 1; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 } | 205 } |
206 | 206 |
207 // The spec requires all bfchar entries for a font must come before bfrange | 207 // The spec requires all bfchar entries for a font must come before bfrange |
208 // entries. | 208 // entries. |
209 append_bfchar_section(bfcharEntries, cmap); | 209 append_bfchar_section(bfcharEntries, cmap); |
210 append_bfrange_section(bfrangeEntries, cmap); | 210 append_bfrange_section(bfrangeEntries, cmap); |
211 } | 211 } |
212 | 212 |
213 sk_sp<SkPDFStream> SkPDFMakeToUnicodeCmap( | 213 sk_sp<SkPDFStream> SkPDFMakeToUnicodeCmap( |
214 const SkTDArray<SkUnichar>& glyphToUnicode, | 214 const SkTDArray<SkUnichar>& glyphToUnicode, |
215 const SkPDFGlyphSet* subset, | 215 const SkBitSet* subset, |
216 bool multiByteGlyphs, | 216 bool multiByteGlyphs, |
217 SkGlyphID firstGlyphID, | 217 SkGlyphID firstGlyphID, |
218 SkGlyphID lastGlyphID) { | 218 SkGlyphID lastGlyphID) { |
219 SkDynamicMemoryWStream cmap; | 219 SkDynamicMemoryWStream cmap; |
220 if (multiByteGlyphs) { | 220 if (multiByteGlyphs) { |
221 append_tounicode_header(&cmap, firstGlyphID, lastGlyphID); | 221 append_tounicode_header(&cmap, firstGlyphID, lastGlyphID); |
222 } else { | 222 } else { |
223 append_tounicode_header(&cmap, 1, lastGlyphID - firstGlyphID + 1); | 223 append_tounicode_header(&cmap, 1, lastGlyphID - firstGlyphID + 1); |
224 } | 224 } |
225 SkPDFAppendCmapSections(glyphToUnicode, subset, &cmap, multiByteGlyphs, | 225 SkPDFAppendCmapSections(glyphToUnicode, subset, &cmap, multiByteGlyphs, |
226 firstGlyphID, lastGlyphID); | 226 firstGlyphID, lastGlyphID); |
227 append_cmap_footer(&cmap); | 227 append_cmap_footer(&cmap); |
228 return sk_make_sp<SkPDFStream>( | 228 return sk_make_sp<SkPDFStream>( |
229 std::unique_ptr<SkStreamAsset>(cmap.detachAsStream())); | 229 std::unique_ptr<SkStreamAsset>(cmap.detachAsStream())); |
230 } | 230 } |
OLD | NEW |