のねのBlog

パソコンの問題や、ソフトウェアの開発で起きた問題など書いていきます。よろしくお願いします^^。

writeTypeface

     58 static size_t writeTypeface(SkWriter32* writer, SkTypeface* typeface) {
     59     SkASSERT(typeface);
     60     SkDynamicMemoryWStream stream;
     61     typeface->serialize(&stream);
     62     size_t size = stream.getOffset();
     63     if (writer) {
     64         writer->write32(size);
     65         SkAutoDataUnref data(stream.copyToData());
     66         writer->write(data.data(), size);
     67     }
     68     return 4 + size;
     69 }
     87 void SkTypeface::serialize(SkWStream* stream) const {
     88     SkFontHost::Serialize(this, stream);
     89 }
    832 void SkFontHost::Serialize(const SkTypeface* face, SkWStream* stream) {
    833     // lookup and record if the font is custom (i.e. not a system font)
    834     bool isCustomFont = !((FamilyTypeface*)face)->isSysFont();
    835     stream->writeBool(isCustomFont);
    836 
    837     if (isCustomFont) {
    838         SkStream* fontStream = ((FamilyTypeface*)face)->openStream();
    839 
    840         // store the length of the custom font
    841         uint32_t len = fontStream->getLength();
    842         stream->write32(len);
    843 
    844         // store the entire font in the serialized stream
    845         void* fontData = malloc(len);
    846 
    847         fontStream->read(fontData, len);
    848         stream->write(fontData, len);
    849 
    850         fontStream->unref();
    851         free(fontData);
    852 //      SkDebugf("--- fonthost custom serialize %d %d\n", face->style(), len);
    853 
    854     } else {
    855         const char* name = ((FamilyTypeface*)face)->getUniqueString();
    856 
    857         stream->write8((uint8_t)face->style());
    858 
    859         if (NULL == name || 0 == *name) {
    860             stream->writePackedUInt(0);
    861 //          SkDebugf("--- fonthost serialize null\n");
    862         } else {
    863             uint32_t len = strlen(name);
    864             stream->writePackedUInt(len);
    865             stream->write(name, len);
    866 //          SkDebugf("--- fonthost serialize <%s> %d\n", name, face->style());
    867         }
    868     }
    869 }