00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "stylefactory.h"
00021
00022 #include <qcolor.h>
00023 #include <qdatetime.h>
00024 #include <KoUnit.h>
00025 #include <kdebug.h>
00026
00027 StyleFactory::StyleFactory()
00028 {
00029 m_strokeDashStyles.setAutoDelete( true );
00030 m_gradientStyles.setAutoDelete( true );
00031 m_hatchStyles.setAutoDelete( true );
00032 m_markerStyles.setAutoDelete( true );
00033 m_fillImageStyles.setAutoDelete( true );
00034 m_listStyles.setAutoDelete( true );
00035 m_pageStyles.setAutoDelete( true );
00036 m_textStyles.setAutoDelete( true );
00037 m_graphicStyles.setAutoDelete( true );
00038 m_paragraphStyles.setAutoDelete( true );
00039 m_pageMasterStyles.setAutoDelete( true );
00040
00041
00042 GraphicStyle * graphicStyle;
00043 graphicStyle = new GraphicStyle ( "standard", "solid", "0cm", "0x000000",
00044 "hidden", "0.3cm", "0.3cm", "0x808080",
00045 "0cm", "0cm", "0cm", "0cm", "0x000000",
00046 "false", "none", "Thorndale", "24pt",
00047 "normal", "none", "none", "normal",
00048 "100%", "start", "solid", "0x00b8ff",
00049 "false" );
00050
00051 m_graphicStyles.append( graphicStyle );
00052 }
00053
00054 StyleFactory::~StyleFactory()
00055 {
00056 }
00057
00058 void StyleFactory::addOfficeStyles( QDomDocument & doc, QDomElement & styles )
00059 {
00060 StrokeDashStyle * sd;
00061 for ( sd = m_strokeDashStyles.first(); sd ; sd = m_strokeDashStyles.next() )
00062 sd->toXML( doc, styles );
00063
00064 GradientStyle * g;
00065 for ( g = m_gradientStyles.first(); g ; g = m_gradientStyles.next() )
00066 g->toXML( doc, styles );
00067
00068 MarkerStyle * m;
00069 for ( m = m_markerStyles.first(); m ; m = m_markerStyles.next() )
00070 m->toXML( doc, styles );
00071
00072 HatchStyle * h;
00073 for ( h = m_hatchStyles.first(); h ; h = m_hatchStyles.next() )
00074 h->toXML( doc, styles );
00075
00076 GraphicStyle * gr;
00077 gr = m_graphicStyles.first();
00078 gr->toXML( doc, styles );
00079 }
00080
00081 void StyleFactory::addOfficeMaster( QDomDocument & doc, QDomElement & master )
00082 {
00083 PageMasterStyle * p;
00084 for ( p = m_pageMasterStyles.first(); p ; p = m_pageMasterStyles.next() )
00085 {
00086 QDomElement masterPage = doc.createElement( "style:master-page" );
00087 masterPage.setAttribute( "style:name", p->style() );
00088 masterPage.setAttribute( "style:page-master-name", p->name() );
00089 masterPage.setAttribute( "draw:style-name", "dp1" );
00090 master.appendChild( masterPage );
00091 }
00092 }
00093
00094 void StyleFactory::addOfficeAutomatic( QDomDocument & doc, QDomElement & automatic )
00095 {
00096 PageMasterStyle * p;
00097 for ( p = m_pageMasterStyles.first(); p ; p = m_pageMasterStyles.next() )
00098 {
00099 p->toXML( doc, automatic );
00100 }
00101 }
00102
00103 void StyleFactory::addAutomaticStyles( QDomDocument & doc, QDomElement & autoStyles )
00104 {
00105 ListStyle * l;
00106 for ( l = m_listStyles.first(); l ; l = m_listStyles.next() )
00107 l->toXML( doc, autoStyles );
00108
00109 PageStyle * p;
00110 for ( p = m_pageStyles.first(); p ; p = m_pageStyles.next() )
00111 p->toXML( doc, autoStyles );
00112
00113 TextStyle * t;
00114 for ( t = m_textStyles.first(); t ; t = m_textStyles.next() )
00115 t->toXML( doc, autoStyles );
00116
00117 GraphicStyle * g;
00118 g = m_graphicStyles.first();
00119 for ( g = m_graphicStyles.next(); g ; g = m_graphicStyles.next() )
00120 g->toXML( doc, autoStyles );
00121
00122 ParagraphStyle * pg;
00123 for ( pg = m_paragraphStyles.first(); pg ; pg = m_paragraphStyles.next() )
00124 pg->toXML( doc, autoStyles );
00125 }
00126
00127 QString StyleFactory::createStrokeDashStyle( int style )
00128 {
00129 StrokeDashStyle * newStrokeDashStyle, * sd;
00130 newStrokeDashStyle = new StrokeDashStyle( style );
00131 for ( sd = m_strokeDashStyles.first(); sd ; sd = m_strokeDashStyles.next() )
00132 {
00133 if ( sd->name() == newStrokeDashStyle->name() )
00134 {
00135 delete newStrokeDashStyle;
00136 return sd->name();
00137 }
00138 }
00139
00140 m_strokeDashStyles.append( newStrokeDashStyle );
00141 return newStrokeDashStyle->name();
00142 }
00143
00144 QString StyleFactory::createGradientStyle( QDomElement & gradient )
00145 {
00146 GradientStyle * newGradientStyle, * g;
00147 newGradientStyle = new GradientStyle( gradient, m_gradientStyles.count() + 1 );
00148 for ( g = m_gradientStyles.first(); g ; g = m_gradientStyles.next() )
00149 {
00150 if ( g->name() == newGradientStyle->name() )
00151 {
00152 delete newGradientStyle;
00153 return g->name();
00154 }
00155 }
00156
00157 m_gradientStyles.append( newGradientStyle );
00158 return newGradientStyle->name();
00159 }
00160
00161 QString StyleFactory::createMarkerStyle( int style )
00162 {
00163 MarkerStyle * newMarkerStyle, * m;
00164 newMarkerStyle = new MarkerStyle( style );
00165 for ( m = m_markerStyles.first(); m ; m = m_markerStyles.next() )
00166 {
00167 if ( m->name() == newMarkerStyle->name() )
00168 {
00169 delete newMarkerStyle;
00170 return m->name();
00171 }
00172 }
00173
00174 m_markerStyles.append( newMarkerStyle );
00175 return newMarkerStyle->name();
00176 }
00177
00178 QString StyleFactory::createHatchStyle( int style, QString & color )
00179 {
00180 HatchStyle * newHatchStyle, * h;
00181 newHatchStyle = new HatchStyle( style, color );
00182 for ( h = m_hatchStyles.first(); h ; h = m_hatchStyles.next() )
00183 {
00184 if ( h->name() == newHatchStyle->name() )
00185 {
00186 delete newHatchStyle;
00187 return h->name();
00188 }
00189 }
00190
00191 m_hatchStyles.append( newHatchStyle );
00192 return newHatchStyle->name();
00193 }
00194
00195 QString StyleFactory::createListStyle( QDomElement & e )
00196 {
00197 ListStyle * newListStyle, * l;
00198 newListStyle = new ListStyle( e, m_listStyles.count() + 1 );
00199 for ( l = m_listStyles.first(); l ; l = m_listStyles.next() )
00200 {
00201 if ( *l == *newListStyle )
00202 {
00203 delete newListStyle;
00204 return l->name();
00205 }
00206 }
00207
00208 m_listStyles.append( newListStyle );
00209 return newListStyle->name();
00210 }
00211
00212 QString StyleFactory::createPageStyle( QDomElement & e )
00213 {
00214 PageStyle * newPageStyle, * p;
00215 newPageStyle = new PageStyle( this, e, m_pageStyles.count() + 1 );
00216 for ( p = m_pageStyles.first(); p ; p = m_pageStyles.next() )
00217 {
00218 if ( *p == *newPageStyle )
00219 {
00220 delete newPageStyle;
00221 return p->name();
00222 }
00223 }
00224
00225 m_pageStyles.append( newPageStyle );
00226 return newPageStyle->name();
00227 }
00228
00229 QString StyleFactory::createTextStyle( QDomElement & e )
00230 {
00231 TextStyle * newTextStyle, * t;
00232 newTextStyle = new TextStyle( e, m_textStyles.count() + 1 );
00233 for ( t = m_textStyles.first(); t ; t = m_textStyles.next() )
00234 {
00235 if ( *t == *newTextStyle )
00236 {
00237 delete newTextStyle;
00238 return t->name();
00239 }
00240 }
00241
00242 m_textStyles.append( newTextStyle );
00243 return newTextStyle->name();
00244 }
00245
00246 QString StyleFactory::createGraphicStyle( QDomElement & e )
00247 {
00248 GraphicStyle * newGraphicStyle, * g;
00249 newGraphicStyle = new GraphicStyle( this, e, m_graphicStyles.count() );
00250 for ( g = m_graphicStyles.first(); g ; g = m_graphicStyles.next() )
00251 {
00252 if ( *g == *newGraphicStyle )
00253 {
00254 delete newGraphicStyle;
00255 return g->name();
00256 }
00257 }
00258
00259 m_graphicStyles.append( newGraphicStyle );
00260 return newGraphicStyle->name();
00261 }
00262
00263 QString StyleFactory::createParagraphStyle( QDomElement & e )
00264 {
00265 ParagraphStyle * newParagraphStyle, * p;
00266 newParagraphStyle = new ParagraphStyle( e, m_paragraphStyles.count() + 1 );
00267 for ( p = m_paragraphStyles.first(); p ; p = m_paragraphStyles.next() )
00268 {
00269 if ( *p == *newParagraphStyle )
00270 {
00271 delete newParagraphStyle;
00272 return p->name();
00273 }
00274 }
00275
00276 m_paragraphStyles.append( newParagraphStyle );
00277 return newParagraphStyle->name();
00278 }
00279
00280 QString StyleFactory::createPageMasterStyle( QDomElement & e )
00281 {
00282 PageMasterStyle * newPMStyle, * p;
00283 newPMStyle = new PageMasterStyle( e, m_pageMasterStyles.count() );
00284 for ( p = m_pageMasterStyles.first(); p ; p = m_pageMasterStyles.next() )
00285 {
00286 if ( *p == *newPMStyle )
00287 {
00288 delete newPMStyle;
00289 return p->style();
00290 }
00291 }
00292
00293 m_pageMasterStyles.append( newPMStyle );
00294 return newPMStyle->style();
00295 }
00296
00297 QString StyleFactory::toCM( const QString & point )
00298 {
00299 double pt = point.toFloat();
00300 double cm = KoUnit::toCM( pt );
00301 return QString( "%1cm" ).arg ( cm );
00302 }
00303
00304 StrokeDashStyle::StrokeDashStyle( int style )
00305 {
00306 switch ( style )
00307 {
00308 case 2:
00309 m_name = "Fine Dashed";
00310 m_style = "rect";
00311 m_dots1 = "1";
00312 m_dots1_length = "0.508cm";
00313 m_dots2 = "1";
00314 m_dots2_length = "0.508cm";
00315 m_distance = "0.508cm";
00316 break;
00317 case 3:
00318 m_name = "Fine Dotted";
00319 m_style = "rect";
00320 m_dots1 = "1";
00321 m_distance = "0.257cm";
00322 break;
00323 case 4:
00324 m_name = "Ultrafine 1 Dot 1 Dash";
00325 m_style = "rect";
00326 m_dots1 = "1";
00327 m_dots1_length = "0.051cm";
00328 m_dots2 = "1";
00329 m_dots2_length = "0.254cm";
00330 m_distance = "0.127cm";
00331 break;
00332 case 5:
00333 m_name = "2 Dots 1 Dash";
00334 m_style = "rect";
00335 m_dots1 = "2";
00336 m_dots2 = "1";
00337 m_dots2_length = "0.203cm";
00338 m_distance = "0.203cm";
00339 break;
00340 }
00341 }
00342
00343 void StrokeDashStyle::toXML( QDomDocument & doc, QDomElement & e ) const
00344 {
00345 QDomElement strokeDash = doc.createElement( "draw:stroke-dash" );
00346 strokeDash.setAttribute( "draw:name", m_name );
00347 if ( !m_style.isNull() )
00348 strokeDash.setAttribute( "draw:style", m_style );
00349 if ( !m_dots1.isNull() )
00350 strokeDash.setAttribute( "draw:dots1", m_dots1 );
00351 if ( !m_dots1_length.isNull() )
00352 strokeDash.setAttribute( "draw:dots1-length", m_dots1_length );
00353 if ( !m_dots2.isNull() )
00354 strokeDash.setAttribute( "draw:dots2", m_dots2 );
00355 if ( !m_dots2_length.isNull() )
00356 strokeDash.setAttribute( "draw:dots2-length", m_dots2_length );
00357 if ( !m_distance.isNull() )
00358 strokeDash.setAttribute( "draw:distance", m_distance );
00359
00360 e.appendChild( strokeDash );
00361 }
00362
00363 GradientStyle::GradientStyle( QDomElement & gradient, int index )
00364 {
00365 m_name = QString( "Gradient %1" ).arg( index );
00366 m_start_intensity = "100%";
00367 m_end_intensity = "100%";
00368 m_border = "0%";
00369
00370 int type = 1;
00371 if ( gradient.nodeName() == "PAGE" )
00372 {
00373
00374 QDomElement backColor1 = gradient.namedItem( "BACKCOLOR1" ).toElement();
00375 QDomElement backColor2 = gradient.namedItem( "BACKCOLOR2" ).toElement();
00376 QDomElement bcType = gradient.namedItem( "BCTYPE" ).toElement();
00377 QDomElement bGradient = gradient.namedItem( "BGRADIENT" ).toElement();
00378
00379 if ( !backColor1.isNull() )
00380 m_start_color = backColor1.attribute( "color" );
00381 if ( !backColor2.isNull() )
00382 m_end_color = backColor2.attribute( "color" );
00383 if ( !bcType.isNull() )
00384 type = bcType.attribute( "value" ).toInt();
00385 if ( !bGradient.isNull() )
00386 {
00387 if ( bGradient.attribute( "unbalanced" ) == "0" )
00388 {
00389 m_cx = "50%";
00390 m_cy = "50%";
00391 }
00392 else
00393 {
00394 int cx = bGradient.attribute( "xfactor" ).toInt();
00395 int cy = bGradient.attribute( "yfactor" ).toInt();
00396 m_cx = QString( "%1%" ).arg( cx / 4 + 50 );
00397 m_cy = QString( "%1%" ).arg( cy / 4 + 50 );
00398 }
00399 }
00400
00401 }
00402 else
00403 {
00404
00405 if ( gradient.hasAttribute( "color1" ) )
00406 m_start_color = gradient.attribute( "color1" );
00407 if ( gradient.hasAttribute( "color2" ) )
00408 m_end_color = gradient.attribute( "color2" );
00409 if ( gradient.hasAttribute( "type" ) )
00410 type = gradient.attribute( "type" ).toInt();
00411 if ( gradient.hasAttribute( "unbalanced" ) )
00412 {
00413 if ( gradient.attribute( "unbalanced" ) == "0" )
00414 {
00415 m_cx = "50%";
00416 m_cy = "50%";
00417 }
00418 else
00419 {
00420 int cx = gradient.attribute( "xfactor" ).toInt();
00421 int cy = gradient.attribute( "yfactor" ).toInt();
00422 m_cx = QString( "%1%" ).arg( cx / 4 + 50 );
00423 m_cy = QString( "%1%" ).arg( cy / 4 + 50 );
00424 }
00425 }
00426
00427 }
00428
00429 switch ( type )
00430 {
00431 case 1:
00432 m_style = "linear";
00433 m_angle = "0";
00434 break;
00435 case 2:
00436 m_style = "linear";
00437 m_angle = "900";
00438 break;
00439 case 3:
00440 m_style = "linear";
00441 m_angle = "450";
00442 break;
00443 case 4:
00444 m_style = "linear";
00445 m_angle = "135";
00446 break;
00447 case 5:
00448 m_style = "radial";
00449 m_angle = "0";
00450 break;
00451 case 6:
00452 m_style = "square";
00453 m_angle = "0";
00454 break;
00455 case 7:
00456 m_style = "axial";
00457 m_angle = "0";
00458 break;
00459 }
00460 }
00461
00462 void GradientStyle::toXML( QDomDocument & doc, QDomElement & e ) const
00463 {
00464 QDomElement gradient = doc.createElement( "draw:gradient" );
00465 gradient.setAttribute( "draw:name", m_name );
00466 if ( !m_style.isNull() )
00467 gradient.setAttribute( "draw:style", m_style );
00468 if ( !m_start_color.isNull() )
00469 gradient.setAttribute( "draw:start-color", m_start_color );
00470 if ( !m_end_color.isNull() )
00471 gradient.setAttribute( "draw:end-color", m_end_color );
00472 if ( !m_start_intensity.isNull() )
00473 gradient.setAttribute( "draw:start-intensity", m_start_intensity );
00474 if ( !m_end_intensity.isNull() )
00475 gradient.setAttribute( "draw:end-intensity", m_end_intensity );
00476 if ( !m_angle.isNull() )
00477 gradient.setAttribute( "draw:angle", m_angle );
00478 if ( !m_border.isNull() )
00479 gradient.setAttribute( "draw:border", m_border );
00480 if ( !m_cx.isNull() )
00481 gradient.setAttribute( "draw:cx", m_cx );
00482 if ( !m_cy.isNull() )
00483 gradient.setAttribute( "draw:cy", m_cy );
00484
00485 e.appendChild( gradient );
00486 }
00487
00488 MarkerStyle::MarkerStyle( int style )
00489 {
00490
00491
00492
00493
00494 switch ( style )
00495 {
00496 case 1:
00497 m_name = "Arrow";
00498 m_viewBox = "0 0 20 30";
00499 m_d = "m10 0-10 30h20z";
00500 break;
00501 case 2:
00502 m_name = "Square";
00503 m_viewBox = "0 0 10 10";
00504 m_d = "m0 0h10v10h-10z";
00505 break;
00506 case 3:
00507 m_name = "Circle";
00508 m_viewBox = "0 0 1131 1131";
00509 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";
00510 break;
00511 case 4:
00512 m_name = "Line Arrow";
00513 m_viewBox = "0 0 1122 2243";
00514 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";
00515 break;
00516 case 5:
00517 m_name = "Dimension Lines";
00518 m_viewBox = "0 0 836 110";
00519 m_d = "m0 0h278 278 280v36 36 38h-278-278-280v-36-36z";
00520 break;
00521 case 6:
00522 case 7:
00523 m_name = "Double Arrow";
00524 m_viewBox = "0 0 1131 1918";
00525 m_d = "m737 1131h394l-564-1131-567 1131h398l-398 787h1131z";
00526 break;
00527 }
00528 }
00529
00530 void MarkerStyle::toXML( QDomDocument & doc, QDomElement & e ) const
00531 {
00532 QDomElement marker = doc.createElement( "draw:marker" );
00533 marker.setAttribute( "draw:name", m_name );
00534 if ( !m_viewBox.isNull() )
00535 marker.setAttribute( "svg:viewBox", m_viewBox );
00536 if ( !m_d.isNull() )
00537 marker.setAttribute( "svg:d", m_d );
00538
00539 e.appendChild( marker );
00540 }
00541
00542 HatchStyle::HatchStyle( int style, QString & color )
00543 {
00544 m_color = color;
00545
00546 switch ( style )
00547 {
00548 case 9:
00549 m_name = m_color + " 0 Degrees";
00550 m_style = "single";
00551 m_distance = "0.102cm";
00552 m_rotation = "0";
00553 break;
00554 case 10:
00555 m_name = m_color + " 90 Degrees";
00556 m_style = "single";
00557 m_distance = "0.102cm";
00558 m_rotation = "900";
00559 break;
00560 case 11:
00561 m_name = m_color + " Crossed 0 Degrees";
00562 m_style = "double";
00563 m_distance = "0.076cm";
00564 m_rotation = "900";
00565 break;
00566 case 12:
00567 m_name = m_color + " 45 Degrees";
00568 m_style = "single";
00569 m_distance = "0.102cm";
00570 m_rotation = "450";
00571 break;
00572 case 13:
00573 m_name = m_color + " -45 Degrees";
00574 m_style = "single";
00575 m_distance = "0.102cm";
00576 m_rotation = "3150";
00577 break;
00578 case 14:
00579 m_name = m_color + " Crossed 45 Degrees";
00580 m_style = "double";
00581 m_distance = "0.076cm";
00582 m_rotation = "450";
00583 break;
00584 }
00585 }
00586
00587 void HatchStyle::toXML( QDomDocument & doc, QDomElement & e ) const
00588 {
00589 QDomElement hatch = doc.createElement( "draw:hatch" );
00590 hatch.setAttribute( "draw:name", m_name );
00591 if ( !m_style.isNull() )
00592 hatch.setAttribute( "draw:style", m_style );
00593 if ( !m_color.isNull() )
00594 hatch.setAttribute( "draw:color", m_color );
00595 if ( !m_distance.isNull() )
00596 hatch.setAttribute( "draw:distance", m_distance );
00597 if ( !m_rotation.isNull() )
00598 hatch.setAttribute( "draw:rotation", m_rotation );
00599
00600 e.appendChild( hatch );
00601 }
00602
00603 FillImageStyle::FillImageStyle( QString & name )
00604 {
00605
00606 }
00607
00608 void FillImageStyle::toXML( QDomDocument & doc, QDomElement & e ) const
00609 {
00610
00611 }
00612
00613 PageMasterStyle::PageMasterStyle( QDomElement & e, const uint index )
00614 {
00615 QDomNode borders = e.namedItem( "PAPERBORDERS" );
00616 QDomElement b = borders.toElement();
00617
00618 m_name = QString( "PM%1" ).arg( index );
00619 m_style = QString( "Default%1" ).arg( index );
00620 m_margin_top = StyleFactory::toCM( b.attribute( "ptTop" ) );
00621 m_margin_bottom = StyleFactory::toCM( b.attribute( "ptBottom" ) );
00622 m_margin_left = StyleFactory::toCM( b.attribute( "ptLeft" ) );
00623 m_margin_right = StyleFactory::toCM( b.attribute( "ptRight" ) );
00624 m_page_width = StyleFactory::toCM( e.attribute( "ptWidth" ) );
00625 m_page_height = StyleFactory::toCM( e.attribute( "ptHeight" ) );
00626 m_orientation = "landscape";
00627 }
00628
00629 void PageMasterStyle::toXML( QDomDocument & doc, QDomElement & e ) const
00630 {
00631 QDomElement style = doc.createElement( "style:page-master" );
00632 style.setAttribute( "style:name", "PM0" );
00633
00634 QDomElement properties = doc.createElement( "style:properties" );
00635 properties.setAttribute( "fo:margin-top", m_margin_top );
00636 properties.setAttribute( "fo:margin-bottom", m_margin_bottom );
00637 properties.setAttribute( "fo:margin-left", m_margin_left );
00638 properties.setAttribute( "fo:margin-right", m_margin_right );
00639 properties.setAttribute( "fo:page-width", m_page_width );
00640 properties.setAttribute( "fo:page-height", m_page_height );
00641 properties.setAttribute( "fo:print-orientation", m_orientation );
00642
00643 style.appendChild( properties );
00644 e.appendChild( style );
00645 }
00646
00647 bool PageMasterStyle::operator==( const PageMasterStyle & pageMasterStyle ) const
00648 {
00649 return ( m_margin_top == pageMasterStyle.m_margin_top &&
00650 m_margin_bottom == pageMasterStyle.m_margin_bottom &&
00651 m_margin_left == pageMasterStyle.m_margin_left &&
00652 m_margin_right == pageMasterStyle.m_margin_right &&
00653 m_page_width == pageMasterStyle.m_page_width &&
00654 m_page_height == pageMasterStyle.m_page_height &&
00655 m_orientation == pageMasterStyle.m_orientation );
00656 }
00657
00658 PageStyle::PageStyle( StyleFactory * styleFactory, QDomElement & e, const uint index )
00659 {
00660 QDomElement backMaster = e.namedItem( "BACKMASTER" ).toElement();
00661 if( !backMaster.isNull())
00662 {
00663 int tmp=0;
00664 if(backMaster.hasAttribute("displayBackground"))
00665 tmp = backMaster.attribute("displayBackground").toInt();
00666 m_bg_visible = (tmp==1) ? "true" : "false";
00667 tmp = 0;
00668 if(backMaster.hasAttribute("displayMasterPageObject"))
00669 tmp = backMaster.attribute("displayMasterPageObject").toInt();
00670 m_bg_objects_visible = (tmp==1) ? "true" : "false";
00671 }
00672 else
00673 {
00674 m_bg_visible = "true";
00675 m_bg_objects_visible = "true";
00676 }
00677
00678 m_name = QString( "dp%1" ).arg( index );
00679
00680
00681 if ( !e.hasChildNodes() )
00682 return;
00683
00684 QDomElement backType = e.namedItem( "BACKTYPE" ).toElement();
00685 if ( backType.isNull() || backType.attribute( "value" ) == "0" )
00686 {
00687
00688 QDomElement bcType = e.namedItem( "BCTYPE" ).toElement();
00689 if ( bcType.isNull() || bcType.attribute( "value" ) == "0" )
00690 {
00691
00692 QDomElement backColor = e.namedItem( "BACKCOLOR1" ).toElement();
00693 m_fill = "solid";
00694 m_fill_color = backColor.attribute( "color" );
00695 }
00696 else
00697 {
00698
00699 m_fill = "gradient";
00700 m_fill_gradient_name = styleFactory->createGradientStyle( e );
00701 }
00702 }
00703 else
00704 {
00705
00706 }
00707
00708 QDomElement pageDuration = e.namedItem( "PGTIMER" ).toElement();
00709 if ( !pageDuration.isNull() )
00710 {
00711
00712 QTime time;
00713 time = time.addSecs( pageDuration.attribute("timer").toInt() );
00714 QString hours( QString::number( time.hour() ).rightJustify( 2, '0' ) );
00715 QString ms( QString::number( time.minute() ).rightJustify( 2, '0' ) );
00716 QString sec( QString::number( time.second() ).rightJustify( 2, '0' ) );
00717
00718
00719
00720
00721 m_page_duration = QString( "PT%1H%2M%3S" ).arg( hours ).arg( ms ).arg( sec );
00722 }
00723
00724 QDomElement pageEffect = e.namedItem( "PGEFFECT" ).toElement();
00725 if ( !pageEffect.isNull() )
00726 {
00727 int tmp=0;
00728 if(pageEffect.hasAttribute("value"))
00729 tmp=pageEffect.attribute("value").toInt();
00730 kdDebug(30518)<<" tmp :"<<tmp<<endl;
00731 switch( tmp )
00732 {
00733 case -1:
00734 m_page_effect = "random";
00735 break;
00736 case 1:
00737 m_page_effect = "close-vertical";
00738 break;
00739 case 2:
00740 m_page_effect = "close-horizontal";
00741 break;
00742 case 3:
00743 m_page_effect = "fade-to-center";
00744 break;
00745 case 4:
00746 m_page_effect = "open-vertical";
00747 break;
00748 case 5:
00749 m_page_effect = "open-horizontal";
00750 break;
00751 case 6:
00752 m_page_effect = "fade-from-center";
00753 break;
00754 case 7:
00755 case 8:
00756 case 9:
00757 case 10:
00758 kdDebug(30518)<<" this style is not defined :"<<tmp<<endl;
00759 break;
00760 case 11:
00761 m_page_effect = "spiralin-left";
00762 break;
00763 case 12:
00764 case 13:
00765 case 14:
00766 case 15:
00767 case 16:
00768 case 17:
00769 case 18:
00770 kdDebug(30518)<<" this style is not defined :"<<tmp<<endl;
00771 break;
00772 case 19:
00773 m_page_effect = "fade-from-top";
00774 break;
00775 case 20:
00776 kdDebug(30518)<<" this style is not defined :"<<tmp<<endl;
00777 break;
00778 case 21:
00779 m_page_effect = "fade-from-bottom";
00780 break;
00781 case 22:
00782 m_page_effect = "roll-from-bottom";
00783 break;
00784 case 23:
00785 kdDebug(30518)<<" this style is not defined :"<<tmp<<endl;
00786 break;
00787 case 24:
00788 m_page_effect = "roll-from-right";
00789 break;
00790 case 25:
00791 kdDebug(30518)<<" this style is not defined :"<<tmp<<endl;
00792 break;
00793 case 26:
00794 kdDebug(30518)<<" this style is not defined :"<<tmp<<endl;
00795 break;
00796 case 27:
00797 kdDebug(30518)<<" this style is not defined :"<<tmp<<endl;
00798 break;
00799 case 28:
00800 kdDebug(30518)<<" this style is not defined :"<<tmp<<endl;
00801 break;
00802 case 29:
00803 kdDebug(30518)<<" this style is not defined :"<<tmp<<endl;
00804 break;
00805 case 30:
00806 kdDebug(30518)<<" this style is not defined :"<<tmp<<endl;
00807 break;
00808 case 31:
00809 kdDebug(30518)<<" this style is not defined :"<<tmp<<endl;
00810 break;
00811 case 32:
00812 kdDebug(30518)<<" this style is not defined :"<<tmp<<endl;
00813 break;
00814 case 33:
00815 kdDebug(30518)<<" this style is not defined :"<<tmp<<endl;
00816 break;
00817 case 34:
00818 kdDebug(30518)<<" this style is not defined :"<<tmp<<endl;
00819 break;
00820 case 35:
00821 m_page_effect = "dissolve";
00822 break;
00823 case 36:
00824 m_page_effect = "fade-from-lowerright";
00825 break;
00826 case 37:
00827 m_page_effect = "fade-from-upperright";
00828 break;
00829 case 38:
00830 m_page_effect = "fade-from-lowerleft";
00831 break;
00832 case 39:
00833 m_page_effect = "fade-from-upperleft";
00834 break;
00835 case 40:
00836 kdDebug(30518)<<" this style is not defined :"<<tmp<<endl;
00837 break;
00838 default:
00839 kdDebug(30518)<<" style page effect not define : "<<tmp<<endl;
00840 break;
00841 }
00842 }
00843 }
00844
00845 void PageStyle::toXML( QDomDocument & doc, QDomElement & e ) const
00846 {
00847 QDomElement style = doc.createElement( "style:style" );
00848 style.setAttribute( "style:name", m_name );
00849 style.setAttribute( "style:family", "drawing-page" );
00850
00851 QDomElement properties = doc.createElement( "style:properties" );
00852 properties.setAttribute( "presentation:background-visible", m_bg_visible );
00853 properties.setAttribute( "presentation:background-objects-visible",
00854 m_bg_objects_visible );
00855 if ( !m_page_duration.isEmpty() )
00856 {
00857 properties.setAttribute( "presentation:duration", m_page_duration );
00858 properties.setAttribute( "presentation:transition-type", "automatic" );
00859 }
00860 if ( !m_page_effect.isEmpty() )
00861 properties.setAttribute( "presentation:transition-style",
00862 m_page_effect );
00863 if ( !m_fill.isNull() )
00864 properties.setAttribute( "draw:fill", m_fill );
00865 if ( !m_fill_color.isNull() )
00866 properties.setAttribute( "draw:fill-color", m_fill_color );
00867 if ( !m_fill_image_name.isNull() )
00868 properties.setAttribute( "draw:fill-image-name", m_fill_image_name );
00869 if ( !m_fill_image_width.isNull() )
00870 properties.setAttribute( "draw:fill-image-width", m_fill_image_width );
00871 if ( !m_fill_image_height.isNull() )
00872 properties.setAttribute( "draw:fill-image-height", m_fill_image_height );
00873 if ( !m_fill_image_ref_point.isNull() )
00874 properties.setAttribute( "draw:fill-image-ref-point", m_fill_image_ref_point );
00875 if ( !m_fill_gradient_name.isNull() )
00876 properties.setAttribute( "draw:fill-gradient-name", m_fill_gradient_name );
00877 if ( !m_repeat.isNull() )
00878 properties.setAttribute( "style:repeat", m_repeat );
00879
00880 style.appendChild( properties );
00881 e.appendChild( style );
00882 }
00883
00884 bool PageStyle::operator==( const PageStyle & pageStyle ) const
00885 {
00886 return ( m_bg_visible == pageStyle.m_bg_visible &&
00887 m_bg_objects_visible == pageStyle.m_bg_objects_visible &&
00888 m_fill == pageStyle.m_fill &&
00889 m_fill_color == pageStyle.m_fill_color &&
00890 m_fill_image_name == pageStyle.m_fill_image_name &&
00891 m_fill_image_width == pageStyle.m_fill_image_width &&
00892 m_fill_image_height == pageStyle.m_fill_image_height &&
00893 m_fill_image_ref_point == pageStyle.m_fill_image_ref_point &&
00894 m_fill_gradient_name == pageStyle.m_fill_gradient_name &&
00895 m_repeat == pageStyle.m_repeat &&
00896 m_page_effect == pageStyle.m_page_effect &&
00897 m_page_duration == pageStyle.m_page_duration );
00898 }
00899
00900 TextStyle::TextStyle( QDomElement & e, const uint index )
00901 {
00902 m_name = QString( "T%1" ).arg( index );
00903 if ( e.hasAttribute( "family" ) )
00904 m_font_family = e.attribute( "family" );
00905 if ( e.hasAttribute( "pointSize" ) )
00906 m_font_size = QString( "%1pt" ).arg( e.attribute( "pointSize" ) );
00907 if ( e.hasAttribute( "color" ) )
00908 m_color = e.attribute( "color" );
00909 if ( e.hasAttribute( "bold" ) && e.attribute( "bold" ) == "1" )
00910 m_font_weight = "bold";
00911 if ( e.hasAttribute( "italic" ) && e.attribute( "italic" ) == "1" )
00912 m_font_style = "italic";
00913 if ( e.hasAttribute( "strikeOut" ) )
00914 {
00915 if ( e.attribute( "strikeOut" ) == "single" )
00916 m_text_crossing_out = "single-line";
00917 else if ( e.attribute( "strikeOut" ) == "single-bold" )
00918 m_text_crossing_out = "thick-line";
00919 else if ( e.attribute( "strikeOut" ) == "double" )
00920 m_text_crossing_out = "double-line";
00921 }
00922 if ( e.hasAttribute( "underline" ) )
00923 {
00924 QString underline = e.attribute( "underline" );
00925 QString style = e.attribute( "underlinestyleline" );
00926 m_text_underline_color = e.attribute( "underlinecolor" );
00927
00928 if ( style == "solid" )
00929 {
00930 if ( underline == "1" )
00931 m_text_underline = "single";
00932 else if ( underline == "single-bold" )
00933 m_text_underline = "bold";
00934 else if ( underline == "double" )
00935 m_text_underline = "double";
00936 else if ( underline == "wave" )
00937 m_text_underline = "wave";
00938 }
00939 else if ( style == "dot" )
00940 {
00941 if ( underline == "1" )
00942 m_text_underline = "dotted";
00943 else if ( underline == "single-bold" )
00944 m_text_underline = "bold-dotted";
00945 }
00946 else if ( style == "dash" )
00947 m_text_underline = "dash";
00948 }
00949 }
00950
00951 void TextStyle::toXML( QDomDocument & doc, QDomElement & e ) const
00952 {
00953 QDomElement style = doc.createElement( "style:style" );
00954 style.setAttribute( "style:name", m_name );
00955 style.setAttribute( "style:family", "text" );
00956
00957 QDomElement properties = doc.createElement( "style:properties" );
00958 if ( !m_font_size.isNull() )
00959 properties.setAttribute( "fo:font-size", m_font_size );
00960 if ( !m_font_family.isNull() )
00961 properties.setAttribute( "fo:font-family", m_font_family );
00962 if ( !m_font_family_generic.isNull() )
00963 properties.setAttribute( "fo:font-family-generic", m_font_family_generic );
00964 if ( !m_color.isNull() )
00965 properties.setAttribute( "fo:color", m_color );
00966 if ( !m_font_pitch.isNull() )
00967 properties.setAttribute( "style:font-pitch", m_font_pitch );
00968 if ( !m_font_style.isNull() )
00969 properties.setAttribute( "fo:font-style", m_font_style );
00970 if ( !m_font_weight.isNull() )
00971 properties.setAttribute( "fo:font-weight", m_font_weight );
00972 if ( !m_text_shadow.isNull() )
00973 properties.setAttribute( "fo:text-shadow", m_text_shadow );
00974 if ( !m_text_underline.isNull() )
00975 properties.setAttribute( "style:text-underline", m_text_underline );
00976 if ( !m_text_underline_color.isNull() )
00977 properties.setAttribute( "style:text-underline-color", m_text_underline_color );
00978 if ( !m_text_crossing_out.isNull() )
00979 properties.setAttribute( "style:text-crossing-out", m_text_crossing_out );
00980
00981 style.appendChild( properties );
00982 e.appendChild( style );
00983 }
00984
00985 bool TextStyle::operator==( const TextStyle & textStyle ) const
00986 {
00987 return ( m_font_size == textStyle.m_font_size &&
00988 m_font_family == textStyle.m_font_family &&
00989 m_font_family_generic == textStyle.m_font_family_generic &&
00990 m_color == textStyle.m_color &&
00991 m_font_pitch == textStyle.m_font_pitch &&
00992 m_font_style == textStyle.m_font_style &&
00993 m_font_weight == textStyle.m_font_weight &&
00994 m_text_shadow == textStyle.m_text_shadow &&
00995 m_text_underline == textStyle.m_text_underline &&
00996 m_text_underline_color == textStyle.m_text_underline_color &&
00997 m_text_crossing_out == textStyle.m_text_crossing_out );
00998 }
00999
01000 GraphicStyle::GraphicStyle( StyleFactory * styleFactory, QDomElement & e, const uint index )
01001 {
01002 QDomNode pen = e.namedItem( "PEN" );
01003 QDomNode brush = e.namedItem( "BRUSH" );
01004 QDomNode linebegin = e.namedItem( "LINEBEGIN" );
01005 QDomNode lineend = e.namedItem( "LINEEND" );
01006 QDomNode gradient = e.namedItem( "GRADIENT" );
01007 QDomNode shadow = e.namedItem( "SHADOW" );
01008 QDomNode textObject = e.namedItem( "TEXTOBJ" );
01009 if ( !textObject.isNull() )
01010 {
01011 QDomElement textObjectElement = textObject.toElement();
01012 if ( textObjectElement.hasAttribute( "verticalAlign" ) )
01013 {
01014 m_textAlignment = textObjectElement.attribute("verticalAlign");
01015 if ( m_textAlignment == "center" )
01016 m_textAlignment = "middle";
01017 }
01018 if ( textObjectElement.hasAttribute( "bleftpt" ) )
01019 {
01020 m_textMarginLeft = QString( "%1pt" ).arg( textObjectElement.attribute( "bleftpt" ) );
01021 }
01022 if ( textObjectElement.hasAttribute( "bbottompt" ) )
01023 {
01024 m_textMarginBottom = QString( "%1pt" ).arg( textObjectElement.attribute( "bbottompt" ) );
01025 }
01026 if ( textObjectElement.hasAttribute( "btoppt" ) )
01027 {
01028 m_textMarginTop = QString( "%1pt" ).arg( textObjectElement.attribute( "btoppt" ) );
01029 }
01030 if ( textObjectElement.hasAttribute( "brightpt" ) )
01031 {
01032 m_textMarginRight = QString( "%1pt" ).arg( textObjectElement.attribute( "brightpt" ) );
01033 }
01034
01035 }
01036 kdDebug(30518)<<" alignment :"<<m_textAlignment<<endl;
01037
01038 m_name = QString( "gr%1" ).arg( index );
01039 if ( !pen.isNull() )
01040 {
01041 QDomElement p = pen.toElement();
01042 m_stroke_width = StyleFactory::toCM( p.attribute( "width" ) );
01043 m_stroke_color = p.attribute( "color" );
01044
01045 int style = p.attribute( "style" ).toInt();
01046 if ( style == 1 )
01047 m_stroke = "solid";
01048 else if ( style >= 2 && style <= 5 )
01049 {
01050 m_stroke = "dash";
01051 m_stroke_dash = styleFactory->createStrokeDashStyle( style );
01052 }
01053 else
01054 m_stroke = "none";
01055 }
01056
01057 if ( !brush.isNull() )
01058 {
01059 QDomElement b = brush.toElement();
01060 m_fill_color = b.attribute( "color" );
01061
01062 int style = b.attribute( "style" ).toInt();
01063 if ( style == 1 )
01064 m_fill = "solid";
01065 else if ( style >= 9 && style <= 14 )
01066 {
01067 m_fill = "hatch";
01068 m_fill_hatch_name = styleFactory->createHatchStyle( style, m_fill_color );
01069 }
01070 else if ( style >= 2 && style <= 8 )
01071 {
01072 if ( style == 2 )
01073 m_transparency = "94%";
01074 else if ( style == 3 )
01075 m_transparency = "88%";
01076 else if ( style == 4 )
01077 m_transparency = "63%";
01078 else if ( style == 5 )
01079 m_transparency = "50%";
01080 else if ( style == 6 )
01081 m_transparency = "37%";
01082 else if ( style == 7 )
01083 m_transparency = "12%";
01084 else if ( style == 8 )
01085 m_transparency = "6%";
01086 }
01087 }
01088 else if ( !gradient.isNull() )
01089 {
01090 QDomElement g = gradient.toElement();
01091 m_fill = "gradient";
01092 m_fill_gradient_name = styleFactory->createGradientStyle( g );
01093 }
01094 else
01095 m_fill = "none";
01096
01097 if ( !linebegin.isNull() )
01098 {
01099 QDomElement lb = linebegin.toElement();
01100 m_marker_start_width = "0.25cm";
01101
01102 int style = lb.attribute( "value" ).toInt();
01103 m_marker_start = styleFactory->createMarkerStyle( style );
01104 }
01105
01106 if ( !lineend.isNull() )
01107 {
01108 QDomElement le = lineend.toElement();
01109 m_marker_end_width = "0.25cm";
01110
01111 int style = le.attribute( "value" ).toInt();
01112 m_marker_end = styleFactory->createMarkerStyle( style );
01113 }
01114
01115 if ( !shadow.isNull() )
01116 {
01117 QDomElement s = shadow.toElement();
01118 m_shadow = "visible";
01119 m_shadow_color = s.attribute( "color" );
01120
01121 int direction = s.attribute( "direction" ).toInt();
01122 QString distance = StyleFactory::toCM( s.attribute( "distance" ) );
01123 switch ( direction )
01124 {
01125 case 1:
01126 m_shadow_offset_x = "-" + distance;
01127 m_shadow_offset_y = "-" + distance;
01128 break;
01129 case 2:
01130 m_shadow_offset_x = "0cm";
01131 m_shadow_offset_y = "-" + distance;
01132 break;
01133 case 3:
01134 m_shadow_offset_x = distance;
01135 m_shadow_offset_y = "-" + distance;
01136 break;
01137 case 4:
01138 m_shadow_offset_x = distance;
01139 m_shadow_offset_y = "0cm";
01140 break;
01141 case 5:
01142 m_shadow_offset_x = distance;
01143 m_shadow_offset_y = distance;
01144 break;
01145 case 6:
01146 m_shadow_offset_x = "0cm";
01147 m_shadow_offset_y = distance;
01148 break;
01149 case 7:
01150 m_shadow_offset_x = "-" + distance;
01151 m_shadow_offset_y = distance;
01152 break;
01153 case 8:
01154 m_shadow_offset_x = "-" + distance;
01155 m_shadow_offset_y = "0cm";
01156 break;
01157 }
01158 }
01159 }
01160
01161 GraphicStyle::GraphicStyle( const char * name,
01162 const char * stroke, const char * stroke_color,
01163 const char * stroke_width, const char * shadow,
01164 const char * shadow_offset_x, const char * shadow_offset_y,
01165 const char * shadow_color, const char * margin_left,
01166 const char * margin_right, const char * margin_top,
01167 const char * margin_bottom, const char * color,
01168 const char * text_outline, const char * text_crossing_out,
01169 const char * font_family, const char * font_size,
01170 const char * font_style, const char * text_shadow,
01171 const char * text_underline, const char * font_weight,
01172 const char * line_height, const char * text_align,
01173 const char * fill, const char * fill_color,
01174 const char * enable_numbering )
01175 : m_name( name )
01176 , m_stroke( stroke )
01177 , m_stroke_color( stroke_color )
01178 , m_stroke_width( stroke_width )
01179 , m_shadow( shadow )
01180 , m_shadow_offset_x( shadow_offset_x )
01181 , m_shadow_offset_y( shadow_offset_y )
01182 , m_shadow_color( shadow_color )
01183 , m_margin_left( margin_left )
01184 , m_margin_right( margin_right )
01185 , m_margin_top( margin_top )
01186 , m_margin_bottom( margin_bottom )
01187 , m_color( color )
01188 , m_text_outline( text_outline )
01189 , m_text_crossing_out( text_crossing_out )
01190 , m_font_family( font_family )
01191 , m_font_size( font_size )
01192 , m_font_style( font_style )
01193 , m_text_shadow( text_shadow )
01194 , m_text_underline( text_underline )
01195 , m_font_weight( font_weight )
01196 , m_line_height( line_height )
01197 , m_text_align( text_align )
01198 , m_fill( fill )
01199 , m_fill_color( fill_color )
01200 , m_enable_numbering( enable_numbering )
01201 {
01202 }
01203
01204
01205 void GraphicStyle::toXML( QDomDocument & doc, QDomElement & e ) const
01206 {
01207 QDomElement style = doc.createElement( "style:style" );
01208 style.setAttribute( "style:name", m_name );
01209 style.setAttribute( "style:family", "graphics" );
01210 if ( m_name != "standard" )
01211 style.setAttribute( "style:parent-style-name", "standard" );
01212
01213 QDomElement properties = doc.createElement( "style:properties" );
01214 if ( !m_stroke.isNull() )
01215 properties.setAttribute( "draw:stroke", m_stroke );
01216 if ( !m_stroke_dash.isNull() )
01217 properties.setAttribute( "draw:stroke-dash", m_stroke_dash );
01218 if ( !m_stroke_color.isNull() )
01219 properties.setAttribute( "svg:stroke-color", m_stroke_color );
01220 if ( !m_stroke_width.isNull() )
01221 properties.setAttribute( "svg:stroke-width", m_stroke_width );
01222 if ( !m_shadow.isNull() )
01223 properties.setAttribute( "draw:shadow", m_shadow );
01224 if ( !m_shadow_offset_x.isNull() )
01225 properties.setAttribute( "draw:shadow-offset-x", m_shadow_offset_x );
01226 if ( !m_shadow_offset_y.isNull() )
01227 properties.setAttribute( "draw:shadow-offset-y", m_shadow_offset_y );
01228 if ( !m_shadow_color.isNull() )
01229 properties.setAttribute( "draw:shadow-color", m_shadow_color );
01230 if ( !m_margin_left.isNull() )
01231 properties.setAttribute( "fo:margin-left", m_margin_left );
01232 if ( !m_margin_right.isNull() )
01233 properties.setAttribute( "fo:margin-right", m_margin_right );
01234 if ( !m_margin_top.isNull() )
01235 properties.setAttribute( "fo:margin-top", m_margin_top );
01236 if ( !m_margin_bottom.isNull() )
01237 properties.setAttribute( "fo:margin-bottom", m_margin_bottom );
01238 if ( !m_color.isNull() )
01239 properties.setAttribute( "fo:color", m_color );
01240 if ( !m_text_outline.isNull() )
01241 properties.setAttribute( "style:text-outline", m_text_outline );
01242 if ( !m_text_crossing_out.isNull() )
01243 properties.setAttribute( "style:text-crossing-out", m_text_crossing_out );
01244 if ( !m_font_family.isNull() )
01245 properties.setAttribute( "fo:font-family", m_font_family );
01246 if ( !m_font_size.isNull() )
01247 properties.setAttribute( "fo:font-size", m_font_size );
01248 if ( !m_font_style.isNull() )
01249 properties.setAttribute( "fo:font-style", m_font_style );
01250 if ( !m_text_shadow.isNull() )
01251 properties.setAttribute( "fo:text-shadow", m_text_shadow );
01252 if ( !m_text_underline.isNull() )
01253 properties.setAttribute( "style:text-underline", m_text_underline );
01254 if ( !m_font_weight.isNull() )
01255 properties.setAttribute( "fo:font-weight", m_font_weight );
01256 if ( !m_line_height.isNull() )
01257 properties.setAttribute( "fo:line-height", m_line_height );
01258 if ( !m_text_align.isNull() )
01259 properties.setAttribute( "fo:text-align", m_text_align );
01260 if ( !m_fill.isNull() )
01261 properties.setAttribute( "draw:fill", m_fill );
01262 if ( !m_fill_color.isNull() )
01263 properties.setAttribute( "draw:fill-color", m_fill_color );
01264 if ( !m_fill_hatch_name.isNull() )
01265 properties.setAttribute( "draw:fill-hatch-name", m_fill_hatch_name );
01266 if ( !m_enable_numbering.isNull() )
01267 properties.setAttribute( "text:enable-numbering", m_enable_numbering );
01268 if ( !m_marker_start.isNull() )
01269 properties.setAttribute( "draw:marker-start", m_marker_start );
01270 if ( !m_marker_start_width.isNull() )
01271 properties.setAttribute( "draw:marker-start-width", m_marker_start_width );
01272 if ( !m_marker_end.isNull() )
01273 properties.setAttribute( "draw:marker-end", m_marker_end );
01274 if ( !m_marker_end_width.isNull() )
01275 properties.setAttribute( "draw:marker-end-width", m_marker_end_width );
01276 if ( !m_fill_gradient_name.isNull() )
01277 properties.setAttribute( "draw:fill-gradient-name", m_fill_gradient_name );
01278 if ( !m_transparency.isNull() )
01279 properties.setAttribute( "draw:transparency", m_transparency );
01280 if ( !m_textAlignment.isNull() )
01281 properties.setAttribute( "draw:textarea-vertical-align", m_textAlignment );
01282 if ( !m_textMarginLeft.isNull() )
01283 properties.setAttribute( "fo:padding-left", m_textMarginLeft );
01284 if ( !m_textMarginBottom.isNull() )
01285 properties.setAttribute( "fo:padding-bottom", m_textMarginBottom );
01286 if ( !m_textMarginTop.isNull() )
01287 properties.setAttribute( "fo:padding-top", m_textMarginTop );
01288 if ( !m_textMarginRight.isNull() )
01289 properties.setAttribute( "fo:padding-right", m_textMarginRight );
01290
01291
01292 style.appendChild( properties );
01293 e.appendChild( style );
01294 }
01295
01296 bool GraphicStyle::operator==( const GraphicStyle & graphicStyle ) const
01297 {
01298 return ( m_stroke == graphicStyle.m_stroke &&
01299 m_stroke_dash == graphicStyle.m_stroke_dash &&
01300 m_stroke_color == graphicStyle.m_stroke_color &&
01301 m_stroke_width == graphicStyle.m_stroke_width &&
01302 m_shadow == graphicStyle.m_shadow &&
01303 m_shadow_offset_x == graphicStyle.m_shadow_offset_x &&
01304 m_shadow_offset_y == graphicStyle.m_shadow_offset_y &&
01305 m_shadow_color == graphicStyle.m_shadow_color &&
01306 m_margin_left == graphicStyle.m_margin_left &&
01307 m_margin_right == graphicStyle.m_margin_right &&
01308 m_margin_top == graphicStyle.m_margin_top &&
01309 m_margin_bottom == graphicStyle.m_margin_bottom &&
01310 m_color == graphicStyle.m_color &&
01311 m_text_outline == graphicStyle.m_text_outline &&
01312 m_text_crossing_out == graphicStyle.m_text_crossing_out &&
01313 m_font_family == graphicStyle.m_font_family &&
01314 m_font_size == graphicStyle.m_font_size &&
01315 m_font_style == graphicStyle.m_font_style &&
01316 m_text_shadow == graphicStyle.m_text_shadow &&
01317 m_text_underline == graphicStyle.m_text_underline &&
01318 m_font_weight == graphicStyle.m_font_weight &&
01319 m_line_height == graphicStyle.m_line_height &&
01320 m_text_align == graphicStyle.m_text_align &&
01321 m_fill == graphicStyle.m_fill &&
01322 m_fill_color == graphicStyle.m_fill_color &&
01323 m_fill_hatch_name == graphicStyle.m_fill_hatch_name &&
01324 m_enable_numbering == graphicStyle.m_enable_numbering &&
01325 m_marker_start == graphicStyle.m_marker_start &&
01326 m_marker_start_width == graphicStyle.m_marker_start_width &&
01327 m_marker_end == graphicStyle.m_marker_end &&
01328 m_marker_end_width == graphicStyle.m_marker_end_width &&
01329 m_fill_gradient_name == graphicStyle.m_fill_gradient_name &&
01330 m_transparency == graphicStyle.m_transparency &&
01331 m_textAlignment == graphicStyle.m_textAlignment &&
01332 m_textMarginLeft == graphicStyle.m_textMarginLeft &&
01333 m_textMarginBottom == graphicStyle.m_textMarginBottom &&
01334 m_textMarginTop == graphicStyle.m_textMarginTop &&
01335 m_textMarginRight == graphicStyle.m_textMarginRight);
01336 }
01337
01338 ParagraphStyle::ParagraphStyle( QDomElement & e, const uint index )
01339 {
01340
01341 m_margin_left = "0cm";
01342 m_margin_right = "0cm";
01343 m_text_indent = "0cm";
01344
01345 QDomNode shadow = e.namedItem( "SHADOW" );
01346 QDomNode indents = e.namedItem( "INDENTS" );
01347 QDomNode offsets = e.namedItem( "OFFSETS" );
01348 QDomNode leftBorder = e.namedItem( "LEFTBORDER" );
01349 QDomNode rightBorder = e.namedItem( "RIGHTBORDER" );
01350 QDomNode topBorder = e.namedItem( "TOPBORDER" );
01351 QDomNode bottomBorder = e.namedItem( "BOTTOMBORDER" );
01352 QDomNode lineSpacing = e.namedItem( "LINESPACING" );
01353 QDomNode counter = e.namedItem( "COUNTER" );
01354
01355 m_name = QString( "P%1" ).arg( index );
01356 if ( e.hasAttribute( "align" ) )
01357 {
01358 int align = e.attribute( "align" ).toInt();
01359 switch ( align )
01360 {
01361 case 0:
01362 m_text_align = "start";
01363 break;
01364 case 2:
01365 m_text_align = "end";
01366 break;
01367 case 4:
01368 m_text_align = "center";
01369 break;
01370 case 8:
01371 m_text_align = "justify";
01372 break;
01373 }
01374 }
01375
01376 if ( !shadow.isNull() )
01377 {
01378 QDomElement s = shadow.toElement();
01379 QString distance = QString( "%1pt" ).arg( s.attribute( "distance" ) );
01380 m_text_shadow = distance + " " + distance;
01381 }
01382
01383 if ( !indents.isNull() )
01384 {
01385 QDomElement i = indents.toElement();
01386 m_margin_left = StyleFactory::toCM( i.attribute( "left" ) );
01387 m_margin_right = StyleFactory::toCM( i.attribute( "right" ) );
01388 m_text_indent = StyleFactory::toCM( i.attribute( "first" ) );
01389 }
01390
01391 if ( !offsets.isNull() )
01392 {
01393 QDomElement o = offsets.toElement();
01394 m_margin_top = StyleFactory::toCM( o.attribute( "before" ) );
01395 m_margin_bottom = StyleFactory::toCM( o.attribute( "after" ) );
01396 }
01397
01398 if ( !leftBorder.isNull() )
01399 m_border_left = parseBorder( leftBorder.toElement() );
01400 if ( !rightBorder.isNull() )
01401 m_border_right = parseBorder( rightBorder.toElement() );
01402 if ( !topBorder.isNull() )
01403 m_border_top = parseBorder( topBorder.toElement() );
01404 if ( !bottomBorder.isNull() )
01405 m_border_bottom = parseBorder( bottomBorder.toElement() );
01406
01407 if ( !lineSpacing.isNull() )
01408 {
01409 QDomElement l = lineSpacing.toElement();
01410 QString type = l.attribute( "type" );
01411
01412 if ( type == "single" )
01413 m_line_height = "100%";
01414 else if ( type == "oneandhalf" )
01415 m_line_height = "150%";
01416 else if ( type == "double" )
01417 m_line_height = "200%";
01418 else if ( type == "multiple" )
01419 m_line_height = QString( "%1%" ).arg( l.attribute( "spacingvalue" ).toInt() * 100 );
01420 else if ( type == "custom" )
01421 m_line_spacing = StyleFactory::toCM( l.attribute( "spacingvalue" ) );
01422 else if ( type == "atleast" )
01423 m_line_height_at_least = StyleFactory::toCM( l.attribute( "spacingvalue" ) );
01424 }
01425
01426 if ( !counter.isNull() )
01427 m_enable_numbering = "true";
01428 }
01429
01430 void ParagraphStyle::toXML( QDomDocument & doc, QDomElement & e ) const
01431 {
01432 QDomElement style = doc.createElement( "style:style" );
01433 style.setAttribute( "style:name", m_name );
01434 style.setAttribute( "style:family", "paragraph" );
01435
01436 QDomElement properties = doc.createElement( "style:properties" );
01437 if ( !m_margin_left.isNull() )
01438 properties.setAttribute( "fo:margin-left", m_margin_left );
01439 if ( !m_margin_right.isNull() )
01440 properties.setAttribute( "fo:margin-right", m_margin_right );
01441 if ( !m_text_indent.isNull() )
01442 properties.setAttribute( "fo:text-indent", m_text_indent );
01443 if ( !m_text_align.isNull() )
01444 properties.setAttribute( "fo:text-align", m_text_align );
01445 if ( !m_enable_numbering.isNull() )
01446 properties.setAttribute( "text:enable-numbering", m_enable_numbering );
01447 if ( !m_text_shadow.isNull() )
01448 properties.setAttribute( "fo:text-shadow", m_text_shadow );
01449 if ( !m_margin_top.isNull() )
01450 properties.setAttribute( "fo:margin-top", m_margin_top );
01451 if ( !m_margin_bottom.isNull() )
01452 properties.setAttribute( "fo:margin-bottom", m_margin_bottom );
01453 if ( !m_border_left.isNull() )
01454 properties.setAttribute( "fo:border-left", m_border_left );
01455 if ( !m_border_right.isNull() )
01456 properties.setAttribute( "fo:border-right", m_border_right );
01457 if ( !m_border_top.isNull() )
01458 properties.setAttribute( "fo:border-top", m_border_top );
01459 if ( !m_border_bottom.isNull() )
01460 properties.setAttribute( "fo:border-bottom", m_border_bottom );
01461 if ( !m_line_height.isNull() )
01462 properties.setAttribute( "fo:line-height", m_line_height );
01463 if ( !m_line_height_at_least.isNull() )
01464 properties.setAttribute( "style:line-height-at-least", m_line_height_at_least );
01465 if ( !m_line_spacing.isNull() )
01466 properties.setAttribute( "style:line-spacing", m_line_spacing );
01467
01468 style.appendChild( properties );
01469 e.appendChild( style );
01470 }
01471
01472 bool ParagraphStyle::operator==( const ParagraphStyle & paragraphStyle ) const
01473 {
01474 return ( m_margin_left == paragraphStyle.m_margin_left &&
01475 m_margin_right == paragraphStyle.m_margin_right &&
01476 m_text_indent == paragraphStyle.m_text_indent &&
01477 m_text_align == paragraphStyle.m_text_align &&
01478 m_enable_numbering == paragraphStyle.m_enable_numbering &&
01479 m_text_shadow == paragraphStyle.m_text_shadow &&
01480 m_margin_top == paragraphStyle.m_margin_top &&
01481 m_margin_bottom == paragraphStyle.m_margin_bottom &&
01482 m_border_left == paragraphStyle.m_border_left &&
01483 m_border_right == paragraphStyle.m_border_right &&
01484 m_border_top == paragraphStyle.m_border_top &&
01485 m_border_bottom == paragraphStyle.m_border_bottom &&
01486 m_line_height == paragraphStyle.m_line_height &&
01487 m_line_height_at_least == paragraphStyle.m_line_height_at_least &&
01488 m_line_spacing == paragraphStyle.m_line_spacing );
01489 }
01490
01491 QString ParagraphStyle::parseBorder( QDomElement e )
01492 {
01493 QString style;
01494 int _style = e.attribute( "style" ).toInt();
01495 if ( _style == 5 )
01496 style = "double";
01497 else
01498 style = "solid";
01499
01500 QString width = StyleFactory::toCM( e.attribute( "width" ) );
01501
01502 QColor color( e.attribute( "red" ).toInt(),
01503 e.attribute( "green" ).toInt(),
01504 e.attribute( "blue" ).toInt() );
01505
01506 return QString( "%1 %2 %3" ).arg( width ).arg( style ).arg( color.name() );
01507 }
01508
01509 ListStyle::ListStyle( QDomElement & e, const uint index )
01510 {
01511
01512 m_min_label_width = 0.6;
01513 m_color = "#000000";
01514 m_font_size = "100%";
01515
01516 m_name = QString( "L%1" ).arg( index );
01517
01518 if ( e.hasAttribute( "type" ) )
01519 {
01520 int type = e.attribute( "type" ).toInt();
01521 switch ( type )
01522 {
01523 case 1:
01524 m_listLevelStyle = LLS_NUMBER;
01525 m_num_suffix = ".";
01526 m_num_format = "1";
01527 break;
01528 case 2:
01529 m_listLevelStyle = LLS_NUMBER;
01530 m_num_suffix = ".";
01531 m_num_format = "a";
01532 break;
01533 case 3:
01534 m_listLevelStyle = LLS_NUMBER;
01535 m_num_suffix = ".";
01536 m_num_format = "A";
01537 break;
01538 case 4:
01539 m_listLevelStyle = LLS_NUMBER;
01540 m_num_suffix = ".";
01541 m_num_format = "i";
01542 break;
01543 case 5:
01544 m_listLevelStyle = LLS_NUMBER;
01545 m_num_suffix = ".";
01546 m_num_format = "I";
01547 break;
01548 case 6:
01549 m_listLevelStyle = LLS_BULLET;
01550 if ( e.hasAttribute( "text" ) )
01551 m_bullet_char = e.attribute( "text" );
01552 break;
01553 case 8:
01554 m_listLevelStyle = LLS_BULLET;
01555 break;
01556 case 9:
01557 m_listLevelStyle = LLS_BULLET;
01558 break;
01559 case 10:
01560 m_listLevelStyle = LLS_BULLET;
01561 break;
01562 case 11:
01563 m_listLevelStyle = LLS_BULLET;
01564 break;
01565 }
01566 }
01567
01568 if ( e.hasAttribute( "bulletfont" ) )
01569 m_font_family = e.attribute( "bulletfont" );
01570 }
01571
01572 void ListStyle::toXML( QDomDocument & doc, QDomElement & e ) const
01573 {
01574 QDomElement style = doc.createElement( "text:list-style" );
01575 style.setAttribute( "style:name", m_name );
01576
01577 for ( int level = 1; level <= 10; level++ )
01578 {
01579 QDomElement listLevelStyle;
01580 if ( m_listLevelStyle == LLS_NUMBER )
01581 {
01582 listLevelStyle = doc.createElement( "text:list-level-style-number" );
01583 listLevelStyle.setAttribute( "text:level", level );
01584 if ( !m_num_suffix.isNull() )
01585 listLevelStyle.setAttribute( "style:num-suffix", m_num_suffix );
01586 if ( !m_num_format.isNull() )
01587 listLevelStyle.setAttribute( "style:num-format", m_num_format );
01588 }
01589 else
01590 {
01591 listLevelStyle = doc.createElement( "text:list-level-style-bullet" );
01592 listLevelStyle.setAttribute( "text:level", level );
01593 if ( !m_bullet_char.isNull() )
01594 listLevelStyle.setAttribute( "text:bullet-char", m_bullet_char );
01595 }
01596
01597 QDomElement properties = doc.createElement( "style:properties" );
01598 if ( level > 1 )
01599 {
01600 properties.setAttribute( "text:min-label-width",
01601 QString( "%1cm" ).arg( m_min_label_width ) );
01602 properties.setAttribute( "text:space-before",
01603 QString( "%1cm" ).arg( m_min_label_width * ( level - 1 ) ) );
01604 }
01605
01606 if ( !m_color.isNull() )
01607 properties.setAttribute( "fo:color", m_color );
01608 if ( !m_font_size.isNull() )
01609 properties.setAttribute( "fo:font-size", m_font_size );
01610 if ( !m_font_family.isNull() )
01611 properties.setAttribute( "fo:font-family", m_font_family );
01612
01613 listLevelStyle.appendChild( properties );
01614 style.appendChild( listLevelStyle );
01615 }
01616 e.appendChild( style );
01617 }
01618
01619 bool ListStyle::operator==( const ListStyle & listStyle ) const
01620 {
01621 return ( m_listLevelStyle == listStyle.m_listLevelStyle &&
01622 m_num_suffix == listStyle.m_num_suffix &&
01623 m_num_format == listStyle.m_num_format &&
01624 m_bullet_char == listStyle.m_bullet_char &&
01625 m_min_label_width == listStyle.m_min_label_width &&
01626 m_color == listStyle.m_color &&
01627 m_font_size == listStyle.m_font_size &&
01628 m_font_family == listStyle.m_font_family );
01629 }