Thanks for the hints... I have since tried the following:
// get internal service factory of the document
XMultiServiceFactory xWriterFactory_tmp = (XMultiServiceFactory)
UnoRuntime.queryInterface(
XMultiServiceFactory.class, xWriterComponent_sdraw_dest);
XModel model = (XModel) UnoRuntime.queryInterface(XModel.class,
xWriterComponent_sdraw_dest);
XController controller = model.getCurrentController();
XWindow xWindow = controller.getFrame().getContainerWindow();
XWindowPeer xWindowPeer = (XWindowPeer)
UnoRuntime.queryInterface(XWindowPeer.class, xWindow);
// XToolkit aToolkit = xWindowPeer.getToolkit();
XUnitConversion m_xConversion = (XUnitConversion)
UnoRuntime.queryInterface(XUnitConversion.class,
xWindowPeer);
XDevice xDevice =
(XDevice)UnoRuntime.queryInterface(XDevice.class, xWindow);
FontDescriptor fontDescriptors[] = xDevice.getFontDescriptors();
FontDescriptor fontDescriptor = null;
Vector names = new Vector();
width = 0;
height = 0;
for (int i = 0; i < fontDescriptors.length; i++) {
if (!names.contains(fontDescriptors[i].Name)) {
names.add((String)fontDescriptors[i].Name);
}
if
(fontDescriptors[i].Name.equalsIgnoreCase(fontToUse.name)) {
fontDescriptors[i].Height = (short)fontToUse.size;
fontDescriptor = fontDescriptors[i];
XFont xFont = xDevice.getFont(fontDescriptors[i]);
width = xFont.getStringWidth(message);
SimpleFontMetric simpleFontMetric =
xFont.getFontMetric();
height = simpleFontMetric.Ascent +
simpleFontMetric.Descent +
simpleFontMetric.Leading;
break;
}
}
Then I use these settings in an attempt to "wrap" the text I am about to add
with a boundary using a rectangle shape:
Object shape = xWriterFactory_tmp.createInstance(
"com.sun.star.drawing.RectangleShape");
XShape xShape = (XShape) UnoRuntime.queryInterface(
XShape.class, shape);
xShape.setPosition(new Point(pageBorderLeft, pageBorderTop));
Size aSize = new Size(width + 3, height + 3);// add a few pixels
for padding...
Size aPointInMM_100TH =
m_xConversion.convertSizeToLogic(aSize,
MeasureUnit.MM_100TH);
//int nwidth = (int)(((float)width / (float)72) * (float)2540) +
50;
//int nheight = (int)(((float)height / (float)72) * (float)2540)
+ 50;
int nwidth = aPointInMM_100TH.Width;
int nheight = aPointInMM_100TH.Height;
System.out.println("New Height: " + nheight);
System.out.println("New Width: " + nwidth);
xShape.setSize(new Size(nwidth, nheight));
xDrawPage.add(xShape);
// Now set the text
XText xText = (XText) UnoRuntime.queryInterface(XText.class,
xShape);
XTextCursor xTextCursor = xText.createTextCursor();
xTextCursor.gotoEnd(false);
XPropertySet xPropertySet = (XPropertySet)
UnoRuntime.queryInterface(
XPropertySet.class, xTextCursor);
xPropertySet.setPropertyValue("CharFontCharSet",
fontDescriptor.CharSet);
xPropertySet.setPropertyValue("CharFontFamily",
fontDescriptor.Family);
xPropertySet.setPropertyValue("CharHeight",
fontDescriptor.Height);
xPropertySet.setPropertyValue("CharFontName",
fontDescriptor.Name);
xPropertySet.setPropertyValue("CharFontPitch",
fontDescriptor.Pitch);
xPropertySet.setPropertyValue("CharPosture",
fontDescriptor.Slant);
xPropertySet.setPropertyValue("CharStrikeout",
fontDescriptor.Strikeout);
xPropertySet.setPropertyValue("CharUnderline",
fontDescriptor.Underline);
xPropertySet.setPropertyValue("CharWeight",
fontDescriptor.Weight);
xText.setString(message);
However, the resultant image is still not correct, see the following image:
http://old.nabble.com/file/p27155936/image1.jpg if I go then to draw and
expand the image, I then get the text, see image 2,
http://old.nabble.com/file/p27155936/image2.jpg
However, If I use my DPI calculation of 72 DPI FYI:
int nwidth = (int)(((float)width / (float)72) * (float)2540) + 50;
int nheight = (int)(((float)height / (float)72) * (float)2540) + 50;
I get the right sized image, at least for hte MAC, on OpenSolaris its no
good.
Any tips, or anything I am doing wrong, please let me know... Thanks once
again!
Regards,
Chris
Ariel Constenla-Haile wrote:
>
> Hello Chris,
>
> On Wednesday 13 January 2010, 18:49, Chris Fleischmann wrote:
>> Hello folks, just wondering if there is a more accurate way of converting
>> pixels to 1/00mm in OpenOffice... Other than the 72 DPI type of
>> calculation
>> people use?
>>
>> Currently I do the following:
>>
>> if (fontDescriptor[i].Name.equalsIgnoreCase("Arial")) {
>> fontDescriptor[i].Height = (short)12; // just an
>> arbitrary height number.
>>
>> XFont xFont = xDevice.getFont(fontDescriptor[i]);
>>
>> width = xFont.getStringWidth(message);
>>
>> SimpleFontMetric simpleFontMetric =
>> xFont.getFontMetric();
>>
>> height = simpleFontMetric.Ascent +
>> simpleFontMetric.Descent +
>> simpleFontMetric.Leading;
>>
>> break;
>> }
>> }
>> Object shape = xWriterFactory_tmp.createInstance(
>> "com.sun.star.drawing.RectangleShape");
>>
>> XShape xShape = (XShape) UnoRuntime.queryInterface(
>> XShape.class, shape);
>>
>> xShape.setPosition(new Point(pageBorderLeft, pageBorderTop));
>>
>> int nwidth = (int)(((float)width / (float)72) * (float)2540)
>> +
>> 50; // This is what I use to convert, which works on the MAC.
>> int nheight = (int)(((float)height / (float)72) *
>> (float)2540)
>> + 50; // This is what I use to convert, which works on the MAC.
>>
>> System.out.println("New Height: " + nheight);
>> System.out.println("New Width: " + nwidth);
>>
>> xShape.setSize(new Size(nwidth, nheight));
>>
>> Now the above code works hapilly on my Apple Laptop, but when I move the
>> same code over to OpenSolaris and the width calculation is way off....
>> the
>> font is either larger or smaller depending on the height size of the
>> font.
>>
>> Any advice or help, much appreciated.
>
> did you try css.awt.XUnitConversion ?
> http://api.openoffice.org/docs/common/ref/com/sun/star/awt/XUnitConversion.html
>
> see the macros in the doc attached to
> http://www.openoffice.org/issues/show_bug.cgi?id=94067
>
> Regards
> --
> Ariel Constenla-Haile
> La Plata, Argentina
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>
>
--
View this message in context:
http://old.nabble.com/Please-Help%3A-Getting-the-width---height-sizes-to-create-a-RectangleShape-to-create-a-boundary-box-tp27152636p27155936.html
Sent from the openoffice - dev mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]