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 ************************************************************************/
60 /*************************************************************************
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
)
90 rtl_TextEncoding rEncode
;
93 rEncode
= RTL_TEXTENCODING_ISO_8859_1
;
97 if (m_pModifiers
&& m_pModifiers
->CodePage
)
98 rEncode
= LwpCharSetMgr::GetInstance()->
99 GetTextCharEncoding(m_pModifiers
->CodePage
);
101 rEncode
= LwpCharSetMgr::GetTextCharEncoding();
103 LwpTools::QuickReadUnicode(pObjStrm
, m_Content
, len
, rEncode
);
107 void LwpFribText::XFConvert(XFContentContainer
* pXFPara
,LwpStory
* pStory
)
111 LwpHyperlinkMgr
* pHyperlink
= pStory
->GetHyperlinkMgr();
112 if (pHyperlink
->GetHyperlinkFlag())
113 LwpFrib::ConvertHyperLink(pXFPara
,pHyperlink
,GetText());
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()
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)
165 void LwpFribDocVar::RegisterStyle(LwpFoundry
* pFoundry
)
167 LwpFrib::RegisterStyle(pFoundry
);
172 case DATELASTREVISION
:
174 // m_TimeStyle = LwpTools::RegisterDefaultTimeStyle();
175 RegisterDefaultTimeStyle();
179 RegisterTotalTimeStyle();
187 * @short: register default time style for doc field
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
224 void LwpFribDocVar::XFConvert(XFContentContainer
* pXFPara
)
226 XFContent
* pContent
=NULL
;
231 pContent
= new XFFileName
;
232 static_cast<XFFileName
*>(pContent
)->SetType("FileName");
237 pContent
= new XFFileName
;
238 static_cast<XFFileName
*>(pContent
)->SetType("Path");
242 pContent
= new XFDescription
;
246 pContent
= new XFCreateTime
;
247 pContent
->SetStyleName(m_TimeStyle
);
250 case DATELASTREVISION
:
252 pContent
= new XFLastEditTime
;
253 pContent
->SetStyleName(m_TimeStyle
);
257 pContent
= new XFPageCount
;
260 pContent
= new XFWordCount
;
263 pContent
= new XFCharCount
;
267 pContent
= new XFTotalEditTime
;
268 pContent
->SetStyleName(m_TimeStyle
);
272 pContent
= new XFKeywords
;
275 pContent
= new XFInitialCreator
;
279 /* pContent = new XFAnnotation;
280 XFTextContent* pSpan = new XFTextContent();
281 pSpan->SetText("Document Size is Here");
282 XFParagraph* pPara = new XFParagraph;
284 static_cast<XFAnnotation*>(pContent)->Add(pPara);
287 OUString text
= "<Document Size>";
288 LwpFrib::ConvertChars(pXFPara
,text
);
293 OUString text
= "<Smart master>";
294 LwpFrib::ConvertChars(pXFPara
,text
);
299 OUString text
= "<Division name>";
300 LwpFrib::ConvertChars(pXFPara
,text
);
305 OUString text
= "<Section name>";
306 LwpFrib::ConvertChars(pXFPara
,text
);
309 case VERSIONCREATEBY
:
311 OUString text
= "<Version Creat by>";
312 LwpFrib::ConvertChars(pXFPara
,text
);
315 case VERSIONCREATEDATE
:
317 OUString text
= "<Version Creat date>";
318 LwpFrib::ConvertChars(pXFPara
,text
);
321 case VERSIONOTHEREDITORS
:
323 OUString text
= "<Version other Editors>";
324 LwpFrib::ConvertChars(pXFPara
,text
);
329 OUString text
= "<Version Name>";
330 LwpFrib::ConvertChars(pXFPara
,text
);
335 OUString text
= "<Version Numbers>";
336 LwpFrib::ConvertChars(pXFPara
,text
);
341 OUString text
= "<All Version Name>";
342 LwpFrib::ConvertChars(pXFPara
,text
);
347 OUString text
= "<Version Remark>";
348 LwpFrib::ConvertChars(pXFPara
,text
);
351 case DOCUMENTCATEGORY
:
353 OUString text
= "<Document Category>";
354 LwpFrib::ConvertChars(pXFPara
,text
);
357 case VERSIONLASTDATE
:
359 OUString text
= "<Version Last Modify Date>";
360 LwpFrib::ConvertChars(pXFPara
,text
);
363 case VERSIONLASTEDITOR
:
365 OUString text
= "<Version Last Editor>";
366 LwpFrib::ConvertChars(pXFPara
,text
);
371 OUString text
= "<Last Editor>";
372 LwpFrib::ConvertChars(pXFPara
,text
);
377 OUString text
= "<Other Editors>";
378 LwpFrib::ConvertChars(pXFPara
,text
);
383 OUString text
= "<Number of Revision>";
384 LwpFrib::ConvertChars(pXFPara
,text
);
390 if (m_ModFlag
)//(m_pModifiers)
392 XFTextSpan
*pSpan
= new XFTextSpan
;
393 pSpan
->SetStyleName(GetStyleName());
394 pSpan
->Add(pContent
);
398 pXFPara
->Add(pContent
);
402 * @short: Read unicode
406 void LwpFribUnicode::Read(LwpObjectStream
* pObjStrm
, sal_uInt16 len
)
410 rtl_TextEncoding rEncode
;
412 if (m_pModifiers
&& m_pModifiers
->CodePage
)
413 rEncode
= LwpCharSetMgr::GetInstance()->
414 GetTextCharEncoding(m_pModifiers
->CodePage
);
416 rEncode
= LwpCharSetMgr::GetTextCharEncoding();
418 LwpTools::QuickReadUnicode(pObjStrm
, m_Content
, len
, rEncode
);
422 pObjStrm
->SeekRel(len
);
425 void LwpFribUnicode::XFConvert(XFContentContainer
* pXFPara
,LwpStory
* pStory
)
429 LwpHyperlinkMgr
* pHyperlink
= pStory
->GetHyperlinkMgr();
430 if (pHyperlink
->GetHyperlinkFlag())
431 LwpFrib::ConvertHyperLink(pXFPara
,pHyperlink
,GetText());
433 LwpFrib::ConvertChars(pXFPara
,GetText());
437 * @short: Read page number
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)
455 XFPageNumber
* pNum
= new XFPageNumber
;
456 // pNum->SetSelect("current");
460 pNum
->SetNumFmt("1");
463 pNum
->SetNumFmt("A");
466 pNum
->SetNumFmt("a");
469 pNum
->SetNumFmt("I");
472 pNum
->SetNumFmt("i");
475 OUString styleName
= GetStyleName();
476 if (!m_aBefText
.str().isEmpty())
478 OUString textStr
= m_aBefText
.str();
479 XFTextSpan
*pBef
= new XFTextSpan(textStr
,styleName
);
482 if (m_ModFlag
)//(m_pModifiers)
484 XFTextSpan
*pSpan
= new XFTextSpan
;
485 pSpan
->SetStyleName(styleName
);
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: */