| 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 <ctype.h> | 8 #include <ctype.h> |
| 9 | 9 |
| 10 #include "SkData.h" | 10 #include "SkData.h" |
| (...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 uint16_t fGlyphId; | 414 uint16_t fGlyphId; |
| 415 SkUnichar fUnicode; | 415 SkUnichar fUnicode; |
| 416 }; | 416 }; |
| 417 | 417 |
| 418 struct BFRange { | 418 struct BFRange { |
| 419 uint16_t fStart; | 419 uint16_t fStart; |
| 420 uint16_t fEnd; | 420 uint16_t fEnd; |
| 421 SkUnichar fUnicode; | 421 SkUnichar fUnicode; |
| 422 }; | 422 }; |
| 423 | 423 |
| 424 static void write_utf16be(SkDynamicMemoryWStream* wStream, SkUnichar utf32) { |
| 425 uint16_t utf16[2] = {0, 0}; |
| 426 size_t len = SkUTF16_FromUnichar(utf32, utf16); |
| 427 SkASSERT(len == 1 || len == 2); |
| 428 SkPDFUtils::WriteUInt16BE(wStream, utf16[0]); |
| 429 if (len == 2) { |
| 430 SkPDFUtils::WriteUInt16BE(wStream, utf16[1]); |
| 431 } |
| 432 } |
| 433 |
| 424 static void append_bfchar_section(const SkTDArray<BFChar>& bfchar, | 434 static void append_bfchar_section(const SkTDArray<BFChar>& bfchar, |
| 425 SkDynamicMemoryWStream* cmap) { | 435 SkDynamicMemoryWStream* cmap) { |
| 426 // PDF spec defines that every bf* list can have at most 100 entries. | 436 // PDF spec defines that every bf* list can have at most 100 entries. |
| 427 for (int i = 0; i < bfchar.count(); i += 100) { | 437 for (int i = 0; i < bfchar.count(); i += 100) { |
| 428 int count = bfchar.count() - i; | 438 int count = bfchar.count() - i; |
| 429 count = SkMin32(count, 100); | 439 count = SkMin32(count, 100); |
| 430 cmap->writeDecAsText(count); | 440 cmap->writeDecAsText(count); |
| 431 cmap->writeText(" beginbfchar\n"); | 441 cmap->writeText(" beginbfchar\n"); |
| 432 for (int j = 0; j < count; ++j) { | 442 for (int j = 0; j < count; ++j) { |
| 433 cmap->writeText("<"); | 443 cmap->writeText("<"); |
| 434 cmap->writeHexAsText(bfchar[i + j].fGlyphId, 4); | 444 SkPDFUtils::WriteUInt16BE(cmap, bfchar[i + j].fGlyphId); |
| 435 cmap->writeText("> <"); | 445 cmap->writeText("> <"); |
| 436 cmap->writeHexAsText(bfchar[i + j].fUnicode, 4); | 446 write_utf16be(cmap, bfchar[i + j].fUnicode); |
| 437 cmap->writeText(">\n"); | 447 cmap->writeText(">\n"); |
| 438 } | 448 } |
| 439 cmap->writeText("endbfchar\n"); | 449 cmap->writeText("endbfchar\n"); |
| 440 } | 450 } |
| 441 } | 451 } |
| 442 | 452 |
| 443 static void append_bfrange_section(const SkTDArray<BFRange>& bfrange, | 453 static void append_bfrange_section(const SkTDArray<BFRange>& bfrange, |
| 444 SkDynamicMemoryWStream* cmap) { | 454 SkDynamicMemoryWStream* cmap) { |
| 445 // PDF spec defines that every bf* list can have at most 100 entries. | 455 // PDF spec defines that every bf* list can have at most 100 entries. |
| 446 for (int i = 0; i < bfrange.count(); i += 100) { | 456 for (int i = 0; i < bfrange.count(); i += 100) { |
| 447 int count = bfrange.count() - i; | 457 int count = bfrange.count() - i; |
| 448 count = SkMin32(count, 100); | 458 count = SkMin32(count, 100); |
| 449 cmap->writeDecAsText(count); | 459 cmap->writeDecAsText(count); |
| 450 cmap->writeText(" beginbfrange\n"); | 460 cmap->writeText(" beginbfrange\n"); |
| 451 for (int j = 0; j < count; ++j) { | 461 for (int j = 0; j < count; ++j) { |
| 452 cmap->writeText("<"); | 462 cmap->writeText("<"); |
| 453 cmap->writeHexAsText(bfrange[i + j].fStart, 4); | 463 SkPDFUtils::WriteUInt16BE(cmap, bfrange[i + j].fStart); |
| 454 cmap->writeText("> <"); | 464 cmap->writeText("> <"); |
| 455 cmap->writeHexAsText(bfrange[i + j].fEnd, 4); | 465 SkPDFUtils::WriteUInt16BE(cmap, bfrange[i + j].fEnd); |
| 456 cmap->writeText("> <"); | 466 cmap->writeText("> <"); |
| 457 cmap->writeHexAsText(bfrange[i + j].fUnicode, 4); | 467 write_utf16be(cmap, bfrange[i + j].fUnicode); |
| 458 cmap->writeText(">\n"); | 468 cmap->writeText(">\n"); |
| 459 } | 469 } |
| 460 cmap->writeText("endbfrange\n"); | 470 cmap->writeText("endbfrange\n"); |
| 461 } | 471 } |
| 462 } | 472 } |
| 463 | 473 |
| 464 // Generate <bfchar> and <bfrange> table according to PDF spec 1.4 and Adobe | 474 // Generate <bfchar> and <bfrange> table according to PDF spec 1.4 and Adobe |
| 465 // Technote 5014. | 475 // Technote 5014. |
| 466 // The function is not static so we can test it in unit tests. | 476 // The function is not static so we can test it in unit tests. |
| 467 // | 477 // |
| (...skipping 941 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1409 } | 1419 } |
| 1410 return *canon->fCanEmbedTypeface.set(id, canEmbed); | 1420 return *canon->fCanEmbedTypeface.set(id, canEmbed); |
| 1411 } | 1421 } |
| 1412 | 1422 |
| 1413 void SkPDFFont::drop() { | 1423 void SkPDFFont::drop() { |
| 1414 fTypeface = nullptr; | 1424 fTypeface = nullptr; |
| 1415 fFontInfo = nullptr; | 1425 fFontInfo = nullptr; |
| 1416 fDescriptor = nullptr; | 1426 fDescriptor = nullptr; |
| 1417 this->SkPDFDict::drop(); | 1427 this->SkPDFDict::drop(); |
| 1418 } | 1428 } |
| OLD | NEW |