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

glyph_cache.hpp « graphics - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 313a0fb95cb85fbf64e2a37fdd8d08f1de87d987 (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
#pragma once

#include "color.hpp"

#include "defines.hpp"

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

#include "../std/shared_ptr.hpp"
#include "../std/vector.hpp"
#include "../std/string.hpp"
#include "../std/utility.hpp"


namespace graphics
{
  /// metrics of the single glyph
  struct GlyphMetrics
  {
    int m_xAdvance;
    int m_yAdvance;
    int m_xOffset;
    int m_yOffset;
    int m_width;
    int m_height;
  };

  struct GlyphBitmap
  {
    unsigned m_width;
    unsigned m_height;
    unsigned m_pitch;
    vector<unsigned char> m_data;
  };

  struct GlyphKey
  {
    strings::UniChar m_symbolCode;
    int m_fontSize;
    bool m_isMask;
    graphics::Color m_color;
    /// as it's used for fixed fonts only, the color doesn't matter
    /// @TODO REMOVE IT!!! All chars are already 32bit
    uint32_t toUInt32() const;
    GlyphKey(strings::UniChar symbolCode,
             int fontSize,
             bool isMask,
             Color const & color);
    GlyphKey();
  };

  struct Font;

  bool operator<(GlyphKey const & l, GlyphKey const & r);
  bool operator!=(GlyphKey const & l, GlyphKey const & r);

  struct GlyphCacheImpl;

  class GlyphCache
  {
  private:

    shared_ptr<GlyphCacheImpl> m_impl;

    static threads::Mutex s_fribidiMutex;

  public:

    struct Params
    {
      string m_blocksFile;
      string m_whiteListFile;
      string m_blackListFile;
      size_t m_maxSize;
      EDensity m_density;
      bool   m_isDebugging;
      Params(string const & blocksFile,
             string const & whiteListFile,
             string const & blackListFile,
             size_t maxSize,
             EDensity density,
             bool isDebugging);
    };

    GlyphCache();
    GlyphCache(Params const & params);

    void reset();
    //void addFont(char const * fileName);
    void addFonts(vector<string> const & fontNames);

    pair<Font*, int> getCharIDX(GlyphKey const & key);

    shared_ptr<GlyphBitmap> const getGlyphBitmap(GlyphKey const & key);
    /// return control box(could be slightly larger than the precise bound box).
    GlyphMetrics const getGlyphMetrics(GlyphKey const & key);

    double getTextLength(double fontSize, string const & text);

    static strings::UniString log2vis(strings::UniString const & str);
  };
}