[Libreoffice-commits] .: filter/inc filter/source sw/source writerfilter/source
Miklos Vajna
vmiklos at kemper.freedesktop.org
Fri Jun 15 09:02:10 PDT 2012
filter/inc/filter/msfilter/util.hxx | 16 +++++
filter/source/msfilter/util.cxx | 78 +++++++++++++++++++++++++
sw/source/filter/inc/msfilter.hxx | 9 --
sw/source/filter/rtf/swparrtf.cxx | 4 -
sw/source/filter/ww8/docxattributeoutput.cxx | 53 ----------------
sw/source/filter/ww8/writerwordglue.cxx | 33 ----------
sw/source/filter/ww8/ww8par.cxx | 4 -
sw/source/filter/ww8/ww8par4.cxx | 2
writerfilter/source/rtftok/rtfdocumentimpl.cxx | 40 ------------
9 files changed, 103 insertions(+), 136 deletions(-)
New commits:
commit 42e41ea6d6ec40977cc339af529b2306840d31cb
Author: Miklos Vajna <vmiklos at suse.cz>
Date: Fri Jun 15 17:48:17 2012 +0200
move DTTM2DateTime and DateTimeToOString to msfilter to avoid copy&paste
diff --git a/filter/inc/filter/msfilter/util.hxx b/filter/inc/filter/msfilter/util.hxx
index 2dc5fa7..ff52209 100644
--- a/filter/inc/filter/msfilter/util.hxx
+++ b/filter/inc/filter/msfilter/util.hxx
@@ -30,6 +30,7 @@
#define INCLUDED_MSFILTER_UTIL_HXX
#include <rtl/textenc.h>
+#include <tools/datetime.hxx>
#include <com/sun/star/lang/Locale.hpp>
#include "filter/msfilter/msfilterdllapi.h"
@@ -43,6 +44,21 @@ MSFILTER_DLLPUBLIC rtl_TextEncoding getBestTextEncodingFromLocale(const ::com::s
/// Convert a color in BGR format to RGB.
MSFILTER_DLLPUBLIC sal_uInt32 BGRToRGB(sal_uInt32 nColour);
+
+/** Convert from DTTM to Writer's DateTime
+
+ @author
+ <a href="mailto:mmaher at openoffice.org">Martin Maher</a
+ */
+MSFILTER_DLLPUBLIC DateTime DTTM2DateTime( long lDTTM );
+
+/** Convert DateTime to xsd::dateTime string.
+
+I guess there must be an implementation of this somewhere in LO, but I failed
+to find it, unfortunately :-(
+*/
+MSFILTER_DLLPUBLIC rtl::OString DateTimeToOString( const DateTime& rDateTime );
+
}
}
diff --git a/filter/source/msfilter/util.cxx b/filter/source/msfilter/util.cxx
index 03df8af..adfe492 100644
--- a/filter/source/msfilter/util.cxx
+++ b/filter/source/msfilter/util.cxx
@@ -27,6 +27,7 @@
*/
#include <rtl/ustring.hxx>
+#include <rtl/strbuf.hxx>
#include <vcl/svapp.hxx>
#include <filter/msfilter/util.hxx>
@@ -62,6 +63,83 @@ sal_uInt32 BGRToRGB(sal_uInt32 nColor)
return nColor;
}
+DateTime DTTM2DateTime( long lDTTM )
+{
+ /*
+ mint short :6 0000003F minutes (0-59)
+ hr short :5 000007C0 hours (0-23)
+ dom short :5 0000F800 days of month (1-31)
+ mon short :4 000F0000 months (1-12)
+ yr short :9 1FF00000 years (1900-2411)-1900
+ wdy short :3 E0000000 weekday(Sunday=0
+ Monday=1
+ ( wdy can be ignored ) Tuesday=2
+ Wednesday=3
+ Thursday=4
+ Friday=5
+ Saturday=6)
+ */
+ DateTime aDateTime(Date( 0 ), Time( 0 ));
+ if( lDTTM )
+ {
+ sal_uInt16 lMin = (sal_uInt16)(lDTTM & 0x0000003F);
+ lDTTM >>= 6;
+ sal_uInt16 lHour= (sal_uInt16)(lDTTM & 0x0000001F);
+ lDTTM >>= 5;
+ sal_uInt16 lDay = (sal_uInt16)(lDTTM & 0x0000001F);
+ lDTTM >>= 5;
+ sal_uInt16 lMon = (sal_uInt16)(lDTTM & 0x0000000F);
+ lDTTM >>= 4;
+ sal_uInt16 lYear= (sal_uInt16)(lDTTM & 0x000001FF) + 1900;
+ aDateTime = DateTime(Date(lDay, lMon, lYear), Time(lHour, lMin));
+ }
+ return aDateTime;
+}
+
+/// Append the number as 2-digit when less than 10.
+static void lcl_AppendTwoDigits( rtl::OStringBuffer &rBuffer, sal_Int32 nNum )
+{
+ if ( nNum < 0 || nNum > 99 )
+ {
+ rBuffer.append( "00" );
+ return;
+ }
+
+ if ( nNum < 10 )
+ rBuffer.append( '0' );
+
+ rBuffer.append( nNum );
+}
+
+rtl::OString DateTimeToOString( const DateTime& rDateTime )
+{
+ DateTime aInUTC( rDateTime );
+// HACK: this is correct according to the spec, but MSOffice believes everybody lives
+// in UTC+0 when reading it back
+// aInUTC.ConvertToUTC();
+
+ rtl::OStringBuffer aBuffer( 25 );
+ aBuffer.append( sal_Int32( aInUTC.GetYear() ) );
+ aBuffer.append( '-' );
+
+ lcl_AppendTwoDigits( aBuffer, aInUTC.GetMonth() );
+ aBuffer.append( '-' );
+
+ lcl_AppendTwoDigits( aBuffer, aInUTC.GetDay() );
+ aBuffer.append( 'T' );
+
+ lcl_AppendTwoDigits( aBuffer, aInUTC.GetHour() );
+ aBuffer.append( ':' );
+
+ lcl_AppendTwoDigits( aBuffer, aInUTC.GetMin() );
+ aBuffer.append( ':' );
+
+ lcl_AppendTwoDigits( aBuffer, aInUTC.GetSec() );
+ aBuffer.append( 'Z' ); // we are in UTC
+
+ return aBuffer.makeStringAndClear();
+}
+
}
}
diff --git a/sw/source/filter/inc/msfilter.hxx b/sw/source/filter/inc/msfilter.hxx
index 3958f74..45fd883 100644
--- a/sw/source/filter/inc/msfilter.hxx
+++ b/sw/source/filter/inc/msfilter.hxx
@@ -37,7 +37,7 @@
#include "wwstyles.hxx" //ww::sti
#include <rtl/textenc.h> //rtl_TextEncoding
#include <tools/gen.hxx> //Size
-#include <tools/datetime.hxx>
+#include <filter/msfilter/util.hxx>
#include <fltshell.hxx> // fuer den Attribut Stack
#include <redline.hxx>
#include <shellio.hxx>
@@ -107,13 +107,6 @@ namespace sw
@author
<a href="mailto:mmaher at openoffice.org">Martin Maher</a
*/
- DateTime DTTM2DateTime( long lDTTM );
-
- /** Convert from DTTM to Writer's DateTime
-
- @author
- <a href="mailto:mmaher at openoffice.org">Martin Maher</a
- */
long DateTime2DTTM( const DateTime& rDT );
/** Convert from Word Date/Time field str to Writer's Date Time str
diff --git a/sw/source/filter/rtf/swparrtf.cxx b/sw/source/filter/rtf/swparrtf.cxx
index 5a73aa1..2e8553a 100644
--- a/sw/source/filter/rtf/swparrtf.cxx
+++ b/sw/source/filter/rtf/swparrtf.cxx
@@ -1847,12 +1847,12 @@ void SwRTFParser::NextToken( int nToken )
case RTF_REVDTTM:
if (pRedlineInsert != NULL)
- pRedlineInsert->aStamp = sw::ms::DTTM2DateTime(nTokenValue);
+ pRedlineInsert->aStamp = msfilter::util::DTTM2DateTime(nTokenValue);
break;
case RTF_REVDTTMDEL:
- pRedlineDelete->aStamp = sw::ms::DTTM2DateTime(nTokenValue);
+ pRedlineDelete->aStamp = msfilter::util::DTTM2DateTime(nTokenValue);
break;
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
index db118a8..ba50463 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -1240,55 +1240,6 @@ void DocxAttributeOutput::Redline( const SwRedlineData* /*pRedline*/ )
OSL_TRACE( "TODO DocxAttributeOutput::Redline( const SwRedlineData* pRedline )" );
}
-/// Append the number as 2-digit when less than 10.
-static void impl_AppendTwoDigits( OStringBuffer &rBuffer, sal_Int32 nNum )
-{
- if ( nNum < 0 || nNum > 99 )
- {
- rBuffer.append( "00" );
- return;
- }
-
- if ( nNum < 10 )
- rBuffer.append( '0' );
-
- rBuffer.append( nNum );
-}
-
-/** Convert DateTime to xsd::dateTime string.
-
-I guess there must be an implementation of this somewhere in OOo, but I failed
-to find it, unfortunately :-(
-*/
-static OString impl_DateTimeToOString( const DateTime& rDateTime )
-{
- DateTime aInUTC( rDateTime );
-// HACK: this is correct according to the spec, but MSOffice believes everybody lives
-// in UTC+0 when reading it back
-// aInUTC.ConvertToUTC();
-
- OStringBuffer aBuffer( 25 );
- aBuffer.append( sal_Int32( aInUTC.GetYear() ) );
- aBuffer.append( '-' );
-
- impl_AppendTwoDigits( aBuffer, aInUTC.GetMonth() );
- aBuffer.append( '-' );
-
- impl_AppendTwoDigits( aBuffer, aInUTC.GetDay() );
- aBuffer.append( 'T' );
-
- impl_AppendTwoDigits( aBuffer, aInUTC.GetHour() );
- aBuffer.append( ':' );
-
- impl_AppendTwoDigits( aBuffer, aInUTC.GetMin() );
- aBuffer.append( ':' );
-
- impl_AppendTwoDigits( aBuffer, aInUTC.GetSec() );
- aBuffer.append( 'Z' ); // we are in UTC
-
- return aBuffer.makeStringAndClear();
-}
-
void DocxAttributeOutput::StartRedline( const SwRedlineData* pRedlineData )
{
m_pRedlineData = pRedlineData;
@@ -1303,7 +1254,7 @@ void DocxAttributeOutput::StartRedline( const SwRedlineData* pRedlineData )
const String &rAuthor( SW_MOD()->GetRedlineAuthor( pRedlineData->GetAuthor() ) );
OString aAuthor( OUStringToOString( rAuthor, RTL_TEXTENCODING_UTF8 ) );
- OString aDate( impl_DateTimeToOString( pRedlineData->GetTimeStamp() ) );
+ OString aDate( msfilter::util::DateTimeToOString( pRedlineData->GetTimeStamp() ) );
switch ( pRedlineData->GetType() )
{
@@ -3380,7 +3331,7 @@ void DocxAttributeOutput::WritePostitFields()
const SwPostItField* f = m_postitFields[ i ];
m_pSerializer->startElementNS( XML_w, XML_comment, FSNS( XML_w, XML_id ), idstr.getStr(),
FSNS( XML_w, XML_author ), rtl::OUStringToOString( f->GetPar1(), RTL_TEXTENCODING_UTF8 ).getStr(),
- FSNS( XML_w, XML_date ), impl_DateTimeToOString(f->GetDateTime()).getStr(), FSEND );
+ FSNS( XML_w, XML_date ), msfilter::util::DateTimeToOString(f->GetDateTime()).getStr(), FSEND );
// Check for the text object existing, it seems that it can be NULL when saving a newly created
// comment without giving focus back to the main document. As GetTxt() is empty in that case as well,
// that is probably a bug in the Writer core.
diff --git a/sw/source/filter/ww8/writerwordglue.cxx b/sw/source/filter/ww8/writerwordglue.cxx
index 2c1bd54..7dbed56 100644
--- a/sw/source/filter/ww8/writerwordglue.cxx
+++ b/sw/source/filter/ww8/writerwordglue.cxx
@@ -728,39 +728,6 @@ namespace sw
return nDT;
}
- DateTime DTTM2DateTime( long lDTTM )
- {
- /*
- mint short :6 0000003F minutes (0-59)
- hr short :5 000007C0 hours (0-23)
- dom short :5 0000F800 days of month (1-31)
- mon short :4 000F0000 months (1-12)
- yr short :9 1FF00000 years (1900-2411)-1900
- wdy short :3 E0000000 weekday(Sunday=0
- Monday=1
- ( wdy can be ignored ) Tuesday=2
- Wednesday=3
- Thursday=4
- Friday=5
- Saturday=6)
- */
- DateTime aDateTime(Date( 0 ), Time( 0 ));
- if( lDTTM )
- {
- sal_uInt16 lMin = (sal_uInt16)(lDTTM & 0x0000003F);
- lDTTM >>= 6;
- sal_uInt16 lHour= (sal_uInt16)(lDTTM & 0x0000001F);
- lDTTM >>= 5;
- sal_uInt16 lDay = (sal_uInt16)(lDTTM & 0x0000001F);
- lDTTM >>= 5;
- sal_uInt16 lMon = (sal_uInt16)(lDTTM & 0x0000000F);
- lDTTM >>= 4;
- sal_uInt16 lYear= (sal_uInt16)(lDTTM & 0x000001FF) + 1900;
- aDateTime = DateTime(Date(lDay, lMon, lYear), Time(lHour, lMin));
- }
- return aDateTime;
- }
-
sal_uLong MSDateTimeFormatToSwFormat(String& rParams,
SvNumberFormatter *pFormatter, sal_uInt16 &rLang, bool bHijri,
sal_uInt16 nDocLang)
diff --git a/sw/source/filter/ww8/ww8par.cxx b/sw/source/filter/ww8/ww8par.cxx
index 82f4312..c497602 100644
--- a/sw/source/filter/ww8/ww8par.cxx
+++ b/sw/source/filter/ww8/ww8par.cxx
@@ -1509,7 +1509,7 @@ void SwWW8ImplReader::ImportDop()
if (xDocuProps.is())
{
DateTime aLastPrinted(
- sw::ms::DTTM2DateTime(pWDop->dttmLastPrint));
+ msfilter::util::DTTM2DateTime(pWDop->dttmLastPrint));
::util::DateTime uDT(aLastPrinted.Get100Sec(),
aLastPrinted.GetSec(), aLastPrinted.GetMin(),
aLastPrinted.GetHour(), aLastPrinted.GetDay(),
@@ -1828,7 +1828,7 @@ long SwWW8ImplReader::Read_And(WW8PLCFManResult* pRes)
nDateTime = SVBT32ToUInt32(*(SVBT32*)(pExtended+(nIndex*18)));
}
- DateTime aDate = sw::ms::DTTM2DateTime(nDateTime);
+ DateTime aDate = msfilter::util::DTTM2DateTime(nDateTime);
String sTxt;
OutlinerParaObject *pOutliner = ImportAsOutliner( sTxt, pRes->nCp2OrIdx,
diff --git a/sw/source/filter/ww8/ww8par4.cxx b/sw/source/filter/ww8/ww8par4.cxx
index 083fbd2..2765d2c 100644
--- a/sw/source/filter/ww8/ww8par4.cxx
+++ b/sw/source/filter/ww8/ww8par4.cxx
@@ -522,7 +522,7 @@ void SwWW8ImplReader::Read_CRevisionMark(RedlineType_t eType,
// start of new revision mark, if not there default to first entry
sal_uInt16 nWWAutNo = pSprmCIbstRMark ? SVBT16ToShort(pSprmCIbstRMark) : 0;
sal_uInt32 nWWDate = pSprmCDttmRMark ? SVBT32ToUInt32(pSprmCDttmRMark): 0;
- DateTime aStamp(sw::ms::DTTM2DateTime(nWWDate));
+ DateTime aStamp(msfilter::util::DTTM2DateTime(nWWDate));
sal_uInt16 nAuthorNo = m_aAuthorInfos[nWWAutNo];
SwFltRedline aNewAttr(eType, nAuthorNo, aStamp);
NewAttr(aNewAttr);
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index 190b1bd..699b42b 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -150,47 +150,9 @@ static void lcl_putBorderProperty(std::stack<RTFParserState>& aStates, Id nId, R
pAttributes->set(nId, pValue);
}
-// NEEDSWORK: DocxAttributeOutput's impl_AppendTwoDigits does the same.
-static void lcl_AppendTwoDigits(OStringBuffer &rBuffer, sal_Int32 nNum)
-{
- if ( nNum < 0 || nNum > 99 )
- {
- rBuffer.append( "00" );
- return;
- }
-
- if ( nNum < 10 )
- rBuffer.append( '0' );
-
- rBuffer.append( nNum );
-}
-
-// NEEDSWORK: sw::ms::DTTM2DateTime and DocxAttributeOutput's
-// impl_DateTimeToOString could be combined to do the same.
static OString lcl_DTTM22OString(long lDTTM)
{
- sal_uInt16 lMin = (sal_uInt16)(lDTTM & 0x0000003F);
- lDTTM >>= 6;
- sal_uInt16 lHour= (sal_uInt16)(lDTTM & 0x0000001F);
- lDTTM >>= 5;
- sal_uInt16 lDay = (sal_uInt16)(lDTTM & 0x0000001F);
- lDTTM >>= 5;
- sal_uInt16 lMon = (sal_uInt16)(lDTTM & 0x0000000F);
- lDTTM >>= 4;
- sal_uInt16 lYear= (sal_uInt16)(lDTTM & 0x000001FF) + 1900;
-
- OStringBuffer aBuf;
- aBuf.append(sal_Int32(lYear));
- aBuf.append('-');
- lcl_AppendTwoDigits(aBuf, lMon);
- aBuf.append('-');
- lcl_AppendTwoDigits(aBuf, lDay);
- aBuf.append('T');
- lcl_AppendTwoDigits(aBuf, lHour);
- aBuf.append(':');
- lcl_AppendTwoDigits(aBuf, lMin);
- aBuf.append(":00Z");
- return aBuf.makeStringAndClear();
+ return msfilter::util::DateTimeToOString(msfilter::util::DTTM2DateTime(lDTTM));
}
static writerfilter::Reference<Properties>::Pointer_t lcl_getBookmarkProperties(int nPos, OUString& rString)
More information about the Libreoffice-commits
mailing list