tdf#131098 docx export: write fill property of graphic
[LibreOffice.git] / lotuswordpro / source / filter / lwpbulletstylemgr.cxx
blobb633f9d18626fde4d8a0235f0655b75ee61e68d6
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * The Contents of this file are made available subject to the terms of
5 * either of the following licenses
7 * - GNU Lesser General Public License Version 2.1
8 * - Sun Industry Standards Source License Version 1.1
10 * Sun Microsystems Inc., October, 2000
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
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.
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.
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
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.
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.
46 * The Initial Developer of the Original Code is: IBM Corporation
48 * Copyright: 2008 by IBM Corporation
50 * All Rights Reserved.
52 * Contributor(s): _______________________________________
55 ************************************************************************/
56 /*************************************************************************
57 * @file
58 * For LWP filter architecture prototype
59 ************************************************************************/
61 #include "lwpbulletstylemgr.hxx"
62 #include "lwpfribheader.hxx"
63 #include "lwppara.hxx"
64 #include "lwpsilverbullet.hxx"
65 #include <lwptools.hxx>
66 #include "lwpparaproperty.hxx"
67 #include <xfilter/xfliststyle.hxx>
68 #include <xfilter/xfstylemanager.hxx>
69 #include <xfilter/xflist.hxx>
70 #include <lwpglobalmgr.hxx>
71 #include <xfilter/xflistitem.hxx>
72 #include <sal/log.hxx>
74 LwpBulletStyleMgr::LwpBulletStyleMgr()
75 : m_pFoundry(nullptr)
76 , m_bContinue(true)
77 , m_bIsBulletSkipped(false)
81 LwpBulletStyleMgr::~LwpBulletStyleMgr()
83 m_vIDsPairList.clear();
84 m_vStyleNameList.clear();
87 /**
88 * @short Register bullet style to style-list. The function only register the bullet and single customized numbering
89 * not including the numbering sequence.
90 * @param pPara pointer to the current paragraph which has a bullet/numbering.
91 * @param pBullOver pointer to the bulletoverride of current paragraph.
92 * @param pIndent pointer to the indentoverride of current paragraph.
94 OUString LwpBulletStyleMgr::RegisterBulletStyle(LwpPara* pPara, const LwpBulletOverride* pBullOver,
95 LwpIndentOverride const * pIndent)
97 if(!pPara || !pIndent || !pBullOver)
99 return OUString();
102 LwpSilverBullet* pSilverBullet = pPara->GetSilverBullet();
103 if (!pSilverBullet)
105 assert(false);
106 return OUString();
109 LwpPara* pBulletPara = pSilverBullet->GetBulletPara();
110 if (!pBulletPara)
112 SAL_WARN("lwp", "missing bullet para");
113 return OUString();
116 LwpParaProperty* pProp = pPara->GetProperty(PP_LOCAL_INDENT);
117 LwpObjectID aIndentID;
118 if (pProp)
120 LwpParaIndentProperty* pIndentProp = static_cast<LwpParaIndentProperty*>(pProp);
121 aIndentID = pIndentProp->GetIndentID();
124 LwpObjectID aBulletID = pBullOver->GetSilverBullet();
125 std::unique_ptr<LwpBulletOverride> pBulletOver(pBullOver->clone());
127 sal_uInt16 nNameIndex = 0;
128 for (auto const& vIDsPair : m_vIDsPairList)
130 if (vIDsPair.first->GetSilverBullet() == aBulletID && vIDsPair.second == aIndentID
131 && vIDsPair.first->IsRightAligned() == pBullOver->IsRightAligned())
133 return m_vStyleNameList[nNameIndex];
135 else
137 nNameIndex++;
141 m_vIDsPairList.emplace_back(std::move(pBulletOver), aIndentID);
142 OUString aStyleName;
144 LwpFribPtr& rBulletParaFribs = pBulletPara->GetFribs();
145 bool bIsNumbering = (rBulletParaFribs.HasFrib(FRIB_TAG_PARANUMBER) != nullptr);
147 enumXFAlignType eAlign = enumXFAlignStart;
148 if (pBullOver->IsRightAligned())
150 eAlign = enumXFAlignEnd;
153 std::unique_ptr<XFListStyle> pListStyle(new XFListStyle());
154 XFStyleManager* pXFStyleMgr = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
156 if (!bIsNumbering)
158 for (sal_uInt8 nC = 1; nC < 11; nC++)
160 pListStyle->SetListBullet(nC, pSilverBullet->GetBulletChar(), pSilverBullet->GetBulletFontName(),
161 LwpSilverBullet::GetPrefix(), LwpSilverBullet::GetSuffix());
163 if (pIndent->GetMRest() > 0) /* note: used to be 0.001, no idea why */
165 pListStyle->SetListPosition(nC, 0.0,
166 LwpTools::ConvertFromUnits(pIndent->GetMRest()), 0.0, eAlign);
168 else
170 pListStyle->SetListPosition(nC, 0.0,
171 0.0, LwpTools::ConvertFromUnits(pIndent->GetMFirst()), eAlign);
175 aStyleName = pXFStyleMgr->AddStyle(std::move(pListStyle)).m_pStyle->GetStyleName();
177 else
179 ParaNumbering aParaNumbering;
180 pBulletPara->GetParaNumber(1, &aParaNumbering);
181 LwpFribParaNumber* pParaNumber = aParaNumbering.pParaNumber;
182 if (pParaNumber)
184 for (sal_uInt8 nPos = 1; nPos < 10; nPos++)
186 if (pParaNumber->GetStyleID() != NUMCHAR_other)
188 OUString aPrefix;
189 XFNumFmt aFmt;
190 if (aParaNumbering.pPrefix)
192 aPrefix += aParaNumbering.pPrefix->GetText();
195 OUString aNumber = LwpSilverBullet::GetNumCharByStyleID(pParaNumber);
196 if (pParaNumber->GetStyleID() == NUMCHAR_01 || pParaNumber->GetStyleID() == NUMCHAR_Chinese4)
198 aPrefix += "0";
200 aFmt.SetPrefix(aPrefix);
202 aFmt.SetFormat(aNumber);
204 if (aParaNumbering.pSuffix)
206 aFmt.SetSuffix(aParaNumbering.pSuffix->GetText());
209 //set numbering format into the style-list.
210 pListStyle->SetListNumber(nPos, aFmt, pParaNumber->GetStart()+1);
213 else
215 OUString aPrefix, aSuffix;
216 if (aParaNumbering.pPrefix)
218 aPrefix = aParaNumbering.pPrefix->GetText();
220 if (aParaNumbering.pSuffix)
222 aSuffix = aParaNumbering.pSuffix->GetText();
225 pListStyle->SetListBullet(nPos, LwpSilverBullet::GetNumCharByStyleID(pParaNumber),
226 u"Times New Roman"_ustr, aPrefix, aSuffix);
229 pListStyle->SetListPosition(nPos, 0.0, 0.635, 0.0);
231 aStyleName = pXFStyleMgr->AddStyle(std::move(pListStyle)).m_pStyle->GetStyleName();
235 m_vStyleNameList.push_back(aStyleName);
236 return aStyleName;
240 //Create nested XFList and XFItems and then add it to XFContentContainer(pCont)
241 //Return the inner XFItem created.
242 rtl::Reference<XFContentContainer> LwpBulletStyleMgr::AddBulletList(
243 XFContentContainer* pCont, bool bIsOrdered,
244 const OUString& rStyleName, sal_Int16 nLevel, bool bIsBulletSkiped)
246 assert(nLevel > 0);
248 m_bIsBulletSkipped = bIsBulletSkiped;
250 //todo: need judge here.
251 bool bContinue = m_bContinue;
253 rtl::Reference<XFList> prevList;
254 XFListItem* theItem;
255 XFListItem* InnerItem = nullptr;
256 for (sal_Int8 nC = nLevel - 1; nC >= 0; nC--)
258 rtl::Reference<XFList> theList(new XFList);
259 theItem = new XFListItem();
260 theList->Add(theItem);
262 if (bIsOrdered)
264 theList->SetOrdered(true);
266 else
268 bContinue = false;
269 theList->SetOrdered(false);
272 if (nC == nLevel - 1)
274 theList->SetContinueNumber(bContinue);
276 //Add the outer list to pCont
277 if (nC == 0 && pCont)
279 theList->SetStyleName(rStyleName);
280 theList->SetContinueNumber(bContinue);
281 pCont->Add(theList.get());
284 if ((nC == 0) && bIsBulletSkiped)
286 theList->SetContinueNumber(true);
289 if ((nC == nLevel - 1) && bIsBulletSkiped)
291 theItem->SetIsHeader();
294 if (nC == nLevel - 1)
296 InnerItem = theItem;
299 if (prevList)
301 theItem->Add(prevList.get());
303 prevList = theList;
305 return InnerItem;
308 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */