예제 #1
0
        /// <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));
        }
예제 #3
0
        /// <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);
        }
예제 #4
0
        /// <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);
        }
예제 #5
0
        /// <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);
        }
예제 #6
0
        /// <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);
            }
        }
예제 #7
0
        /// <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);
            }
        }
예제 #8
0
        /// <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);
        }
예제 #9
0
        /// <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);

        }
예제 #10
0
        /// <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));
            }
        }
예제 #11
0
        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);
        }
예제 #12
0
        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]);
        }
예제 #13
0
 /// <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;
 }
예제 #14
0
 /// <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);
 }
예제 #15
0
 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));
 }
예제 #16
0
 /// <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);
     }
 }
예제 #17
0
 /// <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));
 }
예제 #18
0
 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));
 }
예제 #20
0
 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)));
 }
예제 #21
0
 protected override RFont CreateFontInt(string family, double size, RFontStyle style)
 {
     return new FontAdapter(family, size, style);
 }
예제 #22
0
        protected override RFont CreateFontInt(string family, double size, RFontStyle style)
        {
            var fontStyle = (FontStyle)((int)style);

            return(new FontAdapter(new Font(family, (float)size, fontStyle)));
        }
예제 #23
0
 protected override RFont CreateFontInt(string family, double size, RFontStyle style)
 {
     var fontStyle = (FontStyle)((int)style);
     return new FontAdapter(new Font(family, (float)size, fontStyle));
 }
예제 #24
0
 protected override RFont CreateFontInt(RFontFamily family, double size, RFontStyle style)
 {
     return new FontAdapter(family.Name, size, style);
 }
예제 #25
0
 protected abstract RFont GetCachedFont(string fontFamily, double fsize, RFontStyle st);
예제 #26
0
 /// <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);
 }
예제 #27
0
 public FontAdapter(string family, double size, RFontStyle style)
 {
     _size = size;
     _font = Utils.FontManager.Instance.GetTTF_Font(family, size, style);
 }
예제 #28
0
 /// <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);
예제 #29
0
 /// <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));
 }
예제 #30
0
 /// <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));
 }
예제 #31
0
 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);
 }
예제 #32
0
 /// <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);
예제 #33
0
        /// <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;
        }
예제 #34
0
 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));
 }
예제 #35
0
        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));
        }
예제 #36
0
 protected override RFont GetCachedFont(string fontFamily, double fsize, RFontStyle st)
 {
     return HtmlContainer.Adapter.GetFont(fontFamily, fsize, st);
 }
예제 #37
0
 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);
 }
예제 #38
0
        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)));
        }
예제 #39
0
 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));
 }
예제 #41
0
 /// <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;
     }
 }
예제 #42
0
 /// <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;
     }
 }
예제 #43
0
 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)));
 }