I need to get the length (dimension in millimeters not the number of characters!) of a string (text) to calculate the size of rectangle it needs to go into.
Here is my code snippet:
Code: Select all
// create a TextShape
XShape headingTexShape = ShapeHelper.createShape(xDrawDoc, new Point( 1410, 1197 ), new Size( 25256, 2037 ), "com.sun.star.drawing.TextShape");
// add it to the page's shapes
xShapes.add(headingTexShape);
// create a new XText object
XText headingTextShapeText = (XText)UnoRuntime.queryInterface(XText.class, headingTexShape);
// create text cursor for selecting and formatting
XTextCursor headingTextShapeTextCursor = headingTextShapeText.createTextCursor();
XPropertySet headingTextShapeTextCursorPropertySet = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, headingTextShapeTextCursor);
headingTextShapeTextCursorPropertySet.setPropertyValue("CharWeight", new Float ( com.sun.star.awt.FontWeight.BOLD));
headingTextShapeTextCursorPropertySet.setPropertyValue("CharHeight", new Float ( 20 ));
headingTextShapeTextCursorPropertySet.setPropertyValue("CharFontName", "Arial");
headingTextShapeText.setString("My very long string goes here ... blah blah blah");
I'm reading in data from a spreadsheet and have to "align" these strings to fit into the rectangles. The rectangles are of fixed width, but, obviously, if the string is long, I will have to 'wrap' it and increase the rectangle's height accordingly. I need the string's length to (a) calculate when I need to split it up, and as a result, by how much to increase the rectangle's height.
My question, again, is: "once I set my string, how can I get its length (in millimeters; since I'm composing the page this way)".
Thanks,
--MA