fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / lotuswordpro / source / filter / lwpfrib.cxx
blobd88ec390a26b04c80d44e996a60cf88d5547f550
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 ************************************************************************/
60 /*************************************************************************
61 * Change History
62 Jan 2005 Created
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)
92 : m_pPara(pPara)
93 , m_pNext(NULL)
94 , m_nFribType(0)
95 , m_pModifiers(NULL)
96 , m_ModFlag(false)
97 , m_nRevisionType(0)
98 , m_bRevisionFlag(false)
99 , m_nEditor(0)
103 LwpFrib::~LwpFrib()
105 if(m_pModifiers)
106 delete m_pModifiers;
109 LwpFrib* LwpFrib::CreateFrib(LwpPara* pPara, LwpObjectStream* pObjStrm, sal_uInt8 fribtag,sal_uInt8 editID)
111 //Read Modifier
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 );
125 //Read frib data
126 LwpFrib* newFrib = NULL;
127 sal_uInt16 friblen = pObjStrm->QuickReaduInt16();
128 sal_uInt8 fribtype = fribtag&~FRIB_TAG_TYPEMASK;
129 switch(fribtype)
131 case FRIB_TAG_INVALID: //fall through
132 case FRIB_TAG_EOP: //fall through
133 default:
134 newFrib = new LwpFrib(pPara);
135 break;
136 case FRIB_TAG_TEXT:
138 newFrib = new LwpFribText (pPara, (fribtag & FRIB_TAG_NOUNICODE) != 0);
139 break;
141 case FRIB_TAG_TABLE:
142 newFrib = new LwpFribTable(pPara);
143 break;
144 case FRIB_TAG_TAB:
145 newFrib = new LwpFribTab(pPara);
146 break;
147 case FRIB_TAG_PAGEBREAK:
148 newFrib = new LwpFribPageBreak(pPara);
149 break;
150 case FRIB_TAG_FRAME:
151 newFrib = new LwpFribFrame(pPara);
152 break;
153 case FRIB_TAG_FOOTNOTE:
154 newFrib = new LwpFribFootnote(pPara);
155 break;
156 case FRIB_TAG_COLBREAK:
157 newFrib = new LwpFribColumnBreak(pPara);
158 break;
159 case FRIB_TAG_LINEBREAK:
160 newFrib = new LwpFribLineBreak(pPara);
161 break;
162 case FRIB_TAG_HARDSPACE:
163 newFrib = new LwpFribHardSpace(pPara);
164 break;
165 case FRIB_TAG_SOFTHYPHEN:
166 newFrib = new LwpFribSoftHyphen(pPara);
167 break;
168 case FRIB_TAG_PARANUMBER:
169 newFrib = new LwpFribParaNumber(pPara);
170 break;
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);
175 break;
176 case FRIB_TAG_NOTE:
177 newFrib = new LwpFribNote(pPara);
178 break;
179 case FRIB_TAG_SECTION:
180 newFrib = new LwpFribSection(pPara);
181 break;
182 case FRIB_TAG_PAGENUMBER:
183 newFrib = new LwpFribPageNumber(pPara);
184 break;
185 case FRIB_TAG_DOCVAR:
186 newFrib = new LwpFribDocVar(pPara);
187 break;
188 case FRIB_TAG_BOOKMARK:
189 newFrib = new LwpFribBookMark(pPara);
190 break;
191 case FRIB_TAG_FIELD:
192 newFrib = new LwpFribField(pPara);
193 break;
194 case FRIB_TAG_CHBLOCK:
195 newFrib = new LwpFribCHBlock(pPara);
196 break;
197 case FRIB_TAG_RUBYMARKER:
198 newFrib = new LwpFribRubyMarker(pPara);
199 break;
200 case FRIB_TAG_RUBYFRAME:
201 newFrib = new LwpFribRubyFrame(pPara);
202 break;
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);
214 return newFrib;
217 void LwpFrib::Read(LwpObjectStream* pObjStrm, sal_uInt16 len)
219 pObjStrm->SeekRel(len);
222 void LwpFrib::SetModifiers(ModifierInfo* pModifiers)
224 if (pModifiers)
226 m_pModifiers = pModifiers;
227 m_ModFlag = true;
228 if (pModifiers->RevisionFlag)
230 m_bRevisionFlag = true;
231 m_nRevisionType = pModifiers->RevisionType;
236 void LwpFrib::RegisterStyle(LwpFoundry* pFoundry)
238 if (!m_pModifiers)
239 return;
240 if (!m_pModifiers->FontID && !m_pModifiers->HasCharStyle && !m_pModifiers->HasHighlight)
242 m_ModFlag = false;
243 return;
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
247 //note by ,1-27
248 rtl::Reference<XFFont> pFont;
249 XFTextStyle* pStyle = NULL;
250 m_StyleName.clear();
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));
258 if (pNamedStyle)
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)
273 pStyle = NULL;
275 else
276 m_StyleName = pNamedStyle->GetStyleName();
278 else
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)
289 pStyle = NULL;
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);
308 else
310 pFont = new XFFont;
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)
321 for(;;)
323 bool bFailure;
325 // Get the modifier type
326 sal_uInt8 Modifier = pObjStrm->QuickReaduInt8(&bFailure);
327 if (bFailure)
328 break;
330 // Stop when we hit the last modifier
331 if (Modifier == FRIB_MTAG_NONE)
332 break;
334 // Get the modifier length
335 sal_uInt8 len = pObjStrm->QuickReaduInt8(&bFailure);
336 if (bFailure)
337 break;
339 switch (Modifier)
341 case FRIB_MTAG_FONT:
342 if (len != sizeof(pModInfo->FontID))
344 OSL_FAIL("FRIB_MTAG_FONT entry wrong size\n");
345 pObjStrm->SeekRel(len);
347 else
348 pModInfo->FontID = pObjStrm->QuickReaduInt32();
349 break;
350 case FRIB_MTAG_CHARSTYLE:
351 pModInfo->HasCharStyle = true;
352 pModInfo->CharStyleID.ReadIndexed(pObjStrm);
353 break;
354 case FRIB_MTAG_LANGUAGE:
355 pModInfo->HasLangOverride = true;
356 pModInfo->Language.Read(pObjStrm);
357 break;
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);
364 else
365 pModInfo->CodePage = pObjStrm->QuickReaduInt16();
366 break;
367 case FRIB_MTAG_ATTRIBUTE:
368 pModInfo->aTxtAttrOverride.Read(pObjStrm);
369 if (pModInfo->aTxtAttrOverride.IsHighlight())
370 pModInfo->HasHighlight = true;
371 break;
372 case FRIB_MTAG_REVISION:
373 pModInfo->RevisionType = pObjStrm->QuickReaduInt8();
374 pModInfo->RevisionFlag = true;
375 break;
376 default:
377 pObjStrm->SeekRel(len);
378 break;
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)
391 return false;
392 return true;
395 void LwpFrib::ConvertChars(XFContentContainer* pXFPara,const OUString& text)
397 if (m_ModFlag)
399 OUString strStyleName = GetStyleName();
400 XFTextSpan *pSpan = new XFTextSpan(text,strStyleName);
401 pXFPara->Add(pSpan);
403 else
405 XFTextContent *pSpan = new XFTextContent();
406 pSpan->SetText(text);
407 pXFPara->Add(pSpan);
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);
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 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */