OLD | NEW |
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 "SkPDFCanon.h" | 8 #include "SkPDFCanon.h" |
9 #include "SkPDFCanvas.h" | 9 #include "SkPDFCanvas.h" |
10 #include "SkPDFDevice.h" | 10 #include "SkPDFDevice.h" |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 } | 161 } |
162 SkDEBUGCODE( for (const auto& n : curNodes) { SkASSERT(!n); } ); | 162 SkDEBUGCODE( for (const auto& n : curNodes) { SkASSERT(!n); } ); |
163 | 163 |
164 curNodes.swap(&nextRoundNodes); | 164 curNodes.swap(&nextRoundNodes); |
165 nextRoundNodes.reset(); | 165 nextRoundNodes.reset(); |
166 treeCapacity *= kNodeSize; | 166 treeCapacity *= kNodeSize; |
167 } while (curNodes.count() > 1); | 167 } while (curNodes.count() > 1); |
168 return std::move(curNodes[0]); | 168 return std::move(curNodes[0]); |
169 } | 169 } |
170 | 170 |
| 171 #if 0 |
| 172 // TODO(halcanary): expose notEmbeddableCount in SkDocument |
| 173 void GetCountOfFontTypes( |
| 174 const SkTDArray<SkPDFDevice*>& pageDevices, |
| 175 int counts[SkAdvancedTypefaceMetrics::kOther_Font + 1], |
| 176 int* notSubsettableCount, |
| 177 int* notEmbeddableCount) { |
| 178 sk_bzero(counts, sizeof(int) * |
| 179 (SkAdvancedTypefaceMetrics::kOther_Font + 1)); |
| 180 SkTDArray<SkFontID> seenFonts; |
| 181 int notSubsettable = 0; |
| 182 int notEmbeddable = 0; |
| 183 |
| 184 for (int pageNumber = 0; pageNumber < pageDevices.count(); pageNumber++) { |
| 185 const SkTDArray<SkPDFFont*>& fontResources = |
| 186 pageDevices[pageNumber]->getFontResources(); |
| 187 for (int font = 0; font < fontResources.count(); font++) { |
| 188 SkFontID fontID = fontResources[font]->typeface()->uniqueID(); |
| 189 if (seenFonts.find(fontID) == -1) { |
| 190 counts[fontResources[font]->getType()]++; |
| 191 seenFonts.push(fontID); |
| 192 if (!fontResources[font]->canSubset()) { |
| 193 notSubsettable++; |
| 194 } |
| 195 if (!fontResources[font]->canEmbed()) { |
| 196 notEmbeddable++; |
| 197 } |
| 198 } |
| 199 } |
| 200 } |
| 201 if (notSubsettableCount) { |
| 202 *notSubsettableCount = notSubsettable; |
| 203 |
| 204 } |
| 205 if (notEmbeddableCount) { |
| 206 *notEmbeddableCount = notEmbeddable; |
| 207 } |
| 208 } |
| 209 #endif |
| 210 |
171 template <typename T> static T* clone(const T* o) { return o ? new T(*o) : nullp
tr; } | 211 template <typename T> static T* clone(const T* o) { return o ? new T(*o) : nullp
tr; } |
172 //////////////////////////////////////////////////////////////////////////////// | 212 //////////////////////////////////////////////////////////////////////////////// |
173 | 213 |
174 SkPDFDocument::SkPDFDocument(SkWStream* stream, | 214 SkPDFDocument::SkPDFDocument(SkWStream* stream, |
175 void (*doneProc)(SkWStream*, bool), | 215 void (*doneProc)(SkWStream*, bool), |
176 SkScalar rasterDpi, | 216 SkScalar rasterDpi, |
177 const SkDocument::PDFMetadata& metadata, | 217 const SkDocument::PDFMetadata& metadata, |
178 sk_sp<SkPixelSerializer> jpegEncoder, | 218 sk_sp<SkPixelSerializer> jpegEncoder, |
179 bool pdfa) | 219 bool pdfa) |
180 : SkDocument(stream, doneProc) | 220 : SkDocument(stream, doneProc) |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 docCatalog->insertObjRef("Pages", generate_page_tree(&fPages)); | 477 docCatalog->insertObjRef("Pages", generate_page_tree(&fPages)); |
438 SkASSERT(fPages.empty()); | 478 SkASSERT(fPages.empty()); |
439 | 479 |
440 if (fDests->size() > 0) { | 480 if (fDests->size() > 0) { |
441 docCatalog->insertObjRef("Dests", std::move(fDests)); | 481 docCatalog->insertObjRef("Dests", std::move(fDests)); |
442 } | 482 } |
443 | 483 |
444 // Build font subsetting info before calling addObjectRecursively(). | 484 // Build font subsetting info before calling addObjectRecursively(). |
445 for (const auto& entry : fGlyphUsage) { | 485 for (const auto& entry : fGlyphUsage) { |
446 sk_sp<SkPDFObject> subsetFont = | 486 sk_sp<SkPDFObject> subsetFont = |
447 entry.fFont->getFontSubset(&fCanon, &entry.fGlyphSet); | 487 entry.fFont->getFontSubset(&entry.fGlyphSet); |
448 if (subsetFont) { | 488 if (subsetFont) { |
449 fObjectSerializer.fSubstituteMap.setSubstitute( | 489 fObjectSerializer.fSubstituteMap.setSubstitute( |
450 entry.fFont, subsetFont.get()); | 490 entry.fFont, subsetFont.get()); |
451 } | 491 } |
452 } | 492 } |
453 | 493 |
454 fObjectSerializer.addObjectRecursively(docCatalog); | 494 fObjectSerializer.addObjectRecursively(docCatalog); |
455 fObjectSerializer.serializeObjects(this->getStream()); | 495 fObjectSerializer.serializeObjects(this->getStream()); |
456 fObjectSerializer.serializeFooter(this->getStream(), docCatalog, fID); | 496 fObjectSerializer.serializeFooter(this->getStream(), docCatalog, fID); |
457 fCanon.reset(); | 497 fCanon.reset(); |
(...skipping 26 matching lines...) Expand all Loading... |
484 } | 524 } |
485 | 525 |
486 sk_sp<SkDocument> SkDocument::MakePDF(SkWStream* stream, | 526 sk_sp<SkDocument> SkDocument::MakePDF(SkWStream* stream, |
487 SkScalar dpi, | 527 SkScalar dpi, |
488 const SkDocument::PDFMetadata& metadata, | 528 const SkDocument::PDFMetadata& metadata, |
489 sk_sp<SkPixelSerializer> jpegEncoder, | 529 sk_sp<SkPixelSerializer> jpegEncoder, |
490 bool pdfa) { | 530 bool pdfa) { |
491 return SkPDFMakeDocument(stream, nullptr, dpi, metadata, | 531 return SkPDFMakeDocument(stream, nullptr, dpi, metadata, |
492 std::move(jpegEncoder), pdfa); | 532 std::move(jpegEncoder), pdfa); |
493 } | 533 } |
OLD | NEW |