stylefactory.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2003 Percy Leonhardt
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#include "stylefactory.h"
21
22#include <tqcolor.h>
23#include <tqdatetime.h>
24#include <KoUnit.h>
25#include <kdebug.h>
26
27StyleFactory::StyleFactory()
28{
29 m_strokeDashStyles.setAutoDelete( true );
30 m_gradientStyles.setAutoDelete( true );
31 m_hatchStyles.setAutoDelete( true );
32 m_markerStyles.setAutoDelete( true );
33 m_fillImageStyles.setAutoDelete( true );
34 m_listStyles.setAutoDelete( true );
35 m_pageStyles.setAutoDelete( true );
36 m_textStyles.setAutoDelete( true );
37 m_graphicStyles.setAutoDelete( true );
38 m_paragraphStyles.setAutoDelete( true );
39 m_pageMasterStyles.setAutoDelete( true );
40
41 // create standard graphic style
42 GraphicStyle * graphicStyle;
43 graphicStyle = new GraphicStyle ( "standard", "solid", "0cm", "0x000000",
44 "hidden", "0.3cm", "0.3cm", "0x808080",
45 "0cm", "0cm", "0cm", "0cm", "0x000000",
46 "false", "none", "Thorndale", "24pt",
47 "normal", "none", "none", "normal",
48 "100%", "start", "solid", "0x00b8ff",
49 "false" );
50
51 m_graphicStyles.append( graphicStyle );
52}
53
54StyleFactory::~StyleFactory()
55{
56}
57
58void StyleFactory::addOfficeStyles( TQDomDocument & doc, TQDomElement & styles )
59{
60 StrokeDashStyle * sd;
61 for ( sd = m_strokeDashStyles.first(); sd ; sd = m_strokeDashStyles.next() )
62 sd->toXML( doc, styles );
63
64 GradientStyle * g;
65 for ( g = m_gradientStyles.first(); g ; g = m_gradientStyles.next() )
66 g->toXML( doc, styles );
67
68 MarkerStyle * m;
69 for ( m = m_markerStyles.first(); m ; m = m_markerStyles.next() )
70 m->toXML( doc, styles );
71
72 HatchStyle * h;
73 for ( h = m_hatchStyles.first(); h ; h = m_hatchStyles.next() )
74 h->toXML( doc, styles );
75
76 GraphicStyle * gr;
77 gr = m_graphicStyles.first(); // skip the "standard" style
78 gr->toXML( doc, styles );
79}
80
81void StyleFactory::addOfficeMaster( TQDomDocument & doc, TQDomElement & master )
82{
83 PageMasterStyle * p;
84 for ( p = m_pageMasterStyles.first(); p ; p = m_pageMasterStyles.next() )
85 {
86 TQDomElement masterPage = doc.createElement( "style:master-page" );
87 masterPage.setAttribute( "style:name", p->style() );
88 masterPage.setAttribute( "style:page-master-name", p->name() );
89 masterPage.setAttribute( "draw:style-name", "dp1" );
90 master.appendChild( masterPage );
91 }
92}
93
94void StyleFactory::addOfficeAutomatic( TQDomDocument & doc, TQDomElement & automatic )
95{
96 PageMasterStyle * p;
97 for ( p = m_pageMasterStyles.first(); p ; p = m_pageMasterStyles.next() )
98 {
99 p->toXML( doc, automatic );
100 }
101}
102
103void StyleFactory::addAutomaticStyles( TQDomDocument & doc, TQDomElement & autoStyles )
104{
105 ListStyle * l;
106 for ( l = m_listStyles.first(); l ; l = m_listStyles.next() )
107 l->toXML( doc, autoStyles );
108
109 PageStyle * p;
110 for ( p = m_pageStyles.first(); p ; p = m_pageStyles.next() )
111 p->toXML( doc, autoStyles );
112
113 TextStyle * t;
114 for ( t = m_textStyles.first(); t ; t = m_textStyles.next() )
115 t->toXML( doc, autoStyles );
116
117 GraphicStyle * g;
118 g = m_graphicStyles.first(); // skip the "standard" style
119 for ( g = m_graphicStyles.next(); g ; g = m_graphicStyles.next() )
120 g->toXML( doc, autoStyles );
121
122 ParagraphStyle * pg;
123 for ( pg = m_paragraphStyles.first(); pg ; pg = m_paragraphStyles.next() )
124 pg->toXML( doc, autoStyles );
125}
126
127TQString StyleFactory::createStrokeDashStyle( int style )
128{
129 StrokeDashStyle * newStrokeDashStyle, * sd;
130 newStrokeDashStyle = new StrokeDashStyle( style );
131 for ( sd = m_strokeDashStyles.first(); sd ; sd = m_strokeDashStyles.next() )
132 {
133 if ( sd->name() == newStrokeDashStyle->name() )
134 {
135 delete newStrokeDashStyle;
136 return sd->name();
137 }
138 }
139
140 m_strokeDashStyles.append( newStrokeDashStyle );
141 return newStrokeDashStyle->name();
142}
143
144TQString StyleFactory::createGradientStyle( TQDomElement & gradient )
145{
146 GradientStyle * newGradientStyle, * g;
147 newGradientStyle = new GradientStyle( gradient, m_gradientStyles.count() + 1 );
148 for ( g = m_gradientStyles.first(); g ; g = m_gradientStyles.next() )
149 {
150 if ( g->name() == newGradientStyle->name() )
151 {
152 delete newGradientStyle;
153 return g->name();
154 }
155 }
156
157 m_gradientStyles.append( newGradientStyle );
158 return newGradientStyle->name();
159}
160
161TQString StyleFactory::createMarkerStyle( int style )
162{
163 MarkerStyle * newMarkerStyle, * m;
164 newMarkerStyle = new MarkerStyle( style );
165 for ( m = m_markerStyles.first(); m ; m = m_markerStyles.next() )
166 {
167 if ( m->name() == newMarkerStyle->name() )
168 {
169 delete newMarkerStyle;
170 return m->name();
171 }
172 }
173
174 m_markerStyles.append( newMarkerStyle );
175 return newMarkerStyle->name();
176}
177
178TQString StyleFactory::createHatchStyle( int style, TQString & color )
179{
180 HatchStyle * newHatchStyle, * h;
181 newHatchStyle = new HatchStyle( style, color );
182 for ( h = m_hatchStyles.first(); h ; h = m_hatchStyles.next() )
183 {
184 if ( h->name() == newHatchStyle->name() )
185 {
186 delete newHatchStyle;
187 return h->name();
188 }
189 }
190
191 m_hatchStyles.append( newHatchStyle );
192 return newHatchStyle->name();
193}
194
195TQString StyleFactory::createListStyle( TQDomElement & e )
196{
197 ListStyle * newListStyle, * l;
198 newListStyle = new ListStyle( e, m_listStyles.count() + 1 );
199 for ( l = m_listStyles.first(); l ; l = m_listStyles.next() )
200 {
201 if ( *l == *newListStyle )
202 {
203 delete newListStyle;
204 return l->name();
205 }
206 }
207
208 m_listStyles.append( newListStyle );
209 return newListStyle->name();
210}
211
212TQString StyleFactory::createPageStyle( TQDomElement & e )
213{
214 PageStyle * newPageStyle, * p;
215 newPageStyle = new PageStyle( this, e, m_pageStyles.count() + 1 );
216 for ( p = m_pageStyles.first(); p ; p = m_pageStyles.next() )
217 {
218 if ( *p == *newPageStyle )
219 {
220 delete newPageStyle;
221 return p->name();
222 }
223 }
224
225 m_pageStyles.append( newPageStyle );
226 return newPageStyle->name();
227}
228
229TQString StyleFactory::createTextStyle( TQDomElement & e )
230{
231 TextStyle * newTextStyle, * t;
232 newTextStyle = new TextStyle( e, m_textStyles.count() + 1 );
233 for ( t = m_textStyles.first(); t ; t = m_textStyles.next() )
234 {
235 if ( *t == *newTextStyle )
236 {
237 delete newTextStyle;
238 return t->name();
239 }
240 }
241
242 m_textStyles.append( newTextStyle );
243 return newTextStyle->name();
244}
245
246TQString StyleFactory::createGraphicStyle( TQDomElement & e )
247{
248 GraphicStyle * newGraphicStyle, * g;
249 newGraphicStyle = new GraphicStyle( this, e, m_graphicStyles.count() );
250 for ( g = m_graphicStyles.first(); g ; g = m_graphicStyles.next() )
251 {
252 if ( *g == *newGraphicStyle )
253 {
254 delete newGraphicStyle;
255 return g->name();
256 }
257 }
258
259 m_graphicStyles.append( newGraphicStyle );
260 return newGraphicStyle->name();
261}
262
263TQString StyleFactory::createParagraphStyle( TQDomElement & e )
264{
265 ParagraphStyle * newParagraphStyle, * p;
266 newParagraphStyle = new ParagraphStyle( e, m_paragraphStyles.count() + 1 );
267 for ( p = m_paragraphStyles.first(); p ; p = m_paragraphStyles.next() )
268 {
269 if ( *p == *newParagraphStyle )
270 {
271 delete newParagraphStyle;
272 return p->name();
273 }
274 }
275
276 m_paragraphStyles.append( newParagraphStyle );
277 return newParagraphStyle->name();
278}
279
280TQString StyleFactory::createPageMasterStyle( TQDomElement & e )
281{
282 PageMasterStyle * newPMStyle, * p;
283 newPMStyle = new PageMasterStyle( e, m_pageMasterStyles.count() );
284 for ( p = m_pageMasterStyles.first(); p ; p = m_pageMasterStyles.next() )
285 {
286 if ( *p == *newPMStyle )
287 {
288 delete newPMStyle;
289 return p->style();
290 }
291 }
292
293 m_pageMasterStyles.append( newPMStyle );
294 return newPMStyle->style();
295}
296
297TQString StyleFactory::toCM( const TQString & point )
298{
299 double pt = point.toFloat();
300 double cm = KoUnit::toCM( pt );
301 return TQString( "%1cm" ).arg ( cm );
302}
303
304StrokeDashStyle::StrokeDashStyle( int style )
305{
306 switch ( style )
307 {
308 case 2:
309 m_name = "Fine Dashed";
310 m_style = "rect";
311 m_dots1 = "1";
312 m_dots1_length = "0.508cm";
313 m_dots2 = "1";
314 m_dots2_length = "0.508cm";
315 m_distance = "0.508cm";
316 break;
317 case 3:
318 m_name = "Fine Dotted";
319 m_style = "rect";
320 m_dots1 = "1";
321 m_distance = "0.257cm";
322 break;
323 case 4:
324 m_name = "Ultrafine 1 Dot 1 Dash";
325 m_style = "rect";
326 m_dots1 = "1";
327 m_dots1_length = "0.051cm";
328 m_dots2 = "1";
329 m_dots2_length = "0.254cm";
330 m_distance = "0.127cm";
331 break;
332 case 5:
333 m_name = "2 Dots 1 Dash";
334 m_style = "rect";
335 m_dots1 = "2";
336 m_dots2 = "1";
337 m_dots2_length = "0.203cm";
338 m_distance = "0.203cm";
339 break;
340 }
341}
342
343void StrokeDashStyle::toXML( TQDomDocument & doc, TQDomElement & e ) const
344{
345 TQDomElement strokeDash = doc.createElement( "draw:stroke-dash" );
346 strokeDash.setAttribute( "draw:name", m_name );
347 if ( !m_style.isNull() )
348 strokeDash.setAttribute( "draw:style", m_style );
349 if ( !m_dots1.isNull() )
350 strokeDash.setAttribute( "draw:dots1", m_dots1 );
351 if ( !m_dots1_length.isNull() )
352 strokeDash.setAttribute( "draw:dots1-length", m_dots1_length );
353 if ( !m_dots2.isNull() )
354 strokeDash.setAttribute( "draw:dots2", m_dots2 );
355 if ( !m_dots2_length.isNull() )
356 strokeDash.setAttribute( "draw:dots2-length", m_dots2_length );
357 if ( !m_distance.isNull() )
358 strokeDash.setAttribute( "draw:distance", m_distance );
359
360 e.appendChild( strokeDash );
361}
362
363GradientStyle::GradientStyle( TQDomElement & gradient, int index )
364{
365 m_name = TQString( "Gradient %1" ).arg( index );
366 m_start_intensity = "100%";
367 m_end_intensity = "100%";
368 m_border = "0%";
369
370 int type = 1;
371 if ( gradient.nodeName() == "PAGE" )
372 {
373 // gradient from page background
374 TQDomElement backColor1 = gradient.namedItem( "BACKCOLOR1" ).toElement();
375 TQDomElement backColor2 = gradient.namedItem( "BACKCOLOR2" ).toElement();
376 TQDomElement bcType = gradient.namedItem( "BCTYPE" ).toElement();
377 TQDomElement bGradient = gradient.namedItem( "BGRADIENT" ).toElement();
378
379 if ( !backColor1.isNull() )
380 m_start_color = backColor1.attribute( "color" );
381 if ( !backColor2.isNull() )
382 m_end_color = backColor2.attribute( "color" );
383 if ( !bcType.isNull() )
384 type = bcType.attribute( "value" ).toInt();
385 if ( !bGradient.isNull() )
386 {
387 if ( bGradient.attribute( "unbalanced" ) == "0" )
388 {
389 m_cx = "50%";
390 m_cy = "50%";
391 }
392 else
393 {
394 int cx = bGradient.attribute( "xfactor" ).toInt();
395 int cy = bGradient.attribute( "yfactor" ).toInt();
396 m_cx = TQString( "%1%" ).arg( cx / 4 + 50 );
397 m_cy = TQString( "%1%" ).arg( cy / 4 + 50 );
398 }
399 }
400
401 }
402 else
403 {
404 // gradient from object
405 if ( gradient.hasAttribute( "color1" ) )
406 m_start_color = gradient.attribute( "color1" );
407 if ( gradient.hasAttribute( "color2" ) )
408 m_end_color = gradient.attribute( "color2" );
409 if ( gradient.hasAttribute( "type" ) )
410 type = gradient.attribute( "type" ).toInt();
411 if ( gradient.hasAttribute( "unbalanced" ) )
412 {
413 if ( gradient.attribute( "unbalanced" ) == "0" )
414 {
415 m_cx = "50%";
416 m_cy = "50%";
417 }
418 else
419 {
420 int cx = gradient.attribute( "xfactor" ).toInt();
421 int cy = gradient.attribute( "yfactor" ).toInt();
422 m_cx = TQString( "%1%" ).arg( cx / 4 + 50 );
423 m_cy = TQString( "%1%" ).arg( cy / 4 + 50 );
424 }
425 }
426
427 }
428
429 switch ( type )
430 {
431 case 1:
432 m_style = "linear";
433 m_angle = "0";
434 break;
435 case 2:
436 m_style = "linear";
437 m_angle = "900";
438 break;
439 case 3:
440 m_style = "linear";
441 m_angle = "450";
442 break;
443 case 4:
444 m_style = "linear";
445 m_angle = "135";
446 break;
447 case 5:
448 m_style = "radial";
449 m_angle = "0";
450 break;
451 case 6:
452 m_style = "square";
453 m_angle = "0";
454 break;
455 case 7:
456 m_style = "axial";
457 m_angle = "0";
458 break;
459 }
460}
461
462void GradientStyle::toXML( TQDomDocument & doc, TQDomElement & e ) const
463{
464 TQDomElement gradient = doc.createElement( "draw:gradient" );
465 gradient.setAttribute( "draw:name", m_name );
466 if ( !m_style.isNull() )
467 gradient.setAttribute( "draw:style", m_style );
468 if ( !m_start_color.isNull() )
469 gradient.setAttribute( "draw:start-color", m_start_color );
470 if ( !m_end_color.isNull() )
471 gradient.setAttribute( "draw:end-color", m_end_color );
472 if ( !m_start_intensity.isNull() )
473 gradient.setAttribute( "draw:start-intensity", m_start_intensity );
474 if ( !m_end_intensity.isNull() )
475 gradient.setAttribute( "draw:end-intensity", m_end_intensity );
476 if ( !m_angle.isNull() )
477 gradient.setAttribute( "draw:angle", m_angle );
478 if ( !m_border.isNull() )
479 gradient.setAttribute( "draw:border", m_border );
480 if ( !m_cx.isNull() )
481 gradient.setAttribute( "draw:cx", m_cx );
482 if ( !m_cy.isNull() )
483 gradient.setAttribute( "draw:cy", m_cy );
484
485 e.appendChild( gradient );
486}
487
488MarkerStyle::MarkerStyle( int style )
489{
490 // Markers are not working because OOImpress depends on the sequence
491 // of the attributes in the draw:marker tag. svg:ViewBox has to be in
492 // front of svg:d in order to work.
493
494 switch ( style )
495 {
496 case 1:
497 m_name = "Arrow";
498 m_viewBox = "0 0 20 30";
499 m_d = "m10 0-10 30h20z";
500 break;
501 case 2:
502 m_name = "Square";
503 m_viewBox = "0 0 10 10";
504 m_d = "m0 0h10v10h-10z";
505 break;
506 case 3:
507 m_name = "Circle";
508 m_viewBox = "0 0 1131 1131";
509 m_d = "m462 1118-102-29-102-51-93-72-72-93-51-102-29-102-13-105 13-102 29-106 51-102 72-89 93-72 102-50 102-34 106-9 101 9 106 34 98 50 93 72 72 89 51 102 29 106 13 102-13 105-29 102-51 102-72 93-93 72-98 51-106 29-101 13z";
510 break;
511 case 4:
512 m_name = "Line Arrow";
513 m_viewBox = "0 0 1122 2243";
514 m_d = "m0 2108v17 17l12 42 30 34 38 21 43 4 29-8 30-21 25-26 13-34 343-1532 339 1520 13 42 29 34 39 21 42 4 42-12 34-30 21-42v-39-12l-4 4-440-1998-9-42-25-39-38-25-43-8-42 8-38 25-26 39-8 42z";
515 break;
516 case 5:
517 m_name = "Dimension Lines";
518 m_viewBox = "0 0 836 110";
519 m_d = "m0 0h278 278 280v36 36 38h-278-278-280v-36-36z";
520 break;
521 case 6:
522 case 7:
523 m_name = "Double Arrow";
524 m_viewBox = "0 0 1131 1918";
525 m_d = "m737 1131h394l-564-1131-567 1131h398l-398 787h1131z";
526 break;
527 }
528}
529
530void MarkerStyle::toXML( TQDomDocument & doc, TQDomElement & e ) const
531{
532 TQDomElement marker = doc.createElement( "draw:marker" );
533 marker.setAttribute( "draw:name", m_name );
534 if ( !m_viewBox.isNull() )
535 marker.setAttribute( "svg:viewBox", m_viewBox );
536 if ( !m_d.isNull() )
537 marker.setAttribute( "svg:d", m_d );
538
539 e.appendChild( marker );
540}
541
542HatchStyle::HatchStyle( int style, TQString & color )
543{
544 m_color = color;
545
546 switch ( style )
547 {
548 case 9:
549 m_name = m_color + " 0 Degrees";
550 m_style = "single";
551 m_distance = "0.102cm";
552 m_rotation = "0";
553 break;
554 case 10:
555 m_name = m_color + " 90 Degrees";
556 m_style = "single";
557 m_distance = "0.102cm";
558 m_rotation = "900";
559 break;
560 case 11:
561 m_name = m_color + " Crossed 0 Degrees";
562 m_style = "double";
563 m_distance = "0.076cm";
564 m_rotation = "900";
565 break;
566 case 12:
567 m_name = m_color + " 45 Degrees";
568 m_style = "single";
569 m_distance = "0.102cm";
570 m_rotation = "450";
571 break;
572 case 13:
573 m_name = m_color + " -45 Degrees";
574 m_style = "single";
575 m_distance = "0.102cm";
576 m_rotation = "3150";
577 break;
578 case 14:
579 m_name = m_color + " Crossed 45 Degrees";
580 m_style = "double";
581 m_distance = "0.076cm";
582 m_rotation = "450";
583 break;
584 }
585}
586
587void HatchStyle::toXML( TQDomDocument & doc, TQDomElement & e ) const
588{
589 TQDomElement hatch = doc.createElement( "draw:hatch" );
590 hatch.setAttribute( "draw:name", m_name );
591 if ( !m_style.isNull() )
592 hatch.setAttribute( "draw:style", m_style );
593 if ( !m_color.isNull() )
594 hatch.setAttribute( "draw:color", m_color );
595 if ( !m_distance.isNull() )
596 hatch.setAttribute( "draw:distance", m_distance );
597 if ( !m_rotation.isNull() )
598 hatch.setAttribute( "draw:rotation", m_rotation );
599
600 e.appendChild( hatch );
601}
602
603FillImageStyle::FillImageStyle( TQString & name )
604{
605
606}
607
608void FillImageStyle::toXML( TQDomDocument & doc, TQDomElement & e ) const
609{
610
611}
612
613PageMasterStyle::PageMasterStyle( TQDomElement & e, const uint index )
614{
615 TQDomNode borders = e.namedItem( "PAPERBORDERS" );
616 TQDomElement b = borders.toElement();
617
618 m_name = TQString( "PM%1" ).arg( index );
619 m_style = TQString( "Default%1" ).arg( index );
620 m_margin_top = StyleFactory::toCM( b.attribute( "ptTop" ) );
621 m_margin_bottom = StyleFactory::toCM( b.attribute( "ptBottom" ) );
622 m_margin_left = StyleFactory::toCM( b.attribute( "ptLeft" ) );
623 m_margin_right = StyleFactory::toCM( b.attribute( "ptRight" ) );
624 m_page_width = StyleFactory::toCM( e.attribute( "ptWidth" ) );
625 m_page_height = StyleFactory::toCM( e.attribute( "ptHeight" ) );
626 m_orientation = "landscape";
627}
628
629void PageMasterStyle::toXML( TQDomDocument & doc, TQDomElement & e ) const
630{
631 TQDomElement style = doc.createElement( "style:page-master" );
632 style.setAttribute( "style:name", "PM0" );
633
634 TQDomElement properties = doc.createElement( "style:properties" );
635 properties.setAttribute( "fo:margin-top", m_margin_top );
636 properties.setAttribute( "fo:margin-bottom", m_margin_bottom );
637 properties.setAttribute( "fo:margin-left", m_margin_left );
638 properties.setAttribute( "fo:margin-right", m_margin_right );
639 properties.setAttribute( "fo:page-width", m_page_width );
640 properties.setAttribute( "fo:page-height", m_page_height );
641 properties.setAttribute( "fo:print-orientation", m_orientation );
642
643 style.appendChild( properties );
644 e.appendChild( style );
645}
646
647bool PageMasterStyle::operator==( const PageMasterStyle & pageMasterStyle ) const
648{
649 return ( m_margin_top == pageMasterStyle.m_margin_top &&
650 m_margin_bottom == pageMasterStyle.m_margin_bottom &&
651 m_margin_left == pageMasterStyle.m_margin_left &&
652 m_margin_right == pageMasterStyle.m_margin_right &&
653 m_page_width == pageMasterStyle.m_page_width &&
654 m_page_height == pageMasterStyle.m_page_height &&
655 m_orientation == pageMasterStyle.m_orientation );
656}
657
658PageStyle::PageStyle( StyleFactory * styleFactory, TQDomElement & e, const uint index )
659{
660 TQDomElement backMaster = e.namedItem( "BACKMASTER" ).toElement();
661 if( !backMaster.isNull())
662 {
663 int tmp=0;
664 if(backMaster.hasAttribute("displayBackground"))
665 tmp = backMaster.attribute("displayBackground").toInt();
666 m_bg_visible = (tmp==1) ? "true" : "false";
667 tmp = 0;
668 if(backMaster.hasAttribute("displayMasterPageObject"))
669 tmp = backMaster.attribute("displayMasterPageObject").toInt();
670 m_bg_objects_visible = (tmp==1) ? "true" : "false";
671 }
672 else
673 {
674 m_bg_visible = "true";
675 m_bg_objects_visible = "true";
676 }
677
678 m_name = TQString( "dp%1" ).arg( index );
679
680 // check if this is an empty page tag
681 if ( !e.hasChildNodes() )
682 return;
683
684 TQDomElement backType = e.namedItem( "BACKTYPE" ).toElement();
685 if ( backType.isNull() || backType.attribute( "value" ) == "0" )
686 {
687 // color
688 TQDomElement bcType = e.namedItem( "BCTYPE" ).toElement();
689 if ( bcType.isNull() || bcType.attribute( "value" ) == "0" )
690 {
691 // plain
692 TQDomElement backColor = e.namedItem( "BACKCOLOR1" ).toElement();
693 m_fill = "solid";
694 m_fill_color = backColor.attribute( "color" );
695 }
696 else
697 {
698 // gradient
699 m_fill = "gradient";
700 m_fill_gradient_name = styleFactory->createGradientStyle( e );
701 }
702 }
703 else
704 {
705 // picture
706 }
707
708 TQDomElement pageDuration = e.namedItem( "PGTIMER" ).toElement();
709 if ( !pageDuration.isNull() )
710 {
711
712 TQTime time;
713 time = time.addSecs( pageDuration.attribute("timer").toInt() );
714 TQString hours( TQString::number( time.hour() ).rightJustify( 2, '0' ) );
715 TQString ms( TQString::number( time.minute() ).rightJustify( 2, '0' ) );
716 TQString sec( TQString::number( time.second() ).rightJustify( 2, '0' ) );
717
718
719 //ISO8601 chapter 5.5.3.2
720 //TQDate doesn't encode it as this format.
721 m_page_duration = TQString( "PT%1H%2M%3S" ).arg( hours ).arg( ms ).arg( sec );
722 }
723
724 TQDomElement pageEffect = e.namedItem( "PGEFFECT" ).toElement();
725 if ( !pageEffect.isNull() )
726 {
727 int tmp=0;
728 if(pageEffect.hasAttribute("value"))
729 tmp=pageEffect.attribute("value").toInt();
730 kdDebug(30518)<<" tmp :"<<tmp<<endl;
731 switch( tmp )
732 {
733 case -1:
734 m_page_effect = "random";
735 break;
736 case 1:
737 m_page_effect = "close-vertical";
738 break;
739 case 2:
740 m_page_effect = "close-horizontal";
741 break;
742 case 3:
743 m_page_effect = "fade-to-center";
744 break;
745 case 4:
746 m_page_effect = "open-vertical";
747 break;
748 case 5:
749 m_page_effect = "open-horizontal";
750 break;
751 case 6:
752 m_page_effect = "fade-from-center";
753 break;
754 case 7:
755 case 8:
756 case 9:
757 case 10:
758 kdDebug(30518)<<" this style is not defined :"<<tmp<<endl;
759 break;
760 case 11:
761 m_page_effect = "spiralin-left";
762 break;
763 case 12:
764 case 13:
765 case 14:
766 case 15:
767 case 16:
768 case 17:
769 case 18:
770 kdDebug(30518)<<" this style is not defined :"<<tmp<<endl;
771 break;
772 case 19:
773 m_page_effect = "fade-from-top";
774 break;
775 case 20:
776 kdDebug(30518)<<" this style is not defined :"<<tmp<<endl;
777 break;
778 case 21:
779 m_page_effect = "fade-from-bottom";
780 break;
781 case 22:
782 m_page_effect = "roll-from-bottom";
783 break;
784 case 23:
785 kdDebug(30518)<<" this style is not defined :"<<tmp<<endl;
786 break;
787 case 24:
788 m_page_effect = "roll-from-right";
789 break;
790 case 25:
791 kdDebug(30518)<<" this style is not defined :"<<tmp<<endl;
792 break;
793 case 26:
794 kdDebug(30518)<<" this style is not defined :"<<tmp<<endl;
795 break;
796 case 27:
797 kdDebug(30518)<<" this style is not defined :"<<tmp<<endl;
798 break;
799 case 28:
800 kdDebug(30518)<<" this style is not defined :"<<tmp<<endl;
801 break;
802 case 29:
803 kdDebug(30518)<<" this style is not defined :"<<tmp<<endl;
804 break;
805 case 30:
806 kdDebug(30518)<<" this style is not defined :"<<tmp<<endl;
807 break;
808 case 31:
809 kdDebug(30518)<<" this style is not defined :"<<tmp<<endl;
810 break;
811 case 32:
812 kdDebug(30518)<<" this style is not defined :"<<tmp<<endl;
813 break;
814 case 33:
815 kdDebug(30518)<<" this style is not defined :"<<tmp<<endl;
816 break;
817 case 34:
818 kdDebug(30518)<<" this style is not defined :"<<tmp<<endl;
819 break;
820 case 35:
821 m_page_effect = "dissolve";
822 break;
823 case 36:
824 m_page_effect = "fade-from-lowerright";
825 break;
826 case 37:
827 m_page_effect = "fade-from-upperright";
828 break;
829 case 38:
830 m_page_effect = "fade-from-lowerleft";
831 break;
832 case 39:
833 m_page_effect = "fade-from-upperleft";
834 break;
835 case 40:
836 kdDebug(30518)<<" this style is not defined :"<<tmp<<endl;
837 break;
838 default:
839 kdDebug(30518)<<" style page effect not define : "<<tmp<<endl;
840 break;
841 }
842 }
843}
844
845void PageStyle::toXML( TQDomDocument & doc, TQDomElement & e ) const
846{
847 TQDomElement style = doc.createElement( "style:style" );
848 style.setAttribute( "style:name", m_name );
849 style.setAttribute( "style:family", "drawing-page" );
850
851 TQDomElement properties = doc.createElement( "style:properties" );
852 properties.setAttribute( "presentation:background-visible", m_bg_visible );
853 properties.setAttribute( "presentation:background-objects-visible",
854 m_bg_objects_visible );
855 if ( !m_page_duration.isEmpty() )
856 {
857 properties.setAttribute( "presentation:duration", m_page_duration );
858 properties.setAttribute( "presentation:transition-type", "automatic" );
859 }
860 if ( !m_page_effect.isEmpty() )
861 properties.setAttribute( "presentation:transition-style",
862 m_page_effect );
863 if ( !m_fill.isNull() )
864 properties.setAttribute( "draw:fill", m_fill );
865 if ( !m_fill_color.isNull() )
866 properties.setAttribute( "draw:fill-color", m_fill_color );
867 if ( !m_fill_image_name.isNull() )
868 properties.setAttribute( "draw:fill-image-name", m_fill_image_name );
869 if ( !m_fill_image_width.isNull() )
870 properties.setAttribute( "draw:fill-image-width", m_fill_image_width );
871 if ( !m_fill_image_height.isNull() )
872 properties.setAttribute( "draw:fill-image-height", m_fill_image_height );
873 if ( !m_fill_image_ref_point.isNull() )
874 properties.setAttribute( "draw:fill-image-ref-point", m_fill_image_ref_point );
875 if ( !m_fill_gradient_name.isNull() )
876 properties.setAttribute( "draw:fill-gradient-name", m_fill_gradient_name );
877 if ( !m_repeat.isNull() )
878 properties.setAttribute( "style:repeat", m_repeat );
879
880 style.appendChild( properties );
881 e.appendChild( style );
882}
883
884bool PageStyle::operator==( const PageStyle & pageStyle ) const
885{
886 return ( m_bg_visible == pageStyle.m_bg_visible &&
887 m_bg_objects_visible == pageStyle.m_bg_objects_visible &&
888 m_fill == pageStyle.m_fill &&
889 m_fill_color == pageStyle.m_fill_color &&
890 m_fill_image_name == pageStyle.m_fill_image_name &&
891 m_fill_image_width == pageStyle.m_fill_image_width &&
892 m_fill_image_height == pageStyle.m_fill_image_height &&
893 m_fill_image_ref_point == pageStyle.m_fill_image_ref_point &&
894 m_fill_gradient_name == pageStyle.m_fill_gradient_name &&
895 m_repeat == pageStyle.m_repeat &&
896 m_page_effect == pageStyle.m_page_effect &&
897 m_page_duration == pageStyle.m_page_duration );
898}
899
900TextStyle::TextStyle( TQDomElement & e, const uint index )
901{
902 m_name = TQString( "T%1" ).arg( index );
903 if ( e.hasAttribute( "family" ) )
904 m_font_family = e.attribute( "family" );
905 if ( e.hasAttribute( "pointSize" ) )
906 m_font_size = TQString( "%1pt" ).arg( e.attribute( "pointSize" ) );
907 if ( e.hasAttribute( "color" ) )
908 m_color = e.attribute( "color" );
909 if ( e.hasAttribute( "bold" ) && e.attribute( "bold" ) == "1" )
910 m_font_weight = "bold";
911 if ( e.hasAttribute( "italic" ) && e.attribute( "italic" ) == "1" )
912 m_font_style = "italic";
913 if ( e.hasAttribute( "strikeOut" ) )
914 {
915 if ( e.attribute( "strikeOut" ) == "single" )
916 m_text_crossing_out = "single-line";
917 else if ( e.attribute( "strikeOut" ) == "single-bold" )
918 m_text_crossing_out = "thick-line";
919 else if ( e.attribute( "strikeOut" ) == "double" )
920 m_text_crossing_out = "double-line";
921 }
922 if ( e.hasAttribute( "underline" ) )
923 {
924 TQString underline = e.attribute( "underline" );
925 TQString style = e.attribute( "underlinestyleline" );
926 m_text_underline_color = e.attribute( "underlinecolor" );
927
928 if ( style == "solid" )
929 {
930 if ( underline == "1" )
931 m_text_underline = "single";
932 else if ( underline == "single-bold" )
933 m_text_underline = "bold";
934 else if ( underline == "double" )
935 m_text_underline = "double";
936 else if ( underline == "wave" )
937 m_text_underline = "wave";
938 }
939 else if ( style == "dot" )
940 {
941 if ( underline == "1" )
942 m_text_underline = "dotted";
943 else if ( underline == "single-bold" )
944 m_text_underline = "bold-dotted";
945 }
946 else if ( style == "dash" )
947 m_text_underline = "dash";
948 }
949}
950
951void TextStyle::toXML( TQDomDocument & doc, TQDomElement & e ) const
952{
953 TQDomElement style = doc.createElement( "style:style" );
954 style.setAttribute( "style:name", m_name );
955 style.setAttribute( "style:family", "text" );
956
957 TQDomElement properties = doc.createElement( "style:properties" );
958 if ( !m_font_size.isNull() )
959 properties.setAttribute( "fo:font-size", m_font_size );
960 if ( !m_font_family.isNull() )
961 properties.setAttribute( "fo:font-family", m_font_family );
962 if ( !m_font_family_generic.isNull() )
963 properties.setAttribute( "fo:font-family-generic", m_font_family_generic );
964 if ( !m_color.isNull() )
965 properties.setAttribute( "fo:color", m_color );
966 if ( !m_font_pitch.isNull() )
967 properties.setAttribute( "style:font-pitch", m_font_pitch );
968 if ( !m_font_style.isNull() )
969 properties.setAttribute( "fo:font-style", m_font_style );
970 if ( !m_font_weight.isNull() )
971 properties.setAttribute( "fo:font-weight", m_font_weight );
972 if ( !m_text_shadow.isNull() )
973 properties.setAttribute( "fo:text-shadow", m_text_shadow );
974 if ( !m_text_underline.isNull() )
975 properties.setAttribute( "style:text-underline", m_text_underline );
976 if ( !m_text_underline_color.isNull() )
977 properties.setAttribute( "style:text-underline-color", m_text_underline_color );
978 if ( !m_text_crossing_out.isNull() )
979 properties.setAttribute( "style:text-crossing-out", m_text_crossing_out );
980
981 style.appendChild( properties );
982 e.appendChild( style );
983}
984
985bool TextStyle::operator==( const TextStyle & textStyle ) const
986{
987 return ( m_font_size == textStyle.m_font_size &&
988 m_font_family == textStyle.m_font_family &&
989 m_font_family_generic == textStyle.m_font_family_generic &&
990 m_color == textStyle.m_color &&
991 m_font_pitch == textStyle.m_font_pitch &&
992 m_font_style == textStyle.m_font_style &&
993 m_font_weight == textStyle.m_font_weight &&
994 m_text_shadow == textStyle.m_text_shadow &&
995 m_text_underline == textStyle.m_text_underline &&
996 m_text_underline_color == textStyle.m_text_underline_color &&
997 m_text_crossing_out == textStyle.m_text_crossing_out );
998}
999
1000GraphicStyle::GraphicStyle( StyleFactory * styleFactory, TQDomElement & e, const uint index )
1001{
1002 TQDomNode pen = e.namedItem( "PEN" );
1003 TQDomNode brush = e.namedItem( "BRUSH" );
1004 TQDomNode linebegin = e.namedItem( "LINEBEGIN" );
1005 TQDomNode lineend = e.namedItem( "LINEEND" );
1006 TQDomNode gradient = e.namedItem( "GRADIENT" );
1007 TQDomNode shadow = e.namedItem( "SHADOW" );
1008 TQDomNode textObject = e.namedItem( "TEXTOBJ" );
1009 if ( !textObject.isNull() )
1010 {
1011 TQDomElement textObjectElement = textObject.toElement();
1012 if ( textObjectElement.hasAttribute( "verticalAlign" ) )
1013 {
1014 m_textAlignment = textObjectElement.attribute("verticalAlign");
1015 if ( m_textAlignment == "center" )
1016 m_textAlignment = "middle";
1017 }
1018 if ( textObjectElement.hasAttribute( "bleftpt" ) )
1019 {
1020 m_textMarginLeft = TQString( "%1pt" ).arg( textObjectElement.attribute( "bleftpt" ) );
1021 }
1022 if ( textObjectElement.hasAttribute( "bbottompt" ) )
1023 {
1024 m_textMarginBottom = TQString( "%1pt" ).arg( textObjectElement.attribute( "bbottompt" ) );
1025 }
1026 if ( textObjectElement.hasAttribute( "btoppt" ) )
1027 {
1028 m_textMarginTop = TQString( "%1pt" ).arg( textObjectElement.attribute( "btoppt" ) );
1029 }
1030 if ( textObjectElement.hasAttribute( "brightpt" ) )
1031 {
1032 m_textMarginRight = TQString( "%1pt" ).arg( textObjectElement.attribute( "brightpt" ) );
1033 }
1034
1035 }
1036 kdDebug(30518)<<" alignment :"<<m_textAlignment<<endl;
1037
1038 m_name = TQString( "gr%1" ).arg( index );
1039 if ( !pen.isNull() )
1040 {
1041 TQDomElement p = pen.toElement();
1042 m_stroke_width = StyleFactory::toCM( p.attribute( "width" ) );
1043 m_stroke_color = p.attribute( "color" );
1044
1045 int style = p.attribute( "style" ).toInt();
1046 if ( style == 1 )
1047 m_stroke = "solid";
1048 else if ( style >= 2 && style <= 5 )
1049 {
1050 m_stroke = "dash";
1051 m_stroke_dash = styleFactory->createStrokeDashStyle( style );
1052 }
1053 else
1054 m_stroke = "none";
1055 }
1056
1057 if ( !brush.isNull() )
1058 {
1059 TQDomElement b = brush.toElement();
1060 m_fill_color = b.attribute( "color" );
1061
1062 int style = b.attribute( "style" ).toInt();
1063 if ( style == 1 )
1064 m_fill = "solid";
1065 else if ( style >= 9 && style <= 14 )
1066 {
1067 m_fill = "hatch";
1068 m_fill_hatch_name = styleFactory->createHatchStyle( style, m_fill_color );
1069 }
1070 else if ( style >= 2 && style <= 8 )
1071 {
1072 if ( style == 2 )
1073 m_transparency = "94%";
1074 else if ( style == 3 )
1075 m_transparency = "88%";
1076 else if ( style == 4 )
1077 m_transparency = "63%";
1078 else if ( style == 5 )
1079 m_transparency = "50%";
1080 else if ( style == 6 )
1081 m_transparency = "37%";
1082 else if ( style == 7 )
1083 m_transparency = "12%";
1084 else if ( style == 8 )
1085 m_transparency = "6%";
1086 }
1087 }
1088 else if ( !gradient.isNull() )
1089 {
1090 TQDomElement g = gradient.toElement();
1091 m_fill = "gradient";
1092 m_fill_gradient_name = styleFactory->createGradientStyle( g );
1093 }
1094 else
1095 m_fill = "none";
1096
1097 if ( !linebegin.isNull() )
1098 {
1099 TQDomElement lb = linebegin.toElement();
1100 m_marker_start_width = "0.25cm";
1101
1102 int style = lb.attribute( "value" ).toInt();
1103 m_marker_start = styleFactory->createMarkerStyle( style );
1104 }
1105
1106 if ( !lineend.isNull() )
1107 {
1108 TQDomElement le = lineend.toElement();
1109 m_marker_end_width = "0.25cm";
1110
1111 int style = le.attribute( "value" ).toInt();
1112 m_marker_end = styleFactory->createMarkerStyle( style );
1113 }
1114
1115 if ( !shadow.isNull() )
1116 {
1117 TQDomElement s = shadow.toElement();
1118 m_shadow = "visible";
1119 m_shadow_color = s.attribute( "color" );
1120
1121 int direction = s.attribute( "direction" ).toInt();
1122 TQString distance = StyleFactory::toCM( s.attribute( "distance" ) );
1123 switch ( direction )
1124 {
1125 case 1:
1126 m_shadow_offset_x = "-" + distance;
1127 m_shadow_offset_y = "-" + distance;
1128 break;
1129 case 2:
1130 m_shadow_offset_x = "0cm";
1131 m_shadow_offset_y = "-" + distance;
1132 break;
1133 case 3:
1134 m_shadow_offset_x = distance;
1135 m_shadow_offset_y = "-" + distance;
1136 break;
1137 case 4:
1138 m_shadow_offset_x = distance;
1139 m_shadow_offset_y = "0cm";
1140 break;
1141 case 5:
1142 m_shadow_offset_x = distance;
1143 m_shadow_offset_y = distance;
1144 break;
1145 case 6:
1146 m_shadow_offset_x = "0cm";
1147 m_shadow_offset_y = distance;
1148 break;
1149 case 7:
1150 m_shadow_offset_x = "-" + distance;
1151 m_shadow_offset_y = distance;
1152 break;
1153 case 8:
1154 m_shadow_offset_x = "-" + distance;
1155 m_shadow_offset_y = "0cm";
1156 break;
1157 }
1158 }
1159}
1160
1161GraphicStyle::GraphicStyle( const char * name,
1162 const char * stroke, const char * stroke_color,
1163 const char * stroke_width, const char * shadow,
1164 const char * shadow_offset_x, const char * shadow_offset_y,
1165 const char * shadow_color, const char * margin_left,
1166 const char * margin_right, const char * margin_top,
1167 const char * margin_bottom, const char * color,
1168 const char * text_outline, const char * text_crossing_out,
1169 const char * font_family, const char * font_size,
1170 const char * font_style, const char * text_shadow,
1171 const char * text_underline, const char * font_weight,
1172 const char * line_height, const char * text_align,
1173 const char * fill, const char * fill_color,
1174 const char * enable_numbering )
1175 : m_name( name )
1176 , m_stroke( stroke )
1177 , m_stroke_color( stroke_color )
1178 , m_stroke_width( stroke_width )
1179 , m_shadow( shadow )
1180 , m_shadow_offset_x( shadow_offset_x )
1181 , m_shadow_offset_y( shadow_offset_y )
1182 , m_shadow_color( shadow_color )
1183 , m_margin_left( margin_left )
1184 , m_margin_right( margin_right )
1185 , m_margin_top( margin_top )
1186 , m_margin_bottom( margin_bottom )
1187 , m_color( color )
1188 , m_text_outline( text_outline )
1189 , m_text_crossing_out( text_crossing_out )
1190 , m_font_family( font_family )
1191 , m_font_size( font_size )
1192 , m_font_style( font_style )
1193 , m_text_shadow( text_shadow )
1194 , m_text_underline( text_underline )
1195 , m_font_weight( font_weight )
1196 , m_line_height( line_height )
1197 , m_text_align( text_align )
1198 , m_fill( fill )
1199 , m_fill_color( fill_color )
1200 , m_enable_numbering( enable_numbering )
1201{
1202}
1203
1204
1205void GraphicStyle::toXML( TQDomDocument & doc, TQDomElement & e ) const
1206{
1207 TQDomElement style = doc.createElement( "style:style" );
1208 style.setAttribute( "style:name", m_name );
1209 style.setAttribute( "style:family", "graphics" );
1210 if ( m_name != "standard" )
1211 style.setAttribute( "style:parent-style-name", "standard" );
1212
1213 TQDomElement properties = doc.createElement( "style:properties" );
1214 if ( !m_stroke.isNull() )
1215 properties.setAttribute( "draw:stroke", m_stroke );
1216 if ( !m_stroke_dash.isNull() )
1217 properties.setAttribute( "draw:stroke-dash", m_stroke_dash );
1218 if ( !m_stroke_color.isNull() )
1219 properties.setAttribute( "svg:stroke-color", m_stroke_color );
1220 if ( !m_stroke_width.isNull() )
1221 properties.setAttribute( "svg:stroke-width", m_stroke_width );
1222 if ( !m_shadow.isNull() )
1223 properties.setAttribute( "draw:shadow", m_shadow );
1224 if ( !m_shadow_offset_x.isNull() )
1225 properties.setAttribute( "draw:shadow-offset-x", m_shadow_offset_x );
1226 if ( !m_shadow_offset_y.isNull() )
1227 properties.setAttribute( "draw:shadow-offset-y", m_shadow_offset_y );
1228 if ( !m_shadow_color.isNull() )
1229 properties.setAttribute( "draw:shadow-color", m_shadow_color );
1230 if ( !m_margin_left.isNull() )
1231 properties.setAttribute( "fo:margin-left", m_margin_left );
1232 if ( !m_margin_right.isNull() )
1233 properties.setAttribute( "fo:margin-right", m_margin_right );
1234 if ( !m_margin_top.isNull() )
1235 properties.setAttribute( "fo:margin-top", m_margin_top );
1236 if ( !m_margin_bottom.isNull() )
1237 properties.setAttribute( "fo:margin-bottom", m_margin_bottom );
1238 if ( !m_color.isNull() )
1239 properties.setAttribute( "fo:color", m_color );
1240 if ( !m_text_outline.isNull() )
1241 properties.setAttribute( "style:text-outline", m_text_outline );
1242 if ( !m_text_crossing_out.isNull() )
1243 properties.setAttribute( "style:text-crossing-out", m_text_crossing_out );
1244 if ( !m_font_family.isNull() )
1245 properties.setAttribute( "fo:font-family", m_font_family );
1246 if ( !m_font_size.isNull() )
1247 properties.setAttribute( "fo:font-size", m_font_size );
1248 if ( !m_font_style.isNull() )
1249 properties.setAttribute( "fo:font-style", m_font_style );
1250 if ( !m_text_shadow.isNull() )
1251 properties.setAttribute( "fo:text-shadow", m_text_shadow );
1252 if ( !m_text_underline.isNull() )
1253 properties.setAttribute( "style:text-underline", m_text_underline );
1254 if ( !m_font_weight.isNull() )
1255 properties.setAttribute( "fo:font-weight", m_font_weight );
1256 if ( !m_line_height.isNull() )
1257 properties.setAttribute( "fo:line-height", m_line_height );
1258 if ( !m_text_align.isNull() )
1259 properties.setAttribute( "fo:text-align", m_text_align );
1260 if ( !m_fill.isNull() )
1261 properties.setAttribute( "draw:fill", m_fill );
1262 if ( !m_fill_color.isNull() )
1263 properties.setAttribute( "draw:fill-color", m_fill_color );
1264 if ( !m_fill_hatch_name.isNull() )
1265 properties.setAttribute( "draw:fill-hatch-name", m_fill_hatch_name );
1266 if ( !m_enable_numbering.isNull() )
1267 properties.setAttribute( "text:enable-numbering", m_enable_numbering );
1268 if ( !m_marker_start.isNull() )
1269 properties.setAttribute( "draw:marker-start", m_marker_start );
1270 if ( !m_marker_start_width.isNull() )
1271 properties.setAttribute( "draw:marker-start-width", m_marker_start_width );
1272 if ( !m_marker_end.isNull() )
1273 properties.setAttribute( "draw:marker-end", m_marker_end );
1274 if ( !m_marker_end_width.isNull() )
1275 properties.setAttribute( "draw:marker-end-width", m_marker_end_width );
1276 if ( !m_fill_gradient_name.isNull() )
1277 properties.setAttribute( "draw:fill-gradient-name", m_fill_gradient_name );
1278 if ( !m_transparency.isNull() )
1279 properties.setAttribute( "draw:transparency", m_transparency );
1280 if ( !m_textAlignment.isNull() )
1281 properties.setAttribute( "draw:textarea-vertical-align", m_textAlignment );
1282 if ( !m_textMarginLeft.isNull() )
1283 properties.setAttribute( "fo:padding-left", m_textMarginLeft );
1284 if ( !m_textMarginBottom.isNull() )
1285 properties.setAttribute( "fo:padding-bottom", m_textMarginBottom );
1286 if ( !m_textMarginTop.isNull() )
1287 properties.setAttribute( "fo:padding-top", m_textMarginTop );
1288 if ( !m_textMarginRight.isNull() )
1289 properties.setAttribute( "fo:padding-right", m_textMarginRight );
1290
1291
1292 style.appendChild( properties );
1293 e.appendChild( style );
1294}
1295
1296bool GraphicStyle::operator==( const GraphicStyle & graphicStyle ) const
1297{
1298 return ( m_stroke == graphicStyle.m_stroke &&
1299 m_stroke_dash == graphicStyle.m_stroke_dash &&
1300 m_stroke_color == graphicStyle.m_stroke_color &&
1301 m_stroke_width == graphicStyle.m_stroke_width &&
1302 m_shadow == graphicStyle.m_shadow &&
1303 m_shadow_offset_x == graphicStyle.m_shadow_offset_x &&
1304 m_shadow_offset_y == graphicStyle.m_shadow_offset_y &&
1305 m_shadow_color == graphicStyle.m_shadow_color &&
1306 m_margin_left == graphicStyle.m_margin_left &&
1307 m_margin_right == graphicStyle.m_margin_right &&
1308 m_margin_top == graphicStyle.m_margin_top &&
1309 m_margin_bottom == graphicStyle.m_margin_bottom &&
1310 m_color == graphicStyle.m_color &&
1311 m_text_outline == graphicStyle.m_text_outline &&
1312 m_text_crossing_out == graphicStyle.m_text_crossing_out &&
1313 m_font_family == graphicStyle.m_font_family &&
1314 m_font_size == graphicStyle.m_font_size &&
1315 m_font_style == graphicStyle.m_font_style &&
1316 m_text_shadow == graphicStyle.m_text_shadow &&
1317 m_text_underline == graphicStyle.m_text_underline &&
1318 m_font_weight == graphicStyle.m_font_weight &&
1319 m_line_height == graphicStyle.m_line_height &&
1320 m_text_align == graphicStyle.m_text_align &&
1321 m_fill == graphicStyle.m_fill &&
1322 m_fill_color == graphicStyle.m_fill_color &&
1323 m_fill_hatch_name == graphicStyle.m_fill_hatch_name &&
1324 m_enable_numbering == graphicStyle.m_enable_numbering &&
1325 m_marker_start == graphicStyle.m_marker_start &&
1326 m_marker_start_width == graphicStyle.m_marker_start_width &&
1327 m_marker_end == graphicStyle.m_marker_end &&
1328 m_marker_end_width == graphicStyle.m_marker_end_width &&
1329 m_fill_gradient_name == graphicStyle.m_fill_gradient_name &&
1330 m_transparency == graphicStyle.m_transparency &&
1331 m_textAlignment == graphicStyle.m_textAlignment &&
1332 m_textMarginLeft == graphicStyle.m_textMarginLeft &&
1333 m_textMarginBottom == graphicStyle.m_textMarginBottom &&
1334 m_textMarginTop == graphicStyle.m_textMarginTop &&
1335 m_textMarginRight == graphicStyle.m_textMarginRight);
1336}
1337
1338ParagraphStyle::ParagraphStyle( TQDomElement & e, const uint index )
1339{
1340 // some defaults that may be overwritten
1341 m_margin_left = "0cm";
1342 m_margin_right = "0cm";
1343 m_text_indent = "0cm";
1344
1345 TQDomNode shadow = e.namedItem( "SHADOW" );
1346 TQDomNode indents = e.namedItem( "INDENTS" );
1347 TQDomNode offsets = e.namedItem( "OFFSETS" );
1348 TQDomNode leftBorder = e.namedItem( "LEFTBORDER" );
1349 TQDomNode rightBorder = e.namedItem( "RIGHTBORDER" );
1350 TQDomNode topBorder = e.namedItem( "TOPBORDER" );
1351 TQDomNode bottomBorder = e.namedItem( "BOTTOMBORDER" );
1352 TQDomNode lineSpacing = e.namedItem( "LINESPACING" );
1353 TQDomNode counter = e.namedItem( "COUNTER" );
1354
1355 m_name = TQString( "P%1" ).arg( index );
1356 if ( e.hasAttribute( "align" ) )
1357 {
1358 int align = e.attribute( "align" ).toInt();
1359 switch ( align )
1360 {
1361 case 0: // left
1362 m_text_align = "start";
1363 break;
1364 case 2: // right
1365 m_text_align = "end";
1366 break;
1367 case 4: // center
1368 m_text_align = "center";
1369 break;
1370 case 8: // justify
1371 m_text_align = "justify";
1372 break;
1373 }
1374 }
1375
1376 if ( !shadow.isNull() )
1377 {
1378 TQDomElement s = shadow.toElement();
1379 TQString distance = TQString( "%1pt" ).arg( s.attribute( "distance" ) );
1380 m_text_shadow = distance + " " + distance;
1381 }
1382
1383 if ( !indents.isNull() )
1384 {
1385 TQDomElement i = indents.toElement();
1386 m_margin_left = StyleFactory::toCM( i.attribute( "left" ) );
1387 m_margin_right = StyleFactory::toCM( i.attribute( "right" ) );
1388 m_text_indent = StyleFactory::toCM( i.attribute( "first" ) );
1389 }
1390
1391 if ( !offsets.isNull() )
1392 {
1393 TQDomElement o = offsets.toElement();
1394 m_margin_top = StyleFactory::toCM( o.attribute( "before" ) );
1395 m_margin_bottom = StyleFactory::toCM( o.attribute( "after" ) );
1396 }
1397
1398 if ( !leftBorder.isNull() )
1399 m_border_left = parseBorder( leftBorder.toElement() );
1400 if ( !rightBorder.isNull() )
1401 m_border_right = parseBorder( rightBorder.toElement() );
1402 if ( !topBorder.isNull() )
1403 m_border_top = parseBorder( topBorder.toElement() );
1404 if ( !bottomBorder.isNull() )
1405 m_border_bottom = parseBorder( bottomBorder.toElement() );
1406
1407 if ( !lineSpacing.isNull() )
1408 {
1409 TQDomElement l = lineSpacing.toElement();
1410 TQString type = l.attribute( "type" );
1411
1412 if ( type == "single" )
1413 m_line_height = "100%";
1414 else if ( type == "oneandhalf" )
1415 m_line_height = "150%";
1416 else if ( type == "double" )
1417 m_line_height = "200%";
1418 else if ( type == "multiple" )
1419 m_line_height = TQString( "%1%" ).arg( l.attribute( "spacingvalue" ).toInt() * 100 );
1420 else if ( type == "custom" )
1421 m_line_spacing = StyleFactory::toCM( l.attribute( "spacingvalue" ) );
1422 else if ( type == "atleast" )
1423 m_line_height_at_least = StyleFactory::toCM( l.attribute( "spacingvalue" ) );
1424 }
1425
1426 if ( !counter.isNull() )
1427 m_enable_numbering = "true";
1428}
1429
1430void ParagraphStyle::toXML( TQDomDocument & doc, TQDomElement & e ) const
1431{
1432 TQDomElement style = doc.createElement( "style:style" );
1433 style.setAttribute( "style:name", m_name );
1434 style.setAttribute( "style:family", "paragraph" );
1435
1436 TQDomElement properties = doc.createElement( "style:properties" );
1437 if ( !m_margin_left.isNull() )
1438 properties.setAttribute( "fo:margin-left", m_margin_left );
1439 if ( !m_margin_right.isNull() )
1440 properties.setAttribute( "fo:margin-right", m_margin_right );
1441 if ( !m_text_indent.isNull() )
1442 properties.setAttribute( "fo:text-indent", m_text_indent );
1443 if ( !m_text_align.isNull() )
1444 properties.setAttribute( "fo:text-align", m_text_align );
1445 if ( !m_enable_numbering.isNull() )
1446 properties.setAttribute( "text:enable-numbering", m_enable_numbering );
1447 if ( !m_text_shadow.isNull() )
1448 properties.setAttribute( "fo:text-shadow", m_text_shadow );
1449 if ( !m_margin_top.isNull() )
1450 properties.setAttribute( "fo:margin-top", m_margin_top );
1451 if ( !m_margin_bottom.isNull() )
1452 properties.setAttribute( "fo:margin-bottom", m_margin_bottom );
1453 if ( !m_border_left.isNull() )
1454 properties.setAttribute( "fo:border-left", m_border_left );
1455 if ( !m_border_right.isNull() )
1456 properties.setAttribute( "fo:border-right", m_border_right );
1457 if ( !m_border_top.isNull() )
1458 properties.setAttribute( "fo:border-top", m_border_top );
1459 if ( !m_border_bottom.isNull() )
1460 properties.setAttribute( "fo:border-bottom", m_border_bottom );
1461 if ( !m_line_height.isNull() )
1462 properties.setAttribute( "fo:line-height", m_line_height );
1463 if ( !m_line_height_at_least.isNull() )
1464 properties.setAttribute( "style:line-height-at-least", m_line_height_at_least );
1465 if ( !m_line_spacing.isNull() )
1466 properties.setAttribute( "style:line-spacing", m_line_spacing );
1467
1468 style.appendChild( properties );
1469 e.appendChild( style );
1470}
1471
1472bool ParagraphStyle::operator==( const ParagraphStyle & paragraphStyle ) const
1473{
1474 return ( m_margin_left == paragraphStyle.m_margin_left &&
1475 m_margin_right == paragraphStyle.m_margin_right &&
1476 m_text_indent == paragraphStyle.m_text_indent &&
1477 m_text_align == paragraphStyle.m_text_align &&
1478 m_enable_numbering == paragraphStyle.m_enable_numbering &&
1479 m_text_shadow == paragraphStyle.m_text_shadow &&
1480 m_margin_top == paragraphStyle.m_margin_top &&
1481 m_margin_bottom == paragraphStyle.m_margin_bottom &&
1482 m_border_left == paragraphStyle.m_border_left &&
1483 m_border_right == paragraphStyle.m_border_right &&
1484 m_border_top == paragraphStyle.m_border_top &&
1485 m_border_bottom == paragraphStyle.m_border_bottom &&
1486 m_line_height == paragraphStyle.m_line_height &&
1487 m_line_height_at_least == paragraphStyle.m_line_height_at_least &&
1488 m_line_spacing == paragraphStyle.m_line_spacing );
1489}
1490
1491TQString ParagraphStyle::parseBorder( TQDomElement e )
1492{
1493 TQString style;
1494 int _style = e.attribute( "style" ).toInt();
1495 if ( _style == 5 )
1496 style = "double";
1497 else
1498 style = "solid";
1499
1500 TQString width = StyleFactory::toCM( e.attribute( "width" ) );
1501
1502 TQColor color( e.attribute( "red" ).toInt(),
1503 e.attribute( "green" ).toInt(),
1504 e.attribute( "blue" ).toInt() );
1505
1506 return TQString( "%1 %2 %3" ).arg( width ).arg( style ).arg( color.name() );
1507}
1508
1509ListStyle::ListStyle( TQDomElement & e, const uint index )
1510{
1511 // setting some default values
1512 m_min_label_width = 0.6;
1513 m_color = "#000000";
1514 m_font_size = "100%";
1515
1516 m_name = TQString( "L%1" ).arg( index );
1517
1518 if ( e.hasAttribute( "type" ) )
1519 {
1520 int type = e.attribute( "type" ).toInt();
1521 switch ( type )
1522 {
1523 case 1: // arabic numbers
1524 m_listLevelStyle = LLS_NUMBER;
1525 m_num_suffix = ".";
1526 m_num_format = "1";
1527 break;
1528 case 2: // lower alphabetical
1529 m_listLevelStyle = LLS_NUMBER;
1530 m_num_suffix = ".";
1531 m_num_format = "a";
1532 break;
1533 case 3: // upper alphabetical
1534 m_listLevelStyle = LLS_NUMBER;
1535 m_num_suffix = ".";
1536 m_num_format = "A";
1537 break;
1538 case 4: // lower roman
1539 m_listLevelStyle = LLS_NUMBER;
1540 m_num_suffix = ".";
1541 m_num_format = "i";
1542 break;
1543 case 5: // upper roman
1544 m_listLevelStyle = LLS_NUMBER;
1545 m_num_suffix = ".";
1546 m_num_format = "I";
1547 break;
1548 case 6: // custom
1549 m_listLevelStyle = LLS_BULLET;
1550 if ( e.hasAttribute( "text" ) )
1551 m_bullet_char = e.attribute( "text" );
1552 break;
1553 case 8: // circle bullet
1554 m_listLevelStyle = LLS_BULLET;
1555 break;
1556 case 9: // square bullet
1557 m_listLevelStyle = LLS_BULLET;
1558 break;
1559 case 10: // disc bullet
1560 m_listLevelStyle = LLS_BULLET;
1561 break;
1562 case 11: // box bullet
1563 m_listLevelStyle = LLS_BULLET;
1564 break;
1565 }
1566 }
1567
1568 if ( e.hasAttribute( "bulletfont" ) )
1569 m_font_family = e.attribute( "bulletfont" );
1570}
1571
1572void ListStyle::toXML( TQDomDocument & doc, TQDomElement & e ) const
1573{
1574 TQDomElement style = doc.createElement( "text:list-style" );
1575 style.setAttribute( "style:name", m_name );
1576
1577 for ( int level = 1; level <= 10; level++ )
1578 {
1579 TQDomElement listLevelStyle;
1580 if ( m_listLevelStyle == LLS_NUMBER )
1581 {
1582 listLevelStyle = doc.createElement( "text:list-level-style-number" );
1583 listLevelStyle.setAttribute( "text:level", level );
1584 if ( !m_num_suffix.isNull() )
1585 listLevelStyle.setAttribute( "style:num-suffix", m_num_suffix );
1586 if ( !m_num_format.isNull() )
1587 listLevelStyle.setAttribute( "style:num-format", m_num_format );
1588 }
1589 else
1590 {
1591 listLevelStyle = doc.createElement( "text:list-level-style-bullet" );
1592 listLevelStyle.setAttribute( "text:level", level );
1593 if ( !m_bullet_char.isNull() )
1594 listLevelStyle.setAttribute( "text:bullet-char", m_bullet_char );
1595 }
1596
1597 TQDomElement properties = doc.createElement( "style:properties" );
1598 if ( level > 1 )
1599 {
1600 properties.setAttribute( "text:min-label-width",
1601 TQString( "%1cm" ).arg( m_min_label_width ) );
1602 properties.setAttribute( "text:space-before",
1603 TQString( "%1cm" ).arg( m_min_label_width * ( level - 1 ) ) );
1604 }
1605
1606 if ( !m_color.isNull() )
1607 properties.setAttribute( "fo:color", m_color );
1608 if ( !m_font_size.isNull() )
1609 properties.setAttribute( "fo:font-size", m_font_size );
1610 if ( !m_font_family.isNull() )
1611 properties.setAttribute( "fo:font-family", m_font_family );
1612
1613 listLevelStyle.appendChild( properties );
1614 style.appendChild( listLevelStyle );
1615 }
1616 e.appendChild( style );
1617}
1618
1619bool ListStyle::operator==( const ListStyle & listStyle ) const
1620{
1621 return ( m_listLevelStyle == listStyle.m_listLevelStyle &&
1622 m_num_suffix == listStyle.m_num_suffix &&
1623 m_num_format == listStyle.m_num_format &&
1624 m_bullet_char == listStyle.m_bullet_char &&
1625 m_min_label_width == listStyle.m_min_label_width &&
1626 m_color == listStyle.m_color &&
1627 m_font_size == listStyle.m_font_size &&
1628 m_font_family == listStyle.m_font_family );
1629}