LibreOffice Module lotuswordpro (master) 1
xfstylecont.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*************************************************************************
3 *
4 * The Contents of this file are made available subject to the terms of
5 * either of the following licenses
6 *
7 * - GNU Lesser General Public License Version 2.1
8 * - Sun Industry Standards Source License Version 1.1
9 *
10 * Sun Microsystems Inc., October, 2000
11 *
12 * GNU Lesser General Public License Version 2.1
13 * =============================================
14 * Copyright 2000 by Sun Microsystems, Inc.
15 * 901 San Antonio Road, Palo Alto, CA 94303, USA
16 *
17 * This library is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU Lesser General Public
19 * License version 2.1, as published by the Free Software Foundation.
20 *
21 * This library is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 * Lesser General Public License for more details.
25 *
26 * You should have received a copy of the GNU Lesser General Public
27 * License along with this library; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
29 * MA 02111-1307 USA
30 *
31 *
32 * Sun Industry Standards Source License Version 1.1
33 * =================================================
34 * The contents of this file are subject to the Sun Industry Standards
35 * Source License Version 1.1 (the "License"); You may not use this file
36 * except in compliance with the License. You may obtain a copy of the
37 * License at http://www.openoffice.org/license.html.
38 *
39 * Software provided under this License is provided on an "AS IS" basis,
40 * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
41 * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
42 * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
43 * See the License for the specific provisions governing your rights and
44 * obligations concerning the Software.
45 *
46 * The Initial Developer of the Original Code is: IBM Corporation
47 *
48 * Copyright: 2008 by IBM Corporation
49 *
50 * All Rights Reserved.
51 *
52 * Contributor(s): _______________________________________
53 *
54 *
55 ************************************************************************/
56/*************************************************************************
57 * @file
58 * Font object to serial to xml filter.
59 ************************************************************************/
60#include <utility>
62#include <xfilter/ixfstyle.hxx>
63#include <xfilter/xffont.hxx>
67#include <lwpglobalmgr.hxx>
68
69XFStyleContainer::XFStyleContainer(OUString strStyleNamePrefix)
70 :m_strStyleNamePrefix(std::move(strStyleNamePrefix))
71{
72}
73
75{
76}
77
79{
80 m_aStyles.clear();
81}
82
83IXFStyleRet XFStyleContainer::AddStyle(std::unique_ptr<IXFStyle> pStyle)
84{
85 IXFStyleRet aRet;
86
87 IXFStyle *pConStyle = nullptr;
88
89 if( !pStyle )
90 return aRet;
91 //no matter we want to delete the style or not,XFFont object should be saved first.
92 ManageStyleFont(pStyle.get());
93
94 if( pStyle->GetStyleName().isEmpty() )
95 pConStyle = FindSameStyle(pStyle.get());
96
97 if( pConStyle )//such a style has exist:
98 {
99 aRet.m_pStyle = pConStyle;
100 aRet.m_bOrigDeleted = true;
101 return aRet;
102 }
103 else
104 {
105 OUString name;
106 if( pStyle->GetStyleName().isEmpty() )
107 {
108 name = m_strStyleNamePrefix + OUString::number(m_aStyles.size()+1);
109 pStyle->SetStyleName(name);
110 }
111 else
112 {
113 name = pStyle->GetStyleName();
114 //for name conflict
115 if(FindStyle( name))
116 {
117 name += OUString::number(m_aStyles.size()+1);
118 pStyle->SetStyleName(name);
119 }
120 }
121
122 //transform the font object to XFFontFactory
123 aRet.m_pStyle = pStyle.get();
124 m_aStyles.push_back(std::move(pStyle));
125 return aRet;
126 }
127}
128
130{
131 for (auto const& style : m_aStyles)
132 {
133 assert(style);
134 if( style->Equal(pStyle) )
135 return style.get();
136 }
137
138 return nullptr;
139}
140
141IXFStyle* XFStyleContainer::FindStyle(std::u16string_view name)
142{
143 for (auto const& style : m_aStyles)
144 {
145 assert(style);
146 if( style->GetStyleName() == name )
147 return style.get();
148 }
149
150 return nullptr;
151}
152
153const IXFStyle* XFStyleContainer::Item(size_t index) const
154{
155 assert(index<m_aStyles.size());
156 if (index < m_aStyles.size())
157 {
158 return m_aStyles[index].get();
159 }
160 return nullptr;
161}
162
164{
165 for (auto const& style : m_aStyles)
166 {
167 assert(style);
168 style->ToXml(pStrm);
169 }
170}
171
173{
174 rtl::Reference<XFFont> pStyleFont;
175 rtl::Reference<XFFont> pFactoryFont;
176
177 if( !pStyle )
178 return;
179
180 if( pStyle->GetStyleFamily() == enumXFStyleText )
181 {
182 XFTextStyle *pTS = static_cast<XFTextStyle*>(pStyle);
183 pStyleFont = pTS->GetFont();
184 if( !pStyleFont.is() )
185 return;
187 XFFontFactory* pFontFactory = pGlobal->GetXFFontFactory();
188 pFactoryFont = pFontFactory->FindSameFont(pStyleFont);
189 //this font has been exists in the factory:
190 if( pFactoryFont.is() )
191 {
192 pTS->SetFont(pFactoryFont);
193 }
194 else
195 {
196 pFontFactory->AddFont(pStyleFont);
197 }
198 }
199 else if( pStyle->GetStyleFamily() == enumXFStylePara )
200 {
201 XFParaStyle *pPS = static_cast<XFParaStyle*>(pStyle);
202 pStyleFont = pPS->GetFont();
203 if( !pStyleFont.is() )
204 return;
206 XFFontFactory* pFontFactory = pGlobal->GetXFFontFactory();
207 pFactoryFont = pFontFactory->FindSameFont(pStyleFont);
208 //this font has been exists in the factory:
209 if( pFactoryFont.is() )
210 {
211 pPS->SetFont(pFactoryFont);
212 }
213 else
214 {
215 pFontFactory->AddFont(pStyleFont);
216 }
217 }
218}
219
221{
223 return false;
224 if( b1.m_aStyles.size() != b2.m_aStyles.size() )
225 return false;
226 for( size_t i=0; i<b1.m_aStyles.size(); ++i )
227 {
228 IXFStyle *pS1 = b1.m_aStyles[i].get();
229 IXFStyle *pS2 = b2.m_aStyles[i].get();
230
231 if( pS1 )
232 {
233 if( !pS2 )
234 return false;
235 if( !pS1->Equal(pS2) )
236 return false;
237 }
238 else
239 {
240 if( pS2 )
241 return false;
242 }
243 }
244 return true;
245}
246
248{
249 return !(b1==b2);
250}
251
252/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Stream wrapper for sax writer.
Definition: ixfstream.hxx:72
@descr Interface for all style object.
Definition: ixfstyle.hxx:71
virtual enumXFStyle GetStyleFamily()=0
@descr: return the style family.
virtual bool Equal(IXFStyle *pStyle)=0
@descr: Compare whatever two style object are the same.
static LwpGlobalMgr * GetInstance(LwpSvStream *pSvStream=nullptr)
XFFontFactory * GetXFFontFactory()
Font factory.
void AddFont(rtl::Reference< XFFont > const &pFont)
@descr Add a font.
rtl::Reference< XFFont > FindSameFont(rtl::Reference< XFFont > const &pFont)
@descr Find whether same font object exists.
Style object for aragraph.
Definition: xfparastyle.hxx:93
const rtl::Reference< XFFont > & GetFont() const
@descr get the font object.
void SetFont(rtl::Reference< XFFont > const &font)
@descr set the paragraph default font.
@descr container object for styles.
Definition: xfstylecont.hxx:85
OUString m_strStyleNamePrefix
IXFStyle * FindSameStyle(IXFStyle *pStyle)
@descr Find the same style.
IXFStyleRet AddStyle(std::unique_ptr< IXFStyle > pStyle)
@descr Add style to container.
Definition: xfstylecont.cxx:83
std::vector< std::unique_ptr< IXFStyle > > m_aStyles
void Reset()
@descr clear container.
Definition: xfstylecont.cxx:78
virtual void ToXml(IXFStream *pStrm)
@descr Output all style.
const IXFStyle * Item(size_t index) const
@descr get style by index.
virtual ~XFStyleContainer()
Definition: xfstylecont.cxx:74
static void ManageStyleFont(IXFStyle *pStyle)
IXFStyle * FindStyle(std::u16string_view name)
@descr get style by name.
void SetFont(rtl::Reference< XFFont > const &font)
@descr: set the font for the text span.
Definition: xftextstyle.cxx:70
const rtl::Reference< XFFont > & GetFont() const
Definition: xftextstyle.hxx:91
const char * name
int i
index
IXFStyle * m_pStyle
Definition: xfstylecont.hxx:71
bool m_bOrigDeleted
Definition: xfstylecont.hxx:72
@ enumXFStyleText
Definition: xfdefs.hxx:82
@ enumXFStylePara
Definition: xfdefs.hxx:83
bool operator==(XFStyleContainer &b1, XFStyleContainer &b2)
bool operator!=(XFStyleContainer &b1, XFStyleContainer &b2)