| 294 | } |
| 295 | |
| 296 | void FontLoader::loadTrueTypeFont(FontId fontId, const VFS::Path::Normalized& path, std::istream& stream) |
| 297 | { |
| 298 | Log(Debug::Info) << "Loading TrueType font file " << path; |
| 299 | |
| 300 | MyGUIPlatform::DataManager* const dataManager |
| 301 | = dynamic_cast<MyGUIPlatform::DataManager*>(&MyGUIPlatform::DataManager::getInstance()); |
| 302 | if (dataManager == nullptr) |
| 303 | { |
| 304 | Log(Debug::Error) << "Can not load TrueType font " << fontId.mValue |
| 305 | << ": osgMyGUI::DataManager is not available."; |
| 306 | return; |
| 307 | } |
| 308 | |
| 309 | // TODO: it may be worth to take in account resolution change, but it is not safe to replace used assets |
| 310 | std::unique_ptr<MyGUI::IDataStream> layersStream(dataManager->getData("openmw_layers.xml")); |
| 311 | MyGUI::IntSize bookSize = getBookSize(layersStream.get()); |
| 312 | float bookScale = MyGUIPlatform::ScalingLayer::getScaleFactor(bookSize); |
| 313 | const VFS::Path::Normalized oldDataPath(dataManager->getResourcePath()); |
| 314 | |
| 315 | struct SetOldResourcePath |
| 316 | { |
| 317 | VFS::Path::NormalizedView mOldDataPath; |
| 318 | |
| 319 | void operator()(MyGUIPlatform::DataManager* dataManager) const |
| 320 | { |
| 321 | dataManager->setResourcePath(mOldDataPath); |
| 322 | } |
| 323 | }; |
| 324 | |
| 325 | std::unique_ptr<MyGUIPlatform::DataManager, SetOldResourcePath> dataManagerPtr( |
| 326 | dataManager, SetOldResourcePath{ oldDataPath }); |
| 327 | |
| 328 | constexpr VFS::Path::NormalizedView fonts("fonts"); |
| 329 | dataManager->setResourcePath(fonts); |
| 330 | |
| 331 | std::unique_ptr<MyGUI::IDataStream> dataStream = std::make_unique<MyGUI::DataStream>(&stream); |
| 332 | |
| 333 | MyGUI::xml::Document xmlDocument; |
| 334 | xmlDocument.open(dataStream.get()); |
| 335 | MyGUI::xml::ElementPtr root = xmlDocument.getRoot(); |
| 336 | |
| 337 | MyGUI::xml::ElementEnumerator resourceNode = root->getElementEnumerator(); |
| 338 | bool valid = false; |
| 339 | if (resourceNode.next("Resource")) |
| 340 | { |
| 341 | valid = resourceNode->findAttribute("type") == "ResourceTrueTypeFont"; |
| 342 | } |
| 343 | |
| 344 | if (valid == false) |
| 345 | { |
| 346 | Log(Debug::Error) << "Can not load TrueType font " << fontId.mValue << ": " << path << " is invalid."; |
| 347 | return; |
| 348 | } |
| 349 | |
| 350 | int resolution = 70; |
| 351 | MyGUI::xml::ElementPtr resolutionNode = getProperty(resourceNode.current(), "Resolution"); |
| 352 | if (resolutionNode == nullptr) |
| 353 | { |
nothing calls this directly
no test coverage detected