Rotating NPrimitiveText


Author
Message
Ted O'Grady
Ted O'Grady
Junior Member (12 reputation)Junior Member (12 reputation)Junior Member (12 reputation)Junior Member (12 reputation)Junior Member (12 reputation)Junior Member (12 reputation)Junior Member (12 reputation)Junior Member (12 reputation)Junior Member (12 reputation)
Group: Forum Members
Posts: 12, Visits: 1
I am having a trouble understanding how to rotate text. Any help would be appreciated.

I have tried using the TextStyle.Orientation and calculating its rotated bounding box, but the stretch function resizes the text and foils my attempts. The text does not rotate without stretch specified. I seem to be missing the trick to rotating text easily.

Here's example code I am using: (uses NTextShape, instead of the primitive to same effect)

private static NShape BuildRotatedStretchTextAndBoundingBox( string str, NDrawingDocument document, NBasicShapesFactory factory)
{
var myStyle = BuildOrientationTextStyle();
// show the box
var originalSize = CalculateRotatedStringSize(document, myStyle, str, 45); // simple trig
var origboundingBox = factory.CreateShape(BasicShapes.Rectangle);
origboundingBox.Bounds = new NRectangleF(new NPointF(0, 500), originalSize);
document.ActiveLayer.AddChild(origboundingBox);

// show the text
var text = new NTextShape(str, origboundingBox.Bounds);
text.Mode = BoxTextMode.Stretch;
text.Style = myStyle;
document.ActiveLayer.AddChild(text);

// show the coordinates
var origcoords = new NTextShape("Rotated and stretched OrigCoords: " + origboundingBox.Bounds, 0, 725, 400, 50);
document.ActiveLayer.AddChild(origcoords);
return origboundingBox;
}

private static NStyle BuildOrientationTextStyle()
{
var myStyle = BuildSimpleTextStyle();
myStyle.TextStyle.Orientation = -45;
return myStyle;
}

public static NSizeF CalculateRotatedStringSize(NDrawingDocument document, NStyle myStyle, string str, float rotation)
{
double radians = DegreeToRadian(rotation);
NSizeF sizeF;
document.MeasureStringInWorld(str, myStyle.TextStyle, out sizeF);
sizeF.Width = (float)((sizeF.Height * Math.Sin(radians)) + (sizeF.Width * Math.Cos(radians)));
sizeF.Height = (float)((sizeF.Height * Math.Cos(radians)) + (sizeF.Width * Math.Sin(radians)));

return sizeF;
}
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Threaded View

Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search