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

Side by Side Diff: src/pdf/SkPDFFont.cpp

Issue 849103004: Make SkStream *not* ref counted. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Rebase, just in case. Created 5 years, 11 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 unified diff | Download patch
« no previous file with comments | « src/images/SkMovie.cpp ('k') | src/pdf/SkPDFFormXObject.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include <ctype.h> 8 #include <ctype.h>
9 9
10 #include "SkData.h" 10 #include "SkData.h"
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 } 150 }
151 151
152 static SkData* handle_type1_stream(SkStream* srcStream, size_t* headerLen, 152 static SkData* handle_type1_stream(SkStream* srcStream, size_t* headerLen,
153 size_t* dataLen, size_t* trailerLen) { 153 size_t* dataLen, size_t* trailerLen) {
154 // srcStream may be backed by a file or a unseekable fd, so we may not be 154 // srcStream may be backed by a file or a unseekable fd, so we may not be
155 // able to use skip(), rewind(), or getMemoryBase(). read()ing through 155 // able to use skip(), rewind(), or getMemoryBase(). read()ing through
156 // the input only once is doable, but very ugly. Furthermore, it'd be nice 156 // the input only once is doable, but very ugly. Furthermore, it'd be nice
157 // if the data was NUL terminated so that we can use strstr() to search it. 157 // if the data was NUL terminated so that we can use strstr() to search it.
158 // Make as few copies as possible given these constraints. 158 // Make as few copies as possible given these constraints.
159 SkDynamicMemoryWStream dynamicStream; 159 SkDynamicMemoryWStream dynamicStream;
160 SkAutoTUnref<SkMemoryStream> staticStream; 160 SkAutoTDelete<SkMemoryStream> staticStream;
161 SkData* data = NULL; 161 SkData* data = NULL;
162 const uint8_t* src; 162 const uint8_t* src;
163 size_t srcLen; 163 size_t srcLen;
164 if ((srcLen = srcStream->getLength()) > 0) { 164 if ((srcLen = srcStream->getLength()) > 0) {
165 staticStream.reset(new SkMemoryStream(srcLen + 1)); 165 staticStream.reset(new SkMemoryStream(srcLen + 1));
166 src = (const uint8_t*)staticStream->getMemoryBase(); 166 src = (const uint8_t*)staticStream->getMemoryBase();
167 if (srcStream->getMemoryBase() != NULL) { 167 if (srcStream->getMemoryBase() != NULL) {
168 memcpy((void *)src, srcStream->getMemoryBase(), srcLen); 168 memcpy((void *)src, srcStream->getMemoryBase(), srcLen);
169 } else { 169 } else {
170 size_t read = 0; 170 size_t read = 0;
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 // Use C-style cast to cast away const and cast type simultaneously. 578 // Use C-style cast to cast away const and cast type simultaneously.
579 delete[] (unsigned char*)ptr; 579 delete[] (unsigned char*)ptr;
580 } 580 }
581 #endif 581 #endif
582 582
583 static size_t get_subset_font_stream(const char* fontName, 583 static size_t get_subset_font_stream(const char* fontName,
584 const SkTypeface* typeface, 584 const SkTypeface* typeface,
585 const SkTDArray<uint32_t>& subset, 585 const SkTDArray<uint32_t>& subset,
586 SkPDFStream** fontStream) { 586 SkPDFStream** fontStream) {
587 int ttcIndex; 587 int ttcIndex;
588 SkAutoTUnref<SkStream> fontData(typeface->openStream(&ttcIndex)); 588 SkAutoTDelete<SkStream> fontData(typeface->openStream(&ttcIndex));
589 SkASSERT(fontData.get()); 589 SkASSERT(fontData.get());
590 590
591 size_t fontSize = fontData->getLength(); 591 size_t fontSize = fontData->getLength();
592 592
593 #if defined (SK_SFNTLY_SUBSETTER) 593 #if defined (SK_SFNTLY_SUBSETTER)
594 // Read font into buffer. 594 // Read font into buffer.
595 SkPDFStream* subsetFontStream = NULL; 595 SkPDFStream* subsetFontStream = NULL;
596 SkTDArray<unsigned char> originalFont; 596 SkTDArray<unsigned char> originalFont;
597 originalFont.setCount(SkToInt(fontSize)); 597 originalFont.setCount(SkToInt(fontSize));
598 if (fontData->read(originalFont.begin(), fontSize) == fontSize) { 598 if (fontData->read(originalFont.begin(), fontSize) == fontSize) {
(...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after
1154 size_t fontSize = 0; 1154 size_t fontSize = 0;
1155 if (canSubset()) { 1155 if (canSubset()) {
1156 SkPDFStream* rawStream = NULL; 1156 SkPDFStream* rawStream = NULL;
1157 fontSize = get_subset_font_stream(fontInfo()->fFontName.c_str(), 1157 fontSize = get_subset_font_stream(fontInfo()->fFontName.c_str(),
1158 typeface(), 1158 typeface(),
1159 *subset, 1159 *subset,
1160 &rawStream); 1160 &rawStream);
1161 fontStream.reset(rawStream); 1161 fontStream.reset(rawStream);
1162 } else { 1162 } else {
1163 int ttcIndex; 1163 int ttcIndex;
1164 SkAutoTUnref<SkStream> fontData( 1164 SkAutoTDelete<SkStream> fontData(
1165 typeface()->openStream(&ttcIndex)); 1165 typeface()->openStream(&ttcIndex));
1166 fontStream.reset(new SkPDFStream(fontData.get())); 1166 fontStream.reset(new SkPDFStream(fontData.get()));
1167 fontSize = fontData->getLength(); 1167 fontSize = fontData->getLength();
1168 } 1168 }
1169 SkASSERT(fontSize); 1169 SkASSERT(fontSize);
1170 SkASSERT(fontStream.get()); 1170 SkASSERT(fontStream.get());
1171 addResource(fontStream.get()); 1171 addResource(fontStream.get());
1172 1172
1173 fontStream->insertInt("Length1", fontSize); 1173 fontStream->insertInt("Length1", fontSize);
1174 descriptor->insert("FontFile2", 1174 descriptor->insert("FontFile2",
1175 new SkPDFObjRef(fontStream.get()))->unref(); 1175 new SkPDFObjRef(fontStream.get()))->unref();
1176 break; 1176 break;
1177 } 1177 }
1178 case SkAdvancedTypefaceMetrics::kCFF_Font: 1178 case SkAdvancedTypefaceMetrics::kCFF_Font:
1179 case SkAdvancedTypefaceMetrics::kType1CID_Font: { 1179 case SkAdvancedTypefaceMetrics::kType1CID_Font: {
1180 int ttcIndex; 1180 int ttcIndex;
1181 SkAutoTUnref<SkStream> fontData(typeface()->openStream(&ttcIndex)); 1181 SkAutoTDelete<SkStream> fontData(typeface()->openStream(&ttcIndex));
1182 SkAutoTUnref<SkPDFStream> fontStream( 1182 SkAutoTUnref<SkPDFStream> fontStream(
1183 new SkPDFStream(fontData.get())); 1183 new SkPDFStream(fontData.get()));
1184 addResource(fontStream.get()); 1184 addResource(fontStream.get());
1185 1185
1186 if (getType() == SkAdvancedTypefaceMetrics::kCFF_Font) { 1186 if (getType() == SkAdvancedTypefaceMetrics::kCFF_Font) {
1187 fontStream->insertName("Subtype", "Type1C"); 1187 fontStream->insertName("Subtype", "Type1C");
1188 } else { 1188 } else {
1189 fontStream->insertName("Subtype", "CIDFontType0c"); 1189 fontStream->insertName("Subtype", "CIDFontType0c");
1190 } 1190 }
1191 descriptor->insert("FontFile3", 1191 descriptor->insert("FontFile3",
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
1301 return true; 1301 return true;
1302 } 1302 }
1303 1303
1304 SkAutoTUnref<SkPDFDict> descriptor(new SkPDFDict("FontDescriptor")); 1304 SkAutoTUnref<SkPDFDict> descriptor(new SkPDFDict("FontDescriptor"));
1305 setFontDescriptor(descriptor.get()); 1305 setFontDescriptor(descriptor.get());
1306 1306
1307 int ttcIndex; 1307 int ttcIndex;
1308 size_t header SK_INIT_TO_AVOID_WARNING; 1308 size_t header SK_INIT_TO_AVOID_WARNING;
1309 size_t data SK_INIT_TO_AVOID_WARNING; 1309 size_t data SK_INIT_TO_AVOID_WARNING;
1310 size_t trailer SK_INIT_TO_AVOID_WARNING; 1310 size_t trailer SK_INIT_TO_AVOID_WARNING;
1311 SkAutoTUnref<SkStream> rawFontData(typeface()->openStream(&ttcIndex)); 1311 SkAutoTDelete<SkStream> rawFontData(typeface()->openStream(&ttcIndex));
1312 SkAutoTUnref<SkData> fontData(handle_type1_stream(rawFontData.get(), &header , 1312 SkAutoTUnref<SkData> fontData(handle_type1_stream(rawFontData.get(), &header ,
1313 &data, &trailer)); 1313 &data, &trailer));
1314 if (fontData.get() == NULL) { 1314 if (fontData.get() == NULL) {
1315 return false; 1315 return false;
1316 } 1316 }
1317 if (canEmbed()) { 1317 if (canEmbed()) {
1318 SkAutoTUnref<SkPDFStream> fontStream(new SkPDFStream(fontData.get())); 1318 SkAutoTUnref<SkPDFStream> fontStream(new SkPDFStream(fontData.get()));
1319 addResource(fontStream.get()); 1319 addResource(fontStream.get());
1320 fontStream->insertInt("Length1", header); 1320 fontStream->insertInt("Length1", header);
1321 fontStream->insertInt("Length2", data); 1321 fontStream->insertInt("Length2", data);
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
1468 1468
1469 SkDynamicMemoryWStream content; 1469 SkDynamicMemoryWStream content;
1470 setGlyphWidthAndBoundingBox(SkFixedToScalar(glyph.fAdvanceX), glyphBBox, 1470 setGlyphWidthAndBoundingBox(SkFixedToScalar(glyph.fAdvanceX), glyphBBox,
1471 &content); 1471 &content);
1472 const SkPath* path = cache->findPath(glyph); 1472 const SkPath* path = cache->findPath(glyph);
1473 if (path) { 1473 if (path) {
1474 SkPDFUtils::EmitPath(*path, paint.getStyle(), &content); 1474 SkPDFUtils::EmitPath(*path, paint.getStyle(), &content);
1475 SkPDFUtils::PaintPath(paint.getStyle(), path->getFillType(), 1475 SkPDFUtils::PaintPath(paint.getStyle(), path->getFillType(),
1476 &content); 1476 &content);
1477 } 1477 }
1478 SkAutoTUnref<SkMemoryStream> glyphStream(new SkMemoryStream()); 1478 SkAutoTDelete<SkMemoryStream> glyphStream(new SkMemoryStream());
1479 glyphStream->setData(content.copyToData())->unref(); 1479 glyphStream->setData(content.copyToData())->unref();
1480 1480
1481 SkAutoTUnref<SkPDFStream> glyphDescription( 1481 SkAutoTUnref<SkPDFStream> glyphDescription(
1482 new SkPDFStream(glyphStream.get())); 1482 new SkPDFStream(glyphStream.get()));
1483 addResource(glyphDescription.get()); 1483 addResource(glyphDescription.get());
1484 charProcs->insert(characterName.c_str(), 1484 charProcs->insert(characterName.c_str(),
1485 new SkPDFObjRef(glyphDescription.get()))->unref(); 1485 new SkPDFObjRef(glyphDescription.get()))->unref();
1486 } 1486 }
1487 1487
1488 insert("FontBBox", makeFontBBox(bbox, 1000))->unref(); 1488 insert("FontBBox", makeFontBBox(bbox, 1000))->unref();
1489 insertInt("FirstChar", 1); 1489 insertInt("FirstChar", 1);
1490 insertInt("LastChar", lastGlyphID() - firstGlyphID() + 1); 1490 insertInt("LastChar", lastGlyphID() - firstGlyphID() + 1);
1491 insert("Widths", widthArray.get()); 1491 insert("Widths", widthArray.get());
1492 insertName("CIDToGIDMap", "Identity"); 1492 insertName("CIDToGIDMap", "Identity");
1493 1493
1494 populateToUnicodeTable(NULL); 1494 populateToUnicodeTable(NULL);
1495 return true; 1495 return true;
1496 } 1496 }
OLDNEW
« no previous file with comments | « src/images/SkMovie.cpp ('k') | src/pdf/SkPDFFormXObject.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698