Branch data 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 : 2607 : LwpFrib::LwpFrib(LwpPara* pPara)
89 : 2607 : : m_pPara(pPara), m_pNext(NULL)
90 : : {
91 : 2607 : m_ModFlag = sal_False;
92 : 2607 : m_pModifiers = NULL;
93 : 2607 : m_bRevisionFlag = sal_False;
94 : 2607 : }
95 : :
96 : 2607 : LwpFrib::~LwpFrib()
97 : : {
98 [ + + ]: 2607 : if(m_pModifiers)
99 [ + - ][ + - ]: 1749 : delete m_pModifiers;
100 [ - + ]: 3402 : }
101 : :
102 : 2607 : LwpFrib* LwpFrib::CreateFrib(LwpPara* pPara, LwpObjectStream* pObjStrm, sal_uInt8 fribtag,sal_uInt8 editID)
103 : : {
104 : : //Read Modifier
105 : 2607 : ModifierInfo* pModInfo = NULL;
106 [ + + ]: 2607 : if(fribtag & FRIB_TAG_MODIFIER)
107 : : {
108 [ + - ]: 1749 : pModInfo = new ModifierInfo();
109 : 1749 : pModInfo->CodePage = 0;
110 : 1749 : pModInfo->FontID = 0;
111 : 1749 : pModInfo->RevisionFlag = sal_False;
112 : 1749 : pModInfo->HasCharStyle = sal_False;
113 : 1749 : pModInfo->HasLangOverride = sal_False;
114 : 1749 : pModInfo->HasHighLight = sal_False;
115 : 1749 : ReadModifiers( pObjStrm, pModInfo );
116 : : }
117 : :
118 : : //Read frib data
119 : 2607 : LwpFrib* newFrib = NULL;
120 : 2607 : sal_uInt16 friblen = pObjStrm->QuickReaduInt16();
121 : 2607 : sal_uInt8 fribtype = fribtag&~FRIB_TAG_TYPEMASK;
122 [ + + + + : 2607 : switch(fribtype)
+ + + - -
- - + - -
- + + - +
- - - ]
123 : : {
124 : : case FRIB_TAG_INVALID: //fall through
125 : : case FRIB_TAG_EOP: //fall through
126 : : default:
127 : 795 : newFrib = new LwpFrib(pPara);
128 : 795 : break;
129 : : case FRIB_TAG_TEXT:
130 : : {
131 [ + - ]: 1230 : newFrib = new LwpFribText (pPara, fribtag & FRIB_TAG_NOUNICODE);
132 : 1230 : break;
133 : : }
134 : : case FRIB_TAG_TABLE:
135 [ + - ]: 3 : newFrib = new LwpFribTable(pPara);
136 : 3 : break;
137 : : case FRIB_TAG_TAB:
138 [ + - ]: 93 : newFrib = new LwpFribTab(pPara);
139 : 93 : break;
140 : : case FRIB_TAG_PAGEBREAK:
141 [ + - ]: 27 : newFrib = new LwpFribPageBreak(pPara);
142 : 27 : break;
143 : : case FRIB_TAG_FRAME:
144 [ + - ]: 78 : newFrib = new LwpFribFrame(pPara);
145 : 78 : break;
146 : : case FRIB_TAG_FOOTNOTE:
147 [ + - ]: 3 : newFrib = new LwpFribFootnote(pPara);
148 : 3 : break;
149 : : case FRIB_TAG_COLBREAK:
150 [ # # ]: 0 : newFrib = new LwpFribColumnBreak(pPara);
151 : 0 : break;
152 : : case FRIB_TAG_LINEBREAK:
153 [ # # ]: 0 : newFrib = new LwpFribLineBreak(pPara);
154 : 0 : break;
155 : : case FRIB_TAG_HARDSPACE:
156 [ # # ]: 0 : newFrib = new LwpFribHardSpace(pPara);
157 : 0 : break;
158 : : case FRIB_TAG_SOFTHYPHEN:
159 [ # # ]: 0 : newFrib = new LwpFribSoftHyphen(pPara);
160 : 0 : break;
161 : : case FRIB_TAG_PARANUMBER:
162 [ + - ]: 327 : newFrib = new LwpFribParaNumber(pPara);
163 : 327 : break;
164 : : case FRIB_TAG_UNICODE: //fall through
165 : : case FRIB_TAG_UNICODE2: //fall through
166 : : case FRIB_TAG_UNICODE3: //fall through
167 [ # # ]: 0 : newFrib = new LwpFribUnicode(pPara);
168 : 0 : break;
169 : : case FRIB_TAG_NOTE:
170 [ # # ]: 0 : newFrib = new LwpFribNote(pPara);
171 : 0 : break;
172 : : /* case FRIB_TAG_KANJI:
173 : : #ifdef KANJI
174 : : newFrib = new CFribHelperKanji;
175 : : #else
176 : : newFrib = new CFribHelperUnicode;
177 : : #endif
178 : : break;
179 : : case FRIB_TAG_HKATAKANA:
180 : : #ifdef KANJI
181 : : newFrib = new CFribHelperHKatakana;
182 : : #else
183 : : newFrib = new CFribHelperUnicode;
184 : : #endif
185 : : break;
186 : : case FRIB_TAG_SEPARATOR:
187 : : newFrib = new CFribHelperSeparator;
188 : : break;*/
189 : : case FRIB_TAG_SECTION:
190 [ # # ]: 0 : newFrib = new LwpFribSection(pPara);
191 : 0 : break;
192 : : /* case FRIB_TAG_TOMBSTONE:
193 : : newFrib = new CFribHelperTombstone;
194 : : break;
195 : : case FRIB_TAG_SPECIALTAB:
196 : : newFrib = new CFribHelperSpecialTab;
197 : : break;
198 : : case FRIB_TAG_PAGENUMBER:
199 : : newFrib = new CFribHelperPageNumber;
200 : : break;
201 : : */ case FRIB_TAG_PAGENUMBER:
202 [ + - ]: 15 : newFrib = new LwpFribPageNumber(pPara);
203 : 15 : break;
204 : : case FRIB_TAG_DOCVAR:
205 [ + - ]: 18 : newFrib = new LwpFribDocVar(pPara);
206 : 18 : break;
207 : : case FRIB_TAG_BOOKMARK:
208 [ # # ]: 0 : newFrib = new LwpFribBookMark(pPara);
209 : 0 : break;
210 : : /* case FRIB_TAG_DOCVAR:
211 : : newFrib = new CFribHelperBookmark;
212 : : break;
213 : : case FRIB_TAG_DDE:
214 : : newFrib = new CFribHelperDDE;
215 : : break;
216 : : */ case FRIB_TAG_FIELD:
217 [ + - ]: 18 : newFrib = new LwpFribField(pPara);
218 : 18 : break;
219 : : case FRIB_TAG_CHBLOCK:
220 [ # # ]: 0 : newFrib = new LwpFribCHBlock(pPara);
221 : 0 : break;
222 : : /* case FRIB_TAG_FLOWBREAK:
223 : : newFrib = new CFribHelperFlowBreak;
224 : : break;
225 : : #ifdef RUBY*/
226 : : case FRIB_TAG_RUBYMARKER:
227 [ # # ]: 0 : newFrib = new LwpFribRubyMarker(pPara);
228 : 0 : break;
229 : : case FRIB_TAG_RUBYFRAME:
230 [ # # ]: 0 : newFrib = new LwpFribRubyFrame(pPara);
231 : 0 : break;
232 : : /*#endif
233 : : */
234 : : }
235 : :
236 : : //Do not know why the fribTag judgement is necessary, to be checked with
237 [ + + ]: 2607 : if ( fribtag & FRIB_TAG_MODIFIER )
238 : : {
239 : 1749 : newFrib->SetModifiers(pModInfo);
240 : : }
241 : :
242 : 2607 : newFrib->SetType(fribtype);
243 : 2607 : newFrib->SetEditor(editID);
244 : 2607 : newFrib->Read(pObjStrm, friblen);
245 : 2607 : return newFrib;
246 : : }
247 : :
248 : 888 : void LwpFrib::Read(LwpObjectStream* pObjStrm, sal_uInt16 len)
249 : : {
250 : 888 : pObjStrm->SeekRel(len);
251 : 888 : }
252 : :
253 : 1749 : void LwpFrib::SetModifiers(ModifierInfo* pModifiers)
254 : : {
255 [ + - ]: 1749 : if (pModifiers)
256 : : {
257 : 1749 : m_pModifiers = pModifiers;
258 : 1749 : m_ModFlag = sal_True;
259 [ - + ]: 1749 : if (pModifiers->RevisionFlag)
260 : : {
261 : 0 : m_bRevisionFlag = sal_True;
262 : 0 : m_nRevisionType = pModifiers->RevisionType;
263 : : }
264 : : }
265 : 1749 : }
266 : :
267 : 1296 : void LwpFrib::RegisterStyle(LwpFoundry* pFoundry)
268 : : {
269 [ + + ]: 1296 : if (!m_pModifiers)
270 : 384 : return;
271 [ + + ][ + - ]: 912 : if (!m_pModifiers->FontID && !m_pModifiers->HasCharStyle && !m_pModifiers->HasHighLight)
[ + - ]
272 : : {
273 : 372 : m_ModFlag = sal_False;
274 : 372 : return;
275 : : }
276 : : //we only read four modifiers, in these modifiers,CodePage and LangOverride are not styles,
277 : : //so we can only handle fontid and characstyle, if others ,we should not reg style
278 : : //note by ,1-27
279 : : XFFont* pFont;
280 : 540 : XFTextStyle* pStyle = NULL;
281 : 540 : m_StyleName = A2OUSTR("");
282 : 540 : XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
283 [ - + ]: 540 : if (m_pModifiers->HasCharStyle)
284 : : {
285 : : XFTextStyle* pNamedStyle = static_cast<XFTextStyle*>
286 : 0 : (pFoundry->GetStyleManager()->GetStyle(m_pModifiers->CharStyleID));
287 [ # # ]: 0 : if (m_pModifiers->FontID)
288 : : {
289 [ # # ]: 0 : pStyle = new XFTextStyle();
290 : 0 : *pStyle = *pNamedStyle;
291 : 0 : LwpCharacterStyle* pCharStyle = static_cast<LwpCharacterStyle*>(m_pModifiers->CharStyleID.obj());
292 : :
293 [ # # ]: 0 : pStyle->SetStyleName(A2OUSTR(""));
294 : 0 : pFont = pFoundry->GetFontManger()->CreateOverrideFont(pCharStyle->GetFinalFontID(),m_pModifiers->FontID);
295 : 0 : pStyle->SetFont(pFont);
296 : 0 : m_StyleName = pXFStyleManager->AddStyle(pStyle)->GetStyleName();
297 : : }
298 : : else
299 : 0 : m_StyleName = pNamedStyle->GetStyleName();
300 : : }
301 : : else
302 : : {
303 [ + - ]: 540 : if (m_pModifiers->FontID)
304 : : {
305 [ + - ]: 540 : pStyle = new XFTextStyle();
306 : 540 : pFont = pFoundry->GetFontManger()->CreateFont(m_pModifiers->FontID);
307 : 540 : pStyle->SetFont(pFont);
308 : 540 : m_StyleName = pXFStyleManager->AddStyle(pStyle)->GetStyleName();
309 : : }
310 : : }
311 : :
312 [ - + ]: 540 : if (m_pModifiers->HasHighLight)
313 : : {
314 [ # # ]: 0 : XFColor aColor = GetHighLightColor();//right yellow
315 [ # # ]: 0 : if (pStyle)//change the style directly
316 : 0 : pStyle->GetFont()->SetBackColor(aColor);
317 : : else //register a new style
318 : : {
319 [ # # ][ # # ]: 0 : pStyle = new XFTextStyle();
320 : :
321 [ # # ]: 0 : if (!m_StyleName.isEmpty())
322 : : {
323 [ # # ]: 0 : XFTextStyle* pOldStyle = pXFStyleManager->FindTextStyle(m_StyleName);
324 : 0 : *pStyle = *pOldStyle;
325 : 0 : pStyle->GetFont()->SetBackColor(aColor);
326 : : }
327 : : else
328 : : {
329 [ # # ][ # # ]: 0 : pFont = new XFFont;
330 : 0 : pFont->SetBackColor(aColor);
331 [ # # ]: 0 : pStyle->SetFont(pFont);
332 : : }
333 [ # # ][ # # ]: 1296 : m_StyleName = pXFStyleManager->AddStyle(pStyle)->GetStyleName();
334 : : }
335 : : }
336 : : }
337 : :
338 : 3600 : void LwpFrib::ReadModifiers(LwpObjectStream* pObjStrm,ModifierInfo* pModInfo)
339 : : {
340 : 1851 : for(;;)
341 : : {
342 : : bool bFailure;
343 : :
344 : : // Get the modifier type
345 [ + - ]: 3600 : sal_uInt8 Modifier = pObjStrm->QuickReaduInt8(&bFailure);
346 [ + - ]: 3600 : if (bFailure)
347 : : break;
348 : :
349 : : // Stop when we hit the last modifier
350 [ + + ]: 3600 : if (Modifier == FRIB_MTAG_NONE)
351 : : break;
352 : :
353 : : // Get the modifier length
354 [ + - ]: 1851 : sal_uInt8 len = pObjStrm->QuickReaduInt8(&bFailure);
355 [ + - ]: 1851 : if (bFailure)
356 : : break;
357 : :
358 [ + - - + : 1851 : switch (Modifier)
+ - - ]
359 : : {
360 : : case FRIB_MTAG_FONT:
361 [ - + ]: 912 : if (len != sizeof(pModInfo->FontID))
362 : : {
363 : : OSL_FAIL("FRIB_MTAG_FONT entry wrong size\n");
364 [ # # ]: 0 : pObjStrm->SeekRel(len);
365 : : }
366 : : else
367 [ + - ]: 912 : pModInfo->FontID = pObjStrm->QuickReaduInt32();
368 : 912 : break;
369 : : case FRIB_MTAG_CHARSTYLE:
370 : 0 : pModInfo->HasCharStyle = sal_True;
371 [ # # ]: 0 : pModInfo->CharStyleID.ReadIndexed(pObjStrm);
372 : 0 : break;
373 : : case FRIB_MTAG_LANGUAGE:
374 : 0 : pModInfo->HasLangOverride = sal_True;
375 [ # # ]: 0 : pModInfo->Language.Read(pObjStrm);
376 : 0 : break;
377 : : case FRIB_MTAG_CODEPAGE:
378 [ - + ]: 156 : if (len != sizeof(pModInfo->CodePage))
379 : : {
380 : : OSL_FAIL("FRIB_MTAG_CODEPAGE entry wrong size\n");
381 [ # # ]: 0 : pObjStrm->SeekRel(len);
382 : : }
383 : : else
384 [ + - ]: 156 : pModInfo->CodePage = pObjStrm->QuickReaduInt16();
385 : 156 : break;
386 : : case FRIB_MTAG_ATTRIBUTE:
387 [ + - ]: 783 : pModInfo->aTxtAttrOverride.Read(pObjStrm);
388 [ + - ][ - + ]: 783 : if (pModInfo->aTxtAttrOverride.IsHighLight())
389 : 0 : pModInfo->HasHighLight = sal_True;
390 : 783 : break;
391 : : case FRIB_MTAG_REVISION:
392 [ # # ]: 0 : pModInfo->RevisionType = pObjStrm->QuickReaduInt8();
393 : 0 : pModInfo->RevisionFlag = sal_True;
394 : 0 : break;
395 : : default:
396 [ # # ]: 0 : pObjStrm->SeekRel(len);
397 : 0 : break;
398 : : }
399 : : // TODO: read the modifier data
400 : : }
401 : 1749 : }
402 : :
403 : : //do nothing
404 : : //void LwpFrib::Parse(IXFStream* pOutputStream)
405 : : //{}
406 : :
407 : : /**
408 : : * @descr: Whether there are other fribs following current frib.
409 : : * @return: Ture if having following fribs, or false.
410 : : */
411 : 75 : sal_Bool LwpFrib::HasNextFrib()
412 : : {
413 [ + - ][ + + ]: 75 : if (!GetNext() || GetNext()->GetType()==FRIB_TAG_EOP)
[ + + ]
414 : 66 : return sal_False;
415 : 75 : return sal_True;
416 : : }
417 : :
418 : 567 : void LwpFrib::ConvertChars(XFContentContainer* pXFPara,OUString text)
419 : : {
420 [ + + ]: 567 : if (m_ModFlag)
421 : : {
422 : 261 : OUString strStyleName = GetStyleName();
423 [ + - ][ + - ]: 261 : XFTextSpan *pSpan = new XFTextSpan(text,strStyleName);
424 [ + - ]: 261 : pXFPara->Add(pSpan);
425 : : }
426 : : else
427 : : {
428 : 306 : XFTextContent *pSpan = new XFTextContent();
429 : 306 : pSpan->SetText(text);
430 : 306 : pXFPara->Add(pSpan);
431 : : }
432 : 567 : }
433 : :
434 : 0 : void LwpFrib::ConvertHyperLink(XFContentContainer* pXFPara,LwpHyperlinkMgr* pHyperlink,OUString text)
435 : : {
436 : 0 : XFHyperlink* pHyper = new XFHyperlink;
437 : 0 : pHyper->SetHRef(pHyperlink->GetHyperlink());
438 : 0 : pHyper->SetText(text);
439 [ # # ]: 0 : pHyper->SetStyleName(GetStyleName());
440 : 0 : pXFPara->Add(pHyper);
441 : 0 : }
442 : :
443 : : /**
444 : : * @descr: Get the current frib font style
445 : : * @return: XFFont pointer
446 : : */
447 : 75 : XFFont* LwpFrib::GetFont()
448 : : {
449 : 75 : XFFont* pFont = NULL;
450 [ + + ][ + + ]: 75 : if(m_pModifiers&&m_pModifiers->FontID)
451 : : {
452 : 30 : LwpFoundry* pFoundry = m_pPara->GetFoundry();
453 : 30 : pFont = pFoundry->GetFontManger()->CreateFont(m_pModifiers->FontID);
454 : : }
455 : : else
456 : : {
457 : 45 : XFParaStyle* pXFParaStyle = m_pPara->GetXFParaStyle();
458 : 45 : pFont = pXFParaStyle->GetFont();
459 : : }
460 : 75 : return pFont;
461 : : }
462 : :
463 : 0 : OUString LwpFrib::GetEditor()
464 : : {
465 : 0 : LwpGlobalMgr* pGlobal = LwpGlobalMgr::GetInstance();
466 : 0 : return pGlobal->GetEditorName(m_nEditor);
467 : : }
468 : :
469 : 0 : XFColor LwpFrib::GetHighLightColor()
470 : : {
471 : 0 : LwpGlobalMgr* pGlobal = LwpGlobalMgr::GetInstance();
472 : 0 : return pGlobal->GetHighLightColor(m_nEditor);
473 : : }
474 : :
475 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|