MinikinFont
100 class MinikinFont : public MinikinRefCounted { 101 public: 102 MinikinFont(int32_t uniqueId) : mUniqueId(uniqueId) {} 103 104 virtual ~MinikinFont(); 105 106 virtual float GetHorizontalAdvance(uint32_t glyph_id, 107 const MinikinPaint &paint) const = 0; 108 109 virtual void GetBounds(MinikinRect* bounds, uint32_t glyph_id, 110 const MinikinPaint &paint) const = 0; 111 112 virtual const void* GetTable(uint32_t tag, size_t* size, MinikinDestroyFunc* destroy) = 0; 113 114 // Override if font can provide access to raw data 115 virtual const void* GetFontData() const { 116 return nullptr; 117 } 118 119 // Override if font can provide access to raw data 120 virtual size_t GetFontSize() const { 121 return 0; 122 } 123 124 // Override if font can provide access to raw data. 125 // Returns index within OpenType collection 126 virtual int GetFontIndex() const { 127 return 0; 128 } 129 130 static uint32_t MakeTag(char c1, char c2, char c3, char c4) { 131 return ((uint32_t)c1 << 24) | ((uint32_t)c2 << 16) | 132 ((uint32_t)c3 << 8) | (uint32_t)c4; 133 } 134 135 int32_t GetUniqueId() const { return mUniqueId; } 136 private: 137 const int32_t mUniqueId; <==IDしかないのか。 138 };
Cross Reference: /frameworks/minikin/include/minikin/MinikinFont.h
28 class ANDROID_API MinikinFontSkia : public MinikinFont { 29 public: 30 // Note: this takes ownership of the reference (will unref on dtor) 31 explicit MinikinFontSkia(SkTypeface *typeface, const void* fontData, size_t fontSize, 32 int ttcIndex); 33 34 ~MinikinFontSkia(); 35 36 float GetHorizontalAdvance(uint32_t glyph_id, 37 const MinikinPaint &paint) const; 38 39 void GetBounds(MinikinRect* bounds, uint32_t glyph_id, 40 const MinikinPaint &paint) const; 41 42 const void* GetTable(uint32_t tag, size_t* size, MinikinDestroyFunc* destroy); 43 44 SkTypeface* GetSkTypeface() const; 45 46 // Access to underlying raw font bytes 47 const void* GetFontData() const; 48 size_t GetFontSize() const; 49 int GetFontIndex() const; 50 51 static uint32_t packPaintFlags(const SkPaint* paint); 52 static void unpackPaintFlags(SkPaint* paint, uint32_t paintFlags); 53 54 // set typeface and fake bold/italic parameters 55 static void populateSkPaint(SkPaint* paint, const MinikinFont* font, FontFakery fakery); 56 private: 57 SkTypeface* mTypeface; 58 59 // A raw pointer to the font data - it should be owned by some other object with 60 // lifetime at least as long as this object. 61 const void* mFontData; 62 size_t mFontSize; 63 int mTtcIndex; 64 };
Cross Reference: /frameworks/base/libs/hwui/hwui/MinikinSkia.h
MinikinFontSkiaを使っているところ、その1
56 static jboolean addSkTypeface( FontFamily* family, SkTypeface* face, const void* fontData, 57 size_t fontSize, int ttcIndex) { 58 MinikinFont* minikinFont = new MinikinFontSkia( face, fontData, fontSize, ttcIndex); 59 bool result = family->addFont(minikinFont); 60 minikinFont->Unref(); 61 return result; 62 }
Cross Reference: /frameworks/base/core/jni/android/graphics/FontFamily.cpp
MinikinFontSkiaを使っているところ、その2
128 static jboolean FontFamily_addFontWeightStyle(JNIEnv* env, jobject clazz, jlong familyPtr, 129 jobject font, jint ttcIndex, jobject listOfAxis, jint weight, jboolean isItalic) { 130 NPE_CHECK_RETURN_ZERO(env, font); 131 132 // Declare axis native type. 133 std::unique_ptr<SkFontMgr::FontParameters::Axis[]> skiaAxes; 134 int skiaAxesLength = 0; 135 if (listOfAxis) { 136 jint listSize = env->CallIntMethod(listOfAxis, gListClassInfo.mSize); 137 138 skiaAxes.reset(new SkFontMgr::FontParameters::Axis[listSize]); 139 skiaAxesLength = listSize; 140 for (jint i = 0; i < listSize; ++i) { 141 jobject axisObject = env->CallObjectMethod(listOfAxis, gListClassInfo.mGet, i); 142 if (!axisObject) { 143 skiaAxes[i].fTag = 0; 144 skiaAxes[i].fStyleValue = 0; 145 continue; 146 } 147 148 jint tag = env->GetIntField(axisObject, gAxisClassInfo.mTag); 149 jfloat stylevalue = env->GetFloatField(axisObject, gAxisClassInfo.mStyleValue); 150 skiaAxes[i].fTag = tag; 151 skiaAxes[i].fStyleValue = SkFloatToScalar(stylevalue); 152 } 153 } 154 155 const void* fontPtr = env->GetDirectBufferAddress(font); 156 if (fontPtr == NULL) { 157 ALOGE("addFont failed to create font, buffer invalid"); 158 return false; 159 } 160 jlong fontSize = env->GetDirectBufferCapacity(font); 161 if (fontSize < 0) { 162 ALOGE("addFont failed to create font, buffer size invalid"); 163 return false; 164 } 165 jobject fontRef = MakeGlobalRefOrDie(env, font); 166 SkAutoTUnref<SkData> data(SkData::NewWithProc(fontPtr, fontSize, 167 release_global_ref, reinterpret_cast<void*>(fontRef))); 168 std::unique_ptr<SkStreamAsset> fontData(new SkMemoryStream(data)); 169 170 SkFontMgr::FontParameters params; 171 params.setCollectionIndex(ttcIndex); 172 params.setAxes(skiaAxes.get(), skiaAxesLength); 173 174 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault()); 175 SkTypeface* face = fm->createFromStream(fontData.release(), params); 176 if (face == NULL) { 177 ALOGE("addFont failed to create font, invalid request"); 178 return false; 179 } 180 FontFamily* fontFamily = reinterpret_cast<FontFamily*>(familyPtr); 181 MinikinFont* minikinFont = new MinikinFontSkia( face, fontPtr, (size_t)fontSize, ttcIndex); 182 fontFamily->addFont(minikinFont, FontStyle(weight / 100, isItalic)); 183 minikinFont->Unref(); 184 return true; 185 }
Cross Reference: /frameworks/base/core/jni/android/graphics/FontFamily.cpp
96 struct hb_font_t { 97 hb_object_header_t header; 98 ASSERT_POD (); 99 100 hb_bool_t immutable; 101 102 hb_font_t *parent; 103 hb_face_t *face; 104 105 int x_scale; 106 int y_scale; 107 108 unsigned int x_ppem; 109 unsigned int y_ppem; 110 111 hb_font_funcs_t *klass; 112 void *user_data; 113 hb_destroy_func_t destroy; 114 115 struct hb_shaper_data_t shaper_data;
Cross Reference: /external/harfbuzz_ng/src/hb-font-private.hh