MyGUI  3.2.0
MyGUI_ResourceManualFont.cpp
Go to the documentation of this file.
1 
6 /*
7  This file is part of MyGUI.
8 
9  MyGUI is free software: you can redistribute it and/or modify
10  it under the terms of the GNU Lesser General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  MyGUI is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public License
20  along with MyGUI. If not, see <http://www.gnu.org/licenses/>.
21 */
22 #include "MyGUI_Precompiled.h"
24 #include "MyGUI_SkinManager.h"
25 #include "MyGUI_RenderManager.h"
26 #include "MyGUI_TextureUtility.h"
27 
28 namespace MyGUI
29 {
30 
32  mDefaultHeight(0),
33  mSubstituteGlyphInfo(nullptr),
34  mTexture(nullptr)
35  {
36  }
37 
39  {
40  }
41 
43  {
44  CharMap::iterator iter = mCharMap.find(_id);
45 
46  if (iter != mCharMap.end())
47  return &iter->second;
48 
49  return mSubstituteGlyphInfo;
50  }
51 
52  void ResourceManualFont::loadTexture()
53  {
54  if (mTexture == nullptr)
55  {
57  mTexture = render.getTexture(mSource);
58  if (mTexture == nullptr)
59  {
60  mTexture = render.createTexture(mSource);
61  mTexture->loadFromFile(mSource);
62  }
63  }
64  }
65 
67  {
68  Base::deserialization(_node, _version);
69 
71  while (node.next())
72  {
73  if (node->getName() == "Property")
74  {
75  const std::string& key = node->findAttribute("key");
76  const std::string& value = node->findAttribute("value");
77  if (key == "Source") mSource = value;
78  else if (key == "DefaultHeight") mDefaultHeight = utility::parseInt(value);
79  }
80  }
81 
82  loadTexture();
83 
84  if (mTexture != nullptr)
85  {
86  int textureWidth = mTexture->getWidth();
87  int textureHeight = mTexture->getHeight();
88 
89  node = _node->getElementEnumerator();
90  while (node.next())
91  {
92  if (node->getName() == "Codes")
93  {
95  while (element.next("Code"))
96  {
97  std::string value;
98  // описане глифов
99  if (element->findAttribute("index", value))
100  {
101  Char id = 0;
102  if (value == "cursor")
104  else if (value == "selected")
106  else if (value == "selected_back")
108  else if (value == "substitute")
110  else
111  id = utility::parseUInt(value);
112 
113  float advance(utility::parseValue<float>(element->findAttribute("advance")));
114  FloatPoint bearing(utility::parseValue<FloatPoint>(element->findAttribute("bearing")));
115  FloatCoord coord(utility::parseValue<FloatCoord>(element->findAttribute("coord")));
116 
117  if (advance == 0.0f)
118  advance = coord.width;
119 
120  GlyphInfo& glyphInfo = mCharMap.insert(CharMap::value_type(id, GlyphInfo(
121  id,
122  coord.width,
123  coord.height,
124  advance,
125  bearing.left,
126  bearing.top,
127  FloatRect(
128  coord.left / textureWidth,
129  coord.top / textureHeight,
130  coord.right() / textureWidth,
131  coord.bottom() / textureHeight)
132  ))).first->second;
133 
134  if (id == FontCodeType::NotDefined)
135  mSubstituteGlyphInfo = &glyphInfo;
136  }
137  }
138  }
139  }
140  }
141  }
142 
144  {
145  return mTexture;
146  }
147 
149  {
150  return mDefaultHeight;
151  }
152 
153 } // namespace MyGUI