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

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-18 (Tuesday) 16:37:32 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.h » ('j') | src/pdf/SkPDFStream.h » ('J')
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 d8755ae9a38572bfe9cca0a73864e479a6c40278..8783f385b65eba91f3860013e95f630e1a9e478d 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());
tomhudson 2015/08/19 19:27:51 The code duplication between here and (canSubset()
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");
tomhudson 2015/08/19 19:27:51 Is the addition of dict() a bugfix? A noop? An int
hal.canary 2015/08/19 19:34:20 I intentionally do not inherit from SkPDFDict anym
} 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.h » ('j') | src/pdf/SkPDFStream.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698