private void InitText() { try { var fwc = new FontWeightConverter(); var fsc = new FontStyleConverter(); if (Properties.Settings.Default.Plot_FG_Color != null) { _fgBrush = new SolidColorBrush( System.Windows.Media.Color.FromRgb( Properties.Settings.Default.Plot_FG_Color.R, Properties.Settings.Default.Plot_FG_Color.G, Properties.Settings.Default.Plot_FG_Color.B)); } // Overall graph text properties... LineGraph.FontFamily = new System.Windows.Media.FontFamily(Properties.Settings.Default.Plot_Font_Name); LineGraph.FontSize = double.Parse(Properties.Settings.Default.Plot_Font_Size); LineGraph.FontWeight = (FontWeight)fwc.ConvertFromString(Properties.Settings.Default.Plot_Font_Weight); LineGraph.FontStyle = (FontStyle)fsc.ConvertFromString(Properties.Settings.Default.Plot_Font_Style); LineGraph.Foreground = _fgBrush; } catch { } }
/// <summary> /// Helper function that converts the values stored in the settings into the font values /// and then sets the tasklist font values. /// </summary> public void SetFont() { var family = new FontFamily(User.Default.TaskListFontFamily); double size = User.Default.TaskListFontSize; var styleConverter = new FontStyleConverter(); FontStyle style = (FontStyle)styleConverter.ConvertFromString(User.Default.TaskListFontStyle); var stretchConverter = new FontStretchConverter(); FontStretch stretch = (FontStretch)stretchConverter.ConvertFromString(User.Default.TaskListFontStretch); var weightConverter = new FontWeightConverter(); FontWeight weight = (FontWeight)weightConverter.ConvertFromString(User.Default.TaskListFontWeight); Color color = (Color)ColorConverter.ConvertFromString(User.Default.TaskListFontBrushColor); lbTasks.FontFamily = family; lbTasks.FontSize = size; lbTasks.FontStyle = style; lbTasks.FontStretch = stretch; lbTasks.FontWeight = weight; lbTasks.Foreground = new SolidColorBrush(color); }
private void InitTextTitle() { try { var fwc = new FontWeightConverter(); var fsc = new FontStyleConverter(); if (Properties.Settings.Default.Plot_FG_Color_Title != null) { _fgBrushTitle = new SolidColorBrush( System.Windows.Media.Color.FromRgb( Properties.Settings.Default.Plot_FG_Color_Title.R, Properties.Settings.Default.Plot_FG_Color_Title.G, Properties.Settings.Default.Plot_FG_Color_Title.B)); } // Title... GraphTitle.FontFamily = new System.Windows.Media.FontFamily(Properties.Settings.Default.Plot_Font_Name_Title); GraphTitle.FontSize = double.Parse(Properties.Settings.Default.Plot_Font_Size_Title); GraphTitle.FontWeight = (FontWeight)fwc.ConvertFromString(Properties.Settings.Default.Plot_Font_Weight_Title); GraphTitle.FontStyle = (FontStyle)fsc.ConvertFromString(Properties.Settings.Default.Plot_Font_Style_Title); GraphTitle.Foreground = _fgBrushTitle; } catch { } }
private FontStyle GetFontStyle() { var fontStyleConverter = new FontStyleConverter(); var fontStyle = (FontStyle)fontStyleConverter.ConvertFromString(FontStyle); return(fontStyle); }
public SSViewModel() { ModelElements = new ObservableCollection <SSElementBaseViewModel>(); _colorCvtr = new BrushConverter(); _fscvtr = new FontStyleConverter(); _fwcvtr = new FontWeightConverter(); }
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(); }
protected virtual void LoadRegistryInfo(RegistryKey regkey) { string selectedLanguagesText = (string)regkey.GetValue(strOcrLanguage, String.Empty); dataSource.SelectedLanguages = new ObservableCollection <string>(selectedLanguagesText.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(p => p.Trim()).Distinct().ToList()); curLangCode = GetLangCodes(selectedLanguagesText); this.textBox1.TextWrapping = (TextWrapping)regkey.GetValue(strWordWrap, TextWrapping.NoWrap); this.textBox1.FontFamily = new System.Windows.Media.FontFamily(regkey.GetValue(strFontFace, "Microsoft Sans Serif").ToString()); this.textBox1.FontSize = double.Parse((string)regkey.GetValue(strFontSize, "10")); var fsc = new FontStyleConverter(); this.textBox1.FontStyle = (FontStyle)fsc.ConvertFromString((string)regkey.GetValue(strFontStyle, "Normal")); var bc = new BrushConverter(); this.textBox1.Foreground = (Brush)bc.ConvertFromString((string)regkey.GetValue(strForeColor, "Black")); this.textBox1.Background = (Brush)bc.ConvertFromString((string)regkey.GetValue(strBackColor, "White")); filterIndex = (int)regkey.GetValue(strFilterIndex, 1); selectedUILanguage = Thread.CurrentThread.CurrentUICulture.Name; this.segmentedRegionsToolStripMenuItem.IsChecked = Convert.ToBoolean((int)regkey.GetValue(strSegmentedRegions, Convert.ToInt32(false))); this.buttonSegmentedRegions.Visibility = this.segmentedRegionsToolStripMenuItem.IsChecked ? Visibility.Visible : Visibility.Hidden; this.toolStripMenuItemPara.IsChecked = Convert.ToBoolean((int)regkey.GetValue(strSegmentedRegionsPara, Convert.ToInt32(false))); this.toolStripMenuItemTextLine.IsChecked = Convert.ToBoolean((int)regkey.GetValue(strSegmentedRegionsTextLine, Convert.ToInt32(false))); this.toolStripMenuItemSymbol.IsChecked = Convert.ToBoolean((int)regkey.GetValue(strSegmentedRegionsSymbol, Convert.ToInt32(false))); this.toolStripMenuItemBlock.IsChecked = Convert.ToBoolean((int)regkey.GetValue(strSegmentedRegionsBlock, Convert.ToInt32(false))); this.toolStripMenuItemWord.IsChecked = Convert.ToBoolean((int)regkey.GetValue(strSegmentedRegionsWord, Convert.ToInt32(false))); }
static FontStyle?ParseFontStyle(string fontStyle) { if (string.IsNullOrEmpty(fontStyle)) { return(null); } return(FontStyleConverter.ConvertFromString(fontStyle)); }
/// <summary> /// Internal API for loading text. Sets a text block's font style. /// </summary> /// <param name="FBlockToSet">The Block to set the font style of.</param> /// <param name="FontStyle">The font family in string form to set the Block's font style to.</param> /// <returns>A Block with the font style set.</returns> internal Block FMXAML_TextAPI_SetFontStyle(Block FBlockToSet, string FontStyle) // Sets the font style. { FontStyleConverter _FontStyleConverter = new FontStyleConverter(); FontStyle _FinalFontStyle = (FontStyle)_FontStyleConverter.ConvertFromString(FontStyle); FBlockToSet.FontStyle = _FinalFontStyle; return(FBlockToSet); }
/// <summary> /// Initializes a new instance of the <see cref="TextEditorOptionsPageViewModel"/> class. /// (Do not use this constructor it is only for design-time support!) /// </summary> public TextEditorOptionsPageViewModel() : base("Text Editor") { Trace.Assert(WindowsHelper.IsInDesignMode, "This TextEditorOptionsPageViewModel constructor must not be used at runtime."); Options = new TextEditorOptions(); _fontStyleConverter = new FontStyleConverter(); _fontWeightConverter = new FontWeightConverter(); }
private void InitSeries1() { var fwc = new FontWeightConverter(); var fsc = new FontStyleConverter(); ((LegendItem)LineGraph.LegendItems[0]).FontFamily = new System.Windows.Media.FontFamily(Properties.Settings.Default.Plot_Font_Name); ((LegendItem)LineGraph.LegendItems[0]).FontSize = double.Parse(Properties.Settings.Default.Plot_Font_Size); ((LegendItem)LineGraph.LegendItems[0]).FontWeight = (FontWeight)fwc.ConvertFromString(Properties.Settings.Default.Plot_Font_Weight); ((LegendItem)LineGraph.LegendItems[0]).FontStyle = (FontStyle)fsc.ConvertFromString(Properties.Settings.Default.Plot_Font_Style); ((LegendItem)LineGraph.LegendItems[0]).Foreground = _fgBrush; }
public static bool CanParseFontStyle(string fontStyleName) { try { FontStyleConverter converter = new FontStyleConverter(); converter.ConvertFromString(fontStyleName); return(true); } catch { return(false); } }
public static FontStyle ParseStyle(string styleString) { FontStyle style = FontStyles.Normal; FontStyleConverter converter = new FontStyleConverter(); try { style = (FontStyle)converter.ConvertFromString(styleString); } catch { } return(style); }
private void ComboBoxStyleTitleSelectionChanged(object sender, SelectionChangedEventArgs e) { if (ComboBoxStyleTitle.SelectedValue == null) { return; } var fontStyle = (string)ComboBoxStyleTitle.SelectedValue; var fsc = new FontStyleConverter(); PlotFontStyleTitle = (FontStyle)fsc.ConvertFromString(fontStyle); TextBlockExampleTitle.FontStyle = PlotFontStyleTitle; Properties.Settings.Default.Plot_Font_Style_Title = fontStyle; GraphUc.UpdateStyles(); }
/// <summary> /// Internal API for loading text. Sets a text block's font style. (INLINE OVERLOAD) /// </summary> /// <param name="FBlockToSet">The Block to set the font style of.</param> /// <param name="FontStyle">The font family in string form to set the Block's font style to.</param> /// <returns>An Inline with the font style set.</returns> internal Inline FMXAML_TextAPI_SetFontStyle(Inline FBlockToSet, string FontStyle) // Sets the font style. { try { FontStyleConverter _FontStyleConverter = new FontStyleConverter(); FontStyle _FinalFontStyle = (FontStyle)_FontStyleConverter.ConvertFromString(FontStyle); FBlockToSet.FontStyle = _FinalFontStyle; return(FBlockToSet); } catch (FormatException err) { FError.ThrowError(15, "An invalid string was supplied.", FErrorSeverity.FatalError, err); return(null); } }
/// <summary> /// Convert FontStyle to string for serialization /// </summary> public static string FontStyleToString(FontStyle value) { string result; try { result = new FontStyleConverter().ConvertToString(value); } catch (NotSupportedException) { result = ""; } return(result); }
/// <summary> /// Initializes a new instance of the <see cref="TextEditorOptionsPageViewModel"/> class. /// </summary> /// <param name="textExtension">The <see cref="TextExtension"/>.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="textExtension"/> is <see langword="null"/>. /// </exception> public TextEditorOptionsPageViewModel(TextExtension textExtension) : base("Text Editor") { if (textExtension == null) { throw new ArgumentNullException(nameof(textExtension)); } _textExtension = textExtension; Options = new TextEditorOptions(); SetDefaultsCommand = new DelegateCommand(SetDefaults); SelectFontCommand = new DelegateCommand(SelectFont); _fontStretchConverter = new FontStretchConverter(); _fontStyleConverter = new FontStyleConverter(); _fontWeightConverter = new FontWeightConverter(); }
/// <summary> /// Deserializes a HighlightingColor. /// </summary> protected HighlightingColor(SerializationInfo info, StreamingContext context) { if (info == null) { throw new ArgumentNullException("info"); } this.Name = info.GetString("Name"); if (info.GetBoolean("HasWeight")) { this.FontWeight = TextAddin.FontWeight.FromOpenTypeWeight(info.GetInt32("Weight")); } if (info.GetBoolean("HasStyle")) { this.FontStyle = FontStyleConverter.ConvertFromString(info.GetString("Style")); } this.Foreground = (Color)info.GetValue("Foreground", typeof(Color)); this.Background = (Color)info.GetValue("Background", typeof(Color)); }
void WriteColorAttributes(XshdColor color) { if (color.Foreground != null) { writer.WriteAttributeString("foreground", color.Foreground.ToString()); } if (color.Background != null) { writer.WriteAttributeString("background", color.Background.ToString()); } if (color.FontWeight != null) { writer.WriteAttributeString("fontWeight", FontWeightConverter.ConvertToString(color.FontWeight.Value).ToLowerInvariant()); } if (color.FontStyle != null) { writer.WriteAttributeString("fontStyle", FontStyleConverter.ConvertToString(color.FontStyle.Value).ToLowerInvariant()); } }
/// <summary> /// Convert string to FontStyle for serialization /// </summary> public static FontStyle FontStyleFromString(string value) { var result = FontStyles.Normal; try { var convertFromString = new FontStyleConverter().ConvertFromString((value)); if (convertFromString != null) { result = (FontStyle)convertFromString; } } catch (NotSupportedException) { } catch (FormatException) { } return(result); }
private void FontMI_Click(object sender, RoutedEventArgs e) { FontDialog dialog = new FontDialog(); if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { var font = dialog.Font; txtField.FontFamily = new FontFamily(font.FontFamily.Name); txtField.FontSize = font.Size; FontStyleConverter conv = new FontStyleConverter(); switch (font.Style) { case System.Drawing.FontStyle.Regular: txtField.FontStyle = FontStyles.Normal; break; case System.Drawing.FontStyle.Bold: txtField.FontStyle = FontStyles.Oblique; break; case System.Drawing.FontStyle.Italic: txtField.FontStyle = FontStyles.Italic; break; default: txtField.FontStyle = FontStyles.Normal; break; } if (font.Underline) { txtField.TextDecorations.Add(TextDecorations.Underline); } if (font.Strikeout) { txtField.TextDecorations.Add(TextDecorations.Strikethrough); } } }
public override void UpdateCustomGeometryProperty() { var customGeomDef = Geometry.GetValue(GeometryExtProps.CustomGeometryProperty); XElement xCustomGeom; if (customGeomDef is string) { xCustomGeom = XElement.Parse((string)customGeomDef); } else { xCustomGeom = new XElement("XDraw2_CustomGeometry", new XAttribute("CompanionAssembly", GetType().Assembly.GetName().Name), new XAttribute("CompanionType", GetType().FullName)); } var xTextGeom = xCustomGeom.Element("TextGeometry"); if (xTextGeom == null) { xTextGeom = new XElement("TextGeometry"); xCustomGeom.Add(xTextGeom); } SetAttr(xTextGeom, "Text", _Text); SetAttr(xTextGeom, "Position", _Position.ToString(CultureInfo.InvariantCulture)); SetAttr(xTextGeom, "Size", _Size.ToString(CultureInfo.InvariantCulture)); SetAttr(xTextGeom, "TextSize", _TextSize.ToString(CultureInfo.InvariantCulture)); SetAttr(xTextGeom, "FontFamily", _FontFamily.Source); var fsc = new FontStyleConverter(); SetAttr(xTextGeom, "FontStyle", fsc.ConvertToInvariantString(_FontStyle)); var fwc = new FontWeightConverter(); SetAttr(xTextGeom, "FontWeight", fwc.ConvertToInvariantString(_FontWeight)); SetAttr(xTextGeom, "TextAlignment", _Alignment.ToString()); SetAttr(xTextGeom, "TextTrimming", _Trimming.ToString()); Geometry.SetValue(GeometryExtProps.CustomGeometryProperty, xCustomGeom.ToString()); }
/// <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 ParseFontStyle(string fontStyleName) { FontStyleConverter converter = new FontStyleConverter(); return((FontStyle)converter.ConvertFromString(fontStyleName)); }
/// <summary> /// Initializes a new instance of the <see cref="SplashScreen"/> class. /// </summary> public SplashScreen() : base(DataWindowMode.Custom) { var assembly = Assembly.GetEntryAssembly(); var titleAttributes = assembly.GetCustomAttributes(typeof(AssemblyTitleAttribute), true); InitializeComponent(); if (titleAttributes.Length > 0) { AppName.Text = ((AssemblyTitleAttribute)titleAttributes[0]).Title; } var copyrightAttributes = assembly.GetCustomAttributes(typeof(AssemblyCopyrightAttribute), true); if (copyrightAttributes.Length > 0) { Copyright.Text = ((AssemblyCopyrightAttribute)copyrightAttributes[0]).Copyright; } var configPath = AppEnvironment.AppPath + @"\Resources\Images\SplashScreen\SplashScreenInfo.xml"; if (File.Exists(configPath)) { //product name var info = XElement.Load(configPath); var productName = info.Element("ProductName"); if (productName != null) { if (!productName.Elements().Any()) { AppName.Text = productName.Value; } else { var text = productName.Element("Text"); if (text != null) { AppName.Text = text.Value; } var fontFile = productName.Element("FontFileDir"); var font = productName.Element("FontFamily"); if (!String.IsNullOrEmpty(font?.Value)) { if (fontFile != null) { var fontFileUri = new Uri("file:///" + AppEnvironment.AppPath + "/" + fontFile.Value + "/"); AppName.FontFamily = new FontFamily(fontFileUri, "./#" + font.Value); } else { AppName.FontFamily = new FontFamily(font.Value.Trim()); } } var size = productName.Element("FontSize"); if (!String.IsNullOrEmpty(size?.Value)) { var myFontSizeConverter = new FontSizeConverter(); var convertFromString = myFontSizeConverter.ConvertFromString(size.Value.Trim()); if (convertFromString != null) { AppName.FontSize = (Double)convertFromString; } } var weight = productName.Element("FontWeight"); if (!String.IsNullOrEmpty(weight?.Value)) { var convertFromString = new FontWeightConverter().ConvertFromString(weight.Value); if (convertFromString != null) { AppName.FontWeight = (FontWeight)convertFromString; } } var style = productName.Element("FontStyle"); if (!String.IsNullOrEmpty(style?.Value)) { var convertFromString = new FontStyleConverter().ConvertFromString(style.Value); if (convertFromString != null) { AppName.FontStyle = (FontStyle)convertFromString; } } var color = productName.Element("Color"); if (!String.IsNullOrEmpty(color?.Value)) { var fromString = new BrushConverter().ConvertFromString(color.Value); if (fromString != null) { var convertFromString = (Brush)fromString; AppName.Foreground = convertFromString; } } var outLineColor = productName.Element("OutlineColor"); if (!String.IsNullOrEmpty(outLineColor?.Value)) { var fromString = ColorConverter.ConvertFromString(outLineColor.Value); if (fromString != null) { var convertFromString = (Color)fromString; AppNameOutline.Color = convertFromString; } } var margin = productName.Element("Margin"); if (!String.IsNullOrEmpty(margin?.Value)) { var fromString = new ThicknessConverter().ConvertFromString(margin.Value); if (fromString != null) { var convertFromString = (Thickness)fromString; AppName.Margin = convertFromString; } } var horizontalAlignment = productName.Element("HorizontalAlignment"); if (!String.IsNullOrEmpty(horizontalAlignment?.Value)) { HorizontalAlignment convertFromString; var r = Enum.TryParse(horizontalAlignment.Value, out convertFromString); if (r) { AppName.HorizontalAlignment = convertFromString; } } } } //sub title var subTitle = info.Element("SubTitle"); if (subTitle != null) { if (!subTitle.Elements().Any()) { SubTitle.Text = subTitle.Value; } else { var text = subTitle.Element("Text"); if (text != null) { SubTitle.Text = text.Value; } else { SubTitle.Height = 0; } var fontFile = subTitle.Element("FontFileDir"); var font = subTitle.Element("FontFamily"); if (!String.IsNullOrEmpty(font?.Value)) { if (fontFile != null) { var fontFileUri = new Uri("file:///" + AppEnvironment.AppPath + "/" + fontFile.Value + "/"); SubTitle.FontFamily = new FontFamily(fontFileUri, "./#" + font.Value); } else { SubTitle.FontFamily = new FontFamily(font.Value.Trim()); } } var size = subTitle.Element("FontSize"); if (!String.IsNullOrEmpty(size?.Value)) { var myFontSizeConverter = new FontSizeConverter(); var convertFromString = myFontSizeConverter.ConvertFromString(size.Value.Trim()); if (convertFromString != null) { SubTitle.FontSize = (Double)convertFromString; } } var weight = subTitle.Element("FontWeight"); if (!String.IsNullOrEmpty(weight?.Value)) { var convertFromString = new FontWeightConverter().ConvertFromString(weight.Value); if (convertFromString != null) { SubTitle.FontWeight = (FontWeight)convertFromString; } } var style = subTitle.Element("FontStyle"); if (!String.IsNullOrEmpty(style?.Value)) { var convertFromString = new FontStyleConverter().ConvertFromString(style.Value); if (convertFromString != null) { SubTitle.FontStyle = (FontStyle)convertFromString; } } var color = subTitle.Element("Color"); if (!String.IsNullOrEmpty(color.Value)) { var fromString = new BrushConverter().ConvertFromString(color.Value); if (fromString != null) { var convertFromString = (Brush)fromString; SubTitle.Foreground = convertFromString; } } var outLineColor = subTitle.Element("OutlineColor"); if (!String.IsNullOrEmpty(outLineColor?.Value)) { var fromString = (Color)ColorConverter.ConvertFromString(outLineColor.Value); if (fromString != null) { var convertFromString = fromString; SubTitleOutline.Color = convertFromString; } } var margin = subTitle.Element("Margin"); if (!String.IsNullOrEmpty(margin?.Value)) { var fromString = new ThicknessConverter().ConvertFromString(margin.Value); if (fromString != null) { var convertFromString = (Thickness)fromString; SubTitle.Margin = convertFromString; } } var horizontalAlignment = subTitle.Element("HorizontalAlignment"); if (!String.IsNullOrEmpty(horizontalAlignment?.Value)) { HorizontalAlignment convertFromString; var r = Enum.TryParse(horizontalAlignment.Value, out convertFromString); if (r) { SubTitle.HorizontalAlignment = convertFromString; } } } } else { SubTitle.Height = 0; } //copy right var copyright = info.Element("Copyright"); if (!string.IsNullOrEmpty(copyright?.Value)) { Copyright.Text = copyright.Value; } else { Copyright.Height = 0; } //info positon var infoPosition = info.Element("Margin"); if (!string.IsNullOrEmpty(infoPosition?.Value)) { var fromString = new ThicknessConverter().ConvertFromString(infoPosition.Value); if (fromString != null) { var convertFromString = (Thickness)fromString; statusPanel.Margin = convertFromString; } } var width = info.Element("Width"); if (!string.IsNullOrEmpty(width?.Value)) { double fromString; var r = double.TryParse(width.Value, out fromString); if (r) { statusPanel.Width = fromString; } } } CustomiseSplashScreen(); }
private void InitText() { var fwc = new FontWeightConverter(); var fsc = new FontStyleConverter(); FontSelector.ItemsSource = Fonts.SystemFontFamilies; var fontIndex = -1; // Font name... if (string.IsNullOrEmpty(Properties.Settings.Default.Plot_Font_Name)) { var g = new Graph(null, null); _fontName = g.FontFamily.Source; Properties.Settings.Default.Plot_Font_Name = _fontName; } else { _fontName = Properties.Settings.Default.Plot_Font_Name; } // Font size... if (string.IsNullOrEmpty(Properties.Settings.Default.Plot_Font_Size)) { PlotFontSize = 12; } else { try { PlotFontSize = double.Parse(Properties.Settings.Default.Plot_Font_Size); } catch { } } // Font weight... if (string.IsNullOrEmpty(Properties.Settings.Default.Plot_Font_Weight)) { PlotFontWeight = (FontWeight)fwc.ConvertFromString("Normal"); } else { PlotFontWeight = (FontWeight)fwc.ConvertFromString(Properties.Settings.Default.Plot_Font_Weight); } // Font style... if (string.IsNullOrEmpty(Properties.Settings.Default.Plot_Font_Style)) { PlotFontStyle = (FontStyle)fsc.ConvertFromString("Normal"); } else { PlotFontStyle = (FontStyle)fsc.ConvertFromString(Properties.Settings.Default.Plot_Font_Style); } foreach (System.Windows.Media.FontFamily ff in FontSelector.Items) { fontIndex++; if (System.String.Compare(ff.Source, _fontName, System.StringComparison.Ordinal) == 0) { _fontFamily = ff; break; } } // Font FG color if (Properties.Settings.Default.Plot_FG_Color != null) { _fgBrush = new SolidColorBrush( System.Windows.Media.Color.FromRgb( Properties.Settings.Default.Plot_FG_Color.R, Properties.Settings.Default.Plot_FG_Color.G, Properties.Settings.Default.Plot_FG_Color.B)); } // Init the controls FontSelector.SelectedIndex = fontIndex; ComboBoxStyle.SelectedValue = fsc.ConvertToString(PlotFontStyle); ComboBoxWeight.SelectedValue = fwc.ConvertToString(PlotFontWeight); SliderFontSize.DataContext = this; }
/// <summary> /// Read the WordsStyle XML tag with its attributes (if any) and return /// a resulting <seealso cref="WordsStyle"/> object. /// </summary> internal static WordsStyle ReadNode(XmlReader reader) { WordsStyle ret = null; FontWeightConverter FontWeightConverter = new FontWeightConverter(); FontStyleConverter FontStyleConverter = new FontStyleConverter(); string name = string.Empty; string fgColor = string.Empty; string bgColor = string.Empty; string fontWeight = string.Empty; string FontStyle = string.Empty; reader.ReadToNextSibling(ReadWordsStyle.XMLName); while (reader.MoveToNextAttribute()) { switch (reader.Name) { case ReadWordsStyle.attr_name: name = reader.Value; break; case ReadWordsStyle.attr_fgColor: fgColor = (reader.Value == null ? string.Empty : reader.Value); break; case ReadWordsStyle.attr_bgColor: bgColor = (reader.Value == null ? string.Empty : reader.Value); break; case ReadWordsStyle.attr_fontWeight: fontWeight = (reader.Value == null ? string.Empty : reader.Value); break; case ReadWordsStyle.attr_FontStyle: FontStyle = (reader.Value == null ? string.Empty : reader.Value); break; case XMLNameSpace: break; default: if (reader.Name.Trim().Length > 0 && reader.Name != XMLComment) { logger.Warn("Parsing the XML child:'" + reader.Name + "' of '" + ReadLexerType.XMLName + "' is not implemented."); } break; } } ret = new WordsStyle(name); if (fgColor != string.Empty) { ret.fgColor = ReadWordsStyle.SetColorFromString(ReadWordsStyle.attr_fgColor, fgColor); } if (bgColor != string.Empty) { ret.bgColor = ReadWordsStyle.SetColorFromString(ReadWordsStyle.attr_bgColor, bgColor); } if (fontWeight != string.Empty) { ret.fontWeight = ParseFontWeight(ReadWordsStyle.attr_fontWeight, fontWeight, FontWeightConverter); } if (FontStyle != string.Empty) { ret.fontStyle = ParseFontStyle(ReadWordsStyle.attr_FontStyle, FontStyle, FontStyleConverter); } return(ret); }
/// <summary> /// Serializes the font style. /// </summary> /// <param name="fontStyle">The font style.</param> /// <returns>The serialized font style.</returns> public static string SerializeFontStyle(FontStyle fontStyle) { var converter = new FontStyleConverter(); return(converter.ConvertToString(fontStyle)); }
/// <summary> /// Deserializes the font style. /// </summary> /// <param name="fontStyle">The font style.</param> /// <returns>The deserialized font style.</returns> public static FontStyle DeserializeFontStyle(string fontStyle) { var converter = new FontStyleConverter(); return((FontStyle)converter.ConvertFromString(fontStyle)); }