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 ************************************************************************/
63 #include "lwpfrib.hxx"
64 #include "lwpcharsetmgr.hxx"
65 #include "lwpsection.hxx"
66 #include "lwphyperlinkmgr.hxx"
67 #include "xfilter/xfhyperlink.hxx"
68 #include "xfilter/xfstylemanager.hxx"
69 #include "xfilter/xfsection.hxx"
70 #include "xfilter/xfsectionstyle.hxx"
71 #include "xfilter/xftextspan.hxx"
72 #include "xfilter/xftextcontent.hxx"
73 #include "lwpfribheader.hxx"
74 #include "lwpfribtext.hxx"
75 #include "lwpfribtable.hxx"
76 #include "lwpfribbreaks.hxx"
77 #include "lwpfribframe.hxx"
78 #include "lwpfribsection.hxx"
79 #include "lwpcharacterstyle.hxx"
80 #include "lwpfootnote.hxx"
81 #include "lwpnotes.hxx"
82 #include "lwpfribmark.hxx"
83 #include "lwpchangemgr.hxx"
84 #include "lwpdocdata.hxx"
85 #include "lwpglobalmgr.hxx"
87 LwpFrib::LwpFrib(LwpPara
* pPara
)
88 : m_pPara(pPara
), m_pNext(NULL
)
90 m_ModFlag
= sal_False
;
92 m_bRevisionFlag
= sal_False
;
101 LwpFrib
* LwpFrib::CreateFrib(LwpPara
* pPara
, LwpObjectStream
* pObjStrm
, sal_uInt8 fribtag
,sal_uInt8 editID
)
104 ModifierInfo
* pModInfo
= NULL
;
105 if(fribtag
& FRIB_TAG_MODIFIER
)
107 pModInfo
= new ModifierInfo();
108 pModInfo
->CodePage
= 0;
109 pModInfo
->FontID
= 0;
110 pModInfo
->RevisionFlag
= sal_False
;
111 pModInfo
->HasCharStyle
= sal_False
;
112 pModInfo
->HasLangOverride
= sal_False
;
113 pModInfo
->HasHighLight
= sal_False
;
114 ReadModifiers( pObjStrm
, pModInfo
);
118 LwpFrib
* newFrib
= NULL
;
119 sal_uInt16 friblen
= pObjStrm
->QuickReaduInt16();
120 sal_uInt8 fribtype
= fribtag
&~FRIB_TAG_TYPEMASK
;
123 case FRIB_TAG_INVALID
: //fall through
124 case FRIB_TAG_EOP
: //fall through
126 newFrib
= new LwpFrib(pPara
);
130 newFrib
= new LwpFribText (pPara
, fribtag
& FRIB_TAG_NOUNICODE
);
134 newFrib
= new LwpFribTable(pPara
);
137 newFrib
= new LwpFribTab(pPara
);
139 case FRIB_TAG_PAGEBREAK
:
140 newFrib
= new LwpFribPageBreak(pPara
);
143 newFrib
= new LwpFribFrame(pPara
);
145 case FRIB_TAG_FOOTNOTE
:
146 newFrib
= new LwpFribFootnote(pPara
);
148 case FRIB_TAG_COLBREAK
:
149 newFrib
= new LwpFribColumnBreak(pPara
);
151 case FRIB_TAG_LINEBREAK
:
152 newFrib
= new LwpFribLineBreak(pPara
);
154 case FRIB_TAG_HARDSPACE
:
155 newFrib
= new LwpFribHardSpace(pPara
);
157 case FRIB_TAG_SOFTHYPHEN
:
158 newFrib
= new LwpFribSoftHyphen(pPara
);
160 case FRIB_TAG_PARANUMBER
:
161 newFrib
= new LwpFribParaNumber(pPara
);
163 case FRIB_TAG_UNICODE
: //fall through
164 case FRIB_TAG_UNICODE2
: //fall through
165 case FRIB_TAG_UNICODE3
: //fall through
166 newFrib
= new LwpFribUnicode(pPara
);
169 newFrib
= new LwpFribNote(pPara
);
171 /* case FRIB_TAG_KANJI:
173 newFrib = new CFribHelperKanji;
175 newFrib = new CFribHelperUnicode;
178 case FRIB_TAG_HKATAKANA:
180 newFrib = new CFribHelperHKatakana;
182 newFrib = new CFribHelperUnicode;
185 case FRIB_TAG_SEPARATOR:
186 newFrib = new CFribHelperSeparator;
188 case FRIB_TAG_SECTION
:
189 newFrib
= new LwpFribSection(pPara
);
191 /* case FRIB_TAG_TOMBSTONE:
192 newFrib = new CFribHelperTombstone;
194 case FRIB_TAG_SPECIALTAB:
195 newFrib = new CFribHelperSpecialTab;
197 case FRIB_TAG_PAGENUMBER:
198 newFrib = new CFribHelperPageNumber;
200 */ case FRIB_TAG_PAGENUMBER
:
201 newFrib
= new LwpFribPageNumber(pPara
);
203 case FRIB_TAG_DOCVAR
:
204 newFrib
= new LwpFribDocVar(pPara
);
206 case FRIB_TAG_BOOKMARK
:
207 newFrib
= new LwpFribBookMark(pPara
);
209 /* case FRIB_TAG_DOCVAR:
210 newFrib = new CFribHelperBookmark;
213 newFrib = new CFribHelperDDE;
215 */ case FRIB_TAG_FIELD
:
216 newFrib
= new LwpFribField(pPara
);
218 case FRIB_TAG_CHBLOCK
:
219 newFrib
= new LwpFribCHBlock(pPara
);
221 /* case FRIB_TAG_FLOWBREAK:
222 newFrib = new CFribHelperFlowBreak;
225 case FRIB_TAG_RUBYMARKER
:
226 newFrib
= new LwpFribRubyMarker(pPara
);
228 case FRIB_TAG_RUBYFRAME
:
229 newFrib
= new LwpFribRubyFrame(pPara
);
235 //Do not know why the fribTag judgement is necessary, to be checked with
236 if ( fribtag
& FRIB_TAG_MODIFIER
)
238 newFrib
->SetModifiers(pModInfo
);
241 newFrib
->SetType(fribtype
);
242 newFrib
->SetEditor(editID
);
243 newFrib
->Read(pObjStrm
, friblen
);
247 void LwpFrib::Read(LwpObjectStream
* pObjStrm
, sal_uInt16 len
)
249 pObjStrm
->SeekRel(len
);
252 void LwpFrib::SetModifiers(ModifierInfo
* pModifiers
)
256 m_pModifiers
= pModifiers
;
257 m_ModFlag
= sal_True
;
258 if (pModifiers
->RevisionFlag
)
260 m_bRevisionFlag
= sal_True
;
261 m_nRevisionType
= pModifiers
->RevisionType
;
266 void LwpFrib::RegisterStyle(LwpFoundry
* pFoundry
)
270 if (!m_pModifiers
->FontID
&& !m_pModifiers
->HasCharStyle
&& !m_pModifiers
->HasHighLight
)
272 m_ModFlag
= sal_False
;
275 //we only read four modifiers, in these modifiers,CodePage and LangOverride are not styles,
276 //so we can only handle fontid and characstyle, if others ,we should not reg style
279 XFTextStyle
* pStyle
= NULL
;
280 m_StyleName
= A2OUSTR("");
281 XFStyleManager
* pXFStyleManager
= LwpGlobalMgr::GetInstance()->GetXFStyleManager();
282 if (m_pModifiers
->HasCharStyle
)
284 XFTextStyle
* pNamedStyle
= static_cast<XFTextStyle
*>
285 (pFoundry
->GetStyleManager()->GetStyle(m_pModifiers
->CharStyleID
));
286 if (m_pModifiers
->FontID
)
288 pStyle
= new XFTextStyle();
289 *pStyle
= *pNamedStyle
;
290 LwpCharacterStyle
* pCharStyle
= static_cast<LwpCharacterStyle
*>(m_pModifiers
->CharStyleID
.obj());
292 pStyle
->SetStyleName(A2OUSTR(""));
293 pFont
= pFoundry
->GetFontManger()->CreateOverrideFont(pCharStyle
->GetFinalFontID(),m_pModifiers
->FontID
);
294 pStyle
->SetFont(pFont
);
295 m_StyleName
= pXFStyleManager
->AddStyle(pStyle
)->GetStyleName();
298 m_StyleName
= pNamedStyle
->GetStyleName();
302 if (m_pModifiers
->FontID
)
304 pStyle
= new XFTextStyle();
305 pFont
= pFoundry
->GetFontManger()->CreateFont(m_pModifiers
->FontID
);
306 pStyle
->SetFont(pFont
);
307 m_StyleName
= pXFStyleManager
->AddStyle(pStyle
)->GetStyleName();
311 if (m_pModifiers
->HasHighLight
)
313 XFColor aColor
= GetHighLightColor();//right yellow
314 if (pStyle
)//change the style directly
315 pStyle
->GetFont()->SetBackColor(aColor
);
316 else //register a new style
318 pStyle
= new XFTextStyle();
320 if (m_StyleName
.getLength()>0)
322 XFTextStyle
* pOldStyle
= pXFStyleManager
->FindTextStyle(m_StyleName
);
323 *pStyle
= *pOldStyle
;
324 pStyle
->GetFont()->SetBackColor(aColor
);
329 pFont
->SetBackColor(aColor
);
330 pStyle
->SetFont(pFont
);
332 m_StyleName
= pXFStyleManager
->AddStyle(pStyle
)->GetStyleName();
337 void LwpFrib::ReadModifiers(LwpObjectStream
* pObjStrm
,ModifierInfo
* pModInfo
)
341 // sal_Bool ModifyFlag = sal_False;
345 // Get the modifier type
346 pObjStrm
->QuickRead(&Modifier
, sizeof(Modifier
));
348 // Stop when we hit the last modifier
349 if (Modifier
== FRIB_MTAG_NONE
)
351 // ModifyFlag = sal_True;
352 // Get the modifier length
353 pObjStrm
->QuickRead(&len
, sizeof(len
));
358 pObjStrm
->QuickRead(&pModInfo
->FontID
,len
);
360 case FRIB_MTAG_CHARSTYLE
:
361 pModInfo
->HasCharStyle
= sal_True
;
362 pModInfo
->CharStyleID
.ReadIndexed(pObjStrm
);
364 case FRIB_MTAG_LANGUAGE
:
365 pModInfo
->HasLangOverride
= sal_True
;
366 pModInfo
->Language
.Read(pObjStrm
);
368 case FRIB_MTAG_CODEPAGE
:
369 pObjStrm
->QuickRead(&pModInfo
->CodePage
,len
);
371 //add by , 02/22/2005
372 case FRIB_MTAG_ATTRIBUTE
:
373 pModInfo
->aTxtAttrOverride
.Read(pObjStrm
);
374 if (pModInfo
->aTxtAttrOverride
.IsHighLight())
375 pModInfo
->HasHighLight
= sal_True
;
378 case FRIB_MTAG_REVISION
:
379 pModInfo
->RevisionType
= pObjStrm
->QuickReaduInt8();
380 pModInfo
->RevisionFlag
= sal_True
;
383 pObjStrm
->SeekRel(len
);
386 // TODO: read the modifier data
387 // pObjStrm->SeekRel(len);
394 //void LwpFrib::Parse(IXFStream* pOutputStream)
398 * @descr: Whether there are other fribs following current frib.
399 * @return: Ture if having following fribs, or false.
401 sal_Bool
LwpFrib::HasNextFrib()
403 if (!GetNext() || GetNext()->GetType()==FRIB_TAG_EOP
)
408 void LwpFrib::ConvertChars(XFContentContainer
* pXFPara
,OUString text
)
412 OUString strStyleName
= GetStyleName();
413 XFTextSpan
*pSpan
= new XFTextSpan(text
,strStyleName
);
418 XFTextContent
*pSpan
= new XFTextContent();
419 pSpan
->SetText(text
);
424 void LwpFrib::ConvertHyperLink(XFContentContainer
* pXFPara
,LwpHyperlinkMgr
* pHyperlink
,OUString text
)
426 XFHyperlink
* pHyper
= new XFHyperlink
;
427 pHyper
->SetHRef(pHyperlink
->GetHyperlink());
428 pHyper
->SetText(text
);
429 pHyper
->SetStyleName(GetStyleName());
430 pXFPara
->Add(pHyper
);
434 * @descr: Get the current frib font style
435 * @return: XFFont pointer
437 XFFont
* LwpFrib::GetFont()
439 XFFont
* pFont
= NULL
;
440 if(m_pModifiers
&&m_pModifiers
->FontID
)
442 LwpFoundry
* pFoundry
= m_pPara
->GetFoundry();
443 pFont
= pFoundry
->GetFontManger()->CreateFont(m_pModifiers
->FontID
);
447 XFParaStyle
* pXFParaStyle
= m_pPara
->GetXFParaStyle();
448 pFont
= pXFParaStyle
->GetFont();
453 OUString
LwpFrib::GetEditor()
455 LwpGlobalMgr
* pGlobal
= LwpGlobalMgr::GetInstance();
456 return pGlobal
->GetEditorName(m_nEditor
);
459 XFColor
LwpFrib::GetHighLightColor()
461 LwpGlobalMgr
* pGlobal
= LwpGlobalMgr::GetInstance();
462 return pGlobal
->GetHighLightColor(m_nEditor
);