Ejemplo n.º 1
0
        void UpdateTextDecorations()
        {
            if (!Element.IsSet(Label.TextDecorationsProperty))
            {
                return;
            }

            var textDecorations = Element.TextDecorations;

            var newTextDecorations = new System.Windows.TextDecorationCollection(Control.TextDecorations);

            if ((textDecorations & TextDecorations.Underline) == 0)
            {
                newTextDecorations.TryRemove(System.Windows.TextDecorations.Underline, out newTextDecorations);
            }
            else
            {
                newTextDecorations.Add(System.Windows.TextDecorations.Underline);
            }

            if ((textDecorations & TextDecorations.Strikethrough) == 0)
            {
                newTextDecorations.TryRemove(System.Windows.TextDecorations.Strikethrough, out newTextDecorations);
            }
            else
            {
                newTextDecorations.Add(System.Windows.TextDecorations.Strikethrough);
            }

            Control.TextDecorations = newTextDecorations;
        }
Ejemplo n.º 2
0
 void SetDecorations(FontDecoration decoration)
 {
     WpfTextDecorations = new sw.TextDecorationCollection();
     if (decoration.HasFlag(FontDecoration.Underline))
     {
         WpfTextDecorations.Add(sw.TextDecorations.Underline);
     }
     if (decoration.HasFlag(FontDecoration.Strikethrough))
     {
         WpfTextDecorations.Add(sw.TextDecorations.Strikethrough);
     }
     this.decoration = decoration;
 }
Ejemplo n.º 3
0
 public override void AddAttribute(object backend, TextAttribute attribute)
 {
     var t = (TextLayoutBackend)backend;
     if (attribute is FontStyleTextAttribute) {
         var xa = (FontStyleTextAttribute)attribute;
         t.FormattedText.SetFontStyle (xa.Style.ToWpfFontStyle (), xa.StartIndex, xa.Count);
     }
     else if (attribute is FontWeightTextAttribute) {
         var xa = (FontWeightTextAttribute)attribute;
         t.FormattedText.SetFontWeight (xa.Weight.ToWpfFontWeight (), xa.StartIndex, xa.Count);
     }
     else if (attribute is ColorTextAttribute) {
         var xa = (ColorTextAttribute)attribute;
         t.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);
         t.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);
         t.FormattedText.SetTextDecorations (col, xa.StartIndex, xa.Count);
     }
 }
 public MarkdownHeaderFormatDefinition()
 {
     IsBold = true;
     TextDecorations = new TextDecorationCollection();
     TextDecorations.Add(new TextDecoration());
     DisplayName = "Markdown Headers";
 }
Ejemplo n.º 5
0
 private TextDecorationCollection GetTextDecorations()
 {
     TextDecorationCollection textDecorations = new TextDecorationCollection();
     if (Strikeout)
         textDecorations.Add(TextDecorations.Strikethrough);
     if (Underline)
         textDecorations.Add(TextDecorations.Underline);
     return textDecorations;
 }
Ejemplo n.º 6
0
        private static void CopyTextDecorationCollection(TextDecorationCollection from, TextDecorationCollection to)
        {
            int count = from.Count;

            for (int i = 0; i < count; ++i)
            {
                to.Add(from[i]);
            }
        }
Ejemplo n.º 7
0
			public CustomTextRunProperties(Typeface typeface, double fontSize, Brush foreground, Brush background, bool underline)
			{
				_typeface = typeface;
				_fontSize = fontSize;
				_foreground = foreground;
				_background = background;
				if (underline)
				{
					_decorations = new TextDecorationCollection(1);
					_decorations.Add(System.Windows.TextDecorations.Underline);
				}
			}
        private TextDecorationCollection BuildDecoration()
        {
            var result = new TextDecorationCollection();
            if (HasFlag(0x01))
            {
                result.Add(new TextDecoration(TextDecorationLocation.Underline, null, 0.0, TextDecorationUnit.FontRecommended, TextDecorationUnit.FontRecommended));
            }
            else if (HasFlag(0x08))
            {
                result.Add(new TextDecoration(TextDecorationLocation.Strikethrough, null, 0.0, TextDecorationUnit.FontRecommended, TextDecorationUnit.FontRecommended));
            }
            else if (HasFlag(0x100))
            {
                result.Add(new TextDecoration() { Location = TextDecorationLocation.Underline, PenOffset = 1 });
                result.Add(new TextDecoration() { Location = TextDecorationLocation.Underline, PenOffset = -1 });
            }
            else if (HasFlag(0x200))
            {
                result.Add(new TextDecoration() { Location = TextDecorationLocation.Strikethrough, PenOffset = 0.5 });
                result.Add(new TextDecoration() { Location = TextDecorationLocation.Strikethrough, PenOffset = 0}   );
            }

            return result;
        }
Ejemplo n.º 9
0
		static void CheckUnderline(TextDecorationCollection td, ExportText exportText)
		{
			if (exportText.Font.Underline) {
				td.Add(new TextDecoration{Location = TextDecorationLocation.Underline});
			}
		}
        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;
        }
Ejemplo n.º 11
0
        private void LoadWord(int i)
        {
            int a = 0;
            foreach (char l in _words[i].WordFull)
            {
                TextBlock letter = new TextBlock();
                letter.Foreground = new SolidColorBrush(Colors.Gray);
                letter.Text = l.ToString();
                letter.Margin = new Thickness(1);
                letter.FontFamily = new FontFamily(new Uri("pack://application:,,,/"), "./Stuff/#Monaco");

                if (_words[i].Index == a)
                {
                    letter.Text = ((char) 160).ToString();

                    // Create an underline text decoration. Default is underline.
                    TextDecoration underline = new TextDecoration();

                    // Create a solid color brush pen for the text decoration.
                    underline.Pen = new Pen(Brushes.Gray, 1);
                    underline.PenThicknessUnit = TextDecorationUnit.FontRecommended;

                    // Set the underline decoration to a TextDecorationCollection and add it to the text block.
                    TextDecorationCollection decorations = new TextDecorationCollection();
                    decorations.Add(underline);
                    letter.TextDecorations = decorations;
                }
                a++;

                letters.Children.Add(letter);
            }
            this.img.Source = null;
            ControlGrid.IsEnabled = true;
        }
Ejemplo n.º 12
0
        static void ApplyPrintStyles(FormattedText formattedText,ExportText exportText)
        {
            var font = exportText.Font;
            var textDecorations = new TextDecorationCollection();
            FontStyle fontStyle;
            FontWeight fontWeight;

            if ((font.Style & System.Drawing.FontStyle.Italic) != 0) {
                fontStyle = FontStyles.Italic;
            } else {
                fontStyle = FontStyles.Normal;
            }

            formattedText.SetFontStyle(fontStyle);

            if ((font.Style & System.Drawing.FontStyle.Bold) != 0) {
                fontWeight = FontWeights.Bold;
            } else {
                fontWeight = FontWeights.Normal;
            }
            formattedText.SetFontWeight(fontWeight);

            if ((font.Style & System.Drawing.FontStyle.Underline) != 0) {
                textDecorations.Add(TextDecorations.Underline);
            }

            if ((font.Style & System.Drawing.FontStyle.Strikeout) != 0) {
                textDecorations.Add(TextDecorations.Strikethrough);
            }

            formattedText.SetTextDecorations(textDecorations);
        }
Ejemplo n.º 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;
        }
Ejemplo n.º 14
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();
        }
Ejemplo n.º 15
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(_pixelsPerDip);
        }
Ejemplo n.º 16
0
 public override void SetUnderline(object backend, int startIndex, int count)
 {
     var t = (TextLayoutBackend)backend;
     var dec = new TextDecoration (TextDecorationLocation.Underline, null, 0, TextDecorationUnit.FontRecommended, TextDecorationUnit.FontRecommended);
     TextDecorationCollection col = new TextDecorationCollection ();
     col.Add (dec);
     t.FormattedText.SetTextDecorations (col);
 }
Ejemplo n.º 17
0
        private void redraw(TerminalRun[] runs)
        {
            Dispatcher.VerifyAccess();

            //drawnRuns = new List<VisualRun>(runs.Length);
            //for (int i = 0; i < runs.Length; ++i)
            //{
            //	drawnRuns.Add(new VisualRun() { Run = runs[i], Text = null });
            //}
            bool changed = false;
            for (int i = 0; i < Math.Min(drawnRuns.Count, runs.Length); ++i)
            {
                if (drawnRuns[i].Run.Text != runs[i].Text || drawnRuns[i].Run.Font != runs[i].Font)
                {
                    drawnRuns[i] = new VisualRun() { Run = runs[i], Text = null };
                    changed = true;
                }
            }

            if (drawnRuns.Count > runs.Length)
                drawnRuns.RemoveRange(runs.Length, drawnRuns.Count - runs.Length);
            else if (drawnRuns.Count < runs.Length)
                drawnRuns.AddRange(runs.Skip(drawnRuns.Count).Select(x => new VisualRun() { Run = x }));
            else if (!changed && !selectionChanged)
                return;
            selectionChanged = false;

            for (int i = 0; i < drawnRuns.Count; ++i)
            {
                var run = drawnRuns[i].Run;
                if (drawnRuns[i].Text != null)
                    continue;

                SolidColorBrush foreground = Terminal.GetFontForegroundBrush(run.Font);

                // Format the text for this run.  However, this is drawn NEXT run.  The
                // background is drawn one run ahead of the text so the text doesn't get
                // clipped.
                var ft = new FormattedText(
                    run.Text,
                    System.Globalization.CultureInfo.CurrentUICulture,
                    Terminal.FlowDirection,
                    Terminal.GetFontTypeface(run.Font),
                    Terminal.FontSize,
                    foreground,
                    new NumberSubstitution(),
                    TextFormattingMode.Ideal
                    );

                if (run.Font.Underline || run.Font.Strike)
                {
                    var textDecorations = new TextDecorationCollection(2);

                    if (run.Font.Underline)
                        textDecorations.Add(TextDecorations.Underline);
                    if (run.Font.Strike)
                        textDecorations.Add(TextDecorations.Strikethrough);

                    ft.SetTextDecorations(textDecorations);
                }

                drawnRuns[i] = new VisualRun() { Run = drawnRuns[i].Run, Text = ft };
            }

            var context = RenderOpen();
            try
            {
                var drawPoint = new System.Windows.Point(0, 0);
                int index = 0;
                foreach (var run in drawnRuns)
                {
                    if (run.Run.Font.Hidden && index == drawnRuns.Count - 1)
                        break;

                    SolidColorBrush background = Terminal.GetFontBackgroundBrush(run.Run.Font);

                    // Draw the background and border for the current run
                    Pen border = null;
                    if (Terminal.DrawRunBoxes)
                        border = new Pen(DebugColors.GetBrush(index), 1);

                    var backgroundTopLeft = new System.Windows.Point(Math.Floor(drawPoint.X), Math.Floor(drawPoint.Y));
                    var backgroundSize = new Vector(Math.Floor(run.Text.WidthIncludingTrailingWhitespace), Math.Ceiling(run.Text.Height));
                    context.DrawRectangle(background, border, new Rect(backgroundTopLeft, backgroundSize));

                    drawPoint.X += run.Text.WidthIncludingTrailingWhitespace;

                    index++;
                }

                drawPoint = new System.Windows.Point(0, 0);
                index = 0;
                foreach (var run in drawnRuns)
                {
                    if (run.Run.Font.Hidden && index == drawnRuns.Count - 1)
                        break;

                    context.DrawText(run.Text, drawPoint);
                    drawPoint.X += run.Text.WidthIncludingTrailingWhitespace;

                    index++;
                }

                // TODO: This selection drawing logic doesn't account for multi-width characters.
                if (SelectionStart != SelectionEnd)
                {
                    var selectRect = new Rect(
                        new System.Windows.Point(Math.Floor(Math.Min(drawPoint.X, Terminal.CharWidth * SelectionStart)), 0.0),
                        new System.Windows.Point(Math.Ceiling(Math.Min(drawPoint.X, Terminal.CharWidth * SelectionEnd)), Math.Ceiling(Terminal.CharHeight)));

                    var brush = new SolidColorBrush(System.Windows.Media.Color.FromArgb(128, 90, 180, 230));
                    context.DrawRectangle(brush, null, selectRect);
                }
            }
            finally
            {
                context.Close();
            }
        }
        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");
        }
Ejemplo n.º 19
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;
        }
Ejemplo n.º 20
0
        // ----------------------------------------------------------------- 
        // Retrieve text properties from specified inline object.
        // 
        // WORKAROUND: see PS task #13486 & #3399. 
        // For inline object go to its parent and retrieve text decoration
        // properties from there. 
        // ------------------------------------------------------------------
        internal static TextDecorationCollection GetTextDecorationsForInlineObject(DependencyObject element, TextDecorationCollection textDecorations)
        {
            Debug.Assert(element != null); 

            DependencyObject parent = LogicalTreeHelper.GetParent(element); 
            TextDecorationCollection parentTextDecorations = null; 

            if (parent != null) 
            {
                // Get parent text decorations if it is non-null
                parentTextDecorations = GetTextDecorations(parent);
            } 

            // see if the two text decorations are equal. 
            bool textDecorationsEqual = (textDecorations == null) ? 
                                         parentTextDecorations == null
                                       : textDecorations.ValueEquals(parentTextDecorations); 

            if (!textDecorationsEqual)
            {
                if (parentTextDecorations == null) 
                {
                    textDecorations = null; 
                } 
                else
                { 
                    textDecorations = new TextDecorationCollection();
                    int count = parentTextDecorations.Count;
                    for (int i = 0; i < count; ++i)
                    { 
                        textDecorations.Add(parentTextDecorations[i]);
                    } 
                } 
            }
            return textDecorations; 
        }
Ejemplo n.º 21
0
        static SpellChecker()
        {
            TextDecorationCollection tdc = new TextDecorationCollection();

            StreamGeometry g = new StreamGeometry();
            using (var context = g.Open())
            {
                context.BeginFigure(new Point(0, 2), false, false);
                context.BezierTo(new Point(2, 0), new Point(4, 4), new Point(6, 2), true, true);
            }

            System.Windows.Shapes.Path p = new System.Windows.Shapes.Path() { Data = g, Stroke = Brushes.Red, StrokeThickness = 0.5, StrokeEndLineCap = PenLineCap.Square, StrokeStartLineCap = PenLineCap.Square };

            VisualBrush vb = new VisualBrush(p)
            {
                Viewbox = new Rect(0, 0, 6, 4),
                ViewboxUnits = BrushMappingMode.Absolute,
                Viewport = new Rect(0, 0, 6, 4),
                ViewportUnits = BrushMappingMode.Absolute,
                TileMode = TileMode.Tile

            };

            TextDecoration td = new TextDecoration()
            {
                Location = TextDecorationLocation.Underline,
                Pen = new Pen(vb, 3),
                PenThicknessUnit = TextDecorationUnit.Pixel,
                PenOffsetUnit = TextDecorationUnit.Pixel

            };
            tdc.Add(td);

            defaultdecoration = tdc;

            tdc = new TextDecorationCollection();

            g = new StreamGeometry();
            using (var context = g.Open())
            {
                context.BeginFigure(new Point(0, 2), false, false);
                context.BezierTo(new Point(2, 0), new Point(4, 4), new Point(6, 2), true, true);
                context.Close();
            }

            p = new System.Windows.Shapes.Path() { Data = g, Stroke = Brushes.Green, StrokeThickness = 0.5, StrokeEndLineCap = PenLineCap.Square, StrokeStartLineCap = PenLineCap.Square };

            vb = new VisualBrush(p)
               {
               Viewbox = new Rect(0, 0, 6, 4),
               ViewboxUnits = BrushMappingMode.Absolute,
               Viewport = new Rect(0, 0, 6, 4),
               ViewportUnits = BrushMappingMode.Absolute,
               TileMode = TileMode.Tile

               };

            td = new TextDecoration()
               {
               Location = TextDecorationLocation.Underline,
               Pen = new Pen(vb, 3),
               PenThicknessUnit = TextDecorationUnit.Pixel,
               PenOffsetUnit = TextDecorationUnit.Pixel

               };
            tdc.Add(td);

            defaultdecorationSuggestion = tdc;
        }
        /// <summary>
        /// ConvertFromString
        /// </summary>
        /// <param name="text"> The string to be converted into TextDecorationCollection object </param>
        /// <returns> the converted value of the string flag </returns>
        /// <remarks>
        /// The text parameter can be either string "None" or a combination of the predefined
        /// TextDecoration names delimited by commas (,). One or more blanks spaces can precede
        /// or follow each text decoration name or comma. There can't be duplicate TextDecoration names in the
        /// string. The operation is case-insensitive.
        /// </remarks>
        public static new TextDecorationCollection ConvertFromString(string text)
        {
            if (text == null)
            {
                return(null);
            }

            TextDecorationCollection textDecorations = new TextDecorationCollection();

            // Flags indicating which Predefined textDecoration has alrady been added.
            byte MatchedTextDecorationFlags = 0;

            // Start from the 1st non-whitespace character
            // Negative index means error is encountered
            int index = AdvanceToNextNonWhiteSpace(text, 0);

            while (index >= 0 && index < text.Length)
            {
                if (Match(None, text, index))
                {
                    // Matched "None" in the input
                    index = AdvanceToNextNonWhiteSpace(text, index + None.Length);
                    if (textDecorations.Count > 0 || index < text.Length)
                    {
                        // Error: "None" can only be specified by its own
                        index = -1;
                    }
                }
                else
                {
                    // Match the input with one of the predefined text decoration names
                    int i;
                    for (i = 0;
                         i < TextDecorationNames.Length &&
                         !Match(TextDecorationNames[i], text, index);
                         i++
                         )
                    {
                        ;
                    }

                    if (i < TextDecorationNames.Length)
                    {
                        // Found a match within the predefined names
                        if ((MatchedTextDecorationFlags & (1 << i)) > 0)
                        {
                            // Error: The matched value is duplicated.
                            index = -1;
                        }
                        else
                        {
                            // Valid match. Add to the collection and remember that this text decoration
                            // has been added
                            textDecorations.Add(PredefinedTextDecorations[i]);
                            MatchedTextDecorationFlags |= (byte)(1 << i);

                            // Advance to the start of next name
                            index = AdvanceToNextNameStart(text, index + TextDecorationNames[i].Length);
                        }
                    }
                    else
                    {
                        // Error: no match found in the predefined names
                        index = -1;
                    }
                }
            }

            if (index < 0)
            {
                throw new ArgumentException(SR.Get(SRID.InvalidTextDecorationCollectionString, text));
            }

            return(textDecorations);
        }
        private static TextDecorationCollection GetUnderlineTextDecorations(XmlReader reader, Inline inline)
        {
            TextDecoration textDecoration;
            Brush brush;
            var color = GetColor(reader[ColorAttribute, WordprocessingMLNamespace]);

            if (color.HasValue)
                brush = new SolidColorBrush(color.Value);
            else
                brush = inline.Foreground;

            var textDecorations = new TextDecorationCollection()
            {
                (textDecoration = new TextDecoration()
                {
                    Location = TextDecorationLocation.Underline,
                    Pen = new Pen()
                    {
                        Brush = brush
                    }
                })
            };

            switch (GetValueAttribute(reader))
            {
                case "single":
                    break;
                case "double":
                    textDecoration.PenOffset = inline.FontSize * 0.05;
                    textDecoration = textDecoration.Clone();
                    textDecoration.PenOffset = inline.FontSize * -0.05;
                    textDecorations.Add(textDecoration);
                    break;
                case "dotted":
                    textDecoration.Pen.DashStyle = DashStyles.Dot;
                    break;
                case "dash":
                    textDecoration.Pen.DashStyle = DashStyles.Dash;
                    break;
                case "dotDash":
                    textDecoration.Pen.DashStyle = DashStyles.DashDot;
                    break;
                case "dotDotDash":
                    textDecoration.Pen.DashStyle = DashStyles.DashDotDot;
                    break;
                case "none":
                default:
                    // If underline type is none or unsupported then it will be ignored.
                    return null;
            }

            return textDecorations;
        }
Ejemplo n.º 24
0
        private static void CopyTextDecorationCollection(TextDecorationCollection from, TextDecorationCollection to)
        {

            int count = from.Count;
            for (int i = 0; i < count; ++i)
            {
                to.Add(from[i]);
            }
        }
Ejemplo n.º 25
0
 protected virtual void Parse(SVG svg, string name, string value)
 {
     if (name == SVGTags.sTransform)
     {
         this.Transform = ShapeUtil.ParseTransform(value.ToLower());
         return;
     }
     if (name == SVGTags.sStroke)
     {
         this.GetStroke(svg).Color = svg.PaintServers.Parse(value);
         return;
     }
     if (name == SVGTags.sStrokeWidth)
     {
         this.GetStroke(svg).Width = XmlUtil.ParseDouble(svg, value);
         return;
     }
     if (name == SVGTags.sStrokeOpacity)
     {
         this.GetStroke(svg).Opacity = XmlUtil.ParseDouble(svg, value) * 100;
         return;
     }
     if (name == SVGTags.sStrokeDashArray)
     {
         if (value == "none")
         {
             this.GetStroke(svg).StrokeArray = null;
             return;
         }
         ShapeUtil.StringSplitter sp = new ShapeUtil.StringSplitter(value);
         List<double> a = new List<double>();
         while (sp.More)
         {
             a.Add(sp.ReadNextValue());
         }
         this.GetStroke(svg).StrokeArray = a.ToArray();
         return;
     }
     if (name == SVGTags.sStrokeLinecap)
     {
         this.GetStroke(svg).LineCap = (Stroke.eLineCap)Enum.Parse(typeof(Stroke.eLineCap), value);
         return;
     }
     if (name == SVGTags.sStrokeLinejoin)
     {
         this.GetStroke(svg).LineJoin = (Stroke.eLineJoin)Enum.Parse(typeof(Stroke.eLineJoin), value);
         return;
     }
     if (name == SVGTags.sClipPath)
     {
         if (value.StartsWith("url"))
         {
             Shape result;
             string id = ShapeUtil.ExtractBetween(value, '(', ')');
             if (id.Length > 0 && id[0] == '#') id = id.Substring(1);
             svg.m_shapes.TryGetValue(id, out result);
             this.m_clip = result as Clip;
             return;
         }
         return;
     }
     if (name == SVGTags.sFill)
     {
         this.GetFill(svg).Color = svg.PaintServers.Parse(value);
         return;
     }
     if (name == SVGTags.sFillOpacity)
     {
         this.GetFill(svg).Opacity = XmlUtil.ParseDouble(svg, value) * 100;
         return;
     }
     if (name == SVGTags.sFillRule)
     {
         this.GetFill(svg).FillRule = (Fill.eFillRule)Enum.Parse(typeof(Fill.eFillRule), value);
         return;
     }
     if (name == SVGTags.sStyle)
     {
         foreach (ShapeUtil.Attribute item in XmlUtil.SplitStyle(svg, value)) this.Parse(svg, item);
     }
     //********************** text *******************
     if (name == SVGTags.sFontFamily)
     {
         this.GetTextStyle(svg).FontFamily = value;
         return;
     }
     if (name == SVGTags.sFontSize)
     {
         this.GetTextStyle(svg).FontSize = XmlUtil.AttrValue(new ShapeUtil.Attribute(name, value));
         return;
     }
     if (name == SVGTags.sFontWeight)
     {
         this.GetTextStyle(svg).Fontweight = (FontWeight)new FontWeightConverter().ConvertFromString(value);
         return;
     }
     if (name == SVGTags.sFontStyle)
     {
         this.GetTextStyle(svg).Fontstyle = (FontStyle)new FontStyleConverter().ConvertFromString(value);
         return;
     }
     if (name == SVGTags.sTextDecoration)
     {
         TextDecoration t = new TextDecoration();
         if (value == "none") return;
         if (value == "underline") t.Location = TextDecorationLocation.Underline;
         if (value == "overline") t.Location = TextDecorationLocation.OverLine;
         if (value == "line-through") t.Location = TextDecorationLocation.Strikethrough;
         TextDecorationCollection tt = new TextDecorationCollection();
         tt.Add(t);
         this.GetTextStyle(svg).TextDecoration = tt;
         return;
     }
     if (name == SVGTags.sTextAnchor)
     {
         if (value == "start") this.GetTextStyle(svg).TextAlignment = TextAlignment.Left;
         if (value == "middle") this.GetTextStyle(svg).TextAlignment = TextAlignment.Center;
         if (value == "end") this.GetTextStyle(svg).TextAlignment = TextAlignment.Right;
         return;
     }
     if (name == "word-spacing")
     {
         this.GetTextStyle(svg).WordSpacing = XmlUtil.AttrValue(new ShapeUtil.Attribute(name, value));
         return;
     }
     if (name == "letter-spacing")
     {
         this.GetTextStyle(svg).LetterSpacing = XmlUtil.AttrValue(new ShapeUtil.Attribute(name, value));
         return;
     }
     if (name == "baseline-shift")
     {
         //GetTextStyle(svg).BaseLineShift = XmlUtil.AttrValue(new ShapeUtil.Attribute(name, value));
         this.GetTextStyle(svg).BaseLineShift = value;
         return;
     }
 }
Ejemplo n.º 26
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);
            };
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Constructor.
        /// </summary>
        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));
            };
        }
Ejemplo n.º 28
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);
            }
        }
Ejemplo n.º 29
0
 public void tdUnder(object sender, RoutedEventArgs e)
 {
     TextDecorationCollection myCollection = new TextDecorationCollection();
     TextDecoration myUnderline = new TextDecoration();
     myUnderline.Location = TextDecorationLocation.Underline;
     myUnderline.Pen = new Pen(Brushes.Red, 1);
     myUnderline.PenThicknessUnit = TextDecorationUnit.FontRecommended;
     myCollection.Add(myUnderline);
     tb1.TextDecorations = myCollection;
 }
        /// <summary>
        /// ConvertFromString
        /// </summary>
        /// <param name="text"> The string to be converted into TextDecorationCollection object </param> 
        /// <returns> the converted value of the string flag </returns>
        /// <remarks> 
        /// The text parameter can be either string "None" or a combination of the predefined 
        /// TextDecoration names delimited by commas (,). One or more blanks spaces can precede
        /// or follow each text decoration name or comma. There can't be duplicate TextDecoration names in the 
        /// string. The operation is case-insensitive.
        /// </remarks>
        public static new TextDecorationCollection ConvertFromString(string text)
        { 
            if (text == null)
            { 
               return null; 
            }
 
            TextDecorationCollection textDecorations = new TextDecorationCollection();

            // Flags indicating which Predefined textDecoration has alrady been added.
            byte MatchedTextDecorationFlags = 0; 

            // Start from the 1st non-whitespace character 
            // Negative index means error is encountered 
            int index = AdvanceToNextNonWhiteSpace(text, 0);
            while (index >= 0 && index < text.Length) 
            {
                if (Match(None, text, index))
                {
                    // Matched "None" in the input 
                    index = AdvanceToNextNonWhiteSpace(text, index + None.Length);
                    if (textDecorations.Count > 0 || index < text.Length) 
                    { 
                        // Error: "None" can only be specified by its own
                        index = -1; 
                    }
                }
                else
                { 
                    // Match the input with one of the predefined text decoration names
                    int i; 
                    for(i = 0; 
                           i < TextDecorationNames.Length
                        && !Match(TextDecorationNames[i], text, index); 
                       i++
                    );

                    if (i < TextDecorationNames.Length) 
                    {
                        // Found a match within the predefined names 
                        if ((MatchedTextDecorationFlags & (1 << i)) > 0) 
                        {
                            // Error: The matched value is duplicated. 
                            index = -1;
                        }
                        else
                        { 
                            // Valid match. Add to the collection and remember that this text decoration
                            // has been added 
                            textDecorations.Add(PredefinedTextDecorations[i]); 
                            MatchedTextDecorationFlags |= (byte)(1 << i);
 
                            // Advance to the start of next name
                            index = AdvanceToNextNameStart(text, index + TextDecorationNames[i].Length);
                        }
                    } 
                    else
                    { 
                        // Error: no match found in the predefined names 
                        index = -1;
                    } 
                }
            }

            if (index < 0) 
            {
                throw new ArgumentException(SR.Get(SRID.InvalidTextDecorationCollectionString, text)); 
            } 

            return textDecorations; 
        }
Ejemplo n.º 31
0
 private void UpdateSelectedDecorations()
 {
     TextDecorationCollection newDecorations = new TextDecorationCollection();
     if (IsUnderline)
     {
         newDecorations.Add(System.Windows.TextDecorations.Underline[0]);
     }
     if (IsStrikethrough)
     {
         newDecorations.Add(System.Windows.TextDecorations.Strikethrough[0]);
     }
     if (IsBaseline)
     {
         newDecorations.Add(System.Windows.TextDecorations.Baseline[0]);
     }
     if (IsOverLine)
     {
         newDecorations.Add(System.Windows.TextDecorations.OverLine[0]);
     }
     newDecorations.Freeze();
     SelectedDecorations = newDecorations;
 }
Ejemplo n.º 32
0
 public void tdStrike(object sender, RoutedEventArgs e)
 {
     TextDecorationCollection myCollection = new TextDecorationCollection();
     TextDecoration myStrikethrough = new TextDecoration();
     myStrikethrough.Location = TextDecorationLocation.Strikethrough;
     myStrikethrough.Pen = new Pen(Brushes.Red, 1);
     myStrikethrough.PenThicknessUnit = TextDecorationUnit.FontRecommended;
     myCollection.Add(myStrikethrough);
     tb1.TextDecorations = myCollection;
 }
Ejemplo n.º 33
0
        void TextBox_Loaded(object sender, RoutedEventArgs e)
        {
            _subtleBrush = (Brush)FindResource("subtle1");
            _normalBrush = (Brush)FindResource("normalText1");

            _savedDecorations = new TextDecorationCollection();
            foreach (var decoration in TextBox1.TextDecorations)
                _savedDecorations.Add(decoration);

            CheckIfEmpty();
        }