LCOV - code coverage report
Current view: top level - writerfilter/source/dmapper - SettingsTable.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 143 147 97.3 %
Date: 2015-06-13 12:38:46 Functions: 23 23 100.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             : #include <SettingsTable.hxx>
      21             : 
      22             : #include <vector>
      23             : 
      24             : #include <rtl/ustring.hxx>
      25             : #include <com/sun/star/beans/XPropertySet.hpp>
      26             : #include <com/sun/star/beans/XPropertyState.hpp>
      27             : #include <com/sun/star/container/XNameContainer.hpp>
      28             : #include <com/sun/star/style/XStyle.hpp>
      29             : #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
      30             : #include <comphelper/sequence.hxx>
      31             : #include <ooxml/resourceids.hxx>
      32             : #include <ConversionHelper.hxx>
      33             : #include "util.hxx"
      34             : 
      35             : using namespace com::sun::star;
      36             : 
      37             : namespace writerfilter {
      38             : 
      39             : namespace dmapper
      40             : {
      41             : 
      42        1984 : struct SettingsTable_Impl
      43             : {
      44             :     DomainMapper&       m_rDMapper;
      45             :     const uno::Reference< lang::XMultiServiceFactory > m_xTextFactory;
      46             : 
      47             :     OUString     m_sCharacterSpacing;
      48             :     OUString     m_sDecimalSymbol;
      49             :     OUString     m_sListSeparatorForFields; //2.15.1.56 listSeparator (List Separator for Field Code Evaluation)
      50             : 
      51             :     int                 m_nDefaultTabStop;
      52             :     int                 m_nHyphenationZone;
      53             : 
      54             :     bool                m_bNoPunctuationKerning;
      55             :     bool                m_doNotIncludeSubdocsInStats; // Do Not Include Content in Text Boxes, Footnotes, and Endnotes in Document Statistics)
      56             :     bool                m_bRecordChanges;
      57             :     int                 m_nEdit;
      58             :     bool                m_bFormatting;
      59             :     bool                m_bEnforcement;
      60             :     int                 m_nCryptProviderType;
      61             :     int                 m_nCryptAlgorithmClass;
      62             :     int                 m_nCryptAlgorithmType;
      63             :     OUString     m_sCryptAlgorithmSid;
      64             :     int                 m_nCryptSpinCount;
      65             :     OUString     m_sCryptProvider;
      66             :     OUString     m_sAlgIdExt;
      67             :     OUString     m_sAlgIdExtSource;
      68             :     OUString     m_sCryptProviderTypeExt;
      69             :     OUString     m_sCryptProviderTypeExtSource;
      70             :     OUString     m_sHash;
      71             :     OUString     m_sSalt;
      72             :     bool                m_bLinkStyles;
      73             :     sal_Int16           m_nZoomFactor;
      74             :     Id                  m_nView;
      75             :     bool                m_bEvenAndOddHeaders;
      76             :     bool                m_bUsePrinterMetrics;
      77             :     bool                embedTrueTypeFonts;
      78             :     bool                embedSystemFonts;
      79             :     bool                m_bDoNotUseHTMLParagraphAutoSpacing;
      80             :     bool                m_bNoColumnBalance;
      81             :     bool                m_bAutoHyphenation;
      82             :     bool                m_bSplitPgBreakAndParaMark;
      83             :     bool                m_bMirrorMargin;
      84             :     uno::Sequence<beans::PropertyValue> m_pThemeFontLangProps;
      85             : 
      86             :     std::vector<beans::PropertyValue> m_aCompatSettings;
      87             :     uno::Sequence<beans::PropertyValue> m_pCurrentCompatSetting;
      88             : 
      89        1984 :     SettingsTable_Impl( DomainMapper& rDMapper, const uno::Reference< lang::XMultiServiceFactory > & xTextFactory ) :
      90             :     m_rDMapper( rDMapper )
      91             :     , m_xTextFactory( xTextFactory )
      92             :     , m_nDefaultTabStop( 720 ) //default is 1/2 in
      93             :     , m_nHyphenationZone(0)
      94             :     , m_bNoPunctuationKerning(false)
      95             :     , m_doNotIncludeSubdocsInStats(false)
      96             :     , m_bRecordChanges(false)
      97             :     , m_nEdit(NS_ooxml::LN_Value_doc_ST_DocProtect_none)
      98             :     , m_bFormatting(false)
      99             :     , m_bEnforcement(false)
     100             :     , m_nCryptProviderType(NS_ooxml::LN_Value_doc_ST_CryptProv_rsaAES)
     101             :     , m_nCryptAlgorithmClass(NS_ooxml::LN_Value_doc_ST_AlgClass_hash)
     102             :     , m_nCryptAlgorithmType(NS_ooxml::LN_Value_doc_ST_AlgType_typeAny)
     103             :     , m_nCryptSpinCount(0)
     104             :     , m_bLinkStyles(false)
     105             :     , m_nZoomFactor(0)
     106             :     , m_nView(0)
     107             :     , m_bEvenAndOddHeaders(false)
     108             :     , m_bUsePrinterMetrics(false)
     109             :     , embedTrueTypeFonts(false)
     110             :     , embedSystemFonts(false)
     111             :     , m_bDoNotUseHTMLParagraphAutoSpacing(false)
     112             :     , m_bNoColumnBalance(false)
     113             :     , m_bAutoHyphenation(false)
     114             :     , m_bSplitPgBreakAndParaMark(false)
     115             :     , m_bMirrorMargin(false)
     116             :     , m_pThemeFontLangProps(3)
     117        1984 :     , m_pCurrentCompatSetting(3)
     118        1984 :     {}
     119             : 
     120             : };
     121             : 
     122        1984 : SettingsTable::SettingsTable(DomainMapper& rDMapper, const uno::Reference< lang::XMultiServiceFactory > & xTextFactory)
     123             : : LoggedProperties("SettingsTable")
     124             : , LoggedTable("SettingsTable")
     125        1984 : , m_pImpl( new SettingsTable_Impl(rDMapper, xTextFactory) )
     126             : {
     127             : 
     128        1984 : }
     129             : 
     130        5952 : SettingsTable::~SettingsTable()
     131             : {
     132        1984 :     delete m_pImpl;
     133        3968 : }
     134             : 
     135       18554 : void SettingsTable::lcl_attribute(Id nName, Value & val)
     136             : {
     137       18554 :     int nIntValue = val.getInt();
     138       18554 :     OUString sStringValue = val.getString();
     139             : 
     140       18554 :     switch(nName)
     141             :     {
     142             :     case NS_ooxml::LN_CT_Zoom_percent:
     143        1628 :         m_pImpl->m_nZoomFactor = nIntValue;
     144        1628 :     break;
     145             :     case NS_ooxml::LN_CT_Language_val:
     146        1400 :         m_pImpl->m_pThemeFontLangProps[0].Name = "val";
     147        1400 :         m_pImpl->m_pThemeFontLangProps[0].Value <<= sStringValue;
     148        1400 :         break;
     149             :     case NS_ooxml::LN_CT_Language_eastAsia:
     150         817 :         m_pImpl->m_pThemeFontLangProps[1].Name = "eastAsia";
     151         817 :         m_pImpl->m_pThemeFontLangProps[1].Value <<= sStringValue;
     152         817 :         break;
     153             :     case NS_ooxml::LN_CT_Language_bidi:
     154         839 :         m_pImpl->m_pThemeFontLangProps[2].Name = "bidi";
     155         839 :         m_pImpl->m_pThemeFontLangProps[2].Value <<= sStringValue;
     156         839 :         break;
     157             :     case NS_ooxml::LN_CT_View_val:
     158          10 :         m_pImpl->m_nView = nIntValue;
     159          10 :         break;
     160             :     case NS_ooxml::LN_CT_CompatSetting_name:
     161        4144 :         m_pImpl->m_pCurrentCompatSetting[0].Name = "name";
     162        4144 :         m_pImpl->m_pCurrentCompatSetting[0].Value <<= sStringValue;
     163        4144 :         break;
     164             :     case NS_ooxml::LN_CT_CompatSetting_uri:
     165        4144 :         m_pImpl->m_pCurrentCompatSetting[1].Name = "uri";
     166        4144 :         m_pImpl->m_pCurrentCompatSetting[1].Value <<= sStringValue;
     167        4144 :         break;
     168             :     case NS_ooxml::LN_CT_CompatSetting_val:
     169        4144 :         m_pImpl->m_pCurrentCompatSetting[2].Name = "val";
     170        4144 :         m_pImpl->m_pCurrentCompatSetting[2].Value <<= sStringValue;
     171        4144 :         break;
     172             :     default:
     173             :     {
     174             : #ifdef DEBUG_WRITERFILTER
     175             :         TagLogger::getInstance().element("unhandled");
     176             : #endif
     177             :     }
     178       18554 :     }
     179       18554 : }
     180             : 
     181       20682 : void SettingsTable::lcl_sprm(Sprm& rSprm)
     182             : {
     183       20682 :     sal_uInt32 nSprmId = rSprm.getId();
     184             : 
     185       20682 :     Value::Pointer_t pValue = rSprm.getValue();
     186       20682 :     sal_Int32 nIntValue = pValue->getInt();
     187             :     (void)nIntValue;
     188       41364 :     OUString sStringValue = pValue->getString();
     189             : 
     190       20682 :     switch(nSprmId)
     191             :     {
     192             :     case NS_ooxml::LN_CT_Settings_zoom: //  92469;
     193             :     case NS_ooxml::LN_CT_Settings_proofState: //  92489;
     194             :     case NS_ooxml::LN_CT_Settings_attachedTemplate: //  92491;
     195             :     case NS_ooxml::LN_CT_Settings_hdrShapeDefaults: //  92544;
     196             :     case NS_ooxml::LN_CT_Settings_footnotePr: //  92545;
     197             :     case NS_ooxml::LN_CT_Settings_endnotePr: //  92546;
     198             :     case NS_ooxml::LN_CT_Settings_compat: //  92547;
     199             :     case NS_ooxml::LN_CT_Settings_themeFontLang: //  92552;
     200             :     case NS_ooxml::LN_CT_Settings_shapeDefaults: //  92560;
     201             :     case NS_ooxml::LN_CT_Settings_view:
     202             :     //PropertySetValues - need to be resolved
     203             :     {
     204        6894 :         writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
     205        6894 :         if( pProperties.get())
     206        6894 :             pProperties->resolve(*this);
     207             :     }
     208        6894 :     break;
     209             :     case NS_ooxml::LN_CT_Settings_stylePaneFormatFilter: // 92493;
     210          95 :     break;
     211             :     case NS_ooxml::LN_CT_Settings_defaultTabStop: //  92505;
     212        1632 :     m_pImpl->m_nDefaultTabStop = nIntValue;
     213        1632 :     break;
     214             :     case NS_ooxml::LN_CT_Settings_linkStyles: // 92663;
     215           8 :     m_pImpl->m_bLinkStyles = nIntValue;
     216           8 :     break;
     217             :     case NS_ooxml::LN_CT_Settings_evenAndOddHeaders:
     218          55 :     m_pImpl->m_bEvenAndOddHeaders = nIntValue;
     219          55 :     break;
     220             :     case NS_ooxml::LN_CT_Settings_noPunctuationKerning: //  92526;
     221          69 :     m_pImpl->m_bNoPunctuationKerning = nIntValue != 0;
     222          69 :     break;
     223             :     case NS_ooxml::LN_CT_Settings_characterSpacingControl: //  92527;
     224         949 :     m_pImpl->m_sCharacterSpacing = sStringValue; // doNotCompress, compressPunctuation, compressPunctuationAndJapaneseKana
     225         949 :     break;
     226             :     case NS_ooxml::LN_CT_Settings_doNotIncludeSubdocsInStats: //  92554; // Do Not Include Content in Text Boxes, Footnotes, and Endnotes in Document Statistics)
     227         108 :     m_pImpl->m_doNotIncludeSubdocsInStats = nIntValue != 0;
     228         108 :     break;
     229             :     case NS_ooxml::LN_CT_Settings_decimalSymbol: //  92562;
     230         949 :     m_pImpl->m_sDecimalSymbol = sStringValue;
     231         949 :     break;
     232             :     case NS_ooxml::LN_CT_Settings_listSeparator: //  92563;
     233         949 :     m_pImpl->m_sListSeparatorForFields = sStringValue;
     234         949 :     break;
     235             :     case NS_ooxml::LN_CT_Settings_rsids: //  92549; revision save Ids - probably not necessary
     236         946 :     break;
     237             :     case NS_ooxml::LN_CT_Settings_hyphenationZone: // 92508;
     238         132 :     m_pImpl->m_nHyphenationZone = nIntValue;
     239         132 :     break;
     240             :     case NS_ooxml::LN_CT_Compat_useFELayout: // 92422;
     241             :     // useFELayout (Do Not Bypass East Asian/Complex Script Layout Code - support of old versions of Word - ignored)
     242         196 :     break;
     243             :     case NS_ooxml::LN_CT_Settings_trackRevisions:
     244             :     {
     245          35 :         m_pImpl->m_bRecordChanges = bool(rSprm.getValue( )->getInt( ) );
     246             :     }
     247          35 :     break;
     248             :     case NS_ooxml::LN_CT_Settings_documentProtection:
     249             :         {
     250          12 :             resolveSprmProps(*this, rSprm);
     251             :         }
     252          12 :         break;
     253             :     case NS_ooxml::LN_CT_Compat_usePrinterMetrics:
     254           0 :         m_pImpl->m_bUsePrinterMetrics = nIntValue;
     255           0 :         break;
     256             :     case NS_ooxml::LN_CT_Settings_embedTrueTypeFonts:
     257           0 :         m_pImpl->embedTrueTypeFonts = nIntValue != 0;
     258           0 :         break;
     259             :     case NS_ooxml::LN_CT_Settings_embedSystemFonts:
     260          94 :         m_pImpl->embedSystemFonts = nIntValue != 0;
     261          94 :         break;
     262             :     case NS_ooxml::LN_CT_Compat_doNotUseHTMLParagraphAutoSpacing:
     263          10 :         m_pImpl->m_bDoNotUseHTMLParagraphAutoSpacing = nIntValue;
     264          10 :         break;
     265             :     case NS_ooxml::LN_CT_Compat_splitPgBreakAndParaMark:
     266          25 :         m_pImpl->m_bSplitPgBreakAndParaMark = nIntValue;
     267          25 :         break;
     268             :     case NS_ooxml::LN_CT_Settings_mirrorMargins:
     269          15 :         m_pImpl->m_bMirrorMargin = nIntValue;
     270          15 :         break;
     271             :     case NS_ooxml::LN_CT_Compat_compatSetting:
     272             :     {
     273        4144 :         writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
     274        4144 :         if (pProperties.get())
     275             :         {
     276        4144 :             pProperties->resolve(*this);
     277             : 
     278        4144 :             beans::PropertyValue aValue;
     279        4144 :             aValue.Name = "compatSetting";
     280        4144 :             aValue.Value = uno::makeAny(m_pImpl->m_pCurrentCompatSetting);
     281        4144 :             m_pImpl->m_aCompatSettings.push_back(aValue);
     282        4144 :         }
     283             :     }
     284        4144 :     break;
     285             :     case NS_ooxml::LN_CT_Compat_noColumnBalance:
     286           2 :         m_pImpl->m_bNoColumnBalance = nIntValue;
     287           2 :         break;
     288             :     case NS_ooxml::LN_CT_Settings_autoHyphenation:
     289          71 :         m_pImpl->m_bAutoHyphenation = nIntValue;
     290          71 :         break;
     291             :     default:
     292             :     {
     293             : #ifdef DEBUG_WRITERFILTER
     294             :         TagLogger::getInstance().element("unhandled");
     295             : #endif
     296             :     }
     297       20682 :     }
     298       20682 : }
     299             : 
     300        1989 : void SettingsTable::lcl_entry(int /*pos*/, writerfilter::Reference<Properties>::Pointer_t ref)
     301             : {
     302        1989 :     ref->resolve(*this);
     303        1989 : }
     304             : 
     305             : //returns default TabStop in 1/100th mm
     306        1967 : int SettingsTable::GetDefaultTabStop() const
     307             : {
     308        1967 :     return ConversionHelper::convertTwipToMM100( m_pImpl->m_nDefaultTabStop );
     309             : }
     310             : 
     311        1967 : bool SettingsTable::GetLinkStyles() const
     312             : {
     313        1967 :     return m_pImpl->m_bLinkStyles;
     314             : }
     315             : 
     316        3614 : sal_Int16 SettingsTable::GetZoomFactor() const
     317             : {
     318        3614 :     return m_pImpl->m_nZoomFactor;
     319             : }
     320             : 
     321        1972 : Id SettingsTable::GetView() const
     322             : {
     323        1972 :     return m_pImpl->m_nView;
     324             : }
     325             : 
     326        1967 : bool SettingsTable::GetUsePrinterMetrics() const
     327             : {
     328        1967 :     return m_pImpl->m_bUsePrinterMetrics;
     329             : }
     330             : 
     331        2191 : bool SettingsTable::GetEvenAndOddHeaders() const
     332             : {
     333        2191 :     return m_pImpl->m_bEvenAndOddHeaders;
     334             : }
     335             : 
     336        1967 : bool SettingsTable::GetEmbedTrueTypeFonts() const
     337             : {
     338        1967 :     return m_pImpl->embedTrueTypeFonts;
     339             : }
     340             : 
     341        1967 : bool SettingsTable::GetEmbedSystemFonts() const
     342             : {
     343        1967 :     return m_pImpl->embedSystemFonts;
     344             : }
     345             : 
     346        3970 : bool SettingsTable::GetDoNotUseHTMLParagraphAutoSpacing() const
     347             : {
     348        3970 :     return m_pImpl->m_bDoNotUseHTMLParagraphAutoSpacing;
     349             : }
     350             : 
     351          47 : bool SettingsTable::GetNoColumnBalance() const
     352             : {
     353          47 :     return m_pImpl->m_bNoColumnBalance;
     354             : }
     355             : 
     356       28861 : bool SettingsTable::GetSplitPgBreakAndParaMark() const
     357             : {
     358       28861 :     return m_pImpl->m_bSplitPgBreakAndParaMark;
     359             : }
     360             : 
     361        2143 : bool SettingsTable::GetMirrorMarginSettings() const
     362             : {
     363        2143 :     return m_pImpl->m_bMirrorMargin;
     364             : }
     365             : 
     366        3364 : uno::Sequence<beans::PropertyValue> SettingsTable::GetThemeFontLangProperties() const
     367             : {
     368        3364 :     return m_pImpl->m_pThemeFontLangProps;
     369             : }
     370             : 
     371        1984 : uno::Sequence<beans::PropertyValue> SettingsTable::GetCompatSettings() const
     372             : {
     373        1984 :     return comphelper::containerToSequence(m_pImpl->m_aCompatSettings);
     374             : }
     375             : 
     376        1984 : void SettingsTable::ApplyProperties(uno::Reference<text::XTextDocument> const& xDoc)
     377             : {
     378        1984 :     uno::Reference< beans::XPropertySet> xDocProps( xDoc, uno::UNO_QUERY );
     379             : 
     380             :     // Record changes value
     381        1984 :     if (xDocProps.is())
     382        1958 :         xDocProps->setPropertyValue("RecordChanges", uno::makeAny( m_pImpl->m_bRecordChanges ) );
     383             : 
     384             :     // Auto hyphenation: turns on hyphenation by default, <w:suppressAutoHyphens/> may still disable it at a paragraph level.
     385        1984 :     if (m_pImpl->m_bAutoHyphenation)
     386             :     {
     387          15 :         uno::Reference<style::XStyleFamiliesSupplier> xStyleFamiliesSupplier(xDoc, uno::UNO_QUERY);
     388          30 :         uno::Reference<container::XNameAccess> xStyleFamilies = xStyleFamiliesSupplier->getStyleFamilies();
     389          30 :         uno::Reference<container::XNameContainer> xParagraphStyles = xStyleFamilies->getByName("ParagraphStyles").get< uno::Reference<container::XNameContainer> >();
     390          30 :         uno::Reference<style::XStyle> xDefault = xParagraphStyles->getByName("Standard").get< uno::Reference<style::XStyle> >();
     391          30 :         uno::Reference<beans::XPropertyState> xPropertyState(xDefault, uno::UNO_QUERY);
     392          15 :         if (xPropertyState->getPropertyState("ParaIsHyphenation") == beans::PropertyState_DEFAULT_VALUE)
     393             :         {
     394           9 :             uno::Reference<beans::XPropertySet> xPropertySet(xDefault, uno::UNO_QUERY);
     395           9 :             xPropertySet->setPropertyValue("ParaIsHyphenation", uno::makeAny(true));
     396          15 :         }
     397        1984 :     }
     398        1984 : }
     399             : 
     400             : }//namespace dmapper
     401             : } //namespace writerfilter
     402             : 
     403             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11