Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / lotuswordpro / source / filter / lwpfrib.cxx
blob64f49eecef2afa140d74a6454939e847e37f3aeb
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,
29 * MA 02111-1307 USA
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 /*************************************************************************
57 * @file
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)
89 : m_pPara(pPara)
90 , m_pNext(nullptr)
91 , m_nFribType(0)
92 , m_pModifiers(nullptr)
93 , m_ModFlag(false)
94 , m_nRevisionType(0)
95 , m_bRevisionFlag(false)
96 , m_nEditor(0)
100 LwpFrib::~LwpFrib()
102 delete m_pModifiers;
105 LwpFrib* LwpFrib::CreateFrib(LwpPara* pPara, LwpObjectStream* pObjStrm, sal_uInt8 fribtag,sal_uInt8 editID)
107 //Read Modifier
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 );
121 //Read frib data
122 LwpFrib* newFrib = nullptr;
123 sal_uInt16 friblen = pObjStrm->QuickReaduInt16();
124 sal_uInt8 fribtype = fribtag&~FRIB_TAG_TYPEMASK;
125 switch(fribtype)
127 case FRIB_TAG_INVALID: //fall through
128 case FRIB_TAG_EOP: //fall through
129 default:
130 newFrib = new LwpFrib(pPara);
131 break;
132 case FRIB_TAG_TEXT:
134 newFrib = new LwpFribText (pPara, (fribtag & FRIB_TAG_NOUNICODE) != 0);
135 break;
137 case FRIB_TAG_TABLE:
138 newFrib = new LwpFribTable(pPara);
139 break;
140 case FRIB_TAG_TAB:
141 newFrib = new LwpFribTab(pPara);
142 break;
143 case FRIB_TAG_PAGEBREAK:
144 newFrib = new LwpFribPageBreak(pPara);
145 break;
146 case FRIB_TAG_FRAME:
147 newFrib = new LwpFribFrame(pPara);
148 break;
149 case FRIB_TAG_FOOTNOTE:
150 newFrib = new LwpFribFootnote(pPara);
151 break;
152 case FRIB_TAG_COLBREAK:
153 newFrib = new LwpFribColumnBreak(pPara);
154 break;
155 case FRIB_TAG_LINEBREAK:
156 newFrib = new LwpFribLineBreak(pPara);
157 break;
158 case FRIB_TAG_HARDSPACE:
159 newFrib = new LwpFribHardSpace(pPara);
160 break;
161 case FRIB_TAG_SOFTHYPHEN:
162 newFrib = new LwpFribSoftHyphen(pPara);
163 break;
164 case FRIB_TAG_PARANUMBER:
165 newFrib = new LwpFribParaNumber(pPara);
166 break;
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);
171 break;
172 case FRIB_TAG_NOTE:
173 newFrib = new LwpFribNote(pPara);
174 break;
175 case FRIB_TAG_SECTION:
176 newFrib = new LwpFribSection(pPara);
177 break;
178 case FRIB_TAG_PAGENUMBER:
179 newFrib = new LwpFribPageNumber(pPara);
180 break;
181 case FRIB_TAG_DOCVAR:
182 newFrib = new LwpFribDocVar(pPara);
183 break;
184 case FRIB_TAG_BOOKMARK:
185 newFrib = new LwpFribBookMark(pPara);
186 break;
187 case FRIB_TAG_FIELD:
188 newFrib = new LwpFribField(pPara);
189 break;
190 case FRIB_TAG_CHBLOCK:
191 newFrib = new LwpFribCHBlock(pPara);
192 break;
193 case FRIB_TAG_RUBYMARKER:
194 newFrib = new LwpFribRubyMarker(pPara);
195 break;
196 case FRIB_TAG_RUBYFRAME:
197 newFrib = new LwpFribRubyFrame(pPara);
198 break;
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);
210 return newFrib;
213 void LwpFrib::Read(LwpObjectStream* pObjStrm, sal_uInt16 len)
215 pObjStrm->SeekRel(len);
218 void LwpFrib::SetModifiers(ModifierInfo* pModifiers)
220 if (pModifiers)
222 m_pModifiers = pModifiers;
223 m_ModFlag = true;
224 if (pModifiers->RevisionFlag)
226 m_bRevisionFlag = true;
227 m_nRevisionType = pModifiers->RevisionType;
232 void LwpFrib::RegisterStyle(LwpFoundry* pFoundry)
234 if (!m_pModifiers)
235 return;
236 if (!m_pModifiers->FontID && !m_pModifiers->HasCharStyle && !m_pModifiers->HasHighlight)
238 m_ModFlag = false;
239 return;
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
243 //note by ,1-27
244 rtl::Reference<XFFont> pFont;
245 XFTextStyle* pStyle = nullptr;
246 m_StyleName.clear();
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));
254 if (pNamedStyle)
256 LwpCharacterStyle* pCharStyle = nullptr;
257 if (m_pModifiers->FontID && pFoundry)
258 pCharStyle = dynamic_cast<LwpCharacterStyle*>(m_pModifiers->CharStyleID.obj().get());
259 if (pCharStyle)
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)
271 pStyle = nullptr;
273 else
274 m_StyleName = pNamedStyle->GetStyleName();
276 else
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)
287 pStyle = nullptr;
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);
306 else
308 pFont = new XFFont;
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)
319 for(;;)
321 bool bFailure;
323 // Get the modifier type
324 sal_uInt8 Modifier = pObjStrm->QuickReaduInt8(&bFailure);
325 if (bFailure)
326 break;
328 // Stop when we hit the last modifier
329 if (Modifier == FRIB_MTAG_NONE)
330 break;
332 // Get the modifier length
333 sal_uInt8 len = pObjStrm->QuickReaduInt8(&bFailure);
334 if (bFailure)
335 break;
337 switch (Modifier)
339 case FRIB_MTAG_FONT:
340 if (len != sizeof(pModInfo->FontID))
342 OSL_FAIL("FRIB_MTAG_FONT entry wrong size\n");
343 pObjStrm->SeekRel(len);
345 else
346 pModInfo->FontID = pObjStrm->QuickReaduInt32();
347 break;
348 case FRIB_MTAG_CHARSTYLE:
349 pModInfo->HasCharStyle = true;
350 pModInfo->CharStyleID.ReadIndexed(pObjStrm);
351 break;
352 case FRIB_MTAG_LANGUAGE:
353 pModInfo->HasLangOverride = true;
354 pModInfo->Language.Read(pObjStrm);
355 break;
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);
362 else
363 pModInfo->CodePage = pObjStrm->QuickReaduInt16();
364 break;
365 case FRIB_MTAG_ATTRIBUTE:
366 pModInfo->aTxtAttrOverride.Read(pObjStrm);
367 if (pModInfo->aTxtAttrOverride.IsHighlight())
368 pModInfo->HasHighlight = true;
369 break;
370 case FRIB_MTAG_REVISION:
371 pModInfo->RevisionType = pObjStrm->QuickReaduInt8();
372 pModInfo->RevisionFlag = true;
373 break;
374 default:
375 pObjStrm->SeekRel(len);
376 break;
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)
389 return false;
390 return true;
393 void LwpFrib::ConvertChars(XFContentContainer* pXFPara,const OUString& text)
395 if (m_ModFlag)
397 OUString strStyleName = GetStyleName();
398 XFTextSpan *pSpan = new XFTextSpan(text,strStyleName);
399 pXFPara->Add(pSpan);
401 else
403 XFTextContent *pSpan = new XFTextContent();
404 pSpan->SetText(text);
405 pXFPara->Add(pSpan);
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();
428 if (pFoundry)
429 pFont = pFoundry->GetFontManger().CreateFont(m_pModifiers->FontID);
431 else
433 XFParaStyle* pXFParaStyle = m_pPara->GetXFParaStyle();
434 pFont = pXFParaStyle->GetFont();
436 return pFont;
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: */