29 #include YFM_YSLib_Adaptor_Font
30 #include YFM_YSLib_Core_YApplication
31 #include YFM_YSLib_Service_FileSystem
32 #include YFM_Helper_Initialization
33 #include YFM_YCLib_Debug
40 #include <internal/internal.h>
41 #include FT_INTERNAL_OBJECTS_H // for FT_Face_InternalRec_;
42 #include FT_INTERNAL_TRUETYPE_TYPES_H // for TT_Face, TT_FaceRec_;
44 using namespace ystdex;
45 using namespace platform;
63 ::FT_Size_RequestRec req{FT_SIZE_REQUEST_TYPE_NOMINAL, ::FT_Long(
s << 6),
64 ::FT_Long(
s << 6), 0, 0};
66 return ::FT_Request_Size(&
face, &req);
73 ::FT_Matrix italic_matrix{0x10000L, 0x0366AL, 0x0000L, 0x10000L};
81 if(
const auto err = ::FT_New_Size(&face, &
size))
84 if(
const auto err = N_SetPixelSizes(face, s))
124 mFaces.insert(make_pair(face.GetStyleName(), &
face));
130 return mFaces.erase(face.GetStyleName()) != 0;
144 const auto i(
mFaces.find(style_name));
146 return (i ==
mFaces.cend()) ?
nullptr : i->second;
170 if(slot && slot->format == FT_GLYPH_FORMAT_BITMAP)
172 auto&
bitmap(slot->bitmap);
176 const auto library(slot->library);
177 const auto face(slot->face);
178 ::FT_Pos xstr(FT_MulFix(
face->units_per_EM,
179 face->size->metrics.y_scale) / 24 & ~63), ystr(xstr);
183 if(::FT_GlyphSlot_Own_Bitmap(slot) == FT_Err_Ok
184 && ::FT_Bitmap_Embolden(library, &
bitmap, xstr, ystr)
188 slot->advance.x += xstr;
190 slot->advance.y += ystr;
192 auto& metrics(slot->metrics);
194 yunseq(metrics.width += xstr, metrics.height += ystr,
195 metrics.horiAdvance += xstr,
196 metrics.vertAdvance += ystr);
198 slot->bitmap_top += ::FT_Int(ystr >> 6);
202 const ::FT_Pos xadvance((slot->advance.x + 32) >> 6),
203 yadvance((slot->advance.y + 32) >> 6);
206 #define SBIT_CHECK_CHAR(d) (temp = ::FT_Char(d), temp == d)
207 #define SBIT_CHECK_BYTE(d) (temp = ::FT_Byte(d), temp == d)
215 ::FT_Char(slot->bitmap_left), ::FT_Char(slot->bitmap_top),
216 ::FT_Byte(
bitmap.pixel_mode), ::FT_Byte(
bitmap.num_grays - 1),
217 ::FT_Char(
bitmap.pitch), ::FT_Char(xadvance),
218 ::FT_Char(yadvance),
bitmap.buffer};
226 #undef SBIT_CHECK_CHAR
227 #undef SBIT_CHECK_BYTE
229 sbit = {255, 0, 0, 0, 0, 0, 0, 0, 0,
nullptr};
232 : sbit(sbit_dat.sbit)
234 sbit_dat.sbit.buffer = {};
239 std::free(sbit.buffer);
254 FT_ENCODING_UNICODE)) && face))
255 cmap_index = face->charmap
256 ? ::FT_Get_Charmap_Index(face->charmap) : 0;
268 return pair<std::reference_wrapper<FontFamily>,
269 std::reference_wrapper<::FT_FaceRec_>>(*
p_ff.get(), *
face);
272 YAssert(::FT_UInt(cmap_index) < ::FT_UInt(ref.second.get().num_charmaps),
273 "Invalid CMap index found.");
274 style_name = ref.second.get().style_name;
275 ref.first.get() += *
this;
282 ref.first.get() -= *
this;
284 const auto face(&
ref.second.get());
287 YAssert(face->internal->refcount == 1,
288 "Invalid face reference count found.");
292 const auto ttface(reinterpret_cast<::TT_Face>(face));
296 std::free(ttface->horizontal.long_metrics),
297 std::free(ttface->horizontal.short_metrics);
299 ::FT_Done_Face(face);
319 ::FT_Set_Transform(&
ref.second.get(),
324 ?
ref.second.get().glyph :
nullptr, key.
Style);
336 ::FT_Set_Charmap(&
ref.second.get(),
340 &
ref.second.get(), ::FT_ULong(c))));
369 const Typeface*
const pDefaultTypeface(
374 return *pDefaultTypeface;
402 const auto i(
mFamilies.find(family_name));
404 return (i ==
mFamilies.cend()) ?
nullptr : i->second.get();
428 mFamilies.emplace(p_family->GetFamilyName(), std::move(p_family));
439 return mFamilies.erase(family.GetFamilyName()) != 0;
460 ::FT_Face
face(
nullptr);
462 if(::FT_New_Face(
library, path.c_str(), -1, &
face) != 0)
465 const auto face_num(face->num_faces);
467 ::FT_Done_Face(face);
471 const size_t face_n(face_num);
473 for(
size_t i(0); i < face_n; ++i)
494 : typeface(family.GetTypefaceRef(fs)), font_size(size), style(fs)
498 Font::GetAdvance(
ucs4_t c, ::FTC_SBit sbit)
const
501 return GetAdvance(
' ') << 2;
503 sbit = GetGlyph(c, FT_LOAD_DEFAULT);
505 return sbit->xadvance;
511 return GetInternalInfo().ascender >> 6;
514 Font::GetDescender()
const
516 return GetInternalInfo().descender >> 6;
519 Font::GetGlyph(
ucs4_t c, ::FT_UInt flags)
const
529 return GetInternalInfo().height >> 6;
532 Font::GetInternalInfo()
const
534 return GetTypeface().LookupSize(GetSize()).GetSizeRec().metrics;
546 auto p(GetFontFamily().GetTypefacePtr(fs));
s8 GetAscender() const
取升部。
void InitializeDefaultTypeface()
初始化默认字型。
FamilyMap mFamilies
字型家族组索引。
std::string FamilyName
字型家族名称。
void Activate() const
激活当前大小。
NativeFontSize & LookupSize(FontSize) const
since build 420
bool operator<(const Typeface &) const
比较:严格递增偏序关系。
static yconstexpr FontSize MinimalSize
#define SBIT_CHECK_BYTE(d)
NativeFontSize(::FT_FaceRec &, FontSize)
YF_API bool ufexists(const char *) ynothrow
判断指定 UTF-8 文件名的文件是否存在。
FontFamily(FontCache &, const FamilyName &)
使用字体缓存引用和名称构造字型家族。
::FT_UInt LookupGlyphIndex(ucs4_t) const
const FontFamily font_size::FT_UInt flags
#define SBIT_CHECK_CHAR(d)
Typeface * pDefaultFace
默认字型指针。
Typeface & GetTypefaceRef(FontStyle) const
GMRUCache< BitmapKey, SmallBitmapData, BitmapKeyHash > bitmap_cache
pair< std::reference_wrapper< FontFamily >, std::reference_wrapper<::FT_FaceRec_ > > ref
bool SetStyle(FontStyle)
设置样式。
const FontFamily GetTypeface()) DefGetter(const ynothrow
SmallBitmapData(::FT_GlyphSlot, FontStyle)
#define YB_UNLIKELY(expr)
分支预测提示。
sizeof(AlphaType)*GetAreaOf(GetSize())) using CompactPixmap void SetSize(const Size &) override
重新设置缓冲区大小。
#define yunseq
无序列依赖表达式组求值。
std::string StyleName
字型样式名称。
Typeface * GetTypefacePtr(const StyleName &) const
取指定样式名称的字型指针。
#define ynothrow
YSLib 无异常抛出保证:若支持 noexcept 关键字, 指定特定的 noexcept 异常规范。
yconstfn const string & name
YF_API Drawing::FontCache & FetchDefaultFontCache()
取默认字体缓存。
FontCache(size_t=DefaultGlyphCacheSize)
构造:分配指定大小的字形缓存空间。
bool operator-=(Typeface &)
从字型组和字型组索引中移除指定字型对象。
const FamilyMap mFamilies const FontFamily * GetFontFamilyPtr(const FamilyName &) const
< 取字型家族组索引。
#define YAssertNonnull(_expr)
YF_API const Typeface & FetchDefaultTypeface()
取默认字型引用。
std::reference_wrapper< Typeface > typeface
auto CacheLookup(_tMap &cache, const _tKey &key, _fCallable init, _tParams &&...args) -> decltype((cache.begin() ->second))
以指定的关键字查找作为缓存的无序关联容器, 若没有找到使用指定的可调用对象和参数初始化内容。 ...
auto error(::FT_New_Face(cache.library, Path.c_str(), face_index,&face))
Typeface(FontCache &, const FontPath &, u32=0)
使用字体缓存引用在指定字体文件路径读取指定索引的字型并构造对象。
void operator+=(Typeface &)
向字型组和字型组索引添加字型对象。
YF_API int yprintf(const char *,...)
调试模式 printf :显示控制台格式化输出 ,按键继续。
size_t LoadTypefaces(const FontPath &)
从字体文件组中载入字型信息。
bool operator==(const Typeface &) const
比较:相等关系。
static yconstexpr FontSize MaximalSize
std::string FontPath
字体文件路径。
unordered_map< FontSize, NativeFontSize > size_cache
Typeface::Typeface(FontCache &cache, const FontPath &path, u32 i)::FT_Face face
char32_t ucs4_t
UCS-4 字符类型。
~Typeface()
since build 461
bool exists(const _tCon &con, const _tKey &key)
判断指定的容器中存在指定的键。
std::basic_string< _tChar > sfmt(const _tChar *fmt,...)
以 C 标准输出格式的输出 std::basic_string 实例的对象。
FontSize GetHeight() const ynothrow
取字体对应的字符高度。
Font()
默认构造:使用默认字型家族、大小和样式的字体对象。
SmallBitmapData & LookupBitmap(const BitmapKey &) const
auto & p_ff(cache.mFamilies[family_name])
unordered_map< ucs4_t,::FT_UInt > glyph_index_cache
字型家族 (Typeface Family) 标识。
::FT_SizeRec & GetSizeRec() const
const Typeface * GetTypefacePtr(const FamilyName &, const StyleName &) const
取指定名称的字型指针。
bool operator-=(FontFamily &)
从字型家族组中移除指定字型对象。
#define YAssert(_expr, _msg)
void operator+=(unique_ptr< FontFamily >)
向字型家族组添加字型家族。
const Typeface * GetDefaultTypefacePtr() const
取默认字型指针。
void ClearContainers()
清除容器。