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

Side by Side Diff: src/pdf/SkPDFFont.cpp

Issue 2292303004: SkPDF: Fix Type3 ToUnicode table. (Closed)
Patch Set: Created 4 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
OLDNEW
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 "SkData.h" 8 #include "SkData.h"
9 #include "SkGlyphCache.h" 9 #include "SkGlyphCache.h"
10 #include "SkPaint.h" 10 #include "SkPaint.h"
(...skipping 11 matching lines...) Expand all
22 #include "SkUtils.h" 22 #include "SkUtils.h"
23 23
24 #ifdef SK_PDF_USE_SFNTLY 24 #ifdef SK_PDF_USE_SFNTLY
25 #include "sample/chromium/font_subsetter.h" 25 #include "sample/chromium/font_subsetter.h"
26 #endif 26 #endif
27 27
28 namespace { 28 namespace {
29 // PDF's notion of symbolic vs non-symbolic is related to the character set, not 29 // PDF's notion of symbolic vs non-symbolic is related to the character set, not
30 // symbols vs. characters. Rarely is a font the right character set to call it 30 // symbols vs. characters. Rarely is a font the right character set to call it
31 // non-symbolic, so always call it symbolic. (PDF 1.4 spec, section 5.7.1) 31 // non-symbolic, so always call it symbolic. (PDF 1.4 spec, section 5.7.1)
32 static const int kPdfSymbolic = 4; 32 static const int32_t kPdfSymbolic = 4;
33 33
34 struct SkPDFType0Font final : public SkPDFFont { 34 struct SkPDFType0Font final : public SkPDFFont {
35 SkPDFType0Font(SkPDFFont::Info, const SkAdvancedTypefaceMetrics&); 35 SkPDFType0Font(SkPDFFont::Info, const SkAdvancedTypefaceMetrics&);
36 virtual ~SkPDFType0Font(); 36 virtual ~SkPDFType0Font();
37 void getFontSubset(SkPDFCanon*) override; 37 void getFontSubset(SkPDFCanon*) override;
38 #ifdef SK_DEBUG 38 #ifdef SK_DEBUG
39 void emitObject(SkWStream*, const SkPDFObjNumMap&) const override; 39 void emitObject(SkWStream*, const SkPDFObjNumMap&) const override;
40 bool fPopulated; 40 bool fPopulated;
41 #endif 41 #endif
42 typedef SkPDFDict INHERITED; 42 typedef SkPDFDict INHERITED;
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 if (type == SkAdvancedTypefaceMetrics::kType1CID_Font) { 419 if (type == SkAdvancedTypefaceMetrics::kType1CID_Font) {
420 newCIDFont->insertName("Subtype", "CIDFontType0"); 420 newCIDFont->insertName("Subtype", "CIDFontType0");
421 } else if (type == SkAdvancedTypefaceMetrics::kTrueType_Font) { 421 } else if (type == SkAdvancedTypefaceMetrics::kTrueType_Font) {
422 newCIDFont->insertName("Subtype", "CIDFontType2"); 422 newCIDFont->insertName("Subtype", "CIDFontType2");
423 newCIDFont->insertName("CIDToGIDMap", "Identity"); 423 newCIDFont->insertName("CIDToGIDMap", "Identity");
424 } else { 424 } else {
425 SkASSERT(false); 425 SkASSERT(false);
426 } 426 }
427 427
428 auto sysInfo = sk_make_sp<SkPDFDict>(); 428 auto sysInfo = sk_make_sp<SkPDFDict>();
429 sysInfo->insertString("Registry", "Adobe"); 429 sysInfo->insertString("Registry", "Skia");
Rik 2016/09/01 17:41:21 This change isn't needed
430 sysInfo->insertString("Ordering", "Identity"); 430 // TODO: Registry+Ordering should be globally unique!
431 sysInfo->insertString("Ordering", "SkiaOrdering");
Rik 2016/09/01 17:41:21 Neither is this one
431 sysInfo->insertInt("Supplement", 0); 432 sysInfo->insertInt("Supplement", 0);
432 newCIDFont->insertObject("CIDSystemInfo", std::move(sysInfo)); 433 newCIDFont->insertObject("CIDSystemInfo", std::move(sysInfo));
433 434
434 uint16_t emSize = metrics.fEmSize; 435 uint16_t emSize = metrics.fEmSize;
435 int16_t defaultWidth = 0; 436 int16_t defaultWidth = 0;
436 { 437 {
437 SkAutoGlyphCache glyphCache = vector_cache(face); 438 SkAutoGlyphCache glyphCache = vector_cache(face);
438 sk_sp<SkPDFArray> widths = SkPDFMakeCIDGlyphWidthsArray( 439 sk_sp<SkPDFArray> widths = SkPDFMakeCIDGlyphWidthsArray(
439 glyphCache.get(), &this->glyphUsage(), emSize, &defaultWidth); 440 glyphCache.get(), &this->glyphUsage(), emSize, &defaultWidth);
440 if (widths && widths->size() > 0) { 441 if (widths && widths->size() > 0) {
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 }; 591 };
591 } 592 }
592 593
593 static void add_type3_font_info(SkPDFCanon* canon, 594 static void add_type3_font_info(SkPDFCanon* canon,
594 SkPDFDict* font, 595 SkPDFDict* font,
595 SkTypeface* typeface, 596 SkTypeface* typeface,
596 SkScalar emSize, 597 SkScalar emSize,
597 const SkBitSet& subset, 598 const SkBitSet& subset,
598 SkGlyphID firstGlyphID, 599 SkGlyphID firstGlyphID,
599 SkGlyphID lastGlyphID) { 600 SkGlyphID lastGlyphID) {
601 const SkAdvancedTypefaceMetrics* metrics = SkPDFFont::GetMetrics(typeface, c anon);
600 SkASSERT(lastGlyphID >= firstGlyphID); 602 SkASSERT(lastGlyphID >= firstGlyphID);
601 // Remove unused glyphs at the end of the range. 603 // Remove unused glyphs at the end of the range.
602 // Keep the lastGlyphID >= firstGlyphID invariant true. 604 // Keep the lastGlyphID >= firstGlyphID invariant true.
603 while (lastGlyphID > firstGlyphID && !subset.has(lastGlyphID)) { 605 while (lastGlyphID > firstGlyphID && !subset.has(lastGlyphID)) {
604 --lastGlyphID; 606 --lastGlyphID;
605 } 607 }
606 SkASSERT(emSize > 0.0f); 608 SkASSERT(emSize > 0.0f);
607 SkAutoGlyphCache cache = vector_cache(typeface, emSize); 609 SkAutoGlyphCache cache = vector_cache(typeface, emSize);
608 font->insertName("Subtype", "Type3"); 610 font->insertName("Subtype", "Type3");
609 // Flip about the x-axis and scale by 1/emSize. 611 // Flip about the x-axis and scale by 1/emSize.
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
677 glyphs of the font were placed with their origins coincident and 679 glyphs of the font were placed with their origins coincident and
678 then filled." */ 680 then filled." */
679 auto fontBBox = sk_make_sp<SkPDFArray>(); 681 auto fontBBox = sk_make_sp<SkPDFArray>();
680 fontBBox->reserve(4); 682 fontBBox->reserve(4);
681 fontBBox->appendInt(bbox.left()); 683 fontBBox->appendInt(bbox.left());
682 fontBBox->appendInt(bbox.bottom()); 684 fontBBox->appendInt(bbox.bottom());
683 fontBBox->appendInt(bbox.right()); 685 fontBBox->appendInt(bbox.right());
684 fontBBox->appendInt(bbox.top()); 686 fontBBox->appendInt(bbox.top());
685 font->insertObject("FontBBox", std::move(fontBBox)); 687 font->insertObject("FontBBox", std::move(fontBBox));
686 font->insertName("CIDToGIDMap", "Identity"); 688 font->insertName("CIDToGIDMap", "Identity");
687 const SkAdvancedTypefaceMetrics* metrics = SkPDFFont::GetMetrics(typeface, c anon); 689 if (metrics && metrics->fGlyphToUnicode.count() > 0) {
688 if (metrics /* && metrics->fGlyphToUnicode.count() > 0 */) {
689 font->insertObjRef("ToUnicode", 690 font->insertObjRef("ToUnicode",
690 SkPDFMakeToUnicodeCmap(metrics->fGlyphToUnicode, 691 SkPDFMakeToUnicodeCmap(metrics->fGlyphToUnicode,
691 &subset, 692 &subset,
692 false, 693 false,
693 firstGlyphID, 694 firstGlyphID,
694 lastGlyphID)); 695 lastGlyphID));
695 } 696 }
697 auto descriptor = sk_make_sp<SkPDFDict>("FontDescriptor");
698 int32_t fontDescriptorFlags = kPdfSymbolic;
699 if (metrics) {
700 // Type3 FontDescriptor does not require all the same fields.
701 descriptor->insertName("FontName", metrics->fFontName);
702 descriptor->insertInt("ItalicAngle", metrics->fItalicAngle);
703 fontDescriptorFlags |= (int32_t)metrics->fStyle;
704 }
705 descriptor->insertInt("Flags", fontDescriptorFlags);
706 font->insertObjRef("FontDescriptor", std::move(descriptor));
696 font->insertObject("Widths", std::move(widthArray)); 707 font->insertObject("Widths", std::move(widthArray));
697 font->insertObject("Encoding", std::move(encoding)); 708 font->insertObject("Encoding", std::move(encoding));
698 font->insertObject("CharProcs", std::move(charProcs)); 709 font->insertObject("CharProcs", std::move(charProcs));
699 } 710 }
700 711
701 SkPDFType3Font::SkPDFType3Font(SkPDFFont::Info info, 712 SkPDFType3Font::SkPDFType3Font(SkPDFFont::Info info,
702 const SkAdvancedTypefaceMetrics& metrics) 713 const SkAdvancedTypefaceMetrics& metrics)
703 : SkPDFFont(std::move(info)) {} 714 : SkPDFFont(std::move(info)) {}
704 715
705 void SkPDFType3Font::getFontSubset(SkPDFCanon* canon) { 716 void SkPDFType3Font::getFontSubset(SkPDFCanon* canon) {
(...skipping 10 matching lines...) Expand all
716 727
717 bool SkPDFFont::CanEmbedTypeface(SkTypeface* typeface, SkPDFCanon* canon) { 728 bool SkPDFFont::CanEmbedTypeface(SkTypeface* typeface, SkPDFCanon* canon) {
718 const SkAdvancedTypefaceMetrics* metrics = SkPDFFont::GetMetrics(typeface, c anon); 729 const SkAdvancedTypefaceMetrics* metrics = SkPDFFont::GetMetrics(typeface, c anon);
719 return metrics && can_embed(*metrics); 730 return metrics && can_embed(*metrics);
720 } 731 }
721 732
722 void SkPDFFont::drop() { 733 void SkPDFFont::drop() {
723 fTypeface = nullptr; 734 fTypeface = nullptr;
724 this->SkPDFDict::drop(); 735 this->SkPDFDict::drop();
725 } 736 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698