/// <summary> /// Calculates the space used for the axis title. /// </summary> internal override void Format() { XGraphics gfx = this.rendererParms.Graphics; AxisTitleRendererInfo atri = ((AxisRendererInfo)this.rendererParms.RendererInfo).axisTitleRendererInfo; if (atri.AxisTitleText != "") { XSize size = gfx.MeasureString(atri.AxisTitleText, atri.AxisTitleFont); if (atri.AxisTitleOrientation != 0) { XPoint[] points = new XPoint[2]; points[0].X = 0; points[0].Y = 0; points[1].X = size.Width; points[1].Y = size.Height; XMatrix matrix = new XMatrix(); //XMatrix.Identity; matrix.RotatePrepend(-atri.AxisTitleOrientation); matrix.TransformPoints(points); size.Width = Math.Abs(points[1].X - points[0].X); size.Height = Math.Abs(points[1].Y - points[0].Y); } atri.X = 0; atri.Y = 0; atri.Height = size.Height; atri.Width = size.Width; } }
public static void DrawLabel(XGraphics g, string text, PointF labelPos, XFont font, XBrush brush, LabelStyle labelStyle) { using (RenderUtil.SaveState(g)) { XTextFormatter tf = new XTextFormatter(g); tf.Alignment = XParagraphAlignment.Center; XMatrix matrix = new XMatrix(); matrix.TranslatePrepend(labelPos.X, labelPos.Y); matrix.ScalePrepend(1.0f / Astrometrics.ParsecScaleX, 1.0f / Astrometrics.ParsecScaleY); if (labelStyle.Uppercase) { text = text.ToUpper(); } if (labelStyle.Wrap) { text = text.Replace(' ', '\n'); } matrix.TranslatePrepend(labelStyle.Translation.X, labelStyle.Translation.Y); matrix.RotatePrepend(labelStyle.Rotation); matrix.ScalePrepend(labelStyle.Scale.Width, labelStyle.Scale.Height); g.MultiplyTransform(matrix, XMatrixOrder.Prepend); XSize size = g.MeasureString(text, font); size.Width *= 2; // prevent cut-off e.g. when rotated XRect bounds = new XRect(-size.Width / 2, -size.Height / 2, size.Width, size.Height); tf.DrawString(text, font, brush, bounds); } }
// Used for names from vector files (macro borders, rifts) internal void DrawName(AbstractGraphics graphics, RectangleF rect, Font font, AbstractBrush textBrush, LabelStyle labelStyle) { if (graphics == null) { throw new ArgumentNullException("graphics"); } RectangleF bounds = TransformedBounds; if (bounds.IntersectsWith(rect)) { if (Name != null) { string str = Name; if (labelStyle.Uppercase) { str = str.ToUpperInvariant(); } PointF pos = NamePosition;// PointF( bounds.Left + bounds.Width / 2, bounds.Top + bounds.Height / 2 ); using (graphics.Save()) { XMatrix matrix = new XMatrix(); matrix.TranslatePrepend(pos.X, pos.Y); matrix.ScalePrepend(1.0f / Astrometrics.ParsecScaleX, 1.0f / Astrometrics.ParsecScaleY); matrix.RotatePrepend(-labelStyle.Rotation); // Rotate it graphics.MultiplyTransform(matrix); RenderUtil.DrawString(graphics, str, font, textBrush, 0, 0); } } } }
public void DrawName(XGraphics graphics, RectangleF rect, MapOptions options, XFont font, XBrush textBrush, LabelStyle labelStyle) { if (graphics == null) { throw new ArgumentNullException("graphics"); } RectangleF bounds = TransformedBounds; if (bounds.IntersectsWith(rect)) { if (Name != null) { string str = Name; if (labelStyle.Uppercase) { str = str.ToUpperInvariant(); } PointF pos = NamePosition;// PointF( bounds.Left + bounds.Width / 2, bounds.Top + bounds.Height / 2 ); using (RenderUtil.SaveState(graphics)) { XMatrix matrix = new XMatrix(); matrix.TranslatePrepend(pos.X, pos.Y); matrix.ScalePrepend(1.0f / Astrometrics.ParsecScaleX, 1.0f / Astrometrics.ParsecScaleY); matrix.RotatePrepend(-labelStyle.Rotation); // Rotate it graphics.MultiplyTransform(matrix, XMatrixOrder.Prepend); // TODO: Accomodate wrapping //SizeF size = graphics.MeasureString( str, font, bounds.Size); XSize size = graphics.MeasureString(str, font); graphics.TranslateTransform(-size.Width / 2, -size.Height / 2); // Center the text //graphics.TextRenderingHint = TextRenderingHint.AntiAlias; RectangleF textBounds = new RectangleF(0, 0, (float)size.Width, (float)size.Height * 2); // *2 or it gets cut off at high sizes graphics.DrawString(str, font, textBrush, textBounds, RenderUtil.StringFormatTopCenter); } } } }
public void RotatePrepend(float angle) { matrix.RotatePrepend(angle); }