[PDF] Fix font width generation when glyph 0 is used.
authorcommit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Wed, 11 Dec 2013 23:54:31 +0000 (23:54 +0000)
committercommit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Wed, 11 Dec 2013 23:54:31 +0000 (23:54 +0000)
Using glyph 0 caused gid 0 to be in the subset list twice, which violated an assumption in the code.  Added an assert for the assumption and updated the code to  not insert gid 0 into the subset list twice.

BUG=skia:1889
R=bungeman@google.com

Author: vandebo@chromium.org

Review URL: https://codereview.chromium.org/113093004

git-svn-id: http://skia.googlecode.com/svn/trunk@12632 2bbb7eff-a529-9590-31e7-b0007b416f81

src/core/SkAdvancedTypefaceMetrics.cpp
src/pdf/SkPDFFont.cpp

index ce64a42d0a9bfb2cbce7d7d405c3db4d217b2254..f9b25dc96aac1808cf59e6dbea403fa3d8e2024c 100644 (file)
@@ -169,6 +169,8 @@ SkAdvancedTypefaceMetrics::AdvanceMetric<Data>* getAdvanceData(
         Data advance = kInvalidAdvance;
         if (gId < lastIndex) {
             // Get glyph id only when subset is NULL, or the id is in subset.
+            SkASSERT(!subsetGlyphIDs || (subsetIndex < subsetGlyphIDsLength &&
+                    static_cast<uint32_t>(gId) <= subsetGlyphIDs[subsetIndex]));
             if (!subsetGlyphIDs ||
                 (subsetIndex < subsetGlyphIDsLength &&
                  static_cast<uint32_t>(gId) == subsetGlyphIDs[subsetIndex])) {
index ef9c3bbc042ebf559a97d29461218f4bfb14204b..07ecbba37e2dbfe34631976e8346009bf3dc9fab 100644 (file)
@@ -1156,8 +1156,11 @@ bool SkPDFCIDFont::populate(const SkPDFGlyphSet* subset) {
     if (fontInfo()->fType == SkAdvancedTypefaceMetrics::kTrueType_Font) {
         // Generate glyph id array.
         SkTDArray<uint32_t> glyphIDs;
-        glyphIDs.push(0);  // Always include glyph 0.
         if (subset) {
+            // Always include glyph 0.
+            if (!subset->has(0)) {
+                glyphIDs.push(0);
+            }
             subset->exportTo(&glyphIDs);
         }
 
@@ -1165,7 +1168,7 @@ bool SkPDFCIDFont::populate(const SkPDFGlyphSet* subset) {
         info = SkAdvancedTypefaceMetrics::kGlyphNames_PerGlyphInfo;
         info = SkTBitOr<SkAdvancedTypefaceMetrics::PerGlyphInfo>(
                   info, SkAdvancedTypefaceMetrics::kHAdvance_PerGlyphInfo);
-        uint32_t* glyphs = (glyphIDs.count() == 1) ? NULL : glyphIDs.begin();
+        uint32_t* glyphs = (glyphIDs.count() == 0) ? NULL : glyphIDs.begin();
         uint32_t glyphsCount = glyphs ? glyphIDs.count() : 0;
         SkAutoTUnref<SkAdvancedTypefaceMetrics> fontMetrics(
             typeface()->getAdvancedTypefaceMetrics(info, glyphs, glyphsCount));