LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/xmloff/source/style - xmlnume.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 351 421 83.4 %
Date: 2013-07-09 Functions: 9 10 90.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : 
      21             : #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
      22             : #include <com/sun/star/style/NumberingType.hpp>
      23             : #include <com/sun/star/style/XStyle.hpp>
      24             : #include <com/sun/star/container/XNameContainer.hpp>
      25             : #include <com/sun/star/container/XIndexReplace.hpp>
      26             : #include <com/sun/star/awt/XBitmap.hpp>
      27             : #include <com/sun/star/awt/FontDescriptor.hpp>
      28             : #include <com/sun/star/text/HoriOrientation.hpp>
      29             : #include <com/sun/star/text/VertOrientation.hpp>
      30             : #include <com/sun/star/text/XChapterNumberingSupplier.hpp>
      31             : #include <com/sun/star/text/PositionAndSpaceMode.hpp>
      32             : #include <com/sun/star/text/LabelFollow.hpp>
      33             : #include <com/sun/star/beans/PropertyValue.hpp>
      34             : #include <com/sun/star/beans/XPropertySet.hpp>
      35             : 
      36             : #include <rtl/ustrbuf.hxx>
      37             : 
      38             : #include <tools/debug.hxx>
      39             : 
      40             : #include <sax/tools/converter.hxx>
      41             : 
      42             : #include <xmloff/nmspmap.hxx>
      43             : #include "xmloff/xmlnmspe.hxx"
      44             : #include <xmloff/xmltoken.hxx>
      45             : #include <xmloff/xmluconv.hxx>
      46             : #include "fonthdl.hxx"
      47             : #include "xmloff/XMLTextListAutoStylePool.hxx"
      48             : #include <xmloff/xmlnume.hxx>
      49             : #include <xmloff/xmlexp.hxx>
      50             : #include <tools/fontenum.hxx>
      51             : 
      52             : 
      53             : 
      54             : using namespace ::com::sun::star;
      55             : using namespace ::com::sun::star::uno;
      56             : using namespace ::com::sun::star::style;
      57             : using namespace ::com::sun::star::text;
      58             : using namespace ::com::sun::star::container;
      59             : using namespace ::com::sun::star::beans;
      60             : using namespace ::xmloff::token;
      61             : 
      62          69 : void SvxXMLNumRuleExport::exportLevelStyles( const uno::Reference< ::com::sun::star::container::XIndexReplace > & xNumRule,
      63             :                                              sal_Bool bOutline )
      64             : {
      65          69 :     sal_Int32 nCount = xNumRule ->getCount();
      66         759 :     for( sal_Int32 i=0; i<nCount; i++ )
      67             :     {
      68         690 :         uno::Any aEntry( xNumRule->getByIndex( i ) );
      69        1380 :         uno::Sequence<beans::PropertyValue> aSeq;
      70         690 :         if( aEntry >>= aSeq )
      71             :         {
      72         690 :             exportLevelStyle( i, aSeq, bOutline );
      73             :         }
      74         690 :     }
      75          69 : }
      76             : 
      77         690 : void SvxXMLNumRuleExport::exportLevelStyle( sal_Int32 nLevel,
      78             :                                     const uno::Sequence<beans::PropertyValue>& rProps,
      79             :                                     sal_Bool bOutline )
      80             : {
      81         690 :     sal_Int16 eType = NumberingType::CHAR_SPECIAL;
      82             : 
      83         690 :     sal_Int16 eAdjust = HoriOrientation::LEFT;
      84        1380 :     OUString sPrefix, sSuffix;
      85        1380 :     OUString sTextStyleName;
      86         690 :     sal_Bool bHasColor = sal_False;
      87         690 :     sal_Int32 nColor = 0;
      88         690 :     sal_Int32 nSpaceBefore = 0, nMinLabelWidth = 0, nMinLabelDist = 0;
      89             : 
      90         690 :     sal_Int16 nStartValue = 1, nDisplayLevels = 1, nBullRelSize = 0;
      91             : 
      92         690 :     sal_Unicode cBullet = 0xf095;
      93        1380 :     OUString sBulletFontName, sBulletFontStyleName ;
      94         690 :     FontFamily eBulletFontFamily = FAMILY_DONTKNOW;
      95         690 :     FontPitch eBulletFontPitch = PITCH_DONTKNOW;
      96         690 :     rtl_TextEncoding eBulletFontEncoding = RTL_TEXTENCODING_DONTKNOW;
      97             : 
      98        1380 :     OUString sImageURL;
      99        1380 :     uno::Reference< ::com::sun::star::awt::XBitmap >  xBitmap;
     100         690 :     sal_Int32 nImageWidth = 0, nImageHeight = 0;
     101         690 :     sal_Int16 eImageVertOrient = VertOrientation::LINE_CENTER;
     102             : 
     103         690 :     sal_Int16 ePosAndSpaceMode = PositionAndSpaceMode::LABEL_WIDTH_AND_POSITION;
     104         690 :     sal_Int16 eLabelFollowedBy = LabelFollow::LISTTAB;
     105         690 :     sal_Int32 nListtabStopPosition( 0 );
     106         690 :     sal_Int32 nFirstLineIndent( 0 );
     107         690 :     sal_Int32 nIndentAt( 0 );
     108             : 
     109         690 :     const sal_Int32 nCount = rProps.getLength();
     110         690 :     const beans::PropertyValue* pPropArray = rProps.getConstArray();
     111        9352 :     for( sal_Int32 i=0; i<nCount; i++ )
     112             :     {
     113        8662 :         const beans::PropertyValue& rProp = pPropArray[i];
     114             : 
     115        8662 :         if( rProp.Name == "NumberingType" )
     116             :         {
     117         690 :             rProp.Value >>= eType;
     118             :         }
     119        7972 :         else if( rProp.Name == "Prefix" )
     120             :         {
     121         690 :             rProp.Value >>= sPrefix;
     122             :         }
     123        7282 :         else if( rProp.Name == "Suffix" )
     124             :         {
     125         690 :             rProp.Value >>= sSuffix;
     126             :         }
     127        6592 :         else if( rProp.Name == "BulletChar" )
     128             :         {
     129         198 :             OUString sValue;
     130         198 :             rProp.Value >>= sValue;
     131         198 :             if( !sValue.isEmpty() )
     132             :             {
     133         198 :                 cBullet = (sal_Unicode)sValue[0];
     134         198 :             }
     135             :         }
     136        6394 :         else if( rProp.Name == "BulletRelSize" )
     137             :         {
     138         180 :             rProp.Value >>= nBullRelSize;
     139             :         }
     140        6214 :         else if( rProp.Name == "Adjust" )
     141             :         {
     142         690 :             sal_Int16 nValue = 0;
     143         690 :             rProp.Value >>= nValue;
     144         690 :             eAdjust = nValue;
     145             :         }
     146        5524 :         else if( rProp.Name == "BulletFont" )
     147             :         {
     148         178 :             awt::FontDescriptor rFDesc;
     149         178 :             if( rProp.Value >>= rFDesc )
     150             :             {
     151         178 :                 sBulletFontName = rFDesc.Name;
     152         178 :                 sBulletFontStyleName = rFDesc.StyleName;
     153         178 :                 eBulletFontFamily = static_cast< FontFamily >( rFDesc.Family );
     154         178 :                 eBulletFontPitch = static_cast< FontPitch >( rFDesc.Pitch );
     155         178 :                 eBulletFontEncoding = (rtl_TextEncoding)rFDesc.CharSet;
     156         178 :             }
     157             :         }
     158        5346 :         else if( rProp.Name == "GraphicURL" )
     159             :         {
     160           0 :             rProp.Value >>= sImageURL;
     161             :         }
     162        5346 :         else if( rProp.Name == "GraphicBitmap" )
     163             :         {
     164           0 :             rProp.Value >>= xBitmap;
     165             :         }
     166        5346 :         else if( rProp.Name == "BulletColor" )
     167             :         {
     168         180 :             rProp.Value >>= nColor;
     169         180 :             bHasColor = sal_True;
     170             :         }
     171        5166 :         else  if( rProp.Name == "StartWith" )
     172             :         {
     173         690 :             rProp.Value >>= nStartValue;
     174             :         }
     175        4476 :         else  if( rProp.Name == "LeftMargin" )
     176             :         {
     177         180 :             rProp.Value >>= nSpaceBefore;
     178             :         }
     179        4296 :         else  if( rProp.Name == "FirstLineOffset" )
     180             :         {
     181         180 :             rProp.Value >>= nMinLabelWidth;
     182             :         }
     183        4116 :         else  if( rProp.Name == "SymbolTextDistance" )
     184             :         {
     185         180 :             rProp.Value >>= nMinLabelDist;
     186             :         }
     187        3936 :         else if( rProp.Name == "ParentNumbering" )
     188             :         {
     189         510 :             rProp.Value >>= nDisplayLevels;
     190         510 :             if( nDisplayLevels > nLevel+1 )
     191          63 :                 nDisplayLevels = static_cast<sal_Int16>( nLevel )+1;
     192             :         }
     193        3426 :         else if( rProp.Name == "CharStyleName" )
     194             :         {
     195         510 :             rProp.Value >>= sTextStyleName;
     196             :         }
     197        2916 :         else if( rProp.Name == "GraphicSize" )
     198             :         {
     199         180 :             awt::Size aSize;
     200         180 :             if( rProp.Value >>= aSize )
     201             :             {
     202         180 :                 nImageWidth = aSize.Width;
     203         180 :                 nImageHeight = aSize.Height;
     204             :             }
     205             :         }
     206        2736 :         else if( rProp.Name == "VertOrient" )
     207             :         {
     208           0 :             sal_Int16 nValue = 0;
     209           0 :             rProp.Value >>= nValue;
     210           0 :             eImageVertOrient = nValue;
     211             :         }
     212        2736 :         else if( rProp.Name == "PositionAndSpaceMode" )
     213             :         {
     214         510 :             sal_Int16 nValue = 0;
     215         510 :             rProp.Value >>= nValue;
     216         510 :             ePosAndSpaceMode = nValue;
     217             :         }
     218        2226 :         else if( rProp.Name == "LabelFollowedBy" )
     219             :         {
     220         510 :             sal_Int16 nValue = 0;
     221         510 :             rProp.Value >>= nValue;
     222         510 :             eLabelFollowedBy = nValue;
     223             :         }
     224        1716 :         else if( rProp.Name == "ListtabStopPosition" )
     225             :         {
     226         510 :             rProp.Value >>= nListtabStopPosition;
     227             :         }
     228        1206 :         else if( rProp.Name == "FirstLineIndent" )
     229             :         {
     230         510 :             rProp.Value >>= nFirstLineIndent;
     231             :         }
     232         696 :         else if( rProp.Name == "IndentAt" )
     233             :         {
     234         510 :             rProp.Value >>= nIndentAt;
     235             :         }
     236             :     }
     237             : 
     238         840 :     if( bOutline && (NumberingType::CHAR_SPECIAL == eType ||
     239         150 :                      NumberingType::BITMAP == eType) )
     240             :     {
     241             :         DBG_ASSERT( !bOutline,
     242             :            "SvxXMLNumRuleExport::exportLevelStyle: invalid style for outline" );
     243         690 :         return;
     244             :     }
     245             : 
     246         690 :     GetExport().CheckAttrList();
     247             : 
     248             :     // text:level
     249        1380 :     OUStringBuffer sTmp;
     250         690 :     sTmp.append( nLevel + 1 );
     251         690 :     GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_LEVEL, sTmp.makeStringAndClear() );
     252             :     // #i110694#: no style-name on list-level-style-image
     253             :     // #i116149#: neither prefix/suffix
     254         690 :     if (NumberingType::BITMAP != eType)
     255             :     {
     256         690 :         if (!sTextStyleName.isEmpty())
     257             :         {
     258          62 :             GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_STYLE_NAME,
     259         124 :                     GetExport().EncodeStyleName( sTextStyleName ) );
     260             :         }
     261         690 :         if (!sPrefix.isEmpty())
     262             :         {
     263           0 :             GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_NUM_PREFIX,
     264           0 :                     sPrefix );
     265             :         }
     266         690 :         if (!sSuffix.isEmpty())
     267             :         {
     268         360 :             GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_NUM_SUFFIX,
     269         360 :                     sSuffix );
     270             :         }
     271             :     }
     272             : 
     273         690 :     enum XMLTokenEnum eElem = XML_LIST_LEVEL_STYLE_NUMBER;
     274         690 :     if( NumberingType::CHAR_SPECIAL == eType )
     275             :     {
     276             :         // <text:list-level-style-bullet>
     277         178 :         eElem = XML_LIST_LEVEL_STYLE_BULLET;
     278             : 
     279         178 :         if( cBullet )
     280             :         {
     281         178 :             if( cBullet < ' ' )
     282             :             {
     283           0 :                 cBullet = 0xF000 + 149;
     284             :             }
     285             :             // text:bullet-char="..."
     286         178 :             sTmp.append( cBullet );
     287         178 :             GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_BULLET_CHAR,
     288         356 :                           sTmp.makeStringAndClear() );
     289             :         }
     290             : 
     291             :     }
     292         512 :     else if( NumberingType::BITMAP == eType )
     293             :     {
     294             :         // <text:list-level-style-image>
     295             : 
     296           0 :         eElem = XML_LIST_LEVEL_STYLE_IMAGE;
     297             : 
     298             : 
     299           0 :         if( !sImageURL.isEmpty() )
     300             :         {
     301           0 :             OUString sURL( GetExport().AddEmbeddedGraphicObject( sImageURL ) );
     302           0 :             if( !sURL.isEmpty() )
     303             :             {
     304           0 :                 GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_HREF, sURL );
     305             : 
     306           0 :                 GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_TYPE, XML_SIMPLE );
     307           0 :                 GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_SHOW, XML_EMBED );
     308           0 :                 GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_ACTUATE, XML_ONLOAD );
     309           0 :             }
     310             :         }
     311             :         else
     312             :         {
     313             :             DBG_ASSERT( !xBitmap.is(),
     314             :                         "embedded images are not supported by now" );
     315             :         }
     316             :     }
     317             :     else
     318             :     {
     319             :         // <text:list-level-style-number> or <text:outline-level-style>
     320         512 :         if( bOutline )
     321         150 :             eElem = XML_OUTLINE_LEVEL_STYLE;
     322             :         else
     323         362 :             eElem = XML_LIST_LEVEL_STYLE_NUMBER;
     324             : 
     325         512 :         GetExport().GetMM100UnitConverter().convertNumFormat( sTmp, eType );
     326         512 :         GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_NUM_FORMAT,
     327        1024 :                                        sTmp.makeStringAndClear() );
     328         512 :         GetExport().GetMM100UnitConverter().convertNumLetterSync( sTmp, eType );
     329         512 :         if( !sTmp.isEmpty() )
     330           0 :             GetExport().AddAttribute( XML_NAMESPACE_STYLE,
     331             :                                       XML_NUM_LETTER_SYNC,
     332           0 :                                            sTmp.makeStringAndClear() );
     333             : 
     334         512 :         if( nStartValue != 1 )
     335             :         {
     336          22 :             sTmp.append( (sal_Int32)nStartValue );
     337          22 :             GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_START_VALUE,
     338          44 :                           sTmp.makeStringAndClear() );
     339             :         }
     340         512 :         if( nDisplayLevels > 1 && NumberingType::NUMBER_NONE != eType )
     341             :         {
     342          16 :             sTmp.append( (sal_Int32)nDisplayLevels );
     343          16 :             GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_DISPLAY_LEVELS,
     344          32 :                           sTmp.makeStringAndClear() );
     345             :         }
     346             :     }
     347             : 
     348             :     {
     349         690 :         SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_TEXT, eElem,
     350         690 :                                   sal_True, sal_True );
     351             : 
     352        1380 :         OUStringBuffer sBuffer;
     353         690 :         if ( ePosAndSpaceMode == PositionAndSpaceMode::LABEL_WIDTH_AND_POSITION )
     354             :         {
     355         180 :             nSpaceBefore += nMinLabelWidth;
     356         180 :             nMinLabelWidth = -nMinLabelWidth;
     357         180 :             if( nSpaceBefore != 0 )
     358             :             {
     359         164 :                 GetExport().GetMM100UnitConverter().convertMeasureToXML(
     360         328 :                         sBuffer, nSpaceBefore );
     361         164 :                 GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_SPACE_BEFORE,
     362         328 :                               sBuffer.makeStringAndClear() );
     363             :             }
     364         180 :             if( nMinLabelWidth != 0 )
     365             :             {
     366         160 :                 GetExport().GetMM100UnitConverter().convertMeasureToXML(
     367         320 :                         sBuffer, nMinLabelWidth );
     368         160 :                 GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_MIN_LABEL_WIDTH,
     369         320 :                               sBuffer.makeStringAndClear() );
     370             :             }
     371         180 :             if( nMinLabelDist > 0 )
     372             :             {
     373           0 :                 GetExport().GetMM100UnitConverter().convertMeasureToXML(
     374           0 :                         sBuffer, nMinLabelDist );
     375           0 :                 GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_MIN_LABEL_DISTANCE,
     376           0 :                               sBuffer.makeStringAndClear() );
     377             :             }
     378             :         }
     379             :         /* Check, if properties for position-and-space-mode LABEL_ALIGNMENT
     380             :            are allowed to be exported. (#i89178#)
     381             :         */
     382         510 :         else if ( ePosAndSpaceMode == PositionAndSpaceMode::LABEL_ALIGNMENT &&
     383             :                   mbExportPositionAndSpaceModeLabelAlignment )
     384             :         {
     385         510 :             GetExport().AddAttribute( XML_NAMESPACE_TEXT,
     386             :                                       XML_LIST_LEVEL_POSITION_AND_SPACE_MODE,
     387         510 :                                       XML_LABEL_ALIGNMENT );
     388             :         }
     389         690 :         if( HoriOrientation::LEFT != eAdjust )
     390             :         {
     391          96 :             enum XMLTokenEnum eValue = XML_TOKEN_INVALID;
     392          96 :             switch( eAdjust )
     393             :             {
     394          96 :             case HoriOrientation::RIGHT:    eValue = XML_END;   break;
     395           0 :             case HoriOrientation::CENTER:   eValue = XML_CENTER;    break;
     396             :             }
     397          96 :             if( eValue != XML_TOKEN_INVALID )
     398          96 :                 GetExport().AddAttribute( XML_NAMESPACE_FO, XML_TEXT_ALIGN, eValue );
     399             :         }
     400             : 
     401         690 :         if( NumberingType::BITMAP == eType )
     402             :         {
     403           0 :             enum XMLTokenEnum eValue = XML_TOKEN_INVALID;
     404           0 :             switch( eImageVertOrient )
     405             :             {
     406             :             case VertOrientation::BOTTOM:   // yes, its OK: BOTTOM means that the baseline
     407             :                                     // hits the frame at its topmost position
     408             :             case VertOrientation::LINE_TOP:
     409             :             case VertOrientation::CHAR_TOP:
     410           0 :                 eValue = XML_TOP;
     411           0 :                 break;
     412             :             case VertOrientation::CENTER:
     413             :             case VertOrientation::LINE_CENTER:
     414             :             case VertOrientation::CHAR_CENTER:
     415           0 :                 eValue = XML_MIDDLE;
     416           0 :                 break;
     417             :             case VertOrientation::TOP:      // yes, its OK: TOP means that the baseline
     418             :                                     // hits the frame at its bottommost position
     419             :             case VertOrientation::LINE_BOTTOM:
     420             :             case VertOrientation::CHAR_BOTTOM:
     421           0 :                 eValue = XML_BOTTOM;
     422           0 :                 break;
     423             :             }
     424           0 :             if( eValue != XML_TOKEN_INVALID )
     425           0 :                 GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_VERTICAL_POS, eValue );
     426             : 
     427           0 :             eValue = XML_TOKEN_INVALID;
     428           0 :             switch( eImageVertOrient )
     429             :             {
     430             :             case VertOrientation::TOP:
     431             :             case VertOrientation::CENTER:
     432             :             case VertOrientation::BOTTOM:
     433           0 :                 eValue = XML_BASELINE;
     434           0 :                 break;
     435             :             case VertOrientation::LINE_TOP:
     436             :             case VertOrientation::LINE_CENTER:
     437             :             case VertOrientation::LINE_BOTTOM:
     438           0 :                 eValue = XML_LINE;
     439           0 :                 break;
     440             :             case VertOrientation::CHAR_TOP:
     441             :             case VertOrientation::CHAR_CENTER:
     442             :             case VertOrientation::CHAR_BOTTOM:
     443           0 :                 eValue = XML_CHAR;
     444           0 :                 break;
     445             :             }
     446           0 :             if( eValue != XML_TOKEN_INVALID )
     447           0 :                 GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_VERTICAL_REL, eValue );
     448             : 
     449           0 :             if( nImageWidth > 0 )
     450             :             {
     451           0 :                 GetExport().GetMM100UnitConverter().convertMeasureToXML(
     452           0 :                         sBuffer, nImageWidth );
     453           0 :                 GetExport().AddAttribute( XML_NAMESPACE_FO, XML_WIDTH,
     454           0 :                               sBuffer.makeStringAndClear() );
     455             :             }
     456             : 
     457           0 :             if( nImageHeight > 0 )
     458             :             {
     459           0 :                 GetExport().GetMM100UnitConverter().convertMeasureToXML(
     460           0 :                         sBuffer, nImageHeight );
     461           0 :                 GetExport().AddAttribute( XML_NAMESPACE_FO, XML_HEIGHT,
     462           0 :                               sBuffer.makeStringAndClear() );
     463             :             }
     464             :         }
     465             : 
     466             :         {
     467         690 :             SvXMLElementExport aElement( GetExport(), XML_NAMESPACE_STYLE,
     468         690 :                                       XML_LIST_LEVEL_PROPERTIES, sal_True, sal_True );
     469             : 
     470             :             /* Check, if properties for position-and-space-mode LABEL_ALIGNMENT
     471             :                are allowed to be exported. (#i89178#)
     472             :             */
     473         690 :             if ( ePosAndSpaceMode == PositionAndSpaceMode::LABEL_ALIGNMENT &&
     474             :                  mbExportPositionAndSpaceModeLabelAlignment )
     475             :             {
     476         510 :                 enum XMLTokenEnum eValue = XML_LISTTAB;
     477         510 :                 if ( eLabelFollowedBy == LabelFollow::SPACE )
     478             :                 {
     479           0 :                     eValue = XML_SPACE;
     480             :                 }
     481         510 :                 else if ( eLabelFollowedBy == LabelFollow::NOTHING )
     482             :                 {
     483           0 :                     eValue = XML_NOTHING;
     484             :                 }
     485         510 :                 GetExport().AddAttribute( XML_NAMESPACE_TEXT,
     486         510 :                                           XML_LABEL_FOLLOWED_BY, eValue );
     487             : 
     488        1020 :                 if ( eLabelFollowedBy == LabelFollow::LISTTAB &&
     489         510 :                      nListtabStopPosition > 0 )
     490             :                 {
     491         510 :                     GetExport().GetMM100UnitConverter().convertMeasureToXML(
     492        1020 :                             sBuffer, nListtabStopPosition );
     493         510 :                     GetExport().AddAttribute( XML_NAMESPACE_TEXT,
     494             :                                               XML_LIST_TAB_STOP_POSITION,
     495        1020 :                                               sBuffer.makeStringAndClear() );
     496             :                 }
     497             : 
     498         510 :                 if ( nFirstLineIndent != 0 )
     499             :                 {
     500         510 :                     GetExport().GetMM100UnitConverter().convertMeasureToXML(
     501        1020 :                             sBuffer, nFirstLineIndent );
     502         510 :                     GetExport().AddAttribute( XML_NAMESPACE_FO,
     503             :                                               XML_TEXT_INDENT,
     504        1020 :                                               sBuffer.makeStringAndClear() );
     505             :                 }
     506             : 
     507         510 :                 if ( nIndentAt != 0 )
     508             :                 {
     509         508 :                     GetExport().GetMM100UnitConverter().convertMeasureToXML(
     510        1016 :                             sBuffer, nIndentAt );
     511         508 :                     GetExport().AddAttribute( XML_NAMESPACE_FO,
     512             :                                               XML_MARGIN_LEFT,
     513        1016 :                                               sBuffer.makeStringAndClear() );
     514             :                 }
     515             : 
     516         510 :                 SvXMLElementExport aLabelAlignmentElement( GetExport(), XML_NAMESPACE_STYLE,
     517             :                                              XML_LIST_LEVEL_LABEL_ALIGNMENT,
     518         510 :                                              sal_True, sal_True );
     519         690 :             }
     520             :         }
     521             : 
     522         690 :         if( NumberingType::CHAR_SPECIAL == eType )
     523             :         {
     524         178 :             if( !sBulletFontName.isEmpty() )
     525             :             {
     526             :                 OUString sStyleName =
     527         178 :                     GetExport().GetFontAutoStylePool()->Find(
     528             :                         sBulletFontName, sBulletFontStyleName,
     529             :                         eBulletFontFamily, eBulletFontPitch,
     530         356 :                         eBulletFontEncoding );
     531             : 
     532         178 :                 if( !sStyleName.isEmpty() )
     533             :                 {
     534           2 :                         GetExport().AddAttribute( XML_NAMESPACE_STYLE,
     535             :                                                   XML_FONT_NAME,
     536           2 :                                                   sStyleName );
     537             :                 }
     538             :                 else
     539             :                 {
     540         176 :                     Any aAny;
     541         352 :                     OUString sTemp;
     542             : 
     543             :                     const SvXMLUnitConverter& rUnitConv =
     544         176 :                         GetExport().GetMM100UnitConverter();
     545         352 :                     XMLFontFamilyNamePropHdl aFamilyNameHdl;
     546         176 :                     aAny <<= sBulletFontName;
     547         176 :                     if( aFamilyNameHdl.exportXML( sTemp, aAny, rUnitConv ) )
     548         176 :                         GetExport().AddAttribute( XML_NAMESPACE_FO,
     549         176 :                                                   XML_FONT_FAMILY, sTemp );
     550             : 
     551         176 :                     if( !sBulletFontStyleName.isEmpty() )
     552           0 :                         GetExport().AddAttribute( XML_NAMESPACE_STYLE,
     553             :                                                   XML_FONT_STYLE_NAME,
     554           0 :                                                   sBulletFontStyleName );
     555             : 
     556         352 :                     XMLFontFamilyPropHdl aFamilyHdl;
     557         176 :                     aAny <<= (sal_Int16)eBulletFontFamily;
     558         176 :                     if( aFamilyHdl.exportXML( sTemp, aAny, rUnitConv  ) )
     559           6 :                         GetExport().AddAttribute( XML_NAMESPACE_STYLE,
     560             :                                                   XML_FONT_FAMILY_GENERIC,
     561           6 :                                                   sTemp );
     562             : 
     563         352 :                     XMLFontPitchPropHdl aPitchHdl;
     564         176 :                     aAny <<= (sal_Int16)eBulletFontPitch;
     565         176 :                     if( aPitchHdl.exportXML( sTemp, aAny, rUnitConv  ) )
     566           6 :                         GetExport().AddAttribute( XML_NAMESPACE_STYLE,
     567           6 :                                                   XML_FONT_PITCH, sTemp );
     568             : 
     569         352 :                     XMLFontEncodingPropHdl aEncHdl;
     570         176 :                     aAny <<= (sal_Int16)eBulletFontEncoding;
     571         176 :                     if( aEncHdl.exportXML( sTemp, aAny, rUnitConv  ) )
     572          10 :                         GetExport().AddAttribute( XML_NAMESPACE_STYLE,
     573         186 :                                                   XML_FONT_CHARSET, sTemp );
     574         178 :                 }
     575             :             }
     576             :         }
     577         690 :         if( NumberingType::BITMAP != eType )
     578             :         {
     579             :             // fo:color = "#..."
     580         690 :             if( bHasColor )
     581             :             {
     582         180 :                 if (0xffffffff == static_cast<sal_uInt32>(nColor))
     583             :                 {
     584         160 :                     GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_USE_WINDOW_FONT_COLOR, XML_TRUE );
     585             :                 }
     586             :                 else
     587             :                 {
     588          20 :                     ::sax::Converter::convertColor( sBuffer, nColor );
     589          20 :                     GetExport().AddAttribute( XML_NAMESPACE_FO, XML_COLOR,
     590          40 :                                   sBuffer.makeStringAndClear() );
     591             :                 }
     592             :             }
     593             :             // fo:height="...%"
     594         690 :             if( nBullRelSize )
     595             :             {
     596         180 :                 ::sax::Converter::convertPercent( sTmp, nBullRelSize );
     597         180 :                 GetExport().AddAttribute( XML_NAMESPACE_FO, XML_FONT_SIZE,
     598         360 :                               sTmp.makeStringAndClear() );
     599             :             }
     600             :         }
     601         690 :         if( GetExport().GetAttrList().getLength() > 0 )
     602             :         {
     603         198 :             SvXMLElementExport aElement( GetExport(), XML_NAMESPACE_STYLE,
     604         198 :                                       XML_TEXT_PROPERTIES, sal_True, sal_True );
     605             :         }
     606         690 :         if( NumberingType::BITMAP == eType && !sImageURL.isEmpty() )
     607             :         {
     608             :             // optional office:binary-data
     609           0 :             GetExport().AddEmbeddedGraphicObjectAsBase64( sImageURL );
     610         690 :         }
     611         690 :     }
     612             : }
     613             : 
     614             : 
     615          54 : void SvxXMLNumRuleExport::AddListStyleAttributes()
     616             : {
     617          54 : }
     618             : 
     619             : 
     620         252 : SvxXMLNumRuleExport::SvxXMLNumRuleExport( SvXMLExport& rExp ) :
     621             :     rExport( rExp ),
     622             :     sNumberingRules( "NumberingRules" ),
     623             :     sIsPhysical( "IsPhysical" ),
     624             :     sIsContinuousNumbering( "IsContinuousNumbering" ),
     625             :     // Let list style creation depend on Load/Save option "ODF format version" (#i89178#)
     626         252 :     mbExportPositionAndSpaceModeLabelAlignment( true )
     627             : {
     628         252 :     switch ( GetExport().getDefaultVersion() )
     629             :     {
     630             :         case SvtSaveOptions::ODFVER_010:
     631             :         case SvtSaveOptions::ODFVER_011:
     632             :         {
     633           0 :             mbExportPositionAndSpaceModeLabelAlignment = false;
     634             :         }
     635           0 :         break;
     636             :         default: // ODFVER_UNKNOWN or ODFVER_012
     637             :         {
     638         252 :             mbExportPositionAndSpaceModeLabelAlignment = true;
     639             :         }
     640             :     }
     641         252 : }
     642             : 
     643         247 : SvxXMLNumRuleExport::~SvxXMLNumRuleExport()
     644             : {
     645         247 : }
     646             : 
     647          54 : void SvxXMLNumRuleExport::exportNumberingRule(
     648             :         const OUString& rName, sal_Bool bIsHidden,
     649             :         const Reference< XIndexReplace >& rNumRule )
     650             : {
     651          54 :     Reference< XPropertySet > xPropSet( rNumRule, UNO_QUERY );
     652         108 :     Reference< XPropertySetInfo > xPropSetInfo;
     653          54 :     if( xPropSet.is() )
     654          36 :            xPropSetInfo = xPropSet->getPropertySetInfo();
     655             : 
     656          54 :     GetExport().CheckAttrList();
     657             : 
     658             :     // style:name="..."
     659          54 :     if( !rName.isEmpty() )
     660             :     {
     661          54 :         sal_Bool bEncoded = sal_False;
     662          54 :         GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_NAME,
     663         108 :                           GetExport().EncodeStyleName( rName, &bEncoded ) );
     664          54 :         if( bEncoded )
     665           0 :             GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_DISPLAY_NAME,
     666           0 :                                  rName);
     667             :     }
     668             : 
     669             :     // style:hidden="..."
     670          54 :     if ( bIsHidden && GetExport( ).getDefaultVersion( ) == SvtSaveOptions::ODFVER_LATEST )
     671           0 :         GetExport( ).AddAttribute( XML_NAMESPACE_STYLE, XML_HIDDEN, "true" );
     672             : 
     673             :     // text:consecutive-numbering="..."
     674          54 :     sal_Bool bContNumbering = sal_False;
     675          90 :     if( xPropSetInfo.is() &&
     676          36 :         xPropSetInfo->hasPropertyByName( sIsContinuousNumbering ) )
     677             :     {
     678          36 :         Any aAny( xPropSet->getPropertyValue( sIsContinuousNumbering ) );
     679          36 :         bContNumbering = *(sal_Bool *)aAny.getValue();
     680             :     }
     681          54 :     if( bContNumbering )
     682           0 :         GetExport().AddAttribute( XML_NAMESPACE_TEXT,
     683           0 :                                   XML_CONSECUTIVE_NUMBERING, XML_TRUE );
     684             : 
     685             :     // other application specific attributes
     686          54 :     AddListStyleAttributes();
     687             : 
     688             :     {
     689          54 :         SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_TEXT, XML_LIST_STYLE ,
     690          54 :                                   sal_True, sal_True );
     691          54 :         exportLevelStyles( rNumRule );
     692          54 :     }
     693          54 : }
     694             : 
     695         196 : sal_Bool SvxXMLNumRuleExport::exportStyle( const Reference< XStyle >& rStyle )
     696             : {
     697         196 :     Reference< XPropertySet > xPropSet( rStyle, UNO_QUERY );
     698         392 :     Reference< XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo();
     699             : 
     700         392 :     Any aAny;
     701             : 
     702             :     // Don't export styles that aren't existing really. This may be the
     703             :     // case for StarOffice Writer's pool styles.
     704         196 :     if( xPropSetInfo->hasPropertyByName( sIsPhysical ) )
     705             :     {
     706         196 :         aAny = xPropSet->getPropertyValue( sIsPhysical );
     707         196 :         if( !*(sal_Bool *)aAny.getValue() )
     708         160 :             return sal_False;
     709             :     }
     710             : 
     711          36 :     aAny = xPropSet->getPropertyValue( sNumberingRules );
     712          72 :     Reference<XIndexReplace> xNumRule;
     713          36 :     aAny >>= xNumRule;
     714             : 
     715          72 :     OUString sName = rStyle->getName();
     716             : 
     717          36 :     sal_Bool bHidden = sal_False;
     718          36 :     if ( xPropSetInfo->hasPropertyByName( "Hidden" ) )
     719             :     {
     720          36 :         aAny = xPropSet->getPropertyValue( "Hidden" );
     721          36 :         aAny >>= bHidden;
     722             :     }
     723             : 
     724          36 :     exportNumberingRule( sName, bHidden, xNumRule );
     725             : 
     726         232 :     return sal_True;
     727             : }
     728             : 
     729          15 : void SvxXMLNumRuleExport::exportOutline()
     730             : {
     731          15 :     Reference< XChapterNumberingSupplier > xCNSupplier( GetExport().GetModel(),
     732          15 :                                                         UNO_QUERY );
     733             :     DBG_ASSERT( xCNSupplier.is(), "no chapter numbering supplier" );
     734             : 
     735          15 :     if( xCNSupplier.is() )
     736             :     {
     737          15 :         Reference< XIndexReplace > xNumRule( xCNSupplier->getChapterNumberingRules() );
     738             :         DBG_ASSERT( xNumRule.is(), "no chapter numbering rules" );
     739             : 
     740          15 :         if( xNumRule.is() )
     741             :         {
     742             :             /* Outline style has property style:name since ODF 1.2
     743             :                Thus, export this property and adjust fix for issue #i69627# (#i90780#)
     744             :             */
     745          15 :             OUString sOutlineStyleName;
     746             :             {
     747             :                 Reference<XPropertySet> xNumRulePropSet(
     748          15 :                     xCNSupplier->getChapterNumberingRules(), UNO_QUERY );
     749          15 :                 if (xNumRulePropSet.is())
     750             :                 {
     751          15 :                     const OUString sName( "Name" );
     752          15 :                     xNumRulePropSet->getPropertyValue( sName ) >>= sOutlineStyleName;
     753          15 :                 }
     754             :             }
     755             :             const SvtSaveOptions::ODFDefaultVersion nODFVersion =
     756          15 :                                                 GetExport().getDefaultVersion();
     757          30 :             if ( ( nODFVersion == SvtSaveOptions::ODFVER_010 ||
     758          15 :                    nODFVersion == SvtSaveOptions::ODFVER_011 ) &&
     759           0 :                  GetExport().writeOutlineStyleAsNormalListStyle() )
     760             :             {
     761           0 :                 exportNumberingRule( sOutlineStyleName, sal_False, xNumRule );
     762             :             }
     763             :             else
     764             :             {
     765          15 :                 if ( nODFVersion != SvtSaveOptions::ODFVER_010 &&
     766             :                      nODFVersion != SvtSaveOptions::ODFVER_011 )
     767             :                 {
     768             :                     // style:name="..."
     769          15 :                     GetExport().CheckAttrList();
     770          15 :                     if ( !sOutlineStyleName.isEmpty() )
     771             :                      {
     772          15 :                         sal_Bool bEncoded = sal_False;
     773          15 :                         GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_NAME,
     774          15 :                                         GetExport().EncodeStyleName( sOutlineStyleName,
     775          30 :                                                                      &bEncoded ) );
     776          15 :                         if( bEncoded )
     777           0 :                             GetExport().AddAttribute( XML_NAMESPACE_STYLE,
     778             :                                                       XML_DISPLAY_NAME,
     779           0 :                                                       sOutlineStyleName );
     780             :                     }
     781             :                 }
     782          15 :                 SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_TEXT,
     783          15 :                                           XML_OUTLINE_STYLE, sal_True, sal_True );
     784          15 :                 exportLevelStyles( xNumRule, sal_True );
     785          15 :             }
     786          15 :         }
     787          15 :     }
     788          15 : }
     789             : 
     790          16 : void SvxXMLNumRuleExport::exportStyles( sal_Bool bUsed,
     791             :                                          XMLTextListAutoStylePool *pPool,
     792             :                                          sal_Bool bExportChapterNumbering )
     793             : {
     794          16 :     if( bExportChapterNumbering )
     795          15 :         exportOutline();
     796             : 
     797          16 :     Reference< XStyleFamiliesSupplier > xFamiliesSupp( GetExport().GetModel(), UNO_QUERY );
     798             :     DBG_ASSERT( xFamiliesSupp.is(), "No XStyleFamiliesSupplier from XModel for export!" );
     799          16 :     if( xFamiliesSupp.is() )
     800             :     {
     801          16 :         Reference< XNameAccess > xFamilies( xFamiliesSupp->getStyleFamilies() );
     802             :         DBG_ASSERT( xFamiliesSupp.is(), "getStyleFamilies() from XModel failed for export!" );
     803             : 
     804          16 :         if( xFamilies.is() )
     805             :         {
     806          16 :             const OUString aNumberStyleName( "NumberingStyles" );
     807             : 
     808          32 :             Reference< XIndexAccess > xStyles;
     809          16 :             if( xFamilies->hasByName( aNumberStyleName ) )
     810             :             {
     811          16 :                 xFamilies->getByName( aNumberStyleName ) >>= xStyles;
     812             : 
     813             :                 DBG_ASSERT( xStyles.is(), "Style not found for export!" );
     814             : 
     815          16 :                 if( xStyles.is() )
     816             :                 {
     817          16 :                     const sal_Int32 nStyles = xStyles->getCount();
     818             : 
     819         212 :                     for( sal_Int32 i=0; i < nStyles; i++ )
     820             :                     {
     821         196 :                         Reference< XStyle > xStyle;
     822         196 :                         xStyles->getByIndex( i ) >>= xStyle;
     823             : 
     824         196 :                         if( !bUsed || xStyle->isInUse() )
     825             :                         {
     826         196 :                             exportStyle( xStyle );
     827         196 :                             if( pPool )
     828         196 :                                 pPool->RegisterName( xStyle->getName() );
     829             :                         }
     830         196 :                     }
     831             :                 }
     832          16 :             }
     833          16 :         }
     834          16 :     }
     835          16 : }
     836             : 
     837             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10