示例#1
0
    private static TextCharDef ChangeDefOnDemand(TextCharDef def, XmlAttributeCollection attributes)
    {
        if (attributes [FONT_ATTRIBUTE] != null)
        {
            def.font = FontCache.GetFont(attributes [FONT_ATTRIBUTE].InnerText);
        }

        if (attributes [SIZE_ATTRIBUTE] != null)
        {
            def.size = float.Parse(attributes [SIZE_ATTRIBUTE].InnerText);
        }

        if (attributes [FONTSIZE_ATTRIBUTE] != null)
        {
            def.fontSize = int.Parse(attributes [FONTSIZE_ATTRIBUTE].InnerText);
        }

        if (attributes [SPACING_ATTRIBUTE] != null)
        {
            def.spacing = float.Parse(attributes [SPACING_ATTRIBUTE].InnerText);
        }

        if (attributes [COLOR_ATTRIBUTE] != null)
        {
            def.color = ColorExtension.ParseColor(attributes [COLOR_ATTRIBUTE].InnerText);
        }

        return(def);
    }
示例#2
0
 protected virtual Font GetItemFont(object item)
 {
     if (FontCallback != null)
     {
         FontStyle fontStyle = FontCallback(item);
         if (fontStyle != FontStyle.Regular)
         {
             return(_fontCache.GetFont(_owner.Font, fontStyle));
         }
     }
     return(_owner.Font);
 }
示例#3
0
    public void Deserialize(NetworkManager networkManager, ElementDataBase elementData, UIBehaviour element)
    {
        TextData textData    = elementData as TextData;
        Text     textElement = element as Text;

        if (textElement)
        {
            textElement.text      = textData.text;
            textElement.fontSize  = textData.fontSize;
            textElement.font      = FontCache.GetFont(textData.fontName);
            textElement.color     = textData.colorData.Deserialize();
            textElement.alignment = textData.alignment;
        }
    }
示例#4
0
 protected Font GetFont(Style style, StyleInstance styleInstance)
 {
     return(m_fontCache.GetFont(MappingHelper.GetStyleFontFamily(style, styleInstance, GetDefaultFont().Name), MappingHelper.GetStyleFontSize(style, styleInstance), MappingHelper.GetStyleFontStyle(MappingHelper.GetStyleFontStyle(style, styleInstance), MappingHelper.GetStyleFontWeight(style, styleInstance), MappingHelper.GetStyleFontTextDecoration(style, styleInstance))));
 }
示例#5
0
        private bool TryParseValue(Type targetType, object currentValue, StyleItemLine item, out object result)
        {
            string value = item.Value;

            if (item.Value.StartsWith("(") && item.Value.EndsWith(")") && TryParseExpression(value, out string v))
            {
                value = v;
            }

            try
            {
                if (targetType == typeof(Color))
                {
                    if (objectCache.ContainsKey(value) && objectCache[value] is Color)
                    {
                        result = objectCache[value];
                    }
                    else
                    {
                        result             = ParseColor(value);
                        objectCache[value] = result;
                    }
                }

                if (typeof(Image).IsAssignableFrom(targetType))
                {
                    string path = Path.Combine(item.RootDir, value);
                    result = ImageCache.Load(path);
                }

                if (typeof(Font).IsAssignableFrom(targetType))
                {
                    result = FontCache.GetFont((Font)currentValue, value);
                }

                if (targetType.IsEnum)
                {
                    if (objectCache.ContainsKey(value) && objectCache[value].GetType() == targetType)
                    {
                        result = objectCache[value];
                    }
                    else
                    {
                        result             = Enum.Parse(targetType, value, true);
                        objectCache[value] = result;
                    }
                }

                if (objectCache.ContainsKey(value) && objectCache[value].GetType() == targetType)
                {
                    result = objectCache[value];
                }
                else
                {
                    result             = ParseLiteral(value, targetType);
                    objectCache[value] = result;
                }

                return(true);
            }
            catch (Exception)
            {
                result = null;
                return(false);
            }
        }
示例#6
0
 /// <summary>
 /// Realize a font from the cache
 /// </summary>
 internal Font.Font GetFont(string familyName, int weight, bool bold, bool italic, bool underline, bool strikeout)
 {
     return(_fonts.GetFont(familyName, weight, bold, italic, underline, strikeout));
 }