fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / lotuswordpro / source / filter / lwpfrib.cxx
blobd801d42ae03887cb4736b64fd68203eaca579986
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 LwpFrib::LwpFrib(LwpPara* pPara)
89 : m_pPara(pPara), m_pNext(NULL)
91 m_ModFlag = sal_False;
92 m_pModifiers = NULL;
93 m_bRevisionFlag = sal_False;
96 LwpFrib::~LwpFrib()
98 if(m_pModifiers)
99 delete m_pModifiers;
102 LwpFrib* LwpFrib::CreateFrib(LwpPara* pPara, LwpObjectStream* pObjStrm, sal_uInt8 fribtag,sal_uInt8 editID)
104 //Read Modifier
105 ModifierInfo* pModInfo = NULL;
106 if(fribtag & FRIB_TAG_MODIFIER)
108 pModInfo = new ModifierInfo();
109 pModInfo->CodePage = 0;
110 pModInfo->FontID = 0;
111 pModInfo->RevisionFlag = sal_False;
112 pModInfo->HasCharStyle = sal_False;
113 pModInfo->HasLangOverride = sal_False;
114 pModInfo->HasHighLight = sal_False;
115 ReadModifiers( pObjStrm, pModInfo );
118 //Read frib data
119 LwpFrib* newFrib = NULL;
120 sal_uInt16 friblen = pObjStrm->QuickReaduInt16();
121 sal_uInt8 fribtype = fribtag&~FRIB_TAG_TYPEMASK;
122 switch(fribtype)
124 case FRIB_TAG_INVALID: //fall through
125 case FRIB_TAG_EOP: //fall through
126 default:
127 newFrib = new LwpFrib(pPara);
128 break;
129 case FRIB_TAG_TEXT:
131 newFrib = new LwpFribText (pPara, fribtag & FRIB_TAG_NOUNICODE);
132 break;
134 case FRIB_TAG_TABLE:
135 newFrib = new LwpFribTable(pPara);
136 break;
137 case FRIB_TAG_TAB:
138 newFrib = new LwpFribTab(pPara);
139 break;
140 case FRIB_TAG_PAGEBREAK:
141 newFrib = new LwpFribPageBreak(pPara);
142 break;
143 case FRIB_TAG_FRAME:
144 newFrib = new LwpFribFrame(pPara);
145 break;
146 case FRIB_TAG_FOOTNOTE:
147 newFrib = new LwpFribFootnote(pPara);
148 break;
149 case FRIB_TAG_COLBREAK:
150 newFrib = new LwpFribColumnBreak(pPara);
151 break;
152 case FRIB_TAG_LINEBREAK:
153 newFrib = new LwpFribLineBreak(pPara);
154 break;
155 case FRIB_TAG_HARDSPACE:
156 newFrib = new LwpFribHardSpace(pPara);
157 break;
158 case FRIB_TAG_SOFTHYPHEN:
159 newFrib = new LwpFribSoftHyphen(pPara);
160 break;
161 case FRIB_TAG_PARANUMBER:
162 newFrib = new LwpFribParaNumber(pPara);
163 break;
164 case FRIB_TAG_UNICODE: //fall through
165 case FRIB_TAG_UNICODE2: //fall through
166 case FRIB_TAG_UNICODE3: //fall through
167 newFrib = new LwpFribUnicode(pPara);
168 break;
169 case FRIB_TAG_NOTE:
170 newFrib = new LwpFribNote(pPara);
171 break;
172 case FRIB_TAG_SECTION:
173 newFrib = new LwpFribSection(pPara);
174 break;
175 case FRIB_TAG_PAGENUMBER:
176 newFrib = new LwpFribPageNumber(pPara);
177 break;
178 case FRIB_TAG_DOCVAR:
179 newFrib = new LwpFribDocVar(pPara);
180 break;
181 case FRIB_TAG_BOOKMARK:
182 newFrib = new LwpFribBookMark(pPara);
183 break;
184 case FRIB_TAG_FIELD:
185 newFrib = new LwpFribField(pPara);
186 break;
187 case FRIB_TAG_CHBLOCK:
188 newFrib = new LwpFribCHBlock(pPara);
189 break;
190 case FRIB_TAG_RUBYMARKER:
191 newFrib = new LwpFribRubyMarker(pPara);
192 break;
193 case FRIB_TAG_RUBYFRAME:
194 newFrib = new LwpFribRubyFrame(pPara);
195 break;
198 //Do not know why the fribTag judgement is necessary, to be checked with
199 if ( fribtag & FRIB_TAG_MODIFIER )
201 newFrib->SetModifiers(pModInfo);
204 newFrib->SetType(fribtype);
205 newFrib->SetEditor(editID);
206 newFrib->Read(pObjStrm, friblen);
207 return newFrib;
210 void LwpFrib::Read(LwpObjectStream* pObjStrm, sal_uInt16 len)
212 pObjStrm->SeekRel(len);
215 void LwpFrib::SetModifiers(ModifierInfo* pModifiers)
217 if (pModifiers)
219 m_pModifiers = pModifiers;
220 m_ModFlag = sal_True;
221 if (pModifiers->RevisionFlag)
223 m_bRevisionFlag = sal_True;
224 m_nRevisionType = pModifiers->RevisionType;
229 void LwpFrib::RegisterStyle(LwpFoundry* pFoundry)
231 if (!m_pModifiers)
232 return;
233 if (!m_pModifiers->FontID && !m_pModifiers->HasCharStyle && !m_pModifiers->HasHighLight)
235 m_ModFlag = sal_False;
236 return;
238 //we only read four modifiers, in these modifiers,CodePage and LangOverride are not styles,
239 //so we can only handle fontid and characstyle, if others ,we should not reg style
240 //note by ,1-27
241 XFFont* pFont;
242 XFTextStyle* pStyle = NULL;
243 m_StyleName = A2OUSTR("");
244 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
245 if (m_pModifiers->HasCharStyle)
247 XFTextStyle* pNamedStyle = static_cast<XFTextStyle*>
248 (pFoundry->GetStyleManager()->GetStyle(m_pModifiers->CharStyleID));
249 if (m_pModifiers->FontID)
251 pStyle = new XFTextStyle();
252 *pStyle = *pNamedStyle;
253 LwpCharacterStyle* pCharStyle = static_cast<LwpCharacterStyle*>(m_pModifiers->CharStyleID.obj());
255 pStyle->SetStyleName(A2OUSTR(""));
256 pFont = pFoundry->GetFontManger()->CreateOverrideFont(pCharStyle->GetFinalFontID(),m_pModifiers->FontID);
257 pStyle->SetFont(pFont);
258 m_StyleName = pXFStyleManager->AddStyle(pStyle)->GetStyleName();
260 else
261 m_StyleName = pNamedStyle->GetStyleName();
263 else
265 if (m_pModifiers->FontID)
267 pStyle = new XFTextStyle();
268 pFont = pFoundry->GetFontManger()->CreateFont(m_pModifiers->FontID);
269 pStyle->SetFont(pFont);
270 m_StyleName = pXFStyleManager->AddStyle(pStyle)->GetStyleName();
274 if (m_pModifiers->HasHighLight)
276 XFColor aColor = GetHighLightColor();//right yellow
277 if (pStyle)//change the style directly
278 pStyle->GetFont()->SetBackColor(aColor);
279 else //register a new style
281 pStyle = new XFTextStyle();
283 if (!m_StyleName.isEmpty())
285 XFTextStyle* pOldStyle = pXFStyleManager->FindTextStyle(m_StyleName);
286 *pStyle = *pOldStyle;
287 pStyle->GetFont()->SetBackColor(aColor);
289 else
291 pFont = new XFFont;
292 pFont->SetBackColor(aColor);
293 pStyle->SetFont(pFont);
295 m_StyleName = pXFStyleManager->AddStyle(pStyle)->GetStyleName();
300 void LwpFrib::ReadModifiers(LwpObjectStream* pObjStrm,ModifierInfo* pModInfo)
302 for(;;)
304 bool bFailure;
306 // Get the modifier type
307 sal_uInt8 Modifier = pObjStrm->QuickReaduInt8(&bFailure);
308 if (bFailure)
309 break;
311 // Stop when we hit the last modifier
312 if (Modifier == FRIB_MTAG_NONE)
313 break;
315 // Get the modifier length
316 sal_uInt8 len = pObjStrm->QuickReaduInt8(&bFailure);
317 if (bFailure)
318 break;
320 switch (Modifier)
322 case FRIB_MTAG_FONT:
323 if (len != sizeof(pModInfo->FontID))
325 OSL_FAIL("FRIB_MTAG_FONT entry wrong size\n");
326 pObjStrm->SeekRel(len);
328 else
329 pModInfo->FontID = pObjStrm->QuickReaduInt32();
330 break;
331 case FRIB_MTAG_CHARSTYLE:
332 pModInfo->HasCharStyle = sal_True;
333 pModInfo->CharStyleID.ReadIndexed(pObjStrm);
334 break;
335 case FRIB_MTAG_LANGUAGE:
336 pModInfo->HasLangOverride = sal_True;
337 pModInfo->Language.Read(pObjStrm);
338 break;
339 case FRIB_MTAG_CODEPAGE:
340 if (len != sizeof(pModInfo->CodePage))
342 OSL_FAIL("FRIB_MTAG_CODEPAGE entry wrong size\n");
343 pObjStrm->SeekRel(len);
345 else
346 pModInfo->CodePage = pObjStrm->QuickReaduInt16();
347 break;
348 case FRIB_MTAG_ATTRIBUTE:
349 pModInfo->aTxtAttrOverride.Read(pObjStrm);
350 if (pModInfo->aTxtAttrOverride.IsHighLight())
351 pModInfo->HasHighLight = sal_True;
352 break;
353 case FRIB_MTAG_REVISION:
354 pModInfo->RevisionType = pObjStrm->QuickReaduInt8();
355 pModInfo->RevisionFlag = sal_True;
356 break;
357 default:
358 pObjStrm->SeekRel(len);
359 break;
361 // TODO: read the modifier data
366 * @descr: Whether there are other fribs following current frib.
367 * @return: Ture if having following fribs, or false.
369 sal_Bool LwpFrib::HasNextFrib()
371 if (!GetNext() || GetNext()->GetType()==FRIB_TAG_EOP)
372 return sal_False;
373 return sal_True;
376 void LwpFrib::ConvertChars(XFContentContainer* pXFPara,OUString text)
378 if (m_ModFlag)
380 OUString strStyleName = GetStyleName();
381 XFTextSpan *pSpan = new XFTextSpan(text,strStyleName);
382 pXFPara->Add(pSpan);
384 else
386 XFTextContent *pSpan = new XFTextContent();
387 pSpan->SetText(text);
388 pXFPara->Add(pSpan);
392 void LwpFrib::ConvertHyperLink(XFContentContainer* pXFPara,LwpHyperlinkMgr* pHyperlink,OUString text)
394 XFHyperlink* pHyper = new XFHyperlink;
395 pHyper->SetHRef(pHyperlink->GetHyperlink());
396 pHyper->SetText(text);
397 pHyper->SetStyleName(GetStyleName());
398 pXFPara->Add(pHyper);
402 * @descr: Get the current frib font style
403 * @return: XFFont pointer
405 XFFont* LwpFrib::GetFont()
407 XFFont* pFont = NULL;
408 if(m_pModifiers&&m_pModifiers->FontID)
410 LwpFoundry* pFoundry = m_pPara->GetFoundry();
411 pFont = pFoundry->GetFontManger()->CreateFont(m_pModifiers->FontID);
413 else
415 XFParaStyle* pXFParaStyle = m_pPara->GetXFParaStyle();
416 pFont = pXFParaStyle->GetFont();
418 return pFont;
421 OUString LwpFrib::GetEditor()
423 LwpGlobalMgr* pGlobal = LwpGlobalMgr::GetInstance();
424 return pGlobal->GetEditorName(m_nEditor);
427 XFColor LwpFrib::GetHighLightColor()
429 LwpGlobalMgr* pGlobal = LwpGlobalMgr::GetInstance();
430 return pGlobal->GetHighLightColor(m_nEditor);
433 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */