Font::Font(const FontDescription &desc, const std::string &ttf_filename, FileSystem fs) { std::string new_filename = PathHelp::get_filename(ttf_filename, PathHelp::path_type_file); FontFamily font_family(new_filename); font_family.add(desc, ttf_filename, fs); impl = std::make_shared<Font_Impl>(font_family, desc); }
Resource<Font> XMLDisplayCache::get_font(Canvas &canvas, const std::string &family_name, const FontDescription &desc) { auto it = fonts.find(family_name); if (it != fonts.end()) return Font(it->second, desc); bool is_resource_font = false; if (doc.resource_exists(family_name)) { XMLResourceNode resource = doc.get_resource(family_name); if (resource.get_element().get_tag_name() == "font") { is_resource_font = true; } } Font font; FontFamily font_family(family_name); fonts[family_name] = font_family; if (is_resource_font) { font = Font::load(canvas, family_name, desc, font_family, doc, bind_member(this, &XMLDisplayCache::get_sprite)); } else { font = Font(font_family, desc); } return font; }
Font::Font(Canvas &canvas, const std::string &typeface_name, Sprite &sprite, const std::string &glyph_list, float spacelen, bool monospace, const FontMetrics &metrics) { FontDescription desc; desc.set_height(metrics.get_height()); FontFamily font_family(typeface_name); font_family.add(canvas, sprite, glyph_list, spacelen, monospace, metrics); impl = std::make_shared<Font_Impl>(font_family, desc); }
Resource<Font> FileDisplayCache::get_font(Canvas &canvas, const std::string &family_name, const FontDescription &desc) { auto it = fonts.find(family_name); if (it != fonts.end()) return Font(it->second, desc); //TODO: Maybe allow loading of fonts from the doc filesystem? FontFamily font_family(family_name); fonts[family_name] = font_family; Font font = Font(font_family, desc); return font; }
// Uses GDI+ to fill the LOGFONT structure. This is computationally expensive // but easy to get right. However it doesn't handle some fonts like Terminal. // font_size is in units of tenths of point size. i.e. 100 is a 10 point font bool get_logfont(const tstring & font_name, int font_size, LOGFONT * lf) { Bitmap b(1, 1); Graphics g(&b); FontFamily font_family(WideBuffer(font_name.c_str())); const FontFamily * ff = &font_family; if (!font_family.IsAvailable()) return false; Gdiplus::Font font(ff, static_cast<REAL>(font_size) / POINT_SIZE_SCALE); if (!font.IsAvailable()) return false; #ifdef UNICODE font.GetLogFontW(&g, lf); #else font.GetLogFontA(&g, lf); #endif return true; }
Font::Font(const std::string &typeface_name, const FontDescription &desc) { FontFamily font_family(typeface_name); *this = Font(font_family, desc); }