Flutter Engine
The Flutter Engine
Functions
SkPDFMakeToUnicodeCmap.h File Reference
#include "include/core/SkTypes.h"
#include <memory>

Go to the source code of this file.

Functions

std::unique_ptr< SkStreamAssetSkPDFMakeToUnicodeCmap (const SkUnichar *glyphToUnicode, const SkPDFGlyphUse *subset, bool multiByteGlyphs, SkGlyphID firstGlyphID, SkGlyphID lastGlyphID)
 
void SkPDFAppendCmapSections (const SkUnichar *glyphToUnicode, const SkPDFGlyphUse *subset, SkDynamicMemoryWStream *cmap, bool multiByteGlyphs, SkGlyphID firstGlyphID, SkGlyphID lastGlyphID)
 

Function Documentation

◆ SkPDFAppendCmapSections()

void SkPDFAppendCmapSections ( const SkUnichar glyphToUnicode,
const SkPDFGlyphUse subset,
SkDynamicMemoryWStream cmap,
bool  multiByteGlyphs,
SkGlyphID  firstGlyphID,
SkGlyphID  lastGlyphID 
)

Definition at line 158 of file SkPDFMakeToUnicodeCmap.cpp.

163 {
164 int glyphOffset = 0;
165 if (!multiByteGlyphs) {
166 glyphOffset = firstGlyphID - 1;
167 }
168
169 std::vector<BFChar> bfcharEntries;
170 std::vector<BFRange> bfrangeEntries;
171
172 BFRange currentRangeEntry = {0, 0, 0};
173 bool rangeEmpty = true;
174 const int limit = (int)lastGlyphID + 1 - glyphOffset;
175
176 for (int i = firstGlyphID - glyphOffset; i < limit + 1; ++i) {
177 SkGlyphID gid = i + glyphOffset;
178 bool inSubset = i < limit && (subset == nullptr || subset->has(gid));
179 if (!rangeEmpty) {
180 // PDF spec requires bfrange not changing the higher byte,
181 // e.g. <1035> <10FF> <2222> is ok, but
182 // <1035> <1100> <2222> is no good
183 bool inRange =
184 i == currentRangeEntry.fEnd + 1 &&
185 i >> 8 == currentRangeEntry.fStart >> 8 &&
186 i < limit &&
187 glyphToUnicode[gid] ==
188 currentRangeEntry.fUnicode + i - currentRangeEntry.fStart;
189 if (!inSubset || !inRange) {
190 if (currentRangeEntry.fEnd > currentRangeEntry.fStart) {
191 bfrangeEntries.push_back(currentRangeEntry);
192 } else {
193 bfcharEntries.push_back({currentRangeEntry.fStart, currentRangeEntry.fUnicode});
194 }
195 rangeEmpty = true;
196 }
197 }
198 if (inSubset) {
199 currentRangeEntry.fEnd = i;
200 if (rangeEmpty) {
201 currentRangeEntry.fStart = i;
202 currentRangeEntry.fUnicode = glyphToUnicode[gid];
203 rangeEmpty = false;
204 }
205 }
206 }
207
208 // The spec requires all bfchar entries for a font must come before bfrange
209 // entries.
210 append_bfchar_section(bfcharEntries, multiByteGlyphs, cmap);
211 append_bfrange_section(bfrangeEntries, multiByteGlyphs, cmap);
212}
static void append_bfrange_section(const std::vector< BFRange > &bfrange, bool multiByte, SkDynamicMemoryWStream *cmap)
static void append_bfchar_section(const std::vector< BFChar > &bfchar, bool multiByte, SkDynamicMemoryWStream *cmap)
uint16_t SkGlyphID
Definition: SkTypes.h:179
bool has(SkGlyphID gid) const
Definition: SkPDFGlyphUse.h:23

◆ SkPDFMakeToUnicodeCmap()

std::unique_ptr< SkStreamAsset > SkPDFMakeToUnicodeCmap ( const SkUnichar glyphToUnicode,
const SkPDFGlyphUse subset,
bool  multiByteGlyphs,
SkGlyphID  firstGlyphID,
SkGlyphID  lastGlyphID 
)

Definition at line 214 of file SkPDFMakeToUnicodeCmap.cpp.

219 {
221 append_tounicode_header(&cmap, multiByteGlyphs);
222 SkPDFAppendCmapSections(glyphToUnicode, subset, &cmap, multiByteGlyphs,
223 firstGlyphID, lastGlyphID);
224 append_cmap_footer(&cmap);
225 return cmap.detachAsStream();
226}
static void append_cmap_footer(SkDynamicMemoryWStream *cmap)
static void append_tounicode_header(SkDynamicMemoryWStream *cmap, bool multibyte)
void SkPDFAppendCmapSections(const SkUnichar *glyphToUnicode, const SkPDFGlyphUse *subset, SkDynamicMemoryWStream *cmap, bool multiByteGlyphs, SkGlyphID firstGlyphID, SkGlyphID lastGlyphID)
std::unique_ptr< SkStreamAsset > detachAsStream()
Definition: SkStream.cpp:876