Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / lotuswordpro / source / filter / lwpfribtext.cxx
blobb48050be6b4275919ba844715101a22e16ac6d39
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/xfpagenumber.hxx>
69 #include <xfilter/xfdocfield.hxx>
70 #include <xfilter/xfdatestyle.hxx>
71 #include <xfilter/xftimestyle.hxx>
72 #include <xfilter/xfpagecount.hxx>
74 LwpFribText::LwpFribText( LwpPara *pPara, bool bNoUnicode )
75 : LwpFrib(pPara), m_bNoUnicode(bNoUnicode)
78 void LwpFribText::Read(LwpObjectStream* pObjStrm, sal_uInt16 len)
80 if( len<1 )
81 return;
83 rtl_TextEncoding rEncode;
84 if(m_bNoUnicode)
86 rEncode = RTL_TEXTENCODING_ISO_8859_1;
88 else
90 if (m_pModifiers && m_pModifiers->CodePage)
91 rEncode = LwpCharSetMgr::GetInstance()->
92 GetTextCharEncoding(m_pModifiers->CodePage);
93 else
94 rEncode = LwpCharSetMgr::GetTextCharEncoding();
96 LwpTools::QuickReadUnicode(pObjStrm, m_Content, len, rEncode);
99 void LwpFribText::XFConvert(XFContentContainer* pXFPara,LwpStory* pStory)
101 if (!pStory)
102 return;
103 LwpHyperlinkMgr* pHyperlink = pStory->GetHyperlinkMgr();
104 if (pHyperlink->GetHyperlinkFlag())
105 LwpFrib::ConvertHyperLink(pXFPara,pHyperlink,GetText());
106 else
107 LwpFrib::ConvertChars(pXFPara,GetText());
111 * @short: Reading mothed of paranumber frib.
112 * @param: pObjStrm wordpro object stream.
113 * @param: len length of the frib
115 void LwpFribParaNumber::Read(LwpObjectStream* pObjStrm, sal_uInt16 /*len*/)
117 m_nStyleID = pObjStrm->QuickReaduInt16();
118 m_nNumberChar = pObjStrm->QuickReaduInt16();
119 m_nLevel = pObjStrm->QuickReaduInt16();
120 m_nStart = pObjStrm->QuickReaduInt16();
124 * @short: default constructor of LwpFribDocVar
126 LwpFribDocVar::LwpFribDocVar(LwpPara* pPara)
127 : LwpFrib(pPara), m_nType(0)
131 * @short: destructor of LwpFribDocVar
133 LwpFribDocVar::~LwpFribDocVar()
137 * @short: Reading mothed of document variable frib.
138 * @param: pObjStrm wordpro object stream.
139 * @param: len length of the frib
141 void LwpFribDocVar::Read(LwpObjectStream* pObjStrm, sal_uInt16 /*len*/)
143 m_nType = pObjStrm->QuickReaduInt16();
144 m_aName.Read(pObjStrm);
148 * @short: register style for doc field (text style,date style)
150 void LwpFribDocVar::RegisterStyle(LwpFoundry* pFoundry)
152 LwpFrib::RegisterStyle(pFoundry);
154 switch(m_nType)
156 case DATECREATED:
157 case DATELASTREVISION:
159 RegisterDefaultTimeStyle();
161 break;
162 case TOTALEDITTIME:
163 RegisterTotalTimeStyle();
164 break;
165 default:
166 break;
171 * @short: register default time style for doc field
173 void LwpFribDocVar::RegisterDefaultTimeStyle()
175 std::unique_ptr<XFDateStyle> pDateStyle(new XFDateStyle);//use the default format
177 pDateStyle->AddMonth();
178 pDateStyle->AddText("/");
179 pDateStyle->AddMonthDay();
180 pDateStyle->AddText("/");
181 pDateStyle->AddYear();
182 pDateStyle->AddText(",");
183 pDateStyle->AddHour();
184 pDateStyle->AddText(":");
185 pDateStyle->AddMinute();
186 pDateStyle->AddText(":");
187 pDateStyle->AddSecond();
189 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
190 m_TimeStyle = pXFStyleManager->AddStyle(std::move(pDateStyle)).m_pStyle->GetStyleName();
192 void LwpFribDocVar::RegisterTotalTimeStyle()
194 std::unique_ptr<XFTimeStyle> pTimeStyle(new XFTimeStyle);//use the default format
195 pTimeStyle->SetTruncate(false);
196 pTimeStyle->AddMinute();
197 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
198 m_TimeStyle = pXFStyleManager->AddStyle(std::move(pTimeStyle)).m_pStyle->GetStyleName();
202 * @short: convert the doc info field
204 void LwpFribDocVar::XFConvert(XFContentContainer* pXFPara)
206 XFContent* pContent=nullptr;
207 switch(m_nType)
209 case FILENAME:
211 pContent = new XFFileName;
212 static_cast<XFFileName*>(pContent)->SetType("FileName");
213 break;
215 case PATH:
217 pContent = new XFFileName;
218 static_cast<XFFileName*>(pContent)->SetType("Path");
219 break;
221 case DESCRIPTION:
222 pContent = new XFDescription;
223 break;
224 case DATECREATED:
226 pContent = new XFCreateTime;
227 pContent->SetStyleName(m_TimeStyle);
228 break;
230 case DATELASTREVISION:
232 pContent = new XFLastEditTime;
233 pContent->SetStyleName(m_TimeStyle);
234 break;
236 case NUMPAGES:
237 pContent = new XFPageCount;
238 break;
239 case NUMWORDS:
240 pContent = new XFWordCount;
241 break;
242 case NUMCHARS:
243 pContent = new XFCharCount;
244 break;
245 case TOTALEDITTIME:
247 pContent = new XFTotalEditTime;
248 pContent->SetStyleName(m_TimeStyle);
249 break;
251 case KEYWORDS:
252 pContent = new XFKeywords;
253 break;
254 case CREATEDBY:
255 pContent = new XFInitialCreator;
256 break;
257 case DOCSIZE:
258 /* pContent = new XFAnnotation;
259 XFTextContent* pSpan = new XFTextContent();
260 pSpan->SetText("Document Size is Here");
261 XFParagraph* pPara = new XFParagraph;
262 pPara->Add(pSpan);
263 static_cast<XFAnnotation*>(pContent)->Add(pPara);
264 break;
266 LwpFrib::ConvertChars(pXFPara,"<Document Size>");
267 return;
268 case SMARTMASTER:
269 LwpFrib::ConvertChars(pXFPara,"<Smart master>");
270 return;
271 case DIVISIONNAME:
272 LwpFrib::ConvertChars(pXFPara,"<Division name>");
273 return;
274 case SECTIONNAME:
275 LwpFrib::ConvertChars(pXFPara,"<Section name>");
276 return;
277 case VERSIONCREATEBY:
278 LwpFrib::ConvertChars(pXFPara,"<Version Creat by>");
279 return;
280 case VERSIONCREATEDATE:
281 LwpFrib::ConvertChars(pXFPara,"<Version Creat date>");
282 return;
283 case VERSIONOTHEREDITORS:
284 LwpFrib::ConvertChars(pXFPara,"<Version other Editors>");
285 return;
286 case VERSIONNAME:
287 LwpFrib::ConvertChars(pXFPara,"<Version Name>");
288 return;
289 case VERSIONNUMBER:
290 LwpFrib::ConvertChars(pXFPara,"<Version Numbers>");
291 return;
292 case ALLVERSIONNAME:
293 LwpFrib::ConvertChars(pXFPara,"<All Version Name>");
294 return;
295 case VERSIONREMARK:
296 LwpFrib::ConvertChars(pXFPara,"<Version Remark>");
297 return;
298 case DOCUMENTCATEGORY:
299 LwpFrib::ConvertChars(pXFPara,"<Document Category>");
300 return;
301 case VERSIONLASTDATE:
302 LwpFrib::ConvertChars(pXFPara,"<Version Last Modify Date>");
303 return;
304 case VERSIONLASTEDITOR:
305 LwpFrib::ConvertChars(pXFPara,"<Version Last Editor>");
306 return;
307 case LASTEDIT:
308 LwpFrib::ConvertChars(pXFPara,"<Last Editor>");
309 return;
310 case OTHEREDITORS:
311 LwpFrib::ConvertChars(pXFPara,"<Other Editors>");
312 return;
313 case NUMOFREVISION:
314 LwpFrib::ConvertChars(pXFPara,"<Number of Revision>");
315 return;
316 default:
317 return;
319 if (m_ModFlag)//(m_pModifiers)
321 XFTextSpan *pSpan = new XFTextSpan;
322 pSpan->SetStyleName(GetStyleName());
323 pSpan->Add(pContent);
324 pXFPara->Add(pSpan);
326 else
327 pXFPara->Add(pContent);
331 * @short: Read unicode
333 void LwpFribUnicode::Read(LwpObjectStream* pObjStrm, sal_uInt16 len)
335 if(len>1)
337 rtl_TextEncoding rEncode;
339 if (m_pModifiers && m_pModifiers->CodePage)
340 rEncode = LwpCharSetMgr::GetInstance()->
341 GetTextCharEncoding(m_pModifiers->CodePage);
342 else
343 rEncode = LwpCharSetMgr::GetTextCharEncoding();
345 LwpTools::QuickReadUnicode(pObjStrm, m_Content, len, rEncode);
348 else
349 pObjStrm->SeekRel(len);
352 void LwpFribUnicode::XFConvert(XFContentContainer* pXFPara,LwpStory* pStory)
354 if (!pStory)
355 return;
356 LwpHyperlinkMgr* pHyperlink = pStory->GetHyperlinkMgr();
357 if (pHyperlink->GetHyperlinkFlag())
358 LwpFrib::ConvertHyperLink(pXFPara,pHyperlink,GetText());
359 else
360 LwpFrib::ConvertChars(pXFPara,GetText());
364 * @short: Read page number
366 void LwpFribPageNumber::Read(LwpObjectStream* pObjStrm, sal_uInt16 /*len*/)
368 m_nNumStyle = pObjStrm->QuickReaduInt16();
369 m_aBefText.Read(pObjStrm);
370 m_aAfterText.Read(pObjStrm);
371 m_nStartNum = pObjStrm->QuickReaduInt16();
372 m_nStartOnPage = pObjStrm->QuickReaduInt16();
373 m_nFlag = pObjStrm->QuickReaduInt16();
376 void LwpFribPageNumber::XFConvert(XFContentContainer* pXFPara)
378 if (m_nNumStyle == 0x0)
379 return;
380 XFPageNumber* pNum = new XFPageNumber;
381 // pNum->SetSelect("current");
382 switch(m_nNumStyle)
384 case 0x01:
385 pNum->SetNumFmt("1");
386 break;
387 case 0x02:
388 pNum->SetNumFmt("A");
389 break;
390 case 0x03:
391 pNum->SetNumFmt("a");
392 break;
393 case 0x04:
394 pNum->SetNumFmt("I");
395 break;
396 case 0x05:
397 pNum->SetNumFmt("i");
398 break;
400 OUString styleName = GetStyleName();
401 if (!m_aBefText.str().isEmpty())
403 OUString textStr = m_aBefText.str();
404 XFTextSpan *pBef = new XFTextSpan(textStr,styleName);
405 pXFPara->Add(pBef);
407 if (m_ModFlag)//(m_pModifiers)
409 XFTextSpan *pSpan = new XFTextSpan;
410 pSpan->SetStyleName(styleName);
411 pSpan->Add(pNum);
412 pXFPara->Add(pSpan);
414 else
415 pXFPara->Add(pNum);
416 if (!m_aAfterText.str().isEmpty())
418 OUString textStr = m_aAfterText.str();
419 XFTextSpan *pAfter = new XFTextSpan(textStr,styleName);
420 pXFPara->Add(pAfter);
424 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */