Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*************************************************************************
3 : *
4 : * The Contents of this file are made available subject to the terms of
5 : * either of the following licenses
6 : *
7 : * - GNU Lesser General Public License Version 2.1
8 : * - Sun Industry Standards Source License Version 1.1
9 : *
10 : * Sun Microsystems Inc., October, 2000
11 : *
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
16 : *
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.
20 : *
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.
25 : *
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
30 : *
31 : *
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.
38 : *
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.
45 : *
46 : * The Initial Developer of the Original Code is: IBM Corporation
47 : *
48 : * Copyright: 2008 by IBM Corporation
49 : *
50 : * All Rights Reserved.
51 : *
52 : * Contributor(s): _______________________________________
53 : *
54 : *
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"
87 :
88 0 : LwpFrib::LwpFrib(LwpPara* pPara)
89 : : m_pPara(pPara)
90 : , m_pNext(NULL)
91 : , m_nFribType(0)
92 : , m_pModifiers(NULL)
93 : , m_ModFlag(sal_False)
94 : , m_nRevisionType(0)
95 : , m_bRevisionFlag(sal_False)
96 0 : , m_nEditor(0)
97 : {
98 0 : }
99 :
100 0 : LwpFrib::~LwpFrib()
101 : {
102 0 : if(m_pModifiers)
103 0 : delete m_pModifiers;
104 0 : }
105 :
106 0 : LwpFrib* LwpFrib::CreateFrib(LwpPara* pPara, LwpObjectStream* pObjStrm, sal_uInt8 fribtag,sal_uInt8 editID)
107 : {
108 : //Read Modifier
109 0 : ModifierInfo* pModInfo = NULL;
110 0 : if(fribtag & FRIB_TAG_MODIFIER)
111 : {
112 0 : pModInfo = new ModifierInfo();
113 0 : pModInfo->CodePage = 0;
114 0 : pModInfo->FontID = 0;
115 0 : pModInfo->RevisionFlag = sal_False;
116 0 : pModInfo->HasCharStyle = sal_False;
117 0 : pModInfo->HasLangOverride = sal_False;
118 0 : pModInfo->HasHighlight = sal_False;
119 0 : ReadModifiers( pObjStrm, pModInfo );
120 : }
121 :
122 : //Read frib data
123 0 : LwpFrib* newFrib = NULL;
124 0 : sal_uInt16 friblen = pObjStrm->QuickReaduInt16();
125 0 : sal_uInt8 fribtype = fribtag&~FRIB_TAG_TYPEMASK;
126 0 : switch(fribtype)
127 : {
128 : case FRIB_TAG_INVALID: //fall through
129 : case FRIB_TAG_EOP: //fall through
130 : default:
131 0 : newFrib = new LwpFrib(pPara);
132 0 : break;
133 : case FRIB_TAG_TEXT:
134 : {
135 0 : newFrib = new LwpFribText (pPara, fribtag & FRIB_TAG_NOUNICODE);
136 0 : break;
137 : }
138 : case FRIB_TAG_TABLE:
139 0 : newFrib = new LwpFribTable(pPara);
140 0 : break;
141 : case FRIB_TAG_TAB:
142 0 : newFrib = new LwpFribTab(pPara);
143 0 : break;
144 : case FRIB_TAG_PAGEBREAK:
145 0 : newFrib = new LwpFribPageBreak(pPara);
146 0 : break;
147 : case FRIB_TAG_FRAME:
148 0 : newFrib = new LwpFribFrame(pPara);
149 0 : break;
150 : case FRIB_TAG_FOOTNOTE:
151 0 : newFrib = new LwpFribFootnote(pPara);
152 0 : break;
153 : case FRIB_TAG_COLBREAK:
154 0 : newFrib = new LwpFribColumnBreak(pPara);
155 0 : break;
156 : case FRIB_TAG_LINEBREAK:
157 0 : newFrib = new LwpFribLineBreak(pPara);
158 0 : break;
159 : case FRIB_TAG_HARDSPACE:
160 0 : newFrib = new LwpFribHardSpace(pPara);
161 0 : break;
162 : case FRIB_TAG_SOFTHYPHEN:
163 0 : newFrib = new LwpFribSoftHyphen(pPara);
164 0 : break;
165 : case FRIB_TAG_PARANUMBER:
166 0 : newFrib = new LwpFribParaNumber(pPara);
167 0 : break;
168 : case FRIB_TAG_UNICODE: //fall through
169 : case FRIB_TAG_UNICODE2: //fall through
170 : case FRIB_TAG_UNICODE3: //fall through
171 0 : newFrib = new LwpFribUnicode(pPara);
172 0 : break;
173 : case FRIB_TAG_NOTE:
174 0 : newFrib = new LwpFribNote(pPara);
175 0 : break;
176 : case FRIB_TAG_SECTION:
177 0 : newFrib = new LwpFribSection(pPara);
178 0 : break;
179 : case FRIB_TAG_PAGENUMBER:
180 0 : newFrib = new LwpFribPageNumber(pPara);
181 0 : break;
182 : case FRIB_TAG_DOCVAR:
183 0 : newFrib = new LwpFribDocVar(pPara);
184 0 : break;
185 : case FRIB_TAG_BOOKMARK:
186 0 : newFrib = new LwpFribBookMark(pPara);
187 0 : break;
188 : case FRIB_TAG_FIELD:
189 0 : newFrib = new LwpFribField(pPara);
190 0 : break;
191 : case FRIB_TAG_CHBLOCK:
192 0 : newFrib = new LwpFribCHBlock(pPara);
193 0 : break;
194 : case FRIB_TAG_RUBYMARKER:
195 0 : newFrib = new LwpFribRubyMarker(pPara);
196 0 : break;
197 : case FRIB_TAG_RUBYFRAME:
198 0 : newFrib = new LwpFribRubyFrame(pPara);
199 0 : break;
200 : }
201 :
202 : //Do not know why the fribTag judgement is necessary, to be checked with
203 0 : if ( fribtag & FRIB_TAG_MODIFIER )
204 : {
205 0 : newFrib->SetModifiers(pModInfo);
206 : }
207 :
208 0 : newFrib->SetType(fribtype);
209 0 : newFrib->SetEditor(editID);
210 0 : newFrib->Read(pObjStrm, friblen);
211 0 : return newFrib;
212 : }
213 :
214 0 : void LwpFrib::Read(LwpObjectStream* pObjStrm, sal_uInt16 len)
215 : {
216 0 : pObjStrm->SeekRel(len);
217 0 : }
218 :
219 0 : void LwpFrib::SetModifiers(ModifierInfo* pModifiers)
220 : {
221 0 : if (pModifiers)
222 : {
223 0 : m_pModifiers = pModifiers;
224 0 : m_ModFlag = sal_True;
225 0 : if (pModifiers->RevisionFlag)
226 : {
227 0 : m_bRevisionFlag = sal_True;
228 0 : m_nRevisionType = pModifiers->RevisionType;
229 : }
230 : }
231 0 : }
232 :
233 0 : void LwpFrib::RegisterStyle(LwpFoundry* pFoundry)
234 : {
235 0 : if (!m_pModifiers)
236 0 : return;
237 0 : if (!m_pModifiers->FontID && !m_pModifiers->HasCharStyle && !m_pModifiers->HasHighlight)
238 : {
239 0 : m_ModFlag = sal_False;
240 0 : return;
241 : }
242 : //we only read four modifiers, in these modifiers,CodePage and LangOverride are not styles,
243 : //so we can only handle fontid and characstyle, if others ,we should not reg style
244 : //note by ,1-27
245 : XFFont* pFont;
246 0 : XFTextStyle* pStyle = NULL;
247 0 : m_StyleName = "";
248 0 : XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
249 0 : if (m_pModifiers->HasCharStyle)
250 : {
251 : XFTextStyle* pNamedStyle = static_cast<XFTextStyle*>
252 0 : (pFoundry->GetStyleManager()->GetStyle(m_pModifiers->CharStyleID));
253 0 : if (m_pModifiers->FontID)
254 : {
255 0 : pStyle = new XFTextStyle();
256 0 : *pStyle = *pNamedStyle;
257 0 : LwpCharacterStyle* pCharStyle = static_cast<LwpCharacterStyle*>(m_pModifiers->CharStyleID.obj());
258 :
259 0 : pStyle->SetStyleName("");
260 0 : pFont = pFoundry->GetFontManger()->CreateOverrideFont(pCharStyle->GetFinalFontID(),m_pModifiers->FontID);
261 0 : pStyle->SetFont(pFont);
262 0 : IXFStyle *pNewStyle = pXFStyleManager->AddStyle(pStyle);
263 0 : m_StyleName = pNewStyle->GetStyleName();
264 0 : if (pNewStyle != pStyle)
265 0 : pStyle = NULL;
266 : }
267 : else
268 0 : m_StyleName = pNamedStyle->GetStyleName();
269 : }
270 : else
271 : {
272 0 : if (m_pModifiers->FontID)
273 : {
274 0 : pStyle = new XFTextStyle();
275 0 : pFont = pFoundry->GetFontManger()->CreateFont(m_pModifiers->FontID);
276 0 : pStyle->SetFont(pFont);
277 0 : IXFStyle *pNewStyle = pXFStyleManager->AddStyle(pStyle);
278 0 : m_StyleName = pNewStyle->GetStyleName();
279 0 : if (pNewStyle != pStyle)
280 0 : pStyle = NULL;
281 : }
282 : }
283 :
284 0 : if (m_pModifiers->HasHighlight)
285 : {
286 0 : XFColor aColor = GetHighlightColor();//right yellow
287 0 : if (pStyle)//change the style directly
288 0 : pStyle->GetFont()->SetBackColor(aColor);
289 : else //register a new style
290 : {
291 0 : pStyle = new XFTextStyle();
292 :
293 0 : if (!m_StyleName.isEmpty())
294 : {
295 0 : XFTextStyle* pOldStyle = pXFStyleManager->FindTextStyle(m_StyleName);
296 0 : *pStyle = *pOldStyle;
297 0 : pStyle->GetFont()->SetBackColor(aColor);
298 : }
299 : else
300 : {
301 0 : pFont = new XFFont;
302 0 : pFont->SetBackColor(aColor);
303 0 : pStyle->SetFont(pFont);
304 : }
305 0 : m_StyleName = pXFStyleManager->AddStyle(pStyle)->GetStyleName();
306 : }
307 : }
308 : }
309 :
310 0 : void LwpFrib::ReadModifiers(LwpObjectStream* pObjStrm,ModifierInfo* pModInfo)
311 : {
312 : for(;;)
313 : {
314 : bool bFailure;
315 :
316 : // Get the modifier type
317 0 : sal_uInt8 Modifier = pObjStrm->QuickReaduInt8(&bFailure);
318 0 : if (bFailure)
319 0 : break;
320 :
321 : // Stop when we hit the last modifier
322 0 : if (Modifier == FRIB_MTAG_NONE)
323 0 : break;
324 :
325 : // Get the modifier length
326 0 : sal_uInt8 len = pObjStrm->QuickReaduInt8(&bFailure);
327 0 : if (bFailure)
328 0 : break;
329 :
330 0 : switch (Modifier)
331 : {
332 : case FRIB_MTAG_FONT:
333 0 : if (len != sizeof(pModInfo->FontID))
334 : {
335 : OSL_FAIL("FRIB_MTAG_FONT entry wrong size\n");
336 0 : pObjStrm->SeekRel(len);
337 : }
338 : else
339 0 : pModInfo->FontID = pObjStrm->QuickReaduInt32();
340 0 : break;
341 : case FRIB_MTAG_CHARSTYLE:
342 0 : pModInfo->HasCharStyle = sal_True;
343 0 : pModInfo->CharStyleID.ReadIndexed(pObjStrm);
344 0 : break;
345 : case FRIB_MTAG_LANGUAGE:
346 0 : pModInfo->HasLangOverride = sal_True;
347 0 : pModInfo->Language.Read(pObjStrm);
348 0 : break;
349 : case FRIB_MTAG_CODEPAGE:
350 0 : if (len != sizeof(pModInfo->CodePage))
351 : {
352 : OSL_FAIL("FRIB_MTAG_CODEPAGE entry wrong size\n");
353 0 : pObjStrm->SeekRel(len);
354 : }
355 : else
356 0 : pModInfo->CodePage = pObjStrm->QuickReaduInt16();
357 0 : break;
358 : case FRIB_MTAG_ATTRIBUTE:
359 0 : pModInfo->aTxtAttrOverride.Read(pObjStrm);
360 0 : if (pModInfo->aTxtAttrOverride.IsHighlight())
361 0 : pModInfo->HasHighlight = sal_True;
362 0 : break;
363 : case FRIB_MTAG_REVISION:
364 0 : pModInfo->RevisionType = pObjStrm->QuickReaduInt8();
365 0 : pModInfo->RevisionFlag = sal_True;
366 0 : break;
367 : default:
368 0 : pObjStrm->SeekRel(len);
369 0 : break;
370 : }
371 : // TODO: read the modifier data
372 0 : }
373 0 : }
374 :
375 : /**
376 : * @descr: Whether there are other fribs following current frib.
377 : * @return: Ture if having following fribs, or false.
378 : */
379 0 : sal_Bool LwpFrib::HasNextFrib()
380 : {
381 0 : if (!GetNext() || GetNext()->GetType()==FRIB_TAG_EOP)
382 0 : return sal_False;
383 0 : return sal_True;
384 : }
385 :
386 0 : void LwpFrib::ConvertChars(XFContentContainer* pXFPara,const OUString& text)
387 : {
388 0 : if (m_ModFlag)
389 : {
390 0 : OUString strStyleName = GetStyleName();
391 0 : XFTextSpan *pSpan = new XFTextSpan(text,strStyleName);
392 0 : pXFPara->Add(pSpan);
393 : }
394 : else
395 : {
396 0 : XFTextContent *pSpan = new XFTextContent();
397 0 : pSpan->SetText(text);
398 0 : pXFPara->Add(pSpan);
399 : }
400 0 : }
401 :
402 0 : void LwpFrib::ConvertHyperLink(XFContentContainer* pXFPara,LwpHyperlinkMgr* pHyperlink,const OUString& text)
403 : {
404 0 : XFHyperlink* pHyper = new XFHyperlink;
405 0 : pHyper->SetHRef(pHyperlink->GetHyperlink());
406 0 : pHyper->SetText(text);
407 0 : pHyper->SetStyleName(GetStyleName());
408 0 : pXFPara->Add(pHyper);
409 0 : }
410 :
411 : /**
412 : * @descr: Get the current frib font style
413 : * @return: XFFont pointer
414 : */
415 0 : XFFont* LwpFrib::GetFont()
416 : {
417 0 : XFFont* pFont = NULL;
418 0 : if(m_pModifiers&&m_pModifiers->FontID)
419 : {
420 0 : LwpFoundry* pFoundry = m_pPara->GetFoundry();
421 0 : pFont = pFoundry->GetFontManger()->CreateFont(m_pModifiers->FontID);
422 : }
423 : else
424 : {
425 0 : XFParaStyle* pXFParaStyle = m_pPara->GetXFParaStyle();
426 0 : pFont = pXFParaStyle->GetFont();
427 : }
428 0 : return pFont;
429 : }
430 :
431 0 : OUString LwpFrib::GetEditor()
432 : {
433 0 : LwpGlobalMgr* pGlobal = LwpGlobalMgr::GetInstance();
434 0 : return pGlobal->GetEditorName(m_nEditor);
435 : }
436 :
437 0 : XFColor LwpFrib::GetHighlightColor()
438 : {
439 0 : LwpGlobalMgr* pGlobal = LwpGlobalMgr::GetInstance();
440 0 : return pGlobal->GetHighlightColor(m_nEditor);
441 : }
442 :
443 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|