LibreOffice Module sw (master)  1
swcss1.hxx
Go to the documentation of this file.
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 #ifndef INCLUDED_SW_SOURCE_FILTER_HTML_SWCSS1_HXX
21 #define INCLUDED_SW_SOURCE_FILTER_HTML_SWCSS1_HXX
22 
23 #include <sal/config.h>
24 
25 #include <string_view>
26 
27 #include <svtools/htmltokn.h>
28 #include <tools/solar.h>
29 
30 #include <poolfmt.hxx>
31 
32 #include "svxcss1.hxx"
33 
34 class SwDoc;
35 class SwCharFormat;
36 class SwTextFormatColl;
37 class SvxBrushItem;
38 class SwFormatDrop;
39 class SwPageDesc;
40 class SwHTMLParser;
41 
42 // This header looks harmless, but includes still quite
43 // inconspicuous one or the other! On the other hand this class
44 // is rarely needed. Therefore its own header.
45 
47 {
50 
52 
53  sal_uInt16 m_nDropCapCnt;
54 
55  bool m_bIsNewDoc : 1;
56 
59  bool m_bBodyTextSet : 1;
60  bool m_bBodyLinkSet : 1;
61  bool m_bBodyVLinkSet : 1;
62 
65 
68 
70 
71  const SwPageDesc* GetPageDesc( sal_uInt16 nPoolId, bool bCreate );
72 
73  void SetTableTextColl( bool bHeader );
74  void SetLinkCharFormats();
75 
76 protected:
77  virtual void StyleParsed( const CSS1Selector *pSelector,
78  SfxItemSet& rItemSet,
79  SvxCSS1PropertyInfo& rPropInfo ) override;
80 
82 
83 public:
84  SwCSS1Parser( SwDoc *pDoc, SwHTMLParser const& rParser,
85  sal_uInt32 const aFHeight[7], const OUString& rBaseURL, bool bNewDoc);
86  virtual ~SwCSS1Parser() override;
87 
88  virtual bool ParseStyleSheet( const OUString& rIn ) override;
89 
90  // determine font height for a certain font size (0-6)
91  virtual sal_uInt32 GetFontHeight( sal_uInt16 nSize ) const override;
92 
93  // fetch current font list (also zero is allowed)
94  virtual const FontList *GetFontList() const override;
95 
96  // determine the character format of a token and a maybe empty class
97  SwCharFormat* GetChrFormat( HtmlTokenId nToken, const OUString& rClass ) const;
98 
99  // determine a TextFormatColl of a Pool-Id
100  SwTextFormatColl *GetTextFormatColl( sal_uInt16 nTextColl, const OUString& rClass );
101 
102  // This methods do the same as the one of SwDoc, but change the
103  // encoding if required.
104  SwTextFormatColl *GetTextCollFromPool( sal_uInt16 nPoolId ) const;
105  SwCharFormat *GetCharFormatFromPool( sal_uInt16 nPoolId ) const;
106 
107  // Fetch the left or right page style. In documents with only
108  // one style there is only a right page.
109  // Otherwise the right page is the HTML pool style and the left
110  // page a user style which is created on-demand if bCreate is set.
112  inline const SwPageDesc* GetFirstPageDesc( bool bCreate=false );
113  inline const SwPageDesc* GetRightPageDesc( bool bCreate=false );
114  inline const SwPageDesc* GetLeftPageDesc( bool bCreate=false );
115 
116  // Set attributes on the HTML page style (set attributes are
117  // deleted from the Item-Set). Is called for the BODY tag.
118  void SetPageDescAttrs( const SvxBrushItem *pBrush,
119  SfxItemSet *pItemSet=nullptr );
120 
121  void ChgPageDesc( const SwPageDesc *pPageDesc,
122  const SwPageDesc& rNewPageDesc );
123 
124  // Is called for @page
125  void SetPageDescAttrs( const SwPageDesc *pPageDesc, SfxItemSet& rItemSet,
126  const SvxCSS1PropertyInfo& rPropInfo );
127 
128  // Fill a DropCap attribute
129  void FillDropCap( SwFormatDrop& rDrop, SfxItemSet& rItemSet,
130  const OUString *pName=nullptr );
131 
132  bool SetFormatBreak( SfxItemSet& rItemSet,
133  const SvxCSS1PropertyInfo& rPropInfo );
134 
135  static void AddClassName( OUString& rFormatName, std::u16string_view rClass );
136 
137  static bool MayBePositioned( const SvxCSS1PropertyInfo& rPropInfo,
138  bool bAutoWidth=false );
139 
140  static Css1ScriptFlags GetScriptFromClass( OUString& rClass,
141  bool bSubClassOnly = true );
142 
143  bool IsBodyBGColorSet() const { return m_bBodyBGColorSet; }
144  bool IsBodyBackgroundSet() const { return m_bBodyBackgroundSet; }
145  bool IsBodyTextSet() const { return m_bBodyTextSet; }
146  bool IsBodyLinkSet() const { return m_bBodyLinkSet; }
147  bool IsBodyVLinkSet() const { return m_bBodyVLinkSet; }
148 
149  bool IsSetFirstPageDesc() const { return m_bSetFirstPageDesc; }
150  bool IsSetRightPageDesc() const { return m_bSetRightPageDesc; }
151 
154  void SetBodyTextSet() { m_bBodyTextSet = true; }
155  void SetBodyLinkSet() { m_bBodyLinkSet = true; }
156  void SetBodyVLinkSet() { m_bBodyVLinkSet = true; }
157 
158  std::unique_ptr<SvxBrushItem> makePageDescBackground() const;
159 
160  inline void SetTHTagStyles();
161  inline void SetTDTagStyles();
162  inline void SetATagStyles();
163  inline void SetDelayedStyles();
164 
165  virtual void SetDfltEncoding( rtl_TextEncoding eEnc ) override;
166 };
167 
168 inline const SwPageDesc* SwCSS1Parser::GetFirstPageDesc( bool bCreate )
169 {
170  return GetPageDesc( RES_POOLPAGE_FIRST, bCreate );
171 }
172 
173 inline const SwPageDesc* SwCSS1Parser::GetRightPageDesc( bool bCreate )
174 {
175  return GetPageDesc( RES_POOLPAGE_RIGHT, bCreate );
176 }
177 
178 inline const SwPageDesc* SwCSS1Parser::GetLeftPageDesc( bool bCreate )
179 {
180  return GetPageDesc( RES_POOLPAGE_LEFT, bCreate );
181 }
182 
184 {
186  SetTableTextColl( true );
187 }
188 
190 {
191  if( !m_bTableTextCollSet )
192  SetTableTextColl( false );
193 }
194 
196 {
197  if( !m_bLinkCharFormatsSet )
199 }
200 
202 {
203  SetTHTagStyles();
204  SetTDTagStyles();
205  SetATagStyles();
206 }
207 
208 #endif
209 
210 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const SwPageDesc * GetFirstPageDesc(bool bCreate=false)
Definition: swcss1.hxx:168
Css1ScriptFlags
Definition: svxcss1.hxx:76
sal_uInt16 m_nDropCapCnt
Definition: swcss1.hxx:53
static Css1ScriptFlags GetScriptFromClass(OUString &rClass, bool bSubClassOnly=true)
Definition: htmlcss1.cxx:554
Represents the style of a paragraph.
Definition: fmtcol.hxx:56
SwTextFormatColl * GetTextFormatColl(sal_uInt16 nTextColl, const OUString &rClass)
Definition: htmlcss1.cxx:1241
SwPageDesc * GetMasterPageDesc()
Definition: htmlcss1.cxx:1322
virtual ~SwCSS1Parser() override
Definition: htmlcss1.cxx:118
bool m_bSetRightPageDesc
Definition: swcss1.hxx:64
SwTextFormatColl * GetTextCollFromPool(sal_uInt16 nPoolId) const
Definition: htmlcss1.cxx:1206
void SetDelayedStyles()
Definition: swcss1.hxx:201
void SetTDTagStyles()
Definition: swcss1.hxx:189
bool m_bBodyBGColorSet
Definition: swcss1.hxx:57
sal_uIntPtr sal_uLong
Definition: doc.hxx:187
void SetBodyVLinkSet()
Definition: swcss1.hxx:156
bool m_bBodyVLinkSet
Definition: swcss1.hxx:61
virtual sal_uInt32 GetFontHeight(sal_uInt16 nSize) const override
Definition: htmlcss1.cxx:1106
bool m_bTableTextCollSet
Definition: swcss1.hxx:67
bool m_bBodyLinkSet
Definition: swcss1.hxx:60
void SetBodyBackgroundSet()
Definition: swcss1.hxx:153
sal_uLong m_aFontHeights[7]
Definition: swcss1.hxx:51
void SetATagStyles()
Definition: swcss1.hxx:195
virtual void SetDfltEncoding(rtl_TextEncoding eEnc) override
Definition: htmlcss1.cxx:2298
void FillDropCap(SwFormatDrop &rDrop, SfxItemSet &rItemSet, const OUString *pName=nullptr)
Definition: htmlcss1.cxx:1464
bool IsBodyBGColorSet() const
Definition: swcss1.hxx:143
SwHTMLParser const & m_rHTMLParser
Definition: swcss1.hxx:49
void ParseStyleSheet()
Definition: parcss1.cxx:669
void SetTHTagStyles()
Definition: swcss1.hxx:183
bool m_bBodyBackgroundSet
Definition: swcss1.hxx:58
bool m_bLinkCharFormatsSet
Definition: swcss1.hxx:69
void SetLinkCharFormats()
Definition: htmlcss1.cxx:215
sal_uInt16 char * pName
First page.
Definition: poolfmt.hxx:171
std::unique_ptr< SvxBrushItem > makePageDescBackground() const
Definition: htmlcss1.cxx:548
const SwPageDesc * GetLeftPageDesc(bool bCreate=false)
Definition: swcss1.hxx:178
bool IsSetFirstPageDesc() const
Definition: swcss1.hxx:149
bool IsSetRightPageDesc() const
Definition: swcss1.hxx:150
static void AddClassName(OUString &rFormatName, std::u16string_view rClass)
Definition: htmlcss1.cxx:1457
const SwPageDesc * GetRightPageDesc(bool bCreate=false)
Definition: swcss1.hxx:173
void SetBodyTextSet()
Definition: swcss1.hxx:154
SwCharFormat * GetChrFormat(HtmlTokenId nToken, const OUString &rClass) const
Definition: htmlcss1.cxx:1126
void SetPageDescAttrs(const SvxBrushItem *pBrush, SfxItemSet *pItemSet=nullptr)
Definition: htmlcss1.cxx:376
SwCSS1Parser(SwDoc *pDoc, SwHTMLParser const &rParser, sal_uInt32 const aFHeight[7], const OUString &rBaseURL, bool bNewDoc)
Definition: htmlcss1.cxx:90
Left page.
Definition: poolfmt.hxx:172
SwCharFormat * GetCharFormatFromPool(sal_uInt16 nPoolId) const
Definition: htmlcss1.cxx:1223
virtual const FontList * GetFontList() const override
Definition: htmlcss1.cxx:1111
bool IsBodyVLinkSet() const
Definition: swcss1.hxx:147
HtmlTokenId
bool IsBodyLinkSet() const
Definition: swcss1.hxx:146
bool m_bBodyTextSet
Definition: swcss1.hxx:59
void ChgPageDesc(const SwPageDesc *pPageDesc, const SwPageDesc &rNewPageDesc)
Definition: htmlcss1.cxx:80
Right page.
Definition: poolfmt.hxx:173
SwDoc * m_pDoc
Definition: swcss1.hxx:48
bool m_bTableHeaderTextCollSet
Definition: swcss1.hxx:66
bool m_bSetFirstPageDesc
Definition: swcss1.hxx:63
const SwPageDesc * GetPageDesc(sal_uInt16 nPoolId, bool bCreate)
Definition: htmlcss1.cxx:1338
void SetTableTextColl(bool bHeader)
Definition: htmlcss1.cxx:331
bool m_bIsNewDoc
Definition: swcss1.hxx:55
SfxItemSet * pItemSet
Definition: svxcss1.hxx:200
bool SetFormatBreak(SfxItemSet &rItemSet, const SvxCSS1PropertyInfo &rPropInfo)
Definition: htmlcss1.cxx:123
bool IsBodyBackgroundSet() const
Definition: swcss1.hxx:144
If SwFormatDrop is a Client, it is the CharFormat that describes the font for the DropCaps...
Definition: paratr.hxx:62
A simple selector.
Definition: parcss1.hxx:91
void SetBodyBGColorSet()
Definition: swcss1.hxx:152
void SetBodyLinkSet()
Definition: swcss1.hxx:155
bool IsBodyTextSet() const
Definition: swcss1.hxx:145
virtual void StyleParsed(const CSS1Selector *pSelector, SfxItemSet &rItemSet, SvxCSS1PropertyInfo &rPropInfo) override
Definition: htmlcss1.cxx:685
static bool MayBePositioned(const SvxCSS1PropertyInfo &rPropInfo, bool bAutoWidth=false)
Definition: htmlcss1.cxx:1425