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/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
)
83 rtl_TextEncoding rEncode
;
86 rEncode
= RTL_TEXTENCODING_ISO_8859_1
;
90 if (m_pModifiers
&& m_pModifiers
->CodePage
)
91 rEncode
= LwpCharSetMgr::GetInstance()->
92 GetTextCharEncoding(m_pModifiers
->CodePage
);
94 rEncode
= LwpCharSetMgr::GetTextCharEncoding();
96 LwpTools::QuickReadUnicode(pObjStrm
, m_Content
, len
, rEncode
);
99 void LwpFribText::XFConvert(XFContentContainer
* pXFPara
,LwpStory
* pStory
)
103 LwpHyperlinkMgr
* pHyperlink
= pStory
->GetHyperlinkMgr();
104 if (pHyperlink
->GetHyperlinkFlag())
105 LwpFrib::ConvertHyperLink(pXFPara
,pHyperlink
,GetText());
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
);
157 case DATELASTREVISION
:
159 RegisterDefaultTimeStyle();
163 RegisterTotalTimeStyle();
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;
211 pContent
= new XFFileName
;
212 static_cast<XFFileName
*>(pContent
)->SetType("FileName");
217 pContent
= new XFFileName
;
218 static_cast<XFFileName
*>(pContent
)->SetType("Path");
222 pContent
= new XFDescription
;
226 pContent
= new XFCreateTime
;
227 pContent
->SetStyleName(m_TimeStyle
);
230 case DATELASTREVISION
:
232 pContent
= new XFLastEditTime
;
233 pContent
->SetStyleName(m_TimeStyle
);
237 pContent
= new XFPageCount
;
240 pContent
= new XFWordCount
;
243 pContent
= new XFCharCount
;
247 pContent
= new XFTotalEditTime
;
248 pContent
->SetStyleName(m_TimeStyle
);
252 pContent
= new XFKeywords
;
255 pContent
= new XFInitialCreator
;
258 /* pContent = new XFAnnotation;
259 XFTextContent* pSpan = new XFTextContent();
260 pSpan->SetText("Document Size is Here");
261 XFParagraph* pPara = new XFParagraph;
263 static_cast<XFAnnotation*>(pContent)->Add(pPara);
266 LwpFrib::ConvertChars(pXFPara
,"<Document Size>");
269 LwpFrib::ConvertChars(pXFPara
,"<Smart master>");
272 LwpFrib::ConvertChars(pXFPara
,"<Division name>");
275 LwpFrib::ConvertChars(pXFPara
,"<Section name>");
277 case VERSIONCREATEBY
:
278 LwpFrib::ConvertChars(pXFPara
,"<Version Creat by>");
280 case VERSIONCREATEDATE
:
281 LwpFrib::ConvertChars(pXFPara
,"<Version Creat date>");
283 case VERSIONOTHEREDITORS
:
284 LwpFrib::ConvertChars(pXFPara
,"<Version other Editors>");
287 LwpFrib::ConvertChars(pXFPara
,"<Version Name>");
290 LwpFrib::ConvertChars(pXFPara
,"<Version Numbers>");
293 LwpFrib::ConvertChars(pXFPara
,"<All Version Name>");
296 LwpFrib::ConvertChars(pXFPara
,"<Version Remark>");
298 case DOCUMENTCATEGORY
:
299 LwpFrib::ConvertChars(pXFPara
,"<Document Category>");
301 case VERSIONLASTDATE
:
302 LwpFrib::ConvertChars(pXFPara
,"<Version Last Modify Date>");
304 case VERSIONLASTEDITOR
:
305 LwpFrib::ConvertChars(pXFPara
,"<Version Last Editor>");
308 LwpFrib::ConvertChars(pXFPara
,"<Last Editor>");
311 LwpFrib::ConvertChars(pXFPara
,"<Other Editors>");
314 LwpFrib::ConvertChars(pXFPara
,"<Number of Revision>");
319 if (m_ModFlag
)//(m_pModifiers)
321 XFTextSpan
*pSpan
= new XFTextSpan
;
322 pSpan
->SetStyleName(GetStyleName());
323 pSpan
->Add(pContent
);
327 pXFPara
->Add(pContent
);
331 * @short: Read unicode
333 void LwpFribUnicode::Read(LwpObjectStream
* pObjStrm
, sal_uInt16 len
)
337 rtl_TextEncoding rEncode
;
339 if (m_pModifiers
&& m_pModifiers
->CodePage
)
340 rEncode
= LwpCharSetMgr::GetInstance()->
341 GetTextCharEncoding(m_pModifiers
->CodePage
);
343 rEncode
= LwpCharSetMgr::GetTextCharEncoding();
345 LwpTools::QuickReadUnicode(pObjStrm
, m_Content
, len
, rEncode
);
349 pObjStrm
->SeekRel(len
);
352 void LwpFribUnicode::XFConvert(XFContentContainer
* pXFPara
,LwpStory
* pStory
)
356 LwpHyperlinkMgr
* pHyperlink
= pStory
->GetHyperlinkMgr();
357 if (pHyperlink
->GetHyperlinkFlag())
358 LwpFrib::ConvertHyperLink(pXFPara
,pHyperlink
,GetText());
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)
380 XFPageNumber
* pNum
= new XFPageNumber
;
381 // pNum->SetSelect("current");
385 pNum
->SetNumFmt("1");
388 pNum
->SetNumFmt("A");
391 pNum
->SetNumFmt("a");
394 pNum
->SetNumFmt("I");
397 pNum
->SetNumFmt("i");
400 OUString styleName
= GetStyleName();
401 if (!m_aBefText
.str().isEmpty())
403 OUString textStr
= m_aBefText
.str();
404 XFTextSpan
*pBef
= new XFTextSpan(textStr
,styleName
);
407 if (m_ModFlag
)//(m_pModifiers)
409 XFTextSpan
*pSpan
= new XFTextSpan
;
410 pSpan
->SetStyleName(styleName
);
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: */