diff options
author | Hal Canary <halcanary@google.com> | 2017-04-17 16:30:06 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-05-04 13:08:29 +0000 |
commit | 5c1b360a89f85accd7dc446670f6f062c73e7e77 (patch) | |
tree | a15f476b39778027f982d753719487bc4a6d34ca /src/pdf/SkPDFFont.cpp | |
parent | bc6e5ff7cfbacc28659c0aecbe9f2989cad80336 (diff) |
src/pdf: code cleanup
* SkPDFCanon: remove unnecessary abstraction
* Make use of SkTHashMap<K, sk_sp<T>>.
* Remove unncessary struct constructors.
* More factory fns return sk_sp<T>
* SkPDFUtility::GetCachedT<T> factored out.
Change-Id: I4055a131b43fe2588fd042b769cd09fff8a3466c
Reviewed-on: https://skia-review.googlesource.com/13655
Reviewed-by: Ben Wagner <bungeman@google.com>
Commit-Queue: Hal Canary <halcanary@google.com>
Diffstat (limited to 'src/pdf/SkPDFFont.cpp')
-rw-r--r-- | src/pdf/SkPDFFont.cpp | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/src/pdf/SkPDFFont.cpp b/src/pdf/SkPDFFont.cpp index 09d133ece7..b373514808 100644 --- a/src/pdf/SkPDFFont.cpp +++ b/src/pdf/SkPDFFont.cpp @@ -142,8 +142,8 @@ const SkAdvancedTypefaceMetrics* SkPDFFont::GetMetrics(SkTypeface* typeface, SkPDFCanon* canon) { SkASSERT(typeface); SkFontID id = typeface->uniqueID(); - if (SkAdvancedTypefaceMetrics** ptr = canon->fTypefaceMetrics.find(id)) { - return *ptr; + if (sk_sp<SkAdvancedTypefaceMetrics>* ptr = canon->fTypefaceMetrics.find(id)) { + return ptr->get(); // canon retains ownership. } int count = typeface->countGlyphs(); if (count <= 0 || count > 1 + SK_MaxU16) { @@ -158,7 +158,7 @@ const SkAdvancedTypefaceMetrics* SkPDFFont::GetMetrics(SkTypeface* typeface, if (!metrics) { metrics = sk_make_sp<SkAdvancedTypefaceMetrics>(); } - return *canon->fTypefaceMetrics.set(id, metrics.release()); + return canon->fTypefaceMetrics.set(id, std::move(metrics))->get(); } SkAdvancedTypefaceMetrics::FontType SkPDFFont::FontType(const SkAdvancedTypefaceMetrics& metrics) { @@ -174,9 +174,9 @@ static SkGlyphID first_nonzero_glyph_for_single_byte_encoding(SkGlyphID gid) { return gid != 0 ? gid - (gid - 1) % 255 : 1; } -SkPDFFont* SkPDFFont::GetFontResource(SkPDFCanon* canon, - SkTypeface* face, - SkGlyphID glyphID) { +sk_sp<SkPDFFont> SkPDFFont::GetFontResource(SkPDFCanon* canon, + SkTypeface* face, + SkGlyphID glyphID) { SkASSERT(canon); SkASSERT(face); // All SkPDFDevice::internalDrawText ensures this. const SkAdvancedTypefaceMetrics* fontMetrics = SkPDFFont::GetMetrics(face, canon); @@ -188,10 +188,10 @@ SkPDFFont* SkPDFFont::GetFontResource(SkPDFCanon* canon, SkGlyphID subsetCode = multibyte ? 0 : first_nonzero_glyph_for_single_byte_encoding(glyphID); uint64_t fontID = (SkTypeface::UniqueID(face) << 16) | subsetCode; - if (SkPDFFont** found = canon->fFontMap.find(fontID)) { - SkPDFFont* foundFont = *found; + if (sk_sp<SkPDFFont>* found = canon->fFontMap.find(fontID)) { + SkDEBUGCODE(SkPDFFont* foundFont = found->get()); SkASSERT(foundFont && multibyte == foundFont->multiByteGlyphs()); - return SkRef(foundFont); + return *found; } sk_sp<SkTypeface> typeface(sk_ref_sp(face)); @@ -227,8 +227,8 @@ SkPDFFont* SkPDFFont::GetFontResource(SkPDFCanon* canon, font = sk_make_sp<SkPDFType3Font>(std::move(info), metrics); break; } - canon->fFontMap.set(fontID, SkRef(font.get())); - return font.release(); // TODO(halcanary) return sk_sp<SkPDFFont>. + canon->fFontMap.set(fontID, font); + return font; } SkPDFFont::SkPDFFont(SkPDFFont::Info info) @@ -544,11 +544,11 @@ SkPDFType1Font::SkPDFType1Font(SkPDFFont::Info info, { SkFontID fontID = this->typeface()->uniqueID(); sk_sp<SkPDFDict> fontDescriptor; - if (SkPDFDict** ptr = canon->fFontDescriptors.find(fontID)) { - fontDescriptor = sk_ref_sp(*ptr); + if (sk_sp<SkPDFDict>* ptr = canon->fFontDescriptors.find(fontID)) { + fontDescriptor = *ptr; } else { fontDescriptor = make_type1_font_descriptor(this->typeface(), metrics); - canon->fFontDescriptors.set(fontID, SkRef(fontDescriptor.get())); + canon->fFontDescriptors.set(fontID, fontDescriptor); } this->insertObjRef("FontDescriptor", std::move(fontDescriptor)); // TODO(halcanary): subset this (advances and names). |