size_t SkGPipeCanvas::getInProcessTypefaces(const SkRefCntSet& typefaceSet, TypefaceBuffer* buffer) { // When in-process, we simply write out the typeface pointers. size_t size = typefaceSet.count() * sizeof(SkTypeface*); buffer->reset(size); typefaceSet.copyToArray(reinterpret_cast<SkRefCnt**>(buffer->get())); return size; }
void SkPictureData::WriteTypefaces(SkWStream* stream, const SkRefCntSet& rec) { int count = rec.count(); write_tag_size(stream, SK_PICT_TYPEFACE_TAG, count); SkAutoSTMalloc<16, SkTypeface*> storage(count); SkTypeface** array = (SkTypeface**)storage.get(); rec.copyToArray((SkRefCnt**)array); for (int i = 0; i < count; i++) { array[i]->serialize(stream); } }
uint32_t SkGPipeCanvas::getTypefaceID(SkTypeface* face) { uint32_t id = 0; // 0 means default/null typeface if (face) { id = fTypefaceSet.find(face); if (0 == id) { id = fTypefaceSet.add(face); size_t size = writeTypeface(nullptr, face); if (this->needOpBytes(size)) { this->writeOp(kDef_Typeface_DrawOp); writeTypeface(&fWriter, face); } } } return id; }
size_t SkGPipeCanvas::getCrossProcessTypefaces(const SkRefCntSet& typefaceSet, TypefaceBuffer* buffer) { // For cross-process we use typeface IDs. size_t size = typefaceSet.count() * sizeof(uint32_t); buffer->reset(size); uint32_t* idBuffer = reinterpret_cast<uint32_t*>(buffer->get()); SkRefCntSet::Iter iter(typefaceSet); int i = 0; for (void* setPtr = iter.next(); setPtr; setPtr = iter.next()) { idBuffer[i++] = this->getTypefaceID(reinterpret_cast<SkTypeface*>(setPtr)); } SkASSERT(i == typefaceSet.count()); return size; }
void SkPictureData::WriteTypefaces(SkWStream* stream, const SkRefCntSet& rec) { int count = rec.count(); write_tag_size(stream, SK_PICT_TYPEFACE_TAG, count); SkAutoSTMalloc<16, SkTypeface*> storage(count); SkTypeface** array = (SkTypeface**)storage.get(); rec.copyToArray((SkRefCnt**)array); for (int i = 0; i < count; i++) { #ifdef SK_PICTURE_FORCE_FONT_EMBEDDING array[i]->serializeForcingEmbedding(stream); #else // TODO: if (embedFonts) { array[i]->serializeForcingEmbedding(stream) } else array[i]->serialize(stream); #endif } }