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();            
        }
示例#2
0
        private void ToolStripButtonStrikeout_Click(object sender, RoutedEventArgs e)
        {
            var range = new TextRange(RichTextControl.Selection.Start, RichTextControl.Selection.End);

            var tdc = (TextDecorationCollection)RichTextControl.Selection.GetPropertyValue(Inline.TextDecorationsProperty);

            if (tdc == null || !tdc.Equals(TextDecorations.Strikethrough))
            {
                tdc = TextDecorations.Strikethrough;
            }
            else
            {
                tdc = new TextDecorationCollection();
            }
            range.ApplyPropertyValue(Inline.TextDecorationsProperty, tdc);
        }
示例#3
0
        void OnFontChanged(object sender, EventArgs e)
        {
            font = App.Current.ClientFont;

            TextDecorations = new TextDecorationCollection();
            if (font.Style.HasFlag(Protocol.FontStyle.Underline))
            {
                TextDecorations.Add(System.Windows.TextDecorations.Underline);
            }

            NotifyPropertyChanged("FontFamily");
            NotifyPropertyChanged("FontWeight");
            NotifyPropertyChanged("FontStyle");
            NotifyPropertyChanged("FontColor");
            NotifyPropertyChanged("TextDecorations");
        }
示例#4
0
        public static TextDecorationCollection ToWPFFontDecorations(unvell.ReoGrid.Drawing.Text.FontStyles textStyle)
        {
            var decorations = new TextDecorationCollection();

            if ((textStyle & Drawing.Text.FontStyles.Underline) == Drawing.Text.FontStyles.Underline)
            {
                decorations.Add(TextDecorations.Underline);
            }

            if ((textStyle & Drawing.Text.FontStyles.Strikethrough) == Drawing.Text.FontStyles.Strikethrough)
            {
                decorations.Add(TextDecorations.Strikethrough);
            }

            return(decorations);
        }
示例#5
0
        // <SnippetTextDecorationSnippets6>
        // Use a Maroon pen for the baseline text decoration.
        private void SetMaroonBaseline()
        {
            // Create an baseline text decoration 2 units lower than the default.
            TextDecoration myBaseline = new TextDecoration(
                TextDecorationLocation.Baseline,
                new Pen(Brushes.Maroon, 1),
                2.0,
                TextDecorationUnit.Pixel,
                TextDecorationUnit.Pixel);

            // Set the baseline decoration to a TextDecorationCollection and add it to the text block.
            TextDecorationCollection myCollection = new TextDecorationCollection();

            myCollection.Add(myBaseline);
            TextBlock2.TextDecorations = myCollection;
        }
        private TextBlock CreateUnderlinedTextBlock(string text)
        {
            var myUnderline = new TextDecoration
            {
                Pen = new Pen(Brushes.Blue, 1),
                PenThicknessUnit = TextDecorationUnit.FontRecommended
            };
            var myCollection = new TextDecorationCollection {
                myUnderline
            };
            var blockHead = new TextBlock {
                TextDecorations = myCollection, Text = text
            };

            return(blockHead);
        }
示例#7
0
        private void SetUnderline()
        {
            // Fill the underline decoration with a solid color brush.
            TextDecorationCollection myCollection = new TextDecorationCollection();
            TextDecoration           myUnderline  = new TextDecoration();

            myUnderline.Location = TextDecorationLocation.Underline;

            // Set the solid color brush.
            myUnderline.Pen = new Pen(Brushes.Red, 1);
            myUnderline.PenThicknessUnit = TextDecorationUnit.FontRecommended;

            // Set the underline decoration to the text block.
            myCollection.Add(myUnderline);
            underlineTextBlock.TextDecorations = myCollection;
        }
示例#8
0
        private void SetStrikeThrough()
        {
            // Fill the overline decoration with a solid color brush.
            TextDecorationCollection myCollection    = new TextDecorationCollection();
            TextDecoration           myStrikeThrough = new TextDecoration();

            myStrikeThrough.Location = TextDecorationLocation.Strikethrough;

            // Set the solid color brush.
            myStrikeThrough.Pen = new Pen(Brushes.Blue, 1);
            myStrikeThrough.PenThicknessUnit = TextDecorationUnit.FontRecommended;

            // Set the underline decoration to the text block.
            myCollection.Add(myStrikeThrough);
            strikethroughTextBlock.TextDecorations = myCollection;
        }
示例#9
0
        private void StrikeThroughButton_Click(object sender, RoutedEventArgs e)
        {
            TextRange range = new TextRange(richTextBox.Selection.Start, richTextBox.Selection.End);

            TextDecorationCollection tdc = (TextDecorationCollection)richTextBox.Selection.GetPropertyValue(Inline.TextDecorationsProperty);

            if (tdc == null || !tdc.Equals(TextDecorations.Strikethrough))
            {
                tdc = TextDecorations.Strikethrough;
            }
            else
            {
                tdc = null;
            }
            range.ApplyPropertyValue(Inline.TextDecorationsProperty, tdc);
        }
 public GenericTextRunProperties(FontRendering newRender, TextEffectCollection effects, TextDecorationCollection decorations = null)
 {
     _typeface          = newRender.Typeface;
     _emSize            = newRender.FontSize;
     _emHintingSize     = newRender.FontSize;
     _textDecorations   = decorations;
     _foregroundBrush   = newRender.TextColor;
     _backgroundBrush   = null;
     _baselineAlignment = BaselineAlignment.Baseline;
     _culture           = CultureInfo.CurrentUICulture;
     _effects           = effects;
     if (_textDecorations == null)
     {
         _textDecorations = new TextDecorationCollection();
     }
 }
 public SpellCheckerColorizer()
 {
     decorations = new TextDecorationCollection
     {
         new TextDecoration()
         {
             Pen = new Pen
             {
                 Thickness = 2,
                 DashStyle = DashStyles.Solid,
                 Brush     = new SolidColorBrush(Colors.Red)
             },
             PenThicknessUnit = TextDecorationUnit.FontRecommended
         }
     };
 }
示例#12
0
        // ctor
        public RichTextBoxCustomSpell()
        {
            // initialize error markers
            _errorUnderline = CreateErrorUnderline();
            _noUnderline    = new TextDecorationCollection();
            _errorRanges    = new List <TextRange>();

            // initialize timer used to perform the spell-checking
            _timer          = new DispatcherTimer();
            _timer.Interval = TimeSpan.FromMilliseconds(SPELLCHECK_DELAY);
            _timer.Tick    += new EventHandler(_timer_Tick);

            // initialize the spell checker
            _spell = new C1SpellChecker();
            _spell.DictionaryChanged += _spell_DictionaryChanged;
        }
示例#13
0
        private void UpdateChatTextBlock(string name, List <Tuple <string, string> > list)
        {
            txt_chat.Inlines.Add(new Run($"{name}: "));

            foreach (Tuple <string, string> tuple in list)
            {
                var format = tuple.Item1;
                var text   = tuple.Item2;

                FontWeight fontWeigth = FontWeights.Normal;
                FontStyle  fontStyle  = FontStyles.Normal;
                TextDecorationCollection textDecoration = new TextDecorationCollection();

                if (format.Contains('*'))
                {
                    fontWeigth = FontWeights.Bold;
                }

                if (format.Contains('_'))
                {
                    fontStyle = FontStyles.Italic;
                }

                if (format.Contains('~'))
                {
                    textDecoration.Add(TextDecorations.Strikethrough);
                }

                if (format.Contains('`'))
                {
                    textDecoration.Add(TextDecorations.Underline);
                }


                txt_chat.Inlines.Add(new Run(text)
                {
                    FontWeight      = fontWeigth,
                    FontStyle       = fontStyle,
                    TextDecorations = textDecoration
                });
            }


            txt_chat.Inlines.Add(new Run("\n"));

            scrollView.ScrollToBottom();
        }
示例#14
0
        //------------------------------------------------------
        //
        //  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);
        }
示例#15
0
        public static void AddTextDecoration(TextDecorationCollection decoration)
        {
            object textdecorations = GetRTBValue(TextBlock.TextDecorationsProperty);

            if (textdecorations == DependencyProperty.UnsetValue)
            {
                textdecorations = decoration;
            }
            else
            {
                // TextDecorationCollection will be frozen, so we have to create a copy of the array.
                textdecorations = new TextDecorationCollection(textdecorations as TextDecorationCollection);
                (textdecorations as TextDecorationCollection).Add(decoration);
            }

            SetRTBValue(TextBlock.TextDecorationsProperty, textdecorations, false);
        }
示例#16
0
        private Run StylizedNewRun(string pChar, SolidColorBrush pColor, bool pIsSqrt = false)
        {
            var lRun = new Run(pChar);
            lRun.Foreground = pColor;

            if (pIsSqrt)
            {
                TextDecoration lOverline = new TextDecoration();
                lOverline.Location = TextDecorationLocation.OverLine;
                lOverline.Pen = new Pen(Brushes.Black, 1);
                lOverline.PenThicknessUnit = TextDecorationUnit.FontRecommended;
                TextDecorationCollection myCollection = new TextDecorationCollection();
                lRun.TextDecorations.Add(lOverline);
            }

            return lRun;
        }
示例#17
0
        public SpellingErrorColorizer()
        {
            // Create the Text decoration collection for the visual effect - you can get creative here
            collection = new TextDecorationCollection();
            var dec = new TextDecoration();

            dec.Pen = new Pen {
                Thickness = 1, DashStyle = DashStyles.DashDot, Brush = new SolidColorBrush(Colors.Red)
            };
            dec.PenThicknessUnit = TextDecorationUnit.FontRecommended;
            collection.Add(dec);

            // Set the static text box properties
            staticTextBox.AcceptsReturn        = true;
            staticTextBox.AcceptsTab           = true;
            staticTextBox.SpellCheck.IsEnabled = true;
        }
示例#18
0
        //
        // ToolStripButton Strikeout wurde gedrückt
        // (läßt sich nicht durch Command in XAML abarbeiten)
        //
        private void ToolStripButtonStrikeout_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            // TODO: Ereignishandlerimplementierung hier einfügen.
            TextRange range = new TextRange(RichTextControl.Selection.Start, RichTextControl.Selection.End);

            TextDecorationCollection tdc = (TextDecorationCollection)RichTextControl.Selection.GetPropertyValue(Inline.TextDecorationsProperty);

            if (tdc == null || !tdc.Equals(TextDecorations.Strikethrough))
            {
                tdc = TextDecorations.Strikethrough;
            }
            else
            {
                tdc = new TextDecorationCollection();
            }
            range.ApplyPropertyValue(Inline.TextDecorationsProperty, tdc);
        }
示例#19
0
        /// <summary>
        /// Fetch the next run at element end edge position.
        /// ElementEndEdge; we can have 2 possibilities:
        /// (1) Close edge of element associated with the text paragraph,
        ///     create synthetic LineBreak run to end the current line.
        /// (2) End of inline element, hide CloseEdge character and continue
        /// </summary>
        /// <param name="position"></param>
        /// Position in current text array
        protected TextRun HandleElementEndEdge(StaticTextPointer position)
        {
            Invariant.Assert(position.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.ElementEnd, "TextPointer does not point to element end edge.");

            TextRun run;

            if (position.Parent == _paraClient.Paragraph.Element)
            {
                // (1) Close edge of element associated with the text paragraph,
                //     create synthetic LineBreak run to end the current line.
                run = new ParagraphBreakRun(_syntheticCharacterLength, PTS.FSFLRES.fsflrEndOfParagraph);
            }
            else
            {
                TextElement element = (TextElement)position.GetAdjacentElement(LogicalDirection.Forward);
                Debug.Assert(element != null, "Element should be here.");
                Inline           inline = (Inline)element;
                DependencyObject parent = inline.Parent;
                FlowDirection    parentFlowDirection = inline.FlowDirection;

                if (parent != null)
                {
                    parentFlowDirection = (FlowDirection)parent.GetValue(FrameworkElement.FlowDirectionProperty);
                }

                if (inline.FlowDirection != parentFlowDirection)
                {
                    run = new TextEndOfSegment(_elementEdgeCharacterLength);
                }
                else
                {
                    TextDecorationCollection textDecorations = DynamicPropertyReader.GetTextDecorations(inline);
                    if (textDecorations == null || textDecorations.Count == 0)
                    {
                        // (2) End of inline element, hide CloseEdge character and continue
                        run = new TextHidden(_elementEdgeCharacterLength);
                    }
                    else
                    {
                        run = new TextEndOfSegment(_elementEdgeCharacterLength);
                    }
                }
            }
            return(run);
        }
示例#20
0
        public static void SetTextDecorationOnSelection(TextRange range, TextDecorationLocation decorationLocation, TextDecorationCollection newTextDecorations, bool value)
        {
            TextDecorationCollection decorations = new TextDecorationCollection();

            if (range.GetPropertyValue(TextBlock.TextDecorationsProperty) != DependencyProperty.UnsetValue)
            {
                TextDecorationCollection oldDecorations = (TextDecorationCollection)range.GetPropertyValue(TextBlock.TextDecorationsProperty);
                if (oldDecorations != null)
                {
                    decorations.Add(oldDecorations);
                }
            }

            if (value == true)
            {
                bool underlineAlreadyFound = false;
                foreach (TextDecoration decoration in decorations)
                {
                    if (decoration.Location == decorationLocation)
                    {
                        underlineAlreadyFound = true;
                        break;
                    }
                }

                if (!underlineAlreadyFound)
                {
                    decorations.Add(newTextDecorations);
                    range.ApplyPropertyValue(TextBlock.TextDecorationsProperty, decorations);
                }
            }
            else
            {
                for (int i = 0; i < decorations.Count; i++)
                {
                    if (decorations[i].Location == decorationLocation)
                    {
                        decorations.RemoveAt(i);
                        break;
                    }
                }

                range.ApplyPropertyValue(TextBlock.TextDecorationsProperty, decorations);
            }
        }
示例#21
0
        // ------------------------------------------------------------------
        // Fetch the next run at element close edge position.
        //
        //      position - current position in the text array
        // ------------------------------------------------------------------
        private TextRun HandleElementEndEdge(StaticTextPointer position)
        {
            Debug.Assert(position.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.ElementEnd, "TextPointer does not point to element end edge.");

            TextRun run = null;

            TextElement element = (TextElement)position.GetAdjacentElement(LogicalDirection.Forward);

            Debug.Assert(element != null, "Element should be here.");
            Inline inline = element as Inline;

            if (inline == null)
            {
                run = new TextHidden(_elementEdgeCharacterLength);
            }
            else
            {
                DependencyObject parent = inline.Parent;
                FlowDirection    parentFlowDirection = inline.FlowDirection;

                if (parent != null)
                {
                    parentFlowDirection = (FlowDirection)parent.GetValue(FrameworkElement.FlowDirectionProperty);
                }

                if (inline.FlowDirection != parentFlowDirection)
                {
                    run = new TextEndOfSegment(_elementEdgeCharacterLength);
                }
                else
                {
                    TextDecorationCollection textDecorations = DynamicPropertyReader.GetTextDecorations(inline);
                    if (textDecorations == null || textDecorations.Count == 0)
                    {
                        // (2) End of inline element, hide CloseEdge character and continue
                        run = new TextHidden(_elementEdgeCharacterLength);
                    }
                    else
                    {
                        run = new TextEndOfSegment(_elementEdgeCharacterLength);
                    }
                }
            }
            return(run);
        }
示例#22
0
        private static void InitializeGlossMap()
        {
            var map = new GlossEntry[Enum.GetValues(typeof(Gloss)).Cast <int>().Aggregate((x, y) => x | y) + 1];

            // This is primarity for debugging.
            for (var i = 0; i < map.Length; i++)
            {
                map[i] = GlossEntry.ERROR;
            }

            Brush NOR = Brushes.Black;
            Brush TAG = Brushes.Purple;
            Brush SYM = Brushes.Gray;

            Brush COMBG = Brushes.Transparent;
            Brush INSBG = Brushes.LightGreen;
            Brush DELBG = Brushes.LightPink;
            Brush EMPBG = Brushes.Yellow;

            var STRIKE = new TextDecorationCollection()
            {
                TextDecorations.Strikethrough
            };

            STRIKE.Freeze();

            map[(int)(Gloss.NOR | Gloss.COM)] = new GlossEntry(NOR, COMBG, null);
            map[(int)(Gloss.NOR | Gloss.INS)] = new GlossEntry(NOR, INSBG, null);
            map[(int)(Gloss.NOR | Gloss.DEL)] = new GlossEntry(NOR, DELBG, STRIKE);
            map[(int)(Gloss.NOR | Gloss.EMP)] = new GlossEntry(NOR, EMPBG, null);
            map[(int)(Gloss.TAG | Gloss.COM)] = new GlossEntry(TAG, COMBG, null);
            map[(int)(Gloss.TAG | Gloss.INS)] = new GlossEntry(TAG, INSBG, null);
            map[(int)(Gloss.TAG | Gloss.DEL)] = new GlossEntry(TAG, DELBG, STRIKE);
            map[(int)(Gloss.TAG | Gloss.EMP)] = new GlossEntry(TAG, EMPBG, null);
            map[(int)(Gloss.SYM | Gloss.COM)] = GlossEntry.IGNORE;
            map[(int)(Gloss.SYM | Gloss.INS)] = GlossEntry.IGNORE;
            map[(int)(Gloss.SYM | Gloss.DEL)] = GlossEntry.IGNORE;
            map[(int)(Gloss.SYM | Gloss.EMP)] = GlossEntry.IGNORE;
            map[(int)(Gloss.ALT | Gloss.COM)] = new GlossEntry(SYM, COMBG, null);
            map[(int)(Gloss.ALT | Gloss.INS)] = new GlossEntry(SYM, INSBG, null);
            map[(int)(Gloss.ALT | Gloss.DEL)] = new GlossEntry(SYM, DELBG, STRIKE);
            map[(int)(Gloss.ALT | Gloss.EMP)] = new GlossEntry(SYM, EMPBG, null);

            GlossMap = map;
        }
        /*
         * public static TextBlock CreateTextBlock(ExportText exportText,bool setBackcolor){
         *
         *      var textBlock = new TextBlock();
         *
         *      textBlock.Foreground = ConvertBrush(exportText.ForeColor);
         *
         *      if (setBackcolor) {
         *              textBlock.Background = ConvertBrush(exportText.BackColor);
         *      }
         *
         *      SetFont(textBlock,exportText);
         *
         *      textBlock.TextWrapping = TextWrapping.Wrap;
         *
         *      CheckForNewLine (textBlock,exportText);
         *      SetContentAlignment(textBlock,exportText);
         *      MeasureTextBlock (textBlock,exportText);
         *      return textBlock;
         * }
         */

        /*
         * static void CheckForNewLine(TextBlock textBlock,ExportText exportText) {
         *      string [] inlines = exportText.Text.Split(Environment.NewLine.ToCharArray());
         *      for (int i = 0; i < inlines.Length; i++) {
         *              if (inlines[i].Length > 0) {
         *                      textBlock.Inlines.Add(new Run(inlines[i]));
         *                      textBlock.Inlines.Add(new LineBreak());
         *              }
         *      }
         *      var li = textBlock.Inlines.LastInline;
         *      textBlock.Inlines.Remove(li);
         * }
         *
         *
         * static void MeasureTextBlock(TextBlock textBlock,ExportText exportText)
         * {
         *      var wpfSize = MeasureTextInWpf(exportText);
         *      textBlock.Width = wpfSize.Width;
         *      textBlock.Height = wpfSize.Height;
         * }
         *
         */

        /*
         * static Size MeasureTextInWpf(ExportText exportText){
         *
         *      if (exportText.CanGrow) {
         *              var formattedText = NewMethod(exportText);
         *
         *              formattedText.MaxTextWidth = exportText.DesiredSize.Width * 96.0 / 72.0;
         *
         *              formattedText.SetFontSize(Math.Floor(exportText.Font.Size  * 96.0 / 72.0));
         *
         *              var size = new Size {
         *                      Width = formattedText.WidthIncludingTrailingWhitespace,
         *                      Height = formattedText.Height + 6};
         *              return size;
         *      }
         *      return new Size(exportText.Size.Width,exportText.Size.Height);
         * }
         *
         */


        public static FormattedText CreateFormattedText(ExportText exportText)
        {
            var formattedText = new FormattedText(exportText.Text,
                                                  CultureInfo.CurrentCulture,
                                                  FlowDirection.LeftToRight,
                                                  new Typeface(exportText.Font.FontFamily.Name),
                                                  exportText.Font.Size,
                                                  new SolidColorBrush(exportText.ForeColor.ToWpf()), null, TextFormattingMode.Display);

            formattedText.MaxTextWidth = exportText.DesiredSize.Width * 96.0 / 72.0;
            formattedText.SetFontSize(Math.Floor(exportText.Font.Size * 96.0 / 72.0));

            var td = new TextDecorationCollection();

            CheckUnderline(td, exportText);
            formattedText.SetTextDecorations(td);
            return(formattedText);
        }
示例#24
0
        /// <summary>
        /// label1のフォント変更
        /// </summary>
        private void ChangeFont(System.Drawing.Font font, TextBlock tage)
        {
            tage.FontFamily = new FontFamily(font.Name);
            tage.FontSize   = font.Size * 96.0 / 72.0;
            tage.FontWeight = font.Bold ? FontWeights.Bold : FontWeights.Regular;
            tage.FontStyle  = font.Italic ? FontStyles.Italic : FontStyles.Normal;
            TextDecorationCollection tdc = new TextDecorationCollection();

            if (font.Underline)
            {
                tdc.Add(TextDecorations.Underline);
            }
            if (font.Strikeout)
            {
                tdc.Add(TextDecorations.Strikethrough);
            }
            tage.TextDecorations = tdc;
        }
示例#25
0
        public void Should_Parse_TextDecorations()
        {
            var baseline = TextDecorationCollection.Parse("baseline");

            Assert.Equal(TextDecorationLocation.Baseline, baseline[0].Location);

            var underline = TextDecorationCollection.Parse("underline");

            Assert.Equal(TextDecorationLocation.Underline, underline[0].Location);

            var overline = TextDecorationCollection.Parse("overline");

            Assert.Equal(TextDecorationLocation.Overline, overline[0].Location);

            var strikethrough = TextDecorationCollection.Parse("strikethrough");

            Assert.Equal(TextDecorationLocation.Strikethrough, strikethrough[0].Location);
        }
示例#26
0
 public object Convert(object value, Type targetType, object parameter,
                       CultureInfo culture)
 {
     if (value is bool)
     {
         if ((bool)value)
         {
             TextDecorationCollection redStrikthroughTextDecoration =
                 TextDecorations.Strikethrough.CloneCurrentValue();
             redStrikthroughTextDecoration[0].Pen =
                 new Pen {
                 Brush = Brushes.Red, Thickness = 3
             };
             return(redStrikthroughTextDecoration);
         }
     }
     return(new TextDecorationCollection());
 }
示例#27
0
        static TextDecorations()
        {
            // Underline
            underline            = new TextDecorationCollection();
            underline.Decoration = new TextDecoration(TextDecorationLocation.Underline);

            // Striketrough
            strikethrough            = new TextDecorationCollection();
            strikethrough.Decoration = new TextDecoration(TextDecorationLocation.Strikethrough);

            // Overline
            overline            = new TextDecorationCollection();
            overline.Decoration = new TextDecoration(TextDecorationLocation.OverLine);

            ////Baseline
            //baseline = new TextDecorationCollection();
            //baseline.Decoration = new TextDecoration(TextDecorationLocation.Baseline);
        }
示例#28
0
        private void SetLinearGradientUnderline()
        {
            var myBaseLine  = new TextDecoration();
            var myUnderLine = new TextDecoration();

            var gy = new Pen
            {
                Brush =
                    new LinearGradientBrush(Colors.Green, Colors.Yellow, new Point(0, 0.5),
                                            new Point(1, 0.5))
                {
                    Opacity = 0.5
                },
                Thickness = .75,
                DashStyle = DashStyles.DashDotDot
            };

            myBaseLine.Pen = gy;
            myBaseLine.PenThicknessUnit = TextDecorationUnit.FontRecommended;
            myBaseLine.Location         = TextDecorationLocation.OverLine;

            var yr = new Pen
            {
                Brush =
                    new LinearGradientBrush(Colors.Yellow, Colors.Red, new Point(0, 0.5), new Point(1, 0.5))
                {
                    Opacity = 0.5
                },
                Thickness = .75,
                DashStyle = DashStyles.DashDotDot
            };

            myUnderLine.Pen = yr;
            myUnderLine.PenThicknessUnit = TextDecorationUnit.FontRecommended;

            var myCollection = new TextDecorationCollection {
                myBaseLine, myUnderLine
            };
            var block = new TextBlock {
                TextDecorations = myCollection, Text = "Elinor"
            };

            label1.Content = block;
        }
示例#29
0
        // Update the menu's checkboxes.
        private void mnuFontStyle_SubmenuOpened(object sender, RoutedEventArgs e)
        {
            // Bold.
            Object fw_obj = rchBody.Selection.GetPropertyValue(
                TextElement.FontWeightProperty);

            if (fw_obj is FontWeight)
            {
                FontWeight fw = (FontWeight)fw_obj;
                mnuFontStyleBold.IsChecked = (fw == FontWeights.Bold);
            }
            else
            {
                mnuFontStyleBold.IsChecked = false;
            }

            // Italic.
            Object it_obj = rchBody.Selection.GetPropertyValue(
                TextElement.FontStyleProperty);

            if (it_obj is FontStyle)
            {
                FontStyle it = (FontStyle)it_obj;
                mnuFontStyleItalic.IsChecked = (it == FontStyles.Italic);
            }
            else
            {
                mnuFontStyleItalic.IsChecked = false;
            }

            // Underlined.
            Object ul_obj = rchBody.Selection.GetPropertyValue(Paragraph.TextDecorationsProperty);

            if (ul_obj is TextDecorationCollection)
            {
                TextDecorationCollection decorations = (TextDecorationCollection)ul_obj;
                mnuFontStyleUnderline.IsChecked = ((decorations.Count > 0) &&
                                                   (decorations[0].Location == TextDecorationLocation.Underline));
            }
            else
            {
                mnuFontStyleUnderline.IsChecked = false;
            }
        }
示例#30
0
        //-------------------------------------------------------------------
        //
        //  Private Methods
        //
        //-------------------------------------------------------------------

        #region Private Methods

        /// <summary>
        /// Fetch the next run at text position.
        /// </summary>
        private TextRun HandleText(StaticTextPointer position)
        {
            // Calculate the end of the run by finding either:
            //      a) the next intersection of highlight ranges, or
            //      b) the natural end of this textrun
            StaticTextPointer endOfRunPosition = _owner.Host.TextContainer.Highlights.GetNextPropertyChangePosition(position, LogicalDirection.Forward);

            // Clamp the text run at an arbitrary limit, so we don't make
            // an unbounded allocation.
            if (position.GetOffsetToPosition(endOfRunPosition) > 4096)
            {
                endOfRunPosition = position.CreatePointer(4096);
            }

            // Factor in any speller error squiggles on the run.
            TextDecorationCollection highlightDecorations = position.TextContainer.Highlights.GetHighlightValue(position, LogicalDirection.Forward, typeof(SpellerHighlightLayer)) as TextDecorationCollection;
            TextRunProperties        properties;

            if (highlightDecorations == null)
            {
                properties = _lineProperties.DefaultTextRunProperties;
            }
            else
            {
                if (_spellerErrorProperties == null)
                {
                    _spellerErrorProperties = new TextProperties((TextProperties)_lineProperties.DefaultTextRunProperties, highlightDecorations);
                }
                properties = _spellerErrorProperties;
            }

            // Get character buffer for the text run.
            char[] textBuffer = new char[position.GetOffsetToPosition(endOfRunPosition)];

            // Copy characters from text run into buffer. Since we are dealing with plain text content,
            // we expect to get all the characters from position to endOfRunPosition.
            int charactersCopied = position.GetTextInRun(LogicalDirection.Forward, textBuffer, 0, textBuffer.Length);

            Invariant.Assert(charactersCopied == textBuffer.Length);

            // Create text run, using characters copied as length
            return(new TextCharacters(textBuffer, 0, charactersCopied, properties));
        }
        public void HighlightErrors(FormattedText text, List <SyntaxError> Errors,
                                    List <InnerTextBlock> blocks)
        {
            Pen path_pen = new Pen(ErrorColor, 0.5)
            {
                EndLineCap   = PenLineCap.Square,
                StartLineCap = PenLineCap.Square
            };
            Point         path_start   = new Point(0, 1);
            BezierSegment path_segment = new BezierSegment(new Point(1, 0),
                                                           new Point(2, 2), new Point(3, 1), true);
            PathFigure path_figure = new PathFigure(path_start,
                                                    new PathSegment[] { path_segment }, false);
            PathGeometry path_geometry  = new PathGeometry(new[] { path_figure });
            DrawingBrush squiggly_brush = new DrawingBrush
            {
                Viewport      = new Rect(0, 0, 6, 4),
                ViewportUnits = BrushMappingMode.Absolute,
                TileMode      = TileMode.Tile,
                Drawing       = new GeometryDrawing(null, path_pen, path_geometry)
            };
            TextDecoration squiggly = new TextDecoration {
                Pen = new Pen(squiggly_brush, 6)
            };
            TextDecorationCollection collection = new TextDecorationCollection {
                squiggly
            };

            foreach (SyntaxError error in Errors)
            {
                string tag    = error.Tag ?? "";
                int    Line   = error.Line ?? -1;
                int    Column = error.Column ?? -1;
                //Check if a block with this line and column exists
                int TagPos = CodeHelper.getStartCharOfPos(text.Text, Line, Column);
                //If cannot find a block for this error
                if (TagPos < 0)
                {
                    continue;
                }
                text.SetTextDecorations(collection, TagPos, TagPos + tag.Length);
            }
        }
        /// <summary>
        /// ToggleUnderline command event handler.
        /// </summary>
        private static void OnToggleUnderline(object target, ExecutedRoutedEventArgs args)
        {
            TextEditor This = TextEditor._GetTextEditor(target);

            if (This == null || !This._IsEnabled || This.IsReadOnly || !This.AcceptsRichContent || !(This.Selection is TextSelection))
            {
                return;
            }

            TextEditorTyping._FlushPendingInputItems(This);

            object propertyValue = ((TextSelection)This.Selection).GetCurrentValue(Inline.TextDecorationsProperty);
            TextDecorationCollection textDecorations = propertyValue != DependencyProperty.UnsetValue ? (TextDecorationCollection)propertyValue : null;

            if (!TextSchema.HasTextDecorations(textDecorations))
            {
                textDecorations = TextDecorations.Underline;
            }
            else
            {
                textDecorations = new TextDecorationCollection(); // empty collection - no underline
            }

            TextEditorCharacters._OnApplyProperty(This, Inline.TextDecorationsProperty, 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;
        }
        //------------------------------------------------------
        //
        //  Internal Methods
        //
        //------------------------------------------------------

        #region Internal Methods

        // Adds a range to this collection.  Additions are expected to be in
        // order, and non-overlapping.
        internal void Add(ITextPointer start, ITextPointer end, TextDecorationCollection textDecorations)
        {
            // We expect all ranges to be added in order....
            Debug.Assert(_attributeRanges.Count == 0 || ((AttributeRange)_attributeRanges[_attributeRanges.Count - 1]).End.CompareTo(start) <= 0);

            _attributeRanges.Add(new AttributeRange(start, end, textDecorations));
        }
            internal AttributeRange(ITextPointer start, ITextPointer end, TextDecorationCollection textDecorations)
            {
                // AttributeRange should not be crossed later.
                Debug.Assert((start.LogicalDirection != LogicalDirection.Forward) || (end.LogicalDirection != LogicalDirection.Backward));

                _start = start;
                _end = end;
                _textDecorations = textDecorations;
            }
示例#36
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;
        }