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
            {
            }
        }
        private void ResetFlowDocumentText()
        {
            Paragraph para = new Paragraph();

            if (MatchedTextLength == 0)
            {
                // If the length is zero, there's nothing selected. Just dump ALL
                // the text into the document and bail.
                Run run = new Run(LastExecutedInputText);
                para.Inlines.Add(run);
            }
            else
            {
                // Cut the last exec'd input text into three pieces - before the matched text (begin),
                // the matched text itself (middle), and after the matched text (end). The "middle" part is
                // the one that we'll apply style stuff to so that it stands out from the rest of the text.
                Run begin  = new Run(LastExecutedInputText.Substring(0, MatchedTextIndex));
                Run middle = new Run(LastExecutedInputText.Substring(MatchedTextIndex, MatchedTextLength));

                _fontWeightConverter = new FontWeightConverter();
                _brushConverter      = new BrushConverter();

                middle.FontWeight = (FontWeight)_fontWeightConverter.ConvertFrom("Bold");
                middle.Foreground = new SolidColorBrush(_applicationOptions.MatchedTextForegroundColor);
                middle.Background = new SolidColorBrush(_applicationOptions.MatchedTextBackgroundColor);
                Run end = new Run(LastExecutedInputText.Substring(MatchedTextIndex + MatchedTextLength));

                para.Inlines.AddRange(new Run[] { begin, middle, end });
            }

            _inputTextResultsFlowDocument.Blocks.Clear();
            _inputTextResultsFlowDocument.Blocks.Add(para);
        }
        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();
        }
Example #6
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 #7
0
        private FontWeight GetFontWeight()
        {
            var fontWeightConverter = new FontWeightConverter();
            var fontWeight          = (FontWeight)fontWeightConverter.ConvertFromString(FontWeight);

            return(fontWeight);
        }
Example #8
0
 public SSViewModel()
 {
     ModelElements = new ObservableCollection <SSElementBaseViewModel>();
     _colorCvtr    = new BrushConverter();
     _fscvtr       = new FontStyleConverter();
     _fwcvtr       = new FontWeightConverter();
 }
Example #9
0
 static FontWeight?ParseFontWeight(string fontWeight)
 {
     if (string.IsNullOrEmpty(fontWeight))
     {
         return(null);
     }
     return(FontWeightConverter.ConvertFromString(fontWeight));
 }
Example #10
0
 /// <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 CanParseFontWeight(string fontWeightName)
 {
     try
     {
         FontWeightConverter converter = new FontWeightConverter();
         converter.ConvertFromString(fontWeightName);
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Example #13
0
        public static FontWeight ParseWeight(string weightString)
        {
            FontWeight          weight    = FontWeights.Normal;
            FontWeightConverter converter = new FontWeightConverter();

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

            return(weight);
        }
Example #14
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 #15
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 #16
0
        /// <summary>
        /// Convert FontWeight to string for serialization
        /// </summary>
        public static string FontWeightToString(FontWeight value)
        {
            string result;

            try
            {
                result = new FontWeightConverter().ConvertToString(value);
            }
            catch (NotSupportedException)
            {
                result = "";
            }

            return(result);
        }
Example #17
0
        /// <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();
        }
Example #18
0
 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());
     }
 }
Example #19
0
        /// <summary>
        /// Convert string to FontWeight for serialization
        /// </summary>
        public static FontWeight FontWeightFromString(string value)
        {
            var result = FontWeights.Normal;

            try
            {
                var convertFromString = new FontWeightConverter().ConvertFromString((value));
                if (convertFromString != null)
                {
                    result = (FontWeight)convertFromString;
                }
            }
            catch (NotSupportedException)
            {
            }
            catch (FormatException)
            {
            }

            return(result);
        }
        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());
        }
Example #21
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;
                }
            }
        }
        public static FontWeight ParseFontWeight(string fontWeightName)
        {
            FontWeightConverter converter = new FontWeightConverter();

            return((FontWeight)converter.ConvertFromString(fontWeightName));
        }
        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;
            }
        }
Example #24
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 #25
0
        /// <summary>
        /// Serializes the font weight.
        /// </summary>
        /// <param name="fontWeight">The font weight.</param>
        /// <returns>The serialized font weight.</returns>
        public static string SerializeFontWeight(FontWeight fontWeight)
        {
            var converter = new FontWeightConverter();

            return(converter.ConvertToString(fontWeight));
        }
Example #26
0
        public static MigraDoc.DocumentObjectModel.Paragraph ExportFormattedText(string Text, FontWeight fntwt, double FontSize, Brush textcolor, FontStyle fstyle)
        {
            bool isSignifCode = false;

            if (Text.Trim().StartsWith("Signif. codes:"))
            {
                isSignifCode = true;
            }


            string text = Text.Replace(Environment.NewLine, String.Empty).Replace("  ", String.Empty);

            //Font Weight
            MigraDoc.DocumentObjectModel.TextFormat txtformat;
            int                 fwt;
            FontWeight          fw     = fntwt;
            FontWeightConverter fwc    = new FontWeightConverter();
            string              fontwt = fwc.ConvertToString(fw);

            bool isItalic = false;

            if (fstyle != null)
            {
                string s = fwc.ConvertToString(fstyle);
                if (s != null && s.Equals("Italic"))
                {
                    isItalic = true;
                }
            }
            switch (fontwt)
            {
            case "SemiBold":
                if (isItalic)
                {
                    txtformat = MigraDoc.DocumentObjectModel.TextFormat.Bold | MigraDoc.DocumentObjectModel.TextFormat.Italic;
                }
                else
                {
                    txtformat = MigraDoc.DocumentObjectModel.TextFormat.Bold;
                }
                break;

            case "Normal":
                if (isItalic)
                {
                    txtformat = MigraDoc.DocumentObjectModel.TextFormat.NotBold | MigraDoc.DocumentObjectModel.TextFormat.Italic;
                }
                else
                {
                    txtformat = MigraDoc.DocumentObjectModel.TextFormat.NotBold;
                }
                break;

            default:
                if (isItalic)
                {
                    txtformat = MigraDoc.DocumentObjectModel.TextFormat.NotBold | MigraDoc.DocumentObjectModel.TextFormat.Italic;
                }
                else
                {
                    txtformat = MigraDoc.DocumentObjectModel.TextFormat.NotBold;
                }
                break;
            }


            //Font Color
            System.Windows.Media.Color         fcolor    = (textcolor as SolidColorBrush).Color;
            MigraDoc.DocumentObjectModel.Color fontcolor = new MigraDoc.DocumentObjectModel.Color(fcolor.A, fcolor.R, fcolor.G, fcolor.B);

            //Font Size
            if (FontSize == 0)
            {
                FontSize = 14;
            }

            // Create a new MigraDoc document
            MigraDoc.DocumentObjectModel.Document document = new MigraDoc.DocumentObjectModel.Document();

            // Add a section to the document
            MigraDoc.DocumentObjectModel.Section section = document.AddSection();

            // Add a paragraph to the section
            MigraDoc.DocumentObjectModel.Paragraph paragraph = section.AddParagraph();

            if (isSignifCode)//add 'Notes.' in italics before 'Signif. codes:'
            {
                paragraph.AddFormattedText("Note. ", MigraDoc.DocumentObjectModel.TextFormat.Italic);
            }

            // Add some text to the paragraph
            paragraph.AddFormattedText(Text, txtformat);
            paragraph.Format.Font.Name  = "Times New Roman";
            paragraph.Format.Font.Size  = FontSize;
            paragraph.Format.Font.Color = fontcolor;
            paragraph.AddLineBreak();
            if (isSignifCode)
            {
                paragraph.AddLineBreak(); //add extra linebreak if 'signif code' is printed
            }

            return(paragraph);
        }
Example #27
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);
        }
Example #28
0
 public Outline(Canvas Canvas)
 {
     this.Canvas = Canvas;
     Converter   = new BrushConverter();
     WConverter  = new FontWeightConverter();
 }
Example #29
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;
        }
Example #30
0
        public static void SetRichFormatText(this TextBlock textBlock, string text)
        {
            if (textBlock == null)
            {
                return;
            }
            string[] strs = text.Split('[');
            textBlock.ClearValue(TextBlock.TextProperty);
            var          solidColorBrush = textBlock.Foreground as SolidColorBrush;
            List <Color> colors          = new List <Color> {
                Colors.Black
            };
            List <double> fontSizes = new List <double> {
                textBlock.FontSize
            };
            List <FontWeight> weights = new List <FontWeight> {
                textBlock.FontWeight
            };

            if (solidColorBrush != null)
            {
                colors.Add(solidColorBrush.Color);
            }
            foreach (string str in strs)
            {
                string[] parts = str.Split(']');
                string   txt;
                if (parts.Length > 1)
                {
                    txt = parts[1];
                    string   format = parts[0];
                    string[] fParts = format.Split('=');
                    if (fParts.Length == 1)//end tag
                    {
                        switch (fParts[0])
                        {
                        case "color":
                            colors.RemoveAt(colors.Count - 1);
                            break;

                        case "weight":
                            weights.RemoveAt(weights.Count - 1);
                            break;

                        case "fsize":
                            fontSizes.RemoveAt(fontSizes.Count - 1);
                            break;
                        }
                    }
                    else
                    {
                        switch (fParts[0])
                        {
                        case "color":
                            string color    = fParts[1];
                            var    colorObj = ColorConverter.ConvertFromString(color);

                            if (colorObj != null)
                            {
                                colors.Add((Color)colorObj);
                            }
                            break;

                        case "weight":
                            var fontWeight = new FontWeightConverter().ConvertFromString(fParts[1]);
                            if (fontWeight != null)
                            {
                                weights.Add((FontWeight)fontWeight);
                            }
                            break;

                        case "fsize":
                            double fontSize = fontSizes.Last();
                            string fSize    = fParts[1];
                            if (fParts[1].StartsWith("+") || fParts[1].StartsWith("-"))
                            {
                                fSize = fParts[1].Substring(1);
                            }
                            var ok = double.TryParse(fSize, out fontSize);

                            if (ok)
                            {
                                if (fParts[1].StartsWith("+"))
                                {
                                    fontSize = fontSizes.Last() + fontSize;
                                }
                                if (fParts[1].StartsWith("-"))
                                {
                                    fontSize = fontSizes.Last() - fontSize;
                                }
                                fontSizes.Add(fontSize);
                            }

                            break;

                        case "image":
                            string imageUrl = fParts[1];
                            AddImage(textBlock, imageUrl, 1.2, BaselineAlignment.Center);
                            break;
                        }
                    }
                }
                else
                {
                    txt = parts[0];
                }
                if (!string.IsNullOrEmpty(txt))
                {
                    textBlock.Inlines.Add(new Run(txt)
                    {
                        Foreground        = new SolidColorBrush(colors.Last()),
                        FontWeight        = weights.Last(),
                        FontSize          = fontSizes.Last(),
                        BaselineAlignment = BaselineAlignment.Center
                    });
                }
            }
        }