예제 #1
0
        public object create_font(string faceName, int size, int weight, font_style italic, uint decoration, out font_metrics fm)
        {
            fm = default(font_metrics);
            var fonts = new List <string>();

            html.split_string(faceName, fonts, ",");
            fonts[0].Trim();
            var fontStyle = italic == font_style.italic ? FontStyle.Italic : FontStyle.Regular;

            if ((decoration & types.font_decoration_linethrough) != 0)
            {
                fontStyle |= FontStyle.Strikeout;
            }
            if ((decoration & types.font_decoration_underline) != 0)
            {
                fontStyle |= FontStyle.Underline;
            }
            return(new Font(fonts[0], weight, fontStyle));
        }
예제 #2
0
        public static FontHolder Create(string faceName, int size, int weight, font_style italic, font_decoration decoration, ref font_metrics fm)
        {
            var possibleFonts = faceName.Split(',').ToList();

            possibleFonts.Add("Helvetica"); // Make sure there's a font in the list.
            CTFont font = null;

            foreach (var fontName in possibleFonts)
            {
                // faceName = faceName; // normalize between WPF and Mac for ways to reference custom fonts.
                font = new CTFont(fontName.TrimEnd().Replace("./#", ""), size);

                // Bold & italic are properties of the CTFont
                var traits = CTFontSymbolicTraits.None;
                if (italic == font_style.fontStyleItalic)
                {
                    traits |= CTFontSymbolicTraits.Italic;
                }
                if (weight > 400)
                {
                    traits |= CTFontSymbolicTraits.Bold;
                }
                font = font.WithSymbolicTraits(font.Size, traits, traits);
                if (font != null)
                {
                    break;
                }
            }

            var strAttrs = new CTStringAttributes {
                Font = font
            };

            // initial size must be unscaled when getting these metrics
            fm.ascent   = (int)Math.Round(font.AscentMetric);
            fm.descent  = (int)Math.Round(font.DescentMetric);
            fm.height   = (int)Math.Round(font.AscentMetric + font.DescentMetric);
            fm.x_height = (int)Math.Round(font.XHeightMetric);

            fm.draw_spaces = decoration.HasFlag(font_decoration.font_decoration_underline) || decoration.HasFlag(font_decoration.font_decoration_linethrough);

            var fontHolder = new FontHolder
            {
                FaceName   = faceName,
                Size       = size,
                Attributes = strAttrs,
                Decoration = decoration,
                Weight     = weight
            };

            return(fontHolder);
        }
예제 #3
0
        public object create_font(string faceName, int size, int weight, font_style italic, uint decoration, out font_metrics fm)
        {
            fm = default(font_metrics);
            var fonts = new List <string>();

            html.split_string(faceName, fonts, ",");
            fonts[0].Trim();
            var fontStyle = italic == font_style.italic ? FontStyle.Italic : FontStyle.Regular;

            if ((decoration & types.font_decoration_linethrough) != 0)
            {
                fontStyle |= FontStyle.Strikeout;
            }
            if ((decoration & types.font_decoration_underline) != 0)
            {
                fontStyle |= FontStyle.Underline;
            }
            var fnt       = new Font(fonts[0], size, fontStyle);
            var fntFamily = fnt.FontFamily;

            if (!_preload)
            {
                PreLoad();
            }
            var dpi = (int)_dpi;

            fm.ascent      = fntFamily.GetCellAscent(fontStyle) / dpi;
            fm.descent     = fntFamily.GetCellDescent(fontStyle) / dpi;
            fm.x_height    = fm.height = fntFamily.GetEmHeight(fontStyle) / dpi;
            fm.draw_spaces = italic == font_style.italic || decoration != 0;
            return(fnt);
        }
예제 #4
0
        protected override UIntPtr CreateFont(string faceName, int size, int weight, font_style italic, font_decoration decoration, ref font_metrics fm)
        {
            var      fontweight = FontWeight.FromOpenTypeWeight(weight);
            FontInfo font       = new FontInfo(faceName, italic == font_style.fontStyleItalic ? FontStyles.Italic : FontStyles.Normal, fontweight, size, FontAbsolutePathDelegate?.Invoke(faceName));

            if ((decoration & font_decoration.font_decoration_underline) != 0)
            {
                font.Decorations.Add(TextDecorations.Underline);
            }

            UIntPtr fontID = new UIntPtr(_nextFontID++);

            _fonts.Add(fontID, font);

            fm.x_height    = font.xHeight;
            fm.ascent      = font.Ascent;
            fm.descent     = font.Descent;
            fm.height      = font.LineHeight;
            fm.draw_spaces = decoration > 0;

            return(fontID);
        }
예제 #5
0
            public static UnityFont Create(string faceName, int size, int weight, font_style italic, uint decoration, out font_metrics fm)
            {
                // Unity
                var fnt = Font.CreateDynamicFontFromOSFont(faceName, size);
                //fm.ascent = fnt.ascent;
                //fm.descent = 0;
                //fm.x_height = fm.height = fnt.lineHeight;
                //fm.draw_spaces = italic == font_style.italic || decoration != 0;
                // From System
                var fontStyle = italic == font_style.italic ? System.Drawing.FontStyle.Italic : System.Drawing.FontStyle.Regular;

                if ((decoration & types.font_decoration_linethrough) != 0)
                {
                    fontStyle |= System.Drawing.FontStyle.Strikeout;
                }
                if ((decoration & types.font_decoration_underline) != 0)
                {
                    fontStyle |= System.Drawing.FontStyle.Underline;
                }
                var fnt2      = new System.Drawing.Font(faceName, size, fontStyle);
                var fntFamily = fnt2.FontFamily;
                var dpi       = 96;

                fm.ascent      = fntFamily.GetCellAscent(fontStyle) / dpi;
                fm.descent     = fntFamily.GetCellDescent(fontStyle) / dpi;
                fm.x_height    = fm.height = fntFamily.GetEmHeight(fontStyle) / dpi;
                fm.draw_spaces = italic == font_style.italic || decoration != 0;
                return(new UnityFont {
                    Font = fnt, SystemFont = fnt2
                });
            }
예제 #6
0
 public object create_font(string faceName, int size, int weight, font_style italic, uint decoration, out font_metrics fm) => UnityFont.Create(faceName, size, weight, italic, decoration, out fm);
예제 #7
0
        public object create_font(string faceName, int size, int weight, font_style italic, uint decoration, out font_metrics fm)
        {
            fm = new font_metrics();
            var fonts = new List <string>();

            html.split_string(faceName, fonts, ",");
            fonts[0].Trim();

            FontFace fnt = null;

            //using (var pattern = FcPatternCreate())
            //{
            //    var found = false;
            //    foreach (var i in fonts)
            //        if (FcPatternAddString(pattern, FC_FAMILY, i))
            //        {
            //            found = true;
            //            break;
            //        }
            //    if (found)
            //    {
            //        FcPatternAddInteger(pattern, FC_SLANT, italic == font_style.italic ? FontSlant.Italic : FontSlant.Normal);
            //        var fc_weight = FontWeight.Normal;
            //        if (weight >= 0 && weight < 150) fc_weight = FC_WEIGHT_THIN;
            //        else if (weight >= 150 && weight < 250) fc_weight = FC_WEIGHT_EXTRALIGHT;
            //        else if (weight >= 250 && weight < 350) fc_weight = FC_WEIGHT_LIGHT;
            //        else if (weight >= 350 && weight < 450) fc_weight = FC_WEIGHT_NORMAL;
            //        else if (weight >= 450 && weight < 550) fc_weight = FC_WEIGHT_MEDIUM;
            //        else if (weight >= 550 && weight < 650) fc_weight = FC_WEIGHT_SEMIBOLD;
            //        else if (weight >= 650 && weight < 750) fc_weight = FC_WEIGHT_BOLD;
            //        else if (weight >= 750 && weight < 850) fc_weight = FC_WEIGHT_EXTRABOLD;
            //        else if (weight >= 950) fc_weight = FC_WEIGHT_BLACK;
            //        FcPatternAddInteger(pattern, FC_WEIGHT, fc_weight);
            //        fnt = cairo_ft_font_face_create_for_pattern(pattern);
            //    }
            //}

            cairo_font ret = null;

            if (fnt != null)
            {
                _temp_cr.Save();
                _temp_cr.SetContextFontFace(fnt);
                _temp_cr.SetFontSize(size);
                var ext = _temp_cr.FontExtents;
                var tex = _temp_cr.TextExtents("x");

                fm.ascent   = (int)ext.Ascent;
                fm.descent  = (int)ext.Descent;
                fm.height   = (int)(ext.Ascent + ext.Descent);
                fm.x_height = (int)tex.Height;
                _temp_cr.Restore();

                ret = new cairo_font
                {
                    font      = fnt,
                    size      = size,
                    strikeout = (decoration & types.font_decoration_linethrough) != 0,
                    underline = (decoration & types.font_decoration_underline) != 0
                };
            }
            return(ret);
        }
예제 #8
0
        protected override UIntPtr CreateFont(string faceName, int size, int weight, font_style italic, font_decoration decoration, ref font_metrics fm)
        {
            var fontId     = new UIntPtr(++lastFontId);
            var fontHolder = FontHolder.Create(faceName, size, weight, italic, decoration, ref fm);

            fontCache.Add(fontId, fontHolder);
            return(fontId);
        }
예제 #9
0
        public object create_font(string faceName, int size, int weight, font_style italic, uint decoration, out font_metrics fm)
        {
            fm = default;
            var fonts = new List <string>();

            html.split_string(faceName, fonts, ",");
            fonts[0].Trim();
            var fnt = Font.CreateDynamicFontFromOSFont(fonts[0], size);

            fm.ascent      = fnt.ascent;
            fm.descent     = 0;
            fm.x_height    = fm.height = fnt.lineHeight;
            fm.draw_spaces = italic == font_style.italic || decoration != 0;
            return(null);
        }