YSTest: Font.cpp 源文件

YSTest PreAlpha_b800_20170810 The YSLib Test Project

- 首页
- 相关页面
- 模块
- 命名空间
- 类
- 文件

- 文件列表
- 文件成员

Font.cpp
浏览该文件的文档.
1 /*
2 © 2009-2016 FrankHB.
3
4 This file is part of the YSLib project, and may only be used,
5 modified, and distributed under the terms of the YSLib project
6 license, LICENSE.TXT. By continuing to use, modify, or distribute
7 this file you indicate that you have read the license and
8 understand and accept it fully.
9 */
10
28 #include "Helper/YModules.h"
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
34 #include <algorithm> // for std::for_each;
35 #include <ft2build.h>
36 #include FT_FREETYPE_H
37 #include FT_CACHE_H
38 #include FT_SIZES_H
39 #include FT_BITMAP_H
40 //#include FT_GLYPH_H
41 //#include FT_OUTLINE_H
42 //#include FT_SYNTHESIS_H
43 #if defined(FT_CONFIG_OPTION_OLD_INTERNALS) \
44 && (FREETYPE_MAJOR * 10000 + FREETYPE_MINOR * 100 + FREETYPE_PATCH >= 20500)
45 # define YF_Impl_Use_FT_Internal 1
46 # include <freetype/internal/internal.h> // for FreeType internal macros;
47 # include FT_INTERNAL_TRUETYPE_TYPES_H // for TT_Face, TT_FaceRec_;
48 #endif
49
50 using namespace ystdex;
51 using namespace platform;
52
53 namespace YSLib
54 {
55
56 using namespace IO;
57
58 namespace Drawing
59 {
60
62
63 static_assert(std::is_same<FontException::FontError, ::FT_Error>(),
64 "Invalid type found.");
65 static_assert(std::is_same<CharBitmap::BufferType, ::FT_Byte*>(),
66 "Invalid type found.");
67 static_assert(int(CharBitmap::None) == ::FT_PIXEL_MODE_NONE && int(
68 CharBitmap::Mono) == ::FT_PIXEL_MODE_MONO && int(CharBitmap::Gray)
69 == ::FT_PIXEL_MODE_GRAY && int(CharBitmap::Gray2) == ::FT_PIXEL_MODE_GRAY2
70 && int(CharBitmap::Gray4) == ::FT_PIXEL_MODE_GRAY4 && int(CharBitmap::LCD)
71 == ::FT_PIXEL_MODE_LCD && int(CharBitmap::LCD_V) == ::FT_PIXEL_MODE_LCD_V,
72 "Incompatible format found.");
73 static_assert(std::is_same<CharBitmap::ScaleType, ::FT_Byte>(),
74 "Invalid type found.");
75 static_assert(std::is_same<CharBitmap::SignedScaleType, ::FT_Char>(),
76 "Invalid type found.");
78
79
80 ImplDeDtor(FontException)
81
82
83 namespace
85 {
86
88 ::FT_Error
89 N_SetPixelSizes(::FT_FaceRec& face, ::FT_UInt s) ynothrow
90 {
91 ::FT_Size_RequestRec req{FT_SIZE_REQUEST_TYPE_NOMINAL, ::FT_Long(s << 6),
92 ::FT_Long(s << 6), 0, 0};
93
94 return ::FT_Request_Size(&face, &req);
95 }
96
101 ::FT_Matrix italic_matrix{0x10000L, 0x0366AL, 0x0000L, 0x10000L};
102
103 } // unnamed namespace;
104
105
106 NativeFontSize::NativeFontSize(::FT_FaceRec& face, FontSize s)
107 : size()
108 {
109 if(const auto err = ::FT_New_Size(&face, &size))
110 throw FontException(err, "Native font size creation failed.");
111 Activate();
112 if(const auto err = N_SetPixelSizes(face, s))
113 throw FontException(err, "Native font setting size failed.");
114 }
115 NativeFontSize::NativeFontSize(NativeFontSize&& ns) ynothrow
116 : size(ns.size)
117 {
118 ns.size = {};
119 }
120 NativeFontSize::~NativeFontSize()
121 {
122 ::FT_Done_Size(size);
123 }
124
125 ::FT_SizeRec&
126 NativeFontSize::GetSizeRec() const
127 {
128 if(YB_UNLIKELY(!size))
129 throw LoggedEvent("Invalid native size found.", Critical);
130 return *size;
131 }
132
133 void
134 NativeFontSize::Activate() const
135 {
136 Deref(Deref(size).face).size = size;
137 }
138
139
140 FontFamily::FontFamily(const FamilyName& name)
141 : family_name(name), mFaces()
142 {}
143
144 void
145 FontFamily::operator+=(Typeface& face)
146 {
147 mFaces.emplace(face.GetStyleName(), face);
148 }
149
150 bool
151 FontFamily::operator-=(Typeface& face) ynothrow
152 {
153 return mFaces.erase(face.GetStyleName()) != 0;
154 }
155
156 observer_ptr<Typeface>
157 FontFamily::GetTypefacePtr(FontStyle fs) const
158 {
159 const auto p(GetTypefacePtr(FetchName(fs)));
160
161 return p ? p : (fs == FontStyle::Regular ? nullptr
162 : GetTypefacePtr("Regular"));
163 }
164 observer_ptr<Typeface>
165 FontFamily::GetTypefacePtr(const StyleName& style_name) const
166 {
167 // TODO: Blocked. Use %string_view as argument using C++14 heterogeneous
168 // %find template.
169 const auto i(mFaces.find(style_name));
170
171 return (i == mFaces.cend()) ? nullptr : make_observer(&i->second.get());
172 }
173 Typeface&
174 FontFamily::GetTypefaceRef(FontStyle fs) const
175 {
176 if(const auto p = GetTypefacePtr(fs))
177 return *p;
178 throw LoggedEvent("No matching face found.", Critical);
179 }
180 Typeface&
181 FontFamily::GetTypefaceRef(const StyleName& style_name) const
182 {
183 if(const auto p = GetTypefacePtr(style_name))
184 return *p;
185 throw LoggedEvent("No matching face found.", Critical);
186 }
187
188
189 Typeface::SmallBitmapData::SmallBitmapData(::FT_GlyphSlot slot, FontStyle style)
190 {
191 if(slot && slot->format == FT_GLYPH_FORMAT_BITMAP)
192 {
193 auto& bitmap(slot->bitmap);
194
195 if(bool(style & FontStyle::Bold))
196 {
197 const auto library(slot->library);
198 const auto face(slot->face);
199 ::FT_Pos xstr(FT_MulFix(face->units_per_EM,
200 face->size->metrics.y_scale) / 24 & ~63), ystr(xstr);
201
202 if(xstr == 0)
203 xstr = 1 << 6;
204 if(::FT_GlyphSlot_Own_Bitmap(slot) == FT_Err_Ok
205 && ::FT_Bitmap_Embolden(library, &bitmap, xstr, ystr)
206 == FT_Err_Ok)
207 {
208 if(slot->advance.x)
209 slot->advance.x += xstr;
210 if(slot->advance.y)
211 slot->advance.y += ystr;
212 {
213 auto& metrics(slot->metrics);
214
215 yunseq(metrics.width += xstr, metrics.height += ystr,
216 metrics.horiAdvance += xstr,
217 metrics.vertAdvance += ystr);
218 }
219 slot->bitmap_top += ::FT_Int(ystr >> 6);
220 }
221 }
222
223 const ::FT_Pos xadv((slot->advance.x + 32) >> 6),
224 yadv((slot->advance.y + 32) >> 6);
225
226 #define YSL_Impl_SB_CheckChar(d) (::FT_Int(::FT_Char(d)) == ::FT_Int(d))
227 #define YSL_Impl_SB_CheckByte(d) (::FT_Int(::FT_Byte(d)) == ::FT_Int(d))
228 if(YSL_Impl_SB_CheckByte(bitmap.rows)
229 && YSL_Impl_SB_CheckByte(bitmap.width)
230 && YSL_Impl_SB_CheckChar(bitmap.pitch)
231 && YSL_Impl_SB_CheckChar(slot->bitmap_left)
232 && YSL_Impl_SB_CheckChar(slot->bitmap_top)
233 && YSL_Impl_SB_CheckChar(xadv) && YSL_Impl_SB_CheckChar(yadv))
234 {
235 yunseq(
236 width = byte(bitmap.width),
237 height = byte(bitmap.rows),
238 left = static_cast<signed char>(slot->bitmap_left),
239 top = static_cast<signed char>(slot->bitmap_top),
240 format = byte(bitmap.pixel_mode),
241 max_grays = byte(bitmap.num_grays - 1),
242 pitch = static_cast<signed char>(bitmap.pitch),
243 xadvance = static_cast<signed char>(xadv),
244 yadvance = static_cast<signed char>(yadv),
245 buffer = bitmap.buffer
246 );
247 bitmap.buffer = {};
248 // XXX: Moving instead of copying should be safe if the library
249 // memory handlers are not customized.
250 // NOTE: Be cautious for DLLs. For documented default behavior, see:
251 // http://www.freetype.org/freetype2/docs/design/design-4.html.
252 return;
253 }
254 #undef YSL_Impl_SB_CheckChar
255 #undef YSL_Impl_SB_CheckByte
256 }
257 }
258 Typeface::SmallBitmapData::SmallBitmapData(SmallBitmapData&& sbit_dat)
259 : width(sbit_dat.width), height(sbit_dat.height), left(sbit_dat.left),
260 top(sbit_dat.top), format(sbit_dat.format), max_grays(sbit_dat.width),
261 pitch(sbit_dat.pitch), xadvance(sbit_dat.xadvance),
262 yadvance(sbit_dat.yadvance), buffer(sbit_dat.buffer)
263 {
264 sbit_dat.buffer = {};
265 }
266 Typeface::SmallBitmapData::~SmallBitmapData()
267 {
268 // NOTE: See constructor.
269 std::free(buffer);
270 }
271
272
273 Typeface::Typeface(FontCache& cache, const FontPath& path, std::uint32_t i)
274 // XXX: Conversion to 'long' might be implementation-defined.
275 : face_index(long(i)), cmap_index(-1), style_name(),
276 ref([&, this]{
277 if(YB_UNLIKELY(ystdex::exists(cache.mFaces, path)))
278 throw LoggedEvent("Duplicate typeface found.", Critical);
279
280 ::FT_Face face;
281 auto error(::FT_New_Face(cache.library, path.c_str(), face_index,
282 &face));
283
284 if(YB_LIKELY(!error))
285 if(YB_LIKELY(!(error = ::FT_Select_Charmap(face,
286 FT_ENCODING_UNICODE)) && face))
287 cmap_index = face->charmap
288 ? ::FT_Get_Charmap_Index(face->charmap) : 0;
289 if(YB_UNLIKELY(error))
290 throw LoggedEvent(ystdex::sfmt("Face loading failed"
291 " with face request error: %08x\n.", error), Critical);
292 return pair<lref<FontFamily>, lref<::FT_FaceRec_>>(
293 cache.LookupFamily(face->family_name), *face);
294 }()), bitmap_cache(2047U), glyph_index_cache()
295 {
296 // FIXME: This should be exception, but not assertion for malformed fonts.
297 YAssert(::FT_UInt(cmap_index) < ::FT_UInt(ref.second.get().num_charmaps),
298 "Invalid CMap index found.");
299 style_name = ref.second.get().style_name;
300 ref.first.get() += *this;
301 }
302 Typeface::~Typeface()
303 {
304 size_cache.clear();
305 glyph_index_cache.clear();
306 bitmap_cache.clear();
307 ref.first.get() -= *this;
308
309 const auto face(&ref.second.get());
310
311 #if YF_Impl_Use_FT_Internal
312 YAssert(Deref(face).internal->refcount == 1,
313 "Invalid face reference count found.");
314 // XXX: Hack for using %ttmtx.c and %sfobjs.c of FreeType 2.4.11.
315 if(FT_IS_SFNT(face))
316 {
317 const auto ttface(reinterpret_cast<::TT_Face>(face));
318
319 // NOTE: See %Typeface::SmallBitmapData::SmallBitmapData.
320 // NOTE: %sfnt_done_face in "sfobjs.c" still releases vertical metrics.
321 std::free(ttface->horizontal.long_metrics),
322 std::free(ttface->horizontal.short_metrics);
323 }
324 #endif
325 ::FT_Done_Face(face);
326 }
327
328 Typeface::SmallBitmapData&
329 Typeface::LookupBitmap(const Typeface::BitmapKey& key) const
330 {
331 return ystdex::cache_lookup(bitmap_cache, key, [&]{
332 LookupSize(key.Size).Activate();
333 ::FT_Set_Transform(&ref.second.get(),
334 bool(key.Style & FontStyle::Italic) ? &italic_matrix : nullptr, {});
335
336 return SmallBitmapData(::FT_Load_Glyph(&ref.second.get(),
337 key.GlyphIndex, std::int32_t(key.Flags | FT_LOAD_RENDER)) == 0
338 ? ref.second.get().glyph : nullptr, key.Style);
339 });
340 }
341
342 ::FT_UInt
343 Typeface::LookupGlyphIndex(char32_t c) const
344 {
345 auto i(glyph_index_cache.find(c));
346
347 if(i == glyph_index_cache.end())
348 {
349 if(cmap_index > 0)
350 ::FT_Set_Charmap(&ref.second.get(),
351 ref.second.get().charmaps[cmap_index]);
352
353 const auto pr(glyph_index_cache.emplace(c, ::FT_Get_Char_Index(
354 &ref.second.get(), ::FT_ULong(c))));
355
356 if(YB_UNLIKELY(!pr.second))
357 throw LoggedEvent("Glyph index cache insertion failed.", Alert);
358 i = pr.first;
359 }
360 return i->second;
361 }
362
363 NativeFontSize&
364 Typeface::LookupSize(FontSize s) const
365 {
366 auto i(size_cache.find(s));
367
368 if(i == size_cache.end())
369 {
370 const auto pr(size_cache.emplace(s, NativeFontSize(ref.second, s)));
371
372 if(YB_UNLIKELY(!pr.second))
373 throw LoggedEvent("Bitmap cache insertion failed.", Alert);
374 i = pr.first;
375 }
376 return i->second;
377 }
378
379
380 const Typeface&
381 FetchDefaultTypeface()
382 {
383 if(const auto p = FetchDefaultFontCache().GetDefaultTypefacePtr())
384 return *p;
385 throw LoggedEvent("Null default font face pointer found.", Critical);
386 }
387
388
389 FontCache::FontCache(size_t /*cache_size*/)
390 : pDefaultFace()
391 {
392 ::FT_Error error;
393
394 if(YB_LIKELY((error = ::FT_Init_FreeType(&library)) == 0))
395 YTraceDe(Informative, "FreeType library instance initialized.");
396 else
397 // TODO: More precise error message.
398 throw LoggedEvent(
399 ystdex::sfmt("Font init failed: %08x\n;", error).c_str(), Alert);
400 }
401 FontCache::~FontCache()
402 {
403 mFaces.clear();
404 mFamilies.clear();
405 ::FT_Done_FreeType(library);
406 }
407
408 observer_ptr<const FontFamily>
409 FontCache::GetFontFamilyPtr(const FamilyName& family_name) const
410 {
411 // TODO: Blocked. Use %string_view as argument using C++14 heterogeneous
412 // %find template.
413 const auto i(mFamilies.find(family_name));
414
415 return (i == mFamilies.cend()) ? nullptr : make_observer(i->second.get());
416 }
417
418 observer_ptr<const Typeface>
419 FontCache::GetDefaultTypefacePtr() const
420 {
421 // NOTE: Guaranteed to be not null for default typeface in default cache.
422 // XXX: Exceptions during initialization?
423 // XXX: Use %common_type?
424 return pDefaultFace ? observer_ptr<const Typeface>(pDefaultFace)
425 : FetchDefaultFontCache().GetDefaultTypefacePtr();
426 }
427 observer_ptr<const Typeface>
428 FontCache::GetTypefacePtr(const FamilyName& family_name,
429 const StyleName& style_name) const
430 {
431 return ystdex::call_value_or([&](const FontFamily& f){
432 return f.GetTypefacePtr(style_name);
433 }, GetFontFamilyPtr(family_name));
434 }
435
436 void
437 FontCache::Add(const FontPath& path, unique_ptr<Typeface> face)
438 {
439 mFaces.emplace(path, std::move(face));
440 }
441
442 size_t
443 FontCache::LoadTypefaces(const FontPath& path)
444 {
445 if(ufexists(path.c_str()) && !IO::VerifyDirectory(path))
446 {
447 ::FT_Face face(nullptr);
448
449 // TODO: Log.
450 if(::FT_New_Face(library, path.c_str(), -1, &face) != 0)
451 return 0;
452
453 const auto face_num(face->num_faces);
454
455 ::FT_Done_Face(face);
456 YTraceDe(Informative, "Loaded faces num '%ld' from path '%s'.",
457 face_num, path.c_str());
458 if(face_num < 0)
459 return 0;
460 for(long i(0); i < face_num; ++i)
461 // XXX: Conversion to 'long' might be implementation-defined.
462 TryExpr(
463 Add(path, make_unique<Typeface>(*this, path, std::uint32_t(i))))
464 CatchExpr(..., YTraceDe(Warning, "Failed loading face of path"
465 " '%s', index '%ld'.", path.c_str(), i))
466 return size_t(face_num);
467 }
468 return 0;
469 }
470
471 FontFamily&
472 FontCache::LookupFamily(const FamilyName& name)
473 {
474 auto& p_ff(mFamilies[name]);
475
476 if(!p_ff)
477 TryExpr(p_ff.reset(new FontFamily(name)))
478 catch(...)
479 {
480 mFamilies.erase(name);
481 throw;
482 }
483 return *p_ff;
484 }
485
486 void
487 FontCache::InitializeDefaultTypeface()
488 {
489 if(YB_LIKELY(!(pDefaultFace || mFaces.empty())))
490 pDefaultFace = make_observer(mFaces.cbegin()->second.get());
491 }
492
493
494 Font::Font(const FontFamily& family, const FontSize size, FontStyle fs)
495 : typeface(family.GetTypefaceRef(fs)), font_size(size), style(fs)
496 {}
497
498 std::int8_t
499 Font::GetAdvance(char32_t c, CharBitmap sbit) const
500 {
501 if(!sbit)
502 sbit = GetGlyph(c, FT_LOAD_DEFAULT);
503 return YB_LIKELY(sbit) ? sbit.GetXAdvance() : 0;
504 }
505 std::int8_t
506 Font::GetAscender() const
507 {
508 return GetInternalInfo().ascender >> 6;
509 }
510 std::int8_t
511 Font::GetDescender() const
512 {
513 return GetInternalInfo().descender >> 6;
514 }
515 CharBitmap
516 Font::GetGlyph(char32_t c, unsigned flags) const
517 {
518 static_assert((FT_LOAD_RENDER | FT_LOAD_TARGET_NORMAL) == 4L,
519 "Invalid default argument found.");
520 const auto& face(GetTypeface());
521
522 return &face.LookupBitmap(Typeface::BitmapKey{flags,
523 face.LookupGlyphIndex(c), font_size, style});
524 }
525 FontSize
526 Font::GetHeight() const ynothrow
527 {
528 return GetInternalInfo().height >> 6;
529 }
530 ::FT_Size_Metrics
531 Font::GetInternalInfo() const
532 {
533 return GetTypeface().LookupSize(GetSize()).GetSizeRec().metrics;
534 }
535
536 void
537 Font::SetSize(FontSize s)
538 {
539 if(IsInClosedInterval(s, MinimalSize, MaximalSize))
540 font_size = s;
541 }
542 bool
543 Font::SetStyle(FontStyle fs)
544 {
545 auto p(GetFontFamily().GetTypefacePtr(fs));
546
547 if(p)
548 {
549 yunseq(typeface = ystdex::ref(*p), style = fs);
550 return true;
551 }
552 return {};
553 }
554
555 } // namespace Drawing;
556
557 } // namespace YSLib;
558
YSLib::Drawing::Typeface::SmallBitmapData::xadvance
signed char xadvance
Definition: Font.h:292
YTraceDe
#define YTraceDe(...)
YCLib 默认调试跟踪。
Definition: Debug.h:313
YSLib::Drawing::FetchName
FetchName
Definition: Font.h:116
YSLib::Drawing::Typeface::SmallBitmapData::max_grays
byte max_grays
Definition: Font.h:290
YSLib::Drawing::Font::GetDescender
std::int8_t GetDescender() const
取降部。
Definition: Font.cpp:511
YSLib::Drawing::Typeface
字型。
Definition: Font.h:244
YSLib::Drawing::FontCache::InitializeDefaultTypeface
void InitializeDefaultTypeface()
初始化默认字型。
Definition: Font.cpp:487
YSLib::Drawing::Font::SetStyle
bool SetStyle(FontStyle)
设置样式。
Definition: Font.cpp:543
YSLib::Drawing::FontCache::Add
void Add(const FontPath &, unique_ptr< Typeface >)
向字型组添加字体路径和字型对象的映射。
Definition: Font.cpp:437
FT_FaceRec
::FT_FaceRec_ FT_FaceRec
Definition: Font.h:48
platform::Descriptions::Alert
Definition: YCommon.h:164
YSLib::Drawing::FontCache::library
::FT_Library library
库实例。
Definition: Font.h:492
YSLib::Drawing::buffer
The boundary is out of the buffer
Definition: YDraw.h:118
YSLib::Drawing::Font::font_size
FontSize font_size
Definition: Font.h:593
YSLib::Drawing::FontFamily::FontFamily
FontFamily(const FamilyName &)
构造：使用指定名称。
Definition: Font.cpp:140
YSLib
YSLib 命名空间。
Definition: AndroidHost.h:45
YSLib::Drawing::Typeface::SmallBitmapData::top
signed char top
Definition: Font.h:289
YSLib::Drawing::FontFamily::GetTypefacePtr
observer_ptr< Typeface > GetTypefacePtr(const StyleName &) const
取指定样式名称的字型指针。
Definition: Font.cpp:157
YSLib::FetchDefaultFontCache
YF_API Drawing::FontCache & FetchDefaultFontCache()
取默认字体缓存。 字体缓存初始化失败。
Definition: Initialization.cpp:530
ystdex::make_observer
observer_ptr< _type > make_observer(_type *p)
Definition: pointer.hpp:326
platform
默认平台命名空间。
Definition: Container.h:47
platform::Deref
yconstfn auto Deref(_type &&p) -> decltype(*p)
断言并解引用非空指针。
Definition: Debug.h:451
YSLib::Drawing::Font::GetHeight
FontSize GetHeight() const ynothrow
取字体对应的字符高度。
Definition: Font.cpp:526
YSLib::Drawing::FontCache
字体缓存。
Definition: Font.h:460
platform::size_t
YF_API size_t
Definition: FileIO.h:1353
YSLib::Drawing::Font::MinimalSize
static yconstexpr const FontSize MinimalSize
Definition: Font.h:587
YSLib::Drawing::FontCache::GetTypefacePtr
observer_ptr< const Typeface > GetTypefacePtr(const FamilyName &, const StyleName &) const
取指定名称的字型指针。
Definition: Font.cpp:428
YSLib::Drawing::NativeFontSize::GetSizeRec
::FT_SizeRec & GetSizeRec() const
Definition: Font.cpp:126
CHRLib::f
f(d, s)
YSLib::Drawing::NativeFontSize
字体异常。
Definition: Font.h:156
YSLib::Drawing::Font::typeface
lref< Typeface > typeface
Definition: Font.h:591
ystdex::call_value_or
auto call_value_or(_func f, _type &&p) -> decay_t< decltype(f(*std::forward< decltype(p)>(p)))>
调用非空值或取默认值。
Definition: deref_op.hpp:140
YSLib::Drawing::FamilyName
string FamilyName
字型家族名称。
Definition: Font.h:83
YSLib::Drawing::FontCache::GetFontFamilyPtr
const FamilyMap mFamilies observer_ptr< const FontFamily > GetFontFamilyPtr(const FamilyName &) const
取指定名称的字型家族指针。
Definition: Font.cpp:409
YSLib::Drawing::NativeFontSize::Activate
void Activate() const
激活当前大小。
Definition: Font.cpp:134
platform::bool
std::FILE *fp bool
Definition: FileIO.h:1280
YSLib::Drawing::FontCache::GetDefaultTypefacePtr
observer_ptr< const Typeface > GetDefaultTypefacePtr() const
取默认字型指针。 异常中立：初始化时发生的异常。
Definition: Font.cpp:419
YSLib::Drawing::FontCache::LoadTypefaces
size_t LoadTypefaces(const FontPath &)
从字体文件组中载入字型信息。
Definition: Font.cpp:443
YB_UNLIKELY
#define YB_UNLIKELY(_expr)
分支预测提示。
Definition: ydef.h:464
NPL::c_str
YF_API const char src c_str())) YF_API void InstallDirectory(const string &
安装目录：复制目录树。
Definition: Dependency.h:131
FT_GlyphSlot
::FT_GlyphSlotRec_ * FT_GlyphSlot
Definition: Font.h:50
YSLib::LoggedEvent
记录日志的异常事件类。
Definition: YException.h:50
YSLib::Drawing::Typeface::glyph_index_cache
unordered_map< char32_t, unsigned > glyph_index_cache
Definition: Font.h:315
YSLib::IsInClosedInterval
YB_STATELESS bool IsInClosedInterval(_type i, _type b) ynothrow
判断 i 是否在闭区间 [_type(0), b] 中。
Definition: YCoreUtilities.h:110
platform::KeyCategory::None
表示未分配或保留的键。
Definition: Keys.h:101
YSLib::Drawing::Typeface::SmallBitmapData::yadvance
signed char yadvance
Definition: Font.h:292
platform::KeyCodes::DS::L
Definition: Keys.h:227
YSLib::YAssert
YAssert(!(v< Deref(a)),"Value less than lower bound found.")
yunseq
#define yunseq
无序列依赖表达式组求值。
Definition: ydef.h:1022
YSLib::Drawing::Font::GetTypeface
const FontFamily GetTypeface()) DefGetter(const ynothrow
YSLib::Drawing::Typeface::BitmapKey::GlyphIndex
unsigned GlyphIndex
Definition: Font.h:259
YSLib::Drawing::Font::style
FontStyle style
字体样式。
Definition: Font.h:598
YSLib::Drawing::FontFamily::mFaces
FaceMap mFaces
字型组索引类型。
Definition: Font.h:196
ystdex::lref
左值引用包装。
Definition: ref.hpp:74
FT_SizeRec
::FT_SizeRec_ FT_SizeRec
Definition: Font.h:46
YSLib::Drawing::Typeface::BitmapKey::Size
FontSize Size
Definition: Font.h:260
TryExpr
#define TryExpr(...)
指定表达式在 try 块中求值。
Definition: YBaseMacro.h:120
YSLib::Drawing::Typeface::SmallBitmapData::left
signed char left
Definition: Font.h:289
YSLib::IO::VerifyDirectory
bool VerifyDirectory(const char *path)
Definition: YSLib/Service/FileSystem.cpp:95
YSLib::Drawing::FetchDefaultTypeface
YF_API const Typeface & FetchDefaultTypeface()
取默认字型引用。
Definition: Font.cpp:381
YSLib::Drawing::Typeface::cmap_index
int cmap_index
Definition: Font.h:307
CatchExpr
#define CatchExpr(_ex,...)
指定表达式作为异常处理器。
Definition: YBaseMacro.h:129
YSLib::Drawing::FontStyle::Bold
粗体。
YSLib::Drawing::FontFamily::GetTypefaceRef
Typeface & GetTypefaceRef(FontStyle) const
Definition: Font.cpp:174
ynothrow
#define ynothrow
YSLib 无异常抛出保证：若支持 noexcept 关键字， 指定特定的 noexcept 异常规范。
Definition: ydef.h:766
YSLib::Drawing::StyleName
string StyleName
字型样式名称。
Definition: Font.h:88
ystdex::cache_lookup
auto cache_lookup(_tMap &cache, const _tKey &key, _func init, _tParams &&...args) -> decltype((cache.begin() ->second))
以指定的关键字查找作为缓存的无序关联容器， 若没有找到使用指定的可调用对象和参数初始化内容。 ...
Definition: cache.hpp:369
CHRLib::s
_tDst const _tSrc * s
Definition: CharacterProcessing.h:140
YSLib::Drawing::Typeface::SmallBitmapData::~SmallBitmapData
~SmallBitmapData()
Definition: Font.cpp:266
ystdex::exists
bool exists(const _tCon &con, const _tKey &key)
判断指定的容器中存在指定的键。
Definition: container.hpp:681
ystdex::sfmt
auto sfmt(const _tChar *fmt,...) -> decltype(vsfmt(fmt, std::declval< std::va_list >()))
以 C 标准输出格式的输出 std::basic_string 实例的对象。
Definition: string.hpp:1200
IO
ystdex
特性测试宏。
Definition: ydef.h:822
YSLib::Drawing::NativeFontSize::NativeFontSize
NativeFontSize(::FT_FaceRec &, FontSize)
Definition: Font.cpp:106
platform::Descriptions::Critical
Definition: YCommon.h:165
YSLib::i
return i
Definition: YCoreUtilities.h:176
YSLib::Drawing::NativeFontSize::size
::FT_Size size
Definition: Font.h:159
YSLib::Drawing::Typeface::LookupBitmap
SmallBitmapData & LookupBitmap(const BitmapKey &) const
Definition: Font.cpp:329
YSLib::Drawing::FontCache::mFaces
FaceMap mFaces
字型映射。
Definition: Font.h:499
YSLib::Drawing::FontCache::pDefaultFace
observer_ptr< Typeface > pDefaultFace
默认字型指针。
Definition: Font.h:506
YSLib::Drawing::Typeface::LookupGlyphIndex
unsigned LookupGlyphIndex(char32_t) const
Definition: Font.cpp:343
YSLib::Drawing::Typeface::BitmapKey
Definition: Font.h:254
Drawing
YSLib::Drawing::CharBitmap
字符位图。
Definition: Font.h:383
YSLib::Drawing::Typeface::bitmap_cache
ystdex::used_list_cache< BitmapKey, SmallBitmapData, BitmapKeyHash > bitmap_cache
Definition: Font.h:313
YSLib::Drawing::Typeface::SmallBitmapData::height
byte height
Definition: Font.h:288
ystdex::path
一般路径模板。
Definition: path.hpp:123
YSLib::Drawing::Font::MaximalSize
static yconstexpr const FontSize MaximalSize
Definition: Font.h:587
YSLib::ynothrow
YB_PURE const _type size_t n ynothrow
Definition: YCoreUtilities.h:168
YSLib::Drawing::FontStyle::Italic
斜体。
YSLib::Drawing::Typeface::face_index
long face_index
Definition: Font.h:305
YSLib::Drawing::FontCache::mFamilies
FamilyMap mFamilies
字型家族组索引。
Definition: Font.h:501
YSLib::Drawing::FontPath
string FontPath
字体文件路径。
Definition: Font.h:78
YSLib::Drawing::Typeface::ref
pair< lref< FontFamily >, lref<::FT_FaceRec_ > > ref
Definition: Font.h:310
YSLib::Drawing::FontStyle::Regular
常规字体。
YSLib::Drawing::Typeface::BitmapKey::Style
FontStyle Style
Definition: Font.h:262
YModules.h
YSLib::Drawing::FontCache::FontCache
FontCache(size_t=DefaultGlyphCacheSize)
构造：分配指定大小的字形缓存空间。
Definition: Font.cpp:389
YSLib::Drawing::FontSize
std::uint8_t FontSize
字体大小。
Definition: Font.h:73
YSLib::Drawing::FontFamily::operator+=
void operator+=(Typeface &)
向字型组和字型组索引添加字型对象。
Definition: Font.cpp:145
ystdex::byte
unsigned char byte
字节类型。
Definition: ydef.h:834
YSLib::Drawing::Typeface::SmallBitmapData::format
byte format
Definition: Font.h:290
YSLib::Drawing::Typeface::SmallBitmapData::buffer
byte * buffer
Definition: Font.h:293
platform::Descriptions::Warning
Definition: YCommon.h:167
YSL_Impl_SB_CheckByte
#define YSL_Impl_SB_CheckByte(d)
YSLib::Drawing::Typeface::SmallBitmapData::pitch
short pitch
Definition: Font.h:291
YSLib::Drawing::Font::GetAscender
bool(style &FontStyle::Strikeout)) std std::int8_t GetAscender() const
取跨距。
Definition: Font.h:632
YSLib::UI::name
yconstfn const string & name
Definition: Loader.h:130
platform::Descriptions::Informative
Definition: YCommon.h:169
ImplDeDtor
#define ImplDeDtor(_t)
Definition: YBaseMacro.h:183
YSLib::Drawing::Typeface::~Typeface
~Typeface()
since build 461
Definition: Font.cpp:302
YSLib::Drawing::FontStyle
FontStyle
字体样式。
Definition: Font.h:95
YSLib::Drawing::Typeface::size_cache
unordered_map< FontSize, NativeFontSize > size_cache
Definition: Font.h:317
YSLib::Drawing::FontCache::~FontCache
~FontCache()
析构：释放空间。
Definition: Font.cpp:401
YSLib::Drawing::Font::Font
Font()
默认构造：使用默认字型家族、大小和样式的字体对象。
Definition: Font.h:605
YSL_Impl_SB_CheckChar
#define YSL_Impl_SB_CheckChar(d)
FT_Size_Metrics
FT_Size_Metrics_ FT_Size_Metrics
Definition: Font.h:54
platform::ufexists
bool ufexists(const char *filename) ynothrowv
Definition: FileIO.cpp:948
YSLib::Drawing::char32_t
tr TextRegion &tr char32_t
Definition: TextLayout.h:92
YSLib::Drawing::NativeFontSize::~NativeFontSize
~NativeFontSize()
Definition: Font.cpp:120
ystdex::size
auto size(const _tRange &c) -> decltype(c.size())
类容器访问。
Definition: range.hpp:233
YSLib::Drawing::Typeface::Typeface
Typeface(FontCache &, const FontPath &, std::uint32_t=0)
使用字体缓存引用在指定字体文件路径读取指定索引的字型并构造对象。
Definition: Font.cpp:273
YB_LIKELY
#define YB_LIKELY(_expr)
Definition: ydef.h:463
YSLib::Drawing::Typeface::SmallBitmapData
Definition: Font.h:278
YSLib::Drawing::Typeface::SmallBitmapData::SmallBitmapData
SmallBitmapData(::FT_GlyphSlot, FontStyle)
Definition: Font.cpp:189
YSLib::Drawing::Typeface::BitmapKey::Flags
unsigned Flags
Definition: Font.h:257
ystdex::ref
lref< _type > ref(_type &t)
构造引用包装。
Definition: ref.hpp:132
YSLib::Drawing::FontFamily::operator-=
bool operator-=(Typeface &) ynothrow
从字型组和字型组索引中移除指定字型对象。
Definition: Font.cpp:151
YSLib::Consoles::Gray
Definition: YConsole.h:60
YSLib::Drawing::Typeface::SmallBitmapData::width
byte width
Definition: Font.h:288
YSLib::Drawing::FontFamily
字型家族。
Definition: Font.h:185
YSLib::Drawing::c
The boundary is out of the const Graphics const Rect const Point const Point Color c const Rect const Rect Color c
Definition: YDraw.h:174
YSLib::Drawing::FontCache::LookupFamily
FontFamily & LookupFamily(const FamilyName &)
在索引中查找字型家族。
Definition: Font.cpp:472
CHRLib::p
const auto p(d)
YSLib::Drawing::Typeface::LookupSize
NativeFontSize & LookupSize(FontSize) const
since build 420
Definition: Font.cpp:364