public static TextDecoration Squiggly(Color color, TextDecorationLocation location = TextDecorationLocation.Underline)
        {
            var penVisual = new Path
            {
                Stroke = new SolidColorBrush(color),
                StrokeThickness = 0.2,
                StrokeEndLineCap = PenLineCap.Square,
                StrokeStartLineCap = PenLineCap.Square,
                Data = new PathGeometry(new[] { new PathFigure(new Point(0, 1), new[] { new BezierSegment(new Point(1, 0), new Point(2, 2), new Point(3, 1), true) }, false) })
            };

            var penBrush = new VisualBrush
            {
                Viewbox = new Rect(0, 0, 3, 2),
                ViewboxUnits = BrushMappingMode.Absolute,
                Viewport = new Rect(0, 0.8, 6, 3),
                ViewportUnits = BrushMappingMode.Absolute,
                TileMode = TileMode.Tile,
                Visual = penVisual
            };

            var pen = new Pen
            {
                Brush = penBrush,
                Thickness = 6
            };

            return new TextDecoration(location, pen, 0, TextDecorationUnit.FontRecommended, TextDecorationUnit.FontRecommended);
        }
예제 #2
0
        public static TextDecoration Squiggly(Color color, TextDecorationLocation location = TextDecorationLocation.Underline)
        {
            var penVisual = new Path
            {
                Stroke             = new SolidColorBrush(color),
                StrokeThickness    = 0.2,
                StrokeEndLineCap   = PenLineCap.Square,
                StrokeStartLineCap = PenLineCap.Square,
                Data = new PathGeometry(new[]
                {
                    new PathFigure(new Point(0, 1), new[]
                    {
                        new BezierSegment(new Point(1, 0), new Point(2, 2), new Point(3, 1), true)
                    }, false)
                })
            };

            var penBrush = new VisualBrush
            {
                Viewbox       = new Rect(0, 0, 3, 2),
                ViewboxUnits  = BrushMappingMode.Absolute,
                Viewport      = new Rect(0, 0.8, 6, 3),
                ViewportUnits = BrushMappingMode.Absolute,
                TileMode      = TileMode.Tile,
                Visual        = penVisual
            };

            var pen = new Pen
            {
                Brush     = penBrush,
                Thickness = 6
            };

            return(new TextDecoration(location, pen, 0, TextDecorationUnit.FontRecommended, TextDecorationUnit.FontRecommended));
        }
예제 #3
0
 private void SetfontDecoration(TextDecorationLocation type, bool setvalue)
 {
     if (Selection != null && Selection.Text.Length > 0)
     {
         TextRange rang = new TextRange(Selection.Start, Selection.End);
         SetfontDecoration(rang, type, setvalue);
         Selection.Select(rang.Start, rang.End);
     }
     else
     {
         try
         {
             foreach (Block block in Document.Blocks)//vivid
             {
                 if (block is Paragraph)
                 {
                     Paragraph para = block as Paragraph;
                     foreach (Run run in para.Inlines)
                     {
                         ChangeElementDecoration(run, type, setvalue);
                     }
                 }
                 else
                 {
                     NLogger.Error("SetfontDecoration->Invalid Block in Document.Blocks!");
                 }
             }
         }
         catch (System.Exception ex)
         {
             System.Diagnostics.Debug.WriteLine(ex.Message);
         }
     }
 }
예제 #4
0
        private static TextDecoration MakeTextDecoration(TextDecorationLocation location, Pen pen, double offset = 0.0)
        {
            TextDecoration textDecoration = new();

            textDecoration.Pen       = pen;
            textDecoration.Location  = location;
            textDecoration.PenOffset = offset;
            return(textDecoration);
        }
        /// <summary>
        ///     Returns whether or not an enumeration instance a valid value.
        ///     This method is designed to be used with ValidateValueCallback, and thus
        ///     matches it's prototype.
        /// </summary>
        /// <param name="valueObject">
        ///     Enumeration value to validate.
        /// </param>
        /// <returns> 'true' if the enumeration contains a valid value, 'false' otherwise. </returns>
        public static bool IsTextDecorationLocationValid(object valueObject)
        {
            TextDecorationLocation value = (TextDecorationLocation)valueObject;

            return((value == TextDecorationLocation.Underline) ||
                   (value == TextDecorationLocation.OverLine) ||
                   (value == TextDecorationLocation.Strikethrough) ||
                   (value == TextDecorationLocation.Baseline));
        }
예제 #6
0
 public FontStyleData(string name, FontStyle fontStyle, FontWeight fontWeight, TextDecorationLocation? textDecoration, FontVariants fontVariant, FontCapitals fontCapitals, double fontSize)
 {
     _name = name;
     _fontStyle = fontStyle;
     _fontWeight = fontWeight;
     _textDecoration = textDecoration;
     _fontVariant = fontVariant;
     _fontCapitals = fontCapitals;
     _fontSize = fontSize;
 }
예제 #7
0
 public ImmutableTextDecoration(TextDecorationLocation location, ImmutablePen pen,
                                TextDecorationUnit penThicknessUnit,
                                double penOffset, TextDecorationUnit penOffsetUnit)
 {
     Location         = location;
     Pen              = pen;
     PenThicknessUnit = penThicknessUnit;
     PenOffset        = penOffset;
     PenOffsetUnit    = penOffsetUnit;
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="location">The location of the text decoration</param>
 /// <param name="pen">The pen used to draw this text decoration</param>
 /// <param name="penOffset">The offset of this text decoration to the location</param>
 /// <param name="penOffsetUnit">The unit of the offset</param>
 /// <param name="penThicknessUnit">The unit of the thickness of the pen</param>
 public TextDecoration(
     TextDecorationLocation location,
     Pen                    pen,
     double                 penOffset,
     TextDecorationUnit     penOffsetUnit,
     TextDecorationUnit     penThicknessUnit
     )
 {
     Location         = location;
     Pen              = pen;
     PenOffset        = penOffset;
     PenOffsetUnit    = penOffsetUnit;
     PenThicknessUnit = penThicknessUnit;        
 }      
예제 #9
0
        private bool?CheckDeco(TextDecorationLocation loc)
        {
            if (_document == null)
            {
                return(null);
            }
            var decos = _document.Selection.GetPropertyValue(Inline.TextDecorationsProperty);

            if (decos != DependencyProperty.UnsetValue)
            {
                return(((TextDecorationCollection)decos)
                       .Any(x => x.Location == loc));
            }
            return(null);
        }
예제 #10
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);
            }
        }
예제 #11
0
        public static bool? GetTextDecorationOnSelection(TextRange range, TextDecorationLocation decorationLocation)
        {
            if (range.GetPropertyValue(TextBlock.TextDecorationsProperty) == DependencyProperty.UnsetValue)
                return null;

            TextDecorationCollection decorations = (TextDecorationCollection)range.GetPropertyValue(TextBlock.TextDecorationsProperty);

            if (decorations == null)
                return false;

            foreach (TextDecoration decoration in decorations)
            {
                if (decoration.Location == decorationLocation)
                    return true;
            }

            return false;
        }
예제 #12
0
        public static bool?GetTextDecorationOnSelection(TextRange range, TextDecorationLocation decorationLocation)
        {
            if (range.GetPropertyValue(TextBlock.TextDecorationsProperty) == DependencyProperty.UnsetValue)
            {
                return(null);
            }

            TextDecorationCollection decorations = (TextDecorationCollection)range.GetPropertyValue(TextBlock.TextDecorationsProperty);

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

            foreach (TextDecoration decoration in decorations)
            {
                if (decoration.Location == decorationLocation)
                {
                    return(true);
                }
            }

            return(false);
        }
예제 #13
0
        private void ToggleTextDecoration(TextDecorationLocation location)
        {
            var value = RichTextBox.Selection.GetPropertyValue(Inline.TextDecorationsProperty) as TextDecorationCollection;

            if (value == null)
            {
                RichTextBox.Selection.ApplyPropertyValue(Inline.TextDecorationsProperty, new TextDecorationCollection());
                return;
            }
            var collection = value.CloneCurrentValue();
            var existing   = collection.FirstOrDefault(x => x.Location == location);

            if (existing != null)
            {
                collection.Remove(existing);
            }
            else
            {
                collection.Add(new TextDecoration {
                    Location = location
                });
            }
            RichTextBox.Selection.ApplyPropertyValue(Inline.TextDecorationsProperty, collection);
        }
예제 #14
0
 internal TextDecoration(TextDecorationLocation location)
 {
     this.Location = location;
 }
 public TextDecoration(TextDecorationLocation location, System.Windows.Media.Pen pen, double penOffset, TextDecorationUnit penOffsetUnit, TextDecorationUnit penThicknessUnit)
 {
 }
예제 #16
0
        /// <summary>
        /// Retrieves TextDecoration style.
        /// </summary>
        private static TextDecorationLineStyle GetTextDecorationLineStyle(TextDecorationCollection decorations, TextDecorationLocation location)
        {
            if (decorations == null)
            {
                return TextDecorationLineStyle.None;
            }

            TextDecorationLineStyle lineStyle = TextDecorationLineStyle.None;
            foreach (TextDecoration decor in decorations)
            {
                if (decor.Location == location)
                {
                    if (lineStyle == TextDecorationLineStyle.None)
                    {
                        // There's a whole bunch of all kinds of custom styles defined in TextDecorationLineStyle 
                        // including WordsOnly, Double, Wavy, DoubleWavy, ThickWavy, which we can not determine from 
                        // TextDecoration anyway. Hence, it seems would be too much bang for a buck if we try 
                        // to guess out the other dozen by analyzing TextDecoration.Pen. Let's keep it simple 
                        // and make difference only between solid and dashed lines. 
                        if (decor.Pen != null)
                        {
                            lineStyle = (decor.Pen.DashStyle.Dashes.Count > 1) ? TextDecorationLineStyle.Dash : TextDecorationLineStyle.Single;
                        }
                        else
                        {
                            lineStyle = TextDecorationLineStyle.Single;
                        }
                    }
                    else
                    {
                        lineStyle = TextDecorationLineStyle.Other;
                        break;
                    }
                }
            }
            return lineStyle;
        }
예제 #17
0
        /// <summary>
        /// Retrieves TextDecoration color.
        /// </summary>
        private static int GetTextDecorationColor(TextDecorationCollection decorations, TextDecorationLocation location)
        {
            if (decorations == null)
            {
                return 0;
            }

            int color = 0;
            foreach (TextDecoration decor in decorations)
            {
                if (decor.Location == location)
                {
                    if (decor.Pen != null)
                    {
                        color = ColorFromBrush(decor.Pen.Brush);
                        // Ignore other decorations and their coloring if there're more at the same location.
                        break;
                    }
                }
            }
            return color;
        }
 public TextDecoration(TextDecorationLocation location, System.Windows.Media.Pen pen, double penOffset, TextDecorationUnit penOffsetUnit, TextDecorationUnit penThicknessUnit)
 {
 }
예제 #19
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);
            }
        }
예제 #20
0
        private void ChangeElementDecoration(Inline run, TextDecorationLocation type, bool bAdd)
        {
            if (type == TextDecorationLocation.Underline)
            {
                if (bAdd)
                {
                    bool isExit = false;

                    foreach (TextDecoration de in run.TextDecorations)
                    {
                        if (de.Location == TextDecorationLocation.Underline)
                        {
                            isExit = true;
                            break;
                        }
                    }

                    if (!isExit)
                    {
                        run.TextDecorations.Add(CommonFunction.GetUnderline()[0]);
                    }
                }
                else
                {
                    int index = -1;
                    foreach (TextDecoration de in run.TextDecorations)
                    {
                        index++;
                        if (de.Location == TextDecorationLocation.Underline)
                        {
                            run.TextDecorations.RemoveAt(index);
                            break;
                        }
                    }
                }
            }

            if (type == TextDecorationLocation.Strikethrough)
            {
                if (bAdd)
                {
                    bool isExit = false;

                    foreach (TextDecoration de in run.TextDecorations)
                    {
                        if (de.Location == TextDecorationLocation.Strikethrough)
                        {
                            isExit = true;
                            break;
                        }
                    }
                    if (!isExit)
                    {
                        run.TextDecorations.Add(CommonFunction.GetStrikeThough()[0]);
                    }
                }
                else
                {
                    int index = -1;
                    foreach (TextDecoration de in run.TextDecorations)
                    {
                        index++;
                        if (de.Location == TextDecorationLocation.Strikethrough)
                        {
                            run.TextDecorations.RemoveAt(index);
                            break;
                        }
                    }
                }
            }
        }
예제 #21
0
        private void SetfontDecoration(TextRange range, TextDecorationLocation type, bool setvalue)
        {
            using (MemoryStream ms = new MemoryStream())
            {
                if (range.CanSave(DataFormats.Xaml))
                {
                    range.Save(ms, DataFormats.Xaml, true);

                    //string teststring =  ASCIIEncoding.Default.GetString(ms.ToArray());
                    ms.Seek(0, SeekOrigin.Begin);

                    object obj = XamlReader.Load(ms);

                    if (obj is Span)
                    {
                        Span span = obj as Span;
                        foreach (Run run in span.Inlines)
                        {
                            ChangeElementDecoration(run, type, setvalue);
                        }

                        using (MemoryStream mso = new MemoryStream())
                        {
                            XamlWriter.Save(span, mso);
                            mso.Seek(0, SeekOrigin.Begin);

                            range.Load(mso, DataFormats.Xaml);
                        }
                    }
                    else if (obj is Section)
                    {
                        Section section = obj as Section;
                        foreach (Block block in section.Blocks)//vivid
                        {
                            if (block is Paragraph)
                            {
                                Paragraph para = block as Paragraph;
                                foreach (Run run in para.Inlines)
                                {
                                    ChangeElementDecoration(run, type, setvalue);
                                }
                            }
                            else
                            {
                                NLogger.Error("SetfontDecoration->Invalid Block in section.Blocks!");
                            }
                        }

                        using (MemoryStream mso = new MemoryStream())
                        {
                            XamlWriter.Save(section, mso);
                            mso.Seek(0, SeekOrigin.Begin);

                            range.Load(mso, DataFormats.Xaml);
                        }
                    }
                    else
                    {
                        NLogger.Error("SetfontDecoration select span or section is null\n" + Selection.Text.ToString());
                    }
                }
            }
        }