21 std::ifstream standardFile;
29 auto message =
"fonts directory does not exist: [" + path.string() +
"]";
33 auto fontsStandardFile = path /
"standard";
34 if (!std::filesystem::exists(fontsStandardFile))
36 auto message =
"fonts/standard file does not exist: [" + fontsStandardFile.string() +
"]";
40 standardFile.open(fontsStandardFile, std::ios::in);
41 if (!standardFile.is_open())
43 auto message =
"unable to open fonts/standard file: [" + fontsStandardFile.string() +
"]";
47 std::shared_ptr<CharacterBlock> pCurrentCharacterBlock;
48 std::shared_ptr<CharacterBlock::LineRecord> pCurrentLineRecord;
49 bool beginTokenFound =
false;
51 while (std::getline(standardFile, line))
59 std::stringstream lineStream(line);
64 else if (line.find(
"XSIZE") == 0)
67 if (!(lineStream >> token))
77 if (!(lineStream >> token))
82 m_xSize = std::stof(token);
84 else if (line.find(
"YSIZE") == 0)
87 if (!(lineStream >> token))
97 if (!(lineStream >> token))
102 m_ySize = std::stof(token);
104 else if (line.find(
"OFFSET") == 0)
107 if (!(lineStream >> token))
112 if (token !=
"OFFSET")
117 if (!(lineStream >> token))
122 m_offset = std::stof(token);
126 pCurrentCharacterBlock = std::make_shared<CharacterBlock>();
127 beginTokenFound =
true;
130 if (!(lineStream >> token))
140 if (!(lineStream >> token))
146 if (token.length() != 1)
151 pCurrentCharacterBlock->character = token;
155 if (pCurrentCharacterBlock !=
nullptr && beginTokenFound)
157 m_characterBlocks.push_back(pCurrentCharacterBlock);
158 beginTokenFound =
false;
159 pCurrentCharacterBlock.reset();
169 if (!(lineStream >> token))
179 if (pCurrentCharacterBlock ==
nullptr || !beginTokenFound)
184 auto pLineRecord = std::make_shared<CharacterBlock::LineRecord>();
186 if (!(lineStream >> token))
190 pLineRecord->xStart = std::stof(token);
192 if (!(lineStream >> token))
196 pLineRecord->yStart = std::stof(token);
198 if (!(lineStream >> token))
202 pLineRecord->xEnd = std::stof(token);
204 if (!(lineStream >> token))
208 pLineRecord->yEnd = std::stof(token);
211 if (!(lineStream >> token))
217 if (token.length() != 1)
230 if (!(lineStream >> token))
236 if (token.length() != 1)
249 if (!(lineStream >> token))
253 pLineRecord->width = std::stof(token);
255 pCurrentCharacterBlock->m_lineRecords.push_back(pLineRecord);
259 logwarn(
"unrecognized line: " + line);
265 standardFile.close();
269 auto m = pe.
toString(
"Parse Error:");
272 standardFile.close();
281 standardFile.close();
std::string ToUtf8(std::string_view input)
Converts input to valid UTF-8.