bool load(const ResourcePtr& resource) { if(!Font::FTLibrary::Instance().library) return false; if(face) { FT_Done_Face(face); } if(resource && resource->getResourceStream()) { font_data = resource->getResourceStream()->readIntoMemory(); if(FT_New_Memory_Face(Font::FTLibrary::Instance().library, static_cast<MemoryStream*>(font_data.get())->data(), font_data->size(), 0, &face)) { return false; } FT_Select_Charmap(face, FT_ENCODING_UNICODE); return true; } else { if(FT_New_Face(Font::FTLibrary::Instance().library, string::WStringToString(resource->getName()).c_str(), 0, &face)) { return false; } return true; } return false; }
void Context::saveCfgFile(const UknString& name) { ConfigParserPtr configParser = ConfigParser::MakeEmptyParser(CPT_XML); if(configParser) { configParser->beginNode(L"cfg"); configParser->beginNode(L"graphics"); configParser->setInt(L"width", mCfg.render_cfg.width); configParser->setInt(L"height", mCfg.render_cfg.height); configParser->setInt(L"top", mCfg.render_cfg.top); configParser->setInt(L"left", mCfg.render_cfg.left); configParser->setBool(L"show_mouse", mCfg.render_cfg.show_mouse); configParser->setBool(L"full_screen", mCfg.render_cfg.full_screen); configParser->setBool(L"resizable", mCfg.render_cfg.resizable); configParser->setInt(L"sample_count", mCfg.render_cfg.sample_count); configParser->setInt(L"sample_quality", mCfg.render_cfg.sample_quality); configParser->setString(L"color_fmt", element_format_to_string(mCfg.render_cfg.color_fmt)); configParser->setString(L"depth_stencil_fmt", element_format_to_string(mCfg.render_cfg.depth_stencil_fmt)); configParser->toNode(L"/cfg"); configParser->beginNode(L"plugins"); if(!mCfg.graphic_factory_name.empty()) configParser->setString(L"graphic_factory", mCfg.graphic_factory_name); } UknString formattedString = configParser->writeToString(); ResourcePtr resource = ResourceLoader::Instance().createFileResource(name); if(resource) { resource->getResourceStream()->write((const uint8*)formattedString.data(), formattedString.size()); } }
bool Font::deserialize(const ConfigParserPtr& config) { mGlyphs.clear(); if(config && config->toNode(L"font")) { UknString font_name = config->getString(L"name"); if(!font_name.empty()) { UknString fullFontPath = Path::CheckAndGetFontPath(font_name); if(fullFontPath.empty()) { log_error(L"ukn::Font::deserialize: error finding font name " + font_name); return false; } ResourcePtr fontResource = ResourceLoader::Instance().loadResource(fullFontPath); if(fontResource && fontResource->getResourceStream()) { bool result = mFace->load(fontResource); if(result) { mGlyphs.resize(mFace->face->num_glyphs); for(int i = 0; i < mFace->face->num_glyphs; ++i) { mGlyphs[i].size = mFontSize; mGlyphs[i].face = &mFace->face; } } } } mEnableShadow = config->getBool(L"shadow", false); mEnableStroke = config->getBool(L"stroke", false); if(config->getBool(L"bold", false)) { this->setFTStyle(FT_STYLE_FLAG_BOLD); } if(config->getBool(L"italic", false)) { this->setFTStyle(FT_STYLE_FLAG_ITALIC); } mShadowXOffset = config->getInt(L"shadow_offset_x", 0); mShadowYOffset = config->getInt(L"shadow_offset_y", 0); mStrokeWidth = config->getInt(L"stroke_width", 0); mFontSize = config->getInt(L"size", 14); mFontName = font_name; config->toParent(); return true; } return false; }
bool ConfigParserXmlImpl::open(ResourcePtr resource) { StreamPtr dataStream = resource->getResourceStream()->readIntoMemory(); if(dataStream) { if(!mDocument) { mDocument = new pugi::xml_document; } bool result = mDocument->load_buffer((void*)static_cast<MemoryStream*>(dataStream.get())->data(), dataStream->size(), pugi::encoding_wchar); if(result) { mName = resource->getName(); mCurrNode = mDocument->root(); return result; } } return false; }