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

glyph_cache.cpp « graphics - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 547829a936b57b754da3cfebd4303a7345b60de1 (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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#include "glyph_cache.hpp"
#include "glyph_cache_impl.hpp"
#include "ft2_debug.hpp"

#include "opengl/data_traits.hpp"
#include "opengl/opengl.hpp"

#include "../3party/fribidi/lib/fribidi-deprecated.h"
#include "../3party/fribidi/lib/fribidi.h"

#include "../coding/lodepng_io.hpp"

#include "../base/logging.hpp"
#include "../base/string_utils.hpp"

#include "../std/vector.hpp"
#include "../std/map.hpp"
#include "../base/mutex.hpp"

#include <boost/gil/gil_all.hpp>


namespace gil = boost::gil;

namespace graphics
{
  GlyphKey::GlyphKey(strings::UniChar symbolCode,
                     int fontSize,
                     bool isMask,
                     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()
  {}

  uint32_t GlyphKey::toUInt32() const
  {
    return static_cast<uint32_t>(m_symbolCode) << 16
         | static_cast<uint32_t>(m_fontSize) << 8
         | static_cast<uint32_t>(m_isMask);
  }

  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(string const & blocksFile, string const & whiteListFile, string const & blackListFile, size_t maxSize, bool isDebugging)
    : m_blocksFile(blocksFile), m_whiteListFile(whiteListFile), m_blackListFile(blackListFile), m_maxSize(maxSize), m_isDebugging(isDebugging)
  {}

  GlyphCache::GlyphCache()
  {}

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

  void GlyphCache::addFont(const char *fileName)
  {
    m_impl->addFont(fileName);
  }

  void GlyphCache::addFonts(vector<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, 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, graphics::Color(0, 0, 0, 255));
      len += getGlyphMetrics(k).m_xAdvance;
    }

    return len;
  }

  threads::Mutex m;

  strings::UniString GlyphCache::log2vis(strings::UniString const & str)
  {
//    FriBidiEnv e;
    threads::MutexGuard g(m);
    size_t const count = str.size();
    strings::UniString res(count);
    FriBidiParType dir = FRIBIDI_PAR_LTR;  // requested base direction
    fribidi_log2vis(&str[0], count, &dir, &res[0], 0, 0, 0);
    return res;
//    return str;
  }

}