blob: e24bc69b6a938da1d6ff82819bf4e9d2b60b2f99 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
#pragma once
#include "software_renderer/glyph_cache.hpp"
#include <ft2build.h>
#include FT_TYPES_H
#include FT_SYSTEM_H
#include FT_FREETYPE_H
#include FT_STROKER_H
#include FT_CACHE_H
#include "base/string_utils.hpp"
#include "coding/reader.hpp"
#include "std/string.hpp"
#include "std/vector.hpp"
#include "std/shared_ptr.hpp"
namespace software_renderer
{
struct Font
{
FT_Stream m_fontStream;
ReaderPtr<Reader> m_fontReader;
/// information about symbol ranges
/// ...
/// constructor
Font(ReaderPtr<Reader> const & fontReader);
~Font();
FT_Error CreateFaceID(FT_Library library, FT_Face * face);
};
/// Information about single unicode block.
struct UnicodeBlock
{
string m_name;
/// @{ font matching tuning
/// whitelist has priority over the blacklist in case of duplicates.
/// this fonts are promoted to the top of the font list for this block.
vector<string> m_whitelist;
/// this fonts are removed from the font list for this block.
vector<string> m_blacklist;
/// @}
strings::UniChar m_start;
strings::UniChar m_end;
/// sorted indices in m_fonts, from the best to the worst
vector<shared_ptr<Font> > m_fonts;
/// coverage of each font, in symbols
vector<int> m_coverage;
UnicodeBlock(string const & name, strings::UniChar start, strings::UniChar end);
bool hasSymbol(strings::UniChar sym) const;
};
struct GlyphCacheImpl
{
FT_Library m_lib;
FT_Stroker m_stroker;
FTC_Manager m_manager; //< freetype cache manager for all caches
FTC_ImageCache m_normalMetricsCache; //< cache of normal glyph metrics
FTC_ImageCache m_strokedMetricsCache; //< cache of stroked glyph metrics
FTC_ImageCache m_normalGlyphCache; //< cache of normal glyph images
FTC_ImageCache m_strokedGlyphCache; //< cache of stroked glyph images
FTC_CMapCache m_charMapCache; //< cache of glyphID -> glyphIdx mapping
typedef vector<UnicodeBlock> unicode_blocks_t;
unicode_blocks_t m_unicodeBlocks;
unicode_blocks_t::iterator m_lastUsedBlock;
bool m_isDebugging;
typedef vector<shared_ptr<Font> > TFonts;
TFonts m_fonts;
static FT_Error RequestFace(FTC_FaceID faceID, FT_Library library, FT_Pointer requestData, FT_Face * face);
void initBlocks(string const & fileName);
void initFonts(string const & whiteListFile, string const & blackListFile);
vector<shared_ptr<Font> > & getFonts(strings::UniChar sym);
void addFont(char const * fileName);
void addFonts(vector<string> const & fontNames);
int getCharIDX(shared_ptr<Font> const & font, strings::UniChar symbolCode);
pair<Font*, int> const getCharIDX(GlyphKey const & key);
GlyphMetrics const getGlyphMetrics(GlyphKey const & key);
shared_ptr<GlyphBitmap> const getGlyphBitmap(GlyphKey const & key);
GlyphCacheImpl(GlyphCache::Params const & params);
~GlyphCacheImpl();
};
}
|