protected override Types.Rectangle CalculateBounds( Renderers.Renderer renderer ) { double width, height, baselineFromTop, x, y; renderer.MeasureText( this, out width, out height, out baselineFromTop ); switch( Alignment ) { case Primitives.Text.Position.TopLeft: case Primitives.Text.Position.CenterLeft: case Primitives.Text.Position.BaseLeft: case Primitives.Text.Position.BottomLeft: x = _point.X; break; case Primitives.Text.Position.TopCenter: case Primitives.Text.Position.Center: case Primitives.Text.Position.BaseCenter: case Primitives.Text.Position.BottomCenter: x = _point.X - width / 2 - 1; break; case Primitives.Text.Position.TopRight: case Primitives.Text.Position.CenterRight: case Primitives.Text.Position.BaseRight: case Primitives.Text.Position.BottomRight: x = _point.X - width; break; default: throw new InvalidOperationException(); } switch( Alignment ) { case Primitives.Text.Position.TopLeft: case Primitives.Text.Position.TopCenter: case Primitives.Text.Position.TopRight: y = _point.Y; break; case Primitives.Text.Position.CenterLeft: case Primitives.Text.Position.Center: case Primitives.Text.Position.CenterRight: y = _point.Y - height / 2; break; case Primitives.Text.Position.BaseLeft: case Primitives.Text.Position.BaseCenter: case Primitives.Text.Position.BaseRight: y = _point.Y - baselineFromTop; break; case Primitives.Text.Position.BottomLeft: case Primitives.Text.Position.BottomCenter: case Primitives.Text.Position.BottomRight: y = _point.Y - height; break; default: throw new InvalidOperationException(); } return new BinaryComponents.VectorGraphics.Types.Rectangle( x, y, width, height ); }