YSTest: Font.cpp 源文件

YSTest PreAlpha_b700_20160611 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 SBIT_CHECK_CHAR(d) (::FT_Int(::FT_Char(d)) == d)
227 #define SBIT_CHECK_BYTE(d) (::FT_Int(::FT_Byte(d)) == d)
228 if(SBIT_CHECK_BYTE(bitmap.rows) && SBIT_CHECK_BYTE(bitmap.width)
229 && SBIT_CHECK_CHAR(bitmap.pitch)
230 && SBIT_CHECK_CHAR(slot->bitmap_left)
231 && SBIT_CHECK_CHAR(slot->bitmap_top) && SBIT_CHECK_CHAR(xadv)
232 && SBIT_CHECK_CHAR(yadv))
233 {
234 yunseq(
235 width = byte(bitmap.width),
236 height = byte(bitmap.rows),
237 left = static_cast<signed char>(slot->bitmap_left),
238 top = static_cast<signed char>(slot->bitmap_top),
239 format = byte(bitmap.pixel_mode),
240 max_grays = byte(bitmap.num_grays - 1),
241 pitch = static_cast<signed char>(bitmap.pitch),
242 xadvance = static_cast<signed char>(xadv),
243 yadvance = static_cast<signed char>(yadv),
244 buffer = bitmap.buffer
245 );
246 bitmap.buffer = {};
247 // XXX: Moving instead of copying should be safe if the library
248 // memory handlers are not customized.
249 // NOTE: Be cautious for DLLs. For documented default behavior, see:
250 // http://www.freetype.org/freetype2/docs/design/design-4.html.
251 return;
252 }
253 #undef SBIT_CHECK_CHAR
254 #undef SBIT_CHECK_BYTE
255 }
256 }
257 Typeface::SmallBitmapData::SmallBitmapData(SmallBitmapData&& sbit_dat)
258 : width(sbit_dat.width), height(sbit_dat.height), left(sbit_dat.left),
259 top(sbit_dat.top), format(sbit_dat.format), max_grays(sbit_dat.width),
260 pitch(sbit_dat.pitch), xadvance(sbit_dat.xadvance),
261 yadvance(sbit_dat.yadvance), buffer(sbit_dat.buffer)
262 {
263 sbit_dat.buffer = {};
264 }
265 Typeface::SmallBitmapData::~SmallBitmapData()
266 {
267 // NOTE: See constructor.
268 std::free(buffer);
269 }
270
271
272 Typeface::Typeface(FontCache& cache, const FontPath& path, std::uint32_t i)
273 // XXX: Conversion to 'long' might be implementation-defined.
274 : face_index(long(i)), cmap_index(-1), style_name(),
275 ref([&, this]{
276 if(YB_UNLIKELY(ystdex::exists(cache.mFaces, path)))
277 throw LoggedEvent("Duplicate typeface found.", Critical);
278
279 ::FT_Face face;
280 auto error(::FT_New_Face(cache.library, path.c_str(), face_index,
281 &face));
282
283 if(YB_LIKELY(!error))
284 if(YB_LIKELY(!(error = ::FT_Select_Charmap(face,
285 FT_ENCODING_UNICODE)) && face))
286 cmap_index = face->charmap
287 ? ::FT_Get_Charmap_Index(face->charmap) : 0;
288 if(YB_UNLIKELY(error))
289 throw LoggedEvent(ystdex::sfmt("Face loading failed"
290 " with face request error: %08x\n.", error), Critical);
291 return pair<lref<FontFamily>, lref<::FT_FaceRec_>>(
292 cache.LookupFamily(face->family_name), *face);
293 }()), bitmap_cache(2047U), glyph_index_cache()
294 {
295 // FIXME: This should be exception, but not assertion for malformed fonts.
296 YAssert(::FT_UInt(cmap_index) < ::FT_UInt(ref.second.get().num_charmaps),
297 "Invalid CMap index found.");
298 style_name = ref.second.get().style_name;
299 ref.first.get() += *this;
300 }
301 Typeface::~Typeface()
302 {
303 size_cache.clear();
304 glyph_index_cache.clear();
305 bitmap_cache.clear();
306 ref.first.get() -= *this;
307
308 const auto face(&ref.second.get());
309
310 #if YF_Impl_Use_FT_Internal
311 YAssert(Deref(face).internal->refcount == 1,
312 "Invalid face reference count found.");
313 // XXX: Hack for using %ttmtx.c and %sfobjs.c of FreeType 2.4.11.
314 if(FT_IS_SFNT(face))
315 {
316 const auto ttface(reinterpret_cast<::TT_Face>(face));
317
318 // NOTE: See %Typeface::SmallBitmapData::SmallBitmapData.
319 // NOTE: %sfnt_done_face in "sfobjs.c" still releases vertical metrics.
320 std::free(ttface->horizontal.long_metrics),
321 std::free(ttface->horizontal.short_metrics);
322 }
323 #endif
324 ::FT_Done_Face(face);
325 }
326
327 Typeface::SmallBitmapData&
328 Typeface::LookupBitmap(const Typeface::BitmapKey& key) const
329 {
330 return ystdex::cache_lookup(bitmap_cache, key, [&]{
331 LookupSize(key.Size).Activate();
332 ::FT_Set_Transform(&ref.second.get(),
333 bool(key.Style & FontStyle::Italic) ? &italic_matrix : nullptr, {});
334
335 return SmallBitmapData(::FT_Load_Glyph(&ref.second.get(),
336 key.GlyphIndex, std::int32_t(key.Flags | FT_LOAD_RENDER)) == 0
337 ? ref.second.get().glyph : nullptr, key.Style);
338 });
339 }
340
341 ::FT_UInt
342 Typeface::LookupGlyphIndex(char32_t c) const
343 {
344 auto i(glyph_index_cache.find(c));
345
346 if(i == glyph_index_cache.end())
347 {
348 if(cmap_index > 0)
349 ::FT_Set_Charmap(&ref.second.get(),
350 ref.second.get().charmaps[cmap_index]);
351
352 const auto pr(glyph_index_cache.emplace(c, ::FT_Get_Char_Index(
353 &ref.second.get(), ::FT_ULong(c))));
354
355 if(YB_UNLIKELY(!pr.second))
356 throw LoggedEvent("Glyph index cache insertion failed.", Alert);
357 i = pr.first;
358 }
359 return i->second;
360 }
361
362 NativeFontSize&
363 Typeface::LookupSize(FontSize s) const
364 {
365 auto i(size_cache.find(s));
366
367 if(i == size_cache.end())
368 {
369 const auto pr(size_cache.emplace(s, NativeFontSize(ref.second, s)));
370
371 if(YB_UNLIKELY(!pr.second))
372 throw LoggedEvent("Bitmap cache insertion failed.", Alert);
373 i = pr.first;
374 }
375 return i->second;
376 }
377
378
379 const Typeface&
380 FetchDefaultTypeface()
381 {
382 if(const auto p = FetchDefaultFontCache().GetDefaultTypefacePtr())
383 return *p;
384 throw LoggedEvent("Null default font face pointer found.", Critical);
385 }
386
387
388 FontCache::FontCache(size_t /*cache_size*/)
389 : pDefaultFace()
390 {
391 ::FT_Error error;
392
393 if(YB_LIKELY((error = ::FT_Init_FreeType(&library)) == 0))
394 YTraceDe(Informative, "FreeType library instance initialized.");
395 else
396 // TODO: More precise error message.
397 throw LoggedEvent(
398 ystdex::sfmt("Font init failed: %08x\n;", error).c_str(), Alert);
399 }
400 FontCache::~FontCache()
401 {
402 mFaces.clear();
403 mFamilies.clear();
404 ::FT_Done_FreeType(library);
405 }
406
407 observer_ptr<const FontFamily>
408 FontCache::GetFontFamilyPtr(const FamilyName& family_name) const
409 {
410 // TODO: Blocked. Use %string_view as argument using C++14 heterogeneous
411 // %find template.
412 const auto i(mFamilies.find(family_name));
413
414 return (i == mFamilies.cend()) ? nullptr : make_observer(i->second.get());
415 }
416
417 observer_ptr<const Typeface>
418 FontCache::GetDefaultTypefacePtr() const
419 {
420 // NOTE: Guaranteed to be not null for default typeface in default cache.
421 // XXX: Exceptions during initialization?
422 // XXX: Use %common_type?
423 return pDefaultFace ? observer_ptr<const Typeface>(pDefaultFace)
424 : FetchDefaultFontCache().GetDefaultTypefacePtr();
425 }
426 observer_ptr<const Typeface>
427 FontCache::GetTypefacePtr(const FamilyName& family_name,
428 const StyleName& style_name) const
429 {
430 return ystdex::call_value_or<observer_ptr<Typeface>>(
431 [&](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
platform::p
while p p
Definition: YCLib/FileSystem.h:225
YSLib::Drawing::CharBitmap
字符位图。
Definition: Font.h:383
YSLib::Drawing::Font::GetDescender
std::int8_t GetDescender() const
取降部。
Definition: Font.cpp:511
YSLib::Drawing::Font::SetStyle
bool SetStyle(FontStyle)
设置样式。
Definition: Font.cpp:543
ystdex::sfmt
auto sfmt(const _tChar *fmt,...) -> decltype(vsfmt(fmt, std::declval< std::va_list >()))
以 C 标准输出格式的输出 std::basic_string 实例的对象。
Definition: string.hpp:1140
YSLib::Drawing::FontPath
string FontPath
字体文件路径。
Definition: Font.h:78
ynothrow
#define ynothrow
YSLib 无异常抛出保证：若支持 noexcept 关键字， 指定特定的 noexcept 异常规范。
Definition: ydef.h:740
YSLib::Drawing::Typeface::SmallBitmapData::height
byte height
Definition: Font.h:288
YSLib::Drawing::Font::typeface
lref< Typeface > typeface
Definition: Font.h:591
platform::Descriptions::Warning
Definition: YCommon.h:157
platform::Descriptions::Informative
Definition: YCommon.h:159
YSLib::Drawing::FontSize
std::uint8_t FontSize
字体大小。
Definition: Font.h:73
YSLib::Drawing::FontCache::pDefaultFace
observer_ptr< Typeface > pDefaultFace
默认字型指针。
Definition: Font.h:506
ImplDeDtor
#define ImplDeDtor(_t)
Definition: YBaseMacro.h:182
YSLib::Drawing::Typeface::SmallBitmapData::max_grays
byte max_grays
Definition: Font.h:290
YSLib::Drawing::Typeface::BitmapKey
Definition: Font.h:254
YSLib::Drawing::FontFamily::operator+=
void operator+=(Typeface &)
向字型组和字型组索引添加字型对象。
Definition: Font.cpp:145
YSLib::Drawing::FontCache::LookupFamily
FontFamily & LookupFamily(const FamilyName &)
在索引中查找字型家族。
Definition: Font.cpp:472
platform::KeyCategory::None
表示未分配或保留的键。
Definition: Keys.h:101
YSLib::FetchDefaultFontCache
YF_API Drawing::FontCache & FetchDefaultFontCache()
取默认字体缓存。 字体缓存初始化失败。
Definition: Initialization.cpp:493
platform::KeyCodes::DS::L
Definition: Keys.h:227
YSLib::Drawing::Typeface::~Typeface
~Typeface()
since build 461
Definition: Font.cpp:301
YSLib::Consoles::Gray
Definition: YConsole.h:60
YSLib::Drawing::FontCache
字体缓存。
Definition: Font.h:460
NPL::A1::name
ctx const string & name
Definition: NPLA1.h:248
YSLib::Drawing::Typeface::LookupGlyphIndex
unsigned LookupGlyphIndex(char32_t) const
Definition: Font.cpp:342
YSLib
YSLib 命名空间。
Definition: AndroidHost.h:45
YSLib::Drawing::Typeface::cmap_index
int cmap_index
Definition: Font.h:307
YSLib::Drawing::FontCache::GetTypefacePtr
observer_ptr< const Typeface > GetTypefacePtr(const FamilyName &, const StyleName &) const
取指定名称的字型指针。
Definition: Font.cpp:427
YSLib::Drawing::NativeFontSize::GetSizeRec
::FT_SizeRec & GetSizeRec() const
Definition: Font.cpp:126
CatchExpr
#define CatchExpr(_ex,...)
指定表达式作为异常处理器。
Definition: YBaseMacro.h:129
YSLib::LoggedEvent
记录日志的异常事件类。
Definition: YException.h:49
YSLib::Drawing::char32_t
tr TextRegion &tr char32_t
Definition: TextLayout.h:92
YSLib::Drawing::Typeface::LookupBitmap
SmallBitmapData & LookupBitmap(const BitmapKey &) const
Definition: Font.cpp:328
YSLib::Drawing::Typeface::SmallBitmapData::pitch
short pitch
Definition: Font.h:291
FT_GlyphSlot
::FT_GlyphSlotRec_ * FT_GlyphSlot
Definition: Font.h:50
YSLib::Drawing::Typeface::BitmapKey::GlyphIndex
unsigned GlyphIndex
Definition: Font.h:259
YSLib::IO::VerifyDirectory
VerifyDirectory
Definition: YSLib/Service/FileSystem.h:394
YSLib::Drawing::Typeface::LookupSize
NativeFontSize & LookupSize(FontSize) const
since build 420
Definition: Font.cpp:363
YSLib::Drawing::Typeface::face_index
long face_index
Definition: Font.h:305
YSLib::Drawing::Typeface::SmallBitmapData::width
byte width
Definition: Font.h:288
YSLib::Drawing::FontCache::mFaces
FaceMap mFaces
字型映射。
Definition: Font.h:499
platform::ufexists
bool ufexists(const char *filename) ynothrowv
Definition: FileIO.cpp:875
YSLib::Drawing::FontStyle
FontStyle
字体样式。
Definition: Font.h:95
ystdex::lref
左值引用包装。
Definition: ref.hpp:74
YSLib::Drawing::FontCache::GetFontFamilyPtr
const FamilyMap mFamilies observer_ptr< const FontFamily > GetFontFamilyPtr(const FamilyName &) const
取指定名称的字型家族指针。
Definition: Font.cpp:408
YSLib::size_t
name const ValueNode::Container const string &name ynothrow observer_ptr< ValueNode::Container > const string &name ynothrow observer_ptr< const ValueNode::Container > const string &name ynothrow size_t
Definition: ValueNode.h:639
YTraceDe
#define YTraceDe(...)
YCLib 默认调试跟踪。
Definition: Debug.h:305
YSLib::Drawing::Typeface::ref
pair< lref< FontFamily >, lref<::FT_FaceRec_ > > ref
Definition: Font.h:310
YSLib::Drawing::FontCache::GetDefaultTypefacePtr
observer_ptr< const Typeface > GetDefaultTypefacePtr() const
取默认字型指针。 异常中立：初始化时发生的异常。
Definition: Font.cpp:418
YSLib::ynothrow
YB_PURE const _type size_t n ynothrow
Definition: YCoreUtilities.h:168
YSLib::Drawing::FontCache::LoadTypefaces
size_t LoadTypefaces(const FontPath &)
从字体文件组中载入字型信息。
Definition: Font.cpp:443
YSLib::Drawing::Font::MaximalSize
static yconstexpr const FontSize MaximalSize
Definition: Font.h:587
ystdex::exists
bool exists(const _tCon &con, const _tKey &key)
判断指定的容器中存在指定的键。
Definition: container.hpp:677
YSLib::Drawing::NativeFontSize::size
::FT_Size size
Definition: Font.h:159
YSLib::Drawing::FetchName
FetchName
Definition: Font.h:116
YSLib::Drawing::Typeface::size_cache
unordered_map< FontSize, NativeFontSize > size_cache
Definition: Font.h:317
YB_UNLIKELY
#define YB_UNLIKELY(_expr)
分支预测提示。
Definition: ydef.h:438
YSLib::IsInClosedInterval
YB_STATELESS bool IsInClosedInterval(_type i, _type b) ynothrow
判断 i 是否在闭区间 [_type(0), b] 中。
Definition: YCoreUtilities.h:110
YSLib::Drawing::FontCache::InitializeDefaultTypeface
void InitializeDefaultTypeface()
初始化默认字型。
Definition: Font.cpp:487
YSLib::Drawing::Font::GetHeight
FontSize GetHeight() const ynothrow
取字体对应的字符高度。
Definition: Font.cpp:526
platform
默认平台命名空间。
Definition: Container.h:47
platform::Deref
yconstfn auto Deref(_type &&p) -> decltype(*p)
断言并解引用非空指针。
Definition: Debug.h:440
TryExpr
#define TryExpr(...)
指定表达式在 try 块中求值。
Definition: YBaseMacro.h:120
YSLib::Drawing::FontStyle::Bold
粗体。
YSLib::Drawing::Typeface::SmallBitmapData::xadvance
signed char xadvance
Definition: Font.h:292
YSLib::Drawing::FontCache::~FontCache
~FontCache()
析构：释放空间。
Definition: Font.cpp:400
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
ystdex::size
auto size(const _tRange &c) -> decltype(c.size())
类容器访问。
Definition: range.hpp:233
YSLib::Drawing::Typeface::glyph_index_cache
unordered_map< char32_t, unsigned > glyph_index_cache
Definition: Font.h:315
YSLib::YAssert
YAssert(!(v< Deref(a)),"Value less than lower bound found.")
YSLib::Drawing::FontStyle::Italic
斜体。
YSLib::Drawing::FontFamily::FontFamily
FontFamily(const FamilyName &)
构造：使用指定名称。
Definition: Font.cpp:140
yunseq
#define yunseq
无序列依赖表达式组求值。
Definition: ydef.h:996
ystdex::path
一般路径模板。
Definition: path.hpp:123
IO
ystdex
特性测试宏。
Definition: ydef.h:796
YSLib::Drawing::Font::GetAscender
bool(style &FontStyle::Strikeout)) std std::int8_t GetAscender() const
取跨距。
Definition: Font.h:632
YSLib::Drawing::FontCache::mFamilies
FamilyMap mFamilies
字型家族组索引。
Definition: Font.h:501
YSLib::Drawing::NativeFontSize::NativeFontSize
NativeFontSize(::FT_FaceRec &, FontSize)
Definition: Font.cpp:106
SBIT_CHECK_BYTE
#define SBIT_CHECK_BYTE(d)
YSLib::Drawing::FontFamily::operator-=
bool operator-=(Typeface &) ynothrow
从字型组和字型组索引中移除指定字型对象。
Definition: Font.cpp:151
YSLib::Drawing::Typeface::SmallBitmapData::format
byte format
Definition: Font.h:290
YSLib::Drawing::Typeface::Typeface
Typeface(FontCache &, const FontPath &, std::uint32_t=0)
使用字体缓存引用在指定字体文件路径读取指定索引的字型并构造对象。
Definition: Font.cpp:272
platform::Descriptions::Critical
Definition: YCommon.h:155
Drawing
YSLib::Drawing::FontCache::FontCache
FontCache(size_t=DefaultGlyphCacheSize)
构造：分配指定大小的字形缓存空间。
Definition: Font.cpp:388
YSLib::Drawing::Font::GetTypeface
const FontFamily GetTypeface()) DefGetter(const ynothrow
YSLib::Drawing::buffer
The boundary is out of the buffer
Definition: YDraw.h:118
YSLib::Drawing::Typeface::BitmapKey::Style
FontStyle Style
Definition: Font.h:262
YSLib::Drawing::Font::style
FontStyle style
字体样式。
Definition: Font.h:598
YSLib::i
return i
Definition: YCoreUtilities.h:176
YSLib::Drawing::FontFamily::mFaces
FaceMap mFaces
字型组索引类型。
Definition: Font.h:196
ystdex::byte
unsigned char byte
字节类型。
Definition: ydef.h:808
YSLib::Drawing::FontStyle::Regular
常规字体。
SBIT_CHECK_CHAR
#define SBIT_CHECK_CHAR(d)
YSLib::Drawing::NativeFontSize::Activate
void Activate() const
激活当前大小。
Definition: Font.cpp:134
FT_SizeRec
::FT_SizeRec_ FT_SizeRec
Definition: Font.h:46
YSLib::Drawing::NativeFontSize::~NativeFontSize
~NativeFontSize()
Definition: Font.cpp:120
YB_LIKELY
#define YB_LIKELY(_expr)
Definition: ydef.h:437
YSLib::Drawing::Typeface::SmallBitmapData::top
signed char top
Definition: Font.h:289
YSLib::Drawing::Typeface::SmallBitmapData::yadvance
signed char yadvance
Definition: Font.h:292
FT_FaceRec
::FT_FaceRec_ FT_FaceRec
Definition: Font.h:48
YModules.h
YSLib::Drawing::Typeface::BitmapKey::Size
FontSize Size
Definition: Font.h:260
NPL::c_str
YF_API const char src c_str())) YF_API void InstallDirectory(const string &
安装目录：复制目录树。
ystdex::cache_lookup
auto cache_lookup(_tMap &cache, const _tKey &key, _func init, _tParams &&...args) -> decltype((cache.begin() ->second))
以指定的关键字查找作为缓存的无序关联容器， 若没有找到使用指定的可调用对象和参数初始化内容。 ...
Definition: cache.hpp:369
FT_Size_Metrics
FT_Size_Metrics_ FT_Size_Metrics
Definition: Font.h:54
YSLib::Drawing::FamilyName
string FamilyName
字型家族名称。
Definition: Font.h:83
YSLib::Drawing::Font::Font
Font()
默认构造：使用默认字型家族、大小和样式的字体对象。
Definition: Font.h:605
YSLib::Drawing::Font::font_size
FontSize font_size
Definition: Font.h:593
ystdex::make_observer
observer_ptr< _type > make_observer(_type *p)
Definition: memory.hpp:1042
YSLib::Drawing::Typeface
字型。
Definition: Font.h:244
YSLib::Drawing::FontFamily::GetTypefacePtr
observer_ptr< Typeface > GetTypefacePtr(const StyleName &) const
取指定样式名称的字型指针。
Definition: Font.cpp:157
YSLib::Drawing::Typeface::SmallBitmapData
Definition: Font.h:278
YSLib::IO::f
const string &path const String &path _func f
Definition: YSLib/Service/FileSystem.h:430
YSLib::Drawing::FetchDefaultTypeface
YF_API const Typeface & FetchDefaultTypeface()
取默认字型引用。
Definition: Font.cpp:380
YSLib::Drawing::Typeface::BitmapKey::Flags
unsigned Flags
Definition: Font.h:257
YSLib::Drawing::Font::MinimalSize
static yconstexpr const FontSize MinimalSize
Definition: Font.h:587
YSLib::Drawing::FontFamily::GetTypefaceRef
Typeface & GetTypefaceRef(FontStyle) const
Definition: Font.cpp:174
YSLib::Drawing::FontCache::Add
void Add(const FontPath &, unique_ptr< Typeface >)
向字型组添加字体路径和字型对象的映射。
Definition: Font.cpp:437
YSLib::Drawing::NativeFontSize
字体异常。
Definition: Font.h:156
YSLib::Drawing::StyleName
string StyleName
字型样式名称。
Definition: Font.h:88
YSLib::Drawing::Typeface::SmallBitmapData::left
signed char left
Definition: Font.h:289
CHRLib::s
_tDst const _tSrc * s
Definition: CharacterProcessing.h:140
YSLib::Drawing::Typeface::SmallBitmapData::buffer
byte * buffer
Definition: Font.h:293
platform::bool
std::FILE *fp bool
Definition: FileIO.h:1187
YSLib::Drawing::Typeface::bitmap_cache
ystdex::used_list_cache< BitmapKey, SmallBitmapData, BitmapKeyHash > bitmap_cache
Definition: Font.h:313
YSLib::Drawing::FontCache::library
::FT_Library library
库实例。
Definition: Font.h:492
YSLib::Drawing::FontFamily
字型家族。
Definition: Font.h:185
YSLib::Drawing::Typeface::SmallBitmapData::SmallBitmapData
SmallBitmapData(::FT_GlyphSlot, FontStyle)
Definition: Font.cpp:189
YSLib::Drawing::Typeface::SmallBitmapData::~SmallBitmapData
~SmallBitmapData()
Definition: Font.cpp:265
platform::Descriptions::Alert
Definition: YCommon.h:154
ystdex::ref
lref< _type > ref(_type &t)
构造引用包装。
Definition: ref.hpp:120