public override void OnDraw(Graphics2D graphics2D) { graphics2D.PushTransform(); int numLines = Text.Split('\n').Length - 1; if(Text.Contains("\r")) { throw new Exception("These should have be converted to \n."); } double yOffsetForText = Printer.TypeFaceStyle.EmSizeInPixels * numLines; double xOffsetForText = 0; switch (printer.Justification) { case Justification.Left: break; case Justification.Center: xOffsetForText = (Width - Printer.LocalBounds.Width) / 2; break; case Justification.Right: xOffsetForText = Width - Printer.LocalBounds.Width; break; default: throw new NotImplementedException(); } graphics2D.SetTransform(graphics2D.GetTransform() * Affine.NewTranslation(xOffsetForText, yOffsetForText)); RGBA_Bytes currentColor = this.textColor; if (EllipsisIfClipped && Printer.LocalBounds.Width > LocalBounds.Width) // only do this if it's static text { TypeFacePrinter shortTextPrinter = Printer; while (shortTextPrinter.LocalBounds.Width > LocalBounds.Width && shortTextPrinter.Text.Length > 4) { shortTextPrinter = new TypeFacePrinter(shortTextPrinter.Text.Substring(0, shortTextPrinter.Text.Length - 4).TrimEnd(spaceTrim) + "...", Printer); } shortTextPrinter.Render(graphics2D, currentColor); } else { // it all fits or it's editable (if editable it will need to be offset/scrolled sometimes). Printer.Render(graphics2D, currentColor); } if (debugIt) { graphics2D.Line(-5, 0, 5, 0, RGBA_Bytes.Blue); graphics2D.Line(0, -5, 0, 5, RGBA_Bytes.Blue); } graphics2D.PopTransform(); if (debugIt) { graphics2D.Line(-5, 0, 5, 0, RGBA_Bytes.Red); graphics2D.Line(0, -5, 0, 5, RGBA_Bytes.Red); } base.OnDraw(graphics2D); }