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 "lwpfrib.hxx"
62 #include "lwpcharsetmgr.hxx"
63 #include "lwpsection.hxx"
64 #include "lwphyperlinkmgr.hxx"
65 #include "xfilter/xfhyperlink.hxx"
66 #include "xfilter/xfstylemanager.hxx"
67 #include "xfilter/xfsection.hxx"
68 #include "xfilter/xfsectionstyle.hxx"
69 #include "xfilter/xftextspan.hxx"
70 #include "xfilter/xftextcontent.hxx"
71 #include "lwpfribheader.hxx"
72 #include "lwpfribtext.hxx"
73 #include "lwpfribtable.hxx"
74 #include "lwpfribbreaks.hxx"
75 #include "lwpfribframe.hxx"
76 #include "lwpfribsection.hxx"
77 #include "lwpcharacterstyle.hxx"
78 #include "lwpfootnote.hxx"
79 #include "lwpnotes.hxx"
80 #include "lwpfribmark.hxx"
81 #include "lwpchangemgr.hxx"
82 #include "lwpdocdata.hxx"
83 #include "lwpglobalmgr.hxx"
85 #include <osl/diagnose.h>
88 LwpFrib::LwpFrib(LwpPara
* pPara
)
93 , m_pModifiers(nullptr)
96 , m_bRevisionFlag(false)
106 LwpFrib
* LwpFrib::CreateFrib(LwpPara
* pPara
, LwpObjectStream
* pObjStrm
, sal_uInt8 fribtag
,sal_uInt8 editID
)
109 ModifierInfo
* pModInfo
= nullptr;
110 if(fribtag
& FRIB_TAG_MODIFIER
)
112 pModInfo
= new ModifierInfo();
113 pModInfo
->CodePage
= 0;
114 pModInfo
->FontID
= 0;
115 pModInfo
->RevisionFlag
= false;
116 pModInfo
->HasCharStyle
= false;
117 pModInfo
->HasLangOverride
= false;
118 pModInfo
->HasHighlight
= false;
119 ReadModifiers( pObjStrm
, pModInfo
);
123 LwpFrib
* newFrib
= nullptr;
124 sal_uInt16 friblen
= pObjStrm
->QuickReaduInt16();
125 sal_uInt8 fribtype
= fribtag
&~FRIB_TAG_TYPEMASK
;
128 case FRIB_TAG_INVALID
: //fall through
129 case FRIB_TAG_EOP
: //fall through
131 newFrib
= new LwpFrib(pPara
);
135 newFrib
= new LwpFribText (pPara
, (fribtag
& FRIB_TAG_NOUNICODE
) != 0);
139 newFrib
= new LwpFribTable(pPara
);
142 newFrib
= new LwpFribTab(pPara
);
144 case FRIB_TAG_PAGEBREAK
:
145 newFrib
= new LwpFribPageBreak(pPara
);
148 newFrib
= new LwpFribFrame(pPara
);
150 case FRIB_TAG_FOOTNOTE
:
151 newFrib
= new LwpFribFootnote(pPara
);
153 case FRIB_TAG_COLBREAK
:
154 newFrib
= new LwpFribColumnBreak(pPara
);
156 case FRIB_TAG_LINEBREAK
:
157 newFrib
= new LwpFribLineBreak(pPara
);
159 case FRIB_TAG_HARDSPACE
:
160 newFrib
= new LwpFribHardSpace(pPara
);
162 case FRIB_TAG_SOFTHYPHEN
:
163 newFrib
= new LwpFribSoftHyphen(pPara
);
165 case FRIB_TAG_PARANUMBER
:
166 newFrib
= new LwpFribParaNumber(pPara
);
168 case FRIB_TAG_UNICODE
: //fall through
169 case FRIB_TAG_UNICODE2
: //fall through
170 case FRIB_TAG_UNICODE3
: //fall through
171 newFrib
= new LwpFribUnicode(pPara
);
174 newFrib
= new LwpFribNote(pPara
);
176 case FRIB_TAG_SECTION
:
177 newFrib
= new LwpFribSection(pPara
);
179 case FRIB_TAG_PAGENUMBER
:
180 newFrib
= new LwpFribPageNumber(pPara
);
182 case FRIB_TAG_DOCVAR
:
183 newFrib
= new LwpFribDocVar(pPara
);
185 case FRIB_TAG_BOOKMARK
:
186 newFrib
= new LwpFribBookMark(pPara
);
189 newFrib
= new LwpFribField(pPara
);
191 case FRIB_TAG_CHBLOCK
:
192 newFrib
= new LwpFribCHBlock(pPara
);
194 case FRIB_TAG_RUBYMARKER
:
195 newFrib
= new LwpFribRubyMarker(pPara
);
197 case FRIB_TAG_RUBYFRAME
:
198 newFrib
= new LwpFribRubyFrame(pPara
);
202 //Do not know why the fribTag judgement is necessary, to be checked with
203 if ( fribtag
& FRIB_TAG_MODIFIER
)
205 newFrib
->SetModifiers(pModInfo
);
208 newFrib
->m_nFribType
= fribtype
;
209 newFrib
->m_nEditor
= editID
;
210 newFrib
->Read(pObjStrm
, friblen
);
214 void LwpFrib::Read(LwpObjectStream
* pObjStrm
, sal_uInt16 len
)
216 pObjStrm
->SeekRel(len
);
219 void LwpFrib::SetModifiers(ModifierInfo
* pModifiers
)
223 m_pModifiers
.reset( pModifiers
);
225 if (pModifiers
->RevisionFlag
)
227 m_bRevisionFlag
= true;
228 m_nRevisionType
= pModifiers
->RevisionType
;
233 void LwpFrib::RegisterStyle(LwpFoundry
* pFoundry
)
237 if (!m_pModifiers
->FontID
&& !m_pModifiers
->HasCharStyle
&& !m_pModifiers
->HasHighlight
)
242 //we only read four modifiers, in these modifiers,CodePage and LangOverride are not styles,
243 //so we can only handle fontid and charstyle, if others, we should not reg style
245 rtl::Reference
<XFFont
> pFont
;
246 XFTextStyle
* pStyle
= nullptr;
248 XFStyleManager
* pXFStyleManager
= LwpGlobalMgr::GetInstance()->GetXFStyleManager();
249 XFTextStyle
* pNamedStyle
= nullptr;
250 if (m_pModifiers
->HasCharStyle
&& pFoundry
)
252 pNamedStyle
= dynamic_cast<XFTextStyle
*>
253 (pFoundry
->GetStyleManager()->GetStyle(m_pModifiers
->CharStyleID
));
257 LwpCharacterStyle
* pCharStyle
= nullptr;
258 if (m_pModifiers
->FontID
&& pFoundry
)
259 pCharStyle
= dynamic_cast<LwpCharacterStyle
*>(m_pModifiers
->CharStyleID
.obj().get());
262 pStyle
= new XFTextStyle();
263 *pStyle
= *pNamedStyle
;
265 pStyle
->SetStyleName("");
266 pFont
= pFoundry
->GetFontManger().CreateOverrideFont(pCharStyle
->GetFinalFontID(),m_pModifiers
->FontID
);
267 pStyle
->SetFont(pFont
);
268 IXFStyleRet aNewStyle
= pXFStyleManager
->AddStyle(pStyle
);
269 m_StyleName
= aNewStyle
.m_pStyle
->GetStyleName();
270 pStyle
= dynamic_cast<XFTextStyle
*>(aNewStyle
.m_pStyle
);
271 if (aNewStyle
.m_bOrigDeleted
)
275 m_StyleName
= pNamedStyle
->GetStyleName();
279 if (m_pModifiers
->FontID
&& pFoundry
)
281 pStyle
= new XFTextStyle();
282 pFont
= pFoundry
->GetFontManger().CreateFont(m_pModifiers
->FontID
);
283 pStyle
->SetFont(pFont
);
284 IXFStyleRet aNewStyle
= pXFStyleManager
->AddStyle(pStyle
);
285 m_StyleName
= aNewStyle
.m_pStyle
->GetStyleName();
286 pStyle
= dynamic_cast<XFTextStyle
*>(aNewStyle
.m_pStyle
);
287 if (aNewStyle
.m_bOrigDeleted
)
292 if (m_pModifiers
->HasHighlight
)
294 XFColor aColor
= GetHighlightColor();//right yellow
295 if (pStyle
)//change the style directly
296 pStyle
->GetFont()->SetBackColor(aColor
);
297 else //register a new style
299 pStyle
= new XFTextStyle();
301 if (!m_StyleName
.isEmpty())
303 XFTextStyle
* pOldStyle
= pXFStyleManager
->FindTextStyle(m_StyleName
);
304 *pStyle
= *pOldStyle
;
305 pStyle
->GetFont()->SetBackColor(aColor
);
310 pFont
->SetBackColor(aColor
);
311 pStyle
->SetFont(pFont
);
313 m_StyleName
= pXFStyleManager
->AddStyle(pStyle
).m_pStyle
->GetStyleName();
318 void LwpFrib::ReadModifiers(LwpObjectStream
* pObjStrm
,ModifierInfo
* pModInfo
)
324 // Get the modifier type
325 sal_uInt8 Modifier
= pObjStrm
->QuickReaduInt8(&bFailure
);
329 // Stop when we hit the last modifier
330 if (Modifier
== FRIB_MTAG_NONE
)
333 // Get the modifier length
334 sal_uInt8 len
= pObjStrm
->QuickReaduInt8(&bFailure
);
341 if (len
!= sizeof(pModInfo
->FontID
))
343 OSL_FAIL("FRIB_MTAG_FONT entry wrong size\n");
344 pObjStrm
->SeekRel(len
);
347 pModInfo
->FontID
= pObjStrm
->QuickReaduInt32();
349 case FRIB_MTAG_CHARSTYLE
:
350 pModInfo
->HasCharStyle
= true;
351 pModInfo
->CharStyleID
.ReadIndexed(pObjStrm
);
353 case FRIB_MTAG_LANGUAGE
:
354 pModInfo
->HasLangOverride
= true;
355 pModInfo
->Language
.Read(pObjStrm
);
357 case FRIB_MTAG_CODEPAGE
:
358 if (len
!= sizeof(pModInfo
->CodePage
))
360 OSL_FAIL("FRIB_MTAG_CODEPAGE entry wrong size\n");
361 pObjStrm
->SeekRel(len
);
364 pModInfo
->CodePage
= pObjStrm
->QuickReaduInt16();
366 case FRIB_MTAG_ATTRIBUTE
:
367 pModInfo
->aTxtAttrOverride
.Read(pObjStrm
);
368 if (pModInfo
->aTxtAttrOverride
.IsHighlight())
369 pModInfo
->HasHighlight
= true;
371 case FRIB_MTAG_REVISION
:
372 pModInfo
->RevisionType
= pObjStrm
->QuickReaduInt8();
373 pModInfo
->RevisionFlag
= true;
376 pObjStrm
->SeekRel(len
);
379 // TODO: read the modifier data
384 * @descr: Whether there are other fribs following current frib.
385 * @return: True if having following fribs, or false.
387 bool LwpFrib::HasNextFrib()
389 if (!GetNext() || GetNext()->GetType()==FRIB_TAG_EOP
)
394 void LwpFrib::ConvertChars(XFContentContainer
* pXFPara
,const OUString
& text
)
398 OUString strStyleName
= GetStyleName();
399 XFTextSpan
*pSpan
= new XFTextSpan(text
,strStyleName
);
404 XFTextContent
*pSpan
= new XFTextContent();
405 pSpan
->SetText(text
);
410 void LwpFrib::ConvertHyperLink(XFContentContainer
* pXFPara
,LwpHyperlinkMgr
* pHyperlink
,const OUString
& text
)
412 XFHyperlink
* pHyper
= new XFHyperlink
;
413 pHyper
->SetHRef(pHyperlink
->GetHyperlink());
414 pHyper
->SetText(text
);
415 pHyper
->SetStyleName(GetStyleName());
416 pXFPara
->Add(pHyper
);
420 * @descr: Get the current frib font style
421 * @return: XFFont pointer
423 rtl::Reference
<XFFont
> LwpFrib::GetFont()
425 rtl::Reference
<XFFont
> pFont
;
426 if(m_pModifiers
&&m_pModifiers
->FontID
)
428 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 void LwpFrib::Register(std::map
<LwpFrib
*,OUString
>* pFribMap
)
455 throw std::runtime_error("registered already");
456 m_pFribMap
= pFribMap
;
459 void LwpFrib::Deregister()
463 m_pFribMap
->erase(this);
464 m_pFribMap
= nullptr;
468 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */