Welcome to mirror list, hosted at ThFree Co, Russian Federation.

glyph_cache.cpp « software_renderer - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: dea432516cd1a365c780ea4665d5666e674ef0e9 (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
#include "software_renderer/glyph_cache.hpp"

#include "software_renderer/glyph_cache_impl.hpp"

namespace software_renderer
{
GlyphKey::GlyphKey(strings::UniChar symbolCode,
                   int fontSize,
                   bool isMask,
                   dp::Color const & color)
  : m_symbolCode(symbolCode),
    m_fontSize(fontSize),
    m_isMask(isMask),
    m_color(color)
{}

GlyphKey::GlyphKey()
  : m_symbolCode(0),
    m_fontSize(),
    m_isMask(),
    m_color()
{}

bool operator<(GlyphKey const & l, GlyphKey const & r)
{
  if (l.m_symbolCode != r.m_symbolCode)
    return l.m_symbolCode < r.m_symbolCode;
  if (l.m_fontSize != r.m_fontSize)
    return l.m_fontSize < r.m_fontSize;
  if (l.m_isMask != r.m_isMask)
    return l.m_isMask < r.m_isMask;
  return l.m_color < r.m_color;
}

bool operator!=(GlyphKey const & l, GlyphKey const & r)
{
  return (l.m_symbolCode != r.m_symbolCode)
      || (l.m_fontSize != r.m_fontSize)
      || (l.m_isMask != r.m_isMask)
      || !(l.m_color == r.m_color);
}

GlyphCache::Params::Params(std::string const & blocksFile,
                           std::string const & whiteListFile,
                           std::string const & blackListFile,
                           size_t maxSize,
                           double visualScale,
                           bool isDebugging)
  : m_blocksFile(blocksFile),
    m_whiteListFile(whiteListFile),
    m_blackListFile(blackListFile),
    m_maxSize(maxSize),
    m_visualScale(visualScale),
    m_isDebugging(isDebugging)
{}

GlyphCache::GlyphCache()
{}

GlyphCache::GlyphCache(Params const & params) : m_impl(new GlyphCacheImpl(params))
{
}

void GlyphCache::addFonts(std::vector<std::string> const & fontNames)
{
  m_impl->addFonts(fontNames);
}

pair<Font*, int> GlyphCache::getCharIDX(GlyphKey const & key)
{
  return m_impl->getCharIDX(key);
}

GlyphMetrics const GlyphCache::getGlyphMetrics(GlyphKey const & key)
{
  return m_impl->getGlyphMetrics(key);
}

shared_ptr<GlyphBitmap> const GlyphCache::getGlyphBitmap(GlyphKey const & key)
{
  return m_impl->getGlyphBitmap(key);
}

double GlyphCache::getTextLength(double fontSize, std::string const & text)
{
  strings::UniString const s = strings::MakeUniString(text);
  double len = 0;
  for (unsigned i = 0; i < s.size(); ++i)
  {
    GlyphKey k(s[i], static_cast<uint32_t>(fontSize), false, dp::Color(0, 0, 0, 255));
    len += getGlyphMetrics(k).m_xAdvance;
  }

  return len;
}
}  // namespace software_renderer