示例#1
0
        public static Font Parse(string str)
        {
            if (str == null)
            {
                throw new ArgumentNullException("str");
            }

            string[] tokens = str.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            Font ret = new Font { Family = null, Size = null, Style = null, OutlineThickness = null };
            if (tokens.Length > 0)
            {
                ret.Family = tokens[0];
            }
            if (tokens.Length > 1)
            {
                ret.Size = float.Parse(tokens[1]);
            }
            if (tokens.Length > 2)
            {
                ret.Style = ParseStyle(tokens[2].Trim());
            }
            if (tokens.Length > 3)
            {
                ret.OutlineThickness = float.Parse(tokens[3]);
            }
            else if (tokens.Length > 4)
            {
                throw new FormatException(string.Format("'{0}' is not a valid value for Font.", str));
            }

            return ret;
        }
示例#2
0
        void TextProperty.IHost.SetText(string text, Font font, Font ansiFont, Color textColor, Color textOutlineColor)
        {
            SystemFontStyle fontStyle;
            switch (font.Style)
            {
                default:
                case FontStyle.Regular:
                    fontStyle = SystemFontStyle.Regular;
                    break;
                case FontStyle.Bold:
                    fontStyle = SystemFontStyle.Bold;
                    break;
                case FontStyle.Italic:
                    fontStyle = SystemFontStyle.Italic;
                    break;
            }

            SystemFontStyle ansiFontStyle;
            switch (ansiFont.Style)
            {
                default:
                case FontStyle.Regular:
                    ansiFontStyle = SystemFontStyle.Regular;
                    break;
                case FontStyle.Bold:
                    ansiFontStyle = SystemFontStyle.Bold;
                    break;
                case FontStyle.Italic:
                    ansiFontStyle = SystemFontStyle.Italic;
                    break;
            }

            if (TypedTarget.FormattedText == null
                || TypedTarget.FormattedText.Text != text
                || TypedTarget.FormattedText.FormatOptions.Font.FamilyName != font.Family
                || TypedTarget.FormattedText.FormatOptions.Font.Size != font.Size
                || TypedTarget.FormattedText.FormatOptions.Font.Style != fontStyle
                || TypedTarget.FormattedText.FormatOptions.Font.OutlineThickness != font.OutlineThickness
                || TypedTarget.FormattedText.FormatOptions.AnsiFont.FamilyName != ansiFont.Family
                || TypedTarget.FormattedText.FormatOptions.AnsiFont.Size != ansiFont.Size
                || TypedTarget.FormattedText.FormatOptions.AnsiFont.Style != ansiFontStyle
                || TypedTarget.FormattedText.FormatOptions.AnsiFont.OutlineThickness != ansiFont.OutlineThickness)
            {
                var fd = new Graphics.TextRenderer.FontDescriptor(font.Family, font.Size.Value, fontStyle, font.OutlineThickness.Value);
                var ansiFd = new Graphics.TextRenderer.FontDescriptor(ansiFont.Family, ansiFont.Size.Value, ansiFontStyle, ansiFont.OutlineThickness.Value);
                TypedTarget.FormattedText = GameApp.Service<Graphics.TextRenderer>().FormatText(text, new Graphics.TextRenderer.FormatOptions(fd, ansiFd));
            }
            TypedTarget.TextColor = new XnaColor(textColor.Red, textColor.Green, textColor.Blue, textColor.Alpha);
            TypedTarget.TextOutlineColor = new XnaColor(textOutlineColor.Red, textOutlineColor.Green, textOutlineColor.Blue, textOutlineColor.Alpha);
        }
示例#3
0
        public static Font ParseFont(this XElement element, XName attributeName, Font defaultValue)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }
            else if (attributeName == null)
            {
                throw new ArgumentNullException("attributeName");
            }

            var attrib = element.Attribute(attributeName);
            return attrib != null ? Font.Parse(attrib.Value) : defaultValue;
        }
示例#4
0
        public override void Apply()
        {
            if (Parent.Definition == null)
            {
                return;
            }

            var host = Parent as IHost;
            if (host == null)
            {
                throw new ArgumentException(String.Format("'{0}' doesn't implement ImageProperty.IHost.", Parent.GetType().Name));
            }

            var text = BindValuesFor(m_text);
            var color = Color.Parse(BindValuesFor(m_textColor));
            var outlineColor = Color.Parse(BindValuesFor(m_textOutlineColor));

            Font font = new Font
            {
                Family = m_fontFamily,
                Size = float.Parse(m_fontSize),
                Style = Font.ParseStyle(m_fontStyle),
                OutlineThickness = float.Parse(m_fontOutlineThickness)
            };

            Font ansiFont = new Font
            {
                Family = m_ansiFontFamily,
                Size = float.Parse(m_ansiFontSize),
                Style = Font.ParseStyle(m_ansiFontStyle),
                OutlineThickness = float.Parse(m_ansiFontOutlineThickness)
            };

            host.SetText(text, font, ansiFont, color, outlineColor);
        }