build fix
[LibreOffice.git] / lotuswordpro / source / filter / lwpfrib.cxx
blob1e1505f88f0a785f442c19c800f15d2a76427811
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_pFribMap(nullptr)
90 , m_pPara(pPara)
91 , m_pNext(nullptr)
92 , m_nFribType(0)
93 , m_pModifiers(nullptr)
94 , m_ModFlag(false)
95 , m_nRevisionType(0)
96 , m_bRevisionFlag(false)
97 , m_nEditor(0)
101 LwpFrib::~LwpFrib()
103 Deregister();
106 LwpFrib* LwpFrib::CreateFrib(LwpPara* pPara, LwpObjectStream* pObjStrm, sal_uInt8 fribtag,sal_uInt8 editID)
108 //Read Modifier
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 );
122 //Read frib data
123 LwpFrib* newFrib = nullptr;
124 sal_uInt16 friblen = pObjStrm->QuickReaduInt16();
125 sal_uInt8 fribtype = fribtag&~FRIB_TAG_TYPEMASK;
126 switch(fribtype)
128 case FRIB_TAG_INVALID: //fall through
129 case FRIB_TAG_EOP: //fall through
130 default:
131 newFrib = new LwpFrib(pPara);
132 break;
133 case FRIB_TAG_TEXT:
135 newFrib = new LwpFribText (pPara, (fribtag & FRIB_TAG_NOUNICODE) != 0);
136 break;
138 case FRIB_TAG_TABLE:
139 newFrib = new LwpFribTable(pPara);
140 break;
141 case FRIB_TAG_TAB:
142 newFrib = new LwpFribTab(pPara);
143 break;
144 case FRIB_TAG_PAGEBREAK:
145 newFrib = new LwpFribPageBreak(pPara);
146 break;
147 case FRIB_TAG_FRAME:
148 newFrib = new LwpFribFrame(pPara);
149 break;
150 case FRIB_TAG_FOOTNOTE:
151 newFrib = new LwpFribFootnote(pPara);
152 break;
153 case FRIB_TAG_COLBREAK:
154 newFrib = new LwpFribColumnBreak(pPara);
155 break;
156 case FRIB_TAG_LINEBREAK:
157 newFrib = new LwpFribLineBreak(pPara);
158 break;
159 case FRIB_TAG_HARDSPACE:
160 newFrib = new LwpFribHardSpace(pPara);
161 break;
162 case FRIB_TAG_SOFTHYPHEN:
163 newFrib = new LwpFribSoftHyphen(pPara);
164 break;
165 case FRIB_TAG_PARANUMBER:
166 newFrib = new LwpFribParaNumber(pPara);
167 break;
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);
172 break;
173 case FRIB_TAG_NOTE:
174 newFrib = new LwpFribNote(pPara);
175 break;
176 case FRIB_TAG_SECTION:
177 newFrib = new LwpFribSection(pPara);
178 break;
179 case FRIB_TAG_PAGENUMBER:
180 newFrib = new LwpFribPageNumber(pPara);
181 break;
182 case FRIB_TAG_DOCVAR:
183 newFrib = new LwpFribDocVar(pPara);
184 break;
185 case FRIB_TAG_BOOKMARK:
186 newFrib = new LwpFribBookMark(pPara);
187 break;
188 case FRIB_TAG_FIELD:
189 newFrib = new LwpFribField(pPara);
190 break;
191 case FRIB_TAG_CHBLOCK:
192 newFrib = new LwpFribCHBlock(pPara);
193 break;
194 case FRIB_TAG_RUBYMARKER:
195 newFrib = new LwpFribRubyMarker(pPara);
196 break;
197 case FRIB_TAG_RUBYFRAME:
198 newFrib = new LwpFribRubyFrame(pPara);
199 break;
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);
211 return newFrib;
214 void LwpFrib::Read(LwpObjectStream* pObjStrm, sal_uInt16 len)
216 pObjStrm->SeekRel(len);
219 void LwpFrib::SetModifiers(ModifierInfo* pModifiers)
221 if (pModifiers)
223 m_pModifiers.reset( pModifiers );
224 m_ModFlag = true;
225 if (pModifiers->RevisionFlag)
227 m_bRevisionFlag = true;
228 m_nRevisionType = pModifiers->RevisionType;
233 void LwpFrib::RegisterStyle(LwpFoundry* pFoundry)
235 if (!m_pModifiers)
236 return;
237 if (!m_pModifiers->FontID && !m_pModifiers->HasCharStyle && !m_pModifiers->HasHighlight)
239 m_ModFlag = false;
240 return;
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
244 //note by ,1-27
245 rtl::Reference<XFFont> pFont;
246 XFTextStyle* pStyle = nullptr;
247 m_StyleName.clear();
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));
255 if (pNamedStyle)
257 LwpCharacterStyle* pCharStyle = nullptr;
258 if (m_pModifiers->FontID && pFoundry)
259 pCharStyle = dynamic_cast<LwpCharacterStyle*>(m_pModifiers->CharStyleID.obj().get());
260 if (pCharStyle)
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)
272 pStyle = nullptr;
274 else
275 m_StyleName = pNamedStyle->GetStyleName();
277 else
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)
288 pStyle = nullptr;
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);
307 else
309 pFont = new XFFont;
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)
320 for(;;)
322 bool bFailure;
324 // Get the modifier type
325 sal_uInt8 Modifier = pObjStrm->QuickReaduInt8(&bFailure);
326 if (bFailure)
327 break;
329 // Stop when we hit the last modifier
330 if (Modifier == FRIB_MTAG_NONE)
331 break;
333 // Get the modifier length
334 sal_uInt8 len = pObjStrm->QuickReaduInt8(&bFailure);
335 if (bFailure)
336 break;
338 switch (Modifier)
340 case FRIB_MTAG_FONT:
341 if (len != sizeof(pModInfo->FontID))
343 OSL_FAIL("FRIB_MTAG_FONT entry wrong size\n");
344 pObjStrm->SeekRel(len);
346 else
347 pModInfo->FontID = pObjStrm->QuickReaduInt32();
348 break;
349 case FRIB_MTAG_CHARSTYLE:
350 pModInfo->HasCharStyle = true;
351 pModInfo->CharStyleID.ReadIndexed(pObjStrm);
352 break;
353 case FRIB_MTAG_LANGUAGE:
354 pModInfo->HasLangOverride = true;
355 pModInfo->Language.Read(pObjStrm);
356 break;
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);
363 else
364 pModInfo->CodePage = pObjStrm->QuickReaduInt16();
365 break;
366 case FRIB_MTAG_ATTRIBUTE:
367 pModInfo->aTxtAttrOverride.Read(pObjStrm);
368 if (pModInfo->aTxtAttrOverride.IsHighlight())
369 pModInfo->HasHighlight = true;
370 break;
371 case FRIB_MTAG_REVISION:
372 pModInfo->RevisionType = pObjStrm->QuickReaduInt8();
373 pModInfo->RevisionFlag = true;
374 break;
375 default:
376 pObjStrm->SeekRel(len);
377 break;
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)
390 return false;
391 return true;
394 void LwpFrib::ConvertChars(XFContentContainer* pXFPara,const OUString& text)
396 if (m_ModFlag)
398 OUString strStyleName = GetStyleName();
399 XFTextSpan *pSpan = new XFTextSpan(text,strStyleName);
400 pXFPara->Add(pSpan);
402 else
404 XFTextContent *pSpan = new XFTextContent();
405 pSpan->SetText(text);
406 pXFPara->Add(pSpan);
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();
429 if (pFoundry)
430 pFont = pFoundry->GetFontManger().CreateFont(m_pModifiers->FontID);
432 else
434 XFParaStyle* pXFParaStyle = m_pPara->GetXFParaStyle();
435 pFont = pXFParaStyle->GetFont();
437 return pFont;
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)
454 if (m_pFribMap)
455 throw std::runtime_error("registered already");
456 m_pFribMap = pFribMap;
459 void LwpFrib::Deregister()
461 if (m_pFribMap)
463 m_pFribMap->erase(this);
464 m_pFribMap = nullptr;
468 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */