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

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

#include "drape_frontend/shape_view_params.hpp"
#include "drape_frontend/intrusive_vector.hpp"

#include "drape/utils/vertex_decl.hpp"
#include "drape/glsl_types.hpp"
#include "drape/pointers.hpp"
#include "drape/texture_manager.hpp"

#include "geometry/spline.hpp"
#include "geometry/screenbase.hpp"

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

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

namespace dp
{
  class OverlayHandle;
}

namespace df
{

class TextLayout
{

public:
  virtual ~TextLayout() {}

  ref_ptr<dp::Texture> GetMaskTexture() const;

  uint32_t GetGlyphCount() const;

  float GetPixelLength() const;
  float GetPixelHeight() const;

  strings::UniString const & GetText() const;

protected:
  void Init(strings::UniString const & text,
            float fontSize,
            ref_ptr<dp::TextureManager> textures);

protected:
  typedef dp::TextureManager::GlyphRegion GlyphRegion;

  dp::TextureManager::TGlyphsBuffer m_metrics;
  strings::UniString m_text;
  float m_textSizeRatio = 0.0f;
};

class StraightTextLayout : public TextLayout
{
  using TBase = TextLayout;
public:
  StraightTextLayout(strings::UniString const & text,
                     float fontSize,
                     ref_ptr<dp::TextureManager> textures,
                     dp::Anchor anchor);

  void Cache(const glm::vec4 & pivot, glsl::vec2 const & pixelOffset,
             dp::TextureManager::ColorRegion const & colorRegion,
             dp::TextureManager::ColorRegion const & outlineRegion,
             gpu::TTextOutlinedStaticVertexBuffer & staticBuffer,
             gpu::TTextDynamicVertexBuffer & dynamicBuffer) const;

  void Cache(const glm::vec4 & pivot, glsl::vec2 const & pixelOffset,
             dp::TextureManager::ColorRegion const & color,
             gpu::TTextStaticVertexBuffer & staticBuffer,
             gpu::TTextDynamicVertexBuffer & dynamicBuffer) const;

  m2::PointU const & GetPixelSize() const { return m_pixelSize; }

private:
  buffer_vector<pair<size_t, glsl::vec2>, 2> m_offsets;
  m2::PointU m_pixelSize;
};

class PathTextLayout : public TextLayout
{
  using TBase = TextLayout;
public:
  PathTextLayout(m2::PointD const & tileCenter, strings::UniString const & text,
                 float fontSize, ref_ptr<dp::TextureManager> textures);

  void CacheStaticGeometry(dp::TextureManager::ColorRegion const & colorRegion,
                           dp::TextureManager::ColorRegion const & outlineRegion,
                           gpu::TTextOutlinedStaticVertexBuffer & staticBuffer) const;

  void CacheStaticGeometry(dp::TextureManager::ColorRegion const & colorRegion,
                           gpu::TTextStaticVertexBuffer & staticBuffer) const;

  bool CacheDynamicGeometry(m2::Spline::iterator const & iter,
                            float depth,
                            m2::PointD const & globalPivot,
                            gpu::TTextDynamicVertexBuffer & buffer) const;

  static bool CalculatePerspectivePosition(float splineLength, float textPixelLength,
                                           float & offset);

  static void CalculatePositions(vector<float> & offsets, float splineLength,
                                 float splineScaleToPixel, float textPixelLength);

private:
  static float CalculateTextLength(float textPixelLength);

  m2::PointD m_tileCenter;
};

class SharedTextLayout
{
public:
  SharedTextLayout(PathTextLayout * layout);

  bool IsNull() const;
  void Reset(PathTextLayout * layout);
  PathTextLayout * GetRaw();

  PathTextLayout * operator->();
  PathTextLayout const * operator->() const;

private:
  shared_ptr<PathTextLayout> m_layout;
};

}