tdf#131098 docx export: write fill property of graphic
[LibreOffice.git] / lotuswordpro / source / filter / lwpfribptr.cxx
blobb1cd449765a181d7e044935682e65cbf05cd94f7
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 "lwpfribptr.hxx"
63 #include "lwpfribheader.hxx"
64 #include "lwpfribtext.hxx"
65 #include "lwppara.hxx"
66 #include "lwpstory.hxx"
67 #include <xfilter/xftextspan.hxx>
68 #include <xfilter/xftabstop.hxx>
69 #include <xfilter/xflinebreak.hxx>
70 #include "lwpfribsection.hxx"
71 #include "lwpsection.hxx"
72 #include "lwpfribbreaks.hxx"
73 #include "lwpfribframe.hxx"
74 #include "lwpfribtable.hxx"
75 #include <xfilter/xftextstyle.hxx>
76 #include <xfilter/xfstylemanager.hxx>
77 #include "lwphyperlinkmgr.hxx"
78 #include "lwpfootnote.hxx"
79 #include "lwpnotes.hxx"
80 #include "lwpfribmark.hxx"
81 #include <xfilter/xfchange.hxx>
82 #include <lwpchangemgr.hxx>
83 #include <lwpglobalmgr.hxx>
84 #include <lwpdropcapmgr.hxx>
86 LwpFribPtr::LwpFribPtr()
87 : m_pFribs(nullptr)
88 , m_pPara(nullptr)
92 LwpFribPtr::~LwpFribPtr()
94 for (LwpFrib* pCurFrib = m_pFribs; pCurFrib;)
96 LwpFrib* pNextFrib = pCurFrib -> GetNext();
97 delete pCurFrib;
98 pCurFrib = pNextFrib;
102 void LwpFribPtr::ReadPara(LwpObjectStream* pObjStrm)
104 LwpFrib* pCurFrib = m_pFribs = nullptr;
105 for(;;)
107 // Get the frib type
108 sal_uInt8 FribTag = pObjStrm->QuickReaduInt8();
110 sal_uInt8 FribType = FribTag & ~FRIB_TAG_TYPEMASK;
112 // Stop when we hit Elvis
113 if (FribType == FRIB_TAG_ELVIS)
114 break;
116 // skip the editor ID
117 //pObjStrm->SeekRel(sizeof(sal_uInt8));
118 sal_uInt8 FribEditor = pObjStrm->QuickReaduInt8();
119 if( FribType != FT_MAXIMUM )
121 LwpFrib* pFrib = LwpFrib::CreateFrib( m_pPara, pObjStrm, FribTag,FribEditor);
122 if(!m_pFribs)
124 m_pFribs = pFrib;
126 if(pCurFrib)
128 pCurFrib->SetNext(pFrib);
130 else//first frib in the para
132 if (pFrib->GetType() == FRIB_TAG_TEXT)
134 LwpFribText* pText = static_cast<LwpFribText*>(pFrib);
135 if (pFrib->GetModifiers())
136 m_pPara->SetFirstFrib(pText->GetText(),pText->GetModifiers()->FontID);
137 else
138 m_pPara->SetFirstFrib(pText->GetText(),0);
141 pCurFrib = pFrib;
146 void LwpFribPtr::XFConvert()
148 LwpFrib* pFrib = m_pFribs;
149 while(pFrib)
151 sal_uInt8 nFribType = pFrib->GetType();
152 bool bRevisionFlag = pFrib->GetRevisionFlag();
153 OUString sChangeID;
154 if (bRevisionFlag)
156 if ( nFribType!= FRIB_TAG_TABLE && nFribType != FRIB_TAG_FIELD
157 && nFribType != FRIB_TAG_FRAME)
159 //sal_uInt8 nRevisionType = pFrib->GetRevisionType();
160 LwpGlobalMgr* pGlobal = LwpGlobalMgr::GetInstance();
161 LwpChangeMgr* pChangeMgr = pGlobal->GetLwpChangeMgr();
162 sChangeID = pChangeMgr->GetChangeID(pFrib);
163 if (!sChangeID.isEmpty())
165 rtl::Reference<XFChangeStart> xChangeStart(new XFChangeStart);
166 xChangeStart->SetChangeID(sChangeID);
167 m_pXFPara->Add(xChangeStart.get());
172 switch(nFribType)
174 case FRIB_TAG_TEXT:
176 LwpFribText* textFrib= static_cast<LwpFribText*>(pFrib);
177 textFrib->XFConvert(m_pXFPara.get(),m_pPara->GetStory());
179 break;
180 case FRIB_TAG_TAB:
182 LwpFribTab* tabFrib = static_cast<LwpFribTab*>(pFrib);
183 if (pFrib->m_ModFlag)
185 rtl::Reference<XFTextSpan> xSpan(new XFTextSpan);
186 xSpan->SetStyleName(tabFrib->GetStyleName());
187 rtl::Reference<XFTabStop> xTab(new XFTabStop);
188 xSpan->Add(xTab.get());
189 m_pXFPara->Add(xSpan.get());
191 else
193 rtl::Reference<XFTabStop> xTab(new XFTabStop);
194 m_pXFPara->Add(xTab.get());
196 break;
198 case FRIB_TAG_SECTION:
200 LwpFribSection* pSectionFrib = static_cast<LwpFribSection*>(pFrib);
201 pSectionFrib->ParseSection();
202 break;
205 case FRIB_TAG_PAGEBREAK:
207 LwpFribPageBreak* pPageBreak = static_cast<LwpFribPageBreak*>(pFrib);
208 LwpPageLayout* pLayout = dynamic_cast<LwpPageLayout*>(pPageBreak->GetLayout().obj().get());
209 if(pLayout)
211 pPageBreak->ParseLayout();
213 else
215 if (pPageBreak->IsLastFrib())
217 m_pXFPara->SetStyleName( pPageBreak->GetStyleName() );
219 else
221 //parse pagebreak
222 rtl::Reference<XFParagraph> xPara(new XFParagraph);
223 xPara->SetStyleName(pFrib->GetStyleName());
224 SetXFPara(xPara.get());
225 m_pPara->AddXFContent(xPara.get());
228 break;
230 case FRIB_TAG_COLBREAK:
232 rtl::Reference<XFParagraph> xPara(new XFParagraph);
233 xPara->SetStyleName(pFrib->GetStyleName());
234 SetXFPara(xPara.get());
235 m_pPara->AddXFContent(xPara.get());
236 break;
238 case FRIB_TAG_LINEBREAK:
240 rtl::Reference<XFLineBreak> xLineBreak(new XFLineBreak);
241 m_pXFPara->Add(xLineBreak.get());
242 break;
244 case FRIB_TAG_UNICODE: //fall through
245 case FRIB_TAG_UNICODE2: //fall through
246 case FRIB_TAG_UNICODE3: //fall through
248 LwpFribUnicode* unicodeFrib= static_cast<LwpFribUnicode*>(pFrib);
249 unicodeFrib->XFConvert(m_pXFPara.get(), m_pPara->GetStory());
251 break;
252 case FRIB_TAG_HARDSPACE:
254 OUString sHardSpace(u'\x00a0');
255 LwpStory *pStory = m_pPara->GetStory();
256 LwpHyperlinkMgr* pHyperlink = pStory ? pStory->GetHyperlinkMgr() : nullptr;
257 if (pHyperlink && pHyperlink->GetHyperlinkFlag())
258 pFrib->ConvertHyperLink(m_pXFPara.get(), pHyperlink,sHardSpace);
259 else
260 pFrib->ConvertChars(m_pXFPara.get(), sHardSpace);
262 break;
263 case FRIB_TAG_SOFTHYPHEN:
264 pFrib->ConvertChars(m_pXFPara.get(), u"\x00ad"_ustr);
265 break;
266 case FRIB_TAG_FRAME:
268 LwpFribFrame* frameFrib= static_cast<LwpFribFrame*>(pFrib);
269 rtl::Reference<LwpObject> pLayout = frameFrib->GetLayout();
270 if (pLayout.is() && pLayout->GetTag() == VO_DROPCAPLAYOUT)
272 LwpFoundry* pFoundry = m_pPara->GetFoundry();
273 LwpDropcapMgr* pMgr = pFoundry ? &pFoundry->GetDropcapMgr() : nullptr;
274 if (pMgr)
275 pMgr->SetXFPara(m_pXFPara.get());
277 frameFrib->XFConvert(m_pXFPara.get());
278 break;
280 case FRIB_TAG_CHBLOCK:
282 LwpFribCHBlock* chbFrib = static_cast<LwpFribCHBlock*>(pFrib);
283 chbFrib->XFConvert(m_pXFPara.get(),m_pPara->GetStory());
285 break;
286 case FRIB_TAG_TABLE:
288 LwpFribTable* tableFrib = static_cast<LwpFribTable*>(pFrib);
289 //tableFrib->XFConvert(m_pPara->GetXFContainer());
290 tableFrib->XFConvert(m_pXFPara.get());
292 break;
293 case FRIB_TAG_BOOKMARK:
295 LwpFribBookMark* bookmarkFrib = static_cast<LwpFribBookMark*>(pFrib);
296 bookmarkFrib->XFConvert(m_pXFPara.get());
298 break;
299 case FRIB_TAG_FOOTNOTE:
301 LwpFribFootnote* pFootnoteFrib = static_cast<LwpFribFootnote*>(pFrib);
302 pFootnoteFrib->XFConvert(m_pXFPara.get());
303 break;
305 case FRIB_TAG_FIELD:
307 LwpFribField* fieldFrib = static_cast<LwpFribField*>(pFrib);
308 fieldFrib->XFConvert(m_pXFPara.get());
309 break;
311 case FRIB_TAG_NOTE:
313 LwpFribNote* pNoteFrib = static_cast<LwpFribNote*>(pFrib);
314 pNoteFrib->XFConvert(m_pXFPara.get());
315 break;
317 case FRIB_TAG_PAGENUMBER:
319 LwpFribPageNumber* pagenumFrib = static_cast<LwpFribPageNumber*>(pFrib);
320 pagenumFrib->XFConvert(m_pXFPara.get());
321 break;
323 case FRIB_TAG_DOCVAR:
325 LwpFribDocVar* docFrib = static_cast<LwpFribDocVar*>(pFrib);
326 docFrib->XFConvert(m_pXFPara.get());
327 break;
329 case FRIB_TAG_RUBYMARKER:
331 LwpFribRubyMarker* rubyFrib = static_cast<LwpFribRubyMarker*>(pFrib);
332 rubyFrib->XFConvert(m_pXFPara.get());
333 break;
335 case FRIB_TAG_RUBYFRAME:
337 LwpFribRubyFrame* rubyfrmeFrib = static_cast<LwpFribRubyFrame*>(pFrib);
338 rubyfrmeFrib->XFConvert();
339 break;
341 default :
342 break;
345 if (bRevisionFlag )//&& pFrib->GetRevisionType() == LwpFrib::REV_INSERT)
347 if (nFribType!= FRIB_TAG_TABLE && nFribType != FRIB_TAG_FIELD
348 && nFribType != FRIB_TAG_FRAME)
350 if (!sChangeID.isEmpty())
352 rtl::Reference<XFChangeEnd> xChangeEnd(new XFChangeEnd);
353 xChangeEnd->SetChangeID(sChangeID);
354 m_pXFPara->Add(xChangeEnd.get());
358 pFrib = pFrib->GetNext();
363 /**************************************************************************
364 * @descr: Whether has a frib which type is nType
365 **************************************************************************/
366 LwpFrib* LwpFribPtr::HasFrib(sal_uInt8 nType)
368 LwpFrib* pFrib = m_pFribs;
369 while(pFrib)
371 if(pFrib->GetType()==nType)
373 return pFrib;
375 pFrib = pFrib->GetNext();
377 return nullptr;
380 void LwpFribPtr::GatherAllText()
382 LwpFrib* pFrib = m_pFribs;
383 while(pFrib)
385 switch(pFrib->GetType())
387 case FRIB_TAG_TEXT:
389 OUString sText = static_cast<LwpFribText*>(pFrib)->GetText();
390 m_pPara->SetAllText(sText);
391 break;
393 case FRIB_TAG_UNICODE: //fall through
394 case FRIB_TAG_UNICODE2: //fall through
395 case FRIB_TAG_UNICODE3: //fall through :
397 OUString sText = static_cast<LwpFribText*>(pFrib)->GetText();
398 m_pPara->SetAllText(sText);
399 break;
401 default :
402 break;
404 pFrib = pFrib->GetNext();
408 void LwpFribPtr::RegisterStyle()
410 LwpFrib* pFrib = m_pFribs;
411 while(pFrib)
413 switch(pFrib->GetType())
415 case FRIB_TAG_TEXT:
417 pFrib->RegisterStyle(m_pPara->GetFoundry());
418 OUString sText = static_cast<LwpFribText*>(pFrib)->GetText();
419 ProcessDropcap(m_pPara->GetStory(), pFrib,sText.getLength());
420 break;
422 case FRIB_TAG_TAB:
423 pFrib->RegisterStyle(m_pPara->GetFoundry());
424 break;
425 case FRIB_TAG_SECTION:
427 //section registerstyle here;
428 LwpFribSection* pSectionFrib = static_cast<LwpFribSection*>(pFrib);
429 pSectionFrib->RegisterSectionStyle();
430 //for bullet
431 pSectionFrib->SetSectionName();
433 break;
434 case FRIB_TAG_PAGEBREAK:
436 LwpFribPageBreak* breakFrib = static_cast<LwpFribPageBreak*>(pFrib);
437 breakFrib->RegisterBreakStyle(m_pPara);
439 break;
440 case FRIB_TAG_COLBREAK:
442 LwpFribColumnBreak* breakFrib = static_cast<LwpFribColumnBreak*>(pFrib);
443 breakFrib->RegisterBreakStyle(m_pPara);
445 break;
446 case FRIB_TAG_UNICODE: //fall through
447 case FRIB_TAG_UNICODE2: //fall through
448 case FRIB_TAG_UNICODE3: //fall through :
450 pFrib->RegisterStyle(m_pPara->GetFoundry());
451 OUString sText = static_cast<LwpFribUnicode*>(pFrib)->GetText();
452 ProcessDropcap(m_pPara->GetStory(), pFrib,sText.getLength());
453 break;
455 case FRIB_TAG_HARDSPACE:
456 pFrib->RegisterStyle(m_pPara->GetFoundry());
457 ProcessDropcap(m_pPara->GetStory(),pFrib,1);
458 break;
459 case FRIB_TAG_SOFTHYPHEN:
460 pFrib->RegisterStyle(m_pPara->GetFoundry());
461 break;
462 case FRIB_TAG_FRAME:
464 LwpFribFrame* frameFrib = static_cast<LwpFribFrame*>(pFrib);
465 frameFrib->SetParaDropcap(m_pPara);
466 frameFrib->RegisterStyle(m_pPara->GetFoundry());
467 //register framelayout style, ,03/09/2005
468 //frameFrib->GetLayout()->RegisterStyle();
470 break;
471 case FRIB_TAG_CHBLOCK:
472 break;
473 case FRIB_TAG_TABLE:
475 LwpFribTable* tableFrib = static_cast<LwpFribTable*>(pFrib);
476 tableFrib->RegisterNewStyle();
478 break;
479 case FRIB_TAG_FOOTNOTE:
481 LwpFribFootnote* pFribFootnote = static_cast<LwpFribFootnote*>(pFrib);
482 pFribFootnote->RegisterNewStyle();
484 break;
485 case FRIB_TAG_NOTE:
487 LwpFribNote* pNoteFrib = static_cast<LwpFribNote*>(pFrib);
488 pNoteFrib->RegisterNewStyle();
489 break;
491 case FRIB_TAG_PAGENUMBER:
493 pFrib->RegisterStyle(m_pPara->GetFoundry());
494 break;
496 case FRIB_TAG_DOCVAR:
498 LwpFribDocVar* docFrib = static_cast<LwpFribDocVar*>(pFrib);
499 docFrib->RegisterStyle(m_pPara->GetFoundry());
500 break;
502 case FRIB_TAG_FIELD:
504 LwpFribField* fieldFrib = static_cast<LwpFribField*>(pFrib);
505 fieldFrib->RegisterStyle(m_pPara->GetFoundry());
506 break;
508 case FRIB_TAG_BOOKMARK:
510 LwpFribBookMark* bookmarkFrib = static_cast<LwpFribBookMark*>(pFrib);
511 bookmarkFrib->RegisterStyle(m_pPara->GetFoundry());
512 break;
514 case FRIB_TAG_RUBYFRAME:
516 LwpFribRubyFrame* rubyfrmeFrib = static_cast<LwpFribRubyFrame*>(pFrib);
517 rubyfrmeFrib->RegisterStyle(m_pPara->GetFoundry());
518 break;
520 default :
521 break;
523 if (pFrib->GetRevisionFlag() && pFrib->GetType()!= FRIB_TAG_FIELD)
525 LwpGlobalMgr* pGlobal = LwpGlobalMgr::GetInstance();
526 LwpChangeMgr* pChangeMgr = pGlobal->GetLwpChangeMgr();
527 pChangeMgr->AddChangeFrib(pFrib);
530 pFrib = pFrib->GetNext();
534 void LwpFribPtr::ProcessDropcap(LwpStory* pStory, const LwpFrib* pFrib,sal_uInt32 nLen)
536 if (pStory && pStory->GetDropcapFlag())
538 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
539 XFTextStyle* pFribStyle = pXFStyleManager->FindTextStyle(pFrib->GetStyleName());
540 pFribStyle->GetFont()->SetFontSize(0);
542 LwpDropcapLayout* pObj = dynamic_cast<LwpDropcapLayout*>(pStory->GetLayoutsWithMe().GetOnlyLayout().obj().get());
543 if (pObj)
544 pObj->SetChars(nLen);
548 * @descr: If the position of pPreLayout is earlier than pNextLayout, return true, or return false, default return true
551 bool LwpFribPtr::ComparePagePosition(LwpVirtualLayout const * pPreLayout, LwpVirtualLayout const * pNextLayout)
553 if(!pPreLayout || !pNextLayout)
554 return true;
556 LwpFrib* pFrib = m_pFribs;
557 LwpVirtualLayout* pLayout = nullptr;
558 while(pFrib)
560 switch(pFrib->GetType())
562 case FRIB_TAG_SECTION:
564 LwpFribSection* pSectionFrib = static_cast<LwpFribSection*>(pFrib);
565 LwpSection* pSection = pSectionFrib->GetSection();
566 if(pSection)
568 pLayout = pSection->GetPageLayout();
571 break;
573 case FRIB_TAG_PAGEBREAK:
575 LwpFribPageBreak* pPageBreak = static_cast<LwpFribPageBreak*>(pFrib);
576 pLayout = dynamic_cast<LwpVirtualLayout*>(pPageBreak->GetLayout().obj().get());
577 break;
579 default:
580 break;
583 if(pLayout)
585 if(pPreLayout == pLayout)
586 return true;
587 if(pNextLayout == pLayout)
588 return false;
590 pFrib = pFrib->GetNext();
593 return true;
596 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */