1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: util.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
34 #include <com/sun/star/awt/Point.hpp>
35 #include <com/sun/star/awt/Rectangle.hpp>
36 #include <com/sun/star/beans/XPropertySet.hpp>
37 #include <com/sun/star/drawing/BitmapMode.hpp>
38 #include <com/sun/star/drawing/FillStyle.hpp>
39 #include <com/sun/star/drawing/HomogenMatrix3.hpp>
40 #include <com/sun/star/text/TextContentAnchorType.hpp>
41 #include <resourcemodel/WW8ResourceModel.hxx>
42 #include <resourcemodel/TagLogger.hxx>
44 namespace writerfilter
46 using namespace com::sun::star
;
48 using text::TextContentAnchorType
;
50 static string
& logger_file()
52 static string _logger_file
= string(getenv("TEMP")?getenv("TEMP"):"/tmp") + "/writerfilter.ooxml.tmp";
56 static ofstream
& logger_stream()
58 static ofstream
_logger_stream(logger_file().c_str());
59 return _logger_stream
;
63 void logger(string prefix
, string message
)
65 logger_stream() << prefix
<< ":" << message
<< endl
;
66 logger_stream().flush();
69 string
propertysetToString(uno::Reference
<beans::XPropertySet
> const & xPropSet
)
73 static int nAttribNames
= 9;
74 static string sPropertyAttribNames
[9] =
87 static const ::rtl::OUString
sMetaFile(RTL_CONSTASCII_USTRINGPARAM("MetaFile"));
89 uno::Reference
<beans::XPropertySetInfo
> xPropSetInfo
90 (xPropSet
->getPropertySetInfo());
92 if (xPropSetInfo
.is())
94 uno::Sequence
<beans::Property
> aProps(xPropSetInfo
->getProperties());
96 sResult
+="<propertyset>";
98 for (sal_Int32 n
= 0; n
< aProps
.getLength(); n
++)
100 ::rtl::OUString
sPropName(aProps
[n
].Name
);
102 if (xPropSetInfo
->hasPropertyByName(sPropName
))
104 bool bPropertyFound
= true;
108 if (sPropName
== sMetaFile
)
109 bPropertyFound
= false;
111 xPropSet
->getPropertyValue(sPropName
) >>= aAny
;
113 catch (beans::UnknownPropertyException
)
115 bPropertyFound
= false;
120 sResult
+= "<property name=\"";
121 sResult
+= OUStringToOString
122 (sPropName
, RTL_TEXTENCODING_ASCII_US
).getStr();
123 sResult
+="\" type=\"";
125 ::rtl::OUString
sPropType(aProps
[n
].Type
.getTypeName());
126 sResult
+= OUStringToOString
127 (sPropType
, RTL_TEXTENCODING_ASCII_US
).getStr();
129 sResult
+= "\" attribs=\"";
131 sal_uInt16 nMask
= 1;
132 bool bFirstAttrib
= true;
133 sal_uInt16 nAttribs
= aProps
[n
].Attributes
;
134 for (int i
= 0; i
< nAttribNames
; i
++)
136 if ((nAttribs
& nMask
) != 0)
139 bFirstAttrib
= false;
143 sResult
+= sPropertyAttribNames
[i
];
153 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM
159 snprintf(buffer
, sizeof(buffer
), "%d", nValue
);
163 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM
166 sal_Int16 nValue
= 0;
169 snprintf(buffer
, sizeof(buffer
), "%d", nValue
);
172 else if (sPropType
==
173 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM
176 sal_Int32 nValue
= 0;
179 snprintf(buffer
, sizeof(buffer
), "%" SAL_PRIdINT32
, nValue
);
182 else if (sPropType
==
183 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM
189 snprintf(buffer
, sizeof(buffer
), "%f", nValue
);
192 else if (sPropType
==
193 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM
199 snprintf(buffer
, sizeof(buffer
), "%lf", nValue
);
202 else if (sPropType
==
203 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM
206 sal_Bool nValue
= sal_False
;
214 else if (sPropType
==
215 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM
218 ::rtl::OUString sValue
;
221 sResult
+= OUStringToOString
222 (sValue
, RTL_TEXTENCODING_ASCII_US
).getStr();
224 else if (sPropType
==
226 (RTL_CONSTASCII_USTRINGPARAM
227 ("com.sun.star.text.TextContentAnchorType")))
229 text::TextContentAnchorType nValue
;
234 case text::TextContentAnchorType_AT_PARAGRAPH
:
235 sResult
+= "AT_PARAGRAPH";
237 case text::TextContentAnchorType_AS_CHARACTER
:
238 sResult
+= "AS_CHARACTER";
240 case text::TextContentAnchorType_AT_PAGE
:
241 sResult
+= "AT_PAGE";
243 case text::TextContentAnchorType_AT_FRAME
:
244 sResult
+= "AT_FRAME";
246 case text::TextContentAnchorType_AT_CHARACTER
:
247 sResult
+= "AT_CHARACTER";
249 case text::TextContentAnchorType_MAKE_FIXED_SIZE
:
250 sResult
+= "MAKE_FIXED_SIZE";
256 else if (sPropType
==
258 (RTL_CONSTASCII_USTRINGPARAM
259 ("com.sun.star.awt.Point")))
264 snprintf(buffer
, sizeof(buffer
), "(%" SAL_PRIdINT32
", %" SAL_PRIdINT32
")", aPoint
.X
,
269 else if (sPropType
==
271 (RTL_CONSTASCII_USTRINGPARAM
272 ("com.sun.star.awt.Rectangle")))
274 awt::Rectangle aRect
;
277 snprintf(buffer
, sizeof(buffer
), "(%" SAL_PRIdINT32
", %" SAL_PRIdINT32
", %" SAL_PRIdINT32
", %" SAL_PRIdINT32
")",
278 aRect
.X
, aRect
.Y
, aRect
.Width
, aRect
.Height
);
281 else if (sPropType
==
283 (RTL_CONSTASCII_USTRINGPARAM
284 ("com.sun.star.drawing.FillStyle")))
286 drawing::FillStyle nValue
;
291 case drawing::FillStyle_NONE
:
294 case drawing::FillStyle_SOLID
:
297 case drawing::FillStyle_GRADIENT
:
298 sResult
+= "GRADIENT";
300 case drawing::FillStyle_HATCH
:
303 case drawing::FillStyle_BITMAP
:
306 case drawing::FillStyle_MAKE_FIXED_SIZE
:
307 sResult
+= "MAKE_FIXED_SIZE";
311 else if (sPropType
==
313 (RTL_CONSTASCII_USTRINGPARAM
314 ("com.sun.star.drawing.BitmapMode")))
316 drawing::BitmapMode nValue
;
321 case drawing::BitmapMode_REPEAT
:
324 case drawing::BitmapMode_STRETCH
:
325 sResult
+= "STRETCH";
327 case drawing::BitmapMode_NO_REPEAT
:
328 sResult
+= "NO_REPEAT";
330 case drawing::BitmapMode_MAKE_FIXED_SIZE
:
331 sResult
+= "MAKE_FIXED_SIZE";
335 else if (sPropType
==
337 (RTL_CONSTASCII_USTRINGPARAM
338 ("com.sun.star.drawing.HomogenMatrix3")))
340 drawing::HomogenMatrix3 aMatrix
;
343 snprintf(buffer
, sizeof(buffer
),
344 "((%f %f %f)(%f %f %f)(%f %f %f))",
345 aMatrix
.Line1
.Column1
,
346 aMatrix
.Line1
.Column2
,
347 aMatrix
.Line1
.Column3
,
348 aMatrix
.Line2
.Column1
,
349 aMatrix
.Line2
.Column2
,
350 aMatrix
.Line2
.Column3
,
351 aMatrix
.Line3
.Column1
,
352 aMatrix
.Line3
.Column2
,
353 aMatrix
.Line3
.Column3
);
357 sResult
+= "</property>";
362 sResult
+= "<unknown-property>";
363 sResult
+= OUStringToOString
364 (sPropName
, RTL_TEXTENCODING_ASCII_US
).getStr();
365 sResult
+= "</unknown-property>";
368 sResult
+= "</propertyset>";
373 string
xmlify(const string
& str
)
378 for (string::const_iterator aIt
= str
.begin(); aIt
!= str
.end(); ++aIt
)
382 if (isprint(c
) && c
!= '\"')
395 snprintf(sBuffer
, sizeof(sBuffer
), "\\%03d", c
);