1 /*************************************************************************
3 * The Contents of this file are made available subject to the terms of
4 * either of the following licenses
6 * - GNU Lesser General Public License Version 2.1
7 * - Sun Industry Standards Source License Version 1.1
9 * Sun Microsystems Inc., October, 2000
11 * GNU Lesser General Public License Version 2.1
12 * =============================================
13 * Copyright 2000 by Sun Microsystems, Inc.
14 * 901 San Antonio Road, Palo Alto, CA 94303, USA
16 * This library is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU Lesser General Public
18 * License version 2.1, as published by the Free Software Foundation.
20 * This library is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 * Lesser General Public License for more details.
25 * You should have received a copy of the GNU Lesser General Public
26 * License along with this library; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
31 * Sun Industry Standards Source License Version 1.1
32 * =================================================
33 * The contents of this file are subject to the Sun Industry Standards
34 * Source License Version 1.1 (the "License"); You may not use this file
35 * except in compliance with the License. You may obtain a copy of the
36 * License at http://www.openoffice.org/license.html.
38 * Software provided under this License is provided on an "AS IS" basis,
39 * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
40 * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
41 * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
42 * See the License for the specific provisions governing your rights and
43 * obligations concerning the Software.
45 * The Initial Developer of the Original Code is: IBM Corporation
47 * Copyright: 2008 by IBM Corporation
49 * All Rights Reserved.
51 * Contributor(s): _______________________________________
54 ************************************************************************/
55 /*************************************************************************
57 * For LWP filter architecture prototype
58 ************************************************************************/
59 /*************************************************************************
62 ************************************************************************/
64 #include "lwpfribptr.hxx"
66 #include "lwpfribheader.hxx"
67 #include "lwpfribtext.hxx"
68 #include "lwppara.hxx"
69 #include "lwpstory.hxx"
70 #include "xfilter/xftextspan.hxx"
71 #include "xfilter/xftextcontent.hxx"
72 #include "xfilter/xftabstop.hxx"
73 #include "xfilter/xflinebreak.hxx"
74 #include "lwpfribsection.hxx"
75 #include "lwpsection.hxx"
76 #include "lwpfribbreaks.hxx"
77 #include "lwpfribframe.hxx"
78 #include "lwpfribtable.hxx"
79 #include "xfilter/xfstylemanager.hxx"
80 #include "lwphyperlinkmgr.hxx"
81 #include "xfilter/xfhyperlink.hxx"
82 #include "lwpfootnote.hxx"
83 #include "lwpnotes.hxx"
84 #include "lwpfribmark.hxx"
85 #include "xfilter/xfchange.hxx"
86 #include "lwpchangemgr.hxx"
87 #include "lwpglobalmgr.hxx"
90 LwpFribPtr::LwpFribPtr()
91 : m_pFribs(NULL
),m_pPara(NULL
),m_pXFPara(NULL
)
94 LwpFribPtr::~LwpFribPtr()
96 LwpFrib
* pNextFrib
= m_pFribs
;
97 LwpFrib
* pCurFrib
= m_pFribs
;
100 pNextFrib
= pCurFrib
-> GetNext();
102 pCurFrib
= pNextFrib
;
106 void LwpFribPtr::ReadPara(LwpObjectStream
* pObjStrm
)
110 sal_uInt8 FribEditor
;
113 LwpFrib
* pCurFrib
= m_pFribs
= NULL
;
118 pObjStrm
->QuickRead(&FribTag
, sizeof(FribTag
));
120 FribType
= FribTag
& ~FRIB_TAG_TYPEMASK
;
122 // Stop when we hit Elvis
123 if (FribType
== FRIB_TAG_ELVIS
)
126 // skip the editor ID
127 //pObjStrm->SeekRel(sizeof(sal_uInt8));
128 pObjStrm
->QuickRead(&FribEditor
, sizeof(FribEditor
));
129 if( FribType
!= FT_MAXIMUM
)
131 LwpFrib
* pFrib
= LwpFrib::CreateFrib( m_pPara
, pObjStrm
, FribTag
,FribEditor
);
138 pCurFrib
->SetNext(pFrib
);
140 else//frist frib in the para,add by 2/1
142 if (pFrib
->GetType() == FRIB_TAG_TEXT
)
144 LwpFribText
* pText
= static_cast<LwpFribText
*>(pFrib
);
145 if (pFrib
->GetModifiers())
146 m_pPara
->SetFirstFrib(pText
->GetText(),pText
->GetModifiers()->FontID
);
148 m_pPara
->SetFirstFrib(pText
->GetText(),0);
158 /*String LwpFribPtr::GetText()
160 LwpFrib* pFrib = m_pFribs;
164 if(pFrib->GetType() == FRIB_TAG_TEXT)
166 content+= static_cast<LwpFribText*>(pFrib)->GetText();
168 pFrib = pFrib->GetNext();
173 #include "lwpdropcapmgr.hxx"
174 void LwpFribPtr::XFConvert()
176 LwpFrib
* pFrib
= m_pFribs
;
179 sal_uInt8 nFribType
= pFrib
->GetType();
180 sal_Bool bRevisionFlag
= pFrib
->GetRevisionFlag();
181 sal_uInt8 nRevisionType
;
185 if ( nFribType
!= FRIB_TAG_TABLE
&& nFribType
!= FRIB_TAG_FIELD
186 && nFribType
!= FRIB_TAG_FRAME
)
188 nRevisionType
= pFrib
->GetRevisionType();
189 LwpGlobalMgr
* pGlobal
= LwpGlobalMgr::GetInstance();
190 LwpChangeMgr
* pChangeMgr
= pGlobal
->GetLwpChangeMgr();
191 sChangeID
= pChangeMgr
->GetChangeID(pFrib
);
192 if (sChangeID
.getLength())
194 /// if (nRevisionType == LwpFrib::REV_INSERT)
196 XFChangeStart
* pChangeStart
= new XFChangeStart
;
197 pChangeStart
->SetChangeID(sChangeID
);
198 m_pXFPara
->Add(pChangeStart
);
200 /// else if (nRevisionType == LwpFrib::REV_DELETE)
202 /// XFChange* pChange = new XFChange;
203 /// pChange->SetChangeID(sChangeID);
204 /// m_pXFPara->Add(pChange);
205 /// pFrib = pFrib->GetNext();
216 LwpFribText
* textFrib
= static_cast<LwpFribText
*>(pFrib
);
217 textFrib
->XFConvert(m_pXFPara
,m_pPara
->GetStory());
222 LwpFribTab
* tabFrib
= static_cast<LwpFribTab
*>(pFrib
);
223 if (pFrib
->m_ModFlag
)
225 XFTextSpan
*pSpan
= new XFTextSpan();
226 pSpan
->SetStyleName(tabFrib
->GetStyleName());
227 XFTabStop
*pTab
= new XFTabStop();
229 m_pXFPara
->Add(pSpan
);
233 XFTabStop
*pTab
= new XFTabStop();
234 m_pXFPara
->Add(pTab
);
238 case FRIB_TAG_SECTION
:
240 LwpFribSection
* pSectionFrib
= static_cast<LwpFribSection
*>(pFrib
);
241 pSectionFrib
->ParseSection();
245 case FRIB_TAG_PAGEBREAK
:
247 LwpFribPageBreak
* pPageBreak
= static_cast<LwpFribPageBreak
*>(pFrib
);
248 LwpPageLayout
* pLayout
= static_cast<LwpPageLayout
*>(pPageBreak
->GetLayout()->obj());
251 pPageBreak
->ParseLayout();
255 if (pPageBreak
->IsLastFrib() == sal_True
)
257 m_pXFPara
->SetStyleName( pPageBreak
->GetStyleName() );
262 XFParagraph
*pPara
= new XFParagraph();
263 pPara
->SetStyleName(pFrib
->GetStyleName());
265 m_pPara
->AddXFContent(pPara
);
270 case FRIB_TAG_COLBREAK
:
272 XFParagraph
*pPara
= new XFParagraph();
273 pPara
->SetStyleName(pFrib
->GetStyleName());
275 m_pPara
->AddXFContent(pPara
);
278 case FRIB_TAG_LINEBREAK
:
280 XFLineBreak
*pLineBreak
= new XFLineBreak();
281 m_pXFPara
->Add(pLineBreak
);
284 case FRIB_TAG_UNICODE
: //fall through
285 case FRIB_TAG_UNICODE2
: //fall through
286 case FRIB_TAG_UNICODE3
: //fall through
288 LwpFribUnicode
* unicodeFrib
= static_cast<LwpFribUnicode
*>(pFrib
);
289 unicodeFrib
->XFConvert(m_pXFPara
,m_pPara
->GetStory());
292 case FRIB_TAG_HARDSPACE
:
294 rtl::OUString
sHardSpace(sal_Unicode(0x00a0));
295 LwpHyperlinkMgr
* pHyperlink
=
296 m_pPara
->GetStory()->GetHyperlinkMgr();
297 if (pHyperlink
->GetHyperlinkFlag())
298 pFrib
->ConvertHyperLink(m_pXFPara
,pHyperlink
,sHardSpace
);
300 pFrib
->ConvertChars(m_pXFPara
,sHardSpace
);
303 case FRIB_TAG_SOFTHYPHEN
:
305 rtl::OUString
sSoftHyphen(sal_Unicode(0x00ad));
306 pFrib
->ConvertChars(m_pXFPara
,sSoftHyphen
);
311 LwpFribFrame
* frameFrib
= static_cast<LwpFribFrame
*>(pFrib
);
312 LwpObject
* pLayout
= frameFrib
->GetLayout();
313 if (pLayout
->GetTag() == VO_DROPCAPLAYOUT
)
315 m_pPara
->GetFoundry()->GetDropcapMgr()->SetXFPara(m_pXFPara
);
316 //LwpObject* pDropCap = frameFrib->GetLayout();
317 //pDropCap ->XFConvert(m_pXFPara);
319 //pLayout->XFConvert(m_pXFPara);
320 frameFrib
->XFConvert(m_pXFPara
);
323 case FRIB_TAG_CHBLOCK
:
325 LwpFribCHBlock
* chbFrib
= static_cast<LwpFribCHBlock
*>(pFrib
);
326 chbFrib
->XFConvert(m_pXFPara
,m_pPara
->GetStory());
331 LwpFribTable
* tableFrib
= static_cast<LwpFribTable
*>(pFrib
);
332 //tableFrib->XFConvert(m_pPara->GetXFContainer());
333 tableFrib
->XFConvert(m_pXFPara
);
336 case FRIB_TAG_BOOKMARK
:
338 LwpFribBookMark
* bookmarkFrib
= static_cast<LwpFribBookMark
*>(pFrib
);
339 bookmarkFrib
->XFConvert(m_pXFPara
);
342 case FRIB_TAG_FOOTNOTE
:
344 LwpFribFootnote
* pFootnoteFrib
= static_cast<LwpFribFootnote
*>(pFrib
);
345 pFootnoteFrib
->XFConvert(m_pXFPara
);
350 LwpFribField
* fieldFrib
= static_cast<LwpFribField
*>(pFrib
);
351 fieldFrib
->XFConvert(m_pXFPara
);
356 LwpFribNote
* pNoteFrib
= static_cast<LwpFribNote
*>(pFrib
);
357 pNoteFrib
->XFConvert(m_pXFPara
);
360 case FRIB_TAG_PAGENUMBER
:
362 LwpFribPageNumber
* pagenumFrib
= static_cast<LwpFribPageNumber
*>(pFrib
);
363 pagenumFrib
->XFConvert(m_pXFPara
);
366 case FRIB_TAG_DOCVAR
:
368 LwpFribDocVar
* docFrib
= static_cast<LwpFribDocVar
*>(pFrib
);
369 docFrib
->XFConvert(m_pXFPara
);
372 case FRIB_TAG_RUBYMARKER
:
374 LwpFribRubyMarker
* rubyFrib
= static_cast<LwpFribRubyMarker
*>(pFrib
);
375 rubyFrib
->XFConvert(m_pXFPara
);
378 case FRIB_TAG_RUBYFRAME
:
380 LwpFribRubyFrame
* rubyfrmeFrib
= static_cast<LwpFribRubyFrame
*>(pFrib
);
381 rubyfrmeFrib
->XFConvert(m_pXFPara
);
388 if (bRevisionFlag
)//&& pFrib->GetRevisionType() == LwpFrib::REV_INSERT)
390 if (nFribType
!= FRIB_TAG_TABLE
&& nFribType
!= FRIB_TAG_FIELD
391 && nFribType
!= FRIB_TAG_FRAME
)
393 if (sChangeID
.getLength())
395 XFChangeEnd
* pChangeEnd
= new XFChangeEnd
;
396 pChangeEnd
->SetChangeID(sChangeID
);
397 m_pXFPara
->Add(pChangeEnd
);
401 pFrib
= pFrib
->GetNext();
406 void LwpFribPtr::FindLayouts()
408 LwpFrib
* pFrib
= m_pFribs
;
411 switch(pFrib
->GetType())
413 case FRIB_TAG_SECTION
:
415 LwpFribSection
* pSectionFrib
= static_cast<LwpFribSection
*>(pFrib
);
416 LwpSection
* pSection
= pSectionFrib
->GetSection();
419 LwpPageLayout
* pLayout
= pSection
->GetPageLayout();
422 LwpLayout::UseWhenType eSectionType
= pLayout
->GetUseWhenType();
423 if(eSectionType
==LwpLayout::StartWithinColume
)
425 //StartWithinColume type not support now
428 LwpStory
* pStory
= static_cast<LwpStory
*>(m_pPara
->GetStoryID()->obj());
429 pStory
->AddPageLayout(pSection
->GetPageLayout());
435 case FRIB_TAG_PAGEBREAK
:
437 LwpFribPageBreak
* pPageBreak
= static_cast<LwpFribPageBreak
*>(pFrib
);
438 LwpPageLayout
* pLayout
= static_cast<LwpPageLayout
*>(pPageBreak
->GetLayout()->obj());
441 LwpStory
* pStory
= static_cast<LwpStory
*>(m_pPara
->GetStoryID()->obj());
442 pStory
->AddPageLayout(pLayout
);
449 pFrib
= pFrib
->GetNext();
452 /**************************************************************************
453 * @descr: Whether has a frib which type is nType
457 **************************************************************************/
458 LwpFrib
* LwpFribPtr::HasFrib(sal_uInt8 nType
)
460 LwpFrib
* pFrib
= m_pFribs
;
463 if(pFrib
->GetType()==nType
)
467 pFrib
= pFrib
->GetNext();
472 void LwpFribPtr::GatherAllText()
474 LwpFrib
* pFrib
= m_pFribs
;
477 switch(pFrib
->GetType())
481 OUString sText
= static_cast<LwpFribText
*>(pFrib
)->GetText();
482 m_pPara
->SetAllText(sText
);
485 case FRIB_TAG_UNICODE
: //fall through
486 case FRIB_TAG_UNICODE2
: //fall through
487 case FRIB_TAG_UNICODE3
: //fall through :
489 OUString sText
= static_cast<LwpFribText
*>(pFrib
)->GetText();
490 m_pPara
->SetAllText(sText
);
496 pFrib
= pFrib
->GetNext();
500 void LwpFribPtr::RegisterStyle()
502 LwpFrib
* pFrib
= m_pFribs
;
505 switch(pFrib
->GetType())
509 pFrib
->RegisterStyle(m_pPara
->GetFoundry());
510 OUString sText
= static_cast<LwpFribText
*>(pFrib
)->GetText();
511 ProcessDropcap(m_pPara
->GetStory(), pFrib
,sText
.getLength());
515 pFrib
->RegisterStyle(m_pPara
->GetFoundry());
517 case FRIB_TAG_SECTION
:
519 //section registerstyle here;
520 LwpFribSection
* pSectionFrib
= static_cast<LwpFribSection
*>(pFrib
);
521 pSectionFrib
->RegisterSectionStyle();
523 pSectionFrib
->SetSectionName();
526 case FRIB_TAG_PAGEBREAK
:
528 LwpFribPageBreak
* breakFrib
= static_cast<LwpFribPageBreak
*>(pFrib
);
529 breakFrib
->RegisterBreakStyle(m_pPara
);
532 case FRIB_TAG_COLBREAK
:
534 LwpFribColumnBreak
* breakFrib
= static_cast<LwpFribColumnBreak
*>(pFrib
);
535 breakFrib
->RegisterBreakStyle(m_pPara
);
538 case FRIB_TAG_UNICODE
: //fall through
539 case FRIB_TAG_UNICODE2
: //fall through
540 case FRIB_TAG_UNICODE3
: //fall through :
542 pFrib
->RegisterStyle(m_pPara
->GetFoundry());
543 OUString sText
= static_cast<LwpFribUnicode
*>(pFrib
)->GetText();
544 ProcessDropcap(m_pPara
->GetStory(), pFrib
,sText
.getLength());
547 case FRIB_TAG_HARDSPACE
:
548 pFrib
->RegisterStyle(m_pPara
->GetFoundry());
549 ProcessDropcap(m_pPara
->GetStory(),pFrib
,1);
551 case FRIB_TAG_SOFTHYPHEN
:
552 pFrib
->RegisterStyle(m_pPara
->GetFoundry());
556 LwpFribFrame
* frameFrib
= static_cast<LwpFribFrame
*>(pFrib
);
557 frameFrib
->SetParaDropcap(m_pPara
);
558 frameFrib
->RegisterStyle(m_pPara
->GetFoundry());
559 //register framelayout style, ,03/09/2005
560 //frameFrib->GetLayout()->RegisterStyle();
563 case FRIB_TAG_CHBLOCK
:
567 LwpFribTable
* tableFrib
= static_cast<LwpFribTable
*>(pFrib
);
568 tableFrib
->RegisterStyle();
571 case FRIB_TAG_FOOTNOTE
:
573 LwpFribFootnote
* pFribFootnote
= static_cast<LwpFribFootnote
*>(pFrib
);
574 pFribFootnote
->RegisterStyle();
579 LwpFribNote
* pNoteFrib
= static_cast<LwpFribNote
*>(pFrib
);
580 pNoteFrib
->RegisterStyle();
583 case FRIB_TAG_PAGENUMBER
:
585 pFrib
->RegisterStyle(m_pPara
->GetFoundry());
588 case FRIB_TAG_DOCVAR
:
590 LwpFribDocVar
* docFrib
= static_cast<LwpFribDocVar
*>(pFrib
);
591 docFrib
->RegisterStyle(m_pPara
->GetFoundry());
596 LwpFribField
* fieldFrib
= static_cast<LwpFribField
*>(pFrib
);
597 fieldFrib
->RegisterStyle(m_pPara
->GetFoundry());
600 case FRIB_TAG_BOOKMARK
:
602 LwpFribBookMark
* bookmarkFrib
= static_cast<LwpFribBookMark
*>(pFrib
);
603 bookmarkFrib
->RegisterStyle(m_pPara
->GetFoundry());
606 case FRIB_TAG_RUBYFRAME
:
608 LwpFribRubyFrame
* rubyfrmeFrib
= static_cast<LwpFribRubyFrame
*>(pFrib
);
609 rubyfrmeFrib
->RegisterStyle(m_pPara
->GetFoundry());
615 if (pFrib
->GetRevisionFlag() && pFrib
->GetType()!= FRIB_TAG_FIELD
)
617 LwpGlobalMgr
* pGlobal
= LwpGlobalMgr::GetInstance();
618 LwpChangeMgr
* pChangeMgr
= pGlobal
->GetLwpChangeMgr();
619 pChangeMgr
->AddChangeFrib(pFrib
);
622 pFrib
= pFrib
->GetNext();
626 void LwpFribPtr::ProcessDropcap(LwpStory
* pStory
,LwpFrib
* pFrib
,sal_uInt32 nLen
)
630 if (pStory
->GetDropcapFlag() == sal_True
)
632 XFStyleManager
* pXFStyleManager
= LwpGlobalMgr::GetInstance()->GetXFStyleManager();
633 XFTextStyle
* pFribStyle
= pXFStyleManager
->FindTextStyle(pFrib
->GetStyleName());
634 pFribStyle
->GetFont()->SetFontSize(0);
636 LwpObject
* pObj
= pStory
->GetLayoutsWithMe()->GetOnlyLayout()->obj();
638 static_cast<LwpDropcapLayout
*>(pObj
)->SetChars(nLen
);
643 * @descr: If the position of pPreLayout is earlier than pNextLayout, return true, or return false, defalut return true
646 sal_Bool
LwpFribPtr::ComparePagePosition(LwpVirtualLayout
* pPreLayout
, LwpVirtualLayout
* pNextLayout
)
648 if(!pPreLayout
|| !pNextLayout
)
651 LwpFrib
* pFrib
= m_pFribs
;
652 LwpVirtualLayout
* pLayout
= NULL
;
655 switch(pFrib
->GetType())
657 case FRIB_TAG_SECTION
:
659 LwpFribSection
* pSectionFrib
= static_cast<LwpFribSection
*>(pFrib
);
660 LwpSection
* pSection
= pSectionFrib
->GetSection();
663 pLayout
= pSection
->GetPageLayout();
668 case FRIB_TAG_PAGEBREAK
:
670 LwpFribPageBreak
* pPageBreak
= static_cast<LwpFribPageBreak
*>(pFrib
);
671 pLayout
= static_cast<LwpVirtualLayout
*>(pPageBreak
->GetLayout()->obj());
680 if(pPreLayout
== pLayout
)
682 if(pNextLayout
== pLayout
)
685 pFrib
= pFrib
->GetNext();