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,
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 /*************************************************************************
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
)
87 rtl_TextEncoding rEncode
;
90 rEncode
= RTL_TEXTENCODING_ISO_8859_1
;
94 if (m_pModifiers
&& m_pModifiers
->CodePage
)
95 rEncode
= LwpCharSetMgr::GetInstance()->
96 GetTextCharEncoding(m_pModifiers
->CodePage
);
98 rEncode
= LwpCharSetMgr::GetTextCharEncoding();
100 LwpTools::QuickReadUnicode(pObjStrm
, m_Content
, len
, rEncode
);
104 void LwpFribText::XFConvert(XFContentContainer
* pXFPara
,LwpStory
* pStory
)
108 LwpHyperlinkMgr
* pHyperlink
= pStory
->GetHyperlinkMgr();
109 if (pHyperlink
->GetHyperlinkFlag())
110 LwpFrib::ConvertHyperLink(pXFPara
,pHyperlink
,GetText());
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()
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
);
167 case DATELASTREVISION
:
169 RegisterDefaultTimeStyle();
173 RegisterTotalTimeStyle();
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;
221 pContent
= new XFFileName
;
222 static_cast<XFFileName
*>(pContent
)->SetType("FileName");
227 pContent
= new XFFileName
;
228 static_cast<XFFileName
*>(pContent
)->SetType("Path");
232 pContent
= new XFDescription
;
236 pContent
= new XFCreateTime
;
237 pContent
->SetStyleName(m_TimeStyle
);
240 case DATELASTREVISION
:
242 pContent
= new XFLastEditTime
;
243 pContent
->SetStyleName(m_TimeStyle
);
247 pContent
= new XFPageCount
;
250 pContent
= new XFWordCount
;
253 pContent
= new XFCharCount
;
257 pContent
= new XFTotalEditTime
;
258 pContent
->SetStyleName(m_TimeStyle
);
262 pContent
= new XFKeywords
;
265 pContent
= new XFInitialCreator
;
269 /* pContent = new XFAnnotation;
270 XFTextContent* pSpan = new XFTextContent();
271 pSpan->SetText("Document Size is Here");
272 XFParagraph* pPara = new XFParagraph;
274 static_cast<XFAnnotation*>(pContent)->Add(pPara);
277 OUString text
= "<Document Size>";
278 LwpFrib::ConvertChars(pXFPara
,text
);
283 OUString text
= "<Smart master>";
284 LwpFrib::ConvertChars(pXFPara
,text
);
289 OUString text
= "<Division name>";
290 LwpFrib::ConvertChars(pXFPara
,text
);
295 OUString text
= "<Section name>";
296 LwpFrib::ConvertChars(pXFPara
,text
);
299 case VERSIONCREATEBY
:
301 OUString text
= "<Version Creat by>";
302 LwpFrib::ConvertChars(pXFPara
,text
);
305 case VERSIONCREATEDATE
:
307 OUString text
= "<Version Creat date>";
308 LwpFrib::ConvertChars(pXFPara
,text
);
311 case VERSIONOTHEREDITORS
:
313 OUString text
= "<Version other Editors>";
314 LwpFrib::ConvertChars(pXFPara
,text
);
319 OUString text
= "<Version Name>";
320 LwpFrib::ConvertChars(pXFPara
,text
);
325 OUString text
= "<Version Numbers>";
326 LwpFrib::ConvertChars(pXFPara
,text
);
331 OUString text
= "<All Version Name>";
332 LwpFrib::ConvertChars(pXFPara
,text
);
337 OUString text
= "<Version Remark>";
338 LwpFrib::ConvertChars(pXFPara
,text
);
341 case DOCUMENTCATEGORY
:
343 OUString text
= "<Document Category>";
344 LwpFrib::ConvertChars(pXFPara
,text
);
347 case VERSIONLASTDATE
:
349 OUString text
= "<Version Last Modify Date>";
350 LwpFrib::ConvertChars(pXFPara
,text
);
353 case VERSIONLASTEDITOR
:
355 OUString text
= "<Version Last Editor>";
356 LwpFrib::ConvertChars(pXFPara
,text
);
361 OUString text
= "<Last Editor>";
362 LwpFrib::ConvertChars(pXFPara
,text
);
367 OUString text
= "<Other Editors>";
368 LwpFrib::ConvertChars(pXFPara
,text
);
373 OUString text
= "<Number of Revision>";
374 LwpFrib::ConvertChars(pXFPara
,text
);
380 if (m_ModFlag
)//(m_pModifiers)
382 XFTextSpan
*pSpan
= new XFTextSpan
;
383 pSpan
->SetStyleName(GetStyleName());
384 pSpan
->Add(pContent
);
388 pXFPara
->Add(pContent
);
392 * @short: Read unicode
394 void LwpFribUnicode::Read(LwpObjectStream
* pObjStrm
, sal_uInt16 len
)
398 rtl_TextEncoding rEncode
;
400 if (m_pModifiers
&& m_pModifiers
->CodePage
)
401 rEncode
= LwpCharSetMgr::GetInstance()->
402 GetTextCharEncoding(m_pModifiers
->CodePage
);
404 rEncode
= LwpCharSetMgr::GetTextCharEncoding();
406 LwpTools::QuickReadUnicode(pObjStrm
, m_Content
, len
, rEncode
);
410 pObjStrm
->SeekRel(len
);
413 void LwpFribUnicode::XFConvert(XFContentContainer
* pXFPara
,LwpStory
* pStory
)
417 LwpHyperlinkMgr
* pHyperlink
= pStory
->GetHyperlinkMgr();
418 if (pHyperlink
->GetHyperlinkFlag())
419 LwpFrib::ConvertHyperLink(pXFPara
,pHyperlink
,GetText());
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)
441 XFPageNumber
* pNum
= new XFPageNumber
;
442 // pNum->SetSelect("current");
446 pNum
->SetNumFmt("1");
449 pNum
->SetNumFmt("A");
452 pNum
->SetNumFmt("a");
455 pNum
->SetNumFmt("I");
458 pNum
->SetNumFmt("i");
461 OUString styleName
= GetStyleName();
462 if (!m_aBefText
.str().isEmpty())
464 OUString textStr
= m_aBefText
.str();
465 XFTextSpan
*pBef
= new XFTextSpan(textStr
,styleName
);
468 if (m_ModFlag
)//(m_pModifiers)
470 XFTextSpan
*pSpan
= new XFTextSpan
;
471 pSpan
->SetStyleName(styleName
);
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: */