1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_SW_SOURCE_FILTER_HTML_SWCSS1_HXX
21 #define INCLUDED_SW_SOURCE_FILTER_HTML_SWCSS1_HXX
23 #include <sal/config.h>
25 #include <string_view>
27 #include <svtools/htmltokn.h>
28 #include <tools/solar.h>
30 #include <poolfmt.hxx>
32 #include "svxcss1.hxx"
36 class SwTextFormatColl
;
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.
46 class SwCSS1Parser
: public SvxCSS1Parser
49 SwHTMLParser
const& m_rHTMLParser
;
51 sal_uLong m_aFontHeights
[7];
53 sal_uInt16 m_nDropCapCnt
;
57 bool m_bBodyBGColorSet
: 1;
58 bool m_bBodyBackgroundSet
: 1;
59 bool m_bBodyTextSet
: 1;
60 bool m_bBodyLinkSet
: 1;
61 bool m_bBodyVLinkSet
: 1;
63 bool m_bSetFirstPageDesc
: 1;
64 bool m_bSetRightPageDesc
: 1;
66 bool m_bTableHeaderTextCollSet
: 1;
67 bool m_bTableTextCollSet
: 1;
69 bool m_bLinkCharFormatsSet
: 1;
71 const SwPageDesc
* GetPageDesc( sal_uInt16 nPoolId
, bool bCreate
);
73 void SetTableTextColl( bool bHeader
);
74 void SetLinkCharFormats();
77 virtual void StyleParsed( const CSS1Selector
*pSelector
,
79 SvxCSS1PropertyInfo
& rPropInfo
) override
;
81 using CSS1Parser::ParseStyleSheet
;
84 SwCSS1Parser( SwDoc
*pDoc
, SwHTMLParser
const& rParser
,
85 sal_uInt32
const aFHeight
[7], const OUString
& rBaseURL
, bool bNewDoc
);
86 virtual ~SwCSS1Parser() override
;
88 virtual bool ParseStyleSheet( const OUString
& rIn
) override
;
90 // determine font height for a certain font size (0-6)
91 virtual sal_uInt32
GetFontHeight( sal_uInt16 nSize
) const override
;
93 // fetch current font list (also zero is allowed)
94 virtual const FontList
*GetFontList() const override
;
96 // determine the character format of a token and a maybe empty class
97 SwCharFormat
* GetChrFormat( HtmlTokenId nToken
, const OUString
& rClass
) const;
99 // determine a TextFormatColl of a Pool-Id
100 SwTextFormatColl
*GetTextFormatColl( sal_uInt16 nTextColl
, const OUString
& rClass
);
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;
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.
111 SwPageDesc
* GetMasterPageDesc();
112 inline const SwPageDesc
* GetFirstPageDesc( bool bCreate
=false );
113 inline const SwPageDesc
* GetRightPageDesc( bool bCreate
=false );
114 inline const SwPageDesc
* GetLeftPageDesc( bool bCreate
=false );
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 );
121 void ChgPageDesc( const SwPageDesc
*pPageDesc
,
122 const SwPageDesc
& rNewPageDesc
);
124 // Is called for @page
125 void SetPageDescAttrs( const SwPageDesc
*pPageDesc
, SfxItemSet
& rItemSet
,
126 const SvxCSS1PropertyInfo
& rPropInfo
);
128 // Fill a DropCap attribute
129 void FillDropCap( SwFormatDrop
& rDrop
, SfxItemSet
& rItemSet
,
130 const OUString
*pName
=nullptr );
132 bool SetFormatBreak( SfxItemSet
& rItemSet
,
133 const SvxCSS1PropertyInfo
& rPropInfo
);
135 static void AddClassName( OUString
& rFormatName
, std::u16string_view rClass
);
137 static bool MayBePositioned( const SvxCSS1PropertyInfo
& rPropInfo
,
138 bool bAutoWidth
=false );
140 static Css1ScriptFlags
GetScriptFromClass( OUString
& rClass
,
141 bool bSubClassOnly
= true );
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
; }
149 bool IsSetFirstPageDesc() const { return m_bSetFirstPageDesc
; }
150 bool IsSetRightPageDesc() const { return m_bSetRightPageDesc
; }
152 void SetBodyBGColorSet() { m_bBodyBGColorSet
= true; }
153 void SetBodyBackgroundSet() { m_bBodyBackgroundSet
= true; }
154 void SetBodyTextSet() { m_bBodyTextSet
= true; }
155 void SetBodyLinkSet() { m_bBodyLinkSet
= true; }
156 void SetBodyVLinkSet() { m_bBodyVLinkSet
= true; }
158 std::unique_ptr
<SvxBrushItem
> makePageDescBackground() const;
160 inline void SetTHTagStyles();
161 inline void SetTDTagStyles();
162 inline void SetATagStyles();
163 inline void SetDelayedStyles();
165 virtual void SetDfltEncoding( rtl_TextEncoding eEnc
) override
;
168 inline const SwPageDesc
* SwCSS1Parser::GetFirstPageDesc( bool bCreate
)
170 return GetPageDesc( RES_POOLPAGE_FIRST
, bCreate
);
173 inline const SwPageDesc
* SwCSS1Parser::GetRightPageDesc( bool bCreate
)
175 return GetPageDesc( RES_POOLPAGE_RIGHT
, bCreate
);
178 inline const SwPageDesc
* SwCSS1Parser::GetLeftPageDesc( bool bCreate
)
180 return GetPageDesc( RES_POOLPAGE_LEFT
, bCreate
);
183 inline void SwCSS1Parser::SetTHTagStyles()
185 if( !m_bTableHeaderTextCollSet
)
186 SetTableTextColl( true );
189 inline void SwCSS1Parser::SetTDTagStyles()
191 if( !m_bTableTextCollSet
)
192 SetTableTextColl( false );
195 inline void SwCSS1Parser::SetATagStyles()
197 if( !m_bLinkCharFormatsSet
)
198 SetLinkCharFormats();
201 inline void SwCSS1Parser::SetDelayedStyles()
210 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */