18 const GlyphInfo* ResourceManualFont::getGlyphInfo(
Char _id)
const
20 CharMap::const_iterator iter = mCharMap.find(_id);
22 if (iter != mCharMap.end())
25 return mSubstituteGlyphInfo;
28 void ResourceManualFont::loadTexture()
30 if (mTexture ==
nullptr)
32 RenderManager& render = RenderManager::getInstance();
33 mTexture = render.getTexture(mSource);
34 if (mTexture ==
nullptr)
36 mTexture = render.createTexture(mSource);
37 if (mTexture !=
nullptr)
38 mTexture->loadFromFile(mSource);
43 void ResourceManualFont::deserialization(xml::ElementPtr _node, Version _version)
45 Base::deserialization(_node, _version);
47 const bool oldAdvanceFormat = _version <= Version{1, 1};
52 "ResourceManualFont: '" << mResourceName
53 <<
"' have old format. Recreate with FontEditor or bump version to "
54 "1.2 if your bearingX is always 0");
57 for (
auto node : _node.node())
59 if (node.name() == std::string_view(
"Property"))
61 std::string_view key = node.attribute(
"key").value();
62 std::string_view value = node.attribute(
"value").value();
65 else if (key ==
"DefaultHeight")
67 else if (key ==
"Shader")
74 if (mTexture !=
nullptr)
77 mTexture->setShader(mShader);
78 int textureWidth = mTexture->getWidth();
79 int textureHeight = mTexture->getHeight();
81 for (
auto node : _node.node())
83 if (node.name() == std::string_view(
"Codes"))
85 for (
auto element : node.children(
"Code"))
87 std::string_view value{element.attribute(
"index").value()};
91 if (value ==
"cursor")
93 else if (value ==
"selected")
95 else if (value ==
"selected_back")
97 else if (value ==
"substitute")
108 std::string_view sizeString{element.attribute(
"size").value()};
109 FloatSize size(coord.width, coord.height);
110 if (!sizeString.empty())
115 std::string_view advanceAttribute{element.attribute(
"advance").value()};
116 float advance = size.width;
117 if (!advanceAttribute.empty())
120 if (oldAdvanceFormat)
121 advance += bearing.left;
133 coord.left / textureWidth,
134 coord.top / textureHeight,
135 coord.right() / textureWidth,
136 coord.bottom() / textureHeight}});
141 for (
auto kerningNode : element.children(
"Kerning"))
145 addKerningInfo(
id, right, offset);
154 ITexture* ResourceManualFont::getTextureFont()
const
159 int ResourceManualFont::getDefaultHeight()
const
161 return mDefaultHeight;
164 void ResourceManualFont::setSource(std::string_view value)
171 void ResourceManualFont::setShader(std::string_view value)
174 if (mTexture !=
nullptr)
175 mTexture->setShader(mShader);
178 void ResourceManualFont::setTexture(ITexture* texture)
184 void ResourceManualFont::setDefaultHeight(
int value)
186 mDefaultHeight = value;
189 void ResourceManualFont::addGlyphInfo(
Char id,
const GlyphInfo& info)
191 GlyphInfo& inserted = mCharMap.insert(CharMap::value_type(
id, info)).first->second;
194 mSubstituteGlyphInfo = &inserted;
197 float ResourceManualFont::getKerning(
Char _left,
Char _right)
const
199 auto iter = mKerningMap.find(std::make_pair(_left, _right));
200 if (iter != mKerningMap.end())
205 void ResourceManualFont::addKerningInfo(
Char _left,
Char _right,
float _value)
207 mKerningMap[std::make_pair(_left, _right)] = _value;
#define MYGUI_LOG(level, text)
unsigned int parseUInt(std::string_view _value)
float parseFloat(std::string_view _value)
T parseValue(std::string_view value)
template MYGUI_EXPORT float parseValue< float >(std::string_view)
int parseInt(std::string_view _value)
types::TCoord< float > FloatCoord
types::TRect< float > FloatRect
types::TPoint< float > FloatPoint
types::TSize< float > FloatSize