private void UpdateFormattedText02() { // Create a DrawingGroup object for storing formatted text. myTextDisplay = new DrawingGroup(); DrawingContext drawingContext = myTextDisplay.Open(); // Update the text store. customTextSource.Text = "The quick red fox jumped over the lazy brown dog."; // Create a TextFormatter object. TextFormatter formatter = TextFormatter.Create(); // Create common paragraph property settings. CustomTextParagraphProperties customTextParagraphProperties = new CustomTextParagraphProperties(); // <SnippetTextFormattingSnippet2> // Create a textline from the text store using the TextFormatter object. TextLine myTextLine = formatter.FormatLine( customTextSource, 0, 400, customTextParagraphProperties, null); // Draw the formatted text into the drawing context. myTextLine.Draw(drawingContext, new Point(0, 0), InvertAxes.None); // </SnippetTextFormattingSnippet2> // Persist the drawn text content. drawingContext.Close(); // Display the formatted text in the DrawingGroup object. myDrawingBrush.Drawing = myTextDisplay; }
private static void DrawTextLine(Graphics grph, TextLine line) { foreach (Word word in line.Words) DrawWord(grph, word); line.Draw(grph); }
/// <summary> /// 渲染一次text,并返回渲染后生成的TextLine对象 /// </summary> /// <param name="offsetX">要渲染的字符串的X偏移量</param> /// <param name="offsetY">要渲染的字符串的Y偏移量</param> /// <param name="text">要渲染的字符串</param> /// <returns></returns> private TextLine Render(double offsetX, double offsetY, string text) { this.textSource.Text = text; int textSourcePosition = 0; Point lineOrigin = new Point(offsetX, offsetY); using (DrawingContext dc = base.RenderOpen()) { // 这里保证TextLine一次就可以把所有的字符都渲染完毕 // DefaultParagraphWidth大于被渲染的字符串的宽度,那么一次就可以渲染完毕 // 渲染完毕后返回TextLine对象,TextLine对象需要在使用完之后释放掉 // 如果渲染了多次,那么就会出现多个TextLine对象,那么此时就没法确定先被渲染的TextLine在什么时候释放 //while (textSourcePosition < this.textSource.Text.Length) { TextLine textLine = this.textFormatter.FormatLine(this.textSource, textSourcePosition, DefaultParagraphWidth, this.textParagraphProperties, null); textLine.Draw(dc, lineOrigin, InvertAxes.None); // 更新下一次要渲染的字符的索引 textSourcePosition += textLine.Length; // 更新下一次要渲染的字符的位置 lineOrigin.X += textLine.Width; return(textLine); } } }
public static void DrawTextLine(Graphics grph, TextLine line) { foreach (Word word in line.Words) { DrawWord(grph, word); } line.Draw(grph); }
public Visual GetOrCreateVisual() { if (drawingVisual is null) { drawingVisual = new DrawingVisual(); var dc = drawingVisual.RenderOpen(); textLine.Draw(dc, new Point(right - textLine.Width, top), InvertAxes.None); dc.Close(); } return(drawingVisual); }
/// <summary> /// Method for starting the text formatting process. Each event handler /// will call this after the current fontrendering is updated. /// </summary> private void UpdateFormattedText(double pixelsPerDip) { // Make sure all UI is loaded if (!_UILoaded) { return; } // Initialize the text store. _textStore = new CustomTextSource(_pixelsPerDip); int textStorePosition = 0; //Index into the text of the textsource System.Windows.Point linePosition = new System.Windows.Point(0, 0); //current line // Create a DrawingGroup object for storing formatted text. textDest = new DrawingGroup(); DrawingContext dc = textDest.Open(); // Update the text store. _textStore.Text = textToFormat.Text; _textStore.FontRendering = _currentRendering; // Create a TextFormatter object. TextFormatter formatter = TextFormatter.Create(); // Format each line of text from the text store and draw it. while (textStorePosition < _textStore.Text.Length) { // Create a textline from the text store using the TextFormatter object. using (TextLine myTextLine = formatter.FormatLine( _textStore, textStorePosition, 96 * 6, new GenericTextParagraphProperties(_currentRendering, _pixelsPerDip), null)) { // Draw the formatted text into the drawing context. myTextLine.Draw(dc, linePosition, InvertAxes.None); // Update the index position in the text store. textStorePosition += myTextLine.Length; // Update the line position coordinate for the displayed line. linePosition.Y += myTextLine.Height; } } // Persist the drawn text content. dc.Close(); // Display the formatted text in the DrawingGroup object. myDrawingBrush.Drawing = textDest; }
private void UpdateFormattedText() { // Index into the text of the TextSource object. int textStorePosition = 0; // The position of the current line. Point linePosition = new Point(0, 0); // Create a DrawingGroup object for storing formatted text. myTextDisplay = new DrawingGroup(); DrawingContext drawingContext = myTextDisplay.Open(); // Update the text store. customTextSource.Text = textToFormat.Text; // <SnippetTextFormattingSnippet1> // Create a TextFormatter object. TextFormatter formatter = TextFormatter.Create(); // Create common paragraph property settings. CustomTextParagraphProperties customTextParagraphProperties = new CustomTextParagraphProperties(); // Format each line of text from the text store and draw it. while (textStorePosition < customTextSource.Text.Length) { // Create a textline from the text store using the TextFormatter object. using (TextLine myTextLine = formatter.FormatLine( customTextSource, textStorePosition, 96 * 6, customTextParagraphProperties, null)) { // Draw the formatted text into the drawing context. myTextLine.Draw(drawingContext, linePosition, InvertAxes.None); // Update the index position in the text store. textStorePosition += myTextLine.Length; // Update the line position coordinate for the displayed line. linePosition.Y += myTextLine.Height; } } // </SnippetTextFormattingSnippet1> // Persist the drawn text content. drawingContext.Close(); // Display the formatted text in the DrawingGroup object. myDrawingBrush.Drawing = myTextDisplay; }
public override void Draw() { base.Draw(); diamond2.Draw(); diamond1.Draw(); candle1.Draw(); candle2.Draw(); title.Draw(); copirightText.Draw(); foreach (var buttonData in menuButtons) { buttonData.Value.Draw(); } }
// Token: 0x0600662F RID: 26159 RVA: 0x001CB8C4 File Offset: 0x001C9AC4 internal void Render(DrawingContext ctx, Point lineOffset) { TextLine textLine = this._line; if (this._line.HasOverflowed && this._owner.ParagraphProperties.TextTrimming != TextTrimming.None) { textLine = this._line.Collapse(new TextCollapsingProperties[] { this.GetCollapsingProps(this._wrappingWidth, this._owner.ParagraphProperties) }); } double num = this.CalculateXOffsetShift(); textLine.Draw(ctx, new Point(lineOffset.X + num, lineOffset.Y), this._mirror ? InvertAxes.Horizontal : InvertAxes.None); }
// Token: 0x060068A0 RID: 26784 RVA: 0x001D8230 File Offset: 0x001D6430 internal void FormatAndDrawVisual(DrawingContext ctx, LineProperties lineProps, int ur, int vrBaseline) { bool flag = lineProps.FlowDirection == FlowDirection.RightToLeft; this._host.Context = this; try { TextLine textLine = this._host.TextFormatter.FormatLine(this._host, 0, 0.0, lineProps.FirstLineProps, null, new TextRunCache()); Point origin = new Point(TextDpi.FromTextDpi(ur), TextDpi.FromTextDpi(vrBaseline) - textLine.Baseline); textLine.Draw(ctx, origin, flag ? InvertAxes.Horizontal : InvertAxes.None); textLine.Dispose(); } finally { this._host.Context = null; } }
/// <summary> /// Draw the screen and contents if the screen is visible. /// </summary> /// <param name="spritebatch">The sprite batch to use when drawing the screen.</param> public override void Draw(SpriteBatch spritebatch) { if (!Visible) { return; } base.Draw(spritebatch); // Draw the frames. spritebatch.Draw(mFrameHor, mFrameHorPos1, null, Color.White, 0.0f, Vector2.Zero, SpriteEffects.FlipVertically, 0.0f); spritebatch.Draw(mFrameHor, mFrameHorPos2, null, Color.White, 0.0f, Vector2.Zero, SpriteEffects.FlipVertically, 0.0f); spritebatch.Draw(mFrameVer, mFrameVerPos1, null, Color.White, 0.0f, Vector2.Zero, SpriteEffects.FlipVertically, 0.0f); spritebatch.Draw(mFrameVer, mFrameVerPos2, null, Color.White, 0.0f, Vector2.Zero, SpriteEffects.FlipVertically | SpriteEffects.FlipHorizontally, 0.0f); // Draw checkboxes. mChkFullscreen.Draw(spritebatch); mChkPlaySounds.Draw(spritebatch); mChkShowShapes.Draw(spritebatch); mChkShowHelpAim.Draw(spritebatch); // Draw texts. mSettingsTitle.Draw(spritebatch); mShortcutTitle.Draw(spritebatch); mInfoTitle.Draw(spritebatch); mInfoText1.Draw(spritebatch); mInfoText2.Draw(spritebatch); foreach (TextLine txt in mShortcutKeys) { txt.Draw(spritebatch); } // Draw buttons. foreach (Button btn in mButtons) { btn.Draw(spritebatch); } }
private void GenerateFormattedText(CustomTextSource textStore, DrawingContext dc, TextFormatter formatter) { int textStorePosition = 0; //Index into the text of the textsource Point linePosition = new Point(0, 0); //current line // Format each line of text from the text store and draw it. while (textStorePosition < textStore.Text.Length) { TextLine textLine = formatter.FormatLine(textStore, textStorePosition, textStore.ParagraphWidth, textStore.CTPProperties, null); // Draw the formatted text into the drawing context. textLine.Draw(dc, linePosition, InvertAxes.None); // Update the index position in the text store. textStorePosition += textLine.Length; // Update the line position coordinate for the displayed line. linePosition.Y += textLine.Height; } }
public void Render() { this.textSource.Text = this.Text; int textSourcePosition = 0; Point lineOrigin = new Point(0, 0); using (DrawingContext dc = base.RenderOpen()) { while (textSourcePosition < this.textSource.Text.Length) { using (TextLine textLine = this.textFormatter.FormatLine(this.textSource, textSourcePosition, 10, this.textParagraphProperties, null)) { textLine.Draw(dc, lineOrigin, InvertAxes.None); // 更新下一次要渲染的字符的索引 textSourcePosition += textLine.Length; // 更新下一次要渲染的字符的位置 lineOrigin.X += textLine.Width; //lineOrigin.Y += textLine.Height; } } } }
protected override void OnRender(DrawingContext drawingContext) { EnsureText(); line.Draw(drawingContext, new Point(0, 0), InvertAxes.None); }
private void Render(Point location, string colour) { int textStorePosition = 0; bool flipped; Position = location; if (ParentAtom == null) { flipped = false; } else { flipped = Flipped; } var textStore = new FunctionalGroupTextSource(ParentGroup, colour, flipped); //main textformatter - this does the writing of the visual using (TextFormatter textFormatter = TextFormatter.Create()) { //set up the default paragraph properties var paraprops = new FunctionalGroupTextSource.GenericTextParagraphProperties( FlowDirection.LeftToRight, TextAlignment.Left, true, false, new LabelTextRunProperties(colour), TextWrapping.NoWrap, GlyphText.SymbolSize, 0d); var anchorRuns = textStore.Runs.Where(f => f.IsAnchor); string anchorString = string.Empty; foreach (var run in anchorRuns) { anchorString += run.Text; } using (TextLine myTextLine = textFormatter.FormatLine(textStore, textStorePosition, 999, paraprops, null)) { IList <TextBounds> textBounds; Rect firstRect = Rect.Empty; if (!Flipped) //isolate them at the beginning { textBounds = myTextLine.GetTextBounds(0, anchorString.Length); } else { //isolate them at the end var start = myTextLine.Length - 1 - anchorString.Length; textBounds = myTextLine.GetTextBounds(start, anchorString.Length); } //add all the bounds together foreach (TextBounds anchorBound in textBounds) { firstRect.Union(anchorBound.Rectangle); } //center will be position close to the origin 0,0 Point center = new Point((firstRect.Left + firstRect.Right) / 2, (firstRect.Top + firstRect.Bottom) / 2); //the displacement vector will be added to each relative coordinate for the glyph run var displacementVector = location - center; //locus is where the text line is drawn var locus = new Point(0, 0) + displacementVector; textBounds = myTextLine.GetTextBounds(0, 999); var obb = textBounds[0].Rectangle; //draw the line of text using (DrawingContext dc = RenderOpen()) { myTextLine.Draw(dc, locus, InvertAxes.None); #if DEBUG #if SHOWBOUNDS obb.Offset(new Vector(locus.X, locus.Y)); dc.DrawRectangle(null, new Pen(new SolidColorBrush(Colors.BlueViolet), 1.0), obb); #endif #endif var glyphRuns = myTextLine.GetIndexedGlyphRuns(); List <Point> outline = new List <Point>(); double advanceWidths = 0d; //build up the convex hull from each glyph //you need to add in the advance widths for each //glyph run as they are traversed, //to the outline foreach (IndexedGlyphRun igr in glyphRuns) { var originalRun = textStore.GetTextRun(igr.TextSourceCharacterIndex); var currentRun = igr.GlyphRun; //need to work out how much the current run has been offset from the baseline var runBounds = myTextLine.GetTextBounds(igr.TextSourceCharacterIndex, igr.TextSourceLength); //get the bounding rect var rect = runBounds[0].TextRunBounds[0].Rectangle; //it's relative to the baseline //adjust it rect.Offset(new Vector(locus.X, locus.Y)); var rectCopy = rect; #if DEBUG #if SHOWBOUNDS dc.DrawRectangle(null, new Pen(new SolidColorBrush(Colors.DarkOrange), 1.0), rect); #endif #endif var runOutline = GlyphUtils.GetOutline(currentRun); //need to see if the run has been super or sub-scripted var variants = originalRun.Properties.TypographyProperties.Variants; if (variants == FontVariants.Subscript || variants == FontVariants.Superscript) { //simply union in the rect -it's easier! outline.AddRange(new[] { rectCopy.BottomLeft, rectCopy.BottomRight, rectCopy.TopLeft, rectCopy.TopRight }); } else { //add in the points from the convex hull for (int i = 0; i < runOutline.Count; i++) { var point = runOutline[i] + displacementVector + new Vector(0.0, myTextLine.Baseline); point.X += advanceWidths; runOutline[i] = point; } outline.AddRange(runOutline); } advanceWidths += currentRun.AdvanceWidths.Sum(); } _sortedOutline = (from Point p in outline orderby p.X ascending, p.Y descending select p).ToList(); Hull = Geometry <Point> .GetHull(_sortedOutline, p => p); // Diag: Show Hulls or Atom centres #if DEBUG #if SHOWHULLS dc.DrawGeometry(null, new Pen(Brushes.GreenYellow, thickness: 1), HullGeometry); #endif #if SHOWATOMCENTRES dc.DrawEllipse(Brushes.Red, null, ParentAtom.Position, 5, 5); #endif #endif // End Diag dc.Close(); } } } }
// Token: 0x06006868 RID: 26728 RVA: 0x001D6FA4 File Offset: 0x001D51A4 internal ContainerVisual CreateVisual() { LineVisual lineVisual = new LineVisual(); this._host.Context = this; try { IList <TextSpan <TextRun> > list = this._runs; TextLine textLine = this._line; if (this._line.HasOverflowed && this.TextParagraph.Properties.TextTrimming != TextTrimming.None) { textLine = this._line.Collapse(new TextCollapsingProperties[] { this.GetCollapsingProps(this._wrappingWidth, this.TextParagraph.Properties) }); Invariant.Assert(textLine.HasCollapsed, "Line has not been collapsed"); list = textLine.GetTextRunSpans(); } if (this.HasInlineObjects()) { VisualCollection children = lineVisual.Children; DependencyObject element = this._paraClient.Paragraph.Element; FlowDirection parentFD = (FlowDirection)element.GetValue(FrameworkElement.FlowDirectionProperty); int num = this._dcp; foreach (TextSpan <TextRun> textSpan in list) { TextRun value = textSpan.Value; if (value is InlineObjectRun) { InlineObjectRun inlineObjectRun = (InlineObjectRun)value; FlowDirection flowDirection; Rect boundsFromPosition = this.GetBoundsFromPosition(num, value.Length, out flowDirection); Visual visual = VisualTreeHelper.GetParent(inlineObjectRun.UIElementIsland) as Visual; if (visual != null) { ContainerVisual containerVisual = visual as ContainerVisual; Invariant.Assert(containerVisual != null, "Parent should always derives from ContainerVisual."); containerVisual.Children.Remove(inlineObjectRun.UIElementIsland); } if (!textLine.HasCollapsed || boundsFromPosition.Left + inlineObjectRun.UIElementIsland.Root.DesiredSize.Width < textLine.Width) { if (inlineObjectRun.UIElementIsland.Root is FrameworkElement) { DependencyObject parent = ((FrameworkElement)inlineObjectRun.UIElementIsland.Root).Parent; FlowDirection childFD = (FlowDirection)parent.GetValue(FrameworkElement.FlowDirectionProperty); PtsHelper.UpdateMirroringTransform(parentFD, childFD, inlineObjectRun.UIElementIsland, boundsFromPosition.Width); } children.Add(inlineObjectRun.UIElementIsland); inlineObjectRun.UIElementIsland.Offset = new Vector(boundsFromPosition.Left, boundsFromPosition.Top); } } num += textSpan.Length; } } double x = TextDpi.FromTextDpi(this.CalculateUOffsetShift()); DrawingContext drawingContext = lineVisual.Open(); textLine.Draw(drawingContext, new Point(x, 0.0), this._mirror ? InvertAxes.Horizontal : InvertAxes.None); drawingContext.Close(); lineVisual.WidthIncludingTrailingWhitespace = textLine.WidthIncludingTrailingWhitespace - this._indent; } finally { this._host.Context = null; } return(lineVisual); }