Beispiel #1
0
        private void FontStyleButton_Click(object sender, RoutedEventArgs e)
        {
            System.Windows.Forms.FontDialog fd = new System.Windows.Forms.FontDialog();
            var result = fd.ShowDialog();

            if (result == System.Windows.Forms.DialogResult.OK)
            {
                editTextBox.FontFamily = new FontFamily(fd.Font.Name);
                editTextBox.FontSize   = fd.Font.Size * 96.0 / 72.0;
                editTextBox.FontWeight = fd.Font.Bold ? FontWeights.Bold : FontWeights.Regular;
                editTextBox.FontStyle  = fd.Font.Italic ? FontStyles.Italic : FontStyles.Normal;

                TextDecorationCollection tdc = new TextDecorationCollection();
                if (fd.Font.Underline)
                {
                    tdc.Add(TextDecorations.Underline);
                }
                if (fd.Font.Strikeout)
                {
                    tdc.Add(TextDecorations.Strikethrough);
                }
                editTextBox.TextDecorations = tdc;

                fontFamily = editTextBox.FontFamily;
                fontSize   = editTextBox.FontSize;
                fontWeight = editTextBox.FontWeight;
                fontStyle  = editTextBox.FontStyle;
                Serialize();
            }
        }
Beispiel #2
0
        private void m_fuentes_Click(object sender, RoutedEventArgs e)
        {
            var fontDialog = new FontDialog();

            fontDialog.ShowDialog();

            System.Drawing.Font font = fontDialog.Font;

            m_contenido.FontFamily = new System.Windows.Media.FontFamily(font.Name);
            m_contenido.FontSize   = font.Size;
            m_contenido.FontWeight = font.Bold ? FontWeights.Bold : FontWeights.Regular;
            m_contenido.FontStyle  = font.Italic ? FontStyles.Italic : FontStyles.Normal;

            TextDecorationCollection tdc = new TextDecorationCollection();

            if (fontDialog.Font.Underline)
            {
                tdc.Add(TextDecorations.Underline);
            }
            if (fontDialog.Font.Strikeout)
            {
                tdc.Add(TextDecorations.Strikethrough);
            }

            m_contenido.TextDecorations = tdc;
        }
Beispiel #3
0
        /// <summary>
        ///     Translator for Font
        /// </summary>
        private static void FontPropertyTranslator(object host, string propertyName, object value)
        {
            ElementHost elementHost = host as ElementHost;

            SD.Font wfFont = value as SD.Font;

            if (elementHost != null && wfFont != null)
            {
                AvalonAdapter adapter = elementHost.HostContainerInternal;
                if (adapter != null)
                {
                    adapter.SetValue(SWC.Control.FontSizeProperty, Convert.SystemDrawingFontToSystemWindowsFontSize(wfFont));
                    adapter.SetValue(SWC.Control.FontFamilyProperty, Convert.ToSystemWindowsFontFamily(wfFont.FontFamily));
                    adapter.SetValue(SWC.Control.FontWeightProperty, Convert.ToSystemWindowsFontWeight(wfFont));
                    adapter.SetValue(SWC.Control.FontStyleProperty, Convert.ToSystemWindowsFontStyle(wfFont));

                    SWC.TextBlock childTextBlock = elementHost.Child as SWC.TextBlock;
                    if (childTextBlock != null)
                    {
                        TextDecorationCollection decorations = new TextDecorationCollection();
                        if (wfFont.Underline)
                        {
                            decorations.Add(TextDecorations.Underline);
                        }
                        ;
                        if (wfFont.Strikeout)
                        {
                            decorations.Add(TextDecorations.Strikethrough);
                        }
                        childTextBlock.TextDecorations = decorations;
                    }
                }
            }
        }
Beispiel #4
0
        private void SetProperties(IClassificationType type, IStyle style, IClassificationFormatMap map)
        {
            var props = map.GetExplicitTextProperties(type)
                        .SetTypeface(new Typeface(style.Font))
                        .SetForeground(style.Foreground)
                        .SetBackground(style.Background)
                        .SetForegroundOpacity(style.Opacity)
                        .SetFontRenderingEmSize(style.Size)
                        .SetItalic(style.Italic)
                        .SetBold(style.Bold);

            var textDecorations = new TextDecorationCollection();

            //? props.TextDecorations.Add(TextDecorations.Underline);
            if (style.Underline)
            {
                textDecorations.Add(TextDecorations.Underline);
            }

            //? props.TextDecorations.Add(TextDecorations.Strikethrough);
            if (style.Strikethrough)
            {
                textDecorations.Add(TextDecorations.Strikethrough);
            }

            //? remove this line when using TextDecorations.Add()
            props = props.SetTextDecorations(textDecorations);

            map.AddExplicitTextProperties(type, props);
        }
        private TextFormattingRunProperties CreateTextProperties(CategoryItemDecorationSettings colorSetting)
        {
            TextFormattingRunProperties textFormatting = TextFormattingRunProperties.CreateTextFormattingRunProperties();

            textFormatting = textFormatting.SetBackground(colorSetting.BackgroundColor);
            textFormatting = textFormatting.SetForeground(colorSetting.ForegroundColor);
            textFormatting = textFormatting.SetBold(colorSetting.IsBold);
            textFormatting = textFormatting.SetItalic(colorSetting.IsItalic);

            if (colorSetting.HasStrikethrough || colorSetting.IsUnderlined)
            {
                TextDecorationCollection decorationsCollection = new TextDecorationCollection();
                TextDecorationCollection decorations           = textFormatting.TextDecorations.Clone();

                if (colorSetting.IsUnderlined)
                {
                    decorations.Add(TextDecorations.Underline);
                }
                if (colorSetting.HasStrikethrough)
                {
                    decorations.Add(TextDecorations.Strikethrough);
                }

                decorationsCollection.Add(decorations);
                textFormatting = textFormatting.SetTextDecorations(decorationsCollection);
            }

            return(textFormatting);
        }
 private void OnStrikeChanged(bool Strike)
 {
     if (Strike)
     {
         if (Decoration == null)
         {
             Decoration = new TextDecorationCollection();
             Decoration.Add(TextDecorations.Strikethrough);
         }
         else
         {
             Decoration = new TextDecorationCollection();
             Decoration.Add(TextDecorations.Strikethrough);
             Decoration.Add(TextDecorations.Underline);
         }
     }
     else
     {
         if (Decoration != null && Decoration.Contains(TextDecorations.Underline[0]))
         {
             Decoration = new TextDecorationCollection();
             Decoration.Add(TextDecorations.Underline);
         }
         else
         {
             Decoration = null;
         }
     }
     this.SetTextDecorations();
 }
Beispiel #7
0
        public MessageFontInfo GetFontInfo()
        {
            var fd     = new FontDialog();
            var result = fd.ShowDialog();

            fd.ShowEffects = false;
            if (result != DialogResult.OK)
            {
                return(null);
            }
            var tdc = new TextDecorationCollection();

            if (fd.Font.Underline)
            {
                tdc.Add(TextDecorations.Underline);
            }
            if (fd.Font.Strikeout)
            {
                tdc.Add(TextDecorations.Strikethrough);
            }
            var fontInfo = new MessageFontInfo(fd.Font.Name, fd.Font.Size * 96.0 / 72.0)
            {
                FontWeight = fd.Font.Bold ? FontWeights.Bold : FontWeights.Regular,
                FontStyle  = fd.Font.Italic ? FontStyles.Italic : FontStyles.Normal,
            };

            return(fontInfo);
        }
Beispiel #8
0
        void tPismo_Click(object sender, RoutedEventArgs e)
        {
            int dpiX = (int)typeof(SystemParameters)
                       .GetProperty("DpiX", BindingFlags.NonPublic | BindingFlags.Static)
                       .GetValue(null, null);

            var fd = new FontDialog();

            fd.ShowApply   = true;
            fd.ShowEffects = false;
            float fs = (float)mw.richTextBox1.FontSize / dpiX * 72;

            fd.Font = new Font(new System.Drawing.FontFamily(mw.richTextBox1.FontFamily.ToString()), fs);

            if (fd.ShowDialog() != System.Windows.Forms.DialogResult.Cancel)
            {
                mw.richTextBox1.FontFamily = new System.Windows.Media.FontFamily(fd.Font.Name);
                mw.richTextBox1.FontSize   = fd.Font.Size * dpiX / 72;
                mw.richTextBox1.FontWeight = fd.Font.Bold ? FontWeights.Bold : FontWeights.Regular;
                mw.richTextBox1.FontStyle  = fd.Font.Italic ? FontStyles.Italic : FontStyles.Normal;

                TextDecorationCollection tdc = new TextDecorationCollection();
                if (fd.Font.Underline)
                {
                    tdc.Add(TextDecorations.Underline);
                }
                if (fd.Font.Strikeout)
                {
                    tdc.Add(TextDecorations.Strikethrough);
                }
            }
        }
Beispiel #9
0
        public void ShowFontDialog()
        {
            var fd     = new System.Windows.Forms.FontDialog();
            var result = fd.ShowDialog();

            if (result == System.Windows.Forms.DialogResult.OK)
            {
                var tr = new TextRange(textBox.Selection.Start, textBox.Selection.End);

                tr.ApplyPropertyValue(TextElement.FontFamilyProperty, new FontFamily(fd.Font.Name));
                tr.ApplyPropertyValue(TextElement.FontSizeProperty, fd.Font.Size * 96.0 / 72.0);
                tr.ApplyPropertyValue(TextElement.FontWeightProperty, textBox.FontWeight = fd.Font.Bold ? FontWeights.Bold : FontWeights.Regular);
                tr.ApplyPropertyValue(TextElement.FontStyleProperty, fd.Font.Italic ? FontStyles.Italic : FontStyles.Normal);

                TextDecorationCollection tdc = new TextDecorationCollection();
                if (fd.Font.Underline)
                {
                    tdc.Add(TextDecorations.Underline);
                }
                else
                {
                    tr.ApplyPropertyValue(Inline.TextDecorationsProperty, null);
                }
                if (fd.Font.Strikeout)
                {
                    tdc.Add(TextDecorations.Strikethrough);
                }
                else
                {
                    tr.ApplyPropertyValue(Inline.TextDecorationsProperty, null);
                }
                tr.ApplyPropertyValue(Inline.TextDecorationsProperty, tdc);
            }
        }
        private void ButtonChangeFont(object sender, RoutedEventArgs e)
        {
            fontDialog.ShowColor         = true;
            fontDialog.ShowApply         = false;
            fontDialog.ShowEffects       = true;
            fontDialog.ShowHelp          = false;
            fontDialog.AllowScriptChange = false;

            if (fontDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                NewTextVM.FontColor    = new SolidColorBrush(Color.FromArgb(fontDialog.Color.A, fontDialog.Color.R, fontDialog.Color.G, fontDialog.Color.B));
                NewTextVM.TbFontFamily = new FontFamily(fontDialog.Font.Name);
                NewTextVM.TbFontSize   = fontDialog.Font.Size;
                NewTextVM.TbFontWeight = fontDialog.Font.Bold ? FontWeights.Bold : FontWeights.Regular;
                NewTextVM.TbFontStyle  = fontDialog.Font.Italic ? FontStyles.Italic : FontStyles.Normal;
                //TextBlockPreview.Foreground = NewTextVM.FontColor;

                TextDecorationCollection tdc = new TextDecorationCollection();
                if (fontDialog.Font.Underline)
                {
                    tdc.Add(TextDecorations.Underline);
                }
                if (fontDialog.Font.Strikeout)
                {
                    tdc.Add(TextDecorations.Strikethrough);
                }
                NewTextVM.TbTextDecorations = tdc;
            }
        }
        private void UpdateFormattedText()
        {
            if (_FormattedText == null)
            {
                return;
            }

            _FormattedText.MaxLineCount  = TextWrapping == TextWrapping.NoWrap ? 1 : int.MaxValue;
            _FormattedText.TextAlignment = TextAlignment;
            _FormattedText.Trimming      = TextTrimming;

            var converter = TypeDescriptor.GetConverter(typeof(System.Drawing.Font));
            var font      = (System.Drawing.Font)converter.ConvertFromInvariantString(Typeface);

            textDecorations.Clear();
            if (font.Strikeout)
            {
                textDecorations.Add(TextDecorations.Strikethrough);
            }
            if (font.Underline)
            {
                textDecorations.Add(TextDecorations.Underline);
            }

            _FormattedText.SetFontSize(font.SizeInPoints);
            _FormattedText.SetFontFamily(new FontFamily(font.Name));
            _FormattedText.SetFontWeight(font.Bold ? FontWeights.Bold : FontWeights.Regular);
            _FormattedText.SetFontStyle(font.Italic ? FontStyles.Italic : FontStyles.Normal);
            _FormattedText.SetTextDecorations(textDecorations);
        }
Beispiel #12
0
        private TextDecorationCollection CopyTextDecorations(TextDecorationCollection textDecorations, Brush brush)
        {
            TextDecorationCollection result = new TextDecorationCollection();
            Pen pen = null;

            foreach (TextDecoration td in textDecorations)
            {
                if (td.Pen == null && brush != null)
                {
                    if (pen == null)
                    {
                        pen = new Pen(brush, 1);
                    }

                    TextDecoration copy = td.Clone();
                    copy.Pen = pen;
                    result.Add(copy);
                }
                else
                {
                    result.Add(td);
                }
            }

            return(result);
        }
Beispiel #13
0
        private void OnTextDecorationCheckBoxChanged(object sender, RoutedEventArgs eventArgs)
        {
            // Only handle if changed was caused by user.
            if (_isInternalUpdate)
            {
                return;
            }

            var textDecorations = new TextDecorationCollection();

            if (_underlineCheckBox.IsChecked.GetValueOrDefault())
            {
                textDecorations.Add(TextDecorations.Underline);
            }

            if (_baselineCheckBox.IsChecked.GetValueOrDefault())
            {
                textDecorations.Add(TextDecorations.Baseline);
            }

            if (_strikethroughCheckBox.IsChecked.GetValueOrDefault())
            {
                textDecorations.Add(TextDecorations.Strikethrough);
            }

            if (_overlineCheckBox.IsChecked.GetValueOrDefault())
            {
                textDecorations.Add(TextDecorations.OverLine);
            }

            textDecorations.Freeze();
            SelectedTextDecorations = textDecorations;
        }
Beispiel #14
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            TextDecorationCollection rValue = new TextDecorationCollection();

            try
            {
                Dictionary <string, bool> data = (Dictionary <string, bool>)value;
                if (data.ContainsKey("underline") && data["underline"])
                {
                    rValue.Add(CommonFunction.GetUnderline());
                }

                if (data.ContainsKey("strikethrough") && data["strikethrough"])
                {
                    rValue.Add(CommonFunction.GetStrikeThough());
                }
            }
            catch (System.Exception ex)
            {
                NLogger.Error("Decoration error!");
            }


            return(rValue);
        }
Beispiel #15
0
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            TextDecorationCollection resultado = new TextDecorationCollection();

            if (values.Length < 2)
            {
                return(resultado);
            }
            if (values[0].GetType().Name == "NamedObject")
            {
                return(resultado);
            }
            int  codigo   = values[0] == null ? 0 : (int)values[0];
            bool haydatos = values[1] == null ? false : (bool)values[1];

            // Evaluamos el código.
            switch (codigo)
            {
            case 1:
            case 2:
                resultado.Add(TextDecorations.Strikethrough);
                break;
            }

            // Si hay extras, subrayamos.
            if (haydatos)
            {
                resultado.Add(TextDecorations.Underline);
            }

            return(resultado);
        }
Beispiel #16
0
        /// <summary>
        /// Event handler for when a new decoration is selected/deselected.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DecorationClickEventHandler(object sender, RoutedEventArgs e)
        {
            // Make sure All UI is loaded
            if (!_UILoaded)
            {
                return;
            }

            TextDecorationCollection tds = new TextDecorationCollection();

            if (underlineButton.IsChecked == true)
            {
                TextDecoration underline = new TextDecoration();
                underline.Location         = TextDecorationLocation.Underline;
                underline.Pen              = new System.Windows.Media.Pen(System.Windows.Media.Brushes.Blue, 1);
                underline.PenThicknessUnit = TextDecorationUnit.FontRecommended;
                tds.Add(underline);
            }
            if (strikeButton.IsChecked == true)
            {
                TextDecoration strikethrough = new TextDecoration();
                strikethrough.Location         = TextDecorationLocation.Strikethrough;
                strikethrough.Pen              = new System.Windows.Media.Pen(System.Windows.Media.Brushes.Red, 1);
                strikethrough.PenThicknessUnit = TextDecorationUnit.FontRecommended;
                tds.Add(strikethrough);
            }
            _currentRendering.TextDecorations = tds;
            UpdateFormattedText();
        }
        private void OpenChangeFontDialog()
        {
            var fd = new System.Windows.Forms.FontDialog();

            //Select current font
            if (this.model.FontFamily != null)
            {
                var isBold      = this.model.FontWeight == FontWeights.Bold ? true : false;
                var isItalic    = this.model.FontStyle == FontStyles.Italic ? true : false;
                var fdFontSize  = (float)((this.model.FontSize * 72.0) / 96.0);
                var fdFontStyle = System.Drawing.FontStyle.Regular;
                if (isBold)
                {
                    fdFontStyle = fdFontStyle | System.Drawing.FontStyle.Bold;
                }
                if (isItalic)
                {
                    fdFontStyle = fdFontStyle | System.Drawing.FontStyle.Italic;
                }

                if (fdFontSize <= 0)
                {
                    fdFontSize = 9;
                }

                string fdFontName = this.model.FontFamily == null ? null : this.model.FontFamily.Source;

                var fdFont = new System.Drawing.Font(fdFontName, fdFontSize, fdFontStyle);

                fd.Font = fdFont;
            }

            var result = fd.ShowDialog();

            if (result == System.Windows.Forms.DialogResult.OK)
            {
                var fontFamily = new FontFamily(fd.Font.Name);
                var fontSize   = fd.Font.Size * 96.0 / 72.0;
                var fontWeight = fd.Font.Bold ? FontWeights.Bold : FontWeights.Regular;
                var fontStyle  = fd.Font.Italic ? FontStyles.Italic : FontStyles.Normal;

                TextDecorationCollection tdc = new TextDecorationCollection();
                if (fd.Font.Underline)
                {
                    tdc.Add(TextDecorations.Underline);
                }
                if (fd.Font.Strikeout)
                {
                    tdc.Add(TextDecorations.Strikethrough);
                }
                var textDecorations = tdc;

                this.model.FontFamily      = fontFamily;
                this.model.FontSize        = fontSize;
                this.model.FontWeight      = fontWeight;
                this.model.FontStyle       = fontStyle;
                this.model.TextDecorations = textDecorations;
            }
        }
Beispiel #18
0
        public void UpdateInspectorStyles()
        {
            __Foreground      = null;
            __FontSize        = null;
            __IsBold          = false;
            __FontWeight      = null;
            __IsItalic        = false;
            __FontStyle       = null;
            __IsStrikethrough = false;
            __TextDecorations = new TextDecorationCollection();
            __FontFamily      = null;

            foreach (LevelStyleProperty style in __StyleList)
            {
                switch (style.PropertyType)
                {
                case StylePropertyType.FontColor:
                    __Foreground = style.Value as SolidColorBrush;
                    break;

                case StylePropertyType.FontSize:
                    __FontSize = (double?)style.Value;
                    break;

                case StylePropertyType.IsBold:
                    __IsBold     = (bool)style.Value;
                    __FontWeight = __IsBold ? FontWeights.Bold : FontWeights.Normal;
                    break;

                case StylePropertyType.IsItalic:
                    __IsItalic  = (bool)style.Value;
                    __FontStyle = __IsItalic ? FontStyles.Italic : FontStyles.Normal;
                    break;

                case StylePropertyType.IsStrike:
                    __IsStrikethrough = (bool)style.Value;
                    if (__IsStrikethrough)
                    {
                        __TextDecorations.Add(TextDecorations.Strikethrough);
                    }
                    break;

                case StylePropertyType.IsUnderlined:
                    __IsUnderlined = (bool)style.Value;
                    if (__IsUnderlined)
                    {
                        __TextDecorations.Add(TextDecorations.Underline);
                    }
                    break;

                case StylePropertyType.Typeface:
                    __FontFamily = style.Value as FontFamily;
                    break;
                }
            }
            DoInspectorChanged();
            DoStyleChanged();
        }
Beispiel #19
0
        private List <Polygon> RenderString(TextToolOptions options, Vector offset)
        {
            var fontfamily = new FontFamily(options.Font.FontFamily.Name);

            var typeface = FindTypeface(options, fontfamily, EmptySynonymMap) ??
                           FindTypeface(options, fontfamily, SynonymMap) ?? fontfamily.GetTypefaces().First();

            var decorations = new TextDecorationCollection();

            if (options.Font.Strikeout)
            {
                decorations.Add(TextDecorations.Strikethrough);
            }

            if (options.Font.Underline)
            {
                decorations.Add(TextDecorations.Underline);
            }

            const double sizeFactor    = 0.1;
            var          formattedText = new FormattedText(options.Text, CultureInfo.InvariantCulture,
                                                           FlowDirection.LeftToRight, typeface, options.Font.SizeInPoints * sizeFactor, Brushes.Black, 1)
            {
                LineHeight = options.LineHeight * options.Font.SizeInPoints * sizeFactor
            };

            formattedText.SetTextDecorations(decorations);

            var smoothness = options.Smoothness;
            var geom       = formattedText.BuildGeometry(new Point(0, 0));

            List <Polygon> polys;

            try
            {
                (polys, smoothness) = BuildPolygons(geom, offset, smoothness);
            }
            catch (PolygonException)
            {
                var opt = TextToolOptions.Default;
                opt.Text = "Unable to render\nthis font without\ntopology errors.";
                return(RenderString(opt, offset));
            }

            try
            {
                FinalizePolygons(polys);
                return(polys);
            }
            catch (TopologyException)
            {
                var opt = options;
                opt.Smoothness = smoothness;
                return(RenderString(opt, offset));
            }
        }
Beispiel #20
0
        public static FontDescriptor Deserialize(XmlElement node)
        {
            if (node.FindBoolean("IsDefault") == true)
            {
                return(Default);
            }

            string fontFamily  = node.FindString("Family");
            int?   fontWight   = node.FindInt32("Weight");
            int?   fontStyle   = node.FindInt32("Style");
            int?   fontStretch = node.FindInt32("Stretch");
            double?fontSize    = node.FindDouble("Size");

            TextDecorationCollection textDecorations = new TextDecorationCollection();
            XmlElement textDecorationsNode           = node["TextDecorations"];

            if (textDecorationsNode != null)
            {
                foreach (int?location in textDecorationsNode.OfType <XmlElement>().Select(decorationNode => decorationNode.FindInt32("Location")).Where(location => location != null))
                {
                    switch ((TextDecorationLocation)location.Value)
                    {
                    case TextDecorationLocation.Baseline:
                        textDecorations.Add(System.Windows.TextDecorations.Baseline[0]);
                        break;

                    case TextDecorationLocation.OverLine:
                        textDecorations.Add(System.Windows.TextDecorations.OverLine[0]);
                        break;

                    case TextDecorationLocation.Strikethrough:
                        textDecorations.Add(System.Windows.TextDecorations.Strikethrough[0]);
                        break;

                    case TextDecorationLocation.Underline:
                        textDecorations.Add(System.Windows.TextDecorations.Underline[0]);
                        break;
                    }
                }
            }

            return(new FontDescriptor
            {
                FontFamily = string.IsNullOrEmpty(fontFamily) ? new FontFamily() : new FontFamily(fontFamily),
                FontWeight = fontWight == null ? new FontWeight() : FontWeight.FromOpenTypeWeight(fontWight.Value),
                FontStyle = fontStyle == null ? new FontStyle() : (FontStyle)(FontStyleConverter)fontStyle.Value,
                FontStretch = fontStretch == null ? new FontStretch() : FontStretch.FromOpenTypeStretch(fontStretch.Value),
                FontSize = fontSize ?? 12,
                TextDecorations = textDecorations
            });
        }
Beispiel #21
0
        private TextDecorationCollection GetTextDecorations()
        {
            TextDecorationCollection textDecorations = new TextDecorationCollection();

            if (Strikeout)
            {
                textDecorations.Add(TextDecorations.Strikethrough);
            }
            if (Underline)
            {
                textDecorations.Add(TextDecorations.Underline);
            }
            return(textDecorations);
        }
        private TextDecorationCollection GetTextDecorations()
        {
            TextDecorationCollection coll = new TextDecorationCollection();

            if (TheUnderline.IsChecked.Value)
            {
                coll.Add(TextDecorations.Underline);
            }
            if (TheStrikethrough.IsChecked.Value)
            {
                coll.Add(TextDecorations.Strikethrough);
            }
            return(coll);
        }
Beispiel #23
0
        private void UpdateDocumentTextDecorations()
        {
            var decorations = new TextDecorationCollection();

            if (SelectionIsStrikeThrough)
            {
                decorations.Add(TextDecorations.Strikethrough[0]);
            }
            if (SelectionIsUnderline)
            {
                decorations.Add(TextDecorations.Underline[0]);
            }
            Selection.ApplyPropertyValue(Inline.TextDecorationsProperty, decorations);
        }
Beispiel #24
0
        public TabItem(string header, TotoConfig.UserRole userRole, TotoConfig.GamePhase gamePhase)
        {
            this.Header = header;

            this.Name = "tab_" + header;

            ScrollViewer.VerticalScrollBarVisibility   = ScrollBarVisibility.Auto;
            ScrollViewer.HorizontalScrollBarVisibility = ScrollBarVisibility.Hidden;

            this.Content = ScrollViewer;

            InitiateGrid();

            // add grid to scrollviewer:
            ScrollViewer.Content = MainTabGrid;

            // create title bar:
            var textBlockTitle = new TextBlock {
                Name = "txtblck_title", Text = "Titel", Background = BarColour, Height = 80
            };
            var textDecorations = new TextDecorationCollection();

            textDecorations.Add(TextDecorations.Underline);
            textDecorations.Add(TextDecorations.OverLine);
            textBlockTitle.TextDecorations = textDecorations;
            Grid.SetColumnSpan(textBlockTitle, 3);
            MainTabGrid.Children.Add(textBlockTitle);

            // create a combobox:
            string[][] cbItems =
            {
                new string[] { "Optie 1", "ID1" },
                new string[] { "Optie 2", "ID2" },
                new string[] { "Optie 3", "ID3" },
                new string[] { "Optie 4", "ID4", "hoi"}
            };
            var controlProperties = new ControlProperties
            {
                Width  = "auto",
                Height = "30",
                Name   = "my_combobox",
                ComboBoxPlaceholder = "Kies een optie...",
                ComboboxItems       = cbItems,
                Row = 1
            };
            var elementFactory = new ElementFactory();

            MainTabGrid.Children.Add(elementFactory.ComboBoxFactory(controlProperties));
        }
Beispiel #25
0
        protected override void Colorize(ITextRunConstructionContext context)
        {
            int lineStartOffset = context.VisualLine.FirstDocumentLine.Offset;
            int lineEndOffset   = context.VisualLine.LastDocumentLine.Offset + context.VisualLine.LastDocumentLine.TotalLength;

            if (Lexter != null)
            {
                foreach (Exception_Information segment in Lexter.ErrorList)
                {
                    int segmentStart = segment.Offset;
                    int segmentEnd   = segment.Offset + segment.Length;
                    if (segmentEnd <= lineStartOffset)
                    {
                        continue;
                    }
                    if (segmentStart >= lineEndOffset)
                    {
                        continue;
                    }
                    int startColumn = context.VisualLine.GetVisualColumn(Math.Max(0, segmentStart - lineStartOffset));
                    int endColumn   = context.VisualLine.GetVisualColumn(segmentEnd - lineStartOffset);

                    ChangeVisualElements(
                        startColumn, endColumn,
                        element =>
                    {
                        TextDecorationCollection coll = new TextDecorationCollection();
                        TextDecoration decor          = new TextDecoration();
                        decor.Pen = new System.Windows.Media.Pen(System.Windows.Media.Brushes.Red, 3);
                        coll.Add(decor);
                        element.TextRunProperties.SetTextDecorations(coll);
                    });
                }
            }
        }
Beispiel #26
0
        public Link(string title, string address)
        {
            FontSize   = 11;
            Cursor     = Cursors.Hand;
            Foreground = new SolidColorBrush(Color.FromRgb(135, 178, 227));

            TextDecoration underline = new TextDecoration()
            {
                Pen = new Pen(new SolidColorBrush(Color.FromRgb(135, 178, 227)), 1),
                PenThicknessUnit = TextDecorationUnit.FontRecommended
            };

            TextDecorationCollection collection = new TextDecorationCollection();

            collection.Add(underline);

            TextBlock text_block = new TextBlock()
            {
                Text            = title,
                TextDecorations = collection
            };

            Content = text_block;

            MouseUp += delegate {
                Process.Start(new ProcessStartInfo(address));
            };
        }
Beispiel #27
0
 private void ChangeTextFormatting(FormattedText ft, char command, string commandArgs, int index)
 {
     if (command == 's')
     {
         double size;
         size = Double.Parse(commandArgs);
         ft.SetFontSize(size, index, ft.Text.Length - index);
     }
     if (command == 'u')
     {
         // underline
         var dec = new TextDecorationCollection();
         dec.Add(TextDecorations.Underline);
         ft.SetTextDecorations(dec, index, ft.Text.Length - index);
     }
     if (command == 'n')
     {
         var dec = new TextDecorationCollection();
         ft.SetTextDecorations(dec, index, ft.Text.Length - index);
     }
     if (command == 'c')
     {
         var  colorMatch = colorRegex.Match(commandArgs);
         byte r, g, b;
         if (!colorMatch.Success ||
             !Byte.TryParse(colorMatch.Groups["red"].Value, out r) ||
             !Byte.TryParse(colorMatch.Groups["green"].Value, out g) ||
             !Byte.TryParse(colorMatch.Groups["blue"].Value, out b)
             )
         {
             throw new Exception("Color did not parse");
         }
         ft.SetForegroundBrush(new SolidColorBrush(Color.FromRgb(r, g, b)), index, ft.Text.Length - index);
     }
 }
Beispiel #28
0
        public SparkleLink(string title, string url)
        {
            FontSize   = 11;
            Cursor     = Cursors.Hand;
            Foreground = new SolidColorBrush(Color.FromRgb(135, 178, 227));

            TextDecoration underline = new TextDecoration()
            {
                Pen = new Pen(new SolidColorBrush(Color.FromRgb(135, 178, 227)), 1),
                PenThicknessUnit = TextDecorationUnit.FontRecommended
            };

            TextDecorationCollection collection = new TextDecorationCollection();

            collection.Add(underline);

            TextBlock text_block = new TextBlock()
            {
                Text            = title,
                TextDecorations = collection
            };

            Content = text_block;

            MouseUp += delegate {
                Program.Controller.OpenWebsite(url);
            };
        }
Beispiel #29
0
 void ApplyAttribute(TextAttribute attribute)
 {
     if (attribute is FontStyleTextAttribute)
     {
         var xa = (FontStyleTextAttribute)attribute;
         FormattedText.SetFontStyle(xa.Style.ToWpfFontStyle(), xa.StartIndex, xa.Count);
     }
     else if (attribute is FontWeightTextAttribute)
     {
         var xa = (FontWeightTextAttribute)attribute;
         FormattedText.SetFontWeight(xa.Weight.ToWpfFontWeight(), xa.StartIndex, xa.Count);
     }
     else if (attribute is ColorTextAttribute)
     {
         var xa = (ColorTextAttribute)attribute;
         FormattedText.SetForegroundBrush(new SolidColorBrush(xa.Color.ToWpfColor()), xa.StartIndex, xa.Count);
     }
     else if (attribute is StrikethroughTextAttribute)
     {
         var xa  = (StrikethroughTextAttribute)attribute;
         var dec = new TextDecoration(TextDecorationLocation.Strikethrough, null, 0, TextDecorationUnit.FontRecommended, TextDecorationUnit.FontRecommended);
         TextDecorationCollection col = new TextDecorationCollection();
         col.Add(dec);
         FormattedText.SetTextDecorations(col, xa.StartIndex, xa.Count);
     }
     else if (attribute is UnderlineTextAttribute)
     {
         var xa  = (UnderlineTextAttribute)attribute;
         var dec = new TextDecoration(TextDecorationLocation.Underline, null, 0, TextDecorationUnit.FontRecommended, TextDecorationUnit.FontRecommended);
         TextDecorationCollection col = new TextDecorationCollection();
         col.Add(dec);
         FormattedText.SetTextDecorations(col, xa.StartIndex, xa.Count);
     }
 }
        static TextDecorations()
        {
            // Init Underline            
            TextDecoration td = new TextDecoration();
            td.Location       = TextDecorationLocation.Underline;
            underline         = new TextDecorationCollection();
            underline.Add(td);
            underline.Freeze();

            // Init strikethrough
            td = new TextDecoration();
            td.Location       = TextDecorationLocation.Strikethrough;
            strikethrough     = new TextDecorationCollection();
            strikethrough.Add(td);
            strikethrough.Freeze();
            
            // Init overline
            td = new TextDecoration();
            td.Location       = TextDecorationLocation.OverLine;
            overLine          = new TextDecorationCollection();
            overLine.Add(td);
            overLine.Freeze();

            // Init baseline
            td = new TextDecoration();
            td.Location       = TextDecorationLocation.Baseline;
            baseline          = new TextDecorationCollection();
            baseline.Add(td);
            baseline.Freeze();            
        }
Beispiel #31
0
        void ApplyChanges(VisualLineElement element)
        {
            // This is where you do anything with the line
            BrushConverter           converter = new BrushConverter();
            Brush                    brush;
            TextDecorationCollection myCollection;

            switch (_diagnosticSeverity)
            {
            case DiagnosticSeverity.Error:
                brush         = (Brush)converter.ConvertFrom("#FF0000");
                brush.Opacity = 0.3;
                TextDecoration myUnderline = new TextDecoration();
                // Create a solid color brush pen for the text decoration.
                myUnderline.Pen = new Pen(Brushes.Red, 1);
                myUnderline.PenThicknessUnit = TextDecorationUnit.FontRecommended;
                myCollection = new TextDecorationCollection();
                myCollection.Add(myUnderline);
                element.TextRunProperties.SetTextDecorations(myCollection);
                break;

            case DiagnosticSeverity.Warning:
                brush = (Brush)converter.ConvertFrom("#ed9200");

                myUnderline = new TextDecoration();
                // Create a solid color brush pen for the text decoration.
                myUnderline.Pen = new Pen(brush, 1);
                myUnderline.PenThicknessUnit = TextDecorationUnit.FontRecommended;
                myCollection = new TextDecorationCollection();
                myCollection.Add(myUnderline);
                element.TextRunProperties.SetTextDecorations(myCollection);
                break;
            }
        }
Beispiel #32
0
        void textDecorationCheckStateChanged(object sender, RoutedEventArgs e)
        {
            var textDecorations = new TextDecorationCollection();

            if (underlineCheckBox.IsChecked.Value)
            {
                textDecorations.Add(TextDecorations.Underline[0]);
            }
            if (baselineCheckBox.IsChecked.Value)
            {
                textDecorations.Add(TextDecorations.Baseline[0]);
            }
            if (strikethroughCheckBox.IsChecked.Value)
            {
                textDecorations.Add(TextDecorations.Strikethrough[0]);
            }
            if (overlineCheckBox.IsChecked.Value)
            {
                textDecorations.Add(TextDecorations.OverLine[0]);
            }

            textDecorations.Freeze();
            SelectedTextDecorations = textDecorations;
        }
        //------------------------------------------------------
        //
        //  Private Methods
        //
        //------------------------------------------------------

        #region Private Methods

        // Calculates TextDecorations for speller errors.
        private static TextDecorationCollection GetErrorTextDecorations()
        {
            //
            // Build a "squiggle" Brush.
            //
            // This works by hard-coding a 3 pixel high TextDecoration, and
            // then tiling horizontally.  (We can't scale the squiggle in
            // the vertical direction, there's no support to limit tiling
            // to just the horizontal from the MIL.)
            //

            DrawingGroup drawingGroup = new DrawingGroup();
            DrawingContext drawingContext = drawingGroup.Open();
            Pen pen = new Pen(Brushes.Red, 0.33);

            // This is our tile:
            //
            //  x   x
            //   x x
            //    x
            //
            drawingContext.DrawLine(pen, new Point(0.0, 0.0), new Point(0.5, 1.0));
            drawingContext.DrawLine(pen, new Point(0.5, 1.0), new Point(1.0, 0.0));

            drawingContext.Close();

            DrawingBrush brush = new DrawingBrush(drawingGroup);
            brush.TileMode = TileMode.Tile;
            brush.Viewport = new Rect(0, 0, 3, 3);
            brush.ViewportUnits = BrushMappingMode.Absolute;

            TextDecoration textDecoration = new TextDecoration(
                            TextDecorationLocation.Underline,
                            new Pen(brush, 3),
                            0,
                            TextDecorationUnit.FontRecommended,
                            TextDecorationUnit.Pixel);

            TextDecorationCollection decorationCollection = new TextDecorationCollection();
            decorationCollection.Add(textDecoration);

            decorationCollection.Freeze();

            return decorationCollection;
        }