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
)
92 , m_pModifiers(nullptr)
95 , m_bRevisionFlag(false)
105 LwpFrib
* LwpFrib::CreateFrib(LwpPara
* pPara
, LwpObjectStream
* pObjStrm
, sal_uInt8 fribtag
,sal_uInt8 editID
)
108 ModifierInfo
* pModInfo
= nullptr;
109 if(fribtag
& FRIB_TAG_MODIFIER
)
111 pModInfo
= new ModifierInfo();
112 pModInfo
->CodePage
= 0;
113 pModInfo
->FontID
= 0;
114 pModInfo
->RevisionFlag
= false;
115 pModInfo
->HasCharStyle
= false;
116 pModInfo
->HasLangOverride
= false;
117 pModInfo
->HasHighlight
= false;
118 ReadModifiers( pObjStrm
, pModInfo
);
122 LwpFrib
* newFrib
= nullptr;
123 sal_uInt16 friblen
= pObjStrm
->QuickReaduInt16();
124 sal_uInt8 fribtype
= fribtag
&~FRIB_TAG_TYPEMASK
;
127 case FRIB_TAG_INVALID
: //fall through
128 case FRIB_TAG_EOP
: //fall through
130 newFrib
= new LwpFrib(pPara
);
134 newFrib
= new LwpFribText (pPara
, (fribtag
& FRIB_TAG_NOUNICODE
) != 0);
138 newFrib
= new LwpFribTable(pPara
);
141 newFrib
= new LwpFribTab(pPara
);
143 case FRIB_TAG_PAGEBREAK
:
144 newFrib
= new LwpFribPageBreak(pPara
);
147 newFrib
= new LwpFribFrame(pPara
);
149 case FRIB_TAG_FOOTNOTE
:
150 newFrib
= new LwpFribFootnote(pPara
);
152 case FRIB_TAG_COLBREAK
:
153 newFrib
= new LwpFribColumnBreak(pPara
);
155 case FRIB_TAG_LINEBREAK
:
156 newFrib
= new LwpFribLineBreak(pPara
);
158 case FRIB_TAG_HARDSPACE
:
159 newFrib
= new LwpFribHardSpace(pPara
);
161 case FRIB_TAG_SOFTHYPHEN
:
162 newFrib
= new LwpFribSoftHyphen(pPara
);
164 case FRIB_TAG_PARANUMBER
:
165 newFrib
= new LwpFribParaNumber(pPara
);
167 case FRIB_TAG_UNICODE
: //fall through
168 case FRIB_TAG_UNICODE2
: //fall through
169 case FRIB_TAG_UNICODE3
: //fall through
170 newFrib
= new LwpFribUnicode(pPara
);
173 newFrib
= new LwpFribNote(pPara
);
175 case FRIB_TAG_SECTION
:
176 newFrib
= new LwpFribSection(pPara
);
178 case FRIB_TAG_PAGENUMBER
:
179 newFrib
= new LwpFribPageNumber(pPara
);
181 case FRIB_TAG_DOCVAR
:
182 newFrib
= new LwpFribDocVar(pPara
);
184 case FRIB_TAG_BOOKMARK
:
185 newFrib
= new LwpFribBookMark(pPara
);
188 newFrib
= new LwpFribField(pPara
);
190 case FRIB_TAG_CHBLOCK
:
191 newFrib
= new LwpFribCHBlock(pPara
);
193 case FRIB_TAG_RUBYMARKER
:
194 newFrib
= new LwpFribRubyMarker(pPara
);
196 case FRIB_TAG_RUBYFRAME
:
197 newFrib
= new LwpFribRubyFrame(pPara
);
201 //Do not know why the fribTag judgement is necessary, to be checked with
202 if ( fribtag
& FRIB_TAG_MODIFIER
)
204 newFrib
->SetModifiers(pModInfo
);
207 newFrib
->SetType(fribtype
);
208 newFrib
->SetEditor(editID
);
209 newFrib
->Read(pObjStrm
, friblen
);
213 void LwpFrib::Read(LwpObjectStream
* pObjStrm
, sal_uInt16 len
)
215 pObjStrm
->SeekRel(len
);
218 void LwpFrib::SetModifiers(ModifierInfo
* pModifiers
)
222 m_pModifiers
= pModifiers
;
224 if (pModifiers
->RevisionFlag
)
226 m_bRevisionFlag
= true;
227 m_nRevisionType
= pModifiers
->RevisionType
;
232 void LwpFrib::RegisterStyle(LwpFoundry
* pFoundry
)
236 if (!m_pModifiers
->FontID
&& !m_pModifiers
->HasCharStyle
&& !m_pModifiers
->HasHighlight
)
241 //we only read four modifiers, in these modifiers,CodePage and LangOverride are not styles,
242 //so we can only handle fontid and charstyle, if others, we should not reg style
244 rtl::Reference
<XFFont
> pFont
;
245 XFTextStyle
* pStyle
= nullptr;
247 XFStyleManager
* pXFStyleManager
= LwpGlobalMgr::GetInstance()->GetXFStyleManager();
248 XFTextStyle
* pNamedStyle
= nullptr;
249 if (m_pModifiers
->HasCharStyle
&& pFoundry
)
251 pNamedStyle
= static_cast<XFTextStyle
*>
252 (pFoundry
->GetStyleManager()->GetStyle(m_pModifiers
->CharStyleID
));
256 LwpCharacterStyle
* pCharStyle
= nullptr;
257 if (m_pModifiers
->FontID
&& pFoundry
)
258 pCharStyle
= dynamic_cast<LwpCharacterStyle
*>(m_pModifiers
->CharStyleID
.obj().get());
261 pStyle
= new XFTextStyle();
262 *pStyle
= *pNamedStyle
;
264 pStyle
->SetStyleName("");
265 pFont
= pFoundry
->GetFontManger().CreateOverrideFont(pCharStyle
->GetFinalFontID(),m_pModifiers
->FontID
);
266 pStyle
->SetFont(pFont
);
267 IXFStyleRet aNewStyle
= pXFStyleManager
->AddStyle(pStyle
);
268 m_StyleName
= aNewStyle
.m_pStyle
->GetStyleName();
269 pStyle
= dynamic_cast<XFTextStyle
*>(aNewStyle
.m_pStyle
);
270 if (aNewStyle
.m_bOrigDeleted
)
274 m_StyleName
= pNamedStyle
->GetStyleName();
278 if (m_pModifiers
->FontID
&& pFoundry
)
280 pStyle
= new XFTextStyle();
281 pFont
= pFoundry
->GetFontManger().CreateFont(m_pModifiers
->FontID
);
282 pStyle
->SetFont(pFont
);
283 IXFStyleRet aNewStyle
= pXFStyleManager
->AddStyle(pStyle
);
284 m_StyleName
= aNewStyle
.m_pStyle
->GetStyleName();
285 pStyle
= dynamic_cast<XFTextStyle
*>(aNewStyle
.m_pStyle
);
286 if (aNewStyle
.m_bOrigDeleted
)
291 if (m_pModifiers
->HasHighlight
)
293 XFColor aColor
= GetHighlightColor();//right yellow
294 if (pStyle
)//change the style directly
295 pStyle
->GetFont()->SetBackColor(aColor
);
296 else //register a new style
298 pStyle
= new XFTextStyle();
300 if (!m_StyleName
.isEmpty())
302 XFTextStyle
* pOldStyle
= pXFStyleManager
->FindTextStyle(m_StyleName
);
303 *pStyle
= *pOldStyle
;
304 pStyle
->GetFont()->SetBackColor(aColor
);
309 pFont
->SetBackColor(aColor
);
310 pStyle
->SetFont(pFont
);
312 m_StyleName
= pXFStyleManager
->AddStyle(pStyle
).m_pStyle
->GetStyleName();
317 void LwpFrib::ReadModifiers(LwpObjectStream
* pObjStrm
,ModifierInfo
* pModInfo
)
323 // Get the modifier type
324 sal_uInt8 Modifier
= pObjStrm
->QuickReaduInt8(&bFailure
);
328 // Stop when we hit the last modifier
329 if (Modifier
== FRIB_MTAG_NONE
)
332 // Get the modifier length
333 sal_uInt8 len
= pObjStrm
->QuickReaduInt8(&bFailure
);
340 if (len
!= sizeof(pModInfo
->FontID
))
342 OSL_FAIL("FRIB_MTAG_FONT entry wrong size\n");
343 pObjStrm
->SeekRel(len
);
346 pModInfo
->FontID
= pObjStrm
->QuickReaduInt32();
348 case FRIB_MTAG_CHARSTYLE
:
349 pModInfo
->HasCharStyle
= true;
350 pModInfo
->CharStyleID
.ReadIndexed(pObjStrm
);
352 case FRIB_MTAG_LANGUAGE
:
353 pModInfo
->HasLangOverride
= true;
354 pModInfo
->Language
.Read(pObjStrm
);
356 case FRIB_MTAG_CODEPAGE
:
357 if (len
!= sizeof(pModInfo
->CodePage
))
359 OSL_FAIL("FRIB_MTAG_CODEPAGE entry wrong size\n");
360 pObjStrm
->SeekRel(len
);
363 pModInfo
->CodePage
= pObjStrm
->QuickReaduInt16();
365 case FRIB_MTAG_ATTRIBUTE
:
366 pModInfo
->aTxtAttrOverride
.Read(pObjStrm
);
367 if (pModInfo
->aTxtAttrOverride
.IsHighlight())
368 pModInfo
->HasHighlight
= true;
370 case FRIB_MTAG_REVISION
:
371 pModInfo
->RevisionType
= pObjStrm
->QuickReaduInt8();
372 pModInfo
->RevisionFlag
= true;
375 pObjStrm
->SeekRel(len
);
378 // TODO: read the modifier data
383 * @descr: Whether there are other fribs following current frib.
384 * @return: True if having following fribs, or false.
386 bool LwpFrib::HasNextFrib()
388 if (!GetNext() || GetNext()->GetType()==FRIB_TAG_EOP
)
393 void LwpFrib::ConvertChars(XFContentContainer
* pXFPara
,const OUString
& text
)
397 OUString strStyleName
= GetStyleName();
398 XFTextSpan
*pSpan
= new XFTextSpan(text
,strStyleName
);
403 XFTextContent
*pSpan
= new XFTextContent();
404 pSpan
->SetText(text
);
409 void LwpFrib::ConvertHyperLink(XFContentContainer
* pXFPara
,LwpHyperlinkMgr
* pHyperlink
,const OUString
& text
)
411 XFHyperlink
* pHyper
= new XFHyperlink
;
412 pHyper
->SetHRef(pHyperlink
->GetHyperlink());
413 pHyper
->SetText(text
);
414 pHyper
->SetStyleName(GetStyleName());
415 pXFPara
->Add(pHyper
);
419 * @descr: Get the current frib font style
420 * @return: XFFont pointer
422 rtl::Reference
<XFFont
> LwpFrib::GetFont()
424 rtl::Reference
<XFFont
> pFont
;
425 if(m_pModifiers
&&m_pModifiers
->FontID
)
427 LwpFoundry
* pFoundry
= m_pPara
->GetFoundry();
429 pFont
= pFoundry
->GetFontManger().CreateFont(m_pModifiers
->FontID
);
433 XFParaStyle
* pXFParaStyle
= m_pPara
->GetXFParaStyle();
434 pFont
= pXFParaStyle
->GetFont();
439 OUString
LwpFrib::GetEditor()
441 LwpGlobalMgr
* pGlobal
= LwpGlobalMgr::GetInstance();
442 return pGlobal
->GetEditorName(m_nEditor
);
445 XFColor
LwpFrib::GetHighlightColor()
447 LwpGlobalMgr
* pGlobal
= LwpGlobalMgr::GetInstance();
448 return pGlobal
->GetHighlightColor(m_nEditor
);
451 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */