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 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
561 return new SkPDFStream(cmapStream.get()); | 561 return new SkPDFStream(cmapStream.get()); |
562 } | 562 } |
563 | 563 |
564 #if defined (SK_SFNTLY_SUBSETTER) | 564 #if defined (SK_SFNTLY_SUBSETTER) |
565 static void sk_delete_array(const void* ptr, size_t, void*) { | 565 static void sk_delete_array(const void* ptr, size_t, void*) { |
566 // Use C-style cast to cast away const and cast type simultaneously. | 566 // Use C-style cast to cast away const and cast type simultaneously. |
567 delete[] (unsigned char*)ptr; | 567 delete[] (unsigned char*)ptr; |
568 } | 568 } |
569 #endif | 569 #endif |
570 | 570 |
571 static int get_subset_font_stream(const char* fontName, | 571 static size_t get_subset_font_stream(const char* fontName, |
572 const SkTypeface* typeface, | 572 const SkTypeface* typeface, |
573 const SkTDArray<uint32_t>& subset, | 573 const SkTDArray<uint32_t>& subset, |
574 SkPDFStream** fontStream) { | 574 SkPDFStream** fontStream) { |
575 int ttcIndex; | 575 int ttcIndex; |
576 SkAutoTUnref<SkStream> fontData(typeface->openStream(&ttcIndex)); | 576 SkAutoTUnref<SkStream> fontData(typeface->openStream(&ttcIndex)); |
577 | 577 |
578 int fontSize = fontData->getLength(); | 578 size_t fontSize = fontData->getLength(); |
579 | 579 |
580 #if defined (SK_SFNTLY_SUBSETTER) | 580 #if defined (SK_SFNTLY_SUBSETTER) |
581 // Read font into buffer. | 581 // Read font into buffer. |
582 SkPDFStream* subsetFontStream = NULL; | 582 SkPDFStream* subsetFontStream = NULL; |
583 SkTDArray<unsigned char> originalFont; | 583 SkTDArray<unsigned char> originalFont; |
584 originalFont.setCount(fontSize); | 584 originalFont.setCount(SkToInt(fontSize)); |
585 if (fontData->read(originalFont.begin(), fontSize) == (size_t)fontSize) { | 585 if (fontData->read(originalFont.begin(), fontSize) == fontSize) { |
586 unsigned char* subsetFont = NULL; | 586 unsigned char* subsetFont = NULL; |
587 // sfntly requires unsigned int* to be passed in, as far as we know, | 587 // sfntly requires unsigned int* to be passed in, as far as we know, |
588 // unsigned int is equivalent to uint32_t on all platforms. | 588 // unsigned int is equivalent to uint32_t on all platforms. |
589 SK_COMPILE_ASSERT(sizeof(unsigned int) == sizeof(uint32_t), | 589 SK_COMPILE_ASSERT(sizeof(unsigned int) == sizeof(uint32_t), |
590 unsigned_int_not_32_bits); | 590 unsigned_int_not_32_bits); |
591 int subsetFontSize = SfntlyWrapper::SubsetFont(fontName, | 591 int subsetFontSize = SfntlyWrapper::SubsetFont(fontName, |
592 originalFont.begin(), | 592 originalFont.begin(), |
593 fontSize, | 593 fontSize, |
594 subset.begin(), | 594 subset.begin(), |
595 subset.count(), | 595 subset.count(), |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
758 } | 758 } |
759 | 759 |
760 SkAdvancedTypefaceMetrics::FontType SkPDFFont::getType() { | 760 SkAdvancedTypefaceMetrics::FontType SkPDFFont::getType() { |
761 return fFontType; | 761 return fFontType; |
762 } | 762 } |
763 | 763 |
764 bool SkPDFFont::hasGlyph(uint16_t id) { | 764 bool SkPDFFont::hasGlyph(uint16_t id) { |
765 return (id >= fFirstGlyphID && id <= fLastGlyphID) || id == 0; | 765 return (id >= fFirstGlyphID && id <= fLastGlyphID) || id == 0; |
766 } | 766 } |
767 | 767 |
768 size_t SkPDFFont::glyphsToPDFFontEncoding(uint16_t* glyphIDs, | 768 int SkPDFFont::glyphsToPDFFontEncoding(uint16_t* glyphIDs, int numGlyphs) { |
769 size_t numGlyphs) { | |
770 // A font with multibyte glyphs will support all glyph IDs in a single font. | 769 // A font with multibyte glyphs will support all glyph IDs in a single font. |
771 if (this->multiByteGlyphs()) { | 770 if (this->multiByteGlyphs()) { |
772 return numGlyphs; | 771 return numGlyphs; |
773 } | 772 } |
774 | 773 |
775 for (size_t i = 0; i < numGlyphs; i++) { | 774 for (int i = 0; i < numGlyphs; i++) { |
776 if (glyphIDs[i] == 0) { | 775 if (glyphIDs[i] == 0) { |
777 continue; | 776 continue; |
778 } | 777 } |
779 if (glyphIDs[i] < fFirstGlyphID || glyphIDs[i] > fLastGlyphID) { | 778 if (glyphIDs[i] < fFirstGlyphID || glyphIDs[i] > fLastGlyphID) { |
780 return i; | 779 return i; |
781 } | 780 } |
782 glyphIDs[i] -= (fFirstGlyphID - 1); | 781 glyphIDs[i] -= (fFirstGlyphID - 1); |
783 } | 782 } |
784 | 783 |
785 return numGlyphs; | 784 return numGlyphs; |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1105 const SkTDArray<uint32_t>* subset) { | 1104 const SkTDArray<uint32_t>* subset) { |
1106 SkAutoTUnref<SkPDFDict> descriptor(new SkPDFDict("FontDescriptor")); | 1105 SkAutoTUnref<SkPDFDict> descriptor(new SkPDFDict("FontDescriptor")); |
1107 setFontDescriptor(descriptor.get()); | 1106 setFontDescriptor(descriptor.get()); |
1108 addResource(descriptor.get()); | 1107 addResource(descriptor.get()); |
1109 | 1108 |
1110 switch (getType()) { | 1109 switch (getType()) { |
1111 case SkAdvancedTypefaceMetrics::kTrueType_Font: { | 1110 case SkAdvancedTypefaceMetrics::kTrueType_Font: { |
1112 SkASSERT(subset); | 1111 SkASSERT(subset); |
1113 // Font subsetting | 1112 // Font subsetting |
1114 SkPDFStream* rawStream = NULL; | 1113 SkPDFStream* rawStream = NULL; |
1115 int fontSize = get_subset_font_stream(fontInfo()->fFontName.c_str(), | 1114 size_t fontSize = get_subset_font_stream(fontInfo()->fFontName.c_str
(), |
1116 typeface(), | 1115 typeface(), |
1117 *subset, | 1116 *subset, |
1118 &rawStream); | 1117 &rawStream); |
1119 SkASSERT(fontSize); | 1118 SkASSERT(fontSize); |
1120 SkASSERT(rawStream); | 1119 SkASSERT(rawStream); |
1121 SkAutoTUnref<SkPDFStream> fontStream(rawStream); | 1120 SkAutoTUnref<SkPDFStream> fontStream(rawStream); |
1122 addResource(fontStream.get()); | 1121 addResource(fontStream.get()); |
1123 | 1122 |
1124 fontStream->insertInt("Length1", fontSize); | 1123 fontStream->insertInt("Length1", fontSize); |
1125 descriptor->insert("FontFile2", | 1124 descriptor->insert("FontFile2", |
1126 new SkPDFObjRef(fontStream.get()))->unref(); | 1125 new SkPDFObjRef(fontStream.get()))->unref(); |
1127 break; | 1126 break; |
1128 } | 1127 } |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1437 | 1436 |
1438 insert("FontBBox", makeFontBBox(bbox, 1000))->unref(); | 1437 insert("FontBBox", makeFontBBox(bbox, 1000))->unref(); |
1439 insertInt("FirstChar", 1); | 1438 insertInt("FirstChar", 1); |
1440 insertInt("LastChar", lastGlyphID() - firstGlyphID() + 1); | 1439 insertInt("LastChar", lastGlyphID() - firstGlyphID() + 1); |
1441 insert("Widths", widthArray.get()); | 1440 insert("Widths", widthArray.get()); |
1442 insertName("CIDToGIDMap", "Identity"); | 1441 insertName("CIDToGIDMap", "Identity"); |
1443 | 1442 |
1444 populateToUnicodeTable(NULL); | 1443 populateToUnicodeTable(NULL); |
1445 return true; | 1444 return true; |
1446 } | 1445 } |
OLD | NEW |