public TextGeometryCompanion(object item) :
            base(item)
        {
            var customGeomDef = Geometry.GetValue(GeometryExtProps.CustomGeometryProperty);

            if (customGeomDef is string)
            {
                var xCustomGeom = XElement.Parse((string)customGeomDef);
                var xTextGeom   = xCustomGeom.Element("TextGeometry");
                if (xTextGeom != null)
                {
                    _Text     = (string)xTextGeom.Attribute("Text") ?? String.Empty;
                    _Position = Point.Parse((string)xTextGeom.Attribute("Position"));
                    _Size     = Size.Parse((string)xTextGeom.Attribute("Size"));
                    _TextSize = Double.Parse((string)xTextGeom.Attribute("TextSize") ?? "12.0", CultureInfo.InvariantCulture);

                    _FontFamily = new FontFamily((string)xTextGeom.Attribute("FontFamily") ?? "Arial");
                    var fsc = new FontStyleConverter();
                    _FontStyle = (FontStyle)fsc.ConvertFromInvariantString((string)xTextGeom.Attribute("FontStyle") ?? "Normal");
                    var fwc = new FontWeightConverter();
                    _FontWeight = (FontWeight)fwc.ConvertFromInvariantString((string)xTextGeom.Attribute("FontWeight") ?? "Normal");
                    _Alignment  = (TextAlignment)Enum.Parse(typeof(TextAlignment), (string)xTextGeom.Attribute("TextAlignment") ?? "Left");
                    _Trimming   = (TextTrimming)Enum.Parse(typeof(TextTrimming), (string)xTextGeom.Attribute("TextTrimming") ?? "None");
                }
            }

            UpdateGeometry();
        }
 static FontWeight?ParseFontWeight(string fontWeight)
 {
     if (string.IsNullOrEmpty(fontWeight))
     {
         return(null);
     }
     return((FontWeight?)FontWeightConverter.ConvertFromInvariantString(fontWeight));
 }
Example #3
0
 public static FontWeight GetFontWeightFromInvariantStringOrNormal(string value)
 {
     try
     {
         return((FontWeight)fontWeightConverter.ConvertFromInvariantString(value));
     }
     catch {
         return(FontWeights.Normal);
     }
 }
Example #4
0
        /// <summary>
        /// Convert a string representation into a null-able <seealso cref="FontWeight"/> object and return it.
        /// </summary>
        /// <param name="stringAttribName"></param>
        /// <param name="fontWeight"></param>
        /// <param name="converter"></param>
        /// <returns></returns>
        protected static FontWeight?ParseFontWeight(string stringAttribName, string fontWeight, FontWeightConverter converter)
        {
            if (string.IsNullOrEmpty(fontWeight))
            {
                return(null);
            }

            try
            {
                return((FontWeight?)converter.ConvertFromInvariantString(fontWeight));
            }
            catch (Exception exp)
            {
                throw new Exception(string.Format(CultureInfo.InvariantCulture, "Invalid FontWeight attribute value '{0}'=\"{1}\"", stringAttribName, fontWeight), exp);
            }
        }
        public static FontWeight GetFontWeightFromInvariantStringOrNormal(string value)
        {
            if (value == null)
            {
                return(FontWeights.Normal);
            }

            try
            {
                return((FontWeight)_fontWeightConverter.ConvertFromInvariantString(value));
            }
            catch (NotSupportedException e)
            {
                Log.Exception($"Can't convert {value} to FontWeight", e, MethodBase.GetCurrentMethod().DeclaringType);
                return(FontWeights.Normal);
            }
        }