void FontPanel::notifyMouseButtonClick(MyGUI::Widget* _widget) { // шрифто?нету if (mComboFont->getOnlyText().empty()) return; if (mEditSaveFileName->getOnlyText().empty() && _widget == mButtonSave) return; MyGUI::xml::Document document; document.createDeclaration(); MyGUI::xml::ElementPtr root = document.createRoot("MyGUI"); generateFontTTFXml(root); if (_widget == mButtonSave) { if (!document.save(mEditSaveFileName->getOnlyText() + ".xml")) { /*MyGUI::Message* message =*/ MyGUI::Message::createMessageBox("Message", "error", document.getLastError(), MyGUI::MessageBoxStyle::Ok | MyGUI::MessageBoxStyle::IconError); } else { /*MyGUI::Message* message =*/ MyGUI::Message::createMessageBox("Message", "success", mEditSaveFileName->getOnlyText() + ".xml", MyGUI::MessageBoxStyle::Ok | MyGUI::MessageBoxStyle::IconInfo); } MyGUI::IFont* font = MyGUI::FontManager::getInstance().getByName(mFontName); MyGUI::ITexture* texture = font->getTextureFont(); texture->saveToFile(mEditSaveFileName->getOnlyText() + ".png"); } else if (_widget == mButtonGenerate) { MyGUI::ResourceManager& manager = MyGUI::ResourceManager::getInstance(); if (manager.isExist(mFontName)) { manager.removeByName(mFontName); } MyGUI::ResourceManager::getInstance().loadFromXmlNode(root, "", MyGUI::Version()); MyGUI::IResource* resource = manager.getByName(mFontName, false); MYGUI_ASSERT(resource != nullptr, "Could not find font '" << mFontName << "'"); MyGUI::IFont* font = resource->castType<MyGUI::IFont>(); // выво?реальног?размер?шрифта mFontHeight = font->getDefaultHeight(); mTextPix->setCaption(MyGUI::utility::toString("Height of a font is ", mFontHeight, " pixels")); mFontView->setFontName(mFontName); mTextureView->setFontName(mFontName); } }
void FontExportSerializer::generateFontManualXml(MyGUI::xml::ElementPtr _root, const MyGUI::UString& _folderName, DataPtr _data) { MyGUI::IFont* resource = MyGUI::FontManager::getInstance().getByName(_data->getPropertyValue("FontName")); MyGUI::ResourceTrueTypeFont* font = resource != nullptr ? resource->castType<MyGUI::ResourceTrueTypeFont>(false) : nullptr; if (font != nullptr) { std::string textureName = _data->getPropertyValue("Name") + ".png"; MyGUI::ITexture* texture = font->getTextureFont(); if (texture == nullptr) return; texture->saveToFile(MyGUI::UString(common::concatenatePath(_folderName, MyGUI::UString(textureName))).asUTF8()); MyGUI::xml::ElementPtr node = _root->createChild("Resource"); node->addAttribute("type", "ResourceManualFont"); node->addAttribute("name", _data->getPropertyValue("Name")); addProperty(node, "Source", textureName); addProperty(node, "SourceSize", MyGUI::IntSize(texture->getWidth(), texture->getHeight())); addProperty(node, "DefaultHeight", font->getDefaultHeight()); MyGUI::xml::Element* codes = node->createChild("Codes"); std::vector<std::pair<MyGUI::Char, MyGUI::Char> > codePointRanges = font->getCodePointRanges(); MyGUI::Char substituteCodePoint = font->getSubstituteCodePoint(); bool isCustomSubstituteCodePoint = substituteCodePoint != MyGUI::FontCodeType::NotDefined; // Add all of the code points. Skip over the substitute code point -- unless it's been customized, in which case it // needs to be added here as a regular code point and then at the end as a substitute code point. for (std::vector<std::pair<MyGUI::Char, MyGUI::Char> >::const_iterator iter = codePointRanges.begin() ; iter != codePointRanges.end(); ++iter) for (MyGUI::Char code = iter->first; code <= iter->second && code >= iter->first; ++code) if (code != substituteCodePoint || isCustomSubstituteCodePoint) addCode(codes, code, font, false); // Always add the substitute code point last, even if it isn't the last one in the range. addCode(codes, substituteCodePoint, font, true); } }
void FontPanel::saveTexture(const std::string& _fontName, const std::string& _fileName) { MyGUI::IFont* font = MyGUI::FontManager::getInstance().getByName(_fontName); MyGUI::ITexture* texture = font->getTextureFont(); texture->saveToFile(_fileName); }