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

Unified Diff: trunk/src/pdf/SkPDFFont.cpp

Issue 12739006: move most of SkFontHost to private (preceeding making it all private) (Closed) Base URL: http://skia.googlecode.com/svn/
Patch Set: Created 7 years, 9 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 side-by-side diff with in-line comments
Download patch
« trunk/src/core/SkTypeface.cpp ('K') | « trunk/src/pdf/SkPDFDevice.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: trunk/src/pdf/SkPDFFont.cpp
===================================================================
--- trunk/src/pdf/SkPDFFont.cpp (revision 8112)
+++ trunk/src/pdf/SkPDFFont.cpp (working copy)
@@ -31,6 +31,36 @@
#include SK_SFNTLY_SUBSETTER
#endif
+class SkAutoDefaultTypeface {
+public:
+ SkAutoDefaultTypeface() : fFace(SkTypeface::RefDefault()) {
+ fCallUnref = true;
+ }
+
+ SkAutoDefaultTypeface(SkTypeface* face) : fFace(face) {
+ if (face) {
+ fFace = SkTypeface::RefDefault();
+ fCallUnref = true;
+ } else {
+ fCallUnref = false;
+ }
+ }
+
+ ~SkAutoDefaultTypeface() {
+ if (fCallUnref) {
+ fFace->unref();
+ }
+ }
+
+ SkTypeface* get() const { return fFace; }
+ SkTypeface* operator->() { return fFace; }
+ operator SkTypeface*() { return fFace; }
+
+private:
+ SkTypeface* fFace;
+ bool fCallUnref;
+};
+
namespace {
///////////////////////////////////////////////////////////////////////////////
@@ -541,11 +571,11 @@
#endif
static int get_subset_font_stream(const char* fontName,
- const SkTypeface* typeface,
+ SkTypeface* typeface,
const SkTDArray<uint32_t>& subset,
SkPDFStream** fontStream) {
- SkAutoTUnref<SkStream> fontData(
- SkFontHost::OpenStream(SkTypeface::UniqueID(typeface)));
+ int ttcIndex;
+ SkAutoTUnref<SkStream> fontData(typeface->openStream(&ttcIndex));
int fontSize = fontData->getLength();
@@ -709,7 +739,7 @@
SkDEBUGCODE(int indexFound;)
SkASSERT(index == -1 ||
- (Find(SkTypeface::UniqueID(fTypeface.get()),
+ (Find(fTypeface->uniqueID(),
fFirstGlyphID,
&indexFound) &&
index == indexFound));
@@ -758,9 +788,12 @@
// static
SkPDFFont* SkPDFFont::GetFontResource(SkTypeface* typeface, uint16_t glyphID) {
SkAutoMutexAcquire lock(CanonicalFontsMutex());
- const uint32_t fontID = SkTypeface::UniqueID(typeface);
+
+ SkAutoDefaultTypeface autoFace(typeface);
bungeman-skia 2013/03/12 21:07:23 Is this less verbose and achieve the same ends? S
+ typeface = autoFace.get();
+
int relatedFontIndex;
- if (Find(fontID, glyphID, &relatedFontIndex)) {
+ if (Find(typeface->uniqueID(), glyphID, &relatedFontIndex)) {
CanonicalFonts()[relatedFontIndex].fFont->ref();
return CanonicalFonts()[relatedFontIndex].fFont;
}
@@ -795,7 +828,7 @@
info, SkAdvancedTypefaceMetrics::kHAdvance_PerGlyphInfo);
#endif
fontMetrics.reset(
- SkFontHost::GetAdvancedTypefaceMetrics(fontID, info, NULL, 0));
+ typeface->getAdvancedTypefaceMetrics(info, NULL, 0));
#if defined (SK_SFNTLY_SUBSETTER)
if (fontMetrics.get() &&
fontMetrics->fType != SkAdvancedTypefaceMetrics::kTrueType_Font) {
@@ -803,14 +836,14 @@
info = SkTBitOr<SkAdvancedTypefaceMetrics::PerGlyphInfo>(
info, SkAdvancedTypefaceMetrics::kHAdvance_PerGlyphInfo);
fontMetrics.reset(
- SkFontHost::GetAdvancedTypefaceMetrics(fontID, info, NULL, 0));
+ typeface->getAdvancedTypefaceMetrics(info, NULL, 0));
}
#endif
}
SkPDFFont* font = Create(fontMetrics.get(), typeface, glyphID,
relatedFontDescriptor);
- FontRec newEntry(font, fontID, font->fFirstGlyphID);
+ FontRec newEntry(font, typeface->uniqueID(), font->fFirstGlyphID);
CanonicalFonts().push(newEntry);
return font; // Return the reference new SkPDFFont() created.
}
@@ -855,7 +888,6 @@
fLastGlyphID(info ? info->fLastGlyphID : 0),
fFontInfo(info),
bungeman-skia 2013/03/12 21:07:23 For the same reason this should have been fFontIn
fDescriptor(relatedFontDescriptor) {
- SkSafeRef(typeface);
SkSafeRef(info);
if (info == NULL) {
fFontType = SkAdvancedTypefaceMetrics::kNotEmbeddable_Font;
@@ -864,6 +896,14 @@
} else {
fFontType = info->fType;
}
+
+ // we want fTypeface to always ref a valid typeface, so if the caller
+ // gave us null, we ref the default.
+ if (typeface) {
+ typeface->ref();
+ } else {
+ fTypeface.reset(SkTypeface::RefDefault());
+ }
}
// static
@@ -1094,8 +1134,8 @@
}
case SkAdvancedTypefaceMetrics::kCFF_Font:
case SkAdvancedTypefaceMetrics::kType1CID_Font: {
- SkAutoTUnref<SkStream> fontData(
- SkFontHost::OpenStream(SkTypeface::UniqueID(typeface())));
+ int ttcIndex;
+ SkAutoTUnref<SkStream> fontData(typeface()->openStream(&ttcIndex));
SkAutoTUnref<SkPDFStream> fontStream(
new SkPDFStream(fontData.get()));
addResource(fontStream.get());
@@ -1134,11 +1174,7 @@
uint32_t* glyphs = (glyphIDs.count() == 1) ? NULL : glyphIDs.begin();
uint32_t glyphsCount = glyphs ? glyphIDs.count() : 0;
SkAutoTUnref<SkAdvancedTypefaceMetrics> fontMetrics(
- SkFontHost::GetAdvancedTypefaceMetrics(
- SkTypeface::UniqueID(typeface()),
- info,
- glyphs,
- glyphsCount));
+ typeface()->getAdvancedTypefaceMetrics(info, glyphs, glyphsCount));
setFontInfo(fontMetrics.get());
addFontDescriptor(0, &glyphIDs);
} else {
@@ -1227,8 +1263,8 @@
size_t header SK_INIT_TO_AVOID_WARNING;
size_t data SK_INIT_TO_AVOID_WARNING;
size_t trailer SK_INIT_TO_AVOID_WARNING;
- SkAutoTUnref<SkStream> rawFontData(
- SkFontHost::OpenStream(SkTypeface::UniqueID(typeface())));
+ int ttcIndex;
+ SkAutoTUnref<SkStream> rawFontData(typeface()->openStream(&ttcIndex));
SkStream* fontData = handleType1Stream(rawFontData.get(), &header, &data,
&trailer);
if (fontData == NULL) {
« trunk/src/core/SkTypeface.cpp ('K') | « trunk/src/pdf/SkPDFDevice.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698