fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / lotuswordpro / source / filter / lwpfribtext.cxx
blobc87818f3007c3bf94ce70ff497694c270064f485
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 "lwpglobalmgr.hxx"
65 #include "lwpfribtext.hxx"
66 #include "lwpcharsetmgr.hxx"
67 #include "lwphyperlinkmgr.hxx"
68 #include "lwptools.hxx"
69 #include "xfilter/xfstylemanager.hxx"
70 #include "xfilter/xftextspan.hxx"
71 #include "xfilter/xfbookmark.hxx"
72 #include "xfilter/xfentry.hxx"
73 #include "xfilter/xftextcontent.hxx"
74 #include "xfilter/xfcrossref.hxx"
75 #include "xfilter/xfpagenumber.hxx"
76 #include "xfilter/xfdocfield.hxx"
77 #include "xfilter/xfdatestyle.hxx"
78 #include "xfilter/xftimestyle.hxx"
79 #include "xfilter/xfdate.hxx"
80 #include "xfilter/xfannotation.hxx"
82 LwpFribText::LwpFribText( LwpPara *pPara, bool bNoUnicode )
83 : LwpFrib(pPara), m_bNoUnicode(bNoUnicode)
86 void LwpFribText::Read(LwpObjectStream* pObjStrm, sal_uInt16 len)
88 if( len>=1 )
90 rtl_TextEncoding rEncode;
91 if(m_bNoUnicode)
93 rEncode = RTL_TEXTENCODING_ISO_8859_1;
95 else
97 if (m_pModifiers && m_pModifiers->CodePage)
98 rEncode = LwpCharSetMgr::GetInstance()->
99 GetTextCharEncoding(m_pModifiers->CodePage);
100 else
101 rEncode = LwpCharSetMgr::GetTextCharEncoding();
103 LwpTools::QuickReadUnicode(pObjStrm, m_Content, len, rEncode);
107 void LwpFribText::XFConvert(XFContentContainer* pXFPara,LwpStory* pStory)
109 if (!pStory)
110 return;
111 LwpHyperlinkMgr* pHyperlink = pStory->GetHyperlinkMgr();
112 if (pHyperlink->GetHyperlinkFlag())
113 LwpFrib::ConvertHyperLink(pXFPara,pHyperlink,GetText());
114 else
115 LwpFrib::ConvertChars(pXFPara,GetText());
119 * @short: Reading mothed of paranumber frib.
120 * @param: pObjStrm wordpro object stream.
121 * @param: len length of the frib
123 void LwpFribParaNumber::Read(LwpObjectStream* pObjStrm, sal_uInt16 /*len*/)
125 m_nStyleID = pObjStrm->QuickReaduInt16();
126 m_nNumberChar = pObjStrm->QuickReaduInt16();
127 m_nLevel = pObjStrm->QuickReaduInt16();
128 m_nStart = pObjStrm->QuickReaduInt16();
132 * @short: default constructor of LwpFribDocVar
134 LwpFribDocVar::LwpFribDocVar(LwpPara* pPara)
135 : LwpFrib(pPara), m_nType(0), m_pName(new LwpAtomHolder)
139 * @short: destructor of LwpFribDocVar
141 LwpFribDocVar::~LwpFribDocVar()
143 if (m_pName)
145 delete m_pName;
146 m_pName = NULL;
150 * @short: Reading mothed of document variable frib.
151 * @param: pObjStrm wordpro object stream.
152 * @param: len length of the frib
154 void LwpFribDocVar::Read(LwpObjectStream* pObjStrm, sal_uInt16 /*len*/)
156 m_nType = pObjStrm->QuickReaduInt16();
157 m_pName->Read(pObjStrm);
161 * @short: register style for doc field (text style,date style)
162 * @param:
163 * @param:
165 void LwpFribDocVar::RegisterStyle(LwpFoundry* pFoundry)
167 LwpFrib::RegisterStyle(pFoundry);
169 switch(m_nType)
171 case DATECREATED:
172 case DATELASTREVISION:
174 // m_TimeStyle = LwpTools::RegisterDefaultTimeStyle();
175 RegisterDefaultTimeStyle();
177 break;
178 case TOTALEDITTIME:
179 RegisterTotalTimeStyle();
180 break;
181 default:
182 break;
187 * @short: register default time style for doc field
188 * @param:
189 * @param:
191 void LwpFribDocVar::RegisterDefaultTimeStyle()
193 XFDateStyle* pDateStyle = new XFDateStyle;//use the default format
195 pDateStyle->AddMonth();
196 pDateStyle->AddText("/");
197 pDateStyle->AddMonthDay();
198 pDateStyle->AddText("/");
199 pDateStyle->AddYear();
200 pDateStyle->AddText(",");
201 pDateStyle->AddHour();
202 pDateStyle->AddText(":");
203 pDateStyle->AddMinute();
204 pDateStyle->AddText(":");
205 pDateStyle->AddSecond(true,0);
207 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
208 m_TimeStyle = pXFStyleManager->AddStyle(pDateStyle).m_pStyle->GetStyleName();
210 void LwpFribDocVar::RegisterTotalTimeStyle()
212 XFTimeStyle* pTimeStyle = new XFTimeStyle;//use the default format
213 pTimeStyle->SetTruncate(false);
214 pTimeStyle->AddMinute();
215 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
216 m_TimeStyle = pXFStyleManager->AddStyle(pTimeStyle).m_pStyle->GetStyleName();
220 * @short: convert the doc info field
221 * @param:
222 * @param:
224 void LwpFribDocVar::XFConvert(XFContentContainer* pXFPara)
226 XFContent* pContent=NULL;
227 switch(m_nType)
229 case FILENAME:
231 pContent = new XFFileName;
232 static_cast<XFFileName*>(pContent)->SetType("FileName");
233 break;
235 case PATH:
237 pContent = new XFFileName;
238 static_cast<XFFileName*>(pContent)->SetType("Path");
239 break;
241 case DESCRIPTION:
242 pContent = new XFDescription;
243 break;
244 case DATECREATED:
246 pContent = new XFCreateTime;
247 pContent->SetStyleName(m_TimeStyle);
248 break;
250 case DATELASTREVISION:
252 pContent = new XFLastEditTime;
253 pContent->SetStyleName(m_TimeStyle);
254 break;
256 case NUMPAGES:
257 pContent = new XFPageCount;
258 break;
259 case NUMWORDS:
260 pContent = new XFWordCount;
261 break;
262 case NUMCHARS:
263 pContent = new XFCharCount;
264 break;
265 case TOTALEDITTIME:
267 pContent = new XFTotalEditTime;
268 pContent->SetStyleName(m_TimeStyle);
269 break;
271 case KEYWORDS:
272 pContent = new XFKeywords;
273 break;
274 case CREATEDBY:
275 pContent = new XFInitialCreator;
276 break;
277 case DOCSIZE:
279 /* pContent = new XFAnnotation;
280 XFTextContent* pSpan = new XFTextContent();
281 pSpan->SetText("Document Size is Here");
282 XFParagraph* pPara = new XFParagraph;
283 pPara->Add(pSpan);
284 static_cast<XFAnnotation*>(pContent)->Add(pPara);
285 break;
287 OUString text = "<Document Size>";
288 LwpFrib::ConvertChars(pXFPara,text);
289 return;
291 case SMARTMASTER:
293 OUString text = "<Smart master>";
294 LwpFrib::ConvertChars(pXFPara,text);
295 return;
297 case DIVISIONNAME:
299 OUString text = "<Division name>";
300 LwpFrib::ConvertChars(pXFPara,text);
301 return;
303 case SECTIONNAME:
305 OUString text = "<Section name>";
306 LwpFrib::ConvertChars(pXFPara,text);
307 return;
309 case VERSIONCREATEBY:
311 OUString text = "<Version Creat by>";
312 LwpFrib::ConvertChars(pXFPara,text);
313 return;
315 case VERSIONCREATEDATE:
317 OUString text = "<Version Creat date>";
318 LwpFrib::ConvertChars(pXFPara,text);
319 return;
321 case VERSIONOTHEREDITORS:
323 OUString text = "<Version other Editors>";
324 LwpFrib::ConvertChars(pXFPara,text);
325 return;
327 case VERSIONNAME:
329 OUString text = "<Version Name>";
330 LwpFrib::ConvertChars(pXFPara,text);
331 return;
333 case VERSIONNUMBER:
335 OUString text = "<Version Numbers>";
336 LwpFrib::ConvertChars(pXFPara,text);
337 return;
339 case ALLVERSIONNAME:
341 OUString text = "<All Version Name>";
342 LwpFrib::ConvertChars(pXFPara,text);
343 return;
345 case VERSIONREMARK:
347 OUString text = "<Version Remark>";
348 LwpFrib::ConvertChars(pXFPara,text);
349 return;
351 case DOCUMENTCATEGORY:
353 OUString text = "<Document Category>";
354 LwpFrib::ConvertChars(pXFPara,text);
355 return;
357 case VERSIONLASTDATE:
359 OUString text = "<Version Last Modify Date>";
360 LwpFrib::ConvertChars(pXFPara,text);
361 return;
363 case VERSIONLASTEDITOR:
365 OUString text = "<Version Last Editor>";
366 LwpFrib::ConvertChars(pXFPara,text);
367 return;
369 case LASTEDIT:
371 OUString text = "<Last Editor>";
372 LwpFrib::ConvertChars(pXFPara,text);
373 return;
375 case OTHEREDITORS:
377 OUString text = "<Other Editors>";
378 LwpFrib::ConvertChars(pXFPara,text);
379 return;
381 case NUMOFREVISION:
383 OUString text = "<Number of Revision>";
384 LwpFrib::ConvertChars(pXFPara,text);
385 return;
387 default:
388 return;
390 if (m_ModFlag)//(m_pModifiers)
392 XFTextSpan *pSpan = new XFTextSpan;
393 pSpan->SetStyleName(GetStyleName());
394 pSpan->Add(pContent);
395 pXFPara->Add(pSpan);
397 else
398 pXFPara->Add(pContent);
402 * @short: Read unicode
403 * @param:
404 * @param:
406 void LwpFribUnicode::Read(LwpObjectStream* pObjStrm, sal_uInt16 len)
408 if(len>1)
410 rtl_TextEncoding rEncode;
412 if (m_pModifiers && m_pModifiers->CodePage)
413 rEncode = LwpCharSetMgr::GetInstance()->
414 GetTextCharEncoding(m_pModifiers->CodePage);
415 else
416 rEncode = LwpCharSetMgr::GetTextCharEncoding();
418 LwpTools::QuickReadUnicode(pObjStrm, m_Content, len, rEncode);
421 else
422 pObjStrm->SeekRel(len);
425 void LwpFribUnicode::XFConvert(XFContentContainer* pXFPara,LwpStory* pStory)
427 if (!pStory)
428 return;
429 LwpHyperlinkMgr* pHyperlink = pStory->GetHyperlinkMgr();
430 if (pHyperlink->GetHyperlinkFlag())
431 LwpFrib::ConvertHyperLink(pXFPara,pHyperlink,GetText());
432 else
433 LwpFrib::ConvertChars(pXFPara,GetText());
437 * @short: Read page number
438 * @param:
439 * @param:
441 void LwpFribPageNumber::Read(LwpObjectStream* pObjStrm, sal_uInt16 /*len*/)
443 m_nNumStyle = pObjStrm->QuickReaduInt16();
444 m_aBefText.Read(pObjStrm);
445 m_aAfterText.Read(pObjStrm);
446 m_nStartNum = pObjStrm->QuickReaduInt16();
447 m_nStartOnPage = pObjStrm->QuickReaduInt16();
448 m_nFlag = pObjStrm->QuickReaduInt16();
451 void LwpFribPageNumber::XFConvert(XFContentContainer* pXFPara)
453 if (m_nNumStyle == 0x0)
454 return;
455 XFPageNumber* pNum = new XFPageNumber;
456 // pNum->SetSelect("current");
457 switch(m_nNumStyle)
459 case 0x01:
460 pNum->SetNumFmt("1");
461 break;
462 case 0x02:
463 pNum->SetNumFmt("A");
464 break;
465 case 0x03:
466 pNum->SetNumFmt("a");
467 break;
468 case 0x04:
469 pNum->SetNumFmt("I");
470 break;
471 case 0x05:
472 pNum->SetNumFmt("i");
473 break;
475 OUString styleName = GetStyleName();
476 if (!m_aBefText.str().isEmpty())
478 OUString textStr = m_aBefText.str();
479 XFTextSpan *pBef = new XFTextSpan(textStr,styleName);
480 pXFPara->Add(pBef);
482 if (m_ModFlag)//(m_pModifiers)
484 XFTextSpan *pSpan = new XFTextSpan;
485 pSpan->SetStyleName(styleName);
486 pSpan->Add(pNum);
487 pXFPara->Add(pSpan);
489 else
490 pXFPara->Add(pNum);
491 if (!m_aAfterText.str().isEmpty())
493 OUString textStr = m_aAfterText.str();
494 XFTextSpan *pAfter = new XFTextSpan(textStr,styleName);
495 pXFPara->Add(pAfter);
499 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */