| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 | 9 |
| 10 #include "SkPDFCatalog.h" | 10 #include "SkPDFCatalog.h" |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 bool SkPDFDocument::appendPage(SkPDFDevice* pdfDevice) { | 251 bool SkPDFDocument::appendPage(SkPDFDevice* pdfDevice) { |
| 252 if (!fPageTree.isEmpty()) { | 252 if (!fPageTree.isEmpty()) { |
| 253 return false; | 253 return false; |
| 254 } | 254 } |
| 255 | 255 |
| 256 SkPDFPage* page = new SkPDFPage(pdfDevice); | 256 SkPDFPage* page = new SkPDFPage(pdfDevice); |
| 257 fPages.push(page); // Reference from new passed to fPages. | 257 fPages.push(page); // Reference from new passed to fPages. |
| 258 return true; | 258 return true; |
| 259 } | 259 } |
| 260 | 260 |
| 261 // Deprecated. | |
| 262 void SkPDFDocument::getCountOfFontTypes( | 261 void SkPDFDocument::getCountOfFontTypes( |
| 263 int counts[SkAdvancedTypefaceMetrics::kOther_Font + 2]) const { | 262 int counts[SkAdvancedTypefaceMetrics::kNotEmbeddable_Font + 1]) const { |
| 264 sk_bzero(counts, sizeof(int) * | 263 sk_bzero(counts, sizeof(int) * |
| 265 (SkAdvancedTypefaceMetrics::kOther_Font + 2)); | 264 (SkAdvancedTypefaceMetrics::kNotEmbeddable_Font + 1)); |
| 266 SkTDArray<SkFontID> seenFonts; | 265 SkTDArray<SkFontID> seenFonts; |
| 267 int notEmbeddable = 0; | |
| 268 | 266 |
| 269 for (int pageNumber = 0; pageNumber < fPages.count(); pageNumber++) { | 267 for (int pageNumber = 0; pageNumber < fPages.count(); pageNumber++) { |
| 270 const SkTDArray<SkPDFFont*>& fontResources = | 268 const SkTDArray<SkPDFFont*>& fontResources = |
| 271 fPages[pageNumber]->getFontResources(); | 269 fPages[pageNumber]->getFontResources(); |
| 272 for (int font = 0; font < fontResources.count(); font++) { | 270 for (int font = 0; font < fontResources.count(); font++) { |
| 273 SkFontID fontID = fontResources[font]->typeface()->uniqueID(); | 271 SkFontID fontID = fontResources[font]->typeface()->uniqueID(); |
| 274 if (seenFonts.find(fontID) == -1) { | 272 if (seenFonts.find(fontID) == -1) { |
| 275 counts[fontResources[font]->getType()]++; | 273 counts[fontResources[font]->getType()]++; |
| 276 seenFonts.push(fontID); | 274 seenFonts.push(fontID); |
| 277 if (!fontResources[font]->canEmbed()) { | |
| 278 notEmbeddable++; | |
| 279 } | |
| 280 } | 275 } |
| 281 } | 276 } |
| 282 } | 277 } |
| 283 counts[SkAdvancedTypefaceMetrics::kOther_Font + 1] = notEmbeddable; | |
| 284 } | |
| 285 | |
| 286 void SkPDFDocument::getCountOfFontTypes( | |
| 287 int counts[SkAdvancedTypefaceMetrics::kOther_Font + 1], | |
| 288 int* notSubsettableCount, | |
| 289 int* notEmbeddableCount) const { | |
| 290 sk_bzero(counts, sizeof(int) * | |
| 291 (SkAdvancedTypefaceMetrics::kOther_Font + 1)); | |
| 292 SkTDArray<SkFontID> seenFonts; | |
| 293 int notSubsettable = 0; | |
| 294 int notEmbeddable = 0; | |
| 295 | |
| 296 for (int pageNumber = 0; pageNumber < fPages.count(); pageNumber++) { | |
| 297 const SkTDArray<SkPDFFont*>& fontResources = | |
| 298 fPages[pageNumber]->getFontResources(); | |
| 299 for (int font = 0; font < fontResources.count(); font++) { | |
| 300 SkFontID fontID = fontResources[font]->typeface()->uniqueID(); | |
| 301 if (seenFonts.find(fontID) == -1) { | |
| 302 counts[fontResources[font]->getType()]++; | |
| 303 seenFonts.push(fontID); | |
| 304 if (!fontResources[font]->canSubset()) { | |
| 305 notSubsettable++; | |
| 306 } | |
| 307 if (!fontResources[font]->canEmbed()) { | |
| 308 notEmbeddable++; | |
| 309 } | |
| 310 } | |
| 311 } | |
| 312 } | |
| 313 if (notSubsettableCount) { | |
| 314 *notSubsettableCount = notSubsettable; | |
| 315 | |
| 316 } | |
| 317 if (notEmbeddableCount) { | |
| 318 *notEmbeddableCount = notEmbeddable; | |
| 319 } | |
| 320 } | 278 } |
| 321 | 279 |
| 322 void SkPDFDocument::emitHeader(SkWStream* stream) { | 280 void SkPDFDocument::emitHeader(SkWStream* stream) { |
| 323 stream->writeText("%PDF-1.4\n%"); | 281 stream->writeText("%PDF-1.4\n%"); |
| 324 // The PDF spec recommends including a comment with four bytes, all | 282 // The PDF spec recommends including a comment with four bytes, all |
| 325 // with their high bits set. This is "Skia" with the high bits set. | 283 // with their high bits set. This is "Skia" with the high bits set. |
| 326 stream->write32(0xD3EBE9E1); | 284 stream->write32(0xD3EBE9E1); |
| 327 stream->writeText("\n"); | 285 stream->writeText("\n"); |
| 328 } | 286 } |
| 329 | 287 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 342 fTrailerDict->insertInt("Size", int(objCount)); | 300 fTrailerDict->insertInt("Size", int(objCount)); |
| 343 fTrailerDict->insert("Root", new SkPDFObjRef(fDocCatalog))->unref(); | 301 fTrailerDict->insert("Root", new SkPDFObjRef(fDocCatalog))->unref(); |
| 344 } | 302 } |
| 345 | 303 |
| 346 stream->writeText("trailer\n"); | 304 stream->writeText("trailer\n"); |
| 347 fTrailerDict->emitObject(stream, fCatalog.get(), false); | 305 fTrailerDict->emitObject(stream, fCatalog.get(), false); |
| 348 stream->writeText("\nstartxref\n"); | 306 stream->writeText("\nstartxref\n"); |
| 349 stream->writeBigDecAsText(fXRefFileOffset); | 307 stream->writeBigDecAsText(fXRefFileOffset); |
| 350 stream->writeText("\n%%EOF"); | 308 stream->writeText("\n%%EOF"); |
| 351 } | 309 } |
| OLD | NEW |