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/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()
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//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
);
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 rtl::Reference
<XFChangeStart
> xChangeStart(new XFChangeStart
);
166 xChangeStart
->SetChangeID(sChangeID
);
167 m_pXFPara
->Add(xChangeStart
.get());
176 LwpFribText
* textFrib
= static_cast<LwpFribText
*>(pFrib
);
177 textFrib
->XFConvert(m_pXFPara
.get(),m_pPara
->GetStory());
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());
193 rtl::Reference
<XFTabStop
> xTab(new XFTabStop
);
194 m_pXFPara
->Add(xTab
.get());
198 case FRIB_TAG_SECTION
:
200 LwpFribSection
* pSectionFrib
= static_cast<LwpFribSection
*>(pFrib
);
201 pSectionFrib
->ParseSection();
205 case FRIB_TAG_PAGEBREAK
:
207 LwpFribPageBreak
* pPageBreak
= static_cast<LwpFribPageBreak
*>(pFrib
);
208 LwpPageLayout
* pLayout
= dynamic_cast<LwpPageLayout
*>(pPageBreak
->GetLayout().obj().get());
211 pPageBreak
->ParseLayout();
215 if (pPageBreak
->IsLastFrib())
217 m_pXFPara
->SetStyleName( pPageBreak
->GetStyleName() );
222 rtl::Reference
<XFParagraph
> xPara(new XFParagraph
);
223 xPara
->SetStyleName(pFrib
->GetStyleName());
224 SetXFPara(xPara
.get());
225 m_pPara
->AddXFContent(xPara
.get());
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());
238 case FRIB_TAG_LINEBREAK
:
240 rtl::Reference
<XFLineBreak
> xLineBreak(new XFLineBreak
);
241 m_pXFPara
->Add(xLineBreak
.get());
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());
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
);
260 pFrib
->ConvertChars(m_pXFPara
.get(), sHardSpace
);
263 case FRIB_TAG_SOFTHYPHEN
:
264 pFrib
->ConvertChars(m_pXFPara
.get(), u
"\x00ad"_ustr
);
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;
275 pMgr
->SetXFPara(m_pXFPara
.get());
277 frameFrib
->XFConvert(m_pXFPara
.get());
280 case FRIB_TAG_CHBLOCK
:
282 LwpFribCHBlock
* chbFrib
= static_cast<LwpFribCHBlock
*>(pFrib
);
283 chbFrib
->XFConvert(m_pXFPara
.get(),m_pPara
->GetStory());
288 LwpFribTable
* tableFrib
= static_cast<LwpFribTable
*>(pFrib
);
289 //tableFrib->XFConvert(m_pPara->GetXFContainer());
290 tableFrib
->XFConvert(m_pXFPara
.get());
293 case FRIB_TAG_BOOKMARK
:
295 LwpFribBookMark
* bookmarkFrib
= static_cast<LwpFribBookMark
*>(pFrib
);
296 bookmarkFrib
->XFConvert(m_pXFPara
.get());
299 case FRIB_TAG_FOOTNOTE
:
301 LwpFribFootnote
* pFootnoteFrib
= static_cast<LwpFribFootnote
*>(pFrib
);
302 pFootnoteFrib
->XFConvert(m_pXFPara
.get());
307 LwpFribField
* fieldFrib
= static_cast<LwpFribField
*>(pFrib
);
308 fieldFrib
->XFConvert(m_pXFPara
.get());
313 LwpFribNote
* pNoteFrib
= static_cast<LwpFribNote
*>(pFrib
);
314 pNoteFrib
->XFConvert(m_pXFPara
.get());
317 case FRIB_TAG_PAGENUMBER
:
319 LwpFribPageNumber
* pagenumFrib
= static_cast<LwpFribPageNumber
*>(pFrib
);
320 pagenumFrib
->XFConvert(m_pXFPara
.get());
323 case FRIB_TAG_DOCVAR
:
325 LwpFribDocVar
* docFrib
= static_cast<LwpFribDocVar
*>(pFrib
);
326 docFrib
->XFConvert(m_pXFPara
.get());
329 case FRIB_TAG_RUBYMARKER
:
331 LwpFribRubyMarker
* rubyFrib
= static_cast<LwpFribRubyMarker
*>(pFrib
);
332 rubyFrib
->XFConvert(m_pXFPara
.get());
335 case FRIB_TAG_RUBYFRAME
:
337 LwpFribRubyFrame
* rubyfrmeFrib
= static_cast<LwpFribRubyFrame
*>(pFrib
);
338 rubyfrmeFrib
->XFConvert();
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
;
371 if(pFrib
->GetType()==nType
)
375 pFrib
= pFrib
->GetNext();
380 void LwpFribPtr::GatherAllText()
382 LwpFrib
* pFrib
= m_pFribs
;
385 switch(pFrib
->GetType())
389 OUString sText
= static_cast<LwpFribText
*>(pFrib
)->GetText();
390 m_pPara
->SetAllText(sText
);
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
);
404 pFrib
= pFrib
->GetNext();
408 void LwpFribPtr::RegisterStyle()
410 LwpFrib
* pFrib
= m_pFribs
;
413 switch(pFrib
->GetType())
417 pFrib
->RegisterStyle(m_pPara
->GetFoundry());
418 OUString sText
= static_cast<LwpFribText
*>(pFrib
)->GetText();
419 ProcessDropcap(m_pPara
->GetStory(), pFrib
,sText
.getLength());
423 pFrib
->RegisterStyle(m_pPara
->GetFoundry());
425 case FRIB_TAG_SECTION
:
427 //section registerstyle here;
428 LwpFribSection
* pSectionFrib
= static_cast<LwpFribSection
*>(pFrib
);
429 pSectionFrib
->RegisterSectionStyle();
431 pSectionFrib
->SetSectionName();
434 case FRIB_TAG_PAGEBREAK
:
436 LwpFribPageBreak
* breakFrib
= static_cast<LwpFribPageBreak
*>(pFrib
);
437 breakFrib
->RegisterBreakStyle(m_pPara
);
440 case FRIB_TAG_COLBREAK
:
442 LwpFribColumnBreak
* breakFrib
= static_cast<LwpFribColumnBreak
*>(pFrib
);
443 breakFrib
->RegisterBreakStyle(m_pPara
);
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());
455 case FRIB_TAG_HARDSPACE
:
456 pFrib
->RegisterStyle(m_pPara
->GetFoundry());
457 ProcessDropcap(m_pPara
->GetStory(),pFrib
,1);
459 case FRIB_TAG_SOFTHYPHEN
:
460 pFrib
->RegisterStyle(m_pPara
->GetFoundry());
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();
471 case FRIB_TAG_CHBLOCK
:
475 LwpFribTable
* tableFrib
= static_cast<LwpFribTable
*>(pFrib
);
476 tableFrib
->RegisterNewStyle();
479 case FRIB_TAG_FOOTNOTE
:
481 LwpFribFootnote
* pFribFootnote
= static_cast<LwpFribFootnote
*>(pFrib
);
482 pFribFootnote
->RegisterNewStyle();
487 LwpFribNote
* pNoteFrib
= static_cast<LwpFribNote
*>(pFrib
);
488 pNoteFrib
->RegisterNewStyle();
491 case FRIB_TAG_PAGENUMBER
:
493 pFrib
->RegisterStyle(m_pPara
->GetFoundry());
496 case FRIB_TAG_DOCVAR
:
498 LwpFribDocVar
* docFrib
= static_cast<LwpFribDocVar
*>(pFrib
);
499 docFrib
->RegisterStyle(m_pPara
->GetFoundry());
504 LwpFribField
* fieldFrib
= static_cast<LwpFribField
*>(pFrib
);
505 fieldFrib
->RegisterStyle(m_pPara
->GetFoundry());
508 case FRIB_TAG_BOOKMARK
:
510 LwpFribBookMark
* bookmarkFrib
= static_cast<LwpFribBookMark
*>(pFrib
);
511 bookmarkFrib
->RegisterStyle(m_pPara
->GetFoundry());
514 case FRIB_TAG_RUBYFRAME
:
516 LwpFribRubyFrame
* rubyfrmeFrib
= static_cast<LwpFribRubyFrame
*>(pFrib
);
517 rubyfrmeFrib
->RegisterStyle(m_pPara
->GetFoundry());
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());
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
)
556 LwpFrib
* pFrib
= m_pFribs
;
557 LwpVirtualLayout
* pLayout
= nullptr;
560 switch(pFrib
->GetType())
562 case FRIB_TAG_SECTION
:
564 LwpFribSection
* pSectionFrib
= static_cast<LwpFribSection
*>(pFrib
);
565 LwpSection
* pSection
= pSectionFrib
->GetSection();
568 pLayout
= pSection
->GetPageLayout();
573 case FRIB_TAG_PAGEBREAK
:
575 LwpFribPageBreak
* pPageBreak
= static_cast<LwpFribPageBreak
*>(pFrib
);
576 pLayout
= dynamic_cast<LwpVirtualLayout
*>(pPageBreak
->GetLayout().obj().get());
585 if(pPreLayout
== pLayout
)
587 if(pNextLayout
== pLayout
)
590 pFrib
= pFrib
->GetNext();
596 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */