Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / lotuswordpro / source / filter / lwpfribtext.cxx
blob1d2c61ed4b84a44f51e8f887d29f08d21b726b8c
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 ************************************************************************/
61 #include "lwpglobalmgr.hxx"
62 #include "lwpfribtext.hxx"
63 #include "lwpcharsetmgr.hxx"
64 #include "lwphyperlinkmgr.hxx"
65 #include "lwptools.hxx"
66 #include "xfilter/xfstylemanager.hxx"
67 #include "xfilter/xftextspan.hxx"
68 #include "xfilter/xfbookmark.hxx"
69 #include "xfilter/xfentry.hxx"
70 #include "xfilter/xftextcontent.hxx"
71 #include "xfilter/xfcrossref.hxx"
72 #include "xfilter/xfpagenumber.hxx"
73 #include "xfilter/xfdocfield.hxx"
74 #include "xfilter/xfdatestyle.hxx"
75 #include "xfilter/xftimestyle.hxx"
76 #include "xfilter/xfdate.hxx"
77 #include "xfilter/xfannotation.hxx"
79 LwpFribText::LwpFribText( LwpPara *pPara, bool bNoUnicode )
80 : LwpFrib(pPara), m_bNoUnicode(bNoUnicode)
83 void LwpFribText::Read(LwpObjectStream* pObjStrm, sal_uInt16 len)
85 if( len>=1 )
87 rtl_TextEncoding rEncode;
88 if(m_bNoUnicode)
90 rEncode = RTL_TEXTENCODING_ISO_8859_1;
92 else
94 if (m_pModifiers && m_pModifiers->CodePage)
95 rEncode = LwpCharSetMgr::GetInstance()->
96 GetTextCharEncoding(m_pModifiers->CodePage);
97 else
98 rEncode = LwpCharSetMgr::GetTextCharEncoding();
100 LwpTools::QuickReadUnicode(pObjStrm, m_Content, len, rEncode);
104 void LwpFribText::XFConvert(XFContentContainer* pXFPara,LwpStory* pStory)
106 if (!pStory)
107 return;
108 LwpHyperlinkMgr* pHyperlink = pStory->GetHyperlinkMgr();
109 if (pHyperlink->GetHyperlinkFlag())
110 LwpFrib::ConvertHyperLink(pXFPara,pHyperlink,GetText());
111 else
112 LwpFrib::ConvertChars(pXFPara,GetText());
116 * @short: Reading mothed of paranumber frib.
117 * @param: pObjStrm wordpro object stream.
118 * @param: len length of the frib
120 void LwpFribParaNumber::Read(LwpObjectStream* pObjStrm, sal_uInt16 /*len*/)
122 m_nStyleID = pObjStrm->QuickReaduInt16();
123 m_nNumberChar = pObjStrm->QuickReaduInt16();
124 m_nLevel = pObjStrm->QuickReaduInt16();
125 m_nStart = pObjStrm->QuickReaduInt16();
129 * @short: default constructor of LwpFribDocVar
131 LwpFribDocVar::LwpFribDocVar(LwpPara* pPara)
132 : LwpFrib(pPara), m_nType(0), m_pName(new LwpAtomHolder)
136 * @short: destructor of LwpFribDocVar
138 LwpFribDocVar::~LwpFribDocVar()
140 if (m_pName)
142 delete m_pName;
143 m_pName = nullptr;
147 * @short: Reading mothed of document variable frib.
148 * @param: pObjStrm wordpro object stream.
149 * @param: len length of the frib
151 void LwpFribDocVar::Read(LwpObjectStream* pObjStrm, sal_uInt16 /*len*/)
153 m_nType = pObjStrm->QuickReaduInt16();
154 m_pName->Read(pObjStrm);
158 * @short: register style for doc field (text style,date style)
160 void LwpFribDocVar::RegisterStyle(LwpFoundry* pFoundry)
162 LwpFrib::RegisterStyle(pFoundry);
164 switch(m_nType)
166 case DATECREATED:
167 case DATELASTREVISION:
169 RegisterDefaultTimeStyle();
171 break;
172 case TOTALEDITTIME:
173 RegisterTotalTimeStyle();
174 break;
175 default:
176 break;
181 * @short: register default time style for doc field
183 void LwpFribDocVar::RegisterDefaultTimeStyle()
185 XFDateStyle* pDateStyle = new XFDateStyle;//use the default format
187 pDateStyle->AddMonth();
188 pDateStyle->AddText("/");
189 pDateStyle->AddMonthDay();
190 pDateStyle->AddText("/");
191 pDateStyle->AddYear();
192 pDateStyle->AddText(",");
193 pDateStyle->AddHour();
194 pDateStyle->AddText(":");
195 pDateStyle->AddMinute();
196 pDateStyle->AddText(":");
197 pDateStyle->AddSecond();
199 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
200 m_TimeStyle = pXFStyleManager->AddStyle(pDateStyle).m_pStyle->GetStyleName();
202 void LwpFribDocVar::RegisterTotalTimeStyle()
204 XFTimeStyle* pTimeStyle = new XFTimeStyle;//use the default format
205 pTimeStyle->SetTruncate(false);
206 pTimeStyle->AddMinute();
207 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
208 m_TimeStyle = pXFStyleManager->AddStyle(pTimeStyle).m_pStyle->GetStyleName();
212 * @short: convert the doc info field
214 void LwpFribDocVar::XFConvert(XFContentContainer* pXFPara)
216 XFContent* pContent=nullptr;
217 switch(m_nType)
219 case FILENAME:
221 pContent = new XFFileName;
222 static_cast<XFFileName*>(pContent)->SetType("FileName");
223 break;
225 case PATH:
227 pContent = new XFFileName;
228 static_cast<XFFileName*>(pContent)->SetType("Path");
229 break;
231 case DESCRIPTION:
232 pContent = new XFDescription;
233 break;
234 case DATECREATED:
236 pContent = new XFCreateTime;
237 pContent->SetStyleName(m_TimeStyle);
238 break;
240 case DATELASTREVISION:
242 pContent = new XFLastEditTime;
243 pContent->SetStyleName(m_TimeStyle);
244 break;
246 case NUMPAGES:
247 pContent = new XFPageCount;
248 break;
249 case NUMWORDS:
250 pContent = new XFWordCount;
251 break;
252 case NUMCHARS:
253 pContent = new XFCharCount;
254 break;
255 case TOTALEDITTIME:
257 pContent = new XFTotalEditTime;
258 pContent->SetStyleName(m_TimeStyle);
259 break;
261 case KEYWORDS:
262 pContent = new XFKeywords;
263 break;
264 case CREATEDBY:
265 pContent = new XFInitialCreator;
266 break;
267 case DOCSIZE:
269 /* pContent = new XFAnnotation;
270 XFTextContent* pSpan = new XFTextContent();
271 pSpan->SetText("Document Size is Here");
272 XFParagraph* pPara = new XFParagraph;
273 pPara->Add(pSpan);
274 static_cast<XFAnnotation*>(pContent)->Add(pPara);
275 break;
277 OUString text = "<Document Size>";
278 LwpFrib::ConvertChars(pXFPara,text);
279 return;
281 case SMARTMASTER:
283 OUString text = "<Smart master>";
284 LwpFrib::ConvertChars(pXFPara,text);
285 return;
287 case DIVISIONNAME:
289 OUString text = "<Division name>";
290 LwpFrib::ConvertChars(pXFPara,text);
291 return;
293 case SECTIONNAME:
295 OUString text = "<Section name>";
296 LwpFrib::ConvertChars(pXFPara,text);
297 return;
299 case VERSIONCREATEBY:
301 OUString text = "<Version Creat by>";
302 LwpFrib::ConvertChars(pXFPara,text);
303 return;
305 case VERSIONCREATEDATE:
307 OUString text = "<Version Creat date>";
308 LwpFrib::ConvertChars(pXFPara,text);
309 return;
311 case VERSIONOTHEREDITORS:
313 OUString text = "<Version other Editors>";
314 LwpFrib::ConvertChars(pXFPara,text);
315 return;
317 case VERSIONNAME:
319 OUString text = "<Version Name>";
320 LwpFrib::ConvertChars(pXFPara,text);
321 return;
323 case VERSIONNUMBER:
325 OUString text = "<Version Numbers>";
326 LwpFrib::ConvertChars(pXFPara,text);
327 return;
329 case ALLVERSIONNAME:
331 OUString text = "<All Version Name>";
332 LwpFrib::ConvertChars(pXFPara,text);
333 return;
335 case VERSIONREMARK:
337 OUString text = "<Version Remark>";
338 LwpFrib::ConvertChars(pXFPara,text);
339 return;
341 case DOCUMENTCATEGORY:
343 OUString text = "<Document Category>";
344 LwpFrib::ConvertChars(pXFPara,text);
345 return;
347 case VERSIONLASTDATE:
349 OUString text = "<Version Last Modify Date>";
350 LwpFrib::ConvertChars(pXFPara,text);
351 return;
353 case VERSIONLASTEDITOR:
355 OUString text = "<Version Last Editor>";
356 LwpFrib::ConvertChars(pXFPara,text);
357 return;
359 case LASTEDIT:
361 OUString text = "<Last Editor>";
362 LwpFrib::ConvertChars(pXFPara,text);
363 return;
365 case OTHEREDITORS:
367 OUString text = "<Other Editors>";
368 LwpFrib::ConvertChars(pXFPara,text);
369 return;
371 case NUMOFREVISION:
373 OUString text = "<Number of Revision>";
374 LwpFrib::ConvertChars(pXFPara,text);
375 return;
377 default:
378 return;
380 if (m_ModFlag)//(m_pModifiers)
382 XFTextSpan *pSpan = new XFTextSpan;
383 pSpan->SetStyleName(GetStyleName());
384 pSpan->Add(pContent);
385 pXFPara->Add(pSpan);
387 else
388 pXFPara->Add(pContent);
392 * @short: Read unicode
394 void LwpFribUnicode::Read(LwpObjectStream* pObjStrm, sal_uInt16 len)
396 if(len>1)
398 rtl_TextEncoding rEncode;
400 if (m_pModifiers && m_pModifiers->CodePage)
401 rEncode = LwpCharSetMgr::GetInstance()->
402 GetTextCharEncoding(m_pModifiers->CodePage);
403 else
404 rEncode = LwpCharSetMgr::GetTextCharEncoding();
406 LwpTools::QuickReadUnicode(pObjStrm, m_Content, len, rEncode);
409 else
410 pObjStrm->SeekRel(len);
413 void LwpFribUnicode::XFConvert(XFContentContainer* pXFPara,LwpStory* pStory)
415 if (!pStory)
416 return;
417 LwpHyperlinkMgr* pHyperlink = pStory->GetHyperlinkMgr();
418 if (pHyperlink->GetHyperlinkFlag())
419 LwpFrib::ConvertHyperLink(pXFPara,pHyperlink,GetText());
420 else
421 LwpFrib::ConvertChars(pXFPara,GetText());
425 * @short: Read page number
427 void LwpFribPageNumber::Read(LwpObjectStream* pObjStrm, sal_uInt16 /*len*/)
429 m_nNumStyle = pObjStrm->QuickReaduInt16();
430 m_aBefText.Read(pObjStrm);
431 m_aAfterText.Read(pObjStrm);
432 m_nStartNum = pObjStrm->QuickReaduInt16();
433 m_nStartOnPage = pObjStrm->QuickReaduInt16();
434 m_nFlag = pObjStrm->QuickReaduInt16();
437 void LwpFribPageNumber::XFConvert(XFContentContainer* pXFPara)
439 if (m_nNumStyle == 0x0)
440 return;
441 XFPageNumber* pNum = new XFPageNumber;
442 // pNum->SetSelect("current");
443 switch(m_nNumStyle)
445 case 0x01:
446 pNum->SetNumFmt("1");
447 break;
448 case 0x02:
449 pNum->SetNumFmt("A");
450 break;
451 case 0x03:
452 pNum->SetNumFmt("a");
453 break;
454 case 0x04:
455 pNum->SetNumFmt("I");
456 break;
457 case 0x05:
458 pNum->SetNumFmt("i");
459 break;
461 OUString styleName = GetStyleName();
462 if (!m_aBefText.str().isEmpty())
464 OUString textStr = m_aBefText.str();
465 XFTextSpan *pBef = new XFTextSpan(textStr,styleName);
466 pXFPara->Add(pBef);
468 if (m_ModFlag)//(m_pModifiers)
470 XFTextSpan *pSpan = new XFTextSpan;
471 pSpan->SetStyleName(styleName);
472 pSpan->Add(pNum);
473 pXFPara->Add(pSpan);
475 else
476 pXFPara->Add(pNum);
477 if (!m_aAfterText.str().isEmpty())
479 OUString textStr = m_aAfterText.str();
480 XFTextSpan *pAfter = new XFTextSpan(textStr,styleName);
481 pXFPara->Add(pAfter);
485 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */