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,
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 /*************************************************************************
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/xftextcontent.hxx"
69 #include "xfilter/xftabstop.hxx"
70 #include "xfilter/xflinebreak.hxx"
71 #include "lwpfribsection.hxx"
72 #include "lwpsection.hxx"
73 #include "lwpfribbreaks.hxx"
74 #include "lwpfribframe.hxx"
75 #include "lwpfribtable.hxx"
76 #include "xfilter/xfstylemanager.hxx"
77 #include "lwphyperlinkmgr.hxx"
78 #include "xfilter/xfhyperlink.hxx"
79 #include "lwpfootnote.hxx"
80 #include "lwpnotes.hxx"
81 #include "lwpfribmark.hxx"
82 #include "xfilter/xfchange.hxx"
83 #include "lwpchangemgr.hxx"
84 #include "lwpglobalmgr.hxx"
85 #include "lwpdropcapmgr.hxx"
87 LwpFribPtr::LwpFribPtr()
88 : m_pFribs(nullptr),m_pXFPara(nullptr),m_pPara(nullptr)
92 LwpFribPtr::~LwpFribPtr()
94 for (LwpFrib
* pCurFrib
= m_pFribs
; pCurFrib
;)
96 LwpFrib
* pNextFrib
= pCurFrib
-> GetNext();
102 void LwpFribPtr::ReadPara(LwpObjectStream
* pObjStrm
)
104 LwpFrib
* pCurFrib
= m_pFribs
= nullptr;
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
)
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
);
128 pCurFrib
->SetNext(pFrib
);
130 else//frist 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
);
138 m_pPara
->SetFirstFrib(pText
->GetText(),0);
146 void LwpFribPtr::XFConvert()
148 LwpFrib
* pFrib
= m_pFribs
;
151 sal_uInt8 nFribType
= pFrib
->GetType();
152 bool bRevisionFlag
= pFrib
->GetRevisionFlag();
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 /// if (nRevisionType == LwpFrib::REV_INSERT)
167 XFChangeStart
* pChangeStart
= new XFChangeStart
;
168 pChangeStart
->SetChangeID(sChangeID
);
169 m_pXFPara
->Add(pChangeStart
);
171 /// else if (nRevisionType == LwpFrib::REV_DELETE)
173 /// XFChange* pChange = new XFChange;
174 /// pChange->SetChangeID(sChangeID);
175 /// m_pXFPara->Add(pChange);
176 /// pFrib = pFrib->GetNext();
187 LwpFribText
* textFrib
= static_cast<LwpFribText
*>(pFrib
);
188 textFrib
->XFConvert(m_pXFPara
,m_pPara
->GetStory());
193 LwpFribTab
* tabFrib
= static_cast<LwpFribTab
*>(pFrib
);
194 if (pFrib
->m_ModFlag
)
196 XFTextSpan
*pSpan
= new XFTextSpan();
197 pSpan
->SetStyleName(tabFrib
->GetStyleName());
198 XFTabStop
*pTab
= new XFTabStop();
200 m_pXFPara
->Add(pSpan
);
204 XFTabStop
*pTab
= new XFTabStop();
205 m_pXFPara
->Add(pTab
);
209 case FRIB_TAG_SECTION
:
211 LwpFribSection
* pSectionFrib
= static_cast<LwpFribSection
*>(pFrib
);
212 pSectionFrib
->ParseSection();
216 case FRIB_TAG_PAGEBREAK
:
218 LwpFribPageBreak
* pPageBreak
= static_cast<LwpFribPageBreak
*>(pFrib
);
219 LwpPageLayout
* pLayout
= dynamic_cast<LwpPageLayout
*>(pPageBreak
->GetLayout().obj().get());
222 pPageBreak
->ParseLayout();
226 if (pPageBreak
->IsLastFrib())
228 m_pXFPara
->SetStyleName( pPageBreak
->GetStyleName() );
233 XFParagraph
*pPara
= new XFParagraph();
234 pPara
->SetStyleName(pFrib
->GetStyleName());
236 m_pPara
->AddXFContent(pPara
);
241 case FRIB_TAG_COLBREAK
:
243 XFParagraph
*pPara
= new XFParagraph();
244 pPara
->SetStyleName(pFrib
->GetStyleName());
246 m_pPara
->AddXFContent(pPara
);
249 case FRIB_TAG_LINEBREAK
:
251 XFLineBreak
*pLineBreak
= new XFLineBreak();
252 m_pXFPara
->Add(pLineBreak
);
255 case FRIB_TAG_UNICODE
: //fall through
256 case FRIB_TAG_UNICODE2
: //fall through
257 case FRIB_TAG_UNICODE3
: //fall through
259 LwpFribUnicode
* unicodeFrib
= static_cast<LwpFribUnicode
*>(pFrib
);
260 unicodeFrib
->XFConvert(m_pXFPara
,m_pPara
->GetStory());
263 case FRIB_TAG_HARDSPACE
:
265 OUString
sHardSpace(sal_Unicode(0x00a0));
266 LwpStory
*pStory
= m_pPara
->GetStory();
267 LwpHyperlinkMgr
* pHyperlink
= pStory
? pStory
->GetHyperlinkMgr() : nullptr;
268 if (pHyperlink
&& pHyperlink
->GetHyperlinkFlag())
269 pFrib
->ConvertHyperLink(m_pXFPara
,pHyperlink
,sHardSpace
);
271 pFrib
->ConvertChars(m_pXFPara
,sHardSpace
);
274 case FRIB_TAG_SOFTHYPHEN
:
276 OUString
sSoftHyphen(sal_Unicode(0x00ad));
277 pFrib
->ConvertChars(m_pXFPara
,sSoftHyphen
);
282 LwpFribFrame
* frameFrib
= static_cast<LwpFribFrame
*>(pFrib
);
283 rtl::Reference
<LwpObject
> pLayout
= frameFrib
->GetLayout();
284 if (pLayout
.is() && pLayout
->GetTag() == VO_DROPCAPLAYOUT
)
286 LwpFoundry
* pFoundry
= m_pPara
->GetFoundry();
287 LwpDropcapMgr
* pMgr
= pFoundry
? pFoundry
->GetDropcapMgr() : nullptr;
289 pMgr
->SetXFPara(m_pXFPara
);
291 frameFrib
->XFConvert(m_pXFPara
);
294 case FRIB_TAG_CHBLOCK
:
296 LwpFribCHBlock
* chbFrib
= static_cast<LwpFribCHBlock
*>(pFrib
);
297 chbFrib
->XFConvert(m_pXFPara
,m_pPara
->GetStory());
302 LwpFribTable
* tableFrib
= static_cast<LwpFribTable
*>(pFrib
);
303 //tableFrib->XFConvert(m_pPara->GetXFContainer());
304 tableFrib
->XFConvert(m_pXFPara
);
307 case FRIB_TAG_BOOKMARK
:
309 LwpFribBookMark
* bookmarkFrib
= static_cast<LwpFribBookMark
*>(pFrib
);
310 bookmarkFrib
->XFConvert(m_pXFPara
);
313 case FRIB_TAG_FOOTNOTE
:
315 LwpFribFootnote
* pFootnoteFrib
= static_cast<LwpFribFootnote
*>(pFrib
);
316 pFootnoteFrib
->XFConvert(m_pXFPara
);
321 LwpFribField
* fieldFrib
= static_cast<LwpFribField
*>(pFrib
);
322 fieldFrib
->XFConvert(m_pXFPara
);
327 LwpFribNote
* pNoteFrib
= static_cast<LwpFribNote
*>(pFrib
);
328 pNoteFrib
->XFConvert(m_pXFPara
);
331 case FRIB_TAG_PAGENUMBER
:
333 LwpFribPageNumber
* pagenumFrib
= static_cast<LwpFribPageNumber
*>(pFrib
);
334 pagenumFrib
->XFConvert(m_pXFPara
);
337 case FRIB_TAG_DOCVAR
:
339 LwpFribDocVar
* docFrib
= static_cast<LwpFribDocVar
*>(pFrib
);
340 docFrib
->XFConvert(m_pXFPara
);
343 case FRIB_TAG_RUBYMARKER
:
345 LwpFribRubyMarker
* rubyFrib
= static_cast<LwpFribRubyMarker
*>(pFrib
);
346 rubyFrib
->XFConvert(m_pXFPara
);
349 case FRIB_TAG_RUBYFRAME
:
351 LwpFribRubyFrame
* rubyfrmeFrib
= static_cast<LwpFribRubyFrame
*>(pFrib
);
352 rubyfrmeFrib
->XFConvert(m_pXFPara
);
359 if (bRevisionFlag
)//&& pFrib->GetRevisionType() == LwpFrib::REV_INSERT)
361 if (nFribType
!= FRIB_TAG_TABLE
&& nFribType
!= FRIB_TAG_FIELD
362 && nFribType
!= FRIB_TAG_FRAME
)
364 if (!sChangeID
.isEmpty())
366 XFChangeEnd
* pChangeEnd
= new XFChangeEnd
;
367 pChangeEnd
->SetChangeID(sChangeID
);
368 m_pXFPara
->Add(pChangeEnd
);
372 pFrib
= pFrib
->GetNext();
377 void LwpFribPtr::FindLayouts()
379 LwpFrib
* pFrib
= m_pFribs
;
382 switch(pFrib
->GetType())
384 case FRIB_TAG_SECTION
:
386 LwpFribSection
* pSectionFrib
= static_cast<LwpFribSection
*>(pFrib
);
387 LwpSection
* pSection
= pSectionFrib
->GetSection();
390 LwpPageLayout
* pLayout
= pSection
->GetPageLayout();
393 LwpLayout::UseWhenType eSectionType
= pLayout
->GetUseWhenType();
394 if(eSectionType
==LwpLayout::StartWithinColume
)
396 //StartWithinColume type not support now
399 LwpStory
* pStory
= dynamic_cast<LwpStory
*>(m_pPara
->GetStoryID().obj().get());
401 pStory
->AddPageLayout(pSection
->GetPageLayout());
407 case FRIB_TAG_PAGEBREAK
:
409 LwpFribPageBreak
* pPageBreak
= static_cast<LwpFribPageBreak
*>(pFrib
);
410 LwpPageLayout
* pLayout
= dynamic_cast<LwpPageLayout
*>(pPageBreak
->GetLayout().obj().get());
413 LwpStory
* pStory
= dynamic_cast<LwpStory
*>(m_pPara
->GetStoryID().obj().get());
415 pStory
->AddPageLayout(pLayout
);
422 pFrib
= pFrib
->GetNext();
425 /**************************************************************************
426 * @descr: Whether has a frib which type is nType
427 **************************************************************************/
428 LwpFrib
* LwpFribPtr::HasFrib(sal_uInt8 nType
)
430 LwpFrib
* pFrib
= m_pFribs
;
433 if(pFrib
->GetType()==nType
)
437 pFrib
= pFrib
->GetNext();
442 void LwpFribPtr::GatherAllText()
444 LwpFrib
* pFrib
= m_pFribs
;
447 switch(pFrib
->GetType())
451 OUString sText
= static_cast<LwpFribText
*>(pFrib
)->GetText();
452 m_pPara
->SetAllText(sText
);
455 case FRIB_TAG_UNICODE
: //fall through
456 case FRIB_TAG_UNICODE2
: //fall through
457 case FRIB_TAG_UNICODE3
: //fall through :
459 OUString sText
= static_cast<LwpFribText
*>(pFrib
)->GetText();
460 m_pPara
->SetAllText(sText
);
466 pFrib
= pFrib
->GetNext();
470 void LwpFribPtr::RegisterStyle()
472 LwpFrib
* pFrib
= m_pFribs
;
475 switch(pFrib
->GetType())
479 pFrib
->RegisterStyle(m_pPara
->GetFoundry());
480 OUString sText
= static_cast<LwpFribText
*>(pFrib
)->GetText();
481 ProcessDropcap(m_pPara
->GetStory(), pFrib
,sText
.getLength());
485 pFrib
->RegisterStyle(m_pPara
->GetFoundry());
487 case FRIB_TAG_SECTION
:
489 //section registerstyle here;
490 LwpFribSection
* pSectionFrib
= static_cast<LwpFribSection
*>(pFrib
);
491 pSectionFrib
->RegisterSectionStyle();
493 pSectionFrib
->SetSectionName();
496 case FRIB_TAG_PAGEBREAK
:
498 LwpFribPageBreak
* breakFrib
= static_cast<LwpFribPageBreak
*>(pFrib
);
499 breakFrib
->RegisterBreakStyle(m_pPara
);
502 case FRIB_TAG_COLBREAK
:
504 LwpFribColumnBreak
* breakFrib
= static_cast<LwpFribColumnBreak
*>(pFrib
);
505 breakFrib
->RegisterBreakStyle(m_pPara
);
508 case FRIB_TAG_UNICODE
: //fall through
509 case FRIB_TAG_UNICODE2
: //fall through
510 case FRIB_TAG_UNICODE3
: //fall through :
512 pFrib
->RegisterStyle(m_pPara
->GetFoundry());
513 OUString sText
= static_cast<LwpFribUnicode
*>(pFrib
)->GetText();
514 ProcessDropcap(m_pPara
->GetStory(), pFrib
,sText
.getLength());
517 case FRIB_TAG_HARDSPACE
:
518 pFrib
->RegisterStyle(m_pPara
->GetFoundry());
519 ProcessDropcap(m_pPara
->GetStory(),pFrib
,1);
521 case FRIB_TAG_SOFTHYPHEN
:
522 pFrib
->RegisterStyle(m_pPara
->GetFoundry());
526 LwpFribFrame
* frameFrib
= static_cast<LwpFribFrame
*>(pFrib
);
527 frameFrib
->SetParaDropcap(m_pPara
);
528 frameFrib
->RegisterStyle(m_pPara
->GetFoundry());
529 //register framelayout style, ,03/09/2005
530 //frameFrib->GetLayout()->RegisterStyle();
533 case FRIB_TAG_CHBLOCK
:
537 LwpFribTable
* tableFrib
= static_cast<LwpFribTable
*>(pFrib
);
538 tableFrib
->RegisterNewStyle();
541 case FRIB_TAG_FOOTNOTE
:
543 LwpFribFootnote
* pFribFootnote
= static_cast<LwpFribFootnote
*>(pFrib
);
544 pFribFootnote
->RegisterNewStyle();
549 LwpFribNote
* pNoteFrib
= static_cast<LwpFribNote
*>(pFrib
);
550 pNoteFrib
->RegisterNewStyle();
553 case FRIB_TAG_PAGENUMBER
:
555 pFrib
->RegisterStyle(m_pPara
->GetFoundry());
558 case FRIB_TAG_DOCVAR
:
560 LwpFribDocVar
* docFrib
= static_cast<LwpFribDocVar
*>(pFrib
);
561 docFrib
->RegisterStyle(m_pPara
->GetFoundry());
566 LwpFribField
* fieldFrib
= static_cast<LwpFribField
*>(pFrib
);
567 fieldFrib
->RegisterStyle(m_pPara
->GetFoundry());
570 case FRIB_TAG_BOOKMARK
:
572 LwpFribBookMark
* bookmarkFrib
= static_cast<LwpFribBookMark
*>(pFrib
);
573 bookmarkFrib
->RegisterStyle(m_pPara
->GetFoundry());
576 case FRIB_TAG_RUBYFRAME
:
578 LwpFribRubyFrame
* rubyfrmeFrib
= static_cast<LwpFribRubyFrame
*>(pFrib
);
579 rubyfrmeFrib
->RegisterStyle(m_pPara
->GetFoundry());
585 if (pFrib
->GetRevisionFlag() && pFrib
->GetType()!= FRIB_TAG_FIELD
)
587 LwpGlobalMgr
* pGlobal
= LwpGlobalMgr::GetInstance();
588 LwpChangeMgr
* pChangeMgr
= pGlobal
->GetLwpChangeMgr();
589 pChangeMgr
->AddChangeFrib(pFrib
);
592 pFrib
= pFrib
->GetNext();
596 void LwpFribPtr::ProcessDropcap(LwpStory
* pStory
,LwpFrib
* pFrib
,sal_uInt32 nLen
)
600 if (pStory
->GetDropcapFlag())
602 XFStyleManager
* pXFStyleManager
= LwpGlobalMgr::GetInstance()->GetXFStyleManager();
603 XFTextStyle
* pFribStyle
= pXFStyleManager
->FindTextStyle(pFrib
->GetStyleName());
604 pFribStyle
->GetFont()->SetFontSize(0);
606 LwpDropcapLayout
* pObj
= dynamic_cast<LwpDropcapLayout
*>(pStory
->GetLayoutsWithMe().GetOnlyLayout().obj().get());
608 pObj
->SetChars(nLen
);
613 * @descr: If the position of pPreLayout is earlier than pNextLayout, return true, or return false, default return true
616 bool LwpFribPtr::ComparePagePosition(LwpVirtualLayout
* pPreLayout
, LwpVirtualLayout
* pNextLayout
)
618 if(!pPreLayout
|| !pNextLayout
)
621 LwpFrib
* pFrib
= m_pFribs
;
622 LwpVirtualLayout
* pLayout
= nullptr;
625 switch(pFrib
->GetType())
627 case FRIB_TAG_SECTION
:
629 LwpFribSection
* pSectionFrib
= static_cast<LwpFribSection
*>(pFrib
);
630 LwpSection
* pSection
= pSectionFrib
->GetSection();
633 pLayout
= pSection
->GetPageLayout();
638 case FRIB_TAG_PAGEBREAK
:
640 LwpFribPageBreak
* pPageBreak
= static_cast<LwpFribPageBreak
*>(pFrib
);
641 pLayout
= dynamic_cast<LwpVirtualLayout
*>(pPageBreak
->GetLayout().obj().get());
650 if(pPreLayout
== pLayout
)
652 if(pNextLayout
== pLayout
)
655 pFrib
= pFrib
->GetNext();
661 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */