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

Unified Diff: src/pdf/SkPDFFont.cpp

Issue 112053005: [PDF] Fix bug in ToUnicode table generation for Type 3 fonts. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/ToUnicode.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/pdf/SkPDFFont.cpp
diff --git a/src/pdf/SkPDFFont.cpp b/src/pdf/SkPDFFont.cpp
index 65a6f5db4b6a2f0da4702f48a3a6de6b952e9f52..53de79b2a924217bf98669a7dfb26ac788604dd1 100644
--- a/src/pdf/SkPDFFont.cpp
+++ b/src/pdf/SkPDFFont.cpp
@@ -460,7 +460,7 @@ static void append_bfrange_section(const SkTDArray<BFRange>& bfrange,
// endbfchar endbfrange
//
// Adobe Technote 5014 said: "Code mappings (unlike codespace ranges) may
-// overlap, but succeeding maps superceded preceding maps."
+// overlap, but succeeding maps supersede preceding maps."
//
// In case of searching text in PDF, bfrange will have higher precedence so
// typing char id 0x0014 in search box will get glyph id 0x0004 first. However,
@@ -475,28 +475,35 @@ static void append_bfrange_section(const SkTDArray<BFRange>& bfrange,
void append_cmap_sections(const SkTDArray<SkUnichar>& glyphToUnicode,
const SkPDFGlyphSet* subset,
SkDynamicMemoryWStream* cmap,
+ bool multiByteGlyphs,
uint16_t firstGlyphID,
uint16_t lastGlyphID);
void append_cmap_sections(const SkTDArray<SkUnichar>& glyphToUnicode,
const SkPDFGlyphSet* subset,
SkDynamicMemoryWStream* cmap,
+ bool multiByteGlyphs,
uint16_t firstGlyphID,
uint16_t lastGlyphID) {
if (glyphToUnicode.isEmpty()) {
return;
}
+ int glyphOffset = 0;
+ if (!multiByteGlyphs) {
+ glyphOffset = firstGlyphID - 1;
+ }
SkTDArray<BFChar> bfcharEntries;
SkTDArray<BFRange> bfrangeEntries;
BFRange currentRangeEntry = {0, 0, 0};
bool rangeEmpty = true;
- const int limit = SkMin32(lastGlyphID + 1, glyphToUnicode.count());
+ const int limit =
+ SkMin32(lastGlyphID + 1, glyphToUnicode.count()) - glyphOffset;
- for (int i = firstGlyphID; i < limit + 1; ++i) {
+ for (int i = firstGlyphID - glyphOffset; i < limit + 1; ++i) {
bool inSubset = i < limit &&
- (subset == NULL || subset->has(i));
+ (subset == NULL || subset->has(i + glyphOffset));
if (!rangeEmpty) {
// PDF spec requires bfrange not changing the higher byte,
// e.g. <1035> <10FF> <2222> is ok, but
@@ -505,8 +512,8 @@ void append_cmap_sections(const SkTDArray<SkUnichar>& glyphToUnicode,
i == currentRangeEntry.fEnd + 1 &&
i >> 8 == currentRangeEntry.fStart >> 8 &&
i < limit &&
- glyphToUnicode[i] == currentRangeEntry.fUnicode + i -
- currentRangeEntry.fStart;
+ glyphToUnicode[i + glyphOffset] ==
+ currentRangeEntry.fUnicode + i - currentRangeEntry.fStart;
if (!inSubset || !inRange) {
if (currentRangeEntry.fEnd > currentRangeEntry.fStart) {
bfrangeEntries.push(currentRangeEntry);
@@ -522,7 +529,7 @@ void append_cmap_sections(const SkTDArray<SkUnichar>& glyphToUnicode,
currentRangeEntry.fEnd = i;
if (rangeEmpty) {
currentRangeEntry.fStart = i;
- currentRangeEntry.fUnicode = glyphToUnicode[i];
+ currentRangeEntry.fUnicode = glyphToUnicode[i + glyphOffset];
rangeEmpty = false;
}
}
@@ -537,11 +544,16 @@ void append_cmap_sections(const SkTDArray<SkUnichar>& glyphToUnicode,
static SkPDFStream* generate_tounicode_cmap(
const SkTDArray<SkUnichar>& glyphToUnicode,
const SkPDFGlyphSet* subset,
+ bool multiByteGlyphs,
uint16_t firstGlyphID,
uint16_t lastGlyphID) {
SkDynamicMemoryWStream cmap;
- append_tounicode_header(&cmap, firstGlyphID, lastGlyphID);
- append_cmap_sections(glyphToUnicode, subset, &cmap,
+ if (multiByteGlyphs) {
+ append_tounicode_header(&cmap, firstGlyphID, lastGlyphID);
+ } else {
+ append_tounicode_header(&cmap, 1, lastGlyphID - firstGlyphID + 1);
+ }
+ append_cmap_sections(glyphToUnicode, subset, &cmap, multiByteGlyphs,
firstGlyphID, lastGlyphID);
append_cmap_footer(&cmap);
SkAutoTUnref<SkMemoryStream> cmapStream(new SkMemoryStream());
@@ -1044,7 +1056,8 @@ void SkPDFFont::populateToUnicodeTable(const SkPDFGlyphSet* subset) {
}
SkAutoTUnref<SkPDFStream> pdfCmap(
generate_tounicode_cmap(fFontInfo->fGlyphToUnicode, subset,
- firstGlyphID(), lastGlyphID()));
+ multiByteGlyphs(), firstGlyphID(),
+ lastGlyphID()));
addResource(pdfCmap.get());
insert("ToUnicode", new SkPDFObjRef(pdfCmap.get()))->unref();
}
@@ -1459,8 +1472,8 @@ bool SkPDFType3Font::populate(int16_t glyphID) {
}
insert("FontBBox", makeFontBBox(bbox, 1000))->unref();
- insertInt("FirstChar", firstGlyphID());
- insertInt("LastChar", lastGlyphID());
+ insertInt("FirstChar", 1);
+ insertInt("LastChar", lastGlyphID() - firstGlyphID() + 1);
insert("Widths", widthArray.get());
insertName("CIDToGIDMap", "Identity");
« no previous file with comments | « no previous file | tests/ToUnicode.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698