/// <summary> /// Get cached font if it exists in cache or null if it is not. /// </summary> private RFont TryGetFont(string family, double size, RFontStyle style) { RFont font = null; if (this._fontsCache.ContainsKey(family)) { var a = this._fontsCache[family]; if (a.ContainsKey(size)) { var b = a[size]; if (b.ContainsKey(style)) { font = b[style]; } } else { this._fontsCache[family][size] = new Dictionary <RFontStyle, RFont>(); } } else { this._fontsCache[family] = new Dictionary <double, Dictionary <RFontStyle, RFont> >(); this._fontsCache[family][size] = new Dictionary <RFontStyle, RFont>(); } return(font); }
protected override RFont CreateFontInt(RFontFamily family, double size, RFontStyle style) { var fontStyle = (XFontStyle)((int)style); var xFont = new XFont(((FontFamilyAdapter)family).FontFamily.Name, size, fontStyle, new XPdfFontOptions(PdfFontEncoding.Unicode)); return(new FontAdapter(xFont)); }
/// <summary> /// Get cached font instance for the given font properties.<br/> /// Improve performance not to create same font multiple times. /// </summary> /// <returns>cached font instance</returns> public RFont GetCachedFont(string family, double size, RFontStyle style) { var font = this.TryGetFont(family, size, style); if (font == null) { if (!this._existingFontFamilies.ContainsKey(family)) { string mappedFamily; if (this._fontsMapping.TryGetValue(family, out mappedFamily)) { font = this.TryGetFont(mappedFamily, size, style); if (font == null) { font = this.CreateFont(mappedFamily, size, style); this._fontsCache[mappedFamily][size][style] = font; } } } if (font == null) { font = this.CreateFont(family, size, style); } this._fontsCache[family][size][style] = font; } return(font); }
/// <summary> /// Get WPF font style for the given style. /// </summary> private static FontStyle GetFontStyle(RFontStyle style) { if ((style & RFontStyle.Italic) == RFontStyle.Italic) { return(FontStyles.Italic); } return(FontStyles.Normal); }
/// <summary> /// Get WPF font style for the given style. /// </summary> private static FontWeight GetFontWidth(RFontStyle style) { if ((style & RFontStyle.Bold) == RFontStyle.Bold) { return(FontWeights.Bold); } return(FontWeights.Normal); }
/// <summary> /// Get WPF font style for the given style. /// </summary> private static FontWeight GetFontWidth(RFontStyle style) { switch (style) { case RFontStyle.Bold: return(FontWeights.Bold); default: return(FontWeights.Normal); } }
/// <summary> /// Get WPF font style for the given style. /// </summary> private static FontStyle GetFontStyle(RFontStyle style) { switch (style) { case RFontStyle.Italic: return(FontStyles.Italic); default: return(FontStyles.Normal); } }
/// <summary> /// Init. /// </summary> public FontAdapter(string fontFamily, double size, RFontStyle style) { Style = style; Name = fontFamily; _size = size; //TODO: Somehow get proper line spacing and underlinePosition var lineSpacing = 1; var underlinePosition = 0; _height = 96d / 72d * _size * lineSpacing; _underlineOffset = 96d / 72d * _size * (lineSpacing + underlinePosition); }
/// <summary> // create font (try using existing font family to support custom fonts) /// </summary> private RFont CreateFont(string family, double size, RFontStyle style) { RFontFamily fontFamily; try { return(_existingFontFamilies.TryGetValue(family, out fontFamily) ? _adapter.CreateFont(fontFamily, size, style) : _adapter.CreateFont(family, size, style)); } catch { // handle possibility of no requested style exists for the font, use regular then return(_existingFontFamilies.TryGetValue(family, out fontFamily) ? _adapter.CreateFont(fontFamily, size, RFontStyle.Regular) : _adapter.CreateFont(family, size, RFontStyle.Regular)); } }
private SKTypefaceStyle DJKJLAW(RFontStyle style) { switch (style) { case RFontStyle.Bold: return(SKTypefaceStyle.Bold); case RFontStyle.Italic: return(SKTypefaceStyle.Italic); case RFontStyle.Regular: return(SKTypefaceStyle.Normal); case RFontStyle.Strikeout: return(SKTypefaceStyle.Normal); case RFontStyle.Underline: return(SKTypefaceStyle.Normal); } // SKTypefaceStyle.Bold return(SKTypefaceStyle.Normal); }
public IntPtr GetTTF_Font(string familyname, double size, RFontStyle style) { if (_defaultFontFamilyId == -1) { throw new Exception("Run FontManager.Instance.SetDefaultsFontFamily() after calling FontManager.Instance.RegisterFont* methods."); } int fontfamily_id = GetFontFamilyId(familyname); int style_id = (int)style; int size_id = (int)size;// Math.Round(_defaultFontSize * size); if (!UseFontCache) { return(OpenTTF_Font(fontfamily_id, size_id, style_id)); } //fontfamily if (!_fontCache.ContainsKey(fontfamily_id)) { _fontCache[fontfamily_id] = new Dictionary <int, Dictionary <int, IntPtr> >(); } var fc_family = _fontCache[fontfamily_id]; //style if (!fc_family.ContainsKey(style_id)) { fc_family[style_id] = new Dictionary <int, IntPtr>(); } var fc_style = fc_family[style_id]; //size if (!fc_style.ContainsKey(size_id)) { fc_style[size_id] = OpenTTF_Font(fontfamily_id, size_id, style_id); } return(fc_style[size_id]); }
/// <summary> /// Get cached font if it exists in cache or null if it is not. /// </summary> private RFont TryGetFont(string family, double size, RFontStyle style) { RFont font = null; if (_fontsCache.ContainsKey(family)) { var a = _fontsCache[family]; if (a.ContainsKey(size)) { var b = a[size]; if (b.ContainsKey(style)) { font = b[style]; } } else { _fontsCache[family][size] = new Dictionary<RFontStyle, RFont>(); } } else { _fontsCache[family] = new Dictionary<double, Dictionary<RFontStyle, RFont>>(); _fontsCache[family][size] = new Dictionary<RFontStyle, RFont>(); } return font; }
/// <summary> /// Get font instance by given font family name, size and style. /// </summary> /// <param name="family">the font family name</param> /// <param name="size">font size</param> /// <param name="style">font style</param> /// <returns>font instance</returns> public RFont GetFont(string family, double size, RFontStyle style) { return _fontsHandler.GetCachedFont(family, size, style); }
protected override RFont CreateFontInt(RFontFamily family, double size, RFontStyle style) { return(new FontAdapter(new Typeface(((FontFamilyAdapter)family).FontFamily, GetFontStyle(style), GetFontWidth(style), FontStretches.Normal), size)); }
/// <summary> // create font (try using existing font family to support custom fonts) /// </summary> private RFont CreateFont(string family, double size, RFontStyle style) { RFontFamily fontFamily; try { return _existingFontFamilies.TryGetValue(family, out fontFamily) ? _adapter.CreateFont(fontFamily, size, style) : _adapter.CreateFont(family, size, style); } catch { // handle possibility of no requested style exists for the font, use regular then return _existingFontFamilies.TryGetValue(family, out fontFamily) ? _adapter.CreateFont(fontFamily, size, RFontStyle.Regular) : _adapter.CreateFont(family, size, RFontStyle.Regular); } }
/// <summary> /// Get font instance by given font family instance, size and style.<br/> /// Used to support custom fonts that require explicit font family instance to be created. /// </summary> /// <param name="family">the font family instance</param> /// <param name="size">font size</param> /// <param name="style">font style</param> /// <returns>font instance</returns> internal RFont CreateFont(RFontFamily family, double size, RFontStyle style) { return(CreateFontInt(family, size, style)); }
protected abstract RFont GetCachedFont(string fontFamily, double fsize, RFontStyle st);
protected override RFont CreateFontInt(string family, double size, RFontStyle style) { return(new FontAdapter(family, size, style)); }
protected override RFont CreateFontInt(RFontFamily family, double size, RFontStyle style) { // var fontStyle = (FontStyle) ((int) style); // return new FontAdapter(new SKFont(((FontFamilyAdapter) family).FontFamily, (float) size, fontStyle)); return(new FontAdapter(new SKFont(SKTypeface.FromFamilyName(family.Name, DJKJLAW(style)), (float)size * 1.1f))); }
protected override RFont CreateFontInt(string family, double size, RFontStyle style) { return new FontAdapter(family, size, style); }
protected override RFont CreateFontInt(string family, double size, RFontStyle style) { var fontStyle = (FontStyle)((int)style); return(new FontAdapter(new Font(family, (float)size, fontStyle))); }
protected override RFont CreateFontInt(string family, double size, RFontStyle style) { var fontStyle = (FontStyle)((int)style); return new FontAdapter(new Font(family, (float)size, fontStyle)); }
protected override RFont CreateFontInt(RFontFamily family, double size, RFontStyle style) { return new FontAdapter(family.Name, size, style); }
/// <summary> /// Get font instance by given font family instance, size and style.<br/> /// Used to support custom fonts that require explicit font family instance to be created. /// </summary> /// <param name="family">the font family instance</param> /// <param name="size">font size</param> /// <param name="style">font style</param> /// <returns>font instance</returns> internal RFont CreateFont(RFontFamily family, double size, RFontStyle style) { return CreateFontInt(family, size, style); }
public FontAdapter(string family, double size, RFontStyle style) { _size = size; _font = Utils.FontManager.Instance.GetTTF_Font(family, size, style); }
/// <summary> /// Get font instance by given font family instance, size and style.<br/> /// Used to support custom fonts that require explicit font family instance to be created. /// </summary> /// <param name="family">the font family instance</param> /// <param name="size">font size</param> /// <param name="style">font style</param> /// <returns>font instance</returns> protected abstract RFont CreateFontInt(RFontFamily family, double size, RFontStyle style);
/// <summary> /// Get font instance by given font family name, size and style. /// </summary> /// <param name="family">the font family name</param> /// <param name="size">font size</param> /// <param name="style">font style</param> /// <returns>font instance</returns> internal RFont CreateFont(string family, double size, RFontStyle style) { return(this.CreateFontInt(family, size, style)); }
/// <summary> /// Get font instance by given font family name, size and style. /// </summary> /// <param name="family">the font family name</param> /// <param name="size">font size</param> /// <param name="style">font style</param> /// <returns>font instance</returns> public RFont GetFont(string family, double size, RFontStyle style) { return(_fontsHandler.GetCachedFont(family, size, style)); }
protected override RFont CreateFontInt(RFontFamily family, double size, RFontStyle style) { var fontStyle = (XFontStyle)((int)style); var xFont = new XFont(((FontFamilyAdapter)family).FontFamily.Name, size, fontStyle, new XPdfFontOptions(PdfFontEncoding.Unicode)); return new FontAdapter(xFont); }
/// <summary> /// Get cached font instance for the given font properties.<br/> /// Improve performance not to create same font multiple times. /// </summary> /// <returns>cached font instance</returns> public RFont GetCachedFont(string family, double size, RFontStyle style) { var font = TryGetFont(family, size, style); if (font == null) { if (!_existingFontFamilies.ContainsKey(family)) { string mappedFamily; if (_fontsMapping.TryGetValue(family, out mappedFamily)) { font = TryGetFont(mappedFamily, size, style); if (font == null) { font = CreateFont(mappedFamily, size, style); _fontsCache[mappedFamily][size][style] = font; } } } if (font == null) { font = CreateFont(family, size, style); } _fontsCache[family][size][style] = font; } return font; }
protected override RFont CreateFontInt(RFontFamily family, double size, RFontStyle style) { var fontStyle = (FontStyle)((int)style); return new FontAdapter(new Font(((FontFamilyAdapter)family).FontFamily, (float)size, fontStyle)); }
protected override RFont CreateFontInt(string family, double size, RFontStyle style) { var fontFamily = (FontFamily) new FontFamilyConverter().ConvertFromString(family) ?? new FontFamily(); return(new FontAdapter(new Typeface(fontFamily, GetFontStyle(style), GetFontWidth(style), FontStretches.Normal), size)); }
protected override RFont GetCachedFont(string fontFamily, double fsize, RFontStyle st) { return HtmlContainer.Adapter.GetFont(fontFamily, fsize, st); }
protected override RFont CreateFontInt(string family, double size, RFontStyle style) { var fontFamily = (FontFamily)new FontFamilyConverter().ConvertFromString(family) ?? new FontFamily(); return new FontAdapter(new Typeface(fontFamily, GetFontStyle(style), GetFontWidth(style), FontStretches.Normal), size); }
protected override RFont CreateFontInt(RFontFamily family, double size, RFontStyle style) { var fontStyle = (FontStyle)((int)style); return(new FontAdapter(new Font(((FontFamilyAdapter)family).FontFamily, (float)size, fontStyle))); }
protected override RFont CreateFontInt(RFontFamily family, double size, RFontStyle style) { return new FontAdapter(new Typeface(((FontFamilyAdapter)family).FontFamily, GetFontStyle(style), GetFontWidth(style), FontStretches.Normal), size); }
protected override RFont CreateFontInt(RFontFamily family, double size, RFontStyle style) { return(new FontAdapter(family.Name, size, style)); }
/// <summary> /// Get WPF font style for the given style. /// </summary> private static FontStyle GetFontStyle(RFontStyle style) { switch (style) { case RFontStyle.Italic: return FontStyles.Italic; default: return FontStyles.Normal; } }
/// <summary> /// Get WPF font style for the given style. /// </summary> private static FontWeight GetFontWidth(RFontStyle style) { switch (style) { case RFontStyle.Bold: return FontWeights.Bold; default: return FontWeights.Normal; } }
protected override RFont CreateFontInt(string family, double size, RFontStyle style) { // var fontStyle = (FontStyle) ((int) style); return(new FontAdapter(new SKFont(SKTypeface.FromFamilyName(family, DJKJLAW(style)), (float)size))); }