Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * Version: MPL 1.1 / GPLv3+ / LGPLv3+
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Initial Developer of the Original Code is
16 : * Novell Inc.
17 : * Portions created by the Initial Developer are Copyright (C) 2010 the
18 : * Initial Developer. All Rights Reserved.
19 : *
20 : * Contributor(s): Florian Reuter <freuter@novell.com>
21 : * Cedric Bosdonnat <cbosdonnat@novell.com>
22 : *
23 : * Alternatively, the contents of this file may be used under the terms of
24 : * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
25 : * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
26 : * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
27 : * instead of those above.
28 : */
29 :
30 : #include "frame.hxx"
31 : #include "frmfmt.hxx"
32 : #include "sectfrm.hxx"
33 : #include "tabfrm.hxx"
34 : #include "txtfrm.hxx"
35 : #include "hffrm.hxx"
36 : #include "porlin.hxx"
37 : #include "porlay.hxx"
38 : #include "portxt.hxx"
39 : #include "sortedobjs.hxx"
40 : #include <anchoredobject.hxx>
41 : #include <libxml/xmlwriter.h>
42 : #include <SwPortionHandler.hxx>
43 :
44 : class XmlPortionDumper:public SwPortionHandler
45 : {
46 : private:
47 : xmlTextWriterPtr writer;
48 : sal_uInt16 ofs;
49 :
50 11 : const char* getTypeName( sal_uInt16 nType )
51 : {
52 11 : switch ( nType )
53 : {
54 0 : case POR_LIN: return "POR_LIN";
55 1 : case POR_FLYCNT: return "POR_FLYCNT";
56 :
57 0 : case POR_HOLE: return "POR_HOLE";
58 0 : case POR_TMPEND: return "POR_TMPEND";
59 0 : case POR_BRK: return "POR_BRK";
60 0 : case POR_KERN: return "POR_KERN";
61 0 : case POR_ARROW: return "POR_ARROW";
62 0 : case POR_MULTI: return "POR_MULTI";
63 0 : case POR_HIDDEN_TXT: return "POR_HIDDEN_TXT";
64 0 : case POR_CONTROLCHAR: return "POR_CONTROLCHAR";
65 :
66 1 : case POR_TXT: return "POR_TXT";
67 0 : case POR_LAY: return "POR_LAY";
68 7 : case POR_PARA: return "POR_PARA";
69 0 : case POR_URL: return "POR_URL";
70 0 : case POR_HNG: return "POR_HNG";
71 :
72 0 : case POR_DROP: return "POR_DROP";
73 0 : case POR_TOX: return "POR_TOX";
74 0 : case POR_ISOTOX: return "POR_ISOTOX";
75 0 : case POR_REF: return "POR_REF";
76 0 : case POR_ISOREF: return "POR_ISOREF";
77 0 : case POR_META: return "POR_META";
78 :
79 0 : case POR_EXP: return "POR_EXP";
80 0 : case POR_BLANK: return "POR_BLANK";
81 0 : case POR_POSTITS: return "POR_POSTITS";
82 :
83 0 : case POR_HYPH: return "POR_HYPH";
84 0 : case POR_HYPHSTR: return "POR_HYPHSTR";
85 0 : case POR_SOFTHYPH: return "POR_SOFTHYPH";
86 0 : case POR_SOFTHYPHSTR: return "POR_SOFTHYPHSTR";
87 0 : case POR_SOFTHYPH_COMP: return "POR_SOFTHYPH_COMP";
88 :
89 0 : case POR_FLD: return "POR_FLD";
90 0 : case POR_HIDDEN: return "POR_HIDDEN";
91 0 : case POR_QUOVADIS: return "POR_QUOVADIS";
92 0 : case POR_ERGOSUM: return "POR_ERGOSUM";
93 0 : case POR_COMBINED: return "POR_COMBINED";
94 0 : case POR_FTN: return "POR_FTN";
95 :
96 0 : case POR_FTNNUM: return "POR_FTNNUM";
97 1 : case POR_NUMBER: return "POR_NUMBER";
98 0 : case POR_BULLET: return "POR_BULLET";
99 0 : case POR_GRFNUM: return "POR_GRFNUM";
100 :
101 0 : case POR_GLUE: return "POR_GLUE";
102 :
103 0 : case POR_MARGIN: return "POR_MARGIN";
104 :
105 0 : case POR_FIX: return "POR_FIX";
106 0 : case POR_FLY: return "POR_FLY";
107 :
108 0 : case POR_TAB: return "POR_TAB";
109 :
110 0 : case POR_TABRIGHT: return "POR_TABRIGHT";
111 0 : case POR_TABCENTER: return "POR_TABCENTER";
112 0 : case POR_TABDECIMAL: return "POR_TABDECIMAL";
113 :
114 1 : case POR_TABLEFT: return "POR_TABLEFT";
115 : default:
116 0 : return "Unknown";
117 : }
118 : }
119 :
120 : public:
121 :
122 35 : XmlPortionDumper( xmlTextWriterPtr some_writer ):writer( some_writer ), ofs( 0 )
123 : {
124 35 : }
125 :
126 35 : virtual ~ XmlPortionDumper( )
127 35 : {
128 35 : }
129 :
130 : /**
131 : @param nLength
132 : length of this portion in the model string
133 : @param rText
134 : text which is painted on-screen
135 : */
136 9 : virtual void Text( sal_uInt16 nLength,
137 : sal_uInt16 nType,
138 : sal_Int32 nHeight,
139 : sal_Int32 nWidth)
140 : {
141 9 : ofs += nLength;
142 9 : xmlTextWriterStartElement( writer, BAD_CAST( "Text" ) );
143 : xmlTextWriterWriteFormatAttribute( writer,
144 : BAD_CAST( "nLength" ),
145 9 : "%i", ( int ) nLength );
146 : xmlTextWriterWriteFormatAttribute( writer,
147 : BAD_CAST( "nType" ),
148 9 : "%s", getTypeName( nType ) );
149 9 : if (nHeight > 0)
150 8 : xmlTextWriterWriteFormatAttribute(writer, BAD_CAST("nHeight"), "%i", (int)nHeight);
151 9 : if (nWidth > 0)
152 7 : xmlTextWriterWriteFormatAttribute(writer, BAD_CAST("nWidth"), "%i", (int)nWidth);
153 :
154 9 : xmlTextWriterEndElement( writer );
155 9 : }
156 :
157 : /**
158 : @param nLength
159 : length of this portion in the model string
160 : @param rText
161 : text which is painted on-screen
162 : @param nType
163 : type of this portion
164 : @param nHeight
165 : font size of the painted text
166 : */
167 2 : virtual void Special( sal_uInt16 nLength,
168 : const String & rText,
169 : sal_uInt16 nType,
170 : sal_Int32 nHeight,
171 : sal_Int32 nWidth )
172 : {
173 2 : xmlTextWriterStartElement( writer, BAD_CAST( "Special" ) );
174 : xmlTextWriterWriteFormatAttribute( writer,
175 : BAD_CAST( "nLength" ),
176 2 : "%i", ( int ) nLength );
177 : xmlTextWriterWriteFormatAttribute( writer,
178 : BAD_CAST( "nType" ),
179 2 : "%s", getTypeName( nType ) );
180 2 : OUString sText( rText );
181 : OString sText8 =::rtl::OUStringToOString( sText,
182 2 : RTL_TEXTENCODING_UTF8 );
183 : xmlTextWriterWriteFormatAttribute( writer, BAD_CAST( "rText" ),
184 2 : "%s", sText8.getStr( ) );
185 :
186 2 : if (nHeight > 0)
187 2 : xmlTextWriterWriteFormatAttribute(writer, BAD_CAST("nHeight"), "%i", (int)nHeight);
188 :
189 2 : if (nWidth > 0)
190 1 : xmlTextWriterWriteFormatAttribute(writer, BAD_CAST("nWidth"), "%i", (int)nWidth);
191 :
192 2 : xmlTextWriterEndElement( writer );
193 2 : ofs += nLength;
194 2 : }
195 :
196 9 : virtual void LineBreak( )
197 : {
198 9 : xmlTextWriterStartElement( writer, BAD_CAST( "LineBreak" ) );
199 9 : xmlTextWriterEndElement( writer );
200 9 : }
201 :
202 : /**
203 : * @param nLength
204 : * number of 'model string' characters to be skipped
205 : */
206 0 : virtual void Skip( sal_uInt16 nLength )
207 : {
208 0 : xmlTextWriterStartElement( writer, BAD_CAST( "Skip" ) );
209 : xmlTextWriterWriteFormatAttribute( writer,
210 : BAD_CAST( "nLength" ),
211 0 : "%i", ( int ) nLength );
212 0 : xmlTextWriterEndElement( writer );
213 0 : ofs += nLength;
214 0 : }
215 :
216 35 : virtual void Finish( )
217 : {
218 35 : xmlTextWriterStartElement( writer, BAD_CAST( "Finish" ) );
219 35 : xmlTextWriterEndElement( writer );
220 35 : }
221 :
222 : };
223 :
224 : namespace
225 : {
226 0 : xmlTextWriterPtr lcl_createDefaultWriter()
227 : {
228 0 : xmlTextWriterPtr writer = xmlNewTextWriterFilename( "layout.xml", 0 );
229 0 : xmlTextWriterStartDocument( writer, NULL, NULL, NULL );
230 0 : return writer;
231 : }
232 :
233 0 : void lcl_freeWriter( xmlTextWriterPtr writer )
234 : {
235 0 : xmlTextWriterEndDocument( writer );
236 0 : xmlFreeTextWriter( writer );
237 0 : }
238 : }
239 :
240 80 : void SwFrm::dumpAsXml( xmlTextWriterPtr writer )
241 : {
242 80 : bool bCreateWriter = ( NULL == writer );
243 80 : if ( bCreateWriter )
244 0 : writer = lcl_createDefaultWriter();
245 :
246 80 : const char *name = NULL;
247 :
248 80 : switch ( GetType( ) )
249 : {
250 : case FRM_ROOT:
251 4 : name = "root";
252 4 : break;
253 : case FRM_PAGE:
254 11 : name = "page";
255 11 : break;
256 : case FRM_COLUMN:
257 0 : name = "column";
258 0 : break;
259 : case FRM_HEADER:
260 6 : name = "header";
261 6 : break;
262 : case FRM_FOOTER:
263 6 : name = "footer";
264 6 : break;
265 : case FRM_FTNCONT:
266 0 : name = "ftncont";
267 0 : break;
268 : case FRM_FTN:
269 0 : name = "ftn";
270 0 : break;
271 : case FRM_BODY:
272 11 : name = "body";
273 11 : break;
274 : case FRM_FLY:
275 6 : name = "fly";
276 6 : break;
277 : case FRM_SECTION:
278 1 : name = "section";
279 1 : break;
280 : case FRM_UNUSED:
281 0 : name = "unused";
282 0 : break;
283 : case FRM_TAB:
284 0 : name = "tab";
285 0 : break;
286 : case FRM_ROW:
287 0 : name = "row";
288 0 : break;
289 : case FRM_CELL:
290 0 : name = "cell";
291 0 : break;
292 : case FRM_TXT:
293 35 : name = "txt";
294 35 : break;
295 : case FRM_NOTXT:
296 0 : name = "notxt";
297 0 : break;
298 : };
299 :
300 80 : if ( name != NULL )
301 : {
302 80 : xmlTextWriterStartElement( writer, ( const xmlChar * ) name );
303 :
304 80 : dumpAsXmlAttributes( writer );
305 :
306 80 : xmlTextWriterStartElement( writer, BAD_CAST( "infos" ) );
307 80 : dumpInfosAsXml( writer );
308 80 : xmlTextWriterEndElement( writer );
309 :
310 : // Dump Anchored objects if any
311 80 : SwSortedObjs* pAnchored = GetDrawObjs();
312 80 : if ( pAnchored && pAnchored->Count( ) > 0 )
313 : {
314 7 : xmlTextWriterStartElement( writer, BAD_CAST( "anchored" ) );
315 :
316 14 : for ( sal_uInt32 i = 0, len = pAnchored->Count(); i < len; i++ )
317 : {
318 7 : SwAnchoredObject* pObject = (*pAnchored)[i];
319 7 : pObject->dumpAsXml( writer );
320 : }
321 :
322 7 : xmlTextWriterEndElement( writer );
323 : }
324 :
325 : // Dump the children
326 80 : if ( IsTxtFrm( ) )
327 : {
328 35 : SwTxtFrm *pTxtFrm = ( SwTxtFrm * ) this;
329 35 : OUString aTxt = pTxtFrm->GetTxt( );
330 1155 : for ( int i = 0; i < 32; i++ )
331 : {
332 1120 : aTxt = aTxt.replace( i, '*' );
333 : }
334 : OString aTxt8 =::rtl::OUStringToOString( aTxt,
335 35 : RTL_TEXTENCODING_UTF8 );
336 : xmlTextWriterWriteString( writer,
337 35 : ( const xmlChar * ) aTxt8.getStr( ) );
338 35 : XmlPortionDumper pdumper( writer );
339 35 : pTxtFrm->VisitPortions( pdumper );
340 :
341 : }
342 : else
343 : {
344 45 : dumpChildrenAsXml( writer );
345 : }
346 80 : xmlTextWriterEndElement( writer );
347 : }
348 :
349 80 : if ( bCreateWriter )
350 0 : lcl_freeWriter( writer );
351 80 : }
352 :
353 80 : void SwFrm::dumpInfosAsXml( xmlTextWriterPtr writer )
354 : {
355 : // output the Frm
356 80 : xmlTextWriterStartElement( writer, BAD_CAST( "bounds" ) );
357 80 : xmlTextWriterWriteFormatAttribute( writer, BAD_CAST( "left" ), "%ld", Frm().Left() );
358 80 : xmlTextWriterWriteFormatAttribute( writer, BAD_CAST( "top" ), "%ld", Frm().Top() );
359 80 : xmlTextWriterWriteFormatAttribute( writer, BAD_CAST( "width" ), "%ld", Frm().Width() );
360 80 : xmlTextWriterWriteFormatAttribute( writer, BAD_CAST( "height" ), "%ld", Frm().Height() );
361 80 : xmlTextWriterEndElement( writer );
362 80 : }
363 :
364 80 : void SwFrm::dumpAsXmlAttributes( xmlTextWriterPtr writer )
365 : {
366 80 : xmlTextWriterWriteFormatAttribute( writer, BAD_CAST( "ptr" ), "%p", this );
367 80 : xmlTextWriterWriteFormatAttribute( writer, BAD_CAST( "id" ), "%" SAL_PRIuUINT32, GetFrmId() );
368 80 : xmlTextWriterWriteFormatAttribute( writer, BAD_CAST( "symbol" ), "%s", BAD_CAST( typeid( *this ).name( ) ) );
369 80 : if ( GetNext( ) )
370 25 : xmlTextWriterWriteFormatAttribute( writer, BAD_CAST( "next" ), "%" SAL_PRIuUINT32, GetNext()->GetFrmId() );
371 80 : if ( GetPrev( ) )
372 25 : xmlTextWriterWriteFormatAttribute( writer, BAD_CAST( "prev" ), "%" SAL_PRIuUINT32, GetPrev()->GetFrmId() );
373 80 : if ( GetUpper( ) )
374 70 : xmlTextWriterWriteFormatAttribute( writer, BAD_CAST( "upper" ), "%" SAL_PRIuUINT32, GetUpper()->GetFrmId() );
375 80 : if ( GetLower( ) )
376 45 : xmlTextWriterWriteFormatAttribute( writer, BAD_CAST( "lower" ), "%" SAL_PRIuUINT32, GetLower()->GetFrmId() );
377 80 : if ( IsTxtFrm( ) )
378 : {
379 35 : SwTxtFrm *pTxtFrm = ( SwTxtFrm * ) this;
380 35 : SwTxtNode *pTxtNode = pTxtFrm->GetTxtNode();
381 35 : xmlTextWriterWriteFormatAttribute( writer, BAD_CAST( "txtNodeIndex" ), "%lu", pTxtNode->GetIndex() );
382 : }
383 80 : if (IsHeaderFrm() || IsFooterFrm())
384 : {
385 12 : SwHeadFootFrm *pHeadFootFrm = (SwHeadFootFrm*)this;
386 12 : OUString aFmtName = pHeadFootFrm->GetFmt()->GetName();
387 12 : xmlTextWriterWriteFormatAttribute( writer, BAD_CAST( "fmtName" ), "%s", BAD_CAST(rtl::OUStringToOString(aFmtName, RTL_TEXTENCODING_UTF8).getStr()));
388 12 : xmlTextWriterWriteFormatAttribute( writer, BAD_CAST( "fmtPtr" ), "%p", pHeadFootFrm->GetFmt());
389 : }
390 80 : }
391 :
392 45 : void SwFrm::dumpChildrenAsXml( xmlTextWriterPtr writer )
393 : {
394 45 : SwFrm *pFrm = GetLower( );
395 115 : for ( ; pFrm != NULL; pFrm = pFrm->GetNext( ) )
396 : {
397 70 : pFrm->dumpAsXml( writer );
398 : }
399 45 : }
400 :
401 1 : void SwAnchoredObject::dumpAsXml( xmlTextWriterPtr writer )
402 : {
403 1 : bool bCreateWriter = ( NULL == writer );
404 1 : if ( bCreateWriter )
405 0 : writer = lcl_createDefaultWriter();
406 :
407 1 : xmlTextWriterStartElement( writer, BAD_CAST( getElementName() ) );
408 1 : xmlTextWriterWriteFormatAttribute( writer, BAD_CAST( "ptr" ), "%p", this );
409 1 : xmlTextWriterEndElement( writer );
410 :
411 1 : if ( bCreateWriter )
412 0 : lcl_freeWriter( writer );
413 1 : }
414 :
415 35 : void SwTxtFrm::dumpAsXmlAttributes( xmlTextWriterPtr writer )
416 : {
417 35 : SwFrm::dumpAsXmlAttributes( writer );
418 35 : if ( HasFollow() )
419 0 : xmlTextWriterWriteFormatAttribute( writer, BAD_CAST( "follow" ), "%" SAL_PRIuUINT32, GetFollow()->GetFrmId() );
420 :
421 35 : if (m_pPrecede != NULL)
422 0 : xmlTextWriterWriteFormatAttribute( writer, BAD_CAST( "precede" ), "%" SAL_PRIuUINT32, static_cast<SwTxtFrm*>(m_pPrecede)->GetFrmId() );
423 35 : }
424 :
425 1 : void SwSectionFrm::dumpAsXmlAttributes( xmlTextWriterPtr writer )
426 : {
427 1 : SwFrm::dumpAsXmlAttributes( writer );
428 1 : if ( HasFollow() )
429 0 : xmlTextWriterWriteFormatAttribute( writer, BAD_CAST( "follow" ), "%" SAL_PRIuUINT32, GetFollow()->GetFrmId() );
430 :
431 1 : if (m_pPrecede != NULL)
432 0 : xmlTextWriterWriteFormatAttribute( writer, BAD_CAST( "precede" ), "%" SAL_PRIuUINT32, static_cast<SwSectionFrm*>( m_pPrecede )->GetFrmId() );
433 1 : }
434 :
435 0 : void SwTabFrm::dumpAsXmlAttributes( xmlTextWriterPtr writer )
436 : {
437 0 : SwFrm::dumpAsXmlAttributes( writer );
438 0 : if ( HasFollow() )
439 0 : xmlTextWriterWriteFormatAttribute( writer, BAD_CAST( "follow" ), "%" SAL_PRIuUINT32, GetFollow()->GetFrmId() );
440 :
441 0 : if (m_pPrecede != NULL)
442 0 : xmlTextWriterWriteFormatAttribute( writer, BAD_CAST( "precede" ), "%" SAL_PRIuUINT32, static_cast<SwTabFrm*>( m_pPrecede )->GetFrmId() );
443 0 : }
444 :
445 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|