public static GeometryDrawing[] GetOutlinedText(string text, double maxFontSize, Rect rect, Brush fill, Brush stroke, Typeface typeFace, double strokeThickness = 2, bool centered = false) { var fText = new FormattedText(text, CultureInfo.GetCultureInfo("en-us"), FlowDirection.LeftToRight, typeFace, maxFontSize, fill); if (!double.IsNaN(rect.Width)) { if (fText.Width > rect.Width) { fText.SetFontSize((int)(maxFontSize * rect.Width / fText.Width)); } fText.MaxTextWidth = rect.Width; } var point = new Point(rect.X + (centered && !double.IsNaN(rect.Width) ? (rect.Width - fText.Width) / 2 : 0), !double.IsNaN(rect.Height) ? (rect.Height - fText.Height) / 2 + fText.Height * 0.05: rect.Y); var drawings = new[] { new GeometryDrawing(stroke, new Pen(Brushes.Black, strokeThickness) { LineJoin = PenLineJoin.Round }, fText.BuildGeometry(point)), new GeometryDrawing(fill, new Pen(Brushes.White, 0), fText.BuildGeometry(point)) }; return(drawings); }
protected override void OnRender(DrawingContext drawingContext) { drawingContext.DrawGeometry(Brushes.Orange, new Pen(Brushes.Black, 1), vm.J.Alak); foreach (PalyaElem p in vm.Elemek) { if (p is Exit) { drawingContext.DrawGeometry(Brushes.Lime, new Pen(Brushes.Black, 1), p.Alak); } else { if (p is Enemy) { drawingContext.DrawGeometry((p as Enemy).Szin, new Pen(Brushes.Black, 1), p.Alak); } else { drawingContext.DrawGeometry(Brushes.Gray, new Pen(Brushes.Black, 1), p.Alak); } } } FormattedText f = new FormattedText("Életek száma: " + elet.ToString(), System.Globalization.CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Arial"), 30, Brushes.Lime); Geometry g = f.BuildGeometry(new Point(0, 0)); drawingContext.DrawGeometry(Brushes.Lime, new Pen(Brushes.Black, 1), f.BuildGeometry(new Point(0, 0))); }
protected override void OnRender(DrawingContext drawingContext) { var str = 内容; var formattedText = new FormattedText(str, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface ( new FontFamily("微软雅黑"), FontStyles.Normal, FontWeights.Bold, FontStretches.Normal ), 字体大小, Brushes.Black, 5); var geometry = formattedText.BuildGeometry(new Point(10, 1)); if (是否居中) { geometry = formattedText.BuildGeometry(new Point(字幕位置 - 50, 1)); } drawingContext.DrawGeometry ( new SolidColorBrush(字体颜色), new Pen(new SolidColorBrush(描边颜色), 1), geometry ); base.OnRender(drawingContext); }
/// <summary> /// 基于格式化文字创建文字的几何轮廓。 /// </summary> public void CreateText() { FontStyle fontStyle = FontStyles.Normal; FontWeight fontWeight = FontWeights.Medium; if (Bold == true) { fontWeight = FontWeights.Bold; } if (Italic == true) { fontStyle = FontStyles.Italic; } // 基于设置的属性集创建格式化的文字。 FormattedText formattedText = new FormattedText( Text, CultureInfo.GetCultureInfo("en-us"), FlowDirection.LeftToRight, new Typeface(Font, fontStyle, fontWeight, FontStretches.Normal), FontSize, Brushes.White) { Trimming = TextTrimming.CharacterEllipsis }; // formattedText.MaxTextWidth = ActualWidth; Width = formattedText.Width; Height = formattedText.Height; // 创建表示文字的几何对象。 // 基于格式化文字的大小设置空心文字的大小。 textHeight = formattedText.Height; HorizontalAlignment horizontalAlignment = (HorizontalAlignment)GetValue(HorizontalContentAlignmentProperty); switch (horizontalAlignment) { case HorizontalAlignment.Center: { m_TextGeometry = formattedText.BuildGeometry(new Point((ActualWidth - formattedText.Width) / 2, (ActualHeight - textHeight) / 2)); break; } default: { m_TextGeometry = formattedText.BuildGeometry(new Point(0, 0)); break; } } }
/// <summary> /// Converts a BindingList of buildings into a GeometryGroup /// </summary> /// <param name="value">A BindingList containing buildings</param> /// <param name="targetType">The parameter is not used.</param> /// <param name="parameter">The parameter is not used.</param> /// <param name="culture">The parameter is not used.</param> /// <returns>Returns a GeometryGroup which has all buildings included</returns> public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { BindingList <Building> buildings = (BindingList <Building>)value; GeometryGroup allBuildingGeo = new GeometryGroup(); foreach (Building building in buildings) { RectangleGeometry bGeo = new RectangleGeometry(new Rect(building.Position.X, building.Position.Y, Building.W, Building.H)); allBuildingGeo.Children.Add(bGeo); if (building.Shield != null && building.Shield.CurHP > 0) { GeometryGroup gg = new GeometryGroup(); RectangleGeometry sGeo = new RectangleGeometry(new Rect(building.Position.X + ((Building.W / 2) - 18), building.Position.Y + (Building.H / 3), Shield.W, Shield.H)); FormattedText text = new FormattedText(building.Shield.CurHP.ToString(), CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Arial"), 16, Brushes.Black); Geometry textGeometry = text.BuildGeometry(new Point(building.Position.X + ((Building.W / 2) + 10), building.Position.Y + (Building.H / 3))); gg.Children.Add(sGeo); gg.Children.Add(textGeometry); allBuildingGeo.Children.Add(gg); } else { FormattedText text = new FormattedText(building.CurHP + "/" + building.MaxHP, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Arial"), 16, Brushes.Black); Geometry textGeometry = text.BuildGeometry(new Point(building.Position.X + ((Building.W / 2) - 11), building.Position.Y + (Building.H / 3))); allBuildingGeo.Children.Add(textGeometry); } } return(allBuildingGeo); }
private Path getUnitPathFromInt(int unit, Point loc) { string unitString = unit.ToString(); Geometry unitGeom; // Create the initial formatted text string. FormattedText formattedText = new FormattedText(unitString, CultureInfo.GetCultureInfo(CultureInfo.CurrentCulture.Name), FlowDirection.LeftToRight, new Typeface("Verdana"), 10, Brushes.Black, VisualTreeHelper.GetDpi(this).PixelsPerDip); // Use an Italic font style beginning at the 28th character and continuing for 28 characters. formattedText.SetFontStyle(FontStyles.Normal); // Convert unitGeom = formattedText.BuildGeometry(loc); Path textPath = new Path(); textPath.Fill = Brushes.Black; textPath.Data = unitGeom; return(textPath); }
public static void DrawText(this DrawingContext drawingContext, string text, Point point, Typeface typeface, double emSize, Color color, Color?haloColor = null, double?haloRadius = null, double angle = 0) { var formattedText = new FormattedText(text, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, typeface, emSize, new SolidColorBrush(color)); var width = formattedText.Width + haloRadius.GetValueOrDefault() * 2; var height = formattedText.Height + haloRadius.GetValueOrDefault() * 2; var rotate = new RotateTransform(angle); var newRect = rotate.TransformBounds(new Rect(new Point(0, 0), new Size(width, height))); drawingContext.PushTransform(new TranslateTransform(-newRect.Left, -newRect.Top)); drawingContext.PushTransform(rotate); if (haloColor.HasValue && haloRadius.HasValue && haloRadius.Value > 0) { var pen = new Pen(new SolidColorBrush(haloColor.Value), haloRadius.Value * 2); var textGeometry = formattedText.BuildGeometry(point); drawingContext.DrawGeometry(null, pen, textGeometry); } drawingContext.DrawText(formattedText, point); drawingContext.Pop(); drawingContext.Pop(); }
/// <summary> /// This method creates the text geometry. /// </summary> private void CreateTextGeometry() { var formattedText = new FormattedText(Text, Thread.CurrentThread.CurrentUICulture, FlowDirection.LeftToRight, new Typeface(FontFamily, FontStyle, FontWeight, FontStretch), FontSize, Brushes.Black); _textGeometry = formattedText.BuildGeometry(Origin); }
private Drawing GetChest() { DrawingGroup dg = new DrawingGroup(); ImageDrawing background = new ImageDrawing(GetImage("questions.png"), new Rect(650, 400, 650, 400)); FormattedText question = new FormattedText(this.model.Chest.Question.ToString(), CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Arial"), 40, Brushes.Black, 1); Geometry geo = question.BuildGeometry(new Point(760, 500)); GeometryDrawing gd = new GeometryDrawing(Brushes.White, null, geo); FormattedText answer0 = new FormattedText(this.model.Chest.Answers[0].ToString(), CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Arial"), 40, Brushes.Black, 1); Geometry geo1 = answer0.BuildGeometry(new Point(730, 600)); GeometryDrawing gd1 = new GeometryDrawing(Brushes.White, null, geo1); FormattedText answer1 = new FormattedText(this.model.Chest.Answers[1].ToString(), CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Arial"), 40, Brushes.Black, 1); Geometry geo2 = answer1.BuildGeometry(new Point(1000, 600)); GeometryDrawing gd2 = new GeometryDrawing(Brushes.White, null, geo2); FormattedText answer2 = new FormattedText(this.model.Chest.Answers[2].ToString(), CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Arial"), 40, Brushes.Black, 1); Geometry geo3 = answer2.BuildGeometry(new Point(720, 685)); GeometryDrawing gd3 = new GeometryDrawing(Brushes.White, null, geo3); FormattedText answer3 = new FormattedText(this.model.Chest.Answers[3].ToString(), CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Arial"), 40, Brushes.Black, 1); Geometry geo4 = answer3.BuildGeometry(new Point(1010, 685)); GeometryDrawing gd4 = new GeometryDrawing(Brushes.White, null, geo4); dg.Children.Add(background); dg.Children.Add(gd); dg.Children.Add(gd1); dg.Children.Add(gd2); dg.Children.Add(gd3); dg.Children.Add(gd4); return(dg); }
/// <summary> /// updates the legend with all of the boxes and descriptions /// </summary> private void Update() { drawing.Children.Clear(); double currentY = 0; //if there is one thing being graphed, don't include a legend if (list.Count <= 1) { return; } else { //makes a new box and description for each tuple in the list foreach (var tuple in list) { Brush myBrush = new SolidColorBrush(tuple.Item2); FormattedText thisText = new FormattedText(tuple.Item1, CultureInfo.CurrentUICulture, FlowDirection.LeftToRight, new Typeface("Arial"), 10, myBrush); double boxSize = thisText.Height; Geometry geo = new RectangleGeometry(new Rect(0, currentY, boxSize, boxSize)); drawing.Children.Add(new GeometryDrawing(myBrush, null, geo)); Geometry textGeo = thisText.BuildGeometry(new Point(1.5 * boxSize, currentY)); drawing.Children.Add(new GeometryDrawing(myBrush, null, textGeo)); currentY += boxSize; } //Rectangle border around legend Geometry legendRect = new RectangleGeometry(new Rect(-.05 * drawing.Bounds.Width, -.05 * drawing.Bounds.Height, drawing.Bounds.Width * 1.1, drawing.Bounds.Height * 1.1)); drawing.Children.Insert(0, new GeometryDrawing(Brushes.White, new Pen(Brushes.Black, 1), legendRect)); } }
/// <summary> /// Create the outline geometry based on the formatted text. /// </summary> public void CreateText() { FontStyle fontStyle = FontStyles.Normal; FontWeight fontWeight = FontWeights.Medium; if (Bold == true) { fontWeight = FontWeights.Bold; } if (Italic == true) { fontStyle = FontStyles.Italic; } // Create the formatted text based on the properties set. FormattedText formattedText = new FormattedText( Text, CultureInfo.CurrentCulture, this.FlowDirection, new Typeface(Font, fontStyle, fontWeight, FontStretches.Normal), FontSize, Brushes.Black // This brush does not matter since we use the geometry of the text. ); // Build the geometry object that represents the text. _textGeometry = formattedText.BuildGeometry(new Point(0, 0)); //set the size of the custome control based on the size of the text this.MinWidth = formattedText.Width; this.MinHeight = formattedText.Height; }
public override Geometry GetGeometry() { GeometryGroup group = new GeometryGroup(); for (int a = 0; a < Texts.Count; a++) { if (!string.IsNullOrEmpty(Texts[a])) { FormattedText formattedText = NewFormattedText(Texts[a]); double locx = 0; double locy = 0; Rect bounds = ShapeComponent.GetGeometry().GetRenderBounds(new Pen(), 0, ToleranceType.Absolute); double width = bounds.Width; double height = bounds.Height; if (a % 2 == 0) { locx = (width / 2) - (formattedText.Width / 2); } if (a % 2 == 1) { locy = (height / 2) - (formattedText.Height / 2); } if (a % 4 == 2) { locy = width - formattedText.Height; } if (a % 4 == 1) { locx = height - formattedText.Width; } group.Children.Add(formattedText.BuildGeometry(new Point(locx, locy))); } } return(group); }
public static Geometry ConstructTextGeometry(SvgTextContentElement textContentElement, string text, Point position, out Size textDimensions) { Typeface typeface = new Typeface( GetTextFontFamily(textContentElement), GetTextFontStyle(textContentElement), GetTextFontWeight(textContentElement), GetTextFontStretch(textContentElement)); FormattedText formattedText = new FormattedText(text, System.Globalization.CultureInfo.CurrentUICulture, GetTextDirection(textContentElement), typeface, GetComputedFontSize(textContentElement), Brushes.Black) { LineHeight = GetComputedLineHeight(textContentElement) }; if (textContentElement is SvgTextPositioningElement tpe) { position = GetCurrentTextPosition(tpe, position); } position.Y -= formattedText.Height; textDimensions = new Size(formattedText.Width, formattedText.Height); return(formattedText.BuildGeometry(position)); }
/// <summary> /// Create the outline geometry based on the formatted text. /// </summary> public static void CreateText(string Text, FontFamily Font = null, bool Bold = false, bool Italic = false) { System.Windows.FontStyle fontStyle = FontStyles.Normal; FontWeight fontWeight = FontWeights.Medium; if (Bold == true) { fontWeight = FontWeights.Bold; } if (Italic == true) { fontStyle = FontStyles.Italic; } if (null == Font) { Font = new FontFamily("Arial"); } // Create the formatted text based on the properties set. FormattedText formattedText = new FormattedText( Text, CultureInfo.GetCultureInfo("en-us"), FlowDirection.LeftToRight, new Typeface( Font, fontStyle, fontWeight, FontStretches.Normal), _fontSize, System.Windows.Media.Brushes.Black // This brush does not matter since we use the geometry of the text. ); // Build the geometry object that represents the text. _textGeometry = formattedText.BuildGeometry(new System.Windows.Point(0, 0)); }
// Convert the text string to a geometry and draw it to the control's DrawingContext. private Drawing DrawMyText(string textString) { // Create a new DrawingGroup of the control. DrawingGroup drawingGroup = new DrawingGroup(); // Open the DrawingGroup in order to access the DrawingContext. using (DrawingContext drawingContext = drawingGroup.Open()) { // Create the formatted text based on the properties set. FormattedText formattedText = new FormattedText( textString, CultureInfo.GetCultureInfo("en-us"), FlowDirection.LeftToRight, new Typeface("Comic Sans MS Bold"), 48, System.Windows.Media.Brushes.Black // This brush does not matter since we use the geometry of the text. ); // Build the geometry object that represents the text. Geometry textGeometry = formattedText.BuildGeometry(new System.Windows.Point(20, 0)); // Draw a rounded rectangle under the text that is slightly larger than the text. drawingContext.DrawRoundedRectangle(System.Windows.Media.Brushes.PapayaWhip, null, new Rect(new System.Windows.Size(formattedText.Width + 50, formattedText.Height + 5)), 5.0, 5.0); // Draw the outline based on the properties that are set. drawingContext.DrawGeometry(System.Windows.Media.Brushes.Gold, new System.Windows.Media.Pen(System.Windows.Media.Brushes.Maroon, 1.5), textGeometry); // Return the updated DrawingGroup content to be used by the control. return(drawingGroup); } }
private Stream GetImageFromText() { MemoryStream ms = null; DrawingVisual drawingVisual = new DrawingVisual(); using (DrawingContext dc = drawingVisual.RenderOpen()) { var typeface = new Typeface(FontFamily, FontStyle, FontWeight, FontStretches.Normal); FormattedText ft = new FormattedText(_fontText, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, typeface, _fontSize, _foreground); Geometry geometry = ft.BuildGeometry(new Point(0.0, 0.0)); dc.DrawText(ft, new Point(0.0, 0.0)); dc.Close(); } //dpi可以自己设定 // 获取dpi方法:PresentationSource.FromVisual(this).CompositionTarget.TransformToDevice RenderTargetBitmap bitmap = new RenderTargetBitmap(100, 100, 72, 72, PixelFormats.Pbgra32); bitmap.Render(drawingVisual); PngBitmapEncoder encode = new PngBitmapEncoder(); encode.Frames.Add(BitmapFrame.Create(bitmap)); ms = new MemoryStream(); encode.Save(ms); ms.Position = 0; return(ms); }
protected override void OnRender(DrawingContext drawingContext) { ensureTextBlock(); base.OnRender(drawingContext); #pragma warning disable CS0618 // Type or member is obsolete var formattedText = new FormattedText( _textBlock.Text, CultureInfo.CurrentUICulture, _textBlock.FlowDirection, new Typeface(_textBlock.FontFamily, _textBlock.FontStyle, _textBlock.FontWeight, _textBlock.FontStretch), _textBlock.FontSize, Brushes.Black // This brush does not matter since we use the geometry of the text. ) { TextAlignment = _textBlock.TextAlignment, Trimming = _textBlock.TextTrimming, LineHeight = _textBlock.LineHeight, MaxTextWidth = _textBlock.ActualWidth - _textBlock.Padding.Left - _textBlock.Padding.Right, MaxTextHeight = _textBlock.ActualHeight - _textBlock.Padding.Top // - _textBlock.Padding.Bottom; }; #pragma warning restore CS0618 // Type or member is obsolete while (formattedText.Extent == double.NegativeInfinity) { formattedText.MaxTextHeight++; } // Build the geometry object that represents the text. var _textGeometry = formattedText.BuildGeometry(new Point(_textBlock.Padding.Left, _textBlock.Padding.Top)); var textPen = new Pen(Stroke, StrokeThickness); drawingContext.DrawGeometry(Brushes.Transparent, textPen, _textGeometry); }
protected override void OnRender(DrawingContext drawingContext) { EnsureFormattedText(); if (_formattedText == null) { return; } var y = !double.IsNaN(ActualHeight) ? (ActualHeight - _formattedText.Height) / 2 + _formattedText.Height * 0.05: 0; drawingContext.DrawGeometry(Stroke, new Pen(Brushes.Black, 2.0) { LineJoin = PenLineJoin.Round }, _formattedText.BuildGeometry(new Point(0, y))); drawingContext.DrawGeometry(Fill, new Pen(Brushes.White, 0), _formattedText.BuildGeometry(new Point(0, y))); }
// Convert the text string to a geometry and draw it to the control's DrawingContext. private DrawingGroup DrawText(string textString) { // Create a new DrawingGroup of the control. DrawingGroup drawingGroup = new DrawingGroup(); drawingGroup.Opacity = 0.8; // Open the DrawingGroup in order to access the DrawingContext. using (DrawingContext drawingContext = drawingGroup.Open()) { // Create the formatted text based on the properties set. var formattedText = new FormattedText(textString, CultureInfo.CurrentUICulture, FlowDirection.LeftToRight, new Typeface(new FontFamily("Tahoma"), FontStyles.Normal, FontWeights.Normal, FontStretches.Normal), 72, Brushes.Black); // Build the geometry object that represents the text. Geometry textGeometry = formattedText.BuildGeometry(new Point(20, 0)); drawingContext.DrawRoundedRectangle(Brushes.Transparent, null, new Rect(new Size(formattedText.Width + 50, formattedText.Height + 5)), 5.0, 5.0); // Draw the outline based on the properties that are set. drawingContext.DrawGeometry(null, new Pen(Brushes.DarkGray, 1.5), textGeometry); } // Return the updated DrawingGroup content to be used by the control. return(drawingGroup); }
static Drawing CreateCharacterDrawing(char c, Color color, bool fillBg) { if (color == Colors.Black) { color = Colors.White; } DrawingGroup dGroup = new DrawingGroup(); Brush brush = new SolidColorBrush(color); using (DrawingContext dc = dGroup.Open()) { var typeFace = new Typeface(new FontFamily("Lucida Console"), FontStyles.Normal, FontWeights.Bold, FontStretches.Normal); var formattedText = new FormattedText( c.ToString(), System.Globalization.CultureInfo.GetCultureInfo("en-us"), FlowDirection.LeftToRight, typeFace, 16, Brushes.Black); var geometry = formattedText.BuildGeometry(new System.Windows.Point(0, 0)); var bg = fillBg ? Brushes.Black : Brushes.Transparent; var pen = fillBg ? null : new Pen(Brushes.Black, 0.5); dc.DrawRectangle(bg, null, new Rect(new Size(formattedText.Width, formattedText.Height))); dc.DrawGeometry(brush, pen, geometry); } return(dGroup); }
public void CreateText() { if (this.TextContent == null) { throw new NullReferenceException("TextContent value cannot be null."); } if (_geometryObjectChanged) { _formattedText = new FormattedText( this.TextContent, CultureInfo.GetCultureInfo("en-us"), FlowDirection.LeftToRight, new Typeface(new FontFamily(this.FontFamily), this.FontStyle, this.FontWeight, _fontStretch), this.FontSize, Brushes.Black); _textGeometry = _formattedText.BuildGeometry(new Point(0, this.Offset)); if (_highlight) { _textHighLightGeometry = _formattedText.BuildHighlightGeometry(new Point(0, 0)); } _geometryObjectChanged = false; } }
private void AddText() { foreach (var t in dxf.Texts) { FormattedText formattedText = new FormattedText(t.Value, CultureInfo.GetCultureInfo("zh-CN"), FlowDirection.LeftToRight, new Typeface("仿宋体"), t.Height * (96.0 / 72.0), System.Windows.Media.Brushes.White); //SolidColorBrush brush = new SolidColorBrush(Colors.Orange); LinearGradientBrush brush = new LinearGradientBrush( Colors.Orange, Colors.Teal, 90.0); formattedText.SetForegroundBrush(brush); //Geometry textGeometry = formattedText.BuildGeometry(new System.Windows.Point(t.BasePoint.X, -t.BasePoint.Y - t.Height * (96.0 / 72.0))); Geometry textGeometry = formattedText.BuildGeometry(new System.Windows.Point(t.Position.X, -t.Position.Y - t.Height * (96.0 / 72.0))); PathGeometry pathGeometry = textGeometry.GetFlattenedPathGeometry(); foreach (var p in MyCanvas.Children) { if (p is Path) { System.Windows.Shapes.Path path = (System.Windows.Shapes.Path)p; if ((string)path.Tag == "Character") { ((GeometryGroup)path.Data).Children.Add(pathGeometry); } } } //Characters.Children.Add(pathGeometry); } }
/// <summary> /// Convert a given text to graphic paths /// </summary> public static (double, double) Vectorize(GraphicPathGeometry graphicPathGeometry, string text, double x, double y, Typeface typeface, double fontSize, double rotate, Matrix currentTransformationMatrix) { FormattedText formattedText = new FormattedText( text, CultureInfo.InvariantCulture, FlowDirection.LeftToRight, typeface, fontSize, Brushes.Black, 96); Matrix fontTransformation = Matrix.Identity; fontTransformation.RotateAt(rotate, 0, formattedText.Baseline); fontTransformation.Translate(x, y - formattedText.Baseline); fontTransformation = fontTransformation * currentTransformationMatrix; var pathGeometry = formattedText.BuildGeometry(new Point(0, 0)); ConvertToGraphicGeometry(graphicPathGeometry, pathGeometry, fontTransformation); var newX = formattedText.WidthIncludingTrailingWhitespace; return(x + newX, y); }
public void CreateText() { FontStyle fontStyle = FontStyles.Normal; FontWeight fontWeight = FontWeights.Medium; if (Bold == true) { fontWeight = FontWeights.Bold; } if (Italic == true) { fontStyle = FontStyles.Italic; } FormattedText formattedText = new FormattedText( Text ?? string.Empty, CultureInfo.InvariantCulture, FlowDirection.LeftToRight, new Typeface(FontFamily, fontStyle, fontWeight, FontStretches.Normal), FontSize, Brushes.Black ); _textGeometry = formattedText.BuildGeometry(new Point(0, 0)); this.MinWidth = formattedText.Width; this.MinHeight = formattedText.Height; }
//[Obsolete] private void MarkerFun() { GeometryGroup geometryGroup = new GeometryGroup(); for (int i = 0; i <= 10; i++) { FormattedText formattedText = new FormattedText( String.Format("{0,7:F}", 1 - i * 0.2), CultureInfo.InvariantCulture, FlowDirection.LeftToRight, new Typeface("Verdana"), 0.05, Brushes.Black); formattedText.SetFontWeight(FontWeights.Bold); Geometry geometry = formattedText.BuildGeometry(new Point(-0.2, i * 0.1 - 0.03)); geometryGroup.Children.Add(geometry); } GeometryDrawing geometryDrawing = new GeometryDrawing(); geometryDrawing.Geometry = geometryGroup; geometryDrawing.Brush = Brushes.LightGray; geometryDrawing.Pen = new Pen(Brushes.Green, 0.003); drawingGroup.Children.Add(geometryDrawing); }
public override Path draw() { Path path = new Path(); TransformGroup transforms = new TransformGroup(); Point shiftedStart = ViewerHelper.mapToWPF(this.start, this.parent); this.text = ViewerHelper.swtichDXFSymbols(this.text); path.Stroke = new SolidColorBrush(ViewerHelper.getColor(layer.lineColor)); path.Fill = new SolidColorBrush(ViewerHelper.getColor(layer.lineColor)); path.StrokeThickness = Math.Abs(this.parent.header.yMin) > 400 ? 0.2 : 0.01; FormattedText text = new FormattedText(this.text, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface(style.getFontFamily()), .05 + this.size * (96 / 72), Brushes.White); //Adjust for difference in WPF text origin (top left) and DXF origin (bottom left) start.Y += text.Baseline; Geometry geometry = text.BuildGeometry(ViewerHelper.mapToWPF(this.start, this.parent)); transforms.Children.Add(style.getMirrorTransform(shiftedStart)); if (!this.text.Equals("")) { transforms.Children.Add(new RotateTransform(-angle, shiftedStart.X, shiftedStart.Y)); } path.Data = geometry; path.RenderTransform = transforms; return(path); }
public static BitmapSource DrawTags(BitmapSource baseImage, Tag[] tags) { if (tags == null) { return(baseImage); } Action <DrawingContext, BitmapSource, double> drawAction = (drawingContext, oriImage, annotationScale) => { double y = 0; foreach (var tag in tags) { // Create formatted text--in a particular font at a particular size FormattedText ft = new FormattedText(tag.Name, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, s_typeface, 21 * annotationScale, Brushes.Black); // Instead of calling DrawText (which can only draw the text in a solid colour), we // convert to geometry and use DrawGeometry, which allows us to add an outline. var geom = ft.BuildGeometry(new System.Windows.Point(10 * annotationScale, y)); drawingContext.DrawGeometry(s_lineBrush, new Pen(Brushes.Black, 2 * annotationScale), geom); // Move line down y += 42 * annotationScale; } }; return(DrawOverlay(baseImage, drawAction)); }
private void getformattedText(string str) { System.Windows.FontStyle fontStyle = FontStyles.Normal; FontWeight fontWeight = FontWeights.Normal; // Create the formatted text based on the properties set. FormattedText formattedText = new FormattedText( str, CultureInfo.GetCultureInfo("en-us"), FlowDirection.LeftToRight, new Typeface( FontFamily, FontStyle, FontWeight, FontStretch), FontSize, System.Windows.Media.Brushes.Black // This brush does not matter since we use the geometry of the text. ); this.Width = formattedText.Width; this.Height = formattedText.Height; // Build the geometry object that represents the text. //pg.AddGeometry(formattedText.BuildGeometry(new System.Windows.Point(5, 5))); TextGeometry = formattedText.BuildGeometry(new System.Windows.Point(0, 0)); // Build the geometry object that represents the text hightlight. if (Highlight == true) { TextHighLightGeometry = formattedText.BuildHighlightGeometry(new System.Windows.Point(0, 0)); } }
public void CreateText() { System.Windows.FontStyle fontStyle = FontStyles.Normal; FontWeight fontWeight = FontWeights.Bold; //if (Bold == true) fontWeight = FontWeights.Bold; //if (Italic == true) fontStyle = FontStyles.Italic; string upperCaseText = Text.ToUpper(); // Create the formatted text based on the properties set. FormattedText formattedText = new FormattedText( upperCaseText, CultureInfo.GetCultureInfo("en-us"), FlowDirection.LeftToRight, new Typeface( FontFamily, fontStyle, fontWeight, FontStretches.Normal), FontSize, System.Windows.Media.Brushes.Black // This brush does not matter since we use the geometry of the text. ); // Build the geometry object that represents the text. _textGeometry = formattedText.BuildGeometry(new System.Windows.Point(0, 0)); // Build the geometry object that represents the text hightlight. //if (Highlight == true) //{ // _textHighLightGeometry = formattedText.BuildHighlightGeometry(new System.Windows.Point(0, 0)); //} }
public static Size MeasureSize(string text, FontFamily fontFamily, double fontSize) { if (text == null) { text = ""; } System.Windows.FontStyle fontStyle = FontStyles.Normal; FontWeight fontWeight = FontWeights.Medium; var formattedText = new FormattedText( text, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface( fontFamily, fontStyle, fontWeight, FontStretches.Normal), fontSize, System.Windows.Media.Brushes.Black ); Geometry _textGeometry = formattedText.BuildGeometry(new System.Windows.Point(0, 0)); Geometry _textHighLightGeometry = formattedText.BuildHighlightGeometry(new System.Windows.Point(0, 0)); return(_textHighLightGeometry == null ? new Size(0, 0) : _textHighLightGeometry.Bounds.Size); }