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 | |
211 template <typename T> static T* clone(const T* o) { return o ? new T(*o) : nullp
tr; } | 171 template <typename T> static T* clone(const T* o) { return o ? new T(*o) : nullp
tr; } |
212 //////////////////////////////////////////////////////////////////////////////// | 172 //////////////////////////////////////////////////////////////////////////////// |
213 | 173 |
214 SkPDFDocument::SkPDFDocument(SkWStream* stream, | 174 SkPDFDocument::SkPDFDocument(SkWStream* stream, |
215 void (*doneProc)(SkWStream*, bool), | 175 void (*doneProc)(SkWStream*, bool), |
216 SkScalar rasterDpi, | 176 SkScalar rasterDpi, |
217 const SkDocument::PDFMetadata& metadata, | 177 const SkDocument::PDFMetadata& metadata, |
218 sk_sp<SkPixelSerializer> jpegEncoder, | 178 sk_sp<SkPixelSerializer> jpegEncoder, |
219 bool pdfa) | 179 bool pdfa) |
220 : SkDocument(stream, doneProc) | 180 : SkDocument(stream, doneProc) |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 docCatalog->insertObjRef("Pages", generate_page_tree(&fPages)); | 437 docCatalog->insertObjRef("Pages", generate_page_tree(&fPages)); |
478 SkASSERT(fPages.empty()); | 438 SkASSERT(fPages.empty()); |
479 | 439 |
480 if (fDests->size() > 0) { | 440 if (fDests->size() > 0) { |
481 docCatalog->insertObjRef("Dests", std::move(fDests)); | 441 docCatalog->insertObjRef("Dests", std::move(fDests)); |
482 } | 442 } |
483 | 443 |
484 // Build font subsetting info before calling addObjectRecursively(). | 444 // Build font subsetting info before calling addObjectRecursively(). |
485 for (const auto& entry : fGlyphUsage) { | 445 for (const auto& entry : fGlyphUsage) { |
486 sk_sp<SkPDFObject> subsetFont = | 446 sk_sp<SkPDFObject> subsetFont = |
487 entry.fFont->getFontSubset(&entry.fGlyphSet); | 447 entry.fFont->getFontSubset(&fCanon, &entry.fGlyphSet); |
488 if (subsetFont) { | 448 if (subsetFont) { |
489 fObjectSerializer.fSubstituteMap.setSubstitute( | 449 fObjectSerializer.fSubstituteMap.setSubstitute( |
490 entry.fFont, subsetFont.get()); | 450 entry.fFont, subsetFont.get()); |
491 } | 451 } |
492 } | 452 } |
493 | 453 |
494 fObjectSerializer.addObjectRecursively(docCatalog); | 454 fObjectSerializer.addObjectRecursively(docCatalog); |
495 fObjectSerializer.serializeObjects(this->getStream()); | 455 fObjectSerializer.serializeObjects(this->getStream()); |
496 fObjectSerializer.serializeFooter(this->getStream(), docCatalog, fID); | 456 fObjectSerializer.serializeFooter(this->getStream(), docCatalog, fID); |
497 fCanon.reset(); | 457 fCanon.reset(); |
(...skipping 26 matching lines...) Expand all Loading... |
524 } | 484 } |
525 | 485 |
526 sk_sp<SkDocument> SkDocument::MakePDF(SkWStream* stream, | 486 sk_sp<SkDocument> SkDocument::MakePDF(SkWStream* stream, |
527 SkScalar dpi, | 487 SkScalar dpi, |
528 const SkDocument::PDFMetadata& metadata, | 488 const SkDocument::PDFMetadata& metadata, |
529 sk_sp<SkPixelSerializer> jpegEncoder, | 489 sk_sp<SkPixelSerializer> jpegEncoder, |
530 bool pdfa) { | 490 bool pdfa) { |
531 return SkPDFMakeDocument(stream, nullptr, dpi, metadata, | 491 return SkPDFMakeDocument(stream, nullptr, dpi, metadata, |
532 std::move(jpegEncoder), pdfa); | 492 std::move(jpegEncoder), pdfa); |
533 } | 493 } |
OLD | NEW |