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 ************************************************************************/
64 #include "lwpfrib.hxx"
65 #include "lwpcharsetmgr.hxx"
66 #include "lwpsection.hxx"
67 #include "lwphyperlinkmgr.hxx"
68 #include "xfilter/xfhyperlink.hxx"
69 #include "xfilter/xfstylemanager.hxx"
70 #include "xfilter/xfsection.hxx"
71 #include "xfilter/xfsectionstyle.hxx"
72 #include "xfilter/xftextspan.hxx"
73 #include "xfilter/xftextcontent.hxx"
74 #include "lwpfribheader.hxx"
75 #include "lwpfribtext.hxx"
76 #include "lwpfribtable.hxx"
77 #include "lwpfribbreaks.hxx"
78 #include "lwpfribframe.hxx"
79 #include "lwpfribsection.hxx"
80 #include "lwpcharacterstyle.hxx"
81 #include "lwpfootnote.hxx"
82 #include "lwpnotes.hxx"
83 #include "lwpfribmark.hxx"
84 #include "lwpchangemgr.hxx"
85 #include "lwpdocdata.hxx"
86 #include "lwpglobalmgr.hxx"
88 LwpFrib::LwpFrib(LwpPara
* pPara
)
89 : m_pPara(pPara
), m_pNext(NULL
)
91 m_ModFlag
= sal_False
;
93 m_bRevisionFlag
= sal_False
;
102 LwpFrib
* LwpFrib::CreateFrib(LwpPara
* pPara
, LwpObjectStream
* pObjStrm
, sal_uInt8 fribtag
,sal_uInt8 editID
)
105 ModifierInfo
* pModInfo
= NULL
;
106 if(fribtag
& FRIB_TAG_MODIFIER
)
108 pModInfo
= new ModifierInfo();
109 pModInfo
->CodePage
= 0;
110 pModInfo
->FontID
= 0;
111 pModInfo
->RevisionFlag
= sal_False
;
112 pModInfo
->HasCharStyle
= sal_False
;
113 pModInfo
->HasLangOverride
= sal_False
;
114 pModInfo
->HasHighLight
= sal_False
;
115 ReadModifiers( pObjStrm
, pModInfo
);
119 LwpFrib
* newFrib
= NULL
;
120 sal_uInt16 friblen
= pObjStrm
->QuickReaduInt16();
121 sal_uInt8 fribtype
= fribtag
&~FRIB_TAG_TYPEMASK
;
124 case FRIB_TAG_INVALID
: //fall through
125 case FRIB_TAG_EOP
: //fall through
127 newFrib
= new LwpFrib(pPara
);
131 newFrib
= new LwpFribText (pPara
, fribtag
& FRIB_TAG_NOUNICODE
);
135 newFrib
= new LwpFribTable(pPara
);
138 newFrib
= new LwpFribTab(pPara
);
140 case FRIB_TAG_PAGEBREAK
:
141 newFrib
= new LwpFribPageBreak(pPara
);
144 newFrib
= new LwpFribFrame(pPara
);
146 case FRIB_TAG_FOOTNOTE
:
147 newFrib
= new LwpFribFootnote(pPara
);
149 case FRIB_TAG_COLBREAK
:
150 newFrib
= new LwpFribColumnBreak(pPara
);
152 case FRIB_TAG_LINEBREAK
:
153 newFrib
= new LwpFribLineBreak(pPara
);
155 case FRIB_TAG_HARDSPACE
:
156 newFrib
= new LwpFribHardSpace(pPara
);
158 case FRIB_TAG_SOFTHYPHEN
:
159 newFrib
= new LwpFribSoftHyphen(pPara
);
161 case FRIB_TAG_PARANUMBER
:
162 newFrib
= new LwpFribParaNumber(pPara
);
164 case FRIB_TAG_UNICODE
: //fall through
165 case FRIB_TAG_UNICODE2
: //fall through
166 case FRIB_TAG_UNICODE3
: //fall through
167 newFrib
= new LwpFribUnicode(pPara
);
170 newFrib
= new LwpFribNote(pPara
);
172 case FRIB_TAG_SECTION
:
173 newFrib
= new LwpFribSection(pPara
);
175 case FRIB_TAG_PAGENUMBER
:
176 newFrib
= new LwpFribPageNumber(pPara
);
178 case FRIB_TAG_DOCVAR
:
179 newFrib
= new LwpFribDocVar(pPara
);
181 case FRIB_TAG_BOOKMARK
:
182 newFrib
= new LwpFribBookMark(pPara
);
185 newFrib
= new LwpFribField(pPara
);
187 case FRIB_TAG_CHBLOCK
:
188 newFrib
= new LwpFribCHBlock(pPara
);
190 case FRIB_TAG_RUBYMARKER
:
191 newFrib
= new LwpFribRubyMarker(pPara
);
193 case FRIB_TAG_RUBYFRAME
:
194 newFrib
= new LwpFribRubyFrame(pPara
);
198 //Do not know why the fribTag judgement is necessary, to be checked with
199 if ( fribtag
& FRIB_TAG_MODIFIER
)
201 newFrib
->SetModifiers(pModInfo
);
204 newFrib
->SetType(fribtype
);
205 newFrib
->SetEditor(editID
);
206 newFrib
->Read(pObjStrm
, friblen
);
210 void LwpFrib::Read(LwpObjectStream
* pObjStrm
, sal_uInt16 len
)
212 pObjStrm
->SeekRel(len
);
215 void LwpFrib::SetModifiers(ModifierInfo
* pModifiers
)
219 m_pModifiers
= pModifiers
;
220 m_ModFlag
= sal_True
;
221 if (pModifiers
->RevisionFlag
)
223 m_bRevisionFlag
= sal_True
;
224 m_nRevisionType
= pModifiers
->RevisionType
;
229 void LwpFrib::RegisterStyle(LwpFoundry
* pFoundry
)
233 if (!m_pModifiers
->FontID
&& !m_pModifiers
->HasCharStyle
&& !m_pModifiers
->HasHighLight
)
235 m_ModFlag
= sal_False
;
238 //we only read four modifiers, in these modifiers,CodePage and LangOverride are not styles,
239 //so we can only handle fontid and characstyle, if others ,we should not reg style
242 XFTextStyle
* pStyle
= NULL
;
243 m_StyleName
= A2OUSTR("");
244 XFStyleManager
* pXFStyleManager
= LwpGlobalMgr::GetInstance()->GetXFStyleManager();
245 if (m_pModifiers
->HasCharStyle
)
247 XFTextStyle
* pNamedStyle
= static_cast<XFTextStyle
*>
248 (pFoundry
->GetStyleManager()->GetStyle(m_pModifiers
->CharStyleID
));
249 if (m_pModifiers
->FontID
)
251 pStyle
= new XFTextStyle();
252 *pStyle
= *pNamedStyle
;
253 LwpCharacterStyle
* pCharStyle
= static_cast<LwpCharacterStyle
*>(m_pModifiers
->CharStyleID
.obj());
255 pStyle
->SetStyleName(A2OUSTR(""));
256 pFont
= pFoundry
->GetFontManger()->CreateOverrideFont(pCharStyle
->GetFinalFontID(),m_pModifiers
->FontID
);
257 pStyle
->SetFont(pFont
);
258 m_StyleName
= pXFStyleManager
->AddStyle(pStyle
)->GetStyleName();
261 m_StyleName
= pNamedStyle
->GetStyleName();
265 if (m_pModifiers
->FontID
)
267 pStyle
= new XFTextStyle();
268 pFont
= pFoundry
->GetFontManger()->CreateFont(m_pModifiers
->FontID
);
269 pStyle
->SetFont(pFont
);
270 m_StyleName
= pXFStyleManager
->AddStyle(pStyle
)->GetStyleName();
274 if (m_pModifiers
->HasHighLight
)
276 XFColor aColor
= GetHighLightColor();//right yellow
277 if (pStyle
)//change the style directly
278 pStyle
->GetFont()->SetBackColor(aColor
);
279 else //register a new style
281 pStyle
= new XFTextStyle();
283 if (!m_StyleName
.isEmpty())
285 XFTextStyle
* pOldStyle
= pXFStyleManager
->FindTextStyle(m_StyleName
);
286 *pStyle
= *pOldStyle
;
287 pStyle
->GetFont()->SetBackColor(aColor
);
292 pFont
->SetBackColor(aColor
);
293 pStyle
->SetFont(pFont
);
295 m_StyleName
= pXFStyleManager
->AddStyle(pStyle
)->GetStyleName();
300 void LwpFrib::ReadModifiers(LwpObjectStream
* pObjStrm
,ModifierInfo
* pModInfo
)
306 // Get the modifier type
307 sal_uInt8 Modifier
= pObjStrm
->QuickReaduInt8(&bFailure
);
311 // Stop when we hit the last modifier
312 if (Modifier
== FRIB_MTAG_NONE
)
315 // Get the modifier length
316 sal_uInt8 len
= pObjStrm
->QuickReaduInt8(&bFailure
);
323 if (len
!= sizeof(pModInfo
->FontID
))
325 OSL_FAIL("FRIB_MTAG_FONT entry wrong size\n");
326 pObjStrm
->SeekRel(len
);
329 pModInfo
->FontID
= pObjStrm
->QuickReaduInt32();
331 case FRIB_MTAG_CHARSTYLE
:
332 pModInfo
->HasCharStyle
= sal_True
;
333 pModInfo
->CharStyleID
.ReadIndexed(pObjStrm
);
335 case FRIB_MTAG_LANGUAGE
:
336 pModInfo
->HasLangOverride
= sal_True
;
337 pModInfo
->Language
.Read(pObjStrm
);
339 case FRIB_MTAG_CODEPAGE
:
340 if (len
!= sizeof(pModInfo
->CodePage
))
342 OSL_FAIL("FRIB_MTAG_CODEPAGE entry wrong size\n");
343 pObjStrm
->SeekRel(len
);
346 pModInfo
->CodePage
= pObjStrm
->QuickReaduInt16();
348 case FRIB_MTAG_ATTRIBUTE
:
349 pModInfo
->aTxtAttrOverride
.Read(pObjStrm
);
350 if (pModInfo
->aTxtAttrOverride
.IsHighLight())
351 pModInfo
->HasHighLight
= sal_True
;
353 case FRIB_MTAG_REVISION
:
354 pModInfo
->RevisionType
= pObjStrm
->QuickReaduInt8();
355 pModInfo
->RevisionFlag
= sal_True
;
358 pObjStrm
->SeekRel(len
);
361 // TODO: read the modifier data
366 * @descr: Whether there are other fribs following current frib.
367 * @return: Ture if having following fribs, or false.
369 sal_Bool
LwpFrib::HasNextFrib()
371 if (!GetNext() || GetNext()->GetType()==FRIB_TAG_EOP
)
376 void LwpFrib::ConvertChars(XFContentContainer
* pXFPara
,OUString text
)
380 OUString strStyleName
= GetStyleName();
381 XFTextSpan
*pSpan
= new XFTextSpan(text
,strStyleName
);
386 XFTextContent
*pSpan
= new XFTextContent();
387 pSpan
->SetText(text
);
392 void LwpFrib::ConvertHyperLink(XFContentContainer
* pXFPara
,LwpHyperlinkMgr
* pHyperlink
,OUString text
)
394 XFHyperlink
* pHyper
= new XFHyperlink
;
395 pHyper
->SetHRef(pHyperlink
->GetHyperlink());
396 pHyper
->SetText(text
);
397 pHyper
->SetStyleName(GetStyleName());
398 pXFPara
->Add(pHyper
);
402 * @descr: Get the current frib font style
403 * @return: XFFont pointer
405 XFFont
* LwpFrib::GetFont()
407 XFFont
* pFont
= NULL
;
408 if(m_pModifiers
&&m_pModifiers
->FontID
)
410 LwpFoundry
* pFoundry
= m_pPara
->GetFoundry();
411 pFont
= pFoundry
->GetFontManger()->CreateFont(m_pModifiers
->FontID
);
415 XFParaStyle
* pXFParaStyle
= m_pPara
->GetXFParaStyle();
416 pFont
= pXFParaStyle
->GetFont();
421 OUString
LwpFrib::GetEditor()
423 LwpGlobalMgr
* pGlobal
= LwpGlobalMgr::GetInstance();
424 return pGlobal
->GetEditorName(m_nEditor
);
427 XFColor
LwpFrib::GetHighLightColor()
429 LwpGlobalMgr
* pGlobal
= LwpGlobalMgr::GetInstance();
430 return pGlobal
->GetHighLightColor(m_nEditor
);
433 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */