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
            {
            }
        }
Example #2
0
        /// <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
            {
            }
        }
Example #4
0
        private FontWeight GetFontWeight()
        {
            var fontWeightConverter = new FontWeightConverter();
            var fontWeight          = (FontWeight)fontWeightConverter.ConvertFromString(FontWeight);

            return(fontWeight);
        }
Example #5
0
        private void ChangeFontStyle(string command, string value)
        {
            switch (command)
            {
            case "weight":
                FontWeightConverter weightConverter = new FontWeightConverter();
                txtSpeech.FontWeight = (FontWeight)weightConverter.ConvertFromString(value);
                break;

            case "color":
                txtSpeech.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString(value));
                break;

            case "size":
                switch (value)
                {
                case "small":
                    txtSpeech.FontSize = 12;
                    break;

                case "medium":
                    txtSpeech.FontSize = 24;
                    break;

                case "large":
                    txtSpeech.FontSize = 48;
                    break;
                }
                break;
            }
        }
Example #6
0
 static FontWeight?ParseFontWeight(string fontWeight)
 {
     if (string.IsNullOrEmpty(fontWeight))
     {
         return(null);
     }
     return(FontWeightConverter.ConvertFromString(fontWeight));
 }
Example #7
0
 private static FontWeight GetThemeFontWeight(string element, string attribute, FontWeight fallback)
 {
     try {
         return((FontWeight)_fontWeightConverter.ConvertFromString(GetThemeValue(element, attribute)));
     }
     catch {
         return(fallback);
     }
 }
        /// <summary>
        /// 转换
        /// </summary>
        /// <param name="attribute">属性</param>
        /// <returns>是否转化成果</returns>
        public override bool Parse(SVGAttribute attribute)
        {
            SVGFontWeight result = new SVGFontWeight();

            result.Value = (FontWeight)Converter.ConvertFromString(attribute.Value);

            attribute.Data = result;

            return(true);
        }
Example #9
0
        public void SetSizes(double x1, double y1, double x2, double y2, double Thickness, double x3, double y3, string text, string fontWeight, string Color, string Tag)
        {
            Line Sizeline = new Line();

            SetLine(Sizeline, x1, y1, x2, y2, Thickness, Color, Tag);
            storyboard = new Storyboard();

            TextBlock textBlock = new TextBlock();

            textBlock.Text       = text;
            textBlock.Foreground = (Brush)Converter.ConvertFromString(Color);
            Canvas.SetLeft(textBlock, x3);
            Canvas.SetTop(textBlock, y3);
            textBlock.FontWeight = (FontWeight)WConverter.ConvertFromString(fontWeight);
            Canvas.Children.Add(textBlock);


            textBlock.Tag = Tag;
        }
        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;
        }
Example #11
0
        public static FontWeight ParseWeight(string weightString)
        {
            FontWeight          weight    = FontWeights.Normal;
            FontWeightConverter converter = new FontWeightConverter();

            try {
                weight = (FontWeight)converter.ConvertFromString(weightString);
            }
            catch {
            }

            return(weight);
        }
 public static bool CanParseFontWeight(string fontWeightName)
 {
     try
     {
         FontWeightConverter converter = new FontWeightConverter();
         converter.ConvertFromString(fontWeightName);
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Example #13
0
        public static FontFace GetFontFaceInfo(string font, MediaCenterTheme theme)
        {
            FontFace          fontFace = new FontFace();
            List <FontFamily> list     = new List <FontFamily>();

            if (theme != null)
            {
                list.AddRange(theme.Fonts);
            }

            InstallMediaCenterFonts();

            list.AddRange(Fonts.SystemFontFamilies);

            foreach (FontFamily fontFamily in list)
            {
                string name = FontUtil.GetName(fontFamily);
                if (font.StartsWith(name))
                {
                    fontFace.FontFamily = name;
                    FontWeightConverter fontWeightConverter = new FontWeightConverter();
                    string str     = font.Substring(name.Length).Trim();
                    char[] chArray = new char[1] {
                        ' '
                    };
                    foreach (string text in str.Split(chArray))
                    {
                        if (!string.IsNullOrEmpty(text))
                        {
                            try
                            {
                                fontFace.FontWeight = (FontWeight)fontWeightConverter.ConvertFromString(text);
                            }
                            catch (FormatException)
                            {
                            }
                        }
                    }
                    break;
                }
            }
            if (fontFace.FontFamily == null)
            {
                return((FontFace)null);
            }
            else
            {
                return(fontFace);
            }
        }
Example #14
0
        private void ComboBoxWeightTitleSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (ComboBoxWeightTitle.SelectedValue == null)
            {
                return;
            }

            var fontWeight = (string)ComboBoxWeightTitle.SelectedValue;
            var fwc        = new FontWeightConverter();

            PlotFontWeightTitle = (FontWeight)fwc.ConvertFromString(fontWeight);
            TextBlockExampleTitle.FontWeight = PlotFontWeightTitle;
            Properties.Settings.Default.Plot_Font_Weight_Title = fontWeight;
            GraphUc.UpdateStyles();
        }
Example #15
0
        internal static Typeface CreateTypeFace(string fontFamily, string fontStyle, string fontWeight, string fontStretch, string fallbackFontFamily)
        {
            if ((fontFamily == null) || (fontStyle == null) || (fontWeight == null) || (fontStretch == null))
            {
                return(null);
            }

            FontFamily  family  = new FontFamily(fontFamily);
            FontStyle   style   = (FontStyle)styleConverter.ConvertFromString(fontStyle);
            FontWeight  weight  = (FontWeight)weightConverter.ConvertFromString(fontWeight);
            FontStretch stretch = (FontStretch)stretchConverter.ConvertFromString(fontStretch);

            if (fallbackFontFamily == null)
            {
                return(new Typeface(family, style, weight, stretch));
            }
            else
            {
                return(new Typeface(family, style, weight, stretch, new FontFamily(fallbackFontFamily)));
            }
        }
Example #16
0
        private void speechRecognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            //lblDemo.Content = e.Result.Text;
            if (e.Result.Words.Count == 2)
            {
                string command = e.Result.Words[0].Text.ToLower();
                string value   = e.Result.Words[1].Text.ToLower();
                switch (command)
                {
                case "weight":
                    FontWeightConverter weightConverter = new FontWeightConverter();
                    lblDemo.FontWeight = (FontWeight)weightConverter.ConvertFromString(value);
                    break;

                case "color":
                    lblDemo.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString(value));
                    break;

                case "size":
                    switch (value)
                    {
                    case "small":
                        lblDemo.FontSize = 12;
                        break;

                    case "medium":
                        lblDemo.FontSize = 24;
                        break;

                    case "large":
                        lblDemo.FontSize = 48;
                        break;
                    }
                    break;
                }
            }
        }
Example #17
0
        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;
        }
        public static FontWeight ParseFontWeight(string fontWeightName)
        {
            FontWeightConverter converter = new FontWeightConverter();

            return((FontWeight)converter.ConvertFromString(fontWeightName));
        }
Example #19
0
        public static object GetDPValueFromStr(this DependencyProperty dp, string str)
        {
            if (str == null)
            {
                return(null);
            }

            Type type = dp.PropertyType;

            if (type.IsEnum)
            {
                return(Enum.Parse(type, str));
            }

            if (type == typeof(double))
            {
                return(double.Parse(str));
            }

            if (type == typeof(float))
            {
                return(float.Parse(str));
            }

            if (type == typeof(decimal))
            {
                return(decimal.Parse(str));
            }

            if (type == typeof(string))
            {
                return(str);
            }

            if (type == typeof(bool))
            {
                return(bool.Parse(str));
            }

            if (type == typeof(byte))
            {
                return(byte.Parse(str));
            }

            if (type == typeof(int))
            {
                return(int.Parse(str));
            }

            if (type == typeof(char))
            {
                return(char.Parse(str));
            }

            if (type == typeof(Brush))
            {
                if (string.IsNullOrEmpty(str))
                {
                    return(null);
                }

                Color color = (Color)ColorConverter.ConvertFromString(str);

                return(new SolidColorBrush(color));
            }

            if (type == typeof(Thickness))
            {
                return(_thicknessConverter.ConvertFromString(str));
            }

            if (type == typeof(FontFamily))
            {
                return(_fontFamilyConverter.ConvertFromString(str));
            }

            if (type == typeof(FontWeight))
            {
                return(_fontWeightConverter.ConvertFromString(str));
            }

            if (type == typeof(Point))
            {
                return(_pointConverter.ConvertFromString(str));
            }

            return(str);
        }
Example #20
0
        /// <summary>
        /// Deserializes the font weight.
        /// </summary>
        /// <param name="fontWeight">The font weight.</param>
        /// <returns>The deserialized font weight.</returns>
        public static FontWeight DeserializeFontWeight(string fontWeight)
        {
            var converter = new FontWeightConverter();

            return((FontWeight)converter.ConvertFromString(fontWeight));
        }
Example #21
0
        public bool LoadFile(string filePath)
        {
            if (string.IsNullOrEmpty(filePath) || !File.Exists(filePath))
            {
                return(false);
            }

            XDocument xmlDoc = new XDocument();

            xmlDoc = XDocument.Load(filePath);

            XElement root = xmlDoc.Elements("root").FirstOrDefault();

            if (root == null)
            {
                return(false);
            }

            XElement drags = root.Elements("FlowDesigns").FirstOrDefault();

            if (drags == null)
            {
                return(false);
            }

            RemoveAllDragThumb(); //清除所有

            IEnumerable <XElement> nodes = drags.Elements();

            foreach (XElement item in nodes)
            {
                string name        = item.Attribute("Name")?.Value ?? "";
                string position    = item.Attribute("Position")?.Value ?? "0,0";
                string size        = item.Attribute("Size")?.Value ?? "10,10";
                string source      = item.Attribute("Source")?.Value ?? "";              //图片路径
                string sBackground = item.Attribute("Background")?.Value ?? "#FF00ACFF"; //背景色
                Brush  background  = new SolidColorBrush((Color)ColorConverter.ConvertFromString(sBackground));

                string sBorderBrush = item.Attribute("BorderBrush")?.Value ?? "White"; //边框
                Brush  borderBrush  = new SolidColorBrush((Color)ColorConverter.ConvertFromString(sBorderBrush));

                EmFlowCtrlType ctrlType =
                    (EmFlowCtrlType)
                    System.Enum.Parse(typeof(EmFlowCtrlType), item.Attribute("ItemType")?.Value ?? "None");      //控件类型
                EmBasicShape shapeType =
                    (EmBasicShape)System.Enum.Parse(typeof(EmBasicShape), item.Attribute("Shape")?.Value ?? "None");

                DragThumb newThumb = new DragThumb();

                if (ctrlType == EmFlowCtrlType.Image)
                {
                    if (!source.Contains(":"))
                    {
                        source = System.Environment.CurrentDirectory + (source[0] == '/' ? "" : "/") + source;
                    }
                    if (File.Exists(source))
                    {
                        newThumb = AddDragImage(name, SafeConverter.SafeToSize(size),
                                                SafeConverter.SafeToPoint(position),
                                                new BitmapImage(new Uri(source)), background, borderBrush);
                    }
                }
                else if (ctrlType == EmFlowCtrlType.PolygonSharp)
                {
                    newThumb = AddDragShape(name, shapeType, SafeConverter.SafeToSize(size),
                                            SafeConverter.SafeToPoint(position), background, borderBrush);
                }
                else if (ctrlType == EmFlowCtrlType.CircleSharp)
                {
                    newThumb = AddDragCircle(name, SafeConverter.SafeToSize(size),
                                             SafeConverter.SafeToPoint(position), background, borderBrush);
                }
                else if (ctrlType == EmFlowCtrlType.Video)
                {
                    newThumb = AddDragVideo(name, SafeConverter.SafeToSize(size),
                                            SafeConverter.SafeToPoint(position), source);
                }
                string sForeground = item.Attribute("Foreground")?.Value ?? "#FF000000"; //字体颜色
                Brush  foreground  = new SolidColorBrush((Color)ColorConverter.ConvertFromString(sForeground));
                newThumb.Foreground = foreground;
                string sFontWeight          = item.Attribute("FontWeight")?.Value ?? "Normal"; //文本粗体
                FontWeightConverter convert = new FontWeightConverter();
                newThumb.FontWeight = (FontWeight)convert.ConvertFromString(sFontWeight);
                string sFontSize = item.Attribute("FontSize")?.Value ?? "12";  //文字大小
                newThumb.FontSize = Double.Parse(sFontSize);

                newThumb.MonitorItem      = SafeConverter.SafeToBool(item.Attribute("Monitor"));          //是否监控
                newThumb.ReadOnlyCanClick = SafeConverter.SafeToBool(item.Attribute("ReadOnlyCanClick")); //是否可以单击

                string text = item.Attribute("Text")?.Value ?? "";
                newThumb.Text = text;
            }
            return(true);
        }
        public static void SetPropertyValue <T>(this T source, string name, string value) //, bool converter = true)
        {
            Type obj = source.GetType();

            PropertyInfo info = obj.GetProperty(name);

            if (info == null)
            {
                return;
            }

            try
            {
                Type propertyType = info.PropertyType;

                Type targetType = propertyType.IsNullableType() ? Nullable.GetUnderlyingType(info.PropertyType) : info.PropertyType;

                object objectValue = null;

                if (targetType == typeof(Brush))
                {
                    objectValue = (SolidColorBrush) new BrushConverter().ConvertFromString(value);
                }
                else if (targetType == typeof(FontFamily))
                {
                    objectValue = new FontFamily(value);
                }
                else if (targetType.BaseType == typeof(Enum))
                {
                    objectValue = Enum.Parse(targetType, value);
                }
                else if (targetType == typeof(Thickness))
                {
                    string[] thicknessValues = value.Split(',');

                    if (thicknessValues.Length == 1)
                    {
                        objectValue = new Thickness(thicknessValues[0].ToDouble());
                    }
                    else
                    {
                        objectValue = new Thickness
                                      (
                            thicknessValues[0].ToDouble(),
                            thicknessValues[1].ToDouble(),
                            thicknessValues[2].ToDouble(),
                            thicknessValues[3].ToDouble()
                                      );
                    }
                }
                else if (targetType == typeof(FontWeight))
                {
                    FontWeightConverter converter = new FontWeightConverter();

                    objectValue = (FontWeight)converter.ConvertFromString(value);
                }
                else if (targetType == typeof(System.Windows.Media.Color))
                {
                    objectValue = (Color)ColorConverter.ConvertFromString(value);
                }
                else
                {
                    objectValue = Convert.ChangeType(value, targetType, CultureInfo.InvariantCulture);
                }

                info.SetValue(source, objectValue, null);
            }
            catch
            {
                // DO NOTHING: This may be because the property was not initialized and is NULL
                throw;
            }
        }