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

Unified Diff: src/pdf/SkPDFFont.cpp

Issue 1227913008: SkPDF: Memory improvements for PDF Streams (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-08-19 (Wednesday) 17:47:45 EDT Created 5 years, 4 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
« no previous file with comments | « no previous file | src/pdf/SkPDFStream.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 017b0168b04d8625131cd1bf78dd2c6b7b78f74a..333fb4aadbe0c91d0671330b96da96c77d005505 100644
--- a/src/pdf/SkPDFFont.cpp
+++ b/src/pdf/SkPDFFont.cpp
@@ -584,6 +584,7 @@ static void sk_delete_array(const void* ptr, void*) {
}
#endif
+#if defined(SK_SFNTLY_SUBSETTER)
static size_t get_subset_font_stream(const char* fontName,
const SkTypeface* typeface,
const SkTDArray<uint32_t>& subset,
@@ -594,7 +595,6 @@ static size_t get_subset_font_stream(const char* fontName,
size_t fontSize = fontData->getLength();
-#if defined (SK_SFNTLY_SUBSETTER)
// Read font into buffer.
SkPDFStream* subsetFontStream = NULL;
SkTDArray<unsigned char> originalFont;
@@ -625,15 +625,12 @@ static size_t get_subset_font_stream(const char* fontName,
return fontSize;
}
fontData->rewind();
-#else
- sk_ignore_unused_variable(fontName);
- sk_ignore_unused_variable(subset);
-#endif
// Fail over: just embed the whole font.
*fontStream = new SkPDFStream(fontData.get());
return fontSize;
}
+#endif
///////////////////////////////////////////////////////////////////////////////
// class SkPDFGlyphSet
@@ -1062,40 +1059,43 @@ bool SkPDFCIDFont::addFontDescriptor(int16_t defaultWidth,
switch (getType()) {
case SkAdvancedTypefaceMetrics::kTrueType_Font: {
- SkAutoTUnref<SkPDFStream> fontStream;
size_t fontSize = 0;
- if (canSubset()) {
+#if defined(SK_SFNTLY_SUBSETTER)
+ if (this->canSubset()) {
+ SkAutoTUnref<SkPDFStream> fontStream;
SkPDFStream* rawStream = NULL;
fontSize = get_subset_font_stream(fontInfo()->fFontName.c_str(),
typeface(),
*subset,
&rawStream);
- fontStream.reset(rawStream);
- } else {
- int ttcIndex;
- SkAutoTDelete<SkStream> fontData(
- typeface()->openStream(&ttcIndex));
- fontStream.reset(new SkPDFStream(fontData.get()));
- fontSize = fontData->getLength();
+ if (rawStream) {
+ fontStream.reset(rawStream);
+ fontStream->insertInt("Length1", fontSize);
+ descriptor->insertObjRef("FontFile2", fontStream.detach());
+ break;
+ }
}
- SkASSERT(fontSize);
- SkASSERT(fontStream.get());
-
- fontStream->insertInt("Length1", fontSize);
+#endif
+ SkAutoTUnref<SkPDFSharedStream> fontStream;
+ SkAutoTDelete<SkStreamAsset> fontData(
+ this->typeface()->openStream(NULL));
+ SkASSERT(fontData);
+ fontSize = fontData->getLength();
+ SkASSERT(fontSize > 0);
+ fontStream.reset(new SkPDFSharedStream(fontData.detach()));
+ fontStream->dict()->insertInt("Length1", fontSize);
descriptor->insertObjRef("FontFile2", fontStream.detach());
break;
}
case SkAdvancedTypefaceMetrics::kCFF_Font:
case SkAdvancedTypefaceMetrics::kType1CID_Font: {
- int ttcIndex;
- SkAutoTDelete<SkStream> fontData(typeface()->openStream(&ttcIndex));
- SkAutoTUnref<SkPDFStream> fontStream(
- new SkPDFStream(fontData.get()));
+ SkAutoTUnref<SkPDFSharedStream> fontStream(
+ new SkPDFSharedStream(this->typeface()->openStream(NULL)));
if (getType() == SkAdvancedTypefaceMetrics::kCFF_Font) {
- fontStream->insertName("Subtype", "Type1C");
+ fontStream->dict()->insertName("Subtype", "Type1C");
} else {
- fontStream->insertName("Subtype", "CIDFontType0c");
+ fontStream->dict()->insertName("Subtype", "CIDFontType0c");
}
descriptor->insertObjRef("FontFile3", fontStream.detach());
break;
« no previous file with comments | « no previous file | src/pdf/SkPDFStream.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698