読者です 読者をやめる 読者になる 読者になる

のねのBlog

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

getHbFontLocked

     50 // An RAII wrapper for hb_blob_t
     51 class HbBlob {
     52 public:
     53     // Takes ownership of hb_blob_t object, caller is no longer
     54     // responsible for calling hb_blob_destroy().
     55     HbBlob(hb_blob_t* blob) : mBlob(blob) {
     56     }
     57 
     58     ~HbBlob() {
     59         hb_blob_destroy(mBlob);
     60     }
     61 
     62     const uint8_t* get() const {
     63         const char* data = hb_blob_get_data(mBlob, nullptr);
     64         return reinterpret_cast<const uint8_t*>(data);
     65     }
     66 
     67     size_t size() const {
     68         unsigned int length = 0;
     69         hb_blob_get_data(mBlob, &length);
     70         return (size_t)length;
     71     }
     72 
     73 private:
     74     hb_blob_t* mBlob;
     75 };

Cross Reference: /frameworks/minikin/libs/minikin/MinikinInternal.h

     53 struct hb_blob_t {
     54   hb_object_header_t header;
     55   ASSERT_POD ();
     56 
     57   bool               immutable;
     58 
     59   const char        *data;
     60   unsigned int       length;
     61   hb_memory_mode_t   mode;
     62 
     63   void              *user_data;
     64   hb_destroy_func_t  destroy;
     65 };

Cross Reference: /external/harfbuzz_ng/src/hb-blob.cc

    172 const SparseBitSet* FontFamily::getCoverage() {
    173     if (!mCoverageValid) {
    174         const FontStyle defaultStyle;
    175         MinikinFont* typeface = getClosestMatch(defaultStyle).font; 
 
    176         const uint32_t cmapTag = MinikinFont::MakeTag('c', 'm', 'a', 'p');

    177         HbBlob cmapTable(getFontTable(typeface, cmapTag));

    178         if (cmapTable.get() == nullptr) {
    179             ALOGE("Could not get cmap table size!\n");
    180             // Note: This means we will retry on the next call to getCoverage, as we can't store
    181             //       the failure. This is fine, as we assume this doesn't really happen in practice.
    182             return nullptr;
    183         }

    184         // TODO: Error check?
    185         CmapCoverage::getCoverage(mCoverage, cmapTable.get(), cmapTable.size(), &mHasVSTable);
    186 #ifdef VERBOSE_DEBUG
    187         ALOGD("font coverage length=%d, first ch=%x\n", mCoverage.length(),
    188                 mCoverage.nextSetBit(0));
    189 #endif
    190         mCoverageValid = true;
    191     }
    192     return &mCoverage;
    193 }

Cross Reference: /frameworks/minikin/libs/minikin/FontFamily.cpp

    129 FakedFont FontFamily::getClosestMatch(FontStyle style) const {
    130     const Font* bestFont = NULL;
    131     int bestMatch = 0;
    132     for (size_t i = 0; i < mFonts.size(); i++) {
    133         const Font& font = mFonts[i];
    134         int match = computeMatch(font.style, style);
    135         if (i == 0 || match < bestMatch) { <==値が小さいほどマッチしている。
    136             bestFont = &font;
    137             bestMatch = match;
    138         }
    139     }
    140     FakedFont result;
    141     if (bestFont == NULL) {
    142         result.font = NULL; <==mFonts.size()が、0のときなのかな?
                                           mFonts.size()が、1なら、何かfontに値がはいるはず。
    143     } else {
    144         result.font = bestFont->typeface;
    145         result.fakery = computeFakery(style, bestFont->style);
    146     }
    147     return result;
    148 }

Cross Reference: /frameworks/minikin/libs/minikin/FontFamily.cpp


     82 hb_blob_t* getFontTable(MinikinFont* minikinFont, uint32_t tag) {
     83     assertMinikinLocked();

     84     hb_font_t* font = getHbFontLocked(minikinFont);
     85     hb_face_t* face = hb_font_get_face(font);
     86     hb_blob_t* blob = hb_face_reference_table(face, tag);
     87     hb_font_destroy(font);

     88     return blob;
     89 }

Cross Reference: /frameworks/minikin/libs/minikin/MinikinInternal.cpp

    100 // Returns a new reference to a hb_font_t object, caller is
    101 // responsible for calling hb_font_destroy() on it.
    102 hb_font_t* getHbFontLocked(MinikinFont* minikinFont) {
    103     assertMinikinLocked();
    104     // TODO: get rid of nullFaceFont
    105     static hb_font_t* nullFaceFont = nullptr;
    106     if (minikinFont == nullptr) {
    107         if (nullFaceFont == nullptr) {
    108             nullFaceFont = hb_font_create(nullptr);
    109         }
    110         return hb_font_reference(nullFaceFont);
    111     }
    112 
    113     HbFontCache* fontCache = getFontCacheLocked();
    114     const int32_t fontId = minikinFont->GetUniqueId();
    115     hb_font_t* font = fontCache->get(fontId);
    116     if (font != nullptr) {
    117         return hb_font_reference(font);
    118     }
    119 
    120     hb_face_t* face;
    121     const void* buf = minikinFont->GetFontData();
    122     if (buf == nullptr) {
    123         face = hb_face_create_for_tables(referenceTable, minikinFont, nullptr);
    124     } else {
    125         size_t size = minikinFont->GetFontSize();
    126         hb_blob_t* blob = hb_blob_create(reinterpret_cast<const char*>(buf), size,
    127             HB_MEMORY_MODE_READONLY, nullptr, nullptr);
    128         face = hb_face_create(blob, minikinFont->GetFontIndex());
    129         hb_blob_destroy(blob);
    130     }
    131     hb_font_t* parent_font = hb_font_create(face);
    132     hb_ot_font_set_funcs(parent_font);
    133 
    134     unsigned int upem = hb_face_get_upem(face);
    135     hb_font_set_scale(parent_font, upem, upem);
    136 
    137     font = hb_font_create_sub_font(parent_font);
    138     hb_font_destroy(parent_font);
    139     hb_face_destroy(face);
    140     fontCache->put(fontId, font);
    141     return hb_font_reference(font);

Cross Reference: /frameworks/minikin/libs/minikin/HbFontCache.cpp

   1121 hb_font_t *
   1122 hb_font_create (hb_face_t *face)
   1123 {
   1124   hb_font_t *font;
   1125 
   1126   if (unlikely (!face))
   1127     face = hb_face_get_empty ();
   1128   if (!(font = hb_object_create<hb_font_t> ()))
   1129     return hb_font_get_empty ();
   1130 
   1131   hb_face_make_immutable (face);
   1132   font->parent = hb_font_get_empty ();
   1133   font->face = hb_face_reference (face);
   1134   font->klass = hb_font_funcs_get_empty ();
   1135 
   1136   font->x_scale = font->y_scale = hb_face_get_upem (face);
   1137 
   1138   return font;
   1139 }

Cross Reference: /external/harfbuzz_ng/src/hb-font.cc