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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 } | 70 } |
71 | 71 |
72 bool parsePFB(const uint8_t* src, size_t size, size_t* headerLen, | 72 bool parsePFB(const uint8_t* src, size_t size, size_t* headerLen, |
73 size_t* dataLen, size_t* trailerLen) { | 73 size_t* dataLen, size_t* trailerLen) { |
74 const uint8_t* srcPtr = src; | 74 const uint8_t* srcPtr = src; |
75 size_t remaining = size; | 75 size_t remaining = size; |
76 | 76 |
77 return parsePFBSection(&srcPtr, &remaining, 1, headerLen) && | 77 return parsePFBSection(&srcPtr, &remaining, 1, headerLen) && |
78 parsePFBSection(&srcPtr, &remaining, 2, dataLen) && | 78 parsePFBSection(&srcPtr, &remaining, 2, dataLen) && |
79 parsePFBSection(&srcPtr, &remaining, 1, trailerLen) && | 79 parsePFBSection(&srcPtr, &remaining, 1, trailerLen) && |
80 parsePFBSection(&srcPtr, &remaining, 3, NULL); | 80 parsePFBSection(&srcPtr, &remaining, 3, nullptr); |
81 } | 81 } |
82 | 82 |
83 /* The sections of a PFA file are implicitly defined. The body starts | 83 /* The sections of a PFA file are implicitly defined. The body starts |
84 * after the line containing "eexec," and the trailer starts with 512 | 84 * after the line containing "eexec," and the trailer starts with 512 |
85 * literal 0's followed by "cleartomark" (plus arbitrary white space). | 85 * literal 0's followed by "cleartomark" (plus arbitrary white space). |
86 * | 86 * |
87 * This function assumes that src is NUL terminated, but the NUL | 87 * This function assumes that src is NUL terminated, but the NUL |
88 * termination is not included in size. | 88 * termination is not included in size. |
89 * | 89 * |
90 */ | 90 */ |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 | 155 |
156 static SkData* handle_type1_stream(SkStream* srcStream, size_t* headerLen, | 156 static SkData* handle_type1_stream(SkStream* srcStream, size_t* headerLen, |
157 size_t* dataLen, size_t* trailerLen) { | 157 size_t* dataLen, size_t* trailerLen) { |
158 // srcStream may be backed by a file or a unseekable fd, so we may not be | 158 // srcStream may be backed by a file or a unseekable fd, so we may not be |
159 // able to use skip(), rewind(), or getMemoryBase(). read()ing through | 159 // able to use skip(), rewind(), or getMemoryBase(). read()ing through |
160 // the input only once is doable, but very ugly. Furthermore, it'd be nice | 160 // the input only once is doable, but very ugly. Furthermore, it'd be nice |
161 // if the data was NUL terminated so that we can use strstr() to search it. | 161 // if the data was NUL terminated so that we can use strstr() to search it. |
162 // Make as few copies as possible given these constraints. | 162 // Make as few copies as possible given these constraints. |
163 SkDynamicMemoryWStream dynamicStream; | 163 SkDynamicMemoryWStream dynamicStream; |
164 SkAutoTDelete<SkMemoryStream> staticStream; | 164 SkAutoTDelete<SkMemoryStream> staticStream; |
165 SkData* data = NULL; | 165 SkData* data = nullptr; |
166 const uint8_t* src; | 166 const uint8_t* src; |
167 size_t srcLen; | 167 size_t srcLen; |
168 if ((srcLen = srcStream->getLength()) > 0) { | 168 if ((srcLen = srcStream->getLength()) > 0) { |
169 staticStream.reset(new SkMemoryStream(srcLen + 1)); | 169 staticStream.reset(new SkMemoryStream(srcLen + 1)); |
170 src = (const uint8_t*)staticStream->getMemoryBase(); | 170 src = (const uint8_t*)staticStream->getMemoryBase(); |
171 if (srcStream->getMemoryBase() != NULL) { | 171 if (srcStream->getMemoryBase() != nullptr) { |
172 memcpy((void *)src, srcStream->getMemoryBase(), srcLen); | 172 memcpy((void *)src, srcStream->getMemoryBase(), srcLen); |
173 } else { | 173 } else { |
174 size_t read = 0; | 174 size_t read = 0; |
175 while (read < srcLen) { | 175 while (read < srcLen) { |
176 size_t got = srcStream->read((void *)staticStream->getAtPos(), | 176 size_t got = srcStream->read((void *)staticStream->getAtPos(), |
177 srcLen - read); | 177 srcLen - read); |
178 if (got == 0) { | 178 if (got == 0) { |
179 return NULL; | 179 return nullptr; |
180 } | 180 } |
181 read += got; | 181 read += got; |
182 staticStream->seek(read); | 182 staticStream->seek(read); |
183 } | 183 } |
184 } | 184 } |
185 ((uint8_t *)src)[srcLen] = 0; | 185 ((uint8_t *)src)[srcLen] = 0; |
186 } else { | 186 } else { |
187 static const size_t kBufSize = 4096; | 187 static const size_t kBufSize = 4096; |
188 uint8_t buf[kBufSize]; | 188 uint8_t buf[kBufSize]; |
189 size_t amount; | 189 size_t amount; |
190 while ((amount = srcStream->read(buf, kBufSize)) > 0) { | 190 while ((amount = srcStream->read(buf, kBufSize)) > 0) { |
191 dynamicStream.write(buf, amount); | 191 dynamicStream.write(buf, amount); |
192 } | 192 } |
193 amount = 0; | 193 amount = 0; |
194 dynamicStream.write(&amount, 1); // NULL terminator. | 194 dynamicStream.write(&amount, 1); // nullptr terminator. |
195 data = dynamicStream.copyToData(); | 195 data = dynamicStream.copyToData(); |
196 src = data->bytes(); | 196 src = data->bytes(); |
197 srcLen = data->size() - 1; | 197 srcLen = data->size() - 1; |
198 } | 198 } |
199 | 199 |
200 // this handles releasing the data we may have gotten from dynamicStream. | 200 // this handles releasing the data we may have gotten from dynamicStream. |
201 // if data is null, it is a no-op | 201 // if data is null, it is a no-op |
202 SkAutoDataUnref aud(data); | 202 SkAutoDataUnref aud(data); |
203 | 203 |
204 if (parsePFB(src, srcLen, headerLen, dataLen, trailerLen)) { | 204 if (parsePFB(src, srcLen, headerLen, dataLen, trailerLen)) { |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 if (!highNibble) { | 261 if (!highNibble) { |
262 resultData[outputOffset++] = dataByte; | 262 resultData[outputOffset++] = dataByte; |
263 } | 263 } |
264 SkASSERT(outputOffset == *dataLen); | 264 SkASSERT(outputOffset == *dataLen); |
265 | 265 |
266 uint8_t* const resultTrailer = &(buffer[SkToInt(*headerLen + outputOffse
t)]); | 266 uint8_t* const resultTrailer = &(buffer[SkToInt(*headerLen + outputOffse
t)]); |
267 memcpy(resultTrailer, src + *headerLen + hexDataLen, *trailerLen); | 267 memcpy(resultTrailer, src + *headerLen + hexDataLen, *trailerLen); |
268 | 268 |
269 return SkData::NewFromMalloc(buffer.detach(), length); | 269 return SkData::NewFromMalloc(buffer.detach(), length); |
270 } | 270 } |
271 return NULL; | 271 return nullptr; |
272 } | 272 } |
273 | 273 |
274 // scale from em-units to base-1000, returning as a SkScalar | 274 // scale from em-units to base-1000, returning as a SkScalar |
275 SkScalar scaleFromFontUnits(int16_t val, uint16_t emSize) { | 275 SkScalar scaleFromFontUnits(int16_t val, uint16_t emSize) { |
276 SkScalar scaled = SkIntToScalar(val); | 276 SkScalar scaled = SkIntToScalar(val); |
277 if (emSize == 1000) { | 277 if (emSize == 1000) { |
278 return scaled; | 278 return scaled; |
279 } else { | 279 } else { |
280 return SkScalarMulDiv(scaled, 1000, emSize); | 280 return SkScalarMulDiv(scaled, 1000, emSize); |
281 } | 281 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 } | 322 } |
323 | 323 |
324 template <typename Data> | 324 template <typename Data> |
325 SkPDFArray* composeAdvanceData( | 325 SkPDFArray* composeAdvanceData( |
326 SkAdvancedTypefaceMetrics::AdvanceMetric<Data>* advanceInfo, | 326 SkAdvancedTypefaceMetrics::AdvanceMetric<Data>* advanceInfo, |
327 uint16_t emSize, | 327 uint16_t emSize, |
328 SkPDFArray* (*appendAdvance)(const Data& advance, uint16_t emSize, | 328 SkPDFArray* (*appendAdvance)(const Data& advance, uint16_t emSize, |
329 SkPDFArray* array), | 329 SkPDFArray* array), |
330 Data* defaultAdvance) { | 330 Data* defaultAdvance) { |
331 SkPDFArray* result = new SkPDFArray(); | 331 SkPDFArray* result = new SkPDFArray(); |
332 for (; advanceInfo != NULL; advanceInfo = advanceInfo->fNext.get()) { | 332 for (; advanceInfo != nullptr; advanceInfo = advanceInfo->fNext.get()) { |
333 switch (advanceInfo->fType) { | 333 switch (advanceInfo->fType) { |
334 case SkAdvancedTypefaceMetrics::WidthRange::kDefault: { | 334 case SkAdvancedTypefaceMetrics::WidthRange::kDefault: { |
335 SkASSERT(advanceInfo->fAdvance.count() == 1); | 335 SkASSERT(advanceInfo->fAdvance.count() == 1); |
336 *defaultAdvance = advanceInfo->fAdvance[0]; | 336 *defaultAdvance = advanceInfo->fAdvance[0]; |
337 break; | 337 break; |
338 } | 338 } |
339 case SkAdvancedTypefaceMetrics::WidthRange::kRange: { | 339 case SkAdvancedTypefaceMetrics::WidthRange::kRange: { |
340 SkAutoTUnref<SkPDFArray> advanceArray(new SkPDFArray()); | 340 SkAutoTUnref<SkPDFArray> advanceArray(new SkPDFArray()); |
341 for (int j = 0; j < advanceInfo->fAdvance.count(); j++) | 341 for (int j = 0; j < advanceInfo->fAdvance.count(); j++) |
342 appendAdvance(advanceInfo->fAdvance[j], emSize, | 342 appendAdvance(advanceInfo->fAdvance[j], emSize, |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
513 SkTDArray<BFChar> bfcharEntries; | 513 SkTDArray<BFChar> bfcharEntries; |
514 SkTDArray<BFRange> bfrangeEntries; | 514 SkTDArray<BFRange> bfrangeEntries; |
515 | 515 |
516 BFRange currentRangeEntry = {0, 0, 0}; | 516 BFRange currentRangeEntry = {0, 0, 0}; |
517 bool rangeEmpty = true; | 517 bool rangeEmpty = true; |
518 const int limit = | 518 const int limit = |
519 SkMin32(lastGlyphID + 1, glyphToUnicode.count()) - glyphOffset; | 519 SkMin32(lastGlyphID + 1, glyphToUnicode.count()) - glyphOffset; |
520 | 520 |
521 for (int i = firstGlyphID - glyphOffset; i < limit + 1; ++i) { | 521 for (int i = firstGlyphID - glyphOffset; i < limit + 1; ++i) { |
522 bool inSubset = i < limit && | 522 bool inSubset = i < limit && |
523 (subset == NULL || subset->has(i + glyphOffset)); | 523 (subset == nullptr || subset->has(i + glyphOffset)); |
524 if (!rangeEmpty) { | 524 if (!rangeEmpty) { |
525 // PDF spec requires bfrange not changing the higher byte, | 525 // PDF spec requires bfrange not changing the higher byte, |
526 // e.g. <1035> <10FF> <2222> is ok, but | 526 // e.g. <1035> <10FF> <2222> is ok, but |
527 // <1035> <1100> <2222> is no good | 527 // <1035> <1100> <2222> is no good |
528 bool inRange = | 528 bool inRange = |
529 i == currentRangeEntry.fEnd + 1 && | 529 i == currentRangeEntry.fEnd + 1 && |
530 i >> 8 == currentRangeEntry.fStart >> 8 && | 530 i >> 8 == currentRangeEntry.fStart >> 8 && |
531 i < limit && | 531 i < limit && |
532 glyphToUnicode[i + glyphOffset] == | 532 glyphToUnicode[i + glyphOffset] == |
533 currentRangeEntry.fUnicode + i - currentRangeEntry.fStart; | 533 currentRangeEntry.fUnicode + i - currentRangeEntry.fStart; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
589 const SkTypeface* typeface, | 589 const SkTypeface* typeface, |
590 const SkTDArray<uint32_t>& subset, | 590 const SkTDArray<uint32_t>& subset, |
591 SkPDFStream** fontStream) { | 591 SkPDFStream** fontStream) { |
592 int ttcIndex; | 592 int ttcIndex; |
593 SkAutoTDelete<SkStream> fontData(typeface->openStream(&ttcIndex)); | 593 SkAutoTDelete<SkStream> fontData(typeface->openStream(&ttcIndex)); |
594 SkASSERT(fontData.get()); | 594 SkASSERT(fontData.get()); |
595 | 595 |
596 size_t fontSize = fontData->getLength(); | 596 size_t fontSize = fontData->getLength(); |
597 | 597 |
598 // Read font into buffer. | 598 // Read font into buffer. |
599 SkPDFStream* subsetFontStream = NULL; | 599 SkPDFStream* subsetFontStream = nullptr; |
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 = nullptr; |
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 static_assert(sizeof(unsigned int) == sizeof(uint32_t), "unsigned_int_no
t_32_bits"); | 606 static_assert(sizeof(unsigned int) == sizeof(uint32_t), "unsigned_int_no
t_32_bits"); |
607 int subsetFontSize = SfntlyWrapper::SubsetFont(fontName, | 607 int subsetFontSize = SfntlyWrapper::SubsetFont(fontName, |
608 originalFont.begin(), | 608 originalFont.begin(), |
609 fontSize, | 609 fontSize, |
610 subset.begin(), | 610 subset.begin(), |
611 subset.count(), | 611 subset.count(), |
612 &subsetFont); | 612 &subsetFont); |
613 if (subsetFontSize > 0 && subsetFont != NULL) { | 613 if (subsetFontSize > 0 && subsetFont != nullptr) { |
614 SkAutoDataUnref data(SkData::NewWithProc(subsetFont, | 614 SkAutoDataUnref data(SkData::NewWithProc(subsetFont, |
615 subsetFontSize, | 615 subsetFontSize, |
616 sk_delete_array, | 616 sk_delete_array, |
617 NULL)); | 617 nullptr)); |
618 subsetFontStream = new SkPDFStream(data.get()); | 618 subsetFontStream = new SkPDFStream(data.get()); |
619 fontSize = subsetFontSize; | 619 fontSize = subsetFontSize; |
620 } | 620 } |
621 } | 621 } |
622 if (subsetFontStream) { | 622 if (subsetFontStream) { |
623 *fontStream = subsetFontStream; | 623 *fontStream = subsetFontStream; |
624 return fontSize; | 624 return fontSize; |
625 } | 625 } |
626 fontData->rewind(); | 626 fontData->rewind(); |
627 | 627 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
664 : fFont(font), | 664 : fFont(font), |
665 fGlyphSet(glyphSet) { | 665 fGlyphSet(glyphSet) { |
666 } | 666 } |
667 | 667 |
668 SkPDFGlyphSetMap::F2BIter::F2BIter(const SkPDFGlyphSetMap& map) { | 668 SkPDFGlyphSetMap::F2BIter::F2BIter(const SkPDFGlyphSetMap& map) { |
669 reset(map); | 669 reset(map); |
670 } | 670 } |
671 | 671 |
672 const SkPDFGlyphSetMap::FontGlyphSetPair* SkPDFGlyphSetMap::F2BIter::next() cons
t { | 672 const SkPDFGlyphSetMap::FontGlyphSetPair* SkPDFGlyphSetMap::F2BIter::next() cons
t { |
673 if (fIndex >= fMap->count()) { | 673 if (fIndex >= fMap->count()) { |
674 return NULL; | 674 return nullptr; |
675 } | 675 } |
676 return &((*fMap)[fIndex++]); | 676 return &((*fMap)[fIndex++]); |
677 } | 677 } |
678 | 678 |
679 void SkPDFGlyphSetMap::F2BIter::reset(const SkPDFGlyphSetMap& map) { | 679 void SkPDFGlyphSetMap::F2BIter::reset(const SkPDFGlyphSetMap& map) { |
680 fMap = &(map.fMap); | 680 fMap = &(map.fMap); |
681 fIndex = 0; | 681 fIndex = 0; |
682 } | 682 } |
683 | 683 |
684 SkPDFGlyphSetMap::SkPDFGlyphSetMap() { | 684 SkPDFGlyphSetMap::SkPDFGlyphSetMap() { |
685 } | 685 } |
686 | 686 |
687 SkPDFGlyphSetMap::~SkPDFGlyphSetMap() { | 687 SkPDFGlyphSetMap::~SkPDFGlyphSetMap() { |
688 reset(); | 688 reset(); |
689 } | 689 } |
690 | 690 |
691 void SkPDFGlyphSetMap::merge(const SkPDFGlyphSetMap& usage) { | 691 void SkPDFGlyphSetMap::merge(const SkPDFGlyphSetMap& usage) { |
692 for (int i = 0; i < usage.fMap.count(); ++i) { | 692 for (int i = 0; i < usage.fMap.count(); ++i) { |
693 SkPDFGlyphSet* myUsage = getGlyphSetForFont(usage.fMap[i].fFont); | 693 SkPDFGlyphSet* myUsage = getGlyphSetForFont(usage.fMap[i].fFont); |
694 myUsage->merge(*(usage.fMap[i].fGlyphSet)); | 694 myUsage->merge(*(usage.fMap[i].fGlyphSet)); |
695 } | 695 } |
696 } | 696 } |
697 | 697 |
698 void SkPDFGlyphSetMap::reset() { | 698 void SkPDFGlyphSetMap::reset() { |
699 for (int i = 0; i < fMap.count(); ++i) { | 699 for (int i = 0; i < fMap.count(); ++i) { |
700 delete fMap[i].fGlyphSet; // Should not be NULL. | 700 delete fMap[i].fGlyphSet; // Should not be nullptr. |
701 } | 701 } |
702 fMap.reset(); | 702 fMap.reset(); |
703 } | 703 } |
704 | 704 |
705 void SkPDFGlyphSetMap::noteGlyphUsage(SkPDFFont* font, const uint16_t* glyphIDs, | 705 void SkPDFGlyphSetMap::noteGlyphUsage(SkPDFFont* font, const uint16_t* glyphIDs, |
706 int numGlyphs) { | 706 int numGlyphs) { |
707 SkPDFGlyphSet* subset = getGlyphSetForFont(font); | 707 SkPDFGlyphSet* subset = getGlyphSetForFont(font); |
708 if (subset) { | 708 if (subset) { |
709 subset->set(glyphIDs, numGlyphs); | 709 subset->set(glyphIDs, numGlyphs); |
710 } | 710 } |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
799 SkAutoResolveDefaultTypeface autoResolve(typeface); | 799 SkAutoResolveDefaultTypeface autoResolve(typeface); |
800 typeface = autoResolve.get(); | 800 typeface = autoResolve.get(); |
801 const uint32_t fontID = typeface->uniqueID(); | 801 const uint32_t fontID = typeface->uniqueID(); |
802 | 802 |
803 SkPDFFont* relatedFont; | 803 SkPDFFont* relatedFont; |
804 if (SkPDFFont* pdfFont = canon->findFont(fontID, glyphID, &relatedFont)) { | 804 if (SkPDFFont* pdfFont = canon->findFont(fontID, glyphID, &relatedFont)) { |
805 return SkRef(pdfFont); | 805 return SkRef(pdfFont); |
806 } | 806 } |
807 | 807 |
808 SkAutoTUnref<const SkAdvancedTypefaceMetrics> fontMetrics; | 808 SkAutoTUnref<const SkAdvancedTypefaceMetrics> fontMetrics; |
809 SkPDFDict* relatedFontDescriptor = NULL; | 809 SkPDFDict* relatedFontDescriptor = nullptr; |
810 if (relatedFont) { | 810 if (relatedFont) { |
811 fontMetrics.reset(SkSafeRef(relatedFont->fontInfo())); | 811 fontMetrics.reset(SkSafeRef(relatedFont->fontInfo())); |
812 relatedFontDescriptor = relatedFont->getFontDescriptor(); | 812 relatedFontDescriptor = relatedFont->getFontDescriptor(); |
813 | 813 |
814 // This only is to catch callers who pass invalid glyph ids. | 814 // This only is to catch callers who pass invalid glyph ids. |
815 // If glyph id is invalid, then we will create duplicate entries | 815 // If glyph id is invalid, then we will create duplicate entries |
816 // for TrueType fonts. | 816 // for TrueType fonts. |
817 SkAdvancedTypefaceMetrics::FontType fontType = | 817 SkAdvancedTypefaceMetrics::FontType fontType = |
818 fontMetrics.get() ? fontMetrics.get()->fType : | 818 fontMetrics.get() ? fontMetrics.get()->fType : |
819 SkAdvancedTypefaceMetrics::kOther_Font; | 819 SkAdvancedTypefaceMetrics::kOther_Font; |
820 | 820 |
821 if (fontType == SkAdvancedTypefaceMetrics::kType1CID_Font || | 821 if (fontType == SkAdvancedTypefaceMetrics::kType1CID_Font || |
822 fontType == SkAdvancedTypefaceMetrics::kTrueType_Font) { | 822 fontType == SkAdvancedTypefaceMetrics::kTrueType_Font) { |
823 return SkRef(relatedFont); | 823 return SkRef(relatedFont); |
824 } | 824 } |
825 } else { | 825 } else { |
826 SkTypeface::PerGlyphInfo info; | 826 SkTypeface::PerGlyphInfo info; |
827 info = SkTypeface::kGlyphNames_PerGlyphInfo; | 827 info = SkTypeface::kGlyphNames_PerGlyphInfo; |
828 info = SkTBitOr<SkTypeface::PerGlyphInfo>( | 828 info = SkTBitOr<SkTypeface::PerGlyphInfo>( |
829 info, SkTypeface::kToUnicode_PerGlyphInfo); | 829 info, SkTypeface::kToUnicode_PerGlyphInfo); |
830 #if !defined (SK_SFNTLY_SUBSETTER) | 830 #if !defined (SK_SFNTLY_SUBSETTER) |
831 info = SkTBitOr<SkTypeface::PerGlyphInfo>( | 831 info = SkTBitOr<SkTypeface::PerGlyphInfo>( |
832 info, SkTypeface::kHAdvance_PerGlyphInfo); | 832 info, SkTypeface::kHAdvance_PerGlyphInfo); |
833 #endif | 833 #endif |
834 fontMetrics.reset( | 834 fontMetrics.reset( |
835 typeface->getAdvancedTypefaceMetrics(info, NULL, 0)); | 835 typeface->getAdvancedTypefaceMetrics(info, nullptr, 0)); |
836 #if defined (SK_SFNTLY_SUBSETTER) | 836 #if defined (SK_SFNTLY_SUBSETTER) |
837 if (fontMetrics.get() && | 837 if (fontMetrics.get() && |
838 fontMetrics->fType != SkAdvancedTypefaceMetrics::kTrueType_Font) { | 838 fontMetrics->fType != SkAdvancedTypefaceMetrics::kTrueType_Font) { |
839 // Font does not support subsetting, get new info with advance. | 839 // Font does not support subsetting, get new info with advance. |
840 info = SkTBitOr<SkTypeface::PerGlyphInfo>( | 840 info = SkTBitOr<SkTypeface::PerGlyphInfo>( |
841 info, SkTypeface::kHAdvance_PerGlyphInfo); | 841 info, SkTypeface::kHAdvance_PerGlyphInfo); |
842 fontMetrics.reset( | 842 fontMetrics.reset( |
843 typeface->getAdvancedTypefaceMetrics(info, NULL, 0)); | 843 typeface->getAdvancedTypefaceMetrics(info, nullptr, 0)); |
844 } | 844 } |
845 #endif | 845 #endif |
846 } | 846 } |
847 | 847 |
848 SkPDFFont* font = SkPDFFont::Create(canon, fontMetrics.get(), typeface, | 848 SkPDFFont* font = SkPDFFont::Create(canon, fontMetrics.get(), typeface, |
849 glyphID, relatedFontDescriptor); | 849 glyphID, relatedFontDescriptor); |
850 canon->addFont(font, fontID, font->fFirstGlyphID); | 850 canon->addFont(font, fontID, font->fFirstGlyphID); |
851 return font; | 851 return font; |
852 } | 852 } |
853 | 853 |
854 SkPDFFont* SkPDFFont::getFontSubset(const SkPDFGlyphSet*) { | 854 SkPDFFont* SkPDFFont::getFontSubset(const SkPDFGlyphSet*) { |
855 return NULL; // Default: no support. | 855 return nullptr; // Default: no support. |
856 } | 856 } |
857 | 857 |
858 SkPDFFont::SkPDFFont(const SkAdvancedTypefaceMetrics* info, | 858 SkPDFFont::SkPDFFont(const SkAdvancedTypefaceMetrics* info, |
859 SkTypeface* typeface, | 859 SkTypeface* typeface, |
860 SkPDFDict* relatedFontDescriptor) | 860 SkPDFDict* relatedFontDescriptor) |
861 : SkPDFDict("Font") | 861 : SkPDFDict("Font") |
862 , fTypeface(ref_or_default(typeface)) | 862 , fTypeface(ref_or_default(typeface)) |
863 , fFirstGlyphID(1) | 863 , fFirstGlyphID(1) |
864 , fLastGlyphID(info ? info->fLastGlyphID : 0) | 864 , fLastGlyphID(info ? info->fLastGlyphID : 0) |
865 , fFontInfo(SkSafeRef(info)) | 865 , fFontInfo(SkSafeRef(info)) |
866 , fDescriptor(SkSafeRef(relatedFontDescriptor)) { | 866 , fDescriptor(SkSafeRef(relatedFontDescriptor)) { |
867 if (info == NULL || | 867 if (info == nullptr || |
868 info->fFlags & SkAdvancedTypefaceMetrics::kMultiMaster_FontFlag) { | 868 info->fFlags & SkAdvancedTypefaceMetrics::kMultiMaster_FontFlag) { |
869 fFontType = SkAdvancedTypefaceMetrics::kOther_Font; | 869 fFontType = SkAdvancedTypefaceMetrics::kOther_Font; |
870 } else { | 870 } else { |
871 fFontType = info->fType; | 871 fFontType = info->fType; |
872 } | 872 } |
873 } | 873 } |
874 | 874 |
875 // static | 875 // static |
876 SkPDFFont* SkPDFFont::Create(SkPDFCanon* canon, | 876 SkPDFFont* SkPDFFont::Create(SkPDFCanon* canon, |
877 const SkAdvancedTypefaceMetrics* info, | 877 const SkAdvancedTypefaceMetrics* info, |
878 SkTypeface* typeface, | 878 SkTypeface* typeface, |
879 uint16_t glyphID, | 879 uint16_t glyphID, |
880 SkPDFDict* relatedFontDescriptor) { | 880 SkPDFDict* relatedFontDescriptor) { |
881 SkAdvancedTypefaceMetrics::FontType type = | 881 SkAdvancedTypefaceMetrics::FontType type = |
882 info ? info->fType : SkAdvancedTypefaceMetrics::kOther_Font; | 882 info ? info->fType : SkAdvancedTypefaceMetrics::kOther_Font; |
883 | 883 |
884 if (info && (info->fFlags & SkAdvancedTypefaceMetrics::kMultiMaster_FontFlag
)) { | 884 if (info && (info->fFlags & SkAdvancedTypefaceMetrics::kMultiMaster_FontFlag
)) { |
885 return new SkPDFType3Font(info, typeface, glyphID); | 885 return new SkPDFType3Font(info, typeface, glyphID); |
886 } | 886 } |
887 if (type == SkAdvancedTypefaceMetrics::kType1CID_Font || | 887 if (type == SkAdvancedTypefaceMetrics::kType1CID_Font || |
888 type == SkAdvancedTypefaceMetrics::kTrueType_Font) { | 888 type == SkAdvancedTypefaceMetrics::kTrueType_Font) { |
889 SkASSERT(relatedFontDescriptor == NULL); | 889 SkASSERT(relatedFontDescriptor == nullptr); |
890 return new SkPDFType0Font(info, typeface); | 890 return new SkPDFType0Font(info, typeface); |
891 } | 891 } |
892 if (type == SkAdvancedTypefaceMetrics::kType1_Font) { | 892 if (type == SkAdvancedTypefaceMetrics::kType1_Font) { |
893 return new SkPDFType1Font(info, typeface, glyphID, relatedFontDescriptor
); | 893 return new SkPDFType1Font(info, typeface, glyphID, relatedFontDescriptor
); |
894 } | 894 } |
895 | 895 |
896 SkASSERT(type == SkAdvancedTypefaceMetrics::kCFF_Font || | 896 SkASSERT(type == SkAdvancedTypefaceMetrics::kCFF_Font || |
897 type == SkAdvancedTypefaceMetrics::kOther_Font); | 897 type == SkAdvancedTypefaceMetrics::kOther_Font); |
898 | 898 |
899 return new SkPDFType3Font(info, typeface, glyphID); | 899 return new SkPDFType3Font(info, typeface, glyphID); |
900 } | 900 } |
901 | 901 |
902 const SkAdvancedTypefaceMetrics* SkPDFFont::fontInfo() { | 902 const SkAdvancedTypefaceMetrics* SkPDFFont::fontInfo() { |
903 return fFontInfo.get(); | 903 return fFontInfo.get(); |
904 } | 904 } |
905 | 905 |
906 void SkPDFFont::setFontInfo(const SkAdvancedTypefaceMetrics* info) { | 906 void SkPDFFont::setFontInfo(const SkAdvancedTypefaceMetrics* info) { |
907 if (info == NULL || info == fFontInfo.get()) { | 907 if (info == nullptr || info == fFontInfo.get()) { |
908 return; | 908 return; |
909 } | 909 } |
910 fFontInfo.reset(info); | 910 fFontInfo.reset(info); |
911 SkSafeRef(info); | 911 SkSafeRef(info); |
912 } | 912 } |
913 | 913 |
914 uint16_t SkPDFFont::firstGlyphID() const { | 914 uint16_t SkPDFFont::firstGlyphID() const { |
915 return fFirstGlyphID; | 915 return fFirstGlyphID; |
916 } | 916 } |
917 | 917 |
918 uint16_t SkPDFFont::lastGlyphID() const { | 918 uint16_t SkPDFFont::lastGlyphID() const { |
919 return fLastGlyphID; | 919 return fLastGlyphID; |
920 } | 920 } |
921 | 921 |
922 void SkPDFFont::setLastGlyphID(uint16_t glyphID) { | 922 void SkPDFFont::setLastGlyphID(uint16_t glyphID) { |
923 fLastGlyphID = glyphID; | 923 fLastGlyphID = glyphID; |
924 } | 924 } |
925 | 925 |
926 SkPDFDict* SkPDFFont::getFontDescriptor() { | 926 SkPDFDict* SkPDFFont::getFontDescriptor() { |
927 return fDescriptor.get(); | 927 return fDescriptor.get(); |
928 } | 928 } |
929 | 929 |
930 void SkPDFFont::setFontDescriptor(SkPDFDict* descriptor) { | 930 void SkPDFFont::setFontDescriptor(SkPDFDict* descriptor) { |
931 fDescriptor.reset(descriptor); | 931 fDescriptor.reset(descriptor); |
932 SkSafeRef(descriptor); | 932 SkSafeRef(descriptor); |
933 } | 933 } |
934 | 934 |
935 bool SkPDFFont::addCommonFontDescriptorEntries(int16_t defaultWidth) { | 935 bool SkPDFFont::addCommonFontDescriptorEntries(int16_t defaultWidth) { |
936 if (fDescriptor.get() == NULL) { | 936 if (fDescriptor.get() == nullptr) { |
937 return false; | 937 return false; |
938 } | 938 } |
939 | 939 |
940 const uint16_t emSize = fFontInfo->fEmSize; | 940 const uint16_t emSize = fFontInfo->fEmSize; |
941 | 941 |
942 fDescriptor->insertName("FontName", fFontInfo->fFontName); | 942 fDescriptor->insertName("FontName", fFontInfo->fFontName); |
943 fDescriptor->insertInt("Flags", fFontInfo->fStyle | kPdfSymbolic); | 943 fDescriptor->insertInt("Flags", fFontInfo->fStyle | kPdfSymbolic); |
944 fDescriptor->insertScalar("Ascent", | 944 fDescriptor->insertScalar("Ascent", |
945 scaleFromFontUnits(fFontInfo->fAscent, emSize)); | 945 scaleFromFontUnits(fFontInfo->fAscent, emSize)); |
946 fDescriptor->insertScalar("Descent", | 946 fDescriptor->insertScalar("Descent", |
(...skipping 16 matching lines...) Expand all Loading... |
963 | 963 |
964 void SkPDFFont::adjustGlyphRangeForSingleByteEncoding(uint16_t glyphID) { | 964 void SkPDFFont::adjustGlyphRangeForSingleByteEncoding(uint16_t glyphID) { |
965 // Single byte glyph encoding supports a max of 255 glyphs. | 965 // Single byte glyph encoding supports a max of 255 glyphs. |
966 fFirstGlyphID = glyphID - (glyphID - 1) % 255; | 966 fFirstGlyphID = glyphID - (glyphID - 1) % 255; |
967 if (fLastGlyphID > fFirstGlyphID + 255 - 1) { | 967 if (fLastGlyphID > fFirstGlyphID + 255 - 1) { |
968 fLastGlyphID = fFirstGlyphID + 255 - 1; | 968 fLastGlyphID = fFirstGlyphID + 255 - 1; |
969 } | 969 } |
970 } | 970 } |
971 | 971 |
972 void SkPDFFont::populateToUnicodeTable(const SkPDFGlyphSet* subset) { | 972 void SkPDFFont::populateToUnicodeTable(const SkPDFGlyphSet* subset) { |
973 if (fFontInfo == NULL || fFontInfo->fGlyphToUnicode.begin() == NULL) { | 973 if (fFontInfo == nullptr || fFontInfo->fGlyphToUnicode.begin() == nullptr) { |
974 return; | 974 return; |
975 } | 975 } |
976 this->insertObjRef("ToUnicode", | 976 this->insertObjRef("ToUnicode", |
977 generate_tounicode_cmap(fFontInfo->fGlyphToUnicode, | 977 generate_tounicode_cmap(fFontInfo->fGlyphToUnicode, |
978 subset, | 978 subset, |
979 multiByteGlyphs(), | 979 multiByteGlyphs(), |
980 firstGlyphID(), | 980 firstGlyphID(), |
981 lastGlyphID())); | 981 lastGlyphID())); |
982 } | 982 } |
983 | 983 |
984 /////////////////////////////////////////////////////////////////////////////// | 984 /////////////////////////////////////////////////////////////////////////////// |
985 // class SkPDFType0Font | 985 // class SkPDFType0Font |
986 /////////////////////////////////////////////////////////////////////////////// | 986 /////////////////////////////////////////////////////////////////////////////// |
987 | 987 |
988 SkPDFType0Font::SkPDFType0Font(const SkAdvancedTypefaceMetrics* info, SkTypeface
* typeface) | 988 SkPDFType0Font::SkPDFType0Font(const SkAdvancedTypefaceMetrics* info, SkTypeface
* typeface) |
989 : SkPDFFont(info, typeface, NULL) { | 989 : SkPDFFont(info, typeface, nullptr) { |
990 SkDEBUGCODE(fPopulated = false); | 990 SkDEBUGCODE(fPopulated = false); |
991 if (!canSubset()) { | 991 if (!canSubset()) { |
992 this->populate(NULL); | 992 this->populate(nullptr); |
993 } | 993 } |
994 } | 994 } |
995 | 995 |
996 SkPDFType0Font::~SkPDFType0Font() {} | 996 SkPDFType0Font::~SkPDFType0Font() {} |
997 | 997 |
998 SkPDFFont* SkPDFType0Font::getFontSubset(const SkPDFGlyphSet* subset) { | 998 SkPDFFont* SkPDFType0Font::getFontSubset(const SkPDFGlyphSet* subset) { |
999 if (!canSubset()) { | 999 if (!canSubset()) { |
1000 return NULL; | 1000 return nullptr; |
1001 } | 1001 } |
1002 SkPDFType0Font* newSubset = new SkPDFType0Font(fontInfo(), typeface()); | 1002 SkPDFType0Font* newSubset = new SkPDFType0Font(fontInfo(), typeface()); |
1003 newSubset->populate(subset); | 1003 newSubset->populate(subset); |
1004 return newSubset; | 1004 return newSubset; |
1005 } | 1005 } |
1006 | 1006 |
1007 #ifdef SK_DEBUG | 1007 #ifdef SK_DEBUG |
1008 void SkPDFType0Font::emitObject(SkWStream* stream, | 1008 void SkPDFType0Font::emitObject(SkWStream* stream, |
1009 const SkPDFObjNumMap& objNumMap, | 1009 const SkPDFObjNumMap& objNumMap, |
1010 const SkPDFSubstituteMap& substitutes) const { | 1010 const SkPDFSubstituteMap& substitutes) const { |
(...skipping 19 matching lines...) Expand all Loading... |
1030 return true; | 1030 return true; |
1031 } | 1031 } |
1032 | 1032 |
1033 /////////////////////////////////////////////////////////////////////////////// | 1033 /////////////////////////////////////////////////////////////////////////////// |
1034 // class SkPDFCIDFont | 1034 // class SkPDFCIDFont |
1035 /////////////////////////////////////////////////////////////////////////////// | 1035 /////////////////////////////////////////////////////////////////////////////// |
1036 | 1036 |
1037 SkPDFCIDFont::SkPDFCIDFont(const SkAdvancedTypefaceMetrics* info, | 1037 SkPDFCIDFont::SkPDFCIDFont(const SkAdvancedTypefaceMetrics* info, |
1038 SkTypeface* typeface, | 1038 SkTypeface* typeface, |
1039 const SkPDFGlyphSet* subset) | 1039 const SkPDFGlyphSet* subset) |
1040 : SkPDFFont(info, typeface, NULL) { | 1040 : SkPDFFont(info, typeface, nullptr) { |
1041 this->populate(subset); | 1041 this->populate(subset); |
1042 } | 1042 } |
1043 | 1043 |
1044 SkPDFCIDFont::~SkPDFCIDFont() {} | 1044 SkPDFCIDFont::~SkPDFCIDFont() {} |
1045 | 1045 |
1046 bool SkPDFCIDFont::addFontDescriptor(int16_t defaultWidth, | 1046 bool SkPDFCIDFont::addFontDescriptor(int16_t defaultWidth, |
1047 const SkTDArray<uint32_t>* subset) { | 1047 const SkTDArray<uint32_t>* subset) { |
1048 SkAutoTUnref<SkPDFDict> descriptor(new SkPDFDict("FontDescriptor")); | 1048 SkAutoTUnref<SkPDFDict> descriptor(new SkPDFDict("FontDescriptor")); |
1049 setFontDescriptor(descriptor.get()); | 1049 setFontDescriptor(descriptor.get()); |
1050 if (!addCommonFontDescriptorEntries(defaultWidth)) { | 1050 if (!addCommonFontDescriptorEntries(defaultWidth)) { |
1051 this->insertObjRef("FontDescriptor", descriptor.detach()); | 1051 this->insertObjRef("FontDescriptor", descriptor.detach()); |
1052 return false; | 1052 return false; |
1053 } | 1053 } |
1054 if (!canEmbed()) { | 1054 if (!canEmbed()) { |
1055 this->insertObjRef("FontDescriptor", descriptor.detach()); | 1055 this->insertObjRef("FontDescriptor", descriptor.detach()); |
1056 return true; | 1056 return true; |
1057 } | 1057 } |
1058 | 1058 |
1059 switch (getType()) { | 1059 switch (getType()) { |
1060 case SkAdvancedTypefaceMetrics::kTrueType_Font: { | 1060 case SkAdvancedTypefaceMetrics::kTrueType_Font: { |
1061 size_t fontSize = 0; | 1061 size_t fontSize = 0; |
1062 #if defined(SK_SFNTLY_SUBSETTER) | 1062 #if defined(SK_SFNTLY_SUBSETTER) |
1063 if (this->canSubset()) { | 1063 if (this->canSubset()) { |
1064 SkAutoTUnref<SkPDFStream> fontStream; | 1064 SkAutoTUnref<SkPDFStream> fontStream; |
1065 SkPDFStream* rawStream = NULL; | 1065 SkPDFStream* rawStream = nullptr; |
1066 fontSize = get_subset_font_stream(fontInfo()->fFontName.c_str(), | 1066 fontSize = get_subset_font_stream(fontInfo()->fFontName.c_str(), |
1067 typeface(), | 1067 typeface(), |
1068 *subset, | 1068 *subset, |
1069 &rawStream); | 1069 &rawStream); |
1070 if (rawStream) { | 1070 if (rawStream) { |
1071 fontStream.reset(rawStream); | 1071 fontStream.reset(rawStream); |
1072 fontStream->insertInt("Length1", fontSize); | 1072 fontStream->insertInt("Length1", fontSize); |
1073 descriptor->insertObjRef("FontFile2", fontStream.detach()); | 1073 descriptor->insertObjRef("FontFile2", fontStream.detach()); |
1074 break; | 1074 break; |
1075 } | 1075 } |
1076 } | 1076 } |
1077 #endif | 1077 #endif |
1078 SkAutoTUnref<SkPDFSharedStream> fontStream; | 1078 SkAutoTUnref<SkPDFSharedStream> fontStream; |
1079 SkAutoTDelete<SkStreamAsset> fontData( | 1079 SkAutoTDelete<SkStreamAsset> fontData( |
1080 this->typeface()->openStream(NULL)); | 1080 this->typeface()->openStream(nullptr)); |
1081 SkASSERT(fontData); | 1081 SkASSERT(fontData); |
1082 fontSize = fontData->getLength(); | 1082 fontSize = fontData->getLength(); |
1083 SkASSERT(fontSize > 0); | 1083 SkASSERT(fontSize > 0); |
1084 fontStream.reset(new SkPDFSharedStream(fontData.detach())); | 1084 fontStream.reset(new SkPDFSharedStream(fontData.detach())); |
1085 fontStream->dict()->insertInt("Length1", fontSize); | 1085 fontStream->dict()->insertInt("Length1", fontSize); |
1086 descriptor->insertObjRef("FontFile2", fontStream.detach()); | 1086 descriptor->insertObjRef("FontFile2", fontStream.detach()); |
1087 break; | 1087 break; |
1088 } | 1088 } |
1089 case SkAdvancedTypefaceMetrics::kCFF_Font: | 1089 case SkAdvancedTypefaceMetrics::kCFF_Font: |
1090 case SkAdvancedTypefaceMetrics::kType1CID_Font: { | 1090 case SkAdvancedTypefaceMetrics::kType1CID_Font: { |
1091 SkAutoTUnref<SkPDFSharedStream> fontStream( | 1091 SkAutoTUnref<SkPDFSharedStream> fontStream( |
1092 new SkPDFSharedStream(this->typeface()->openStream(NULL))); | 1092 new SkPDFSharedStream(this->typeface()->openStream(nullptr))
); |
1093 | 1093 |
1094 if (getType() == SkAdvancedTypefaceMetrics::kCFF_Font) { | 1094 if (getType() == SkAdvancedTypefaceMetrics::kCFF_Font) { |
1095 fontStream->dict()->insertName("Subtype", "Type1C"); | 1095 fontStream->dict()->insertName("Subtype", "Type1C"); |
1096 } else { | 1096 } else { |
1097 fontStream->dict()->insertName("Subtype", "CIDFontType0c"); | 1097 fontStream->dict()->insertName("Subtype", "CIDFontType0c"); |
1098 } | 1098 } |
1099 descriptor->insertObjRef("FontFile3", fontStream.detach()); | 1099 descriptor->insertObjRef("FontFile3", fontStream.detach()); |
1100 break; | 1100 break; |
1101 } | 1101 } |
1102 default: | 1102 default: |
(...skipping 13 matching lines...) Expand all Loading... |
1116 if (!subset->has(0)) { | 1116 if (!subset->has(0)) { |
1117 glyphIDs.push(0); | 1117 glyphIDs.push(0); |
1118 } | 1118 } |
1119 subset->exportTo(&glyphIDs); | 1119 subset->exportTo(&glyphIDs); |
1120 } | 1120 } |
1121 | 1121 |
1122 SkTypeface::PerGlyphInfo info; | 1122 SkTypeface::PerGlyphInfo info; |
1123 info = SkTypeface::kGlyphNames_PerGlyphInfo; | 1123 info = SkTypeface::kGlyphNames_PerGlyphInfo; |
1124 info = SkTBitOr<SkTypeface::PerGlyphInfo>( | 1124 info = SkTBitOr<SkTypeface::PerGlyphInfo>( |
1125 info, SkTypeface::kHAdvance_PerGlyphInfo); | 1125 info, SkTypeface::kHAdvance_PerGlyphInfo); |
1126 uint32_t* glyphs = (glyphIDs.count() == 0) ? NULL : glyphIDs.begin(); | 1126 uint32_t* glyphs = (glyphIDs.count() == 0) ? nullptr : glyphIDs.begin(); |
1127 uint32_t glyphsCount = glyphs ? glyphIDs.count() : 0; | 1127 uint32_t glyphsCount = glyphs ? glyphIDs.count() : 0; |
1128 SkAutoTUnref<const SkAdvancedTypefaceMetrics> fontMetrics( | 1128 SkAutoTUnref<const SkAdvancedTypefaceMetrics> fontMetrics( |
1129 typeface()->getAdvancedTypefaceMetrics(info, glyphs, glyphsCount)); | 1129 typeface()->getAdvancedTypefaceMetrics(info, glyphs, glyphsCount)); |
1130 setFontInfo(fontMetrics.get()); | 1130 setFontInfo(fontMetrics.get()); |
1131 addFontDescriptor(0, &glyphIDs); | 1131 addFontDescriptor(0, &glyphIDs); |
1132 } else { | 1132 } else { |
1133 // Other CID fonts | 1133 // Other CID fonts |
1134 addFontDescriptor(0, NULL); | 1134 addFontDescriptor(0, nullptr); |
1135 } | 1135 } |
1136 | 1136 |
1137 insertName("BaseFont", fontInfo()->fFontName); | 1137 insertName("BaseFont", fontInfo()->fFontName); |
1138 | 1138 |
1139 if (getType() == SkAdvancedTypefaceMetrics::kType1CID_Font) { | 1139 if (getType() == SkAdvancedTypefaceMetrics::kType1CID_Font) { |
1140 insertName("Subtype", "CIDFontType0"); | 1140 insertName("Subtype", "CIDFontType0"); |
1141 } else if (getType() == SkAdvancedTypefaceMetrics::kTrueType_Font) { | 1141 } else if (getType() == SkAdvancedTypefaceMetrics::kTrueType_Font) { |
1142 insertName("Subtype", "CIDFontType2"); | 1142 insertName("Subtype", "CIDFontType2"); |
1143 insertName("CIDToGIDMap", "Identity"); | 1143 insertName("CIDToGIDMap", "Identity"); |
1144 } else { | 1144 } else { |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1212 SkAutoTUnref<SkPDFDict> descriptor(new SkPDFDict("FontDescriptor")); | 1212 SkAutoTUnref<SkPDFDict> descriptor(new SkPDFDict("FontDescriptor")); |
1213 setFontDescriptor(descriptor.get()); | 1213 setFontDescriptor(descriptor.get()); |
1214 | 1214 |
1215 int ttcIndex; | 1215 int ttcIndex; |
1216 size_t header SK_INIT_TO_AVOID_WARNING; | 1216 size_t header SK_INIT_TO_AVOID_WARNING; |
1217 size_t data SK_INIT_TO_AVOID_WARNING; | 1217 size_t data SK_INIT_TO_AVOID_WARNING; |
1218 size_t trailer SK_INIT_TO_AVOID_WARNING; | 1218 size_t trailer SK_INIT_TO_AVOID_WARNING; |
1219 SkAutoTDelete<SkStream> rawFontData(typeface()->openStream(&ttcIndex)); | 1219 SkAutoTDelete<SkStream> rawFontData(typeface()->openStream(&ttcIndex)); |
1220 SkAutoTUnref<SkData> fontData(handle_type1_stream(rawFontData.get(), &header
, | 1220 SkAutoTUnref<SkData> fontData(handle_type1_stream(rawFontData.get(), &header
, |
1221 &data, &trailer)); | 1221 &data, &trailer)); |
1222 if (fontData.get() == NULL) { | 1222 if (fontData.get() == nullptr) { |
1223 return false; | 1223 return false; |
1224 } | 1224 } |
1225 if (canEmbed()) { | 1225 if (canEmbed()) { |
1226 SkAutoTUnref<SkPDFStream> fontStream(new SkPDFStream(fontData.get())); | 1226 SkAutoTUnref<SkPDFStream> fontStream(new SkPDFStream(fontData.get())); |
1227 fontStream->insertInt("Length1", header); | 1227 fontStream->insertInt("Length1", header); |
1228 fontStream->insertInt("Length2", data); | 1228 fontStream->insertInt("Length2", data); |
1229 fontStream->insertInt("Length3", trailer); | 1229 fontStream->insertInt("Length3", trailer); |
1230 descriptor->insertObjRef("FontFile", fontStream.detach()); | 1230 descriptor->insertObjRef("FontFile", fontStream.detach()); |
1231 } | 1231 } |
1232 | 1232 |
1233 this->insertObjRef("FontDescriptor", descriptor.detach()); | 1233 this->insertObjRef("FontDescriptor", descriptor.detach()); |
1234 | 1234 |
1235 return addCommonFontDescriptorEntries(defaultWidth); | 1235 return addCommonFontDescriptorEntries(defaultWidth); |
1236 } | 1236 } |
1237 | 1237 |
1238 bool SkPDFType1Font::populate(int16_t glyphID) { | 1238 bool SkPDFType1Font::populate(int16_t glyphID) { |
1239 SkASSERT(!fontInfo()->fVerticalMetrics.get()); | 1239 SkASSERT(!fontInfo()->fVerticalMetrics.get()); |
1240 SkASSERT(fontInfo()->fGlyphWidths.get()); | 1240 SkASSERT(fontInfo()->fGlyphWidths.get()); |
1241 | 1241 |
1242 adjustGlyphRangeForSingleByteEncoding(glyphID); | 1242 adjustGlyphRangeForSingleByteEncoding(glyphID); |
1243 | 1243 |
1244 int16_t defaultWidth = 0; | 1244 int16_t defaultWidth = 0; |
1245 const SkAdvancedTypefaceMetrics::WidthRange* widthRangeEntry = NULL; | 1245 const SkAdvancedTypefaceMetrics::WidthRange* widthRangeEntry = nullptr; |
1246 const SkAdvancedTypefaceMetrics::WidthRange* widthEntry; | 1246 const SkAdvancedTypefaceMetrics::WidthRange* widthEntry; |
1247 for (widthEntry = fontInfo()->fGlyphWidths.get(); | 1247 for (widthEntry = fontInfo()->fGlyphWidths.get(); |
1248 widthEntry != NULL; | 1248 widthEntry != nullptr; |
1249 widthEntry = widthEntry->fNext.get()) { | 1249 widthEntry = widthEntry->fNext.get()) { |
1250 switch (widthEntry->fType) { | 1250 switch (widthEntry->fType) { |
1251 case SkAdvancedTypefaceMetrics::WidthRange::kDefault: | 1251 case SkAdvancedTypefaceMetrics::WidthRange::kDefault: |
1252 defaultWidth = widthEntry->fAdvance[0]; | 1252 defaultWidth = widthEntry->fAdvance[0]; |
1253 break; | 1253 break; |
1254 case SkAdvancedTypefaceMetrics::WidthRange::kRun: | 1254 case SkAdvancedTypefaceMetrics::WidthRange::kRun: |
1255 SkASSERT(false); | 1255 SkASSERT(false); |
1256 break; | 1256 break; |
1257 case SkAdvancedTypefaceMetrics::WidthRange::kRange: | 1257 case SkAdvancedTypefaceMetrics::WidthRange::kRange: |
1258 SkASSERT(widthRangeEntry == NULL); | 1258 SkASSERT(widthRangeEntry == nullptr); |
1259 widthRangeEntry = widthEntry; | 1259 widthRangeEntry = widthEntry; |
1260 break; | 1260 break; |
1261 } | 1261 } |
1262 } | 1262 } |
1263 | 1263 |
1264 if (!addFontDescriptor(defaultWidth)) { | 1264 if (!addFontDescriptor(defaultWidth)) { |
1265 return false; | 1265 return false; |
1266 } | 1266 } |
1267 | 1267 |
1268 insertName("Subtype", "Type1"); | 1268 insertName("Subtype", "Type1"); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1313 this->insertObject("Widths", widthArray.detach()); | 1313 this->insertObject("Widths", widthArray.detach()); |
1314 } | 1314 } |
1315 | 1315 |
1316 /////////////////////////////////////////////////////////////////////////////// | 1316 /////////////////////////////////////////////////////////////////////////////// |
1317 // class SkPDFType3Font | 1317 // class SkPDFType3Font |
1318 /////////////////////////////////////////////////////////////////////////////// | 1318 /////////////////////////////////////////////////////////////////////////////// |
1319 | 1319 |
1320 SkPDFType3Font::SkPDFType3Font(const SkAdvancedTypefaceMetrics* info, | 1320 SkPDFType3Font::SkPDFType3Font(const SkAdvancedTypefaceMetrics* info, |
1321 SkTypeface* typeface, | 1321 SkTypeface* typeface, |
1322 uint16_t glyphID) | 1322 uint16_t glyphID) |
1323 : SkPDFFont(info, typeface, NULL) { | 1323 : SkPDFFont(info, typeface, nullptr) { |
1324 this->populate(glyphID); | 1324 this->populate(glyphID); |
1325 } | 1325 } |
1326 | 1326 |
1327 SkPDFType3Font::~SkPDFType3Font() {} | 1327 SkPDFType3Font::~SkPDFType3Font() {} |
1328 | 1328 |
1329 bool SkPDFType3Font::populate(uint16_t glyphID) { | 1329 bool SkPDFType3Font::populate(uint16_t glyphID) { |
1330 SkPaint paint; | 1330 SkPaint paint; |
1331 paint.setTypeface(typeface()); | 1331 paint.setTypeface(typeface()); |
1332 paint.setTextSize(1000); | 1332 paint.setTextSize(1000); |
1333 const SkSurfaceProps props(0, kUnknown_SkPixelGeometry); | 1333 const SkSurfaceProps props(0, kUnknown_SkPixelGeometry); |
1334 SkAutoGlyphCache autoCache(paint, &props, NULL); | 1334 SkAutoGlyphCache autoCache(paint, &props, nullptr); |
1335 SkGlyphCache* cache = autoCache.getCache(); | 1335 SkGlyphCache* cache = autoCache.getCache(); |
1336 // If fLastGlyphID isn't set (because there is not fFontInfo), look it up. | 1336 // If fLastGlyphID isn't set (because there is not fFontInfo), look it up. |
1337 if (lastGlyphID() == 0) { | 1337 if (lastGlyphID() == 0) { |
1338 setLastGlyphID(cache->getGlyphCount() - 1); | 1338 setLastGlyphID(cache->getGlyphCount() - 1); |
1339 } | 1339 } |
1340 | 1340 |
1341 adjustGlyphRangeForSingleByteEncoding(glyphID); | 1341 adjustGlyphRangeForSingleByteEncoding(glyphID); |
1342 | 1342 |
1343 insertName("Subtype", "Type3"); | 1343 insertName("Subtype", "Type3"); |
1344 // Flip about the x-axis and scale by 1/1000. | 1344 // Flip about the x-axis and scale by 1/1000. |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1387 | 1387 |
1388 this->insertObject("CharProcs", charProcs.detach()); | 1388 this->insertObject("CharProcs", charProcs.detach()); |
1389 this->insertObject("Encoding", encoding.detach()); | 1389 this->insertObject("Encoding", encoding.detach()); |
1390 | 1390 |
1391 this->insertObject("FontBBox", makeFontBBox(bbox, 1000)); | 1391 this->insertObject("FontBBox", makeFontBBox(bbox, 1000)); |
1392 this->insertInt("FirstChar", 1); | 1392 this->insertInt("FirstChar", 1); |
1393 this->insertInt("LastChar", lastGlyphID() - firstGlyphID() + 1); | 1393 this->insertInt("LastChar", lastGlyphID() - firstGlyphID() + 1); |
1394 this->insertObject("Widths", widthArray.detach()); | 1394 this->insertObject("Widths", widthArray.detach()); |
1395 this->insertName("CIDToGIDMap", "Identity"); | 1395 this->insertName("CIDToGIDMap", "Identity"); |
1396 | 1396 |
1397 this->populateToUnicodeTable(NULL); | 1397 this->populateToUnicodeTable(nullptr); |
1398 return true; | 1398 return true; |
1399 } | 1399 } |
1400 | 1400 |
1401 SkPDFFont::Match SkPDFFont::IsMatch(SkPDFFont* existingFont, | 1401 SkPDFFont::Match SkPDFFont::IsMatch(SkPDFFont* existingFont, |
1402 uint32_t existingFontID, | 1402 uint32_t existingFontID, |
1403 uint16_t existingGlyphID, | 1403 uint16_t existingGlyphID, |
1404 uint32_t searchFontID, | 1404 uint32_t searchFontID, |
1405 uint16_t searchGlyphID) { | 1405 uint16_t searchGlyphID) { |
1406 if (existingFontID != searchFontID) { | 1406 if (existingFontID != searchFontID) { |
1407 return SkPDFFont::kNot_Match; | 1407 return SkPDFFont::kNot_Match; |
1408 } | 1408 } |
1409 if (existingGlyphID == 0 || searchGlyphID == 0) { | 1409 if (existingGlyphID == 0 || searchGlyphID == 0) { |
1410 return SkPDFFont::kExact_Match; | 1410 return SkPDFFont::kExact_Match; |
1411 } | 1411 } |
1412 if (existingFont != NULL) { | 1412 if (existingFont != nullptr) { |
1413 return (existingFont->fFirstGlyphID <= searchGlyphID && | 1413 return (existingFont->fFirstGlyphID <= searchGlyphID && |
1414 searchGlyphID <= existingFont->fLastGlyphID) | 1414 searchGlyphID <= existingFont->fLastGlyphID) |
1415 ? SkPDFFont::kExact_Match | 1415 ? SkPDFFont::kExact_Match |
1416 : SkPDFFont::kRelated_Match; | 1416 : SkPDFFont::kRelated_Match; |
1417 } | 1417 } |
1418 return (existingGlyphID == searchGlyphID) ? SkPDFFont::kExact_Match | 1418 return (existingGlyphID == searchGlyphID) ? SkPDFFont::kExact_Match |
1419 : SkPDFFont::kRelated_Match; | 1419 : SkPDFFont::kRelated_Match; |
1420 } | 1420 } |
OLD | NEW |