protected TextSprite(string name) : base() { _name = name; _hAlign = TextHorizontalAlignment.Left; _vAlign = TextVerticalAlignment.Center; }
/// <summary> /// Gets the hash code /// </summary> /// <returns>Hash code</returns> public override int GetHashCode() { unchecked // Overflow is fine, just wrap { int hashCode = 41; hashCode = hashCode * 59 + TextVerticalAlignment.GetHashCode(); hashCode = hashCode * 59 + TextHorizontalAlignment.GetHashCode(); if (Text != null) { hashCode = hashCode * 59 + Text.GetHashCode(); } if (TextColor != null) { hashCode = hashCode * 59 + TextColor.GetHashCode(); } if (FontName != null) { hashCode = hashCode * 59 + FontName.GetHashCode(); } hashCode = hashCode * 59 + StandardFontName.GetHashCode(); hashCode = hashCode * 59 + FontStyle.GetHashCode(); hashCode = hashCode * 59 + FontSize.GetHashCode(); return(hashCode); } }
private void ForGlyph <T>(CommandList commandList, ref StringProxy text, ref Vector2 fontSize, GlyphAction <T> action, ref T parameters, int forStart, int forEnd, bool updateGpuResources, float startX = 0, float startY = 0, TextVerticalAlignment vertAlign = TextVerticalAlignment.Top, float fontSizeY = 0f) { var key = 0; var x = startX; var y = startY; // tag management var escaping = false; colorStack.Clear(); for (var i = forStart; i < forEnd; i++) { var character = text[i]; if (!escaping && character == '<') { // check tags if (CheckAndProcessColorTag(ref text, ref i, out Color4 color)) { colorStack.Push(color); } else if (colorStack.Count > 0 && EndsTag("</color>", ref text, ref i)) { colorStack.Pop(); } }
private void AppendAlignment(W.TableCell cell, TextVerticalAlignment alignment) { TableVerticalAlignmentValues al = TableVerticalAlignmentValues.Center; switch (alignment) { case TextVerticalAlignment.Top: al = TableVerticalAlignmentValues.Top; break; case TextVerticalAlignment.Center: al = TableVerticalAlignmentValues.Center; break; case TextVerticalAlignment.Bottom: al = TableVerticalAlignmentValues.Bottom; break; } cell.TableCellProperties.Append( new W.TableCellVerticalAlignment() { Val = al } ); }
internal BitmapGeometry(Bitmap bitmap, double width, double height, TextVerticalAlignment alignment) : base(width, height, height, alignment, false) { this.Bitmap = bitmap; this.Width = width; this.Height = height; }
/// <summary> /// Initializes a new instance of the <see cref="Text" /> class. /// </summary> /// <param name="text">Text that will be drawn.</param> /// <param name="font">Font that will be used to draw the text.</param> /// <param name="foreground">Brush that will be used to paint the text.</param> /// <param name="background">Brush that will be used to paint the text's background.</param> /// <param name="left">Left position of the text.</param> /// <param name="top">Top position of the text.</param> /// <param name="width">Virtual text box width. If value is less than 0, it will be automatically computed.</param> /// <param name="height">Virtual text box height. If value is less than 0, it will be automatically computed.</param> /// <param name="horizontalAlignment">Text horizontal alignment.</param> /// <param name="verticalAlignment">Text vertical alignment.</param> /// <param name="wrapping">Text wrapping.</param> /// <param name="rotation">Text clockwise rotation in radians.</param> public Text(string text, IFont font, IBrush foreground, IBrush background, double left, double top, double width, double height, TextHorizontalAlignment horizontalAlignment, TextVerticalAlignment verticalAlignment, TextWrapping wrapping, double rotation) { Label = text; Font = font; Background = background; Foreground = foreground; Width = width; Height = height; HorizontalAlignment = horizontalAlignment; VerticalAlignment = verticalAlignment; Wrapping = wrapping; Rotation = rotation; System.Windows.FontStyle fontStyle; switch (font.Style) { default: case FontStyle.Normal: fontStyle = System.Windows.FontStyles.Normal; break; case FontStyle.Italic: fontStyle = System.Windows.FontStyles.Italic; break; case FontStyle.Oblique: fontStyle = System.Windows.FontStyles.Oblique; break; } UIText = new System.Windows.Controls.TextBlock() { Text = text, HorizontalAlignment = (System.Windows.HorizontalAlignment)horizontalAlignment, VerticalAlignment = (System.Windows.VerticalAlignment)((int)verticalAlignment - 1), Foreground = (foreground as Brush)?.UIBrush, Background = (background as Brush)?.UIBrush, FontFamily = new System.Windows.Media.FontFamily(font.Family), FontSize = font.Size, FontStyle = fontStyle, FontWeight = System.Windows.FontWeight.FromOpenTypeWeight((int)font.Weight), TextWrapping = (System.Windows.TextWrapping)((int)wrapping + 1), }; if (width >= 0) { UIText.Width = width; } if (height >= 0) { UIText.Height = height; } if (rotation != 0) { UIText.RenderTransform = new System.Windows.Media.RotateTransform(rotation * 180 / Math.PI); UIText.RenderTransformOrigin = new System.Windows.Point(0.5, 0.5); } System.Windows.Controls.Canvas.SetLeft(UIText, left); System.Windows.Controls.Canvas.SetTop(UIText, top); }
public void ReadXml(XmlReader reader) { TypeConverter ffc = TypeDescriptor.GetConverter(typeof(FontFamily)); TypeConverter fsc = TypeDescriptor.GetConverter(typeof(FontStyle)); TypeConverter fwc = TypeDescriptor.GetConverter(typeof(FontWeight)); TypeConverter rc = TypeDescriptor.GetConverter(typeof(Rect)); _family = (FontFamily)ffc.ConvertFromString(null, System.Globalization.CultureInfo.InvariantCulture, reader.ReadElementString("FontFamily")); _style = (FontStyle)fsc.ConvertFromString(null, System.Globalization.CultureInfo.InvariantCulture, reader.ReadElementString("FontStyle")); _weight = (FontWeight)fwc.ConvertFromString(null, System.Globalization.CultureInfo.InvariantCulture, reader.ReadElementString("FontWeight")); _size = double.Parse(reader.ReadElementString("FontSize"), CultureInfo.InvariantCulture); _configuredFontSize = _size; if (reader.Name.Equals("HorizontalAlignment")) { _horizontalAlignment = (TextHorizontalAlignment)Enum.Parse(typeof(TextHorizontalAlignment), reader.ReadElementString("HorizontalAlignment")); _verticalAlignment = (TextVerticalAlignment)Enum.Parse(typeof(TextVerticalAlignment), reader.ReadElementString("VerticalAlignment")); } if (reader.Name.Equals("Padding")) { reader.ReadStartElement("Padding"); PaddingLeft = double.Parse(reader.ReadElementString("Left"), CultureInfo.InvariantCulture); PaddingTop = double.Parse(reader.ReadElementString("Top"), CultureInfo.InvariantCulture); PaddingRight = double.Parse(reader.ReadElementString("Right"), CultureInfo.InvariantCulture); PaddingBottom = double.Parse(reader.ReadElementString("Bottom"), CultureInfo.InvariantCulture); reader.ReadEndElement(); } else { PaddingLeft = 0d; PaddingRight = 0d; PaddingTop = 0d; PaddingBottom = 0d; } if (reader.Name.Equals("Underline")) { _decorations |= Helios.TextDecorations.Underline; reader.Skip(); } if (reader.Name.Equals("Strikethrough")) { _decorations |= Helios.TextDecorations.Strikethrough; reader.Skip(); } if (reader.Name.Equals("Baseline")) { _decorations |= Helios.TextDecorations.Baseline; reader.Skip(); } if (reader.Name.Equals("OverLine")) { _decorations |= Helios.TextDecorations.OverLine; reader.Skip(); } }
private void MapJustification(int just, out TextVerticalAlignment vertical, out TextHorizontalAlignment horizontal) { switch (just) { case 0: // "TopLeft": vertical = TextVerticalAlignment.Top; horizontal = TextHorizontalAlignment.Left; break; case 1: // "TopCenter": vertical = TextVerticalAlignment.Top; horizontal = TextHorizontalAlignment.Center; break; case 2: // "TopRight": vertical = TextVerticalAlignment.Top; horizontal = TextHorizontalAlignment.Right; break; case 3: // "MiddleLeft": vertical = TextVerticalAlignment.Middle; horizontal = TextHorizontalAlignment.Left; break; case 4: // "MiddleCenter": vertical = TextVerticalAlignment.Middle; horizontal = TextHorizontalAlignment.Center; break; case 5: // "MiddleRight": vertical = TextVerticalAlignment.Middle; horizontal = TextHorizontalAlignment.Right; break; case 6: // "BottomLeft": vertical = TextVerticalAlignment.Bottom; horizontal = TextHorizontalAlignment.Left; break; case 7: // "BottomCenter": vertical = TextVerticalAlignment.Bottom; horizontal = TextHorizontalAlignment.Center; break; case 8: // "BottomRight": vertical = TextVerticalAlignment.Bottom; horizontal = TextHorizontalAlignment.Right; break; default: // "BottomLeft": vertical = TextVerticalAlignment.Bottom; horizontal = TextHorizontalAlignment.Left; break; } }
public CGeometry( double width, double height, double baseHeight, TextVerticalAlignment textVerticalAlignment, bool linebreak) { this.Width = width; this.Height = height; this.BaseHeight = baseHeight; this.TextVerticalAlignment = textVerticalAlignment; this.LineBreak = linebreak; }
/// <summary> /// Creates a new content alignment object with the specified horizontal and vertical alignment type. /// </summary> /// <param name="horizontalAlignment">The horizontal alignment type.</param> /// <param name="verticalAlignment">The vertical alignment type.</param> public ContentAlignment(TextHorizontalAlignment horizontalAlignment, TextVerticalAlignment verticalAlignment) { this.horizontalAlignment = null; this.verticalAlignment = null; this.textIndent = null; this.textOrientation = null; this.textRotationAngle = null; this.rightToLeft = null; this.wordWrap = null; this.horizontalAlignment = new TextHorizontalAlignment?(horizontalAlignment); this.verticalAlignment = new TextVerticalAlignment?(verticalAlignment); }
protected TextDisplay AddTextDisplay( string name, Point pos, Size size, string font, TextHorizontalAlignment horizontalAlignment, TextVerticalAlignment verticalAligment, double baseFontsize, string testTextDisplay, Color textColor, Color backgroundColor, bool useBackground, string interfaceDeviceName, string interfaceElementName ) { string componentName = GetComponentName(name); TextDisplay display = new TextDisplay { Top = pos.Y, Left = pos.X, Width = size.Width, Height = size.Height, Name = componentName }; TextFormat textFormat = new TextFormat { FontFamily = new FontFamily(font), HorizontalAlignment = horizontalAlignment, VerticalAlignment = verticalAligment, FontSize = baseFontsize, PaddingRight = 0, PaddingLeft = 0, PaddingTop = 0, PaddingBottom = 0 }; display.TextFormat = textFormat; display.OnTextColor = textColor; // Color.FromArgb(0xff, 0x40, 0xb3, 0x29); display.BackgroundColor = backgroundColor; // Color.FromArgb(0xff, 0x00, 0x00, 0x00); display.UseBackground = useBackground; display.ParserDictionary = ""; display.TextTestValue = testTextDisplay; Children.Add(display); AddAction(display.Actions["set.TextDisplay"], componentName); AddDefaultInputBinding( childName: componentName, interfaceTriggerName: interfaceDeviceName + "." + interfaceElementName + ".changed", deviceActionName: "set.TextDisplay"); return(display); }
/// <summary> /// Synchronizes the properties. /// </summary> public override void SynchronizeProperties() { base.SynchronizeProperties(); var a = (Annotations.TextualAnnotation)InternalAnnotation; a.TextColor = TextColor.ToOxyColor(); a.Text = Text; a.TextPosition = TextPosition; a.TextRotation = TextRotation; a.TextHorizontalAlignment = TextHorizontalAlignment.ToHorizontalAlignment(); a.TextVerticalAlignment = TextVerticalAlignment.ToVerticalAlignment(); }
public TextWidget(int ID, Element2D parent) : base(ID, parent) { color = new Color4(0.0f, 0.0f, 0.0f, 1f); off_x = 0; off_y = 0; text = ""; size = FontSize.Medium; alignment = QFontAlignment.Centre; vertical_alignment = TextVerticalAlignment.Middle; IgnoreMouse = true; }
public TextSprite(TextSprite clone) { _name = clone._name + "_clone"; _transform = clone._transform; _tint = clone._tint; _hAlign = clone.HorizontalAlignment; _vAlign = clone.VerticalAlignment; _font = clone._font; _text = clone._text; _size = clone._size; _flipMode = clone._flipMode; }
public TextFormat() { _family = new FontFamily("Franklin Gothic"); _style = FontStyles.Normal; _weight = FontWeights.Normal; _size = 12f; _textPaddingLeft = 0d; _textPaddingTop = 0d; _textPaddingRight = 0d; _textPaddingBottom = 0d; _horizontalAlignment = TextHorizontalAlignment.Center; _verticalAlignment = TextVerticalAlignment.Center; }
/// <summary> /// Creates a new content alignment object with the specified alignment types, text indent, /// text orientation, rotation angle, word wrap, and right to left setting. /// </summary> /// <param name="horizontalAlignment">The horizontal alignment type.</param> /// <param name="verticalAlignment">The vertical alignment type.</param> /// <param name="textIndent">The amount in pixels to indent the text.</param> /// <param name="textOrientation">The text orientation type.</param> /// <param name="textRotationAngle">The text rotation angle.</param> /// <param name="wordWrap">Whether words wrap in the cell.</param> /// <param name="rightToLeft">Whether text displays right to left.</param> public ContentAlignment(TextHorizontalAlignment horizontalAlignment, TextVerticalAlignment verticalAlignment, int textIndent, Dt.Cells.Data.TextOrientation textOrientation, double textRotationAngle, bool wordWrap, bool rightToLeft) { this.horizontalAlignment = null; this.verticalAlignment = null; this.textIndent = null; this.textOrientation = null; this.textRotationAngle = null; this.rightToLeft = null; this.wordWrap = null; this.horizontalAlignment = new TextHorizontalAlignment?(horizontalAlignment); this.verticalAlignment = new TextVerticalAlignment?(verticalAlignment); this.textIndent = new int?(textIndent); this.textOrientation = new Dt.Cells.Data.TextOrientation?(textOrientation); this.textRotationAngle = new double?(textRotationAngle); this.rightToLeft = new bool?(rightToLeft); this.wordWrap = new bool?(wordWrap); }
/// <summary> /// Returns true if PdfAlignedTextParameters instances are equal /// </summary> /// <param name="input">Instance of PdfAlignedTextParameters to be compared</param> /// <returns>Boolean</returns> public bool Equals(PdfAlignedTextParameters input) { if (input == null) { return(false); } return (( TextVerticalAlignment == input.TextVerticalAlignment || TextVerticalAlignment.Equals(input.TextVerticalAlignment) ) && ( TextHorizontalAlignment == input.TextHorizontalAlignment || TextHorizontalAlignment.Equals(input.TextHorizontalAlignment) ) && ( Text == input.Text || (Text != null && Text.Equals(input.Text)) ) && ( TextColor == input.TextColor || (TextColor != null && TextColor.Equals(input.TextColor)) ) && ( FontName == input.FontName || (FontName != null && FontName.Equals(input.FontName)) ) && ( StandardFontName == input.StandardFontName || StandardFontName.Equals(input.StandardFontName) ) && ( FontStyle == input.FontStyle || FontStyle.Equals(input.FontStyle) ) && ( FontSize == input.FontSize || FontSize.Equals(input.FontSize) )); }
private void ForGlyph <T>(CommandList commandList, ref StringProxy text, ref Vector2 fontSize, GlyphAction <T> action, ref T parameters, int forStart, int forEnd, bool updateGpuResources, float startX = 0, float startY = 0, TextVerticalAlignment vertAlign = TextVerticalAlignment.Top, float fontSizeY = 0f) { var key = 0; var x = startX; var y = startY; // color tags var escaping = false; var tagStack = new List <Color4>(); for (var i = forStart; i < forEnd; i++) { var character = text[i]; if (StartsColorTag(ref text, ref i, out Color4 color) && !escaping) { tagStack.Add(color); }
private void DrawString(SpriteFont spriteFont, ref SpriteFont.StringProxy text, float fontSize, ref Vector2 position, ref Color4 color, float rotation, ref Vector2 origin, ref Vector2 scale, SpriteEffects effects, float layerDepth, TextAlignment alignment, TextVerticalAlignment vert_alignment = TextVerticalAlignment.Top, float lineAdjustment = 0f) { if (spriteFont == null) { throw new ArgumentNullException("spriteFont"); } if (text.IsNull) { throw new ArgumentNullException("text"); } if (fontSize < 0) { fontSize = spriteFont.Size; } // calculate the resolution ratio between the screen real size and the virtual resolution var commandList = GraphicsContext.CommandList; var viewportSize = commandList.Viewport; var virtualResolution = GetCurrentResolution(commandList); var resolutionRatio = new Vector2(viewportSize.Width / virtualResolution.X, viewportSize.Height / virtualResolution.Y); scale.X = scale.X / resolutionRatio.X; scale.Y = scale.Y / resolutionRatio.Y; var fontSize2 = fontSize * ((spriteFont.FontType == SpriteFontType.Dynamic) ? resolutionRatio : Vector2.One); var drawCommand = new SpriteFont.InternalDrawCommand(this, ref fontSize2, ref position, ref color, rotation, ref origin, ref scale, effects, layerDepth); // snap the position the closest 'real' pixel Vector2.Modulate(ref drawCommand.Position, ref resolutionRatio, out drawCommand.Position); drawCommand.Position.X = (float)Math.Round(drawCommand.Position.X); drawCommand.Position.Y = (float)Math.Round(drawCommand.Position.Y); drawCommand.Position.X /= resolutionRatio.X; drawCommand.Position.Y /= resolutionRatio.Y; spriteFont.InternalDraw(commandList, ref text, ref drawCommand, alignment, vert_alignment, lineAdjustment); }
public static void DrawTextAligned(String fontName, String text, SpriteBatch spriteBatch, Point location, TextVerticalAlignment verticalAlignment, TextHorizantialAlignment horizantialAlignment, Color color) { Fonts.DrawTextAligned(fontName, text, spriteBatch, new Vector2((float)location.X, (float)location.Y), verticalAlignment, horizantialAlignment, color); }
public static void DrawTextAligned(String fontName, String text, SpriteBatch spriteBatch, Vector2 location, TextVerticalAlignment verticalAlignment, TextHorizantialAlignment horizantialAlignment, Color color) { SpriteFont spriteFont = Fonts.GetFont(fontName); Vector2 textSize = spriteFont.MeasureString(text); Vector2 alignedLocation = new Vector2(); // Calculate Horizantial Aligned Location switch (horizantialAlignment) { case TextHorizantialAlignment.Left: alignedLocation.X = location.X; break; case TextHorizantialAlignment.Center: alignedLocation.X = location.X - (textSize.X / 2.0f); break; case TextHorizantialAlignment.Right: alignedLocation.X = location.X - textSize.X; break; } // Calculate Vertical Aligned Location switch (verticalAlignment) { case TextVerticalAlignment.Top: alignedLocation.Y = location.Y; break; case TextVerticalAlignment.Middle: alignedLocation.Y = location.Y - (textSize.Y / 2.0f); break; case TextVerticalAlignment.Bottom: alignedLocation.Y = location.Y - textSize.Y; break; } spriteBatch.DrawString(spriteFont, text, alignedLocation, color); }
public void ReadXml(XmlReader reader) { TypeConverter ffc = TypeDescriptor.GetConverter(typeof(FontFamily)); TypeConverter fsc = TypeDescriptor.GetConverter(typeof(FontStyle)); TypeConverter fwc = TypeDescriptor.GetConverter(typeof(FontWeight)); TypeConverter rc = TypeDescriptor.GetConverter(typeof(Rect)); _family = (FontFamily)ffc.ConvertFromString(null, System.Globalization.CultureInfo.InvariantCulture, reader.ReadElementString("FontFamily")); _style = (FontStyle)fsc.ConvertFromString(null, System.Globalization.CultureInfo.InvariantCulture, reader.ReadElementString("FontStyle")); _weight = (FontWeight)fwc.ConvertFromString(null, System.Globalization.CultureInfo.InvariantCulture, reader.ReadElementString("FontWeight")); _size = double.Parse(reader.ReadElementString("FontSize"), CultureInfo.InvariantCulture); if (reader.Name.Equals("HorizontalAlignment")) { _horizontalAlignment = (TextHorizontalAlignment)Enum.Parse(typeof(TextHorizontalAlignment), reader.ReadElementString("HorizontalAlignment")); _verticalAlignment = (TextVerticalAlignment)Enum.Parse(typeof(TextVerticalAlignment), reader.ReadElementString("VerticalAlignment")); } if (reader.Name.Equals("Padding")) { reader.ReadStartElement("Padding"); PaddingLeft = double.Parse(reader.ReadElementString("Left"), CultureInfo.InvariantCulture); PaddingTop = double.Parse(reader.ReadElementString("Top"), CultureInfo.InvariantCulture); PaddingRight = double.Parse(reader.ReadElementString("Right"), CultureInfo.InvariantCulture); PaddingBottom = double.Parse(reader.ReadElementString("Bottom"), CultureInfo.InvariantCulture); reader.ReadEndElement(); } else { PaddingLeft = 0d; PaddingRight = 0d; PaddingTop = 0d; PaddingBottom = 0d; } if (reader.Name.Equals("Underline")) { _decorations |= Helios.TextDecorations.Underline; reader.Skip(); } if (reader.Name.Equals("Strikethrough")) { _decorations |= Helios.TextDecorations.Strikethrough; reader.Skip(); } if (reader.Name.Equals("Baseline")) { _decorations |= Helios.TextDecorations.Baseline; reader.Skip(); } if (reader.Name.Equals("OverLine")) { _decorations |= Helios.TextDecorations.OverLine; reader.Skip(); } }
private void ForEachGlyph <T>(CommandList commandList, ref StringProxy text, ref Vector2 requestedFontSize, GlyphAction <T> action, ref T parameters, TextAlignment scanOrder, TextVerticalAlignment vertAlign, bool updateGpuResources, Vector2?textBoxSize = null, float lineSpaceAdjustment = 0f) { float rawYSpacing = GetTotalLineSpacing(requestedFontSize.Y); float yStart, ySpacing = rawYSpacing + lineSpaceAdjustment; if (textBoxSize.HasValue && vertAlign != TextVerticalAlignment.Top) { int extraLines = text.LineCount - 1; float lineHeight = rawYSpacing + extraLines * ySpacing; switch (vertAlign) { default: case TextVerticalAlignment.Center: yStart = textBoxSize.Value.Y * 0.5f - (lineHeight * 0.5f); break; case TextVerticalAlignment.Bottom: yStart = textBoxSize.Value.Y - lineHeight; break; } } else { yStart = 0f; } if (scanOrder == TextAlignment.Left) { // scan the whole text only one time following the text letter order ForGlyph(commandList, ref text, ref requestedFontSize, action, ref parameters, 0, text.Length, updateGpuResources, 0f, yStart, vertAlign, ySpacing); } else { // scan the text line by line incrementing y start position // measure the whole string in order to be able to determine xStart var wholeSize = textBoxSize ?? MeasureString(ref text, ref requestedFontSize); // scan the text line by line var startIndex = 0; var endIndex = FindCariageReturn(ref text, 0); while (startIndex < text.Length) { // measure the size of the current line var lineSize = Vector2.Zero; ForGlyph(commandList, ref text, ref requestedFontSize, MeasureStringGlyph, ref lineSize, startIndex, endIndex, updateGpuResources, 0f, 0f, vertAlign, ySpacing); // Determine the start position of the line along the x axis // We round this value to the closest integer to force alignment of all characters to the same pixels // Otherwise the starting offset can fall just in between two pixels and due to float imprecision // some characters can be aligned to the pixel before and others to the pixel after, resulting in gaps and character overlapping var xStart = (scanOrder == TextAlignment.Center) ? (wholeSize.X - lineSize.X) / 2 : wholeSize.X - lineSize.X; xStart = (float)Math.Round(xStart); // scan the line ForGlyph(commandList, ref text, ref requestedFontSize, action, ref parameters, startIndex, endIndex, updateGpuResources, xStart, yStart, vertAlign, ySpacing); // update variable before going to next line yStart += ySpacing; startIndex = endIndex + 1; endIndex = FindCariageReturn(ref text, startIndex); } } }
internal void InternalDraw(CommandList commandList, ref StringProxy text, ref InternalDrawCommand drawCommand, TextAlignment alignment, TextVerticalAlignment vert_alignment, float lineAdjustment) { // If the text is mirrored, offset the start position accordingly. if (drawCommand.SpriteEffects != SpriteEffects.None) { drawCommand.Origin -= MeasureString(ref text, ref drawCommand.FontSize, lineAdjustment) * AxisIsMirroredTable[(int)drawCommand.SpriteEffects & 3]; } // Draw each character in turn. ForEachGlyph(commandList, ref text, ref drawCommand.FontSize, internalDrawGlyphAction, ref drawCommand, alignment, vert_alignment, true, null, lineAdjustment); }
/// <summary> /// Creates text as drawing object. /// </summary> /// <param name="graphics"><see cref="IGraphics"/> object.</param> /// <param name="text">Text that will be drawn.</param> /// <param name="font">Font that will be used to draw the text.</param> /// <param name="foregroundColor">Color of the brush that will be used to paint the text.</param> /// <param name="backgroundColor">Color of the brush that will be used to paint the text's background.</param> /// <param name="left">Left position of the text.</param> /// <param name="top">Top position of the text.</param> /// <param name="width">Virtual text box width. If value is less than 0, it will be automatically computed.</param> /// <param name="height">Virtual text box height. If value is less than 0, it will be automatically computed.</param> /// <param name="horizontalAlignment">Text horizontal alignment.</param> /// <param name="verticalAlignment">Text vertical alignment.</param> /// <param name="wrapping">Text wrapping.</param> /// <param name="rotation">Text clockwise rotation in radians.</param> /// <returns>Text as drawing object.</returns> public static IText CreateText(this IGraphics graphics, string text, IFont font, Color foregroundColor, Color backgroundColor, double left = 0, double top = 0, double width = -1, double height = -1, TextHorizontalAlignment horizontalAlignment = TextHorizontalAlignment.Left, TextVerticalAlignment verticalAlignment = TextVerticalAlignment.Top, TextWrapping wrapping = TextWrapping.Wrap, double rotation = 0) { IBrush foreground = graphics.CreateSolidColorBrush(foregroundColor); IBrush background = graphics.CreateSolidColorBrush(backgroundColor); return(graphics.CreateText(text, font, foreground, background, left, top, width, height, horizontalAlignment, verticalAlignment, wrapping, rotation)); }
/// <summary> /// Draw a text message (string) with transparent background /// to support redraw, compiled textures are cached for a short while <seealso cref="SweepInterval"/> /// </summary> public static void DrawString(Vector2 point, Color color, string message, System.Drawing.Font font, Vector2 scale, TextHorizontalAlignment horizontalAlignment = TextHorizontalAlignment.Left, TextVerticalAlignment verticalAlignment = TextVerticalAlignment.Bottom, SpriteEffects effects = SpriteEffects.None, SpriteBatch spriteBatch = null) { int identifier = HashCode.Combine(font, message); if (!instance.currentResources.TryGetValue(identifier, out Texture2D texture)) { if (!instance.previousResources.TryGetValue(identifier, out texture)) { texture = TextTextureRenderer.Resize(message, font, instance.Game.GraphicsDevice, instance.measureGraphics); TextTextureRenderer.RenderText(message, font, texture); instance.currentResources.Add(identifier, texture); } else { instance.currentResources.Add(identifier, texture); instance.previousResources.Remove(identifier); } } point -= new Vector2(texture.Width * ((int)horizontalAlignment / 2f), texture.Height * ((int)verticalAlignment / 2f)); (spriteBatch ?? instance.spriteBatch).Draw(texture, point, null, color, 0, Vector2.Zero, scale, effects, 0); }
public void SetTextVerticalAlign(TextVerticalAlignment align) { VAlign = align; OnTextChange(); base.UpdateVAO(); }
/// <summary> /// Creates text as drawing object. /// </summary> /// <param name="text">Text that will be drawn.</param> /// <param name="font">Font that will be used to draw the text.</param> /// <param name="foreground">Brush that will be used to paint the text.</param> /// <param name="background">Brush that will be used to paint the text's background.</param> /// <param name="left">Left position of the text.</param> /// <param name="top">Top position of the text.</param> /// <param name="width">Virtual text box width. If value is less than 0, it will be automatically computed.</param> /// <param name="height">Virtual text box height. If value is less than 0, it will be automatically computed.</param> /// <param name="horizontalAlignment">Text horizontal alignment.</param> /// <param name="verticalAlignment">Text vertical alignment.</param> /// <param name="wrapping">Text wrapping.</param> /// <param name="rotation">Text clockwise rotation in radians.</param> /// <returns>Text as drawing object.</returns> public IText CreateText(string text, IFont font, IBrush foreground, IBrush background, double left = 0, double top = 0, double width = -1, double height = -1, TextHorizontalAlignment horizontalAlignment = TextHorizontalAlignment.Left, TextVerticalAlignment verticalAlignment = TextVerticalAlignment.Top, TextWrapping wrapping = TextWrapping.Wrap, double rotation = 0) { return(dispatcher.Invoke(() => new Text(text, font, foreground, background, left, top, width, height, horizontalAlignment, verticalAlignment, wrapping, rotation))); }
protected TextDisplay AddTextDisplay( string name, Point posn, Size size, string font, TextHorizontalAlignment horizontalAlignment, TextVerticalAlignment verticalAligment, double baseFontsize, string testTextDisplay, Color textColor, Color backgroundColor, bool useBackground, string interfaceDeviceName, string interfaceElementName, string textDisplayDictionary ) { string componentName = GetComponentName(name); TextDisplay display = new TextDisplay { Top = posn.Y, Left = posn.X, Width = size.Width, Height = size.Height, Name = componentName }; TextFormat textFormat = new TextFormat { FontFamily = ConfigManager.FontManager.GetFontFamilyByName(font), HorizontalAlignment = horizontalAlignment, VerticalAlignment = verticalAligment, FontSize = baseFontsize, ConfiguredFontSize = baseFontsize, PaddingRight = 0, PaddingLeft = 0, PaddingTop = 0, PaddingBottom = 0 }; // NOTE: for scaling purposes, we commit to the reference height at the time we set TextFormat, since that indirectly sets ConfiguredFontSize display.TextFormat = textFormat; display.OnTextColor = textColor; // Color.FromArgb(0xff, 0x40, 0xb3, 0x29); display.BackgroundColor = backgroundColor; // Color.FromArgb(0xff, 0x00, 0x00, 0x00); display.UseBackground = useBackground; if (textDisplayDictionary.Equals("")) { display.ParserDictionary = ""; } else { display.ParserDictionary = textDisplayDictionary; display.UseParseDictionary = true; } display.TextTestValue = testTextDisplay; Children.Add(display); AddAction(display.Actions["set.TextDisplay"], componentName); AddDefaultInputBinding( childName: componentName, interfaceTriggerName: interfaceDeviceName + "." + interfaceElementName + ".changed", deviceActionName: "set.TextDisplay"); return(display); }