当前位置: 首页>>代码示例>>C#>>正文


C# FormattedText.SetTextDecorations方法代码示例

本文整理汇总了C#中System.Windows.Media.FormattedText.SetTextDecorations方法的典型用法代码示例。如果您正苦于以下问题:C# FormattedText.SetTextDecorations方法的具体用法?C# FormattedText.SetTextDecorations怎么用?C# FormattedText.SetTextDecorations使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Media.FormattedText的用法示例。


在下文中一共展示了FormattedText.SetTextDecorations方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetFormattedText

        public static FormattedText GetFormattedText(this FlowDocument doc)
        {
            if (doc == null)
            {
                throw new ArgumentNullException("doc");
            }

            FormattedText output = new FormattedText(
              GetText(doc),
              CultureInfo.CurrentCulture,
              doc.FlowDirection,
              new Typeface(doc.FontFamily, doc.FontStyle, doc.FontWeight, doc.FontStretch),
              doc.FontSize,
              doc.Foreground);

            int offset = 0;

            foreach (TextElement el in GetRunsAndParagraphs(doc))
            {
                Run run = el as Run;

                if (run != null)
                {
                    int count = run.Text.Length;

                    output.SetFontFamily(run.FontFamily, offset, count);
                    output.SetFontStyle(run.FontStyle, offset, count);
                    output.SetFontWeight(run.FontWeight, offset, count);
                    output.SetFontSize(run.FontSize, offset, count);
                    output.SetForegroundBrush(run.Foreground, offset, count);
                    output.SetFontStretch(run.FontStretch, offset, count);
                    output.SetTextDecorations(run.TextDecorations, offset, count);

                    offset += count;
                }
                else
                {
                    offset += Environment.NewLine.Length;
                }
            }

            return output;
        }
开发者ID:RagingBigFemaleBird,项目名称:sgs,代码行数:43,代码来源:FlowDocumentExtensions.cs

示例2: DrawTextRun

        private void DrawTextRun(SvgTextContentElement element, ref Point ctp,
            WpfTextRun textRun, double rotate, WpfTextPlacement placement)
        {
            if (textRun == null || textRun.IsEmpty)
                return;

            string text           = textRun.Text;
            double emSize         = GetComputedFontSize(element);
            FontFamily fontFamily = GetTextFontFamily(element, emSize);

            FontStyle fontStyle   = GetTextFontStyle(element);
            FontWeight fontWeight = GetTextFontWeight(element);

            FontStretch fontStretch = GetTextFontStretch(element);

            WpfTextStringFormat stringFormat = GetTextStringFormat(element);

            // Fix the use of Postscript fonts...
            WpfFontFamilyVisitor fontFamilyVisitor = _drawContext.FontFamilyVisitor;
            if (!String.IsNullOrEmpty(_actualFontName) && fontFamilyVisitor != null)
            {
                WpfFontFamilyInfo currentFamily = new WpfFontFamilyInfo(fontFamily, fontWeight,
                    fontStyle, fontStretch);
                WpfFontFamilyInfo familyInfo = fontFamilyVisitor.Visit(_actualFontName,
                    currentFamily, _drawContext);
                if (familyInfo != null && !familyInfo.IsEmpty)
                {
                    fontFamily  = familyInfo.Family;
                    fontWeight  = familyInfo.Weight;
                    fontStyle   = familyInfo.Style;
                    fontStretch = familyInfo.Stretch;
                }
            }

            WpfSvgPaint fillPaint = new WpfSvgPaint(_drawContext, element, "fill");
            Brush textBrush       = fillPaint.GetBrush();

            WpfSvgPaint strokePaint = new WpfSvgPaint(_drawContext, element, "stroke");
            Pen textPen = strokePaint.GetPen();

            if (textBrush == null && textPen == null)
            {
                return;
            }
            else if (textBrush == null)
            {
                // If here, then the pen is not null, and so the fill cannot be null.
                // We set this to transparent for stroke only text path...
                textBrush = Brushes.Transparent;
            }

            TextDecorationCollection textDecors = GetTextDecoration(element);
            TextAlignment alignment = stringFormat.Alignment;

            string letterSpacing = element.GetAttribute("letter-spacing");
            if (String.IsNullOrEmpty(letterSpacing))
            {
                FormattedText formattedText = new FormattedText(text,
                    textRun.IsLatin ? _drawContext.EnglishCultureInfo : _drawContext.CultureInfo,
                    stringFormat.Direction, new Typeface(fontFamily, fontStyle, fontWeight, fontStretch),
                    emSize, textBrush);

                formattedText.TextAlignment = stringFormat.Alignment;
                formattedText.Trimming      = stringFormat.Trimming;

                if (textDecors != null && textDecors.Count != 0)
                {
                    formattedText.SetTextDecorations(textDecors);
                }

                //float xCorrection = 0;
                //if (alignment == TextAlignment.Left)
                //    xCorrection = emSize * 1f / 6f;
                //else if (alignment == TextAlignment.Right)
                //    xCorrection = -emSize * 1f / 6f;

                double yCorrection = formattedText.Baseline;

                Point textPoint = new Point(ctp.X, ctp.Y - yCorrection);

                RotateTransform rotateAt = new RotateTransform(90, ctp.X, ctp.Y);
                _textContext.PushTransform(rotateAt);

                _textContext.DrawText(formattedText, textPoint);

                //float bboxWidth = (float)formattedText.Width;
                double bboxWidth = formattedText.WidthIncludingTrailingWhitespace;
                if (alignment == TextAlignment.Center)
                    bboxWidth /= 2f;
                else if (alignment == TextAlignment.Right)
                    bboxWidth = 0;

                //ctp.X += bboxWidth + emSize / 4;
                ctp.X += bboxWidth;

                if (rotateAt != null)
                {
                    _textContext.Pop();
                }
            }
//.........这里部分代码省略.........
开发者ID:udayanroy,项目名称:SvgSharp,代码行数:101,代码来源:WpfVertTextRenderer.cs

示例3: RenderTextRun


//.........这里部分代码省略.........

            bool isRotatePosOnly = false;

            IList<WpfTextPosition> textPositions = null;
            int textPosCount = 0;
            if ((placement != null && placement.HasPositions))
            {
                textPositions   = placement.Positions;
                textPosCount    = textPositions.Count;
                isRotatePosOnly = placement.IsRotateOnly;
            }

            if (hasLetterSpacing || hasWordSpacing || textPositions != null)
            {
                double spacing = Convert.ToDouble(letterSpacing);
                for (int i = 0; i < text.Length; i++)
                {
                    FormattedText formattedText = new FormattedText(new string(text[i], 1),
                        _drawContext.CultureInfo, stringFormat.Direction,
                        new Typeface(fontFamily, fontStyle, fontWeight, fontStretch),
                        emSize, textBrush);

                    if (this.IsMeasuring)
                    {
                        this.AddTextWidth(formattedText.WidthIncludingTrailingWhitespace);
                        continue;
                    }

                    formattedText.Trimming      = stringFormat.Trimming;
                    formattedText.TextAlignment = stringFormat.Alignment;

                    if (textDecors != null && textDecors.Count != 0)
                    {
                        formattedText.SetTextDecorations(textDecors);
                    }

                    WpfTextPosition? textPosition = null;
                    if (textPositions != null && i < textPosCount)
                    {
                        textPosition = textPositions[i];
                    }

                    //float xCorrection = 0;
                    //if (alignment == TextAlignment.Left)
                    //    xCorrection = emSize * 1f / 6f;
                    //else if (alignment == TextAlignment.Right)
                    //    xCorrection = -emSize * 1f / 6f;

                    double yCorrection = formattedText.Baseline;

                    float rotateAngle = (float)rotate;
                    if (textPosition != null)
                    {
                        if (!isRotatePosOnly)
                        {
                            Point pt = textPosition.Value.Location;
                            ctp.X = pt.X;
                            ctp.Y = pt.Y;
                        }
                        rotateAngle = (float)textPosition.Value.Rotation;
                    }
                    Point textStart = ctp;

                    RotateTransform rotateAt = null;
                    if (rotateAngle != 0)
                    {
开发者ID:udayanroy,项目名称:SvgSharp,代码行数:67,代码来源:WpfHorzTextRenderer.cs

示例4: Draw

        /// <inheritdoc/>
        public override void Draw(object dc, XText text, double dx, double dy, ImmutableArray<XProperty> db, XRecord r)
        {
            var _dc = dc as DrawingContext;

            var style = text.Style;
            if (style == null)
                return;

            var tbind = text.BindText(db, r);
            if (string.IsNullOrEmpty(tbind))
                return;

            double thickness = style.Thickness / _state.ZoomX;
            double half = thickness / 2.0;

            Tuple<Brush, Pen> styleCached = _styleCache.Get(style);
            Brush fill;
            Pen stroke;
            if (styleCached != null)
            {
                fill = styleCached.Item1;
                stroke = styleCached.Item2;
            }
            else
            {
                fill = CreateBrush(style.Fill);
                stroke = CreatePen(style, thickness);
                _styleCache.Set(style, Tuple.Create(fill, stroke));
            }

            var rect = CreateRect(text.TopLeft, text.BottomRight, dx, dy);

            Tuple<string, FormattedText, ShapeStyle> tcache = _textCache.Get(text);
            FormattedText ft;
            string ct;
            if (tcache != null && string.Compare(tcache.Item1, tbind) == 0 && tcache.Item3 == style)
            {
                ct = tcache.Item1;
                ft = tcache.Item2;
                _dc.DrawText(ft, GetTextOrigin(style, ref rect, ft));
            }
            else
            {
                var ci = CultureInfo.InvariantCulture;

                var fontStyle = System.Windows.FontStyles.Normal;
                var fontWeight = FontWeights.Regular;

                if (style.TextStyle.FontStyle != null)
                {
                    if (style.TextStyle.FontStyle.Flags.HasFlag(Core2D.Style.FontStyleFlags.Italic))
                    {
                        fontStyle = System.Windows.FontStyles.Italic;
                    }

                    if (style.TextStyle.FontStyle.Flags.HasFlag(Core2D.Style.FontStyleFlags.Bold))
                    {
                        fontWeight = FontWeights.Bold;
                    }
                }

                var tf = new Typeface(new FontFamily(style.TextStyle.FontName), fontStyle, fontWeight, FontStretches.Normal);

                ft = new FormattedText(
                    tbind,
                    ci,
                    ci.TextInfo.IsRightToLeft ? FlowDirection.RightToLeft : FlowDirection.LeftToRight,
                    tf,
                    style.TextStyle.FontSize > 0.0 ? style.TextStyle.FontSize : double.Epsilon,
                    stroke.Brush, null, TextFormattingMode.Ideal);

                if (style.TextStyle.FontStyle != null)
                {
                    if (style.TextStyle.FontStyle.Flags.HasFlag(Core2D.Style.FontStyleFlags.Underline)
                    || style.TextStyle.FontStyle.Flags.HasFlag(Core2D.Style.FontStyleFlags.Strikeout))
                    {
                        var decorations = new TextDecorationCollection();

                        if (style.TextStyle.FontStyle.Flags.HasFlag(Core2D.Style.FontStyleFlags.Underline))
                        {
                            decorations = new TextDecorationCollection(
                                decorations.Union(TextDecorations.Underline));
                        }

                        if (style.TextStyle.FontStyle.Flags.HasFlag(Core2D.Style.FontStyleFlags.Strikeout))
                        {
                            decorations = new TextDecorationCollection(
                                decorations.Union(TextDecorations.Strikethrough));
                        }

                        ft.SetTextDecorations(decorations);
                    }
                }

                _textCache.Set(text, Tuple.Create(tbind, ft, style));

                _dc.DrawText(ft, GetTextOrigin(style, ref rect, ft));
            }
        }
开发者ID:Core2D,项目名称:Core2D,代码行数:100,代码来源:WpfRenderer.cs

示例5: ApplyPrintStyles

        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);
        }
开发者ID:2594636985,项目名称:SharpDevelop,代码行数:32,代码来源:FixedDocumentCreator.cs

示例6: UseFormattedText

        private void UseFormattedText(RenderCallback renderCallback)
        {
            Brush textBrush = new SolidColorBrush(ForeColour);
            FontDescription fontDescription = Font.GetFontDescription();
            FormattedText formattedText = new FormattedText(Text, CultureInfo.CurrentCulture, FlowDirection.LeftToRight,
                                                            fontDescription.Typeface, fontDescription.Size, textBrush);
            formattedText.SetTextDecorations(fontDescription.TextDecorations);
            if (Width != null)
                formattedText.MaxTextWidth = Width.Value;
            if (Height != null)
                formattedText.MaxTextHeight = Height.Value;
            if (!Multiline)
                formattedText.MaxLineCount = 1;
            formattedText.Trimming = TextTrimming.None;
            //formattedText.TextAlignment = HorizontalTextAlignment;

            renderCallback(formattedText);
        }
开发者ID:sitdap,项目名称:dynamic-image,代码行数:18,代码来源:TextLayer.cs

示例7: DrawString


//.........这里部分代码省略.........
          switch (format.Alignment)
          {
            case XStringAlignment.Near:
              // nothing to do, this is the default
              //formattedText.TextAlignment = TextAlignment.Left;
              break;

            case XStringAlignment.Center:
              x += layoutRectangle.Width / 2;
              formattedText.TextAlignment = TextAlignment.Center;
              break;

            case XStringAlignment.Far:
              x += layoutRectangle.Width;
              formattedText.TextAlignment = TextAlignment.Right;
              break;
          }
          if (PageDirection == XPageDirection.Downwards)
          {
            switch (format.LineAlignment)
            {
              case XLineAlignment.Near:
                //y += cyAscent;
                break;

              case XLineAlignment.Center:
                // TODO use CapHeight. PDFlib also uses 3/4 of ascent
                y += -formattedText.Baseline + (cyAscent * 1 / 3) + layoutRectangle.Height / 2;
                //y += -formattedText.Baseline + (font.Size * font.Metrics.CapHeight / font.unitsPerEm / 2) + layoutRectangle.Height / 2;
                break;

              case XLineAlignment.Far:
                y += -formattedText.Baseline - cyDescent + layoutRectangle.Height;
                break;

              case XLineAlignment.BaseLine:
                y -= formattedText.Baseline;
                break;
            }
          }
          else
          {
            // TODOWPF
            switch (format.LineAlignment)
            {
              case XLineAlignment.Near:
                //y += cyDescent;
                break;

              case XLineAlignment.Center:
                // TODO use CapHeight. PDFlib also uses 3/4 of ascent
                //y += -(cyAscent * 3 / 4) / 2 + rect.Height / 2;
                break;

              case XLineAlignment.Far:
                //y += -cyAscent + rect.Height;
                break;

              case XLineAlignment.BaseLine:
                // nothing to do
                break;
            }
          }

          //if (bold && !descriptor.IsBoldFace)
          //{
          //  // TODO: emulate bold by thicker outline
          //}

          //if (italic && !descriptor.IsBoldFace)
          //{
          //  // TODO: emulate italic by shearing transformation
          //}

          if (underline)
          {
            formattedText.SetTextDecorations(TextDecorations.Underline);
            //double underlinePosition = lineSpace * realizedFont.FontDescriptor.descriptor.UnderlinePosition / font.cellSpace;
            //double underlineThickness = lineSpace * realizedFont.FontDescriptor.descriptor.UnderlineThickness / font.cellSpace;
            //DrawRectangle(null, brush, x, y - underlinePosition, width, underlineThickness);
          }

          if (strikeout)
          {
            formattedText.SetTextDecorations(TextDecorations.Strikethrough);
            //double strikeoutPosition = lineSpace * realizedFont.FontDescriptor.descriptor.StrikeoutPosition / font.cellSpace;
            //double strikeoutSize = lineSpace * realizedFont.FontDescriptor.descriptor.StrikeoutSize / font.cellSpace;
            //DrawRectangle(null, brush, x, y - strikeoutPosition - strikeoutSize, width, strikeoutSize);
          }


          //this.dc.DrawText(formattedText, layoutRectangle.Location.ToPoint());
          this.dc.DrawText(formattedText, new System.Windows.Point(x, y));
        }
#endif
      }

      if (this.renderer != null)
        this.renderer.DrawString(text, font, brush, layoutRectangle, format);
    }
开发者ID:AnthonyNystrom,项目名称:Pikling,代码行数:101,代码来源:XGraphics.cs

示例8: redraw

        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;

//.........这里部分代码省略.........
开发者ID:npcook,项目名称:terminal,代码行数:101,代码来源:TerminalLineVisual.cs

示例9: CreatedFormattedText

 private FormattedText CreatedFormattedText(string text, CultureInfo cultureInfo)
 {
     FormattedText formattedText = new FormattedText(text, cultureInfo, base.FlowDirection, this.Typeface, this.FontSize, this.Foreground, this.GetNumberSubstitution(), TextOptions.GetTextFormattingMode(this));
     formattedText.Trimming = this.TextTrimming;
     formattedText.TextAlignment = SimpleTextBlock.GetResolvedTextAlignment(this.TextWrapping, this.TextAlignment);
     formattedText.SetTextDecorations(this.TextDecorations);
     return formattedText;
 }
开发者ID:mdjabirov,项目名称:C1Decompiled,代码行数:8,代码来源:SimpleTextBlock.cs

示例10: GetFormattedText

        public FormattedText GetFormattedText(Brush textBrush, string text)
        {
            Typeface type = new Typeface(FontFamily, FontStyle, FontWeight, FontStretches.Normal);
            FormattedText formatedText = new FormattedText(text, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, type, FontSize, textBrush);

            formatedText.SetTextDecorations(TextDecorations);

            formatedText.Trimming = TextTrimming.CharacterEllipsis;

            switch (_horizontalAlignment)
            {
                case TextHorizontalAlignment.Left:
                    formatedText.TextAlignment = TextAlignment.Left;
                    break;
                case TextHorizontalAlignment.Center:
                    formatedText.TextAlignment = TextAlignment.Center;
                    break;
                case TextHorizontalAlignment.Right:
                    formatedText.TextAlignment = TextAlignment.Right;
                    break;
            }

            return formatedText;
        }
开发者ID:Heliflyer,项目名称:helios,代码行数:24,代码来源:TextFormat.cs

示例11: CreateTextBlock

		/*
		public static TextBlock CreateTextBlock(ExportText exportText,bool setBackcolor){
			
			var textBlock = new TextBlock();

			textBlock.Foreground = ConvertBrush(exportText.ForeColor);
			
			if (setBackcolor) {
				textBlock.Background = ConvertBrush(exportText.BackColor);
			}
			 
			SetFont(textBlock,exportText);
			
			textBlock.TextWrapping = TextWrapping.Wrap;
			
			CheckForNewLine (textBlock,exportText);
			SetContentAlignment(textBlock,exportText);
			MeasureTextBlock (textBlock,exportText);
			return textBlock;
		}
		*/
		
		/*
		static void CheckForNewLine(TextBlock textBlock,ExportText exportText) {
			string [] inlines = exportText.Text.Split(Environment.NewLine.ToCharArray());
			for (int i = 0; i < inlines.Length; i++) {
				if (inlines[i].Length > 0) {
					textBlock.Inlines.Add(new Run(inlines[i]));
					textBlock.Inlines.Add(new LineBreak());
				}
			}
			var li = textBlock.Inlines.LastInline;
			textBlock.Inlines.Remove(li);
		}
		
		
		static void MeasureTextBlock(TextBlock textBlock,ExportText exportText)
		{
			var wpfSize = MeasureTextInWpf(exportText);
			textBlock.Width = wpfSize.Width;
			textBlock.Height = wpfSize.Height;
		}	
		
		*/
		
		/*
		static Size MeasureTextInWpf(ExportText exportText){
			
			if (exportText.CanGrow) {
				var formattedText = NewMethod(exportText);
				
				formattedText.MaxTextWidth = exportText.DesiredSize.Width * 96.0 / 72.0;
				
				formattedText.SetFontSize(Math.Floor(exportText.Font.Size  * 96.0 / 72.0));
				
				var size = new Size {
					Width = formattedText.WidthIncludingTrailingWhitespace,
					Height = formattedText.Height + 6};
				return size;
			}
			return new Size(exportText.Size.Width,exportText.Size.Height);
		}

		*/
		
		
		public static FormattedText CreateFormattedText(ExportText exportText)
		{
			var formattedText = new FormattedText(exportText.Text,
				CultureInfo.CurrentCulture,
				FlowDirection.LeftToRight,
				new Typeface(exportText.Font.FontFamily.Name),
				exportText.Font.Size,
				new SolidColorBrush(exportText.ForeColor.ToWpf()), null, TextFormattingMode.Display);
			
			formattedText.MaxTextWidth = exportText.DesiredSize.Width * 96.0 / 72.0;
			formattedText.SetFontSize(Math.Floor(exportText.Font.Size  * 96.0 / 72.0));
			
			var td = new TextDecorationCollection()	;
			CheckUnderline(td,exportText);
			formattedText.SetTextDecorations(td);
			return formattedText;
		}
开发者ID:Rpinski,项目名称:SharpDevelop,代码行数:83,代码来源:FixedDocumentCreator.cs

示例12: GetFormattedText

        private static FormattedText GetFormattedText(FlowDocument doc)
        {
            var output = new FormattedText(
                GetText(doc),
                CultureInfo.CurrentCulture,
                doc.FlowDirection,
                new Typeface(doc.FontFamily, doc.FontStyle, doc.FontWeight, doc.FontStretch),
                doc.FontSize,
                doc.Foreground);

            int offset = 0;

            foreach (TextElement textElement in GetRunsAndParagraphs(doc))
            {
                var run = textElement as Run;

                if (run != null)
                {
                    int count = run.Text.Length;

                    output.SetFontFamily(run.FontFamily, offset, count);
                    output.SetFontSize(run.FontSize, offset, count);
                    output.SetFontStretch(run.FontStretch, offset, count);
                    output.SetFontStyle(run.FontStyle, offset, count);
                    output.SetFontWeight(run.FontWeight, offset, count);
                    output.SetForegroundBrush(run.Foreground, offset, count);
                    output.SetTextDecorations(run.TextDecorations, offset, count);

                    offset += count;
                }
                else
                {
                    offset += Environment.NewLine.Length;
                }
            }

            return output;
        }
开发者ID:nick121212,项目名称:xima_desktop3,代码行数:38,代码来源:AutoSizeRichTextBox.cs

示例13: _formatBody

      private void _formatBody() {
         var showMembers = Canvas.DisplayOptions.Has(DisplayOptions.DisplayClassMembers);
         var showInherited = Canvas.DisplayOptions.Has(DisplayOptions.DisplayInheritedMembers);
         var sortMembers = Canvas.DisplayOptions.Has(DisplayOptions.SortMembersByName);
         if (!showMembers) {
            _bodyText = null;
            return;
         }

         var bodyParts = new List<string>();
         var bodyStyles = new List<TextStyle>();

         Action<string, TextStyle> addPart = (t, s) => { bodyParts.Add(t); bodyStyles.Add(s); };
         Action addSpacer = () => addPart("-\n", TextStyle.Spacer);
         Action<BplClass> addProperties = bplClass => {
            var properties = (showInherited ? bplClass.Properties : bplClass.OwnProperties);
            if (sortMembers) {
               properties = properties.OrderBy(p => p.Name);
            }
            foreach (var prop in properties) {
               var name = prop.Name.At(0).ToUpper() + prop.Name.After(0);
               var type = String.Empty;
               if (prop.IsPrimitive) {
                  type = prop.PrimitiveType.Name;
               } else {
                  if (prop.IsReference) {
                     type = prop.UnderlyingType.Name;
                  } else if (prop.IsCollection) {
                     type = prop.UnderlyingItemType.Name + "*";
                  }
               }
               addPart("\u2022 " + name, (prop == bplClass.IdentityProperty ? TextStyle.Identity : TextStyle.FieldName));
               addPart(" (" + type + ")\n", TextStyle.DataType);
            }
         };

         var operation = Class.Operation;
         if (operation == null) {
            addProperties(Class);
         } else {
            addPart("INPUT:\n", TextStyle.Subtitle);
            addSpacer();
            addProperties(Class);
            if (operation.Output != null) {
               addSpacer();
               addSpacer();
               addPart("OUTPUT:\n", TextStyle.Subtitle);
               addSpacer();
               addProperties(operation.Output);
            }
         }

         _bodyText = ToFormattedText(bodyParts.ToArray().Join(), 14, _normalFG);
         for (int i = 0, j = 0; i < bodyParts.Count; i++) {
            var k = bodyParts[i].Length;
            switch(bodyStyles[i]) {
               case TextStyle.Identity:
                  _bodyText.SetTextDecorations(TextDecorations.Underline, j + 2, k - 2);
                  break;
               case TextStyle.DataType:
                  _bodyText.SetForegroundBrush(_lightFG, j, k);
                  _bodyText.SetFontStyle(FontStyles.Italic, j + 2, k - 4);
                  break;
               case TextStyle.Subtitle:
                  _bodyText.SetFontSize(13, j, k);
                  _bodyText.SetTextDecorations(TextDecorations.Underline, j, k);
                  break;
               case TextStyle.Spacer:
                  _bodyText.SetForegroundBrush(_bodyBG.Fill, j, k);
                  _bodyText.SetFontSize(3, j, k);
                  break;
            }
            j += k;
         }
      }
开发者ID:borkaborka,项目名称:gmit,代码行数:75,代码来源:DiagramNode.cs

示例14: FormatLine

        public void FormatLine(int line, FormattedText text)
        {
            foreach (var provider in this.providers)
            {
                TextChange change;
                var formatInfos = provider.GetFormatDataForLine(line, out change);

                if (formatInfos != null)
                {
                    foreach (var info in formatInfos)
                    {
                        var range = info.Range;

                        if (change != null)
                        {
                            for (var c = change.NextChange; c != null; c = c.NextChange)
                            {
                                range = c.ApplyTo(range);
                            }
                        }

                        int start = (range.Start.Line < line) ? 0 : range.Start.Index;
                        int end = (range.End.Line > line) ? this.Buffer.TextData.Lines[line].Length : range.End.Index;

                        if (end > start && end <= this.Buffer.TextData.Lines[line].Length)
                        {
                            if (info.Foreground != null)
                            {
                                text.SetForegroundBrush(info.Foreground, start, end - start);
                            }

                            if (info.Flags.HasFlag(FormatFlags.Bold))
                            {
                                text.SetFontWeight(FontWeights.Bold, start, end - start);
                            }

                            if (info.Flags.HasFlag(FormatFlags.Italic))
                            {
                                text.SetFontStyle(FontStyles.Italic, start, end - start);
                            }

                            if (info.Flags.HasFlag(FormatFlags.Underline))
                            {
                                var decorations = new TextDecorationCollection(new TextDecoration[] { new TextDecoration(TextDecorationLocation.Underline, null, 0, TextDecorationUnit.FontRecommended, TextDecorationUnit.FontRecommended) });
                                text.SetTextDecorations(decorations, start, end - start);
                            }
                        }
                    }
                }
            }
        }
开发者ID:UnaNancyOwen,项目名称:Kinect-Studio-Sample,代码行数:51,代码来源:TextFormatter.cs


注:本文中的System.Windows.Media.FormattedText.SetTextDecorations方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。