예제 #1
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;
        }
예제 #2
0
        private static double CheckTextBox(TextBox textBox)  // Функция проверит значение, если вернется не 0, то все условия выполнены
        {
            double checkedString = 0;

            try
            {
                checkedString = Convert.ToDouble(textBox.Text);
                if (textBox.TextDecorations != null) textBox.TextDecorations.Clear();
            }
            catch (FormatException)
            {
                var myUnderline = new TextDecoration();

                // Create a linear gradient pen for the text decoration.
                var myPen = new Pen();
                myPen.Brush = new LinearGradientBrush(Colors.Red, Colors.Red, new Point(0, 0.5), new Point(1, 0.5));
                myPen.Brush.Opacity = 0.5;
                myPen.Thickness = 1.5;
                myPen.DashStyle = DashStyles.DashDot;
                myUnderline.Pen = myPen;
                myUnderline.PenThicknessUnit = TextDecorationUnit.FontRecommended;

                // Set the underline decoration to a TextDecorationCollection and add it to the text block.
                var myDecorationCollection = new TextDecorationCollection {myUnderline};
                textBox.TextDecorations = myDecorationCollection;
            }

            return checkedString;
        }
예제 #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 PopupContextMenu()
        {
            Title = "Popup Context Menu";

            //ContextMenu 생성
            menu = new ContextMenu();

            //"Bold" 항목 추가
            itemBold = new MenuItem();
            itemBold.Header = "Bold";
            menu.Items.Add(itemBold);

            //"Italic" 항목 추가
            itemItalic = new MenuItem();
            itemItalic.Header = "Italic";
            menu.Items.Add(itemItalic);

            //모든 TextDecorationLocation 멤버를 구함
            TextDecorationLocation[] locs=(TextDecorationLocation[])Enum.GetValues(typeof (TextDecorationLocation));

            //MenuItem 객체 배열을 생성를 구함
            itemDecor=new MenuItem[locs.Length];

            for (int i = 0; i < locs.Length; i++)
            {
                TextDecoration decor = new TextDecoration();
                decor.Location = locs[i];

                itemDecor[i] = new MenuItem();
                itemDecor[i].Header = locs[i].ToString();
                itemDecor[i].Tag = decor;
                menu.Items.Add(itemDecor[i]);
            }

            //전체 컨텍스트 메뉴를 핸들러 한 개로 처리
            menu.AddHandler(MenuItem.ClickEvent, new RoutedEventHandler(MenuOnClick));

            //윈도우 Content 를 위한 TextBlock을 생성
            TextBlock text = new TextBlock();
            text.FontSize = 32;
            text.HorizontalAlignment = HorizontalAlignment.Center;
            text.VerticalAlignment = VerticalAlignment.Center;
            Content = text;

            //문장을 단어로 분리
            string strQuote = "To be,or not to be,that is the question";
            string[] strWords = strQuote.Split();

            //각 단어로 Run 객체를 만들어서 TextBlock에 추가
            foreach (string str in strWords)
            {
                Run run = new Run(str);

                //TextDecorations이 실제로 컬렉션인지를 확인
                run.TextDecorations = new TextDecorationCollection();
                text.Inlines.Add(run);
                text.Inlines.Add(" ");
            }
        }
예제 #5
0
 public override bool Equals(object o)
 {
     if (o is TextDecoration)
     {
         TextDecoration td = (TextDecoration)o;
         return(this.Decoration == td.Decoration);
     }
     return(false);
 }
예제 #6
0
 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;
 }
        /// <summary>
        /// Compare the values of thhe properties in the two TextDecoration objects
        /// </summary>
        /// <param name="textDecoration">The TextDecoration object to be compared against</param>
        /// <returns>True if their property values are equal. False otherwise</returns>
        /// <remarks>
        /// The method doesn't check "full" equality as it can not take into account of all the possible 
        /// values associated with the DependencyObject,such as Animation, DataBinding and Attached property. 
        /// It only compares the public properties to serve the specific Framework's needs in inline property 
        /// management and Editing serialization. 
        /// </remarks>        
        internal bool ValueEquals(TextDecoration textDecoration)
        {
            if (textDecoration == null)
                return false; // o is either null or not a TextDecoration object.

            if (this == textDecoration) 
                return true; // reference equality.
               
            return (    
               Location         == textDecoration.Location 
            && PenOffset        == textDecoration.PenOffset 
            && PenOffsetUnit    == textDecoration.PenOffsetUnit 
            && PenThicknessUnit == textDecoration.PenThicknessUnit
            && (Pen == null ? textDecoration.Pen == null : Pen.Equals( textDecoration.Pen)) 
            );
        }
예제 #8
0
 /// <summary>
 /// Compare the values of thhe properties in the two TextDecoration objects
 /// </summary>
 /// <param name="textDecoration">The TextDecoration object to be compared against</param>
 /// <returns>True if their property values are equal. False otherwise</returns>
 /// <remarks>
 /// The method doesn't check "full" equality as it can not take into account of all the possible
 /// values associated with the DependencyObject,such as Animation, DataBinding and Attached property.
 /// It only compares the public properties to serve the specific Framework's needs in inline property
 /// management and Editing serialization.
 /// </remarks>
 internal bool ValueEquals(TextDecoration textDecoration)
 {
     if (textDecoration == null)
     {
         return(false); // o is either null or not a TextDecoration object.
     }
     if (this == textDecoration)
     {
         return(true); // reference equality.
     }
     return(
         Location == textDecoration.Location &&
         PenOffset == textDecoration.PenOffset &&
         PenOffsetUnit == textDecoration.PenOffsetUnit &&
         PenThicknessUnit == textDecoration.PenThicknessUnit &&
         (Pen == null ? textDecoration.Pen == null : Pen.Equals(textDecoration.Pen))
         );
 }
        public PascalSyntaxHighlighterFormat()
        {
            var firstCharacterUnderline = new TextDecoration();

            var underlinePen = new Pen
                            {
                                Brush =
                                    new LinearGradientBrush(
                                    Colors.Black, Colors.White, new Point(0.75, 0.5), new Point(1, 0.5)) { Opacity = 0.5 },
                                Thickness = 1.75,
                                DashStyle = DashStyles.Solid
                            };

            firstCharacterUnderline.Pen = underlinePen;
            firstCharacterUnderline.PenThicknessUnit = TextDecorationUnit.FontRecommended;

            var textDecorations = new TextDecorationCollection { firstCharacterUnderline };
            this.TextDecorations = textDecorations;

            this.DisplayName = "Pascal Syntax Highlighter";
            this.IsBold = true;
        }
		void CreateStrikeout (TextBlock textBlock,ExportColumn exportColumn )
		{
			var strikeOut = new TextDecoration();
			strikeOut.Location = TextDecorationLocation.Strikethrough;

			Pen p = CreateWpfPen(exportColumn);
			strikeOut.Pen = p ;
			strikeOut.PenThicknessUnit = TextDecorationUnit.FontRecommended;
			textBlock.TextDecorations.Add(strikeOut);
		}
예제 #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;
        }
예제 #12
0
 public static bool operator !=(TextDecorationCollection left, TextDecorationCollection right)
 {
     return(!TextDecoration.Equals(left.Decoration, right.Decoration));
 }
		void CreateStrikeout (TextBlock textBlock, TextStyleDecorator styleDecorator)
		{
			TextDecoration strikeOut = new TextDecoration();
			strikeOut.Location = TextDecorationLocation.Strikethrough;

			Pen p = CreateWpfPen(styleDecorator);
			strikeOut.Pen = p ;
			strikeOut.PenThicknessUnit = TextDecorationUnit.FontRecommended;
			textBlock.TextDecorations.Add(strikeOut);
		}
예제 #14
0
파일: LabelBackend.cs 프로젝트: m13253/xwt
		void GenerateBlocks (SWD.InlineCollection col, string text, ref int i, int spanEnd, List<Drawing.TextAttribute> attributes, ref int attrIndex)
		{
			while (attrIndex < attributes.Count) {
				var at = attributes[attrIndex];
				if (at.StartIndex > spanEnd) {
					FlushText (col, text, ref i, spanEnd);
					return;
				}

				FlushText (col, text, ref i, at.StartIndex);

				var s = new SWD.Span ();

				if (at is Drawing.BackgroundTextAttribute) {
					s.Background = new SWM.SolidColorBrush (((Drawing.BackgroundTextAttribute)at).Color.ToWpfColor ());
				}
				else if (at is Drawing.FontWeightTextAttribute) {
					s.FontWeight = ((Drawing.FontWeightTextAttribute)at).Weight.ToWpfFontWeight ();
				}
				else if (at is Drawing.FontStyleTextAttribute) {
					s.FontStyle = ((Drawing.FontStyleTextAttribute)at).Style.ToWpfFontStyle ();
				}
				else if (at is Drawing.UnderlineTextAttribute) {
					var xa = (Drawing.UnderlineTextAttribute)at;
					var dec = new TextDecoration (TextDecorationLocation.Underline, null, 0, TextDecorationUnit.FontRecommended, TextDecorationUnit.FontRecommended);
					s.TextDecorations.Add (dec);
				}
				else if (at is Drawing.StrikethroughTextAttribute) {
					var xa = (Drawing.UnderlineTextAttribute)at;
					var dec = new TextDecoration (TextDecorationLocation.Strikethrough, null, 0, TextDecorationUnit.FontRecommended, TextDecorationUnit.FontRecommended);
					s.TextDecorations.Add (dec);
				}
				else if (at is Drawing.FontTextAttribute) {
					var xa = (Drawing.FontTextAttribute)at;
					s.FontFamily = new SWM.FontFamily (xa.Font.Family);
					s.FontSize = WpfFontBackendHandler.GetPointsFromDeviceUnits (xa.Font.Size);
					s.FontStretch = xa.Font.Stretch.ToWpfFontStretch ();
					s.FontStyle = xa.Font.Style.ToWpfFontStyle ();
					s.FontWeight = xa.Font.Weight.ToWpfFontWeight ();
				}
				else if (at is Drawing.ColorTextAttribute) {
					s.Foreground = new SWM.SolidColorBrush (((Drawing.ColorTextAttribute)at).Color.ToWpfColor ());
				}
				else if (at is Drawing.LinkTextAttribute) {
					var link = new SWD.Hyperlink () {
						NavigateUri = ((Drawing.LinkTextAttribute)at).Target
					};
					link.RequestNavigate += new System.Windows.Navigation.RequestNavigateEventHandler (link_RequestNavigate);
					s = link;
				}

				col.Add (s);

				var max = i + at.Count;
				if (max > spanEnd)
					max = spanEnd;

				attrIndex++;
				GenerateBlocks (s.Inlines, text, ref i, i + at.Count, attributes, ref attrIndex);
			}
			FlushText (col, text, ref i, spanEnd);
		}
예제 #15
0
		static void CreateStrikeout (TextBlock textBlock,IExportText exportColumn ){
			if (textBlock == null)
				throw new ArgumentNullException("textBlock");
			if (exportColumn == null)
				throw new ArgumentNullException("exportColumn");
			var strikeOut = new TextDecoration();
			strikeOut.Location = TextDecorationLocation.Strikethrough;

			Pen p = CreateWpfPen(exportColumn);
			strikeOut.Pen = p ;
			strikeOut.PenThicknessUnit = TextDecorationUnit.FontRecommended;
			textBlock.TextDecorations.Add(strikeOut);
		}
예제 #16
0
파일: Shape.cs 프로젝트: swcomp/SVGImage
 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;
     }
 }
        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;
        }
        private Rect DrawTextDecoration(
            LSRun           lsrun,           // lsrun
            Brush           foregroundBrush, // default brush if text decoration has no pen
            LSPOINT         ptOrigin,        // drawing origin
            int             ulLength,        // underline length
            int             ulThickness,     // underline thickness
            LsTFlow         textFlow,        // text flow direction
            TextDecoration  textDecoration   //TextDecoration to be draw (add to sublinecollection
            )
        {
            switch (textFlow)
            {
                case LsTFlow.lstflowWS:
                case LsTFlow.lstflowNE:
                case LsTFlow.lstflowNW:

                    ptOrigin.x -= ulLength;
                    break;
            }

            TextMetrics.FullTextLine currentLine = Draw.CurrentLine;

            if (currentLine.RightToLeft)
            {
                ptOrigin.x = -ptOrigin.x;
            }

            int u = currentLine.LSLineUToParagraphU(ptOrigin.x);

            Point baselineOrigin = LSRun.UVToXY(
                Draw.LineOrigin,
                Draw.VectorToLineOrigin,
                u,
                currentLine.BaselineOffset,
                currentLine
                );

            Point lineOrigin = LSRun.UVToXY(
                Draw.LineOrigin,
                Draw.VectorToLineOrigin,
                u,
                ptOrigin.y + lsrun.BaselineMoveOffset,
                currentLine
                );



            double penThickness = 1.0;
            if (textDecoration.Pen != null)
            {
                penThickness = textDecoration.Pen.Thickness;
            }


            switch (textDecoration.PenThicknessUnit)
            {
                case TextDecorationUnit.FontRecommended:

                    penThickness = currentLine.Formatter.IdealToReal(ulThickness * penThickness);
                    break;

                case TextDecorationUnit.FontRenderingEmSize:
                    penThickness = currentLine.Formatter.IdealToReal(penThickness * lsrun.EmSize);
                    break;

                case TextDecorationUnit.Pixel:

                    break;

                default:
                    Debug.Assert(false, "Not supported TextDecorationUnit");
                    break;
            }


            penThickness = Math.Abs(penThickness);            




            double unitValue = 1.0;
            switch (textDecoration.PenOffsetUnit)
            {
                case TextDecorationUnit.FontRecommended:

                    unitValue = (lineOrigin.Y - baselineOrigin.Y);
                    break;

                case TextDecorationUnit.FontRenderingEmSize:
                    unitValue = currentLine.Formatter.IdealToReal(lsrun.EmSize);
                    break;

                case TextDecorationUnit.Pixel:
                    unitValue = 1.0;
                    break;

                default:
                    Debug.Assert(false, "Not supported TextDecorationUnit");
                    break;
            }


            double lineLength = currentLine.Formatter.IdealToReal(ulLength);

            DrawingContext drawingContext = Draw.DrawingContext;

            if (drawingContext != null)
            {      
                
                


                double drawingPenThickness = penThickness;



                Point  drawingLineOrigin   = lineOrigin;

                bool animated = !textDecoration.CanFreeze && (unitValue != 0);

                int pushCount = 0; // counter for the number of explicit DrawingContext.Push()
                

                Draw.SetGuidelineY(baselineOrigin.Y);                
                
                try 
                {
                    if (animated)
                    {                    









                        ScaleTransform scaleTransform = new ScaleTransform(
                            1.0,        // X scale
                            unitValue,  // y scale 
                            drawingLineOrigin.X,  // reference point of scaling
                            drawingLineOrigin.Y  // reference point of scaling
                            );
                           
                        TranslateTransform yTranslate = new TranslateTransform(
                            0,                       // x translate
                            textDecoration.PenOffset // y translate
                            );


                        drawingPenThickness = drawingPenThickness / Math.Abs(unitValue);
                                                    

                        drawingContext.PushTransform(scaleTransform);
                        pushCount++;
                        drawingContext.PushTransform(yTranslate);
                        pushCount++;

                    }
                    else
                    {

                        drawingLineOrigin.Y += unitValue * textDecoration.PenOffset;
                    }                    







                    drawingContext.PushGuidelineY2(baselineOrigin.Y, drawingLineOrigin.Y - drawingPenThickness * 0.5 - baselineOrigin.Y);
                    pushCount++;









                    if (textDecoration.Pen == null)
                    {

                        drawingContext.DrawRectangle(
                            foregroundBrush,               // fill using foreground
                            null,                          // null pen for rectangle stroke
                            new Rect(
                                drawingLineOrigin.X,
                                drawingLineOrigin.Y - drawingPenThickness * 0.5,
                                lineLength,
                                drawingPenThickness
                                )                    
                            );                    
                    }
                    else                    
                    {





                        Pen textDecorationPen = textDecoration.Pen.CloneCurrentValue();
                        if (Object.ReferenceEquals(textDecoration.Pen, textDecorationPen))
                        {

                            textDecorationPen = textDecoration.Pen.Clone();
                        }
                        
                        textDecorationPen.Thickness = drawingPenThickness;                  
                        

                        drawingContext.DrawLine(
                            textDecorationPen,
                            drawingLineOrigin,
                            new Point(drawingLineOrigin.X + lineLength, drawingLineOrigin.Y)
                            );
                    }
                }
                finally 
                {               
                    for (int i = 0; i < pushCount; i++)
                    {
                        drawingContext.Pop(); 
                    }

                    Draw.UnsetGuidelineY();
                }
            }
            
            return new Rect(
                lineOrigin.X,
                lineOrigin.Y + unitValue * textDecoration.PenOffset - penThickness * 0.5,
                lineLength,
                penThickness
                );
        }
예제 #19
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;
        }
예제 #20
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);
        }
		void CreateUnderline(TextBlock textBlock,ExportColumn exportColumn)
		{
			var underLine = new TextDecoration();
			Pen p = CreateWpfPen(exportColumn);
			underLine.Pen = p ;
			underLine.PenThicknessUnit = TextDecorationUnit.FontRecommended;
			textBlock.TextDecorations.Add(underLine);
		}
예제 #22
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);
            };
        }
예제 #23
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CobraIndentErrorFormat"/> class,
        /// which defines the visual format for the <c>CobraIndentError</c> classification type.
        /// </summary>
        public CobraIndentErrorFormat()
        {
            DisplayName = "CobraIndentErrorFormat";

            var cobraIndentErrorColor = Colors.Orange;
            const double cobraIndentErrorPenWidth = 1.0;

            var cobraIndentErrorUnderline = new TextDecoration();
            var orangePen = new Pen(new SolidColorBrush(cobraIndentErrorColor), cobraIndentErrorPenWidth) { DashStyle = DashStyles.Dot };

            cobraIndentErrorUnderline.Pen = orangePen;
            cobraIndentErrorUnderline.PenThicknessUnit = TextDecorationUnit.FontRecommended;

            var myCollection = new TextDecorationCollection { cobraIndentErrorUnderline };

            TextDecorations = myCollection;
        }
예제 #24
0
파일: About.cs 프로젝트: emrul/CmisSync
        /// <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));
            };
        }
예제 #25
0
        //redraw textblock
        private static void updateTextBlock(DecoratedTextBlock textblock)
        {
            var defaultIsSelectedForeground = textblock.IsSelectedForeground ?? textblock.Foreground;
            var defaultIsSelectedBackground = textblock.IsSelectedBackground ?? textblock.Background;

            //reset the textblock
            textblock.Inlines.Clear();

            //if we have no datacontext dont even bother trying to update the textblock
            if (textblock.DataContext == null)
                return;

            //don't decorate if selection is not set
            if (!textblock.ShowDecorations)
            {
                textblock.Text = textblock.BoundText;
                return;
            }

            //setup decorations for pulling by index
            Dictionary<int, List<TextDecoration>> decorations = new Dictionary<int, List<TextDecoration>>();
            foreach (var dec in textblock.TextBlockDecorations)
            {
                //iterate over each text inside the decoration and add to dictionary according to the index the text was found in (for quick lookup)
                if (dec.DecoratedText != null)
                {
                    foreach (var text in dec.DecoratedText)
                    {
                        if (!decorations.ContainsKey(text.Start))
                        {
                            decorations.Add(text.Start, new List<TextDecoration>());
                        }
                        //create a decrated text for this text
                        DecorationType flag = (dec.BackgroundColor.HasValue ? DecorationType.Background : DecorationType.None)
                            | (dec.ForegroundColor.HasValue ? DecorationType.Foreground : DecorationType.None)
                            | (dec.FontStyle.HasValue ? DecorationType.Style : DecorationType.None)
                            | (dec.FontWeight.HasValue ? DecorationType.Weight : DecorationType.None);
                        TextDecoration textdec = new TextDecoration()
                        {
                            Index = text.Start,
                            Text = text.Item,
                            Background = dec.BackgroundColor,
                            FontStyle = dec.FontStyle,
                            Foreground = dec.ForegroundColor,
                            FontWeight = dec.FontWeight,
                            DecorationFlags = flag,
                        };
                        decorations[text.Start].Add(textdec);
                    }
                }
            }

            StringBuilder builder = new StringBuilder();
            Dictionary<DecorationType, TextDecoration> decorationMap = new Dictionary<DecorationType, TextDecoration>();
            decorationMap.Add(DecorationType.Background, null);
            decorationMap.Add(DecorationType.Foreground, null);
            decorationMap.Add(DecorationType.Style, null);
            decorationMap.Add(DecorationType.Weight, null);
            System.Windows.Media.Color? currentBackground = null;
            System.Windows.Media.Color? currentForeground = null;
            FontStyle? currentStyle = null;
            FontWeight? currentWeight = null;
            bool backgroundChanged = false;
            bool foregroundChanged = false;
            bool styleChanged = false;
            bool weightChanged = false;
            //iterate through string and detect when a decration is added/removed to create runs for each decoration change
            List<TextDecoration> decorationMem = new List<TextDecoration>();
            for (int i = 0; i < textblock.BoundText.Length; i++)
            {
                //check if we need to remove the current decoration for each decoration type
                if(decorationMap[DecorationType.Background] != null
                    && decorationMap[DecorationType.Background].Background != null
                    && decorationMap[DecorationType.Background].Index + decorationMap[DecorationType.Background].Text.Length <= i)
                {
                    backgroundChanged = true;
                }
                if (decorationMap[DecorationType.Foreground] != null
                    && decorationMap[DecorationType.Foreground].Foreground != null
                    && decorationMap[DecorationType.Foreground].Index + decorationMap[DecorationType.Foreground].Text.Length <= i)
                {
                    foregroundChanged = true;
                }
                if (decorationMap[DecorationType.Style] != null
                    && decorationMap[DecorationType.Style].FontStyle != null
                    && decorationMap[DecorationType.Style].Index + decorationMap[DecorationType.Style].Text.Length <= i)
                {
                    styleChanged = true;
                }
                if (decorationMap[DecorationType.Weight] != null
                    && decorationMap[DecorationType.Weight].FontWeight != null
                    && decorationMap[DecorationType.Weight].Index + decorationMap[DecorationType.Weight].Text.Length <= i)
                {
                    weightChanged = true;
                }

                //check for new decorations
                if (decorations.ContainsKey(i))
                {
                    //go through the dictionary at the current index
                    foreach (var dec in decorations[i])
                    {
                        //if the decoration has a change and there is nothing currently tracked, flag as changed and add to the decoration memory
                        if (dec.Background != null && decorationMap[DecorationType.Background] == null)
                        {
                            backgroundChanged = true;
                        }
                        if (dec.Foreground != null && decorationMap[DecorationType.Foreground] == null)
                        {
                            foregroundChanged = true;
                        }
                        if (dec.FontStyle != null && decorationMap[DecorationType.Style] == null)
                        {
                            styleChanged = true;
                        }
                        if (dec.FontWeight != null && decorationMap[DecorationType.Weight] == null)
                        {
                            weightChanged = true;
                        }
                        decorationMem.Add(dec);
                    }
                }

                //get the previous background and reset the kept decoration that was changed
                if(backgroundChanged || foregroundChanged || styleChanged || weightChanged)
                {
                    currentBackground = decorationMap[DecorationType.Background] != null ? decorationMap[DecorationType.Background].Background : null;
                    currentForeground = decorationMap[DecorationType.Foreground] != null ? decorationMap[DecorationType.Foreground].Foreground : null;
                    currentStyle = decorationMap[DecorationType.Style] != null ? decorationMap[DecorationType.Style].FontStyle : null;
                    currentWeight = decorationMap[DecorationType.Weight] != null ? decorationMap[DecorationType.Weight].FontWeight : null;

                    //reset the changed values to null for updating
                    if(backgroundChanged)
                    {
                        decorationMap[DecorationType.Background] = null;
                    }
                    if(foregroundChanged)
                    {
                        decorationMap[DecorationType.Foreground] = null;
                    }
                    if(styleChanged)
                    {
                        decorationMap[DecorationType.Style] = null;
                    }
                    if(weightChanged)
                    {
                        decorationMap[DecorationType.Weight] = null;
                    }
                }

                //check if we need to remove decorations in memory and update current decoration if need be
                if (decorationMem.Count > 0)
                {
                    List<TextDecoration> remaining = new List<TextDecoration>();
                    //go through each of the queued decorations
                    foreach (var dec in decorationMem)
                    {
                        //check if our position is past the word in the decoration
                        if (dec.Index + dec.Text.Length > i)
                        {
                            //check if all styling for the decoration is open, if not then skip the decoration (aka make sure all decorations for a textblockdecoration is done rather than partial)
                            DecorationType openDecorations = (decorationMap[DecorationType.Background] == null ? DecorationType.Background : DecorationType.None)
                                | (decorationMap[DecorationType.Foreground] == null ? DecorationType.Foreground : DecorationType.None)
                                | (decorationMap[DecorationType.Style] == null ? DecorationType.Style : DecorationType.None)
                                | (decorationMap[DecorationType.Weight] == null ? DecorationType.Weight : DecorationType.None);

                            if (openDecorations.HasFlag(dec.DecorationFlags))
                            {
                                //check which styles is open so we can add new style if the decoration is open
                                if (decorationMap[DecorationType.Background] == null && dec.Background.HasValue)
                                {
                                    decorationMap[DecorationType.Background] = dec;
                                }
                                if (decorationMap[DecorationType.Foreground] == null && dec.Foreground.HasValue)
                                {
                                    decorationMap[DecorationType.Foreground] = dec;
                                }
                                if (decorationMap[DecorationType.Style] == null && dec.FontStyle.HasValue)
                                {
                                    decorationMap[DecorationType.Style] = dec;
                                }
                                if (decorationMap[DecorationType.Weight] == null && dec.FontWeight.HasValue)
                                {
                                    decorationMap[DecorationType.Weight] = dec;
                                }
                            }
                            //add back to mem since we're still tracking this decoration
                            remaining.Add(dec);
                        }
                    }

                    //set the mem to whatever the remaining strings are
                    decorationMem = remaining;
                }

                //if anything has changed add previous builder and create a new run
                if (backgroundChanged || foregroundChanged || styleChanged || weightChanged)
                {
                    if (builder != null && builder.Length > 0)
                    {
                        System.Windows.Documents.Run run = new System.Windows.Documents.Run(builder.ToString());
                        //set the current run values
                        run.Background = currentBackground.HasValue ? new SolidColorBrush(currentBackground.Value) : defaultIsSelectedBackground;
                        run.Foreground = currentForeground.HasValue ? new SolidColorBrush(currentForeground.Value) : defaultIsSelectedForeground;
                        run.FontStyle = currentStyle.HasValue ? currentStyle.Value : textblock.FontStyle;
                        run.FontWeight = currentWeight.HasValue ? currentWeight.Value : textblock.FontWeight;

                        //reset the  values
                        currentBackground = null;
                        currentForeground = null;
                        currentStyle = null;
                        currentWeight = null;

                        textblock.Inlines.Add(run); //add the new run decoration
                        builder = new StringBuilder(); //reset the builder for the next run
                    }

                    //reset the changed flags
                    backgroundChanged = false;
                    foregroundChanged = false;
                    styleChanged = false;
                    weightChanged = false;

                }

                builder.Append(textblock.BoundText[i]);
            }

            //add the final run
            System.Windows.Documents.Run finalRun = new System.Windows.Documents.Run(builder.ToString());
            finalRun.Background = decorationMap[DecorationType.Background] != null && decorationMap[DecorationType.Background].Background.HasValue ? new SolidColorBrush(decorationMap[DecorationType.Background].Background.Value) : defaultIsSelectedBackground;
            finalRun.Foreground = decorationMap[DecorationType.Foreground] != null && decorationMap[DecorationType.Foreground].Foreground.HasValue ? new SolidColorBrush(decorationMap[DecorationType.Foreground].Foreground.Value) : defaultIsSelectedForeground;
            finalRun.FontStyle = decorationMap[DecorationType.Style] != null && decorationMap[DecorationType.Style].FontStyle.HasValue ? decorationMap[DecorationType.Style].FontStyle.Value : textblock.FontStyle;
            finalRun.FontWeight = decorationMap[DecorationType.Weight] != null && decorationMap[DecorationType.Weight].FontWeight.HasValue ? decorationMap[DecorationType.Weight].FontWeight.Value : textblock.FontWeight;

            textblock.Inlines.Add(finalRun); //add the new run decoration
        }
		void CreateUnderline(TextBlock textBlock,TextStyleDecorator styleDecorator)
		{
			TextDecoration underLine = new TextDecoration();
			Pen p = CreateWpfPen(styleDecorator);
			underLine.Pen = p ;
			underLine.PenThicknessUnit = TextDecorationUnit.FontRecommended;
			textBlock.TextDecorations.Add(underLine);
		}
예제 #27
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;
 }
예제 #28
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;
 }
예제 #29
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);
 }