| 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. |
| 261 void SkPDFDocument::getCountOfFontTypes( | 262 void SkPDFDocument::getCountOfFontTypes( |
| 262 int counts[SkAdvancedTypefaceMetrics::kNotEmbeddable_Font + 1]) const { | 263 int counts[SkAdvancedTypefaceMetrics::kOther_Font + 2]) const { |
| 263 sk_bzero(counts, sizeof(int) * | 264 sk_bzero(counts, sizeof(int) * |
| 264 (SkAdvancedTypefaceMetrics::kNotEmbeddable_Font + 1)); | 265 (SkAdvancedTypefaceMetrics::kOther_Font + 2)); |
| 265 SkTDArray<SkFontID> seenFonts; | 266 SkTDArray<SkFontID> seenFonts; |
| 267 int notEmbeddable = 0; |
| 266 | 268 |
| 267 for (int pageNumber = 0; pageNumber < fPages.count(); pageNumber++) { | 269 for (int pageNumber = 0; pageNumber < fPages.count(); pageNumber++) { |
| 268 const SkTDArray<SkPDFFont*>& fontResources = | 270 const SkTDArray<SkPDFFont*>& fontResources = |
| 269 fPages[pageNumber]->getFontResources(); | 271 fPages[pageNumber]->getFontResources(); |
| 270 for (int font = 0; font < fontResources.count(); font++) { | 272 for (int font = 0; font < fontResources.count(); font++) { |
| 271 SkFontID fontID = fontResources[font]->typeface()->uniqueID(); | 273 SkFontID fontID = fontResources[font]->typeface()->uniqueID(); |
| 272 if (seenFonts.find(fontID) == -1) { | 274 if (seenFonts.find(fontID) == -1) { |
| 273 counts[fontResources[font]->getType()]++; | 275 counts[fontResources[font]->getType()]++; |
| 274 seenFonts.push(fontID); | 276 seenFonts.push(fontID); |
| 277 if (!fontResources[font]->canEmbed()) { |
| 278 notEmbeddable++; |
| 279 } |
| 275 } | 280 } |
| 276 } | 281 } |
| 277 } | 282 } |
| 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 } |
| 278 } | 320 } |
| 279 | 321 |
| 280 void SkPDFDocument::emitHeader(SkWStream* stream) { | 322 void SkPDFDocument::emitHeader(SkWStream* stream) { |
| 281 stream->writeText("%PDF-1.4\n%"); | 323 stream->writeText("%PDF-1.4\n%"); |
| 282 // The PDF spec recommends including a comment with four bytes, all | 324 // The PDF spec recommends including a comment with four bytes, all |
| 283 // with their high bits set. This is "Skia" with the high bits set. | 325 // with their high bits set. This is "Skia" with the high bits set. |
| 284 stream->write32(0xD3EBE9E1); | 326 stream->write32(0xD3EBE9E1); |
| 285 stream->writeText("\n"); | 327 stream->writeText("\n"); |
| 286 } | 328 } |
| 287 | 329 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 300 fTrailerDict->insertInt("Size", int(objCount)); | 342 fTrailerDict->insertInt("Size", int(objCount)); |
| 301 fTrailerDict->insert("Root", new SkPDFObjRef(fDocCatalog))->unref(); | 343 fTrailerDict->insert("Root", new SkPDFObjRef(fDocCatalog))->unref(); |
| 302 } | 344 } |
| 303 | 345 |
| 304 stream->writeText("trailer\n"); | 346 stream->writeText("trailer\n"); |
| 305 fTrailerDict->emitObject(stream, fCatalog.get(), false); | 347 fTrailerDict->emitObject(stream, fCatalog.get(), false); |
| 306 stream->writeText("\nstartxref\n"); | 348 stream->writeText("\nstartxref\n"); |
| 307 stream->writeBigDecAsText(fXRefFileOffset); | 349 stream->writeBigDecAsText(fXRefFileOffset); |
| 308 stream->writeText("\n%%EOF"); | 350 stream->writeText("\n%%EOF"); |
| 309 } | 351 } |
| OLD | NEW |