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 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
577 return new SkPDFStream(cmapData.get()); | 577 return new SkPDFStream(cmapData.get()); |
578 } | 578 } |
579 | 579 |
580 #if defined (SK_SFNTLY_SUBSETTER) | 580 #if defined (SK_SFNTLY_SUBSETTER) |
581 static void sk_delete_array(const void* ptr, void*) { | 581 static void sk_delete_array(const void* ptr, void*) { |
582 // Use C-style cast to cast away const and cast type simultaneously. | 582 // Use C-style cast to cast away const and cast type simultaneously. |
583 delete[] (unsigned char*)ptr; | 583 delete[] (unsigned char*)ptr; |
584 } | 584 } |
585 #endif | 585 #endif |
586 | 586 |
| 587 #if defined(SK_SFNTLY_SUBSETTER) |
587 static size_t get_subset_font_stream(const char* fontName, | 588 static size_t get_subset_font_stream(const char* fontName, |
588 const SkTypeface* typeface, | 589 const SkTypeface* typeface, |
589 const SkTDArray<uint32_t>& subset, | 590 const SkTDArray<uint32_t>& subset, |
590 SkPDFStream** fontStream) { | 591 SkPDFStream** fontStream) { |
591 int ttcIndex; | 592 int ttcIndex; |
592 SkAutoTDelete<SkStream> fontData(typeface->openStream(&ttcIndex)); | 593 SkAutoTDelete<SkStream> fontData(typeface->openStream(&ttcIndex)); |
593 SkASSERT(fontData.get()); | 594 SkASSERT(fontData.get()); |
594 | 595 |
595 size_t fontSize = fontData->getLength(); | 596 size_t fontSize = fontData->getLength(); |
596 | 597 |
597 #if defined (SK_SFNTLY_SUBSETTER) | |
598 // Read font into buffer. | 598 // Read font into buffer. |
599 SkPDFStream* subsetFontStream = NULL; | 599 SkPDFStream* subsetFontStream = NULL; |
600 SkTDArray<unsigned char> originalFont; | 600 SkTDArray<unsigned char> originalFont; |
601 originalFont.setCount(SkToInt(fontSize)); | 601 originalFont.setCount(SkToInt(fontSize)); |
602 if (fontData->read(originalFont.begin(), fontSize) == fontSize) { | 602 if (fontData->read(originalFont.begin(), fontSize) == fontSize) { |
603 unsigned char* subsetFont = NULL; | 603 unsigned char* subsetFont = NULL; |
604 // sfntly requires unsigned int* to be passed in, as far as we know, | 604 // sfntly requires unsigned int* to be passed in, as far as we know, |
605 // unsigned int is equivalent to uint32_t on all platforms. | 605 // unsigned int is equivalent to uint32_t on all platforms. |
606 SK_COMPILE_ASSERT(sizeof(unsigned int) == sizeof(uint32_t), | 606 SK_COMPILE_ASSERT(sizeof(unsigned int) == sizeof(uint32_t), |
607 unsigned_int_not_32_bits); | 607 unsigned_int_not_32_bits); |
(...skipping 10 matching lines...) Expand all Loading... |
618 NULL)); | 618 NULL)); |
619 subsetFontStream = new SkPDFStream(data.get()); | 619 subsetFontStream = new SkPDFStream(data.get()); |
620 fontSize = subsetFontSize; | 620 fontSize = subsetFontSize; |
621 } | 621 } |
622 } | 622 } |
623 if (subsetFontStream) { | 623 if (subsetFontStream) { |
624 *fontStream = subsetFontStream; | 624 *fontStream = subsetFontStream; |
625 return fontSize; | 625 return fontSize; |
626 } | 626 } |
627 fontData->rewind(); | 627 fontData->rewind(); |
628 #else | |
629 sk_ignore_unused_variable(fontName); | |
630 sk_ignore_unused_variable(subset); | |
631 #endif | |
632 | 628 |
633 // Fail over: just embed the whole font. | 629 // Fail over: just embed the whole font. |
634 *fontStream = new SkPDFStream(fontData.get()); | 630 *fontStream = new SkPDFStream(fontData.get()); |
635 return fontSize; | 631 return fontSize; |
636 } | 632 } |
| 633 #endif |
637 | 634 |
638 /////////////////////////////////////////////////////////////////////////////// | 635 /////////////////////////////////////////////////////////////////////////////// |
639 // class SkPDFGlyphSet | 636 // class SkPDFGlyphSet |
640 /////////////////////////////////////////////////////////////////////////////// | 637 /////////////////////////////////////////////////////////////////////////////// |
641 | 638 |
642 SkPDFGlyphSet::SkPDFGlyphSet() : fBitSet(SK_MaxU16 + 1) { | 639 SkPDFGlyphSet::SkPDFGlyphSet() : fBitSet(SK_MaxU16 + 1) { |
643 } | 640 } |
644 | 641 |
645 void SkPDFGlyphSet::set(const uint16_t* glyphIDs, int numGlyphs) { | 642 void SkPDFGlyphSet::set(const uint16_t* glyphIDs, int numGlyphs) { |
646 for (int i = 0; i < numGlyphs; ++i) { | 643 for (int i = 0; i < numGlyphs; ++i) { |
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1055 this->insertObjRef("FontDescriptor", descriptor.detach()); | 1052 this->insertObjRef("FontDescriptor", descriptor.detach()); |
1056 return false; | 1053 return false; |
1057 } | 1054 } |
1058 if (!canEmbed()) { | 1055 if (!canEmbed()) { |
1059 this->insertObjRef("FontDescriptor", descriptor.detach()); | 1056 this->insertObjRef("FontDescriptor", descriptor.detach()); |
1060 return true; | 1057 return true; |
1061 } | 1058 } |
1062 | 1059 |
1063 switch (getType()) { | 1060 switch (getType()) { |
1064 case SkAdvancedTypefaceMetrics::kTrueType_Font: { | 1061 case SkAdvancedTypefaceMetrics::kTrueType_Font: { |
1065 SkAutoTUnref<SkPDFStream> fontStream; | |
1066 size_t fontSize = 0; | 1062 size_t fontSize = 0; |
1067 if (canSubset()) { | 1063 #if defined(SK_SFNTLY_SUBSETTER) |
| 1064 if (this->canSubset()) { |
| 1065 SkAutoTUnref<SkPDFStream> fontStream; |
1068 SkPDFStream* rawStream = NULL; | 1066 SkPDFStream* rawStream = NULL; |
1069 fontSize = get_subset_font_stream(fontInfo()->fFontName.c_str(), | 1067 fontSize = get_subset_font_stream(fontInfo()->fFontName.c_str(), |
1070 typeface(), | 1068 typeface(), |
1071 *subset, | 1069 *subset, |
1072 &rawStream); | 1070 &rawStream); |
1073 fontStream.reset(rawStream); | 1071 if (rawStream) { |
1074 } else { | 1072 fontStream.reset(rawStream); |
1075 int ttcIndex; | 1073 fontStream->insertInt("Length1", fontSize); |
1076 SkAutoTDelete<SkStream> fontData( | 1074 descriptor->insertObjRef("FontFile2", fontStream.detach()); |
1077 typeface()->openStream(&ttcIndex)); | 1075 break; |
1078 fontStream.reset(new SkPDFStream(fontData.get())); | 1076 } |
1079 fontSize = fontData->getLength(); | |
1080 } | 1077 } |
1081 SkASSERT(fontSize); | 1078 #endif |
1082 SkASSERT(fontStream.get()); | 1079 SkAutoTUnref<SkPDFSharedStream> fontStream; |
1083 | 1080 SkAutoTDelete<SkStreamAsset> fontData( |
1084 fontStream->insertInt("Length1", fontSize); | 1081 this->typeface()->openStream(NULL)); |
| 1082 SkASSERT(fontData); |
| 1083 fontSize = fontData->getLength(); |
| 1084 SkASSERT(fontSize > 0); |
| 1085 fontStream.reset(new SkPDFSharedStream(fontData.detach())); |
| 1086 fontStream->dict()->insertInt("Length1", fontSize); |
1085 descriptor->insertObjRef("FontFile2", fontStream.detach()); | 1087 descriptor->insertObjRef("FontFile2", fontStream.detach()); |
1086 break; | 1088 break; |
1087 } | 1089 } |
1088 case SkAdvancedTypefaceMetrics::kCFF_Font: | 1090 case SkAdvancedTypefaceMetrics::kCFF_Font: |
1089 case SkAdvancedTypefaceMetrics::kType1CID_Font: { | 1091 case SkAdvancedTypefaceMetrics::kType1CID_Font: { |
1090 int ttcIndex; | 1092 SkAutoTUnref<SkPDFSharedStream> fontStream( |
1091 SkAutoTDelete<SkStream> fontData(typeface()->openStream(&ttcIndex)); | 1093 new SkPDFSharedStream(this->typeface()->openStream(NULL))); |
1092 SkAutoTUnref<SkPDFStream> fontStream( | |
1093 new SkPDFStream(fontData.get())); | |
1094 | 1094 |
1095 if (getType() == SkAdvancedTypefaceMetrics::kCFF_Font) { | 1095 if (getType() == SkAdvancedTypefaceMetrics::kCFF_Font) { |
1096 fontStream->insertName("Subtype", "Type1C"); | 1096 fontStream->dict()->insertName("Subtype", "Type1C"); |
1097 } else { | 1097 } else { |
1098 fontStream->insertName("Subtype", "CIDFontType0c"); | 1098 fontStream->dict()->insertName("Subtype", "CIDFontType0c"); |
1099 } | 1099 } |
1100 descriptor->insertObjRef("FontFile3", fontStream.detach()); | 1100 descriptor->insertObjRef("FontFile3", fontStream.detach()); |
1101 break; | 1101 break; |
1102 } | 1102 } |
1103 default: | 1103 default: |
1104 SkASSERT(false); | 1104 SkASSERT(false); |
1105 } | 1105 } |
1106 this->insertObjRef("FontDescriptor", descriptor.detach()); | 1106 this->insertObjRef("FontDescriptor", descriptor.detach()); |
1107 return true; | 1107 return true; |
1108 } | 1108 } |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1412 } | 1412 } |
1413 if (existingFont != NULL) { | 1413 if (existingFont != NULL) { |
1414 return (existingFont->fFirstGlyphID <= searchGlyphID && | 1414 return (existingFont->fFirstGlyphID <= searchGlyphID && |
1415 searchGlyphID <= existingFont->fLastGlyphID) | 1415 searchGlyphID <= existingFont->fLastGlyphID) |
1416 ? SkPDFFont::kExact_Match | 1416 ? SkPDFFont::kExact_Match |
1417 : SkPDFFont::kRelated_Match; | 1417 : SkPDFFont::kRelated_Match; |
1418 } | 1418 } |
1419 return (existingGlyphID == searchGlyphID) ? SkPDFFont::kExact_Match | 1419 return (existingGlyphID == searchGlyphID) ? SkPDFFont::kExact_Match |
1420 : SkPDFFont::kRelated_Match; | 1420 : SkPDFFont::kRelated_Match; |
1421 } | 1421 } |
OLD | NEW |