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 ************************************************************************/
60 /*************************************************************************
63 ************************************************************************/
65 #include "lwpfribptr.hxx"
67 #include "lwpfribheader.hxx"
68 #include "lwpfribtext.hxx"
69 #include "lwppara.hxx"
70 #include "lwpstory.hxx"
71 #include "xfilter/xftextspan.hxx"
72 #include "xfilter/xftextcontent.hxx"
73 #include "xfilter/xftabstop.hxx"
74 #include "xfilter/xflinebreak.hxx"
75 #include "lwpfribsection.hxx"
76 #include "lwpsection.hxx"
77 #include "lwpfribbreaks.hxx"
78 #include "lwpfribframe.hxx"
79 #include "lwpfribtable.hxx"
80 #include "xfilter/xfstylemanager.hxx"
81 #include "lwphyperlinkmgr.hxx"
82 #include "xfilter/xfhyperlink.hxx"
83 #include "lwpfootnote.hxx"
84 #include "lwpnotes.hxx"
85 #include "lwpfribmark.hxx"
86 #include "xfilter/xfchange.hxx"
87 #include "lwpchangemgr.hxx"
88 #include "lwpglobalmgr.hxx"
90 LwpFribPtr::LwpFribPtr()
91 : m_pFribs(NULL
),m_pXFPara(NULL
),m_pPara(NULL
)
95 LwpFribPtr::~LwpFribPtr()
97 LwpFrib
* pNextFrib
= m_pFribs
;
98 LwpFrib
* pCurFrib
= m_pFribs
;
101 pNextFrib
= pCurFrib
-> GetNext();
103 pCurFrib
= pNextFrib
;
107 void LwpFribPtr::ReadPara(LwpObjectStream
* pObjStrm
)
109 LwpFrib
* pCurFrib
= m_pFribs
= NULL
;
113 sal_uInt8 FribTag
= pObjStrm
->QuickReaduInt8();
115 sal_uInt8 FribType
= FribTag
& ~FRIB_TAG_TYPEMASK
;
117 // Stop when we hit Elvis
118 if (FribType
== FRIB_TAG_ELVIS
)
121 // skip the editor ID
122 //pObjStrm->SeekRel(sizeof(sal_uInt8));
123 sal_uInt8 FribEditor
= pObjStrm
->QuickReaduInt8();
124 if( FribType
!= FT_MAXIMUM
)
126 LwpFrib
* pFrib
= LwpFrib::CreateFrib( m_pPara
, pObjStrm
, FribTag
,FribEditor
);
133 pCurFrib
->SetNext(pFrib
);
135 else//frist frib in the para,add by 2/1
137 if (pFrib
->GetType() == FRIB_TAG_TEXT
)
139 LwpFribText
* pText
= static_cast<LwpFribText
*>(pFrib
);
140 if (pFrib
->GetModifiers())
141 m_pPara
->SetFirstFrib(pText
->GetText(),pText
->GetModifiers()->FontID
);
143 m_pPara
->SetFirstFrib(pText
->GetText(),0);
151 #include "lwpdropcapmgr.hxx"
152 void LwpFribPtr::XFConvert()
154 LwpFrib
* pFrib
= m_pFribs
;
157 sal_uInt8 nFribType
= pFrib
->GetType();
158 bool bRevisionFlag
= pFrib
->GetRevisionFlag();
162 if ( nFribType
!= FRIB_TAG_TABLE
&& nFribType
!= FRIB_TAG_FIELD
163 && nFribType
!= FRIB_TAG_FRAME
)
165 //sal_uInt8 nRevisionType = pFrib->GetRevisionType();
166 LwpGlobalMgr
* pGlobal
= LwpGlobalMgr::GetInstance();
167 LwpChangeMgr
* pChangeMgr
= pGlobal
->GetLwpChangeMgr();
168 sChangeID
= pChangeMgr
->GetChangeID(pFrib
);
169 if (!sChangeID
.isEmpty())
171 /// if (nRevisionType == LwpFrib::REV_INSERT)
173 XFChangeStart
* pChangeStart
= new XFChangeStart
;
174 pChangeStart
->SetChangeID(sChangeID
);
175 m_pXFPara
->Add(pChangeStart
);
177 /// else if (nRevisionType == LwpFrib::REV_DELETE)
179 /// XFChange* pChange = new XFChange;
180 /// pChange->SetChangeID(sChangeID);
181 /// m_pXFPara->Add(pChange);
182 /// pFrib = pFrib->GetNext();
193 LwpFribText
* textFrib
= static_cast<LwpFribText
*>(pFrib
);
194 textFrib
->XFConvert(m_pXFPara
,m_pPara
->GetStory());
199 LwpFribTab
* tabFrib
= static_cast<LwpFribTab
*>(pFrib
);
200 if (pFrib
->m_ModFlag
)
202 XFTextSpan
*pSpan
= new XFTextSpan();
203 pSpan
->SetStyleName(tabFrib
->GetStyleName());
204 XFTabStop
*pTab
= new XFTabStop();
206 m_pXFPara
->Add(pSpan
);
210 XFTabStop
*pTab
= new XFTabStop();
211 m_pXFPara
->Add(pTab
);
215 case FRIB_TAG_SECTION
:
217 LwpFribSection
* pSectionFrib
= static_cast<LwpFribSection
*>(pFrib
);
218 pSectionFrib
->ParseSection();
222 case FRIB_TAG_PAGEBREAK
:
224 LwpFribPageBreak
* pPageBreak
= static_cast<LwpFribPageBreak
*>(pFrib
);
225 LwpPageLayout
* pLayout
= dynamic_cast<LwpPageLayout
*>(pPageBreak
->GetLayout().obj().get());
228 pPageBreak
->ParseLayout();
232 if (pPageBreak
->IsLastFrib())
234 m_pXFPara
->SetStyleName( pPageBreak
->GetStyleName() );
239 XFParagraph
*pPara
= new XFParagraph();
240 pPara
->SetStyleName(pFrib
->GetStyleName());
242 m_pPara
->AddXFContent(pPara
);
247 case FRIB_TAG_COLBREAK
:
249 XFParagraph
*pPara
= new XFParagraph();
250 pPara
->SetStyleName(pFrib
->GetStyleName());
252 m_pPara
->AddXFContent(pPara
);
255 case FRIB_TAG_LINEBREAK
:
257 XFLineBreak
*pLineBreak
= new XFLineBreak();
258 m_pXFPara
->Add(pLineBreak
);
261 case FRIB_TAG_UNICODE
: //fall through
262 case FRIB_TAG_UNICODE2
: //fall through
263 case FRIB_TAG_UNICODE3
: //fall through
265 LwpFribUnicode
* unicodeFrib
= static_cast<LwpFribUnicode
*>(pFrib
);
266 unicodeFrib
->XFConvert(m_pXFPara
,m_pPara
->GetStory());
269 case FRIB_TAG_HARDSPACE
:
271 OUString
sHardSpace(sal_Unicode(0x00a0));
272 LwpHyperlinkMgr
* pHyperlink
=
273 m_pPara
->GetStory()->GetHyperlinkMgr();
274 if (pHyperlink
->GetHyperlinkFlag())
275 pFrib
->ConvertHyperLink(m_pXFPara
,pHyperlink
,sHardSpace
);
277 pFrib
->ConvertChars(m_pXFPara
,sHardSpace
);
280 case FRIB_TAG_SOFTHYPHEN
:
282 OUString
sSoftHyphen(sal_Unicode(0x00ad));
283 pFrib
->ConvertChars(m_pXFPara
,sSoftHyphen
);
288 LwpFribFrame
* frameFrib
= static_cast<LwpFribFrame
*>(pFrib
);
289 rtl::Reference
<LwpObject
> pLayout
= frameFrib
->GetLayout();
290 if (pLayout
.is() && pLayout
->GetTag() == VO_DROPCAPLAYOUT
)
291 m_pPara
->GetFoundry()->GetDropcapMgr()->SetXFPara(m_pXFPara
);
292 frameFrib
->XFConvert(m_pXFPara
);
295 case FRIB_TAG_CHBLOCK
:
297 LwpFribCHBlock
* chbFrib
= static_cast<LwpFribCHBlock
*>(pFrib
);
298 chbFrib
->XFConvert(m_pXFPara
,m_pPara
->GetStory());
303 LwpFribTable
* tableFrib
= static_cast<LwpFribTable
*>(pFrib
);
304 //tableFrib->XFConvert(m_pPara->GetXFContainer());
305 tableFrib
->XFConvert(m_pXFPara
);
308 case FRIB_TAG_BOOKMARK
:
310 LwpFribBookMark
* bookmarkFrib
= static_cast<LwpFribBookMark
*>(pFrib
);
311 bookmarkFrib
->XFConvert(m_pXFPara
);
314 case FRIB_TAG_FOOTNOTE
:
316 LwpFribFootnote
* pFootnoteFrib
= static_cast<LwpFribFootnote
*>(pFrib
);
317 pFootnoteFrib
->XFConvert(m_pXFPara
);
322 LwpFribField
* fieldFrib
= static_cast<LwpFribField
*>(pFrib
);
323 fieldFrib
->XFConvert(m_pXFPara
);
328 LwpFribNote
* pNoteFrib
= static_cast<LwpFribNote
*>(pFrib
);
329 pNoteFrib
->XFConvert(m_pXFPara
);
332 case FRIB_TAG_PAGENUMBER
:
334 LwpFribPageNumber
* pagenumFrib
= static_cast<LwpFribPageNumber
*>(pFrib
);
335 pagenumFrib
->XFConvert(m_pXFPara
);
338 case FRIB_TAG_DOCVAR
:
340 LwpFribDocVar
* docFrib
= static_cast<LwpFribDocVar
*>(pFrib
);
341 docFrib
->XFConvert(m_pXFPara
);
344 case FRIB_TAG_RUBYMARKER
:
346 LwpFribRubyMarker
* rubyFrib
= static_cast<LwpFribRubyMarker
*>(pFrib
);
347 rubyFrib
->XFConvert(m_pXFPara
);
350 case FRIB_TAG_RUBYFRAME
:
352 LwpFribRubyFrame
* rubyfrmeFrib
= static_cast<LwpFribRubyFrame
*>(pFrib
);
353 rubyfrmeFrib
->XFConvert(m_pXFPara
);
360 if (bRevisionFlag
)//&& pFrib->GetRevisionType() == LwpFrib::REV_INSERT)
362 if (nFribType
!= FRIB_TAG_TABLE
&& nFribType
!= FRIB_TAG_FIELD
363 && nFribType
!= FRIB_TAG_FRAME
)
365 if (!sChangeID
.isEmpty())
367 XFChangeEnd
* pChangeEnd
= new XFChangeEnd
;
368 pChangeEnd
->SetChangeID(sChangeID
);
369 m_pXFPara
->Add(pChangeEnd
);
373 pFrib
= pFrib
->GetNext();
378 void LwpFribPtr::FindLayouts()
380 LwpFrib
* pFrib
= m_pFribs
;
383 switch(pFrib
->GetType())
385 case FRIB_TAG_SECTION
:
387 LwpFribSection
* pSectionFrib
= static_cast<LwpFribSection
*>(pFrib
);
388 LwpSection
* pSection
= pSectionFrib
->GetSection();
391 LwpPageLayout
* pLayout
= pSection
->GetPageLayout();
394 LwpLayout::UseWhenType eSectionType
= pLayout
->GetUseWhenType();
395 if(eSectionType
==LwpLayout::StartWithinColume
)
397 //StartWithinColume type not support now
400 LwpStory
* pStory
= dynamic_cast<LwpStory
*>(m_pPara
->GetStoryID().obj().get());
402 pStory
->AddPageLayout(pSection
->GetPageLayout());
408 case FRIB_TAG_PAGEBREAK
:
410 LwpFribPageBreak
* pPageBreak
= static_cast<LwpFribPageBreak
*>(pFrib
);
411 LwpPageLayout
* pLayout
= dynamic_cast<LwpPageLayout
*>(pPageBreak
->GetLayout().obj().get());
414 LwpStory
* pStory
= dynamic_cast<LwpStory
*>(m_pPara
->GetStoryID().obj().get());
416 pStory
->AddPageLayout(pLayout
);
423 pFrib
= pFrib
->GetNext();
426 /**************************************************************************
427 * @descr: Whether has a frib which type is nType
431 **************************************************************************/
432 LwpFrib
* LwpFribPtr::HasFrib(sal_uInt8 nType
)
434 LwpFrib
* pFrib
= m_pFribs
;
437 if(pFrib
->GetType()==nType
)
441 pFrib
= pFrib
->GetNext();
446 void LwpFribPtr::GatherAllText()
448 LwpFrib
* pFrib
= m_pFribs
;
451 switch(pFrib
->GetType())
455 OUString sText
= static_cast<LwpFribText
*>(pFrib
)->GetText();
456 m_pPara
->SetAllText(sText
);
459 case FRIB_TAG_UNICODE
: //fall through
460 case FRIB_TAG_UNICODE2
: //fall through
461 case FRIB_TAG_UNICODE3
: //fall through :
463 OUString sText
= static_cast<LwpFribText
*>(pFrib
)->GetText();
464 m_pPara
->SetAllText(sText
);
470 pFrib
= pFrib
->GetNext();
474 void LwpFribPtr::RegisterStyle()
476 LwpFrib
* pFrib
= m_pFribs
;
479 switch(pFrib
->GetType())
483 pFrib
->RegisterStyle(m_pPara
->GetFoundry());
484 OUString sText
= static_cast<LwpFribText
*>(pFrib
)->GetText();
485 ProcessDropcap(m_pPara
->GetStory(), pFrib
,sText
.getLength());
489 pFrib
->RegisterStyle(m_pPara
->GetFoundry());
491 case FRIB_TAG_SECTION
:
493 //section registerstyle here;
494 LwpFribSection
* pSectionFrib
= static_cast<LwpFribSection
*>(pFrib
);
495 pSectionFrib
->RegisterSectionStyle();
497 pSectionFrib
->SetSectionName();
500 case FRIB_TAG_PAGEBREAK
:
502 LwpFribPageBreak
* breakFrib
= static_cast<LwpFribPageBreak
*>(pFrib
);
503 breakFrib
->RegisterBreakStyle(m_pPara
);
506 case FRIB_TAG_COLBREAK
:
508 LwpFribColumnBreak
* breakFrib
= static_cast<LwpFribColumnBreak
*>(pFrib
);
509 breakFrib
->RegisterBreakStyle(m_pPara
);
512 case FRIB_TAG_UNICODE
: //fall through
513 case FRIB_TAG_UNICODE2
: //fall through
514 case FRIB_TAG_UNICODE3
: //fall through :
516 pFrib
->RegisterStyle(m_pPara
->GetFoundry());
517 OUString sText
= static_cast<LwpFribUnicode
*>(pFrib
)->GetText();
518 ProcessDropcap(m_pPara
->GetStory(), pFrib
,sText
.getLength());
521 case FRIB_TAG_HARDSPACE
:
522 pFrib
->RegisterStyle(m_pPara
->GetFoundry());
523 ProcessDropcap(m_pPara
->GetStory(),pFrib
,1);
525 case FRIB_TAG_SOFTHYPHEN
:
526 pFrib
->RegisterStyle(m_pPara
->GetFoundry());
530 LwpFribFrame
* frameFrib
= static_cast<LwpFribFrame
*>(pFrib
);
531 frameFrib
->SetParaDropcap(m_pPara
);
532 frameFrib
->RegisterStyle(m_pPara
->GetFoundry());
533 //register framelayout style, ,03/09/2005
534 //frameFrib->GetLayout()->RegisterStyle();
537 case FRIB_TAG_CHBLOCK
:
541 LwpFribTable
* tableFrib
= static_cast<LwpFribTable
*>(pFrib
);
542 tableFrib
->RegisterNewStyle();
545 case FRIB_TAG_FOOTNOTE
:
547 LwpFribFootnote
* pFribFootnote
= static_cast<LwpFribFootnote
*>(pFrib
);
548 pFribFootnote
->RegisterNewStyle();
553 LwpFribNote
* pNoteFrib
= static_cast<LwpFribNote
*>(pFrib
);
554 pNoteFrib
->RegisterNewStyle();
557 case FRIB_TAG_PAGENUMBER
:
559 pFrib
->RegisterStyle(m_pPara
->GetFoundry());
562 case FRIB_TAG_DOCVAR
:
564 LwpFribDocVar
* docFrib
= static_cast<LwpFribDocVar
*>(pFrib
);
565 docFrib
->RegisterStyle(m_pPara
->GetFoundry());
570 LwpFribField
* fieldFrib
= static_cast<LwpFribField
*>(pFrib
);
571 fieldFrib
->RegisterStyle(m_pPara
->GetFoundry());
574 case FRIB_TAG_BOOKMARK
:
576 LwpFribBookMark
* bookmarkFrib
= static_cast<LwpFribBookMark
*>(pFrib
);
577 bookmarkFrib
->RegisterStyle(m_pPara
->GetFoundry());
580 case FRIB_TAG_RUBYFRAME
:
582 LwpFribRubyFrame
* rubyfrmeFrib
= static_cast<LwpFribRubyFrame
*>(pFrib
);
583 rubyfrmeFrib
->RegisterStyle(m_pPara
->GetFoundry());
589 if (pFrib
->GetRevisionFlag() && pFrib
->GetType()!= FRIB_TAG_FIELD
)
591 LwpGlobalMgr
* pGlobal
= LwpGlobalMgr::GetInstance();
592 LwpChangeMgr
* pChangeMgr
= pGlobal
->GetLwpChangeMgr();
593 pChangeMgr
->AddChangeFrib(pFrib
);
596 pFrib
= pFrib
->GetNext();
600 void LwpFribPtr::ProcessDropcap(LwpStory
* pStory
,LwpFrib
* pFrib
,sal_uInt32 nLen
)
604 if (pStory
->GetDropcapFlag())
606 XFStyleManager
* pXFStyleManager
= LwpGlobalMgr::GetInstance()->GetXFStyleManager();
607 XFTextStyle
* pFribStyle
= pXFStyleManager
->FindTextStyle(pFrib
->GetStyleName());
608 pFribStyle
->GetFont()->SetFontSize(0);
610 LwpDropcapLayout
* pObj
= dynamic_cast<LwpDropcapLayout
*>(pStory
->GetLayoutsWithMe().GetOnlyLayout().obj().get());
612 pObj
->SetChars(nLen
);
617 * @descr: If the position of pPreLayout is earlier than pNextLayout, return true, or return false, defalut return true
620 bool LwpFribPtr::ComparePagePosition(LwpVirtualLayout
* pPreLayout
, LwpVirtualLayout
* pNextLayout
)
622 if(!pPreLayout
|| !pNextLayout
)
625 LwpFrib
* pFrib
= m_pFribs
;
626 LwpVirtualLayout
* pLayout
= NULL
;
629 switch(pFrib
->GetType())
631 case FRIB_TAG_SECTION
:
633 LwpFribSection
* pSectionFrib
= static_cast<LwpFribSection
*>(pFrib
);
634 LwpSection
* pSection
= pSectionFrib
->GetSection();
637 pLayout
= pSection
->GetPageLayout();
642 case FRIB_TAG_PAGEBREAK
:
644 LwpFribPageBreak
* pPageBreak
= static_cast<LwpFribPageBreak
*>(pFrib
);
645 pLayout
= dynamic_cast<LwpVirtualLayout
*>(pPageBreak
->GetLayout().obj().get());
654 if(pPreLayout
== pLayout
)
656 if(pNextLayout
== pLayout
)
659 pFrib
= pFrib
->GetNext();
665 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */