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 #include <osl/diagnose.h>
91 LwpFrib::LwpFrib(LwpPara
* pPara
)
98 , m_bRevisionFlag(false)
109 LwpFrib
* LwpFrib::CreateFrib(LwpPara
* pPara
, LwpObjectStream
* pObjStrm
, sal_uInt8 fribtag
,sal_uInt8 editID
)
112 ModifierInfo
* pModInfo
= NULL
;
113 if(fribtag
& FRIB_TAG_MODIFIER
)
115 pModInfo
= new ModifierInfo();
116 pModInfo
->CodePage
= 0;
117 pModInfo
->FontID
= 0;
118 pModInfo
->RevisionFlag
= false;
119 pModInfo
->HasCharStyle
= false;
120 pModInfo
->HasLangOverride
= false;
121 pModInfo
->HasHighlight
= false;
122 ReadModifiers( pObjStrm
, pModInfo
);
126 LwpFrib
* newFrib
= NULL
;
127 sal_uInt16 friblen
= pObjStrm
->QuickReaduInt16();
128 sal_uInt8 fribtype
= fribtag
&~FRIB_TAG_TYPEMASK
;
131 case FRIB_TAG_INVALID
: //fall through
132 case FRIB_TAG_EOP
: //fall through
134 newFrib
= new LwpFrib(pPara
);
138 newFrib
= new LwpFribText (pPara
, (fribtag
& FRIB_TAG_NOUNICODE
) != 0);
142 newFrib
= new LwpFribTable(pPara
);
145 newFrib
= new LwpFribTab(pPara
);
147 case FRIB_TAG_PAGEBREAK
:
148 newFrib
= new LwpFribPageBreak(pPara
);
151 newFrib
= new LwpFribFrame(pPara
);
153 case FRIB_TAG_FOOTNOTE
:
154 newFrib
= new LwpFribFootnote(pPara
);
156 case FRIB_TAG_COLBREAK
:
157 newFrib
= new LwpFribColumnBreak(pPara
);
159 case FRIB_TAG_LINEBREAK
:
160 newFrib
= new LwpFribLineBreak(pPara
);
162 case FRIB_TAG_HARDSPACE
:
163 newFrib
= new LwpFribHardSpace(pPara
);
165 case FRIB_TAG_SOFTHYPHEN
:
166 newFrib
= new LwpFribSoftHyphen(pPara
);
168 case FRIB_TAG_PARANUMBER
:
169 newFrib
= new LwpFribParaNumber(pPara
);
171 case FRIB_TAG_UNICODE
: //fall through
172 case FRIB_TAG_UNICODE2
: //fall through
173 case FRIB_TAG_UNICODE3
: //fall through
174 newFrib
= new LwpFribUnicode(pPara
);
177 newFrib
= new LwpFribNote(pPara
);
179 case FRIB_TAG_SECTION
:
180 newFrib
= new LwpFribSection(pPara
);
182 case FRIB_TAG_PAGENUMBER
:
183 newFrib
= new LwpFribPageNumber(pPara
);
185 case FRIB_TAG_DOCVAR
:
186 newFrib
= new LwpFribDocVar(pPara
);
188 case FRIB_TAG_BOOKMARK
:
189 newFrib
= new LwpFribBookMark(pPara
);
192 newFrib
= new LwpFribField(pPara
);
194 case FRIB_TAG_CHBLOCK
:
195 newFrib
= new LwpFribCHBlock(pPara
);
197 case FRIB_TAG_RUBYMARKER
:
198 newFrib
= new LwpFribRubyMarker(pPara
);
200 case FRIB_TAG_RUBYFRAME
:
201 newFrib
= new LwpFribRubyFrame(pPara
);
205 //Do not know why the fribTag judgement is necessary, to be checked with
206 if ( fribtag
& FRIB_TAG_MODIFIER
)
208 newFrib
->SetModifiers(pModInfo
);
211 newFrib
->SetType(fribtype
);
212 newFrib
->SetEditor(editID
);
213 newFrib
->Read(pObjStrm
, friblen
);
217 void LwpFrib::Read(LwpObjectStream
* pObjStrm
, sal_uInt16 len
)
219 pObjStrm
->SeekRel(len
);
222 void LwpFrib::SetModifiers(ModifierInfo
* pModifiers
)
226 m_pModifiers
= pModifiers
;
228 if (pModifiers
->RevisionFlag
)
230 m_bRevisionFlag
= true;
231 m_nRevisionType
= pModifiers
->RevisionType
;
236 void LwpFrib::RegisterStyle(LwpFoundry
* pFoundry
)
240 if (!m_pModifiers
->FontID
&& !m_pModifiers
->HasCharStyle
&& !m_pModifiers
->HasHighlight
)
245 //we only read four modifiers, in these modifiers,CodePage and LangOverride are not styles,
246 //so we can only handle fontid and characstyle, if others ,we should not reg style
248 rtl::Reference
<XFFont
> pFont
;
249 XFTextStyle
* pStyle
= NULL
;
251 XFStyleManager
* pXFStyleManager
= LwpGlobalMgr::GetInstance()->GetXFStyleManager();
252 XFTextStyle
* pNamedStyle
= nullptr;
253 if (m_pModifiers
->HasCharStyle
)
255 pNamedStyle
= static_cast<XFTextStyle
*>
256 (pFoundry
->GetStyleManager()->GetStyle(m_pModifiers
->CharStyleID
));
260 if (m_pModifiers
->FontID
)
262 pStyle
= new XFTextStyle();
263 *pStyle
= *pNamedStyle
;
264 LwpCharacterStyle
* pCharStyle
= static_cast<LwpCharacterStyle
*>(m_pModifiers
->CharStyleID
.obj().get());
266 pStyle
->SetStyleName("");
267 pFont
= pFoundry
->GetFontManger().CreateOverrideFont(pCharStyle
->GetFinalFontID(),m_pModifiers
->FontID
);
268 pStyle
->SetFont(pFont
);
269 IXFStyleRet aNewStyle
= pXFStyleManager
->AddStyle(pStyle
);
270 m_StyleName
= aNewStyle
.m_pStyle
->GetStyleName();
271 pStyle
= dynamic_cast<XFTextStyle
*>(aNewStyle
.m_pStyle
);
272 if (aNewStyle
.m_bOrigDeleted
)
276 m_StyleName
= pNamedStyle
->GetStyleName();
280 if (m_pModifiers
->FontID
)
282 pStyle
= new XFTextStyle();
283 pFont
= pFoundry
->GetFontManger().CreateFont(m_pModifiers
->FontID
);
284 pStyle
->SetFont(pFont
);
285 IXFStyleRet aNewStyle
= pXFStyleManager
->AddStyle(pStyle
);
286 m_StyleName
= aNewStyle
.m_pStyle
->GetStyleName();
287 pStyle
= dynamic_cast<XFTextStyle
*>(aNewStyle
.m_pStyle
);
288 if (aNewStyle
.m_bOrigDeleted
)
293 if (m_pModifiers
->HasHighlight
)
295 XFColor aColor
= GetHighlightColor();//right yellow
296 if (pStyle
)//change the style directly
297 pStyle
->GetFont()->SetBackColor(aColor
);
298 else //register a new style
300 pStyle
= new XFTextStyle();
302 if (!m_StyleName
.isEmpty())
304 XFTextStyle
* pOldStyle
= pXFStyleManager
->FindTextStyle(m_StyleName
);
305 *pStyle
= *pOldStyle
;
306 pStyle
->GetFont()->SetBackColor(aColor
);
311 pFont
->SetBackColor(aColor
);
312 pStyle
->SetFont(pFont
);
314 m_StyleName
= pXFStyleManager
->AddStyle(pStyle
).m_pStyle
->GetStyleName();
319 void LwpFrib::ReadModifiers(LwpObjectStream
* pObjStrm
,ModifierInfo
* pModInfo
)
325 // Get the modifier type
326 sal_uInt8 Modifier
= pObjStrm
->QuickReaduInt8(&bFailure
);
330 // Stop when we hit the last modifier
331 if (Modifier
== FRIB_MTAG_NONE
)
334 // Get the modifier length
335 sal_uInt8 len
= pObjStrm
->QuickReaduInt8(&bFailure
);
342 if (len
!= sizeof(pModInfo
->FontID
))
344 OSL_FAIL("FRIB_MTAG_FONT entry wrong size\n");
345 pObjStrm
->SeekRel(len
);
348 pModInfo
->FontID
= pObjStrm
->QuickReaduInt32();
350 case FRIB_MTAG_CHARSTYLE
:
351 pModInfo
->HasCharStyle
= true;
352 pModInfo
->CharStyleID
.ReadIndexed(pObjStrm
);
354 case FRIB_MTAG_LANGUAGE
:
355 pModInfo
->HasLangOverride
= true;
356 pModInfo
->Language
.Read(pObjStrm
);
358 case FRIB_MTAG_CODEPAGE
:
359 if (len
!= sizeof(pModInfo
->CodePage
))
361 OSL_FAIL("FRIB_MTAG_CODEPAGE entry wrong size\n");
362 pObjStrm
->SeekRel(len
);
365 pModInfo
->CodePage
= pObjStrm
->QuickReaduInt16();
367 case FRIB_MTAG_ATTRIBUTE
:
368 pModInfo
->aTxtAttrOverride
.Read(pObjStrm
);
369 if (pModInfo
->aTxtAttrOverride
.IsHighlight())
370 pModInfo
->HasHighlight
= true;
372 case FRIB_MTAG_REVISION
:
373 pModInfo
->RevisionType
= pObjStrm
->QuickReaduInt8();
374 pModInfo
->RevisionFlag
= true;
377 pObjStrm
->SeekRel(len
);
380 // TODO: read the modifier data
385 * @descr: Whether there are other fribs following current frib.
386 * @return: True if having following fribs, or false.
388 bool LwpFrib::HasNextFrib()
390 if (!GetNext() || GetNext()->GetType()==FRIB_TAG_EOP
)
395 void LwpFrib::ConvertChars(XFContentContainer
* pXFPara
,const OUString
& text
)
399 OUString strStyleName
= GetStyleName();
400 XFTextSpan
*pSpan
= new XFTextSpan(text
,strStyleName
);
405 XFTextContent
*pSpan
= new XFTextContent();
406 pSpan
->SetText(text
);
411 void LwpFrib::ConvertHyperLink(XFContentContainer
* pXFPara
,LwpHyperlinkMgr
* pHyperlink
,const OUString
& text
)
413 XFHyperlink
* pHyper
= new XFHyperlink
;
414 pHyper
->SetHRef(pHyperlink
->GetHyperlink());
415 pHyper
->SetText(text
);
416 pHyper
->SetStyleName(GetStyleName());
417 pXFPara
->Add(pHyper
);
421 * @descr: Get the current frib font style
422 * @return: XFFont pointer
424 rtl::Reference
<XFFont
> LwpFrib::GetFont()
426 rtl::Reference
<XFFont
> pFont
;
427 if(m_pModifiers
&&m_pModifiers
->FontID
)
429 LwpFoundry
* pFoundry
= m_pPara
->GetFoundry();
430 pFont
= pFoundry
->GetFontManger().CreateFont(m_pModifiers
->FontID
);
434 XFParaStyle
* pXFParaStyle
= m_pPara
->GetXFParaStyle();
435 pFont
= pXFParaStyle
->GetFont();
440 OUString
LwpFrib::GetEditor()
442 LwpGlobalMgr
* pGlobal
= LwpGlobalMgr::GetInstance();
443 return pGlobal
->GetEditorName(m_nEditor
);
446 XFColor
LwpFrib::GetHighlightColor()
448 LwpGlobalMgr
* pGlobal
= LwpGlobalMgr::GetInstance();
449 return pGlobal
->GetHighlightColor(m_nEditor
);
452 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */