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

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

#include "indexer/drules_include.hpp"

#include <algorithm>
#include <vector>

namespace
{
double ConvertWidth(double w, double scale)
{
  return std::max(w * scale, 1.0);
}
}  // namespace

namespace software_renderer
{
dp::Color ConvertColor(uint32_t c)
{
  return dp::Extract(c, 255 - (c >> 24));
}

void ConvertStyle(LineDefProto const * pSrc, double scale, PenInfo & dest)
{
  double offset = 0.0;
  std::vector<double> v;

  if (pSrc->has_dashdot())
  {
    DashDotProto const & dd = pSrc->dashdot();

    int const count = dd.dd_size();
    v.reserve(count);
    for (int i = 0; i < count; ++i)
      v.push_back(dd.dd(i) * scale);

    if (dd.offset() != 0)
      offset = dd.offset() * scale;
  }

  dest = PenInfo(ConvertColor(pSrc->color()),
                 ConvertWidth(pSrc->width(), scale),
                 v.empty() ? 0 : &v[0], v.size(), offset);

  if (pSrc->has_pathsym())
  {
    PathSymProto const & ps = pSrc->pathsym();

    dest.m_step = ps.step() * scale;
    dest.m_icon.m_name = ps.name();

    if (ps.offset() != 0)
      dest.m_offset = ps.offset() * scale;
  }

  switch (pSrc->join())
  {
  case ROUNDJOIN:
    dest.m_join = dp::RoundJoin;
    break;
  case BEVELJOIN:
    dest.m_join = dp::BevelJoin;
    break;
  case NOJOIN:
    dest.m_join = dp::MiterJoin;
    break;
  default:
    break;
  }

  switch (pSrc->cap())
  {
  case ROUNDCAP:
    dest.m_cap = dp::RoundCap;
    break;
  case BUTTCAP:
    dest.m_cap = dp::ButtCap;
    break;
  case SQUARECAP:
    dest.m_cap = dp::SquareCap;
    break;
  default:
    break;
  }
}

void ConvertStyle(AreaRuleProto const * pSrc, BrushInfo & dest)
{
  dest.m_color = ConvertColor(pSrc->color());
}

void ConvertStyle(SymbolRuleProto const * pSrc, IconInfo & dest)
{
  dest.m_name = pSrc->name();
}

void ConvertStyle(CaptionDefProto const * pSrc, double scale, dp::FontDecl & dest, m2::PointD & offset)
{
  // fonts smaller than 8px look "jumpy" on LDPI devices
  uint8_t const h = std::max(8, static_cast<int>(pSrc->height() * scale));

  offset = m2::PointD(0, 0);
  if (pSrc->offset_x() != 0)
    offset.x = scale * pSrc->offset_x();
  if (pSrc->offset_y() != 0)
    offset.y = scale * pSrc->offset_y();

  dest = dp::FontDecl(ConvertColor(pSrc->color()), h);

  if (pSrc->stroke_color() != 0)
    dest.m_outlineColor = ConvertColor(pSrc->stroke_color());
}

void ConvertStyle(ShieldRuleProto const * pSrc, double scale, dp::FontDecl & dest)
{
  // fonts smaller than 8px look "jumpy" on LDPI devices
  uint8_t const h = std::max(8, static_cast<int>(pSrc->height() * scale));

  dest = dp::FontDecl(ConvertColor(pSrc->color()), h);

  if (pSrc->stroke_color() != 0)
    dest.m_outlineColor = ConvertColor(pSrc->stroke_color());
}

uint8_t GetFontSize(CaptionDefProto const * pSrc)
{
  return pSrc->height();
}
}  // namespace software_renderer