/// <summary> /// Draws a bar over the text of a pin to symbolize negative logic. /// </summary> private void DrawOverline(Graphics g, string text, Font font, Pen pen, float x, float y, StringAlignmentKind alignmentKind, StringAlignment horizontalAlignment, StringAlignment verticalAlignment) { var overlineRanges = OverlineHelper.Parse(text); if (overlineRanges.Length == 0) { return; } var plainText = text.Replace(@"\", ""); var offsetX = ScalePixelLength(0.5f); var offsetY = 0.0f; var rangeBounds = DrawingUtils.CalculateTextExtent(g, plainText, x, y, font, alignmentKind, horizontalAlignment, verticalAlignment, overlineRanges); foreach (var bound in rangeBounds) { var inflatedBound = bound.Inflated(-offsetX, -offsetY); g.DrawLine(pen, inflatedBound.X, inflatedBound.Y, inflatedBound.Right, inflatedBound.Y); } }
private void RenderTextStringPrimitive(Graphics g, TextStringRecord textString) { var location = ScreenFromWorld(textString.Location.X, textString.Location.Y); using (var brush = new SolidBrush(textString.Color)) using (var font = CreateFont(textString.FontId)) { StringAlignment horizontalAlignment; if (textString.Justification == TextJustification.BottomLeft || textString.Justification == TextJustification.MiddleLeft || textString.Justification == TextJustification.TopLeft) { horizontalAlignment = StringAlignment.Near; } else if (textString.Justification == TextJustification.BottomCenter || textString.Justification == TextJustification.MiddleCenter || textString.Justification == TextJustification.TopCenter) { horizontalAlignment = StringAlignment.Center; } else { horizontalAlignment = StringAlignment.Far; } StringAlignment verticalAlignment; if (textString.Justification == TextJustification.BottomLeft || textString.Justification == TextJustification.BottomCenter || textString.Justification == TextJustification.BottomRight) { verticalAlignment = StringAlignment.Far; } else if (textString.Justification == TextJustification.MiddleLeft || textString.Justification == TextJustification.MiddleCenter || textString.Justification == TextJustification.MiddleRight) { verticalAlignment = StringAlignment.Center; } else { verticalAlignment = StringAlignment.Near; } g.TranslateTransform(location.X, location.Y); if (textString.Orientations.HasFlag(TextOrientations.Rotated)) { g.RotateTransform(-90); } if (textString.Orientations.HasFlag(TextOrientations.Flipped)) { horizontalAlignment = StringAlignment.Far - (int)horizontalAlignment; verticalAlignment = StringAlignment.Far - (int)verticalAlignment; } DrawingUtils.DrawString(g, textString.DisplayText, font, brush, 0, 0, StringAlignmentKind.Extent, horizontalAlignment, verticalAlignment); PrimitiveScreenBounds[textString] = DrawingUtils.CalculateTextExtent(g, textString.DisplayText, font, location.X, location.Y, StringAlignmentKind.Extent, horizontalAlignment, verticalAlignment); } }