/// <inheritdoc /> public override void OnRender(IDrawingContext context, Themes.Color backColor, Themes.Color foreColor, MainMenu mainMenu, int itemAreaWidth) { var firstArea = $"{(Checked ? Application.Environment.GetCheckStateChar(CheckState.Checked) : ' ')}"; context.DrawText(firstArea, backColor, foreColor); var textContentLength = mainMenu.DrawMenuItem(this, context, backColor, foreColor); if (ShowShortcut && !Items.Any()) { var shortcutText = Shortcut?.ToString() ?? string.Empty; context.DrawText((shortcutText + " ") .PadLeft(itemAreaWidth - firstArea.Length - textContentLength - (Text.IndexOf('&') > -1 ? 0 : 2)), backColor, foreColor); } if (Items.Any()) { context.DrawText(Application.Environment.MenuSubItemsMarker .ToString() .PadLeft(itemAreaWidth - firstArea.Length - textContentLength - (Text.IndexOf('&') > -1 ? 0 : 2)), backColor, foreColor); } }
internal static int DrawMenuItem(this MainMenu mainMenu, MenuItemBase item, IDrawingContext context, Color backColor, Color foreColor) { if (item.Text.IndexOf('&') == -1 || !item.Enabled) { context.DrawText($" {item.Text.Replace("&", string.Empty)} ", item.Enabled ? backColor : mainMenu.DisabledBackground, item.Enabled ? foreColor : mainMenu.DisabledForeground); return(item.Text.Length); } var leftText = " " + item.Text.Substring(0, item.Text.IndexOf('&')); var middleText = item.Text.Substring(item.Text.IndexOf('&') + 1, 1); var rightText = item.Text.Substring(item.Text.IndexOf('&') + 2) + " "; context.DrawText(leftText, backColor, foreColor); context.DrawText(middleText, backColor, mainMenu.MnemonicForeground); context.DrawText(rightText, backColor, foreColor); return(leftText.Length + middleText.Length + rightText.Length); }
internal void OnRender(IDrawingContext context) { if (borderThickness.Top > 0) { context.SetCursorPos(borderThickness.Left - 1, borderThickness.Top - 1); var topStr = borderChars.TopLeft + (context.ContextBounds.Width - borderThickness.Horizontal > 0 ? new string(borderChars.TopMiddle, context.ContextBounds.Width - borderThickness.Horizontal) : string.Empty) + borderChars.TopRight; context.DrawText(topStr, borderColor); } if (!string.IsNullOrWhiteSpace(text)) { var presenterText = text.Length > context.ContextBounds.Width - borderThickness.Horizontal ? text.Substring(0, context.ContextBounds.Width - borderThickness.Horizontal - 1) + "…" : text; DrawHeaderText(context, presenterText, TextArea.X, TextArea.Y); } for (var row = borderThickness.Top; row < context.ContextBounds.Height - borderThickness.Bottom; row++) { if (borderThickness.Left > 0) { context.SetCursorPos(borderThickness.Left - 1, row); context.DrawText(borderChars.MiddleLeft, borderColor); } if (borderThickness.Right > 0) { context.SetCursorPos(context.ContextBounds.Width - borderThickness.Right, row); context.DrawText(borderChars.MiddleRight, borderColor); } } if (borderThickness.Bottom > 0) { context.SetCursorPos(borderThickness.Left - 1, context.ContextBounds.Height - borderThickness.Bottom); var bottomStr = borderChars.BottomLeft + (context.ContextBounds.Width - borderThickness.Horizontal > 0 ? new string(borderChars.BottomMiddle, context.ContextBounds.Width - borderThickness.Horizontal) : string.Empty) + borderChars.BottomRight; context.DrawText(bottomStr, borderColor); } }
/// <inheritdoc /> protected override void OnRender(IDrawingContext context) { base.OnRender(context); for (var i = 0; i < items.Count; i++) { if (items[i] is SeparatorMenuItem) { context.SetCursorPos(BorderThickness.Left - 1, BorderThickness.Top + i); context.DrawText(Application.Environment.MenuSeparatorLeftBorder, BorderColor); context.SetCursorPos(context.ContextBounds.Width - BorderThickness.Right, BorderThickness.Top + i); context.DrawText(Application.Environment.MenuSeparatorRightBorder, BorderColor); } } }
public override void Render(IDrawingContext context) { Rect rect = new Rect(this.ActualSize); context.DrawText(Brushes.Black, rect, this.FormattedText); if (this.parent.IsFocused) { ITextService textService = Locator.Current.GetService <ITextService>(); Point caretPos = textService.GetCaretPosition( this.formattedText, this.parent.CaretIndex, this.ActualSize); double[] lineHeights = textService.GetLineHeights(this.formattedText, this.ActualSize); Brush caretBrush = Brushes.Black; if (this.caretBlink) { context.DrawLine( new Pen(caretBrush, 1), caretPos, new Point(caretPos.X, caretPos.Y + lineHeights[0])); } } }
public override void DrawString(string str, RFont font, RColor color, RPoint point, RSize size, bool rtl) { var text = GetText(str, font); text.Constraint = Util.Convert(size); _g.DrawText(new SolidColorBrush(Util.Convert(color)), Util.Convert(point), text); }
public override void Render(IDrawingContext context) { double range = this.Bounds.Width/(MaxValue - MinValue); Pen backgroundPen = new Pen(Brushes.Black, 5); Brush TextBrush = Brushes.Black; double step = 0.5; int countValue = (int) (range / step); double stepX = this.Bounds.Width/countValue; for (int i = 0; i < countValue; i++) { var x = i* stepX; // context.DrawLine(backgroundPen, new Point(x, 0), new Point(x, this.Bounds.Height)); context.DrawText(TextBrush, new Point(x, 2),new FormattedText((i*step).ToString(), "Verdana", 22,FontStyle.Normal, TextAlignment.Center,FontWeight.Normal)); } //context.DrawLine(foreground, new Point(100, 100), new Point(200, 200)); /* var AxisMajorBrush = Brushes.Black; context.DrawRectange(new Pen(AxisMajorBrush,2),new Rect(new Point(10, 0), new Point(10, Height))); var borderBrush = Brushes.AliceBlue; var borderThickness = 3; var cornerRadius = 2; var rect = new Rect(Bounds.Size).Deflate(new Thickness(borderThickness)); context.FillRectange(backgroundPen.Brush, rect, cornerRadius); if (borderBrush != null && borderThickness > 0) { context.DrawRectange(new Pen(borderBrush, borderThickness), rect, cornerRadius); }*/ }
/// <inheritdoc /> public override void OnRender(IDrawingContext context, Color backColor, Color foreColor, MainMenu mainMenu, int itemAreaWidth) => context.DrawText( new string(Application.Environment.MenuSeparatorBorder, itemAreaWidth), backColor, mainMenu.Foreground);
internal static void OnRender(Control targetControl, IDrawingContext context, Rect reducedArea, ICollection items, int startRenderedItemIndex) { var shouldScrollBar = reducedArea.Height < items.Count; var scrollArea = reducedArea.Height - 2; if (shouldScrollBar && scrollArea > 0) { var scrollHeight = Math.Max((scrollArea * (scrollArea * 100 / items.Count)) / 100, 1); var scrollTopOffset = ((startRenderedItemIndex * scrollArea) / items.Count) + 1; if (startRenderedItemIndex > 0 && scrollTopOffset == 1) { scrollTopOffset = 2; } if (startRenderedItemIndex + reducedArea.Height >= items.Count) { scrollTopOffset = reducedArea.Height - 1 - scrollHeight; } for (var row = 0; row < reducedArea.Height; row++) { context.SetCursorPos(targetControl.Padding.Left + reducedArea.Width - 1, targetControl.Padding.Top + row); if (row == 0 || row == reducedArea.Height - 1) { context.DrawText(row == 0 ? '▴' : '▾', Application.SystemColors.ScrollBackground, Application.SystemColors.ScrollForeground); } else { if (row >= scrollTopOffset && row <= scrollTopOffset + scrollHeight) { context.DrawText('▓', targetControl.Background, Application.SystemColors.ScrollBackground); } else { context.DrawText('╽', targetControl.Background, Application.SystemColors.ScrollBackground); } } } } }
public override void Render(IDrawingContext drawingContext) { if (Text == null) { return; } drawingContext.DrawText(FormattedText, VisualBounds.Point); }
public override void Render(IDrawingContext context) { Brush background = this.Background; if (background != null) { context.FillRectange(background, new Rect(this.ActualSize)); } context.DrawText(this.Foreground, new Point(), this.FormattedText); }
/// <summary> /// Renders the <see cref="TextBlock"/> to a drawing context. /// </summary> /// <param name="context">The drawing context.</param> public override void Render(IDrawingContext context) { Brush background = Background; if (background != null) { context.FillRectange(background, new Rect(Bounds.Size)); } FormattedText.Constraint = Bounds.Size; context.DrawText(Foreground, new Point(), FormattedText); }
/// <inheritdoc cref="ButtonBase.OnRender"/> protected override void OnRender(IDrawingContext context) { base.OnRender(context); var reducedArea = context.ContextBounds.Reduce(Padding); if (!reducedArea.HasEmptyDimension() || string.IsNullOrWhiteSpace(GetTextPresenter())) { context.SetCursorPos(RenderTextPosition.X + Padding.Left, RenderTextPosition.Y + Padding.Top); var foreColor = IsDisabled ? DisabledForeground : owner.MnemonicForeground; context.DrawText(StatusBarShortcutKey.ToString(), foreColor); foreColor = IsDisabled ? DisabledForeground : Foreground; context.DrawText($" {Text}", foreColor); } }
protected override void OnRender(IDrawingContext drawingContext) { if (this.Background != null) { drawingContext.DrawRectangle(new Rect(0, 0, this.ActualWidth, this.ActualHeight), this.Background); } drawingContext.DrawText( this.spriteFont, this.formattedText, new Point(this.Padding.Left, this.Padding.Top), this.Foreground ?? new SolidColorBrush(Colors.Black)); }
protected override void OnRender(IDrawingContext context, Rect bounds, double opacity) { base.OnRender(context, bounds, opacity); TextBlock textBlock = WpfElement as TextBlock; DrawingStyle style = DrawingStyle.FromElement(this); style.Fill = textBlock.Foreground; style.FontFamily = textBlock.FontFamily; style.FontSize = textBlock.FontSize; style.FontStyle = textBlock.FontStyle; style.FontWeight = textBlock.FontWeight; style.Opacity = opacity; context.DrawText(bounds, textBlock.Text, style); }
/// <inheritdoc cref="GroupBase.DrawHeaderText"/> internal override void DrawHeaderText(IDrawingContext context, string presenterText, int x, int y) { var foreColor = ownerListView.IsDisabled ? ownerListView.DisabledForeground : ownerListView.IsFocus ? ownerListView.FocusForeground : ownerListView.Foreground; var backColor = ownerListView.IsDisabled ? ownerListView.DisabledBackground : ownerListView.IsFocus ? ownerListView.FocusBackground : ownerListView.Background; context.SetCursorPos(x, y); context.DrawText(presenterText, backColor, foreColor); }
/// <summary> /// Draws text containing sub- and superscript. /// </summary> /// <param name="renderer">The render context.</param> /// <param name="point">The point.</param> /// <param name="color">Color of the text.</param> /// <param name="text">The text.</param> /// <param name="fontFamily">The font family.</param> /// <param name="fontSize">The font size.</param> /// <param name="fontWeight">The font weight.</param> /// <param name="hAlign">The horizontal alignment.</param> /// <param name="vAlign">The vertical alignment.</param> /// <param name="isHitTestVisible"><c>true</c> if hit testing should be enabled, <c>false</c> otherwise. The default is <c>false</c>.</param> /// <returns>The size of the text.</returns> /// <example>Subscript: H_{2}O /// Superscript: E=mc^{2} /// Both: A^{2}_{i,j}</example> public static void DrawMathText(this IDrawingContext renderer, Point point, Color color, string text, FontFamily fontFamily, double fontSize, FontWeight fontWeight, HorizontalAlignment hAlign = HorizontalAlignment.Left, VerticalAlignment vAlign = VerticalAlignment.Top, bool isHitTestVisible = false) { if (string.IsNullOrEmpty(text)) { return; } if (text.Contains("^{") || text.Contains("_{")) { var x = point.X; var y = point.Y; InternalDrawMathText(renderer, x, y, color, text, fontFamily, fontSize, fontWeight, isHitTestVisible); } else { renderer.DrawText(point, color, text, fontFamily, fontSize, fontWeight, hAlign, vAlign, isHitTestVisible); } }
/// <inheritdoc /> protected override void OnRenderItemInternal(IDrawingContext context, T item, int itemAreaWidth) { var itemText = GetItemText(item); var drawingText = itemText.Substring(0, Math.Min(itemAreaWidth, itemText.Length)); var backColor = GetRenderBackColor(); var foreColor = GetRenderForeColor(); if (SelectedItems.Contains(item)) { backColor = IsDisabled ? DisabledForeground : SelectedBackground; foreColor = IsDisabled ? DisabledBackground : SelectedForeground; } context.DrawText(TextHelper.GetTextWithAlignment(drawingText, itemAreaWidth, TextAlignment), backColor, foreColor); }
protected override void OnContentRender(IDrawingContext context) { if (focusedIndex == -1) { var visibleItems = chunks.AllList; var firstElement = visibleItems.FirstOrDefault(x => !x.IsDisabled); if (firstElement != null) { focusedIndex = visibleItems.IndexOf(firstElement); } } var renderArea = new Rect(context.ContextBounds.Size) .Reduce(BorderThickness) .Reduce(Padding); var leftIndent = renderArea.Left + (renderArea.Width - contentSize.Width) / 2; var topIndent = renderArea.Top + (renderArea.Height - contentSize.Height) / 2; for (var col = 0; col < chunks.Count; col++) { var items = chunks[col].ToList(); for (var i = 0; i < items.Count; i++) { if (!renderArea.Contains(leftIndent, topIndent + i)) { break; } var foreColor = IsDisabled || items[i].IsDisabled ? DisabledForeground : IsFocus && Items.IndexOf(items[i]) == focusedIndex ? FocusForeground : Foreground; context.SetCursorPos(leftIndent, topIndent + i); context.DrawText($"{GetGlyph(selectedItems.Contains(items[i]))} {items[i].Text}", foreColor); } leftIndent += items.Max(x => x.Text.Length) + ContentMeasureItemIndent * 2; } }
public void Render(LayoutInformation layout, ILayoutContext layoutContext, IDrawingContext drawingContext) { Point renderLocation = Location.Resolve(layout, layoutContext.Options); TextAlignment tempAlignment = Alignment; var flipType = layout.GetFlipType(); if ((flipType & FlipType.Horizontal) == FlipType.Horizontal) { switch (Alignment) { case TextAlignment.BottomLeft: tempAlignment = TextAlignment.BottomRight; break; case TextAlignment.BottomRight: tempAlignment = TextAlignment.BottomLeft; break; case TextAlignment.CentreLeft: tempAlignment = TextAlignment.CentreRight; break; case TextAlignment.CentreRight: tempAlignment = TextAlignment.CentreLeft; break; case TextAlignment.TopLeft: tempAlignment = TextAlignment.TopRight; break; case TextAlignment.TopRight: tempAlignment = TextAlignment.TopLeft; break; } } if ((flipType & FlipType.Vertical) == FlipType.Vertical) { switch (Alignment) { case TextAlignment.BottomCentre: tempAlignment = TextAlignment.TopCentre; break; case TextAlignment.BottomLeft: tempAlignment = TextAlignment.TopLeft; break; case TextAlignment.BottomRight: tempAlignment = TextAlignment.TopRight; break; case TextAlignment.TopCentre: tempAlignment = TextAlignment.BottomCentre; break; case TextAlignment.TopLeft: tempAlignment = TextAlignment.BottomLeft; break; case TextAlignment.TopRight: tempAlignment = TextAlignment.BottomRight; break; } } List <TextRun> renderTextRuns = new List <TextRun>(TextRuns.Count); // Build runs foreach (TextRun run in TextRuns) { // Resolve value string renderValue; if (run.Text.StartsWith("$")) { renderValue = layoutContext.GetFormattedVariable(run.Text); } else { renderValue = run.Text; } System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(@"\\[uU]([0-9A-F]{4})"); renderValue = regex.Replace(renderValue, match => ((char)int.Parse(match.Value.Substring(2), System.Globalization.NumberStyles.HexNumber)).ToString()); renderTextRuns.Add(new TextRun(renderValue, run.Formatting)); } if (layoutContext.Options.Absolute) { drawingContext.DrawText(Point.Add(renderLocation, layout.Location), tempAlignment, (int)Rotation * 90, renderTextRuns); } else { drawingContext.DrawText(renderLocation, tempAlignment, (int)Rotation * 90, renderTextRuns); } }
/// <summary> /// Draws text with sub- and superscript items. /// </summary> /// <param name="renderer">The render context.</param> /// <param name="x">The x.</param> /// <param name="y">The y.</param> /// <param name="s">The s.</param> /// <param name="color">The text color.</param> /// <param name="fontFamily">The font family.</param> /// <param name="fontSize">The font size.</param> /// <param name="fontWeight">The font weight.</param> /// <param name="isHitTestVisible"><c>true</c> if hit testing should be enabled, <c>false</c> otherwise. The default is <c>false</c>.</param> /// <returns>The size of the text.</returns> private static void InternalDrawMathText(IDrawingContext renderer, double x, double y, Color color, string s, FontFamily fontFamily, double fontSize, FontWeight fontWeight, bool isHitTestVisible) { var i = 0; var currentX = x; var maximumX = x; var currentY = y; // http://en.wikipedia.org/wiki/Subscript_and_superscript var superScriptYDisplacement = fontSize * SuperAlignment; var subscriptYDisplacement = fontSize * SubAlignment; var superscriptFontSize = fontSize * SuperSize; var subscriptFontSize = fontSize * SubSize; Func <double, double, string, double, Size> drawText = (xb, yb, text, fSize) => { renderer.DrawText(new Point(xb, yb), color, text, fontFamily, fSize, fontWeight, isHitTestVisible: isHitTestVisible); var flatSize = renderer.MeasureText(text, fontFamily, fSize, fontWeight); return(new Size(flatSize.Width, flatSize.Height)); }; while (i < s.Length) { // Superscript if (i + 1 < s.Length && s[i] == '^' && s[i + 1] == '{') { var i1 = s.IndexOf('}', i); if (i1 != -1) { var supString = s.Substring(i + 2, i1 - i - 2); i = i1 + 1; var sx = currentX; var sy = currentY + superScriptYDisplacement; var size = drawText(sx, sy, supString, superscriptFontSize); maximumX = Math.Max(sx + size.Width, maximumX); continue; } } // Subscript if (i + 1 < s.Length && s[i] == '_' && s[i + 1] == '{') { var i1 = s.IndexOf('}', i); if (i1 != -1) { var subString = s.Substring(i + 2, i1 - i - 2); i = i1 + 1; var sx = currentX; var sy = currentY + subscriptYDisplacement; var size = drawText(sx, sy, subString, subscriptFontSize); maximumX = Math.Max(sx + size.Width, maximumX); continue; } } // Regular text var i2 = s.IndexOfAny("^_".ToCharArray(), i + 1); string regularString; if (i2 == -1) { regularString = s.Substring(i); i = s.Length; } else { regularString = s.Substring(i, i2 - i); i = i2; } currentX = maximumX + 2; var size2 = drawText(currentX, currentY, regularString, fontSize); maximumX = Math.Max(currentX + size2.Width, maximumX); currentX = maximumX; } }
public void DrawText(Point anchor, TextAlignment alignment, IList <TextRun> textRuns) { double totalWidth = 0.0; double height = 0.0; foreach (var textRun in textRuns) { var size = MeasureText(textRun); totalWidth += size.Width; height = Math.Max(height, size.Height); } double topLeftX; switch (alignment) { case TextAlignment.TopLeft: case TextAlignment.CentreLeft: case TextAlignment.BottomLeft: topLeftX = anchor.X; break; case TextAlignment.TopCentre: case TextAlignment.CentreCentre: case TextAlignment.BottomCentre: topLeftX = anchor.X - totalWidth / 2; break; case TextAlignment.TopRight: case TextAlignment.CentreRight: case TextAlignment.BottomRight: topLeftX = anchor.X - totalWidth; break; default: throw new InvalidOperationException($"Missing case for {alignment}"); } double topLeftY; switch (alignment) { case TextAlignment.TopLeft: case TextAlignment.TopCentre: case TextAlignment.TopRight: topLeftY = anchor.Y; break; case TextAlignment.CentreLeft: case TextAlignment.CentreCentre: case TextAlignment.CentreRight: topLeftY = anchor.Y - height / 2; break; case TextAlignment.BottomLeft: case TextAlignment.BottomCentre: case TextAlignment.BottomRight: topLeftY = anchor.Y - height; break; default: throw new InvalidOperationException($"Missing case for {alignment}"); } var topLeft = new Point(topLeftX, topLeftY); Expand(new Rect(topLeft, new Size(totalWidth, height))); underlying?.DrawText(anchor, alignment, textRuns); underlying?.DrawRectangle(topLeft, new Size(totalWidth, height), 1.0); }
public static bool RenderFromXml(Stream xmlStream, IDrawingContext drawingContext, out Size imageSize) { var doc = XDocument.Load(xmlStream); var previewNode = doc.Elements().First(x => x.Name == PreviewNamespace + "preview"); imageSize = new Size(double.Parse(previewNode.Attribute("width").Value), double.Parse(previewNode.Attribute("height").Value)); var renderElements = previewNode.Elements(); foreach (var renderElement in renderElements) { if (renderElement.Name == "line") { Point start = Point.Parse(renderElement.Attribute("start").Value); Point end = Point.Parse(renderElement.Attribute("end").Value); double thickness = double.Parse(renderElement.Attribute("thickness").Value); drawingContext.DrawLine(start, end, thickness); } else if (renderElement.Name == "rect") { Point start = Point.Parse(renderElement.Attribute("start").Value); Size size = Size.Parse(renderElement.Attribute("size").Value); double thickness = double.Parse(renderElement.Attribute("thickness").Value); bool fill = bool.Parse(renderElement.Attribute("fill").Value); drawingContext.DrawRectangle(start, size, thickness, fill); } else if (renderElement.Name == "ellipse") { Point centre = Point.Parse(renderElement.Attribute("centre").Value); double radiusx = double.Parse(renderElement.Attribute("rx").Value); double radiusy = double.Parse(renderElement.Attribute("ry").Value); double thickness = double.Parse(renderElement.Attribute("thickness").Value); bool fill = bool.Parse(renderElement.Attribute("fill").Value); drawingContext.DrawEllipse(centre, radiusx, radiusy, thickness, fill); } else if (renderElement.Name == "path") { Point start = Point.Parse(renderElement.Attribute("start").Value); double thickness = double.Parse(renderElement.Attribute("thickness").Value); bool fill = bool.Parse(renderElement.Attribute("fill").Value); string data = renderElement.Value; List <IPathCommand> pathCommands = new List <IPathCommand>(); using (MemoryStream dataStream = new MemoryStream(Convert.FromBase64String(data))) { BinaryReader reader = new BinaryReader(dataStream); int numCommands = reader.ReadInt32(); for (int l = 0; l < numCommands; l++) { CommandType pType = (CommandType)reader.ReadInt32(); IPathCommand theCommand = null; switch (pType) { case CommandType.MoveTo: theCommand = new MoveTo(); break; case CommandType.LineTo: theCommand = new LineTo(); break; case CommandType.CurveTo: theCommand = new CurveTo(); break; case CommandType.EllipticalArcTo: theCommand = new EllipticalArcTo(); break; case CommandType.QuadraticBeizerCurveTo: theCommand = new QuadraticBeizerCurveTo(); break; case CommandType.SmoothCurveTo: theCommand = new SmoothCurveTo(); break; case CommandType.SmoothQuadraticBeizerCurveTo: theCommand = new SmoothQuadraticBeizerCurveTo(); break; default: theCommand = new ClosePath(); break; } theCommand.Read(reader); pathCommands.Add(theCommand); } } drawingContext.DrawPath(start, pathCommands, thickness, fill); } else if (renderElement.Name == "text") { Point anchor = Point.Parse(renderElement.Attribute("anchor").Value); TextAlignment alignment = (TextAlignment)Enum.Parse(typeof(TextAlignment), renderElement.Attribute("alignment").Value); List <TextRun> runs = new List <TextRun>(); foreach (var runNode in renderElement.Elements()) { if (runNode.Name != "run") { continue; } double size = double.Parse(runNode.Attribute("size").Value); TextRunFormattingType formattingType = (TextRunFormattingType)Enum.Parse(typeof(TextRunFormattingType), runNode.Attribute("formatting").Value); string text = runNode.Value; runs.Add(new TextRun(text, new TextRunFormatting(formattingType, size))); } drawingContext.DrawText(anchor, alignment, runs); } } return(true); }
/// <summary> /// Draws text with sub- and superscript items. /// </summary> /// <param name="renderer">The render context.</param> /// <param name="x">The x.</param> /// <param name="y">The y.</param> /// <param name="s">The s.</param> /// <param name="color">The text color.</param> /// <param name="fontFamily">The font family.</param> /// <param name="fontSize">The font size.</param> /// <param name="fontWeight">The font weight.</param> /// <param name="isHitTestVisible"><c>true</c> if hit testing should be enabled, <c>false</c> otherwise. The default is <c>false</c>.</param> /// <returns>The size of the text.</returns> private static void InternalDrawMathText(IDrawingContext renderer, double x, double y, Color color, string s, FontFamily fontFamily, double fontSize, FontWeight fontWeight, bool isHitTestVisible) { var i = 0; var currentX = x; var maximumX = x; var currentY = y; // http://en.wikipedia.org/wiki/Subscript_and_superscript var superScriptYDisplacement = fontSize * SuperAlignment; var subscriptYDisplacement = fontSize * SubAlignment; var superscriptFontSize = fontSize * SuperSize; var subscriptFontSize = fontSize * SubSize; Func<double, double, string, double, Size> drawText = (xb, yb, text, fSize) => { renderer.DrawText(new Point(xb, yb), color, text, fontFamily, fSize, fontWeight, isHitTestVisible: isHitTestVisible); var flatSize = renderer.MeasureText(text, fontFamily, fSize, fontWeight); return new Size(flatSize.Width, flatSize.Height); }; while (i < s.Length) { // Superscript if (i + 1 < s.Length && s[i] == '^' && s[i + 1] == '{') { var i1 = s.IndexOf('}', i); if (i1 != -1) { var supString = s.Substring(i + 2, i1 - i - 2); i = i1 + 1; var sx = currentX; var sy = currentY + superScriptYDisplacement; var size = drawText(sx, sy, supString, superscriptFontSize); maximumX = Math.Max(sx + size.Width, maximumX); continue; } } // Subscript if (i + 1 < s.Length && s[i] == '_' && s[i + 1] == '{') { var i1 = s.IndexOf('}', i); if (i1 != -1) { var subString = s.Substring(i + 2, i1 - i - 2); i = i1 + 1; var sx = currentX; var sy = currentY + subscriptYDisplacement; var size = drawText(sx, sy, subString, subscriptFontSize); maximumX = Math.Max(sx + size.Width, maximumX); continue; } } // Regular text var i2 = s.IndexOfAny("^_".ToCharArray(), i + 1); string regularString; if (i2 == -1) { regularString = s.Substring(i); i = s.Length; } else { regularString = s.Substring(i, i2 - i); i = i2; } currentX = maximumX + 2; var size2 = drawText(currentX, currentY, regularString, fontSize); maximumX = Math.Max(currentX + size2.Width, maximumX); currentX = maximumX; } }
internal virtual void DrawHeaderText(IDrawingContext context, string presenterText, int x, int y) { context.SetCursorPos(x, y); context.DrawText(presenterText, borderColor); }
public bool NextDraw(Point pt, IDrawingContext dc, bool isFinal) { Points[1] = pt; double radius = Math.Atan((Points[1].X - Points[0].X) / (Points[0].Y - Points[1].Y)); double degree = radius * 180 / Math.PI; if (degree < 0) { if (Points[1].X > Points[0].X) { degree = 180 + degree; } } else { if (Points[1].X < Points[0].X) { degree = 180 + degree; } } IPen pen = DrawingObjectFactory.CreatePen(MeasureColor, MeasureThickness); if (MeasureDashes != null) { pen.Dashes = MeasureDashes; } //Trace.WriteLine(radius + "," + degree); RotateTransform transferm = new RotateTransform() { Angle = degree, CenterX = Points[0].X, CenterY = Points[0].Y }; dc.PushTransform(transferm); Point pt1 = new Point(Points[0].X + 3, Points[0].Y); Point pt2 = new Point(Points[0].X - 3, Points[0].Y); dc.DrawLine(pen, pt1, pt2); double value = -Math.Sqrt(Math.Abs(Points[0].X - Points[1].X) * Math.Abs(Points[0].X - Points[1].X) + Math.Abs(Points[0].Y - Points[1].Y) * Math.Abs(Points[0].Y - Points[1].Y)); Point pt3 = new Point(Points[0].X, Points[0].Y + value); dc.DrawLine(pen, Points[0], pt3); pt1 = new Point(Points[0].X + 3, Points[0].Y + value); pt2 = new Point(Points[0].X - 3, Points[0].Y + value); dc.DrawLine(pen, pt1, pt2); dc.Pop(); ITextFormat format = DrawingObjectFactory.CreateTextFormat(measureValue.ToString("P2"), FlowDirection, FontFamily, FontStyle, FontWeight, FontStretch, FontSize, Foreground); Point ptText = Points[1]; ptText.Y -= format.Height; dc.DrawText(format, ptText); return(false); }
public void DrawText(Point anchor, TextAlignment alignment, IList <TextRun> textRuns) { underlying.DrawText(anchor.Add(offset), alignment, textRuns); }
public override void OnRender(IDrawingContext context) { context.DrawText(Location, Text, FontColor); }