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

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

#include "../../base/base.hpp"
#include "../../std/vector.hpp"
#include "../../std/list.hpp"
#include "../../std/string.hpp"
#include "../../std/map.hpp"
#include "../../geometry/rect2d.hpp"
#include "../../coding/writer.hpp"
#include "../../geometry/packer.hpp"
#include <boost/gil/gil_all.hpp>

#include <QtGui/QPainter>
#include <QtGui/QImage>
#include <QtCore/QFileInfo>
#include <QtCore/QSize>
#include <QtSvg/QSvgRenderer>
#include <QtXml/QXmlContentHandler>
#include <QtXml/QXmlDefaultHandler>

class QImage;

namespace gil = boost::gil;

namespace tools
{
  class SkinGenerator
  {
  public:

      struct CharInfo
      {
        int m_width;
        int m_height;
        int m_xOffset;
        int m_yOffset;
        int m_xAdvance;
        gil::gray8_image_t m_image;

        m2::Packer::handle_t m_handle;
      };

      typedef map<int32_t, pair<CharInfo, CharInfo> > TChars;

      struct FontInfo
      {
        int8_t m_size;
        TChars m_chars;
      };

      typedef vector<FontInfo> TFonts;

      struct SymbolInfo
      {
        QSize m_size;
        QString m_fullFileName;
        QString m_symbolID;

        m2::Packer::handle_t m_handle;

        SymbolInfo() {}
        SymbolInfo(QSize size, QString const & fullFileName, QString const & symbolID)
          : m_size(size), m_fullFileName(fullFileName), m_symbolID(symbolID) {}
      };

      typedef vector<SymbolInfo> TSymbols;

      struct SkinPageInfo
      {
        TFonts m_fonts;
        TSymbols m_symbols;
        int m_width;
        int m_height;
        string m_fileName;
        string m_dir;
        string m_suffix;
        m2::Packer m_packer;
      };

      string const getBaseFileName(string const & fileName);

  private:

      QSvgRenderer m_svgRenderer;

      int m_baseLineOffset;
      QString m_fontFileName;

      typedef vector<SkinPageInfo> TSkinPages;
      TSkinPages m_pages;

      bool m_overflowDetected;
      void markOverflow();

      void renderIcon(string const & svgFile, string const & pngFile, QSize const & size);

  public:

      SkinGenerator();
      void processFont(string const & fileName, string const & skinName, vector<int8_t> const & fontSizes, int symbolScale);
      void processSymbols(string const & symbolsDir,
                          string const & skinName,
                          vector<QSize> const & symbolSizes,
                          vector<string> const & suffix);

      void processSearchIcons(string const & symbolsDir,
                              string const & searchCategories,
                              string const & searchIconsPath,
                              int searchIconWidth,
                              int searchIconHeight);
      void renderPages();
      bool writeToFile(string const & skinName);
    };
} // namespace tools