/////////////////////////////////////////////////////////////////////////// ResFont ///////////////////////////////////////////////////////////////////////////
| 214 | /// ResFont |
| 215 | //////////////////////////////////////////////////////////////////////////////// |
| 216 | void ResFont::HGEFont::ReadDefine(const std::wstring& data, std::unordered_map<wchar_t, f2dGlyphInfo>& out, std::wstring& tex) |
| 217 | { |
| 218 | out.clear(); |
| 219 | tex.clear(); |
| 220 | |
| 221 | std::vector<std::wstring> tLines; |
| 222 | fcyStringHelper::StringSplit(data, L"\n", true, tLines); |
| 223 | for (auto& i : tLines) |
| 224 | { |
| 225 | i = fcyStringHelper::Trim(i); |
| 226 | } |
| 227 | |
| 228 | // ��һ�б�����HGEFONT |
| 229 | if (tLines.size() <= 1 || tLines[0] != L"[HGEFONT]") |
| 230 | throw fcyException("ResFont::HGEFont::readDefine", "Bad file format."); |
| 231 | |
| 232 | for (size_t i = 1; i < tLines.size(); ++i) |
| 233 | { |
| 234 | wstring& tLine = tLines[i]; |
| 235 | if (tLine.size() == 0) |
| 236 | continue; |
| 237 | |
| 238 | wstring::size_type tPos; |
| 239 | if (string::npos == (tPos = tLine.find_first_of(L"="))) |
| 240 | throw fcyException("ResFont::HGEFont::readDefine", "Bad file format."); |
| 241 | wstring tKey = tLine.substr(0, tPos); |
| 242 | wstring tValue = tLine.substr(tPos + 1, tLine.size() - tPos - 1); |
| 243 | if (tKey == L"Bitmap") |
| 244 | tex = tValue; |
| 245 | else if (tKey == L"Char") |
| 246 | { |
| 247 | wchar_t c; |
| 248 | int c_hex; |
| 249 | float x, y, w, h, left_offset, right_offset; |
| 250 | if (7 != swscanf(tValue.c_str(), L"\"%c\",%f,%f,%f,%f,%f,%f", &c, &x, &y, &w, &h, &left_offset, &right_offset)) |
| 251 | { |
| 252 | if (7 != swscanf(tValue.c_str(), L"%X,%f,%f,%f,%f,%f,%f", &c_hex, &x, &y, &w, &h, &left_offset, &right_offset)) |
| 253 | throw fcyException("ResFont::HGEFont::readDefine", "Bad file format."); |
| 254 | c = static_cast<wchar_t>(c_hex); |
| 255 | } |
| 256 | |
| 257 | // ���㵽f2d����ƫ���� |
| 258 | f2dGlyphInfo tInfo = { |
| 259 | fcyRect(x, y, x + w, y + h), |
| 260 | fcyVec2(w, h), |
| 261 | fcyVec2(-left_offset, h), |
| 262 | fcyVec2(w + left_offset + right_offset, 0) |
| 263 | }; |
| 264 | if (out.find(c) != out.end()) |
| 265 | throw fcyException("ResFont::HGEFont::readDefine", "Duplicated character defination."); |
| 266 | out.emplace(c, tInfo); |
| 267 | } |
| 268 | else |
| 269 | throw fcyException("ResFont::HGEFont::readDefine", "Bad file format."); |
| 270 | } |
| 271 | |
| 272 | if (tex.empty()) |
| 273 | throw fcyException("ResFont::HGEFont::readDefine", "Bad file format."); |