LCOV - code coverage report
Current view: top level - sw/source/filter/html - svxcss1.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 13 17 76.5 %
Date: 2015-06-13 12:38:46 Functions: 11 15 73.3 %
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             : #ifndef INCLUDED_SW_SOURCE_FILTER_HTML_SVXCSS1_HXX
      20             : #define INCLUDED_SW_SOURCE_FILTER_HTML_SVXCSS1_HXX
      21             : 
      22             : #include <svl/itemset.hxx>
      23             : #include <editeng/svxenum.hxx>
      24             : #include <rtl/textenc.h>
      25             : #include "parcss1.hxx"
      26             : 
      27             : #include <boost/ptr_container/ptr_vector.hpp>
      28             : #include <boost/ptr_container/ptr_map.hpp>
      29             : 
      30             : class SfxItemPool;
      31             : class SvxBoxItem;
      32             : class FontList;
      33             : 
      34             : enum SvxCSS1Position
      35             : {
      36             :     SVX_CSS1_POS_NONE,          // nichts angegeben
      37             :     SVX_CSS1_POS_STATIC,        // normal
      38             :     SVX_CSS1_POS_ABSOLUTE,      // absolut
      39             :     SVX_CSS1_POS_RELATIVE,      // relativ
      40             :     SVX_CSS1_POS_END
      41             : };
      42             : 
      43             : enum SvxCSS1LengthType
      44             : {
      45             :     SVX_CSS1_LTYPE_NONE,        // nichts angegeben
      46             :     SVX_CSS1_LTYPE_AUTO,        // automatisch
      47             :     SVX_CSS1_LTYPE_TWIP,        // twip
      48             :     SVX_CSS1_LTYPE_PERCENTAGE,  // %-Angabe
      49             :     SVX_CSS1_LTYPE_END
      50             : };
      51             : 
      52             : // Feature: PrintExt
      53             : enum SvxCSS1SizeType
      54             : {
      55             :     SVX_CSS1_STYPE_NONE,        // nichts angegeben
      56             :     SVX_CSS1_STYPE_AUTO,        // automatisch
      57             :     SVX_CSS1_STYPE_TWIP,        // twip
      58             :     SVX_CSS1_STYPE_LANDSCAPE,   // Landscape
      59             :     SVX_CSS1_STYPE_PORTRAIT,    // Landscape
      60             :     SVX_CSS1_STYPE_END
      61             : };
      62             : 
      63             : enum SvxCSS1PageBreak
      64             : {
      65             :     SVX_CSS1_PBREAK_NONE,       // nichts angegeben
      66             :     SVX_CSS1_PBREAK_AUTO,       // automatisch
      67             :     SVX_CSS1_PBREAK_ALWAYS,     // immer
      68             :     SVX_CSS1_PBREAK_AVOID,      // nie
      69             :     SVX_CSS1_PBREAK_LEFT,       // naechste Seite ist eine linke
      70             :     SVX_CSS1_PBREAK_RIGHT,      // naechste Seite ist eine rechte
      71             :     SVX_CSS1_PBREAK_END
      72             : };
      73             : 
      74             : // /Feature: PrintExt
      75             : 
      76             : #define CSS1_SCRIPT_WESTERN 0x01
      77             : #define CSS1_SCRIPT_CJK     0x02
      78             : #define CSS1_SCRIPT_CTL     0x04
      79             : #define CSS1_SCRIPT_ALL     0x07
      80             : 
      81             : struct CSS1PropertyEnum
      82             : {
      83             :     const sal_Char *pName;  // Wert einer Property
      84             :     sal_uInt16 nEnum;           // und der dazugehoerige Wert eines Enums
      85             : };
      86             : 
      87             : namespace editeng { class SvxBorderLine; }
      88             : 
      89             : #define SVX_CSS1_BORDERINFO_WIDTH 1
      90             : #define SVX_CSS1_BORDERINFO_COLOR 2
      91             : #define SVX_CSS1_BORDERINFO_STYLE 4
      92             : 
      93             : struct SvxCSS1BorderInfo;
      94             : class SvxCSS1PropertyInfo
      95             : {
      96             :     SvxCSS1BorderInfo *aBorderInfos[4];
      97             : 
      98             :     void DestroyBorderInfos();
      99             : 
     100             : public:
     101             : 
     102             :     OUString aId;             // ID fuer Bookmarks, Rahmen etc.
     103             : 
     104             :     bool bTopMargin : 1;
     105             :     bool bBottomMargin : 1;
     106             : 
     107             :     bool bLeftMargin : 1;
     108             :     bool bRightMargin : 1;
     109             :     bool bTextIndent : 1;
     110             : 
     111             :     SvxAdjust eFloat;
     112             : 
     113             :     SvxCSS1Position ePosition;
     114             : 
     115             :     sal_uInt16 nTopBorderDistance;
     116             :     sal_uInt16 nBottomBorderDistance;
     117             :     sal_uInt16 nLeftBorderDistance;
     118             :     sal_uInt16 nRightBorderDistance;
     119             : 
     120             :     sal_uInt16 nColumnCount;
     121             : 
     122             :     long nLeft, nTop;
     123             :     long nWidth, nHeight;
     124             :     long nLeftMargin, nRightMargin;
     125             : 
     126             :     SvxCSS1LengthType eLeftType, eTopType;
     127             :     SvxCSS1LengthType eWidthType, eHeightType;
     128             : 
     129             : // Feature: PrintExt
     130             :     SvxCSS1SizeType eSizeType;
     131             : 
     132             :     SvxCSS1PageBreak ePageBreakBefore;
     133             :     SvxCSS1PageBreak ePageBreakAfter;
     134             : // /Feature: PrintExt
     135             : 
     136             :     SvxCSS1PropertyInfo();
     137             :     SvxCSS1PropertyInfo( const SvxCSS1PropertyInfo& rProp );
     138             :     ~SvxCSS1PropertyInfo();
     139             : 
     140             :     void Merge( const SvxCSS1PropertyInfo& rProp );
     141             : 
     142             :     void Clear();
     143             : 
     144             :     SvxCSS1BorderInfo *GetBorderInfo( SvxBoxItemLine nLine, bool bCreate=true );
     145             :     void CopyBorderInfo( SvxBoxItemLine nSrcLine, SvxBoxItemLine nDstLine, sal_uInt16 nWhat );
     146             :     void CopyBorderInfo( sal_uInt16 nCount, sal_uInt16 nWhat );
     147             : 
     148             :     void SetBoxItem( SfxItemSet& rItemSet, sal_uInt16 nMinBorderDist,
     149             :                      const SvxBoxItem* pDflt=0, bool bTable = false );
     150             : 
     151             : };
     152             : 
     153          33 : class SvxCSS1MapEntry
     154             : {
     155             :     OUString aKey;
     156             :     SfxItemSet aItemSet;
     157             :     SvxCSS1PropertyInfo aPropInfo;
     158             : 
     159             : public:
     160             : 
     161          16 :     SvxCSS1MapEntry( SfxItemPool& rPool, const sal_uInt16 *pWhichMap ) :
     162          16 :         aItemSet( rPool, pWhichMap )
     163          16 :     {}
     164             : 
     165             :     SvxCSS1MapEntry( const OUString& rKey, const SfxItemSet& rItemSet,
     166             :                      const SvxCSS1PropertyInfo& rProp );
     167             : 
     168           0 :     const SfxItemSet& GetItemSet() const { return aItemSet; }
     169          46 :     SfxItemSet& GetItemSet() { return aItemSet; }
     170             : 
     171           0 :     const SvxCSS1PropertyInfo& GetPropertyInfo() const { return aPropInfo; }
     172          43 :     SvxCSS1PropertyInfo& GetPropertyInfo() { return aPropInfo; }
     173             : 
     174             :     const OUString& GetKey()  const { return aKey; }
     175             :     void SetKey( const OUString& rKey ) { aKey = rKey.toAsciiUpperCase(); }
     176             : 
     177             :     friend bool operator==( const SvxCSS1MapEntry& rE1,
     178             :                             const SvxCSS1MapEntry& rE2 );
     179             :     friend bool operator<( const SvxCSS1MapEntry& rE1,
     180             :                             const SvxCSS1MapEntry& rE2 );
     181             : };
     182             : 
     183             : inline bool operator==( const SvxCSS1MapEntry& rE1, const SvxCSS1MapEntry& rE2 )
     184             : {
     185             :     return  rE1.aKey==rE2.aKey;
     186             : }
     187             : 
     188             : inline bool operator<( const SvxCSS1MapEntry& rE1,  const SvxCSS1MapEntry& rE2 )
     189             : {
     190             :     return  rE1.aKey<rE2.aKey;
     191             : }
     192             : 
     193             : // Diese Klasse bereitet den Output des CSS1-Parsers auf,
     194             : // indem die CSS1-Properties in SvxItem(Set)s umgewandelt werden.
     195             : // Ausserdem werden die Selektoren samt zugehoeriger Item-Set
     196             : // gespeichert.
     197             : // Ein abgeleiteter Parser kann dies fuer einzelne Selektoren unterdruecken,
     198             : // indem er die Methode StyleParsed ueberlaed.
     199             : 
     200             : class SvxCSS1Parser : public CSS1Parser
     201             : {
     202             :     typedef ::boost::ptr_vector<CSS1Selector> CSS1Selectors;
     203             :     typedef ::boost::ptr_map<OUString, SvxCSS1MapEntry> CSS1Map;
     204             :     CSS1Selectors aSelectors;   // Liste der "offenen" Selectoren
     205             : 
     206             :     CSS1Map aIds;
     207             :     CSS1Map aClasses;
     208             :     CSS1Map aPages;
     209             :     CSS1Map aTags;
     210             : 
     211             :     OUString sBaseURL;
     212             : 
     213             :     SfxItemSet *pSheetItemSet;  // der Item-Set fuer Style-Sheets
     214             :     SfxItemSet *pItemSet;       // der aktuelle Item-Set
     215             :     SvxCSS1MapEntry *pSearchEntry;
     216             : 
     217             :     SvxCSS1PropertyInfo *pSheetPropInfo;
     218             :     SvxCSS1PropertyInfo *pPropInfo;
     219             : 
     220             :     sal_uInt16 nMinFixLineSpace;    // Mindest-Abstand fuer festen Zeilenabstand
     221             : 
     222             :     rtl_TextEncoding    eDfltEnc;
     223             :     sal_uInt16          nScriptFlags;
     224             : 
     225             :     bool bIgnoreFontFamily;
     226             : 
     227             :     void ParseProperty( const OUString& rProperty,
     228             :                         const CSS1Expression *pExpr );
     229             : 
     230             :     std::vector<sal_uInt16> aWhichMap;        // Which-Map des Parser
     231             : 
     232             :     using CSS1Parser::ParseStyleOption;
     233             : 
     234             : protected:
     235             : 
     236             :     using CSS1Parser::ParseStyleSheet;
     237             : 
     238             :     // Diese Methode wird fuer jeden Selektor mit dem zugehoerigen
     239             :     // Item-Set aufgerufen. Fuer einen Selektor koennen mehrere
     240             :     // Aufrufe erfolgen.
     241             :     // wenn true zuruckgegeben wird, wird der Item-Set bzw. der
     242             :     // Selektor nicht mehr gespeichert!
     243             :     // Der ItemSet darf entsprechend modifiziert werden!
     244             :     // Die Implementierung dieser Methode gibt false zurueck.
     245             :     virtual bool StyleParsed( const CSS1Selector *pSelector,
     246             :                               SfxItemSet& rItemSet,
     247             :                               SvxCSS1PropertyInfo& rPropInfo );
     248             : 
     249             :     /// Will be called when a Selector is parsed.  If bFirst is true,
     250             :     /// the content of the aItemSet will be copied into all recently
     251             :     /// created Styles.
     252             :     /// Derived classes should not override this method!
     253             :     virtual bool SelectorParsed( CSS1Selector *pSelector, bool bFirst ) SAL_OVERRIDE;
     254             : 
     255             :     /// Will be called for every parsed Property.  Adds the item to the
     256             :     /// pItemSet.
     257             :     /// Derived classes should not override this method!
     258             :     virtual bool DeclarationParsed( const OUString& rProperty,
     259             :                                     const CSS1Expression *pExpr ) SAL_OVERRIDE;
     260             : 
     261             : public:
     262             : 
     263             :     SvxCSS1Parser( SfxItemPool& rPool,
     264             :                     const OUString& rBaseURL,
     265             :                    sal_uInt16 nMinFixLineSp,
     266             :                    sal_uInt16 *pWhichIds=0, sal_uInt16 nWhichIds=0 );
     267             :     virtual ~SvxCSS1Parser();
     268             : 
     269           5 :     bool IsIgnoreFontFamily() const { return bIgnoreFontFamily; }
     270          16 :     void SetIgnoreFontFamily( bool bSet ) { bIgnoreFontFamily = bSet; }
     271             : 
     272             :     // Parsen eines Style-Sheets. Fuer jeden gefundenen Selektor
     273             :     // wird StyleParsed mit dem entsprechenem Item-Set aufgerufen
     274             :     virtual bool ParseStyleSheet( const OUString& rIn );
     275             : 
     276             :     // Parsen einer Style-Option. Hier wird einfach nur der Item-Set
     277             :     // gefuellt.
     278             :     bool ParseStyleOption( const OUString& rIn, SfxItemSet& rItemSet,
     279             :                            SvxCSS1PropertyInfo& rPropInfo );
     280             : 
     281             :     // Umwandeln eines Strings in den Wert eines Enums
     282             :     static bool GetEnum( const CSS1PropertyEnum *pPropTable,
     283             :                          const OUString& rValue, sal_uInt16 &rEnum );
     284             : 
     285             :     // Pixel in Twips wandeln
     286             :     static void PixelToTwip( long &nWidth, long &nHeight );
     287             : 
     288             :     // Die Font-Hoehe fuer eine bestimmte Font-Groesse (0-6) ermitteln
     289             :     virtual sal_uInt32 GetFontHeight( sal_uInt16 nSize ) const;
     290             : 
     291             :     virtual const FontList *GetFontList() const;
     292             : 
     293         596 :     const sal_uInt16 *GetWhichMap() const { return &aWhichMap[0]; }
     294             : 
     295             :     static void InsertMapEntry( const OUString& rKey, const SfxItemSet& rItemSet,
     296             :                          const SvxCSS1PropertyInfo& rProp, CSS1Map& rMap );
     297             : 
     298             :     void InsertId( const OUString& rId, const SfxItemSet& rItemSet,
     299             :                    const SvxCSS1PropertyInfo& rProp );
     300             : 
     301             :     const SvxCSS1MapEntry* GetId( const OUString& rId ) const;
     302             : 
     303             :     void InsertClass( const OUString& rClass, const SfxItemSet& rItemSet,
     304             :                       const SvxCSS1PropertyInfo& rProp );
     305             : 
     306             :     const SvxCSS1MapEntry* GetClass( const OUString& rClass ) const;
     307             : 
     308             :     void InsertPage( const OUString& rPage, bool bPseudo,
     309             :                             const SfxItemSet& rItemSet,
     310             :                             const SvxCSS1PropertyInfo& rProp );
     311             : 
     312             :     SvxCSS1MapEntry* GetPage( const OUString& rPage, bool bPseudo );
     313             : 
     314             :     void InsertTag( const OUString& rTag, const SfxItemSet& rItemSet,
     315             :                       const SvxCSS1PropertyInfo& rProp );
     316             : 
     317             :     SvxCSS1MapEntry* GetTag( const OUString& rTag );
     318             : 
     319             :     static void MergeStyles( const SfxItemSet& rSrcSet,
     320             :                       const SvxCSS1PropertyInfo& rSrcInfo,
     321             :                       SfxItemSet& rTargetSet,
     322             :                       SvxCSS1PropertyInfo& rTargetInfo,
     323             :                       bool bSmart );
     324             : 
     325           0 :     sal_uInt16 GetMinFixLineSpace() const { return nMinFixLineSpace; }
     326             : 
     327             :     virtual void SetDfltEncoding( rtl_TextEncoding eEnc );
     328         157 :     rtl_TextEncoding GetDfltEncoding() const { return eDfltEnc; }
     329             : 
     330          45 :     bool IsSetWesternProps() const { return (nScriptFlags & CSS1_SCRIPT_WESTERN) != 0; }
     331          45 :     bool IsSetCJKProps() const { return (nScriptFlags & CSS1_SCRIPT_CJK) != 0; }
     332          45 :     bool IsSetCTLProps() const { return (nScriptFlags & CSS1_SCRIPT_CTL) != 0; }
     333             : 
     334           0 :     const OUString& GetBaseURL() const { return sBaseURL;}
     335             : 
     336             : };
     337             : 
     338             : #endif
     339             : 
     340             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11