disable caption/text from rotating in picturebase

Sep 15, 2012 at 11:53 PM

how do i keep text from rotating when i rotate the picturebase?

I do not want the text to rotate when i rotate the picture or rectangle.

please help.

Sep 17, 2012 at 9:57 AM

The position and size of the Caption object (which handles most of the text related stuff) is calculated in the shape's CalculatePath() method - in this case in CaptionedShapeBase.CalculatePath(). The graphics paths are calculated referring to the center of origin as the shape's position.
The rotation and the position on the diagram is applied in the TransformDrawCache() method - in this case CaptionedShapeBase.TransformDrawCache.

Depending on the desired behavior, you can either rotate the text in the opposite direction by overriding "TransformDrawCache" or completely customize the text position and rotation by overriding both CalculatePath and TransformDrawCache.
This is the original code (with a few additional comments)

        protected override bool CalculatePath() {
            if (caption == null) return true;
            bool result = false;

            // Calculate the bounds for the text (defines location and size)
           Rectangle layoutRectangle = Rectangle.Empty;
            CalcCaptionBounds(0, out layoutRectangle);

            // Based on the calculated layout rectangle, calculate the text's graphics path
            result = caption.CalculatePath(layoutRectangle.X, layoutRectangle.Y, layoutRectangle.Width, layoutRectangle.Height, CharacterStyle, ParagraphStyle);

            if (maintainTextAngle && Angle > 900 && Angle < 2700) {
                // Flip text in order to maintain its orientation (we don't want the text to be drawn upside down in most cases)
                PointF rotationCenter = PointF.Empty;
                rotationCenter.X = layoutRectangle.X + (layoutRectangle.Width / 2f);
                rotationCenter.Y = layoutRectangle.Y + (layoutRectangle.Height / 2f);
                Matrix.RotateAt(180, rotationCenter, MatrixOrder.Append);
            return result;

        protected override void TransformDrawCache(int deltaX, int deltaY, int deltaAngle, int rotationCenterX, int rotationCenterY) {
            base.TransformDrawCache(deltaX, deltaY, deltaAngle, rotationCenterX, rotationCenterY);
            // transform DrawCache only if the drawCache is valid, otherwise it will be recalculated
            // at the correct position/size
            if (!drawCacheIsInvalid && caption != null)

In both cases, you probably have to override CalculateBoundingRectangle() which calculates the X-axis aligned bounding rectangle of the shape. Include the parts of the text area that are outside the shape's rectangle to the bounding rectangle.