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 FontStyle?ParseFontStyle(string fontStyle) { if (string.IsNullOrEmpty(fontStyle)) { return(null); } return((FontStyle?)FontStyleConverter.ConvertFromInvariantString(fontStyle)); }
public static FontStyle GetFontStyleFromInvariantStringOrNormal(string value) { try { return((FontStyle)fontStyleConverter.ConvertFromInvariantString(value)); } catch { return(FontStyles.Normal); } }
/// <summary> /// Convert a string representation into a null-able <seealso cref="FontStyle"/> object and return it. /// </summary> /// <param name="stringAttribName"></param> /// <param name="fontStyle"></param> /// <param name="converter"></param> /// <returns></returns> protected static FontStyle?ParseFontStyle(string stringAttribName, string fontStyle, FontStyleConverter converter) { if (string.IsNullOrEmpty(fontStyle)) { return(null); } try { return((FontStyle?)converter.ConvertFromInvariantString(fontStyle)); } catch (Exception exp) { throw new Exception(string.Format(CultureInfo.InvariantCulture, "Invalid FontStyle attribute value '{0}'=\"{1}\"", stringAttribName, fontStyle), exp); } }
public static FontStyle GetFontStyleFromInvariantStringOrNormal(string value) { if (value == null) { return(FontStyles.Normal); } try { return((FontStyle)_fontStyleConverter.ConvertFromInvariantString(value)); } catch (NotSupportedException e) { Log.Exception($"Can't convert {value} to FontStyle", e, MethodBase.GetCurrentMethod().DeclaringType); return(FontStyles.Normal); } }