| 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 634 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 645 void SkPDFGlyphSet::set(const uint16_t* glyphIDs, int numGlyphs) { | 645 void SkPDFGlyphSet::set(const uint16_t* glyphIDs, int numGlyphs) { |
| 646 for (int i = 0; i < numGlyphs; ++i) { | 646 for (int i = 0; i < numGlyphs; ++i) { |
| 647 fBitSet.setBit(glyphIDs[i], true); | 647 fBitSet.setBit(glyphIDs[i], true); |
| 648 } | 648 } |
| 649 } | 649 } |
| 650 | 650 |
| 651 bool SkPDFGlyphSet::has(uint16_t glyphID) const { | 651 bool SkPDFGlyphSet::has(uint16_t glyphID) const { |
| 652 return fBitSet.isBitSet(glyphID); | 652 return fBitSet.isBitSet(glyphID); |
| 653 } | 653 } |
| 654 | 654 |
| 655 void SkPDFGlyphSet::merge(const SkPDFGlyphSet& usage) { | |
| 656 fBitSet.orBits(usage.fBitSet); | |
| 657 } | |
| 658 | |
| 659 void SkPDFGlyphSet::exportTo(SkTDArray<unsigned int>* glyphIDs) const { | 655 void SkPDFGlyphSet::exportTo(SkTDArray<unsigned int>* glyphIDs) const { |
| 660 fBitSet.exportTo(glyphIDs); | 656 fBitSet.exportTo(glyphIDs); |
| 661 } | 657 } |
| 662 | 658 |
| 663 /////////////////////////////////////////////////////////////////////////////// | 659 /////////////////////////////////////////////////////////////////////////////// |
| 664 // class SkPDFGlyphSetMap | 660 // class SkPDFGlyphSetMap |
| 665 /////////////////////////////////////////////////////////////////////////////// | 661 /////////////////////////////////////////////////////////////////////////////// |
| 666 SkPDFGlyphSetMap::FontGlyphSetPair::FontGlyphSetPair(SkPDFFont* font, | |
| 667 SkPDFGlyphSet* glyphSet) | |
| 668 : fFont(font), | |
| 669 fGlyphSet(glyphSet) { | |
| 670 } | |
| 671 | 662 |
| 672 SkPDFGlyphSetMap::SkPDFGlyphSetMap() { | 663 SkPDFGlyphSetMap::SkPDFGlyphSetMap() {} |
| 673 } | |
| 674 | 664 |
| 675 SkPDFGlyphSetMap::~SkPDFGlyphSetMap() { | 665 SkPDFGlyphSetMap::~SkPDFGlyphSetMap() { |
| 676 reset(); | |
| 677 } | |
| 678 | |
| 679 void SkPDFGlyphSetMap::merge(const SkPDFGlyphSetMap& usage) { | |
| 680 for (int i = 0; i < usage.fMap.count(); ++i) { | |
| 681 SkPDFGlyphSet* myUsage = getGlyphSetForFont(usage.fMap[i].fFont); | |
| 682 myUsage->merge(*(usage.fMap[i].fGlyphSet)); | |
| 683 } | |
| 684 } | |
| 685 | |
| 686 void SkPDFGlyphSetMap::reset() { | |
| 687 for (int i = 0; i < fMap.count(); ++i) { | |
| 688 delete fMap[i].fGlyphSet; // Should not be nullptr. | |
| 689 } | |
| 690 fMap.reset(); | 666 fMap.reset(); |
| 691 } | 667 } |
| 692 | 668 |
| 693 void SkPDFGlyphSetMap::noteGlyphUsage(SkPDFFont* font, const uint16_t* glyphIDs, | 669 void SkPDFGlyphSetMap::noteGlyphUsage(SkPDFFont* font, const uint16_t* glyphIDs, |
| 694 int numGlyphs) { | 670 int numGlyphs) { |
| 695 SkPDFGlyphSet* subset = getGlyphSetForFont(font); | 671 SkPDFGlyphSet* subset = getGlyphSetForFont(font); |
| 696 if (subset) { | 672 if (subset) { |
| 697 subset->set(glyphIDs, numGlyphs); | 673 subset->set(glyphIDs, numGlyphs); |
| 698 } | 674 } |
| 699 } | 675 } |
| 700 | 676 |
| 701 SkPDFGlyphSet* SkPDFGlyphSetMap::getGlyphSetForFont(SkPDFFont* font) { | 677 SkPDFGlyphSet* SkPDFGlyphSetMap::getGlyphSetForFont(SkPDFFont* font) { |
| 702 int index = fMap.count(); | 678 int index = fMap.count(); |
| 703 for (int i = 0; i < index; ++i) { | 679 for (int i = 0; i < index; ++i) { |
| 704 if (fMap[i].fFont == font) { | 680 if (fMap[i].fFont == font) { |
| 705 return fMap[i].fGlyphSet; | 681 return &fMap[i].fGlyphSet; |
| 706 } | 682 } |
| 707 } | 683 } |
| 708 fMap.append(); | 684 FontGlyphSetPair& pair = fMap.push_back(); |
| 709 index = fMap.count() - 1; | 685 pair.fFont = font; |
| 710 fMap[index].fFont = font; | 686 return &pair.fGlyphSet; |
| 711 fMap[index].fGlyphSet = new SkPDFGlyphSet(); | |
| 712 return fMap[index].fGlyphSet; | |
| 713 } | 687 } |
| 714 | 688 |
| 715 /////////////////////////////////////////////////////////////////////////////// | 689 /////////////////////////////////////////////////////////////////////////////// |
| 716 // class SkPDFFont | 690 // class SkPDFFont |
| 717 /////////////////////////////////////////////////////////////////////////////// | 691 /////////////////////////////////////////////////////////////////////////////// |
| 718 | 692 |
| 719 /* Font subset design: It would be nice to be able to subset fonts | 693 /* Font subset design: It would be nice to be able to subset fonts |
| 720 * (particularly type 3 fonts), but it's a lot of work and not a priority. | 694 * (particularly type 3 fonts), but it's a lot of work and not a priority. |
| 721 * | 695 * |
| 722 * Resources are canonicalized and uniqueified by pointer so there has to be | 696 * Resources are canonicalized and uniqueified by pointer so there has to be |
| (...skipping 712 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1435 } | 1409 } |
| 1436 return *canon->fCanEmbedTypeface.set(id, canEmbed); | 1410 return *canon->fCanEmbedTypeface.set(id, canEmbed); |
| 1437 } | 1411 } |
| 1438 | 1412 |
| 1439 void SkPDFFont::drop() { | 1413 void SkPDFFont::drop() { |
| 1440 fTypeface = nullptr; | 1414 fTypeface = nullptr; |
| 1441 fFontInfo = nullptr; | 1415 fFontInfo = nullptr; |
| 1442 fDescriptor = nullptr; | 1416 fDescriptor = nullptr; |
| 1443 this->SkPDFDict::drop(); | 1417 this->SkPDFDict::drop(); |
| 1444 } | 1418 } |
| OLD | NEW |