forked from organicmaps/organicmaps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglyph_cache_impl.hpp
101 lines (77 loc) · 2.89 KB
/
glyph_cache_impl.hpp
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
#pragma once
#include "software_renderer/glyph_cache.hpp"
#include "coding/reader.hpp"
#include "base/string_utils.hpp"
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include <ft2build.h>
#include FT_TYPES_H
#include FT_SYSTEM_H
#include FT_FREETYPE_H
#include FT_STROKER_H
#include FT_CACHE_H
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
{
std::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.
std::vector<std::string> m_whitelist;
/// this fonts are removed from the font list for this block.
std::vector<std::string> m_blacklist;
/// @}
strings::UniChar m_start;
strings::UniChar m_end;
/// sorted indices in m_fonts, from the best to the worst
std::vector<std::shared_ptr<Font> > m_fonts;
/// coverage of each font, in symbols
std::vector<int> m_coverage;
UnicodeBlock(std::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 std::vector<UnicodeBlock> unicode_blocks_t;
unicode_blocks_t m_unicodeBlocks;
unicode_blocks_t::iterator m_lastUsedBlock;
bool m_isDebugging;
typedef std::vector<std::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(std::string const & fileName);
void initFonts(std::string const & whiteListFile, std::string const & blackListFile);
std::vector<std::shared_ptr<Font> > & getFonts(strings::UniChar sym);
void addFont(char const * fileName);
void addFonts(std::vector<std::string> const & fontNames);
int getCharIDX(std::shared_ptr<Font> const & font, strings::UniChar symbolCode);
std::pair<Font*, int> const getCharIDX(GlyphKey const & key);
GlyphMetrics const getGlyphMetrics(GlyphKey const & key);
std::shared_ptr<GlyphBitmap> const getGlyphBitmap(GlyphKey const & key);
GlyphCacheImpl(GlyphCache::Params const & params);
~GlyphCacheImpl();
};
} // namespace software_renderer