Hi Eike,
I've been looking at providing support for the repeating character in
number formats. I've been playing abit with the code and what I have
sofar seems to work reasonably well ( no doubt there are plenty of edge
cases still to be discovered ) But.. life would be simpler I think if
we had just stored a plain format code like docx seems to rather than
the fancy pants xml that's there now :/ thus I need some input at the
very least on persisting the format code to odf. Currently I have
implemented a pretty simple change that introduces a new child element
to the number-style definition ( see 0002-xxxxx.patch attached ) Talking
to Kohei he says that you investigated those special financial formats
that use the repeat code at some point and I wondered if you had any
input, ideas or comments. I'm not at all sure about the xml choice I
made and would be happy to take on board any suggestions for that or....
perhaps you might have a sneaky way to avoid an odf change/addition
altogether. Also I worry a little that there seemed to be at one point
support for the '*' format code, I wonder what the history was or is it
just a case of unfinished business? Note: I partially re-enabled that
for the basic xls import support ( see
http://cgit.freedesktop.org/libreoffice/core/commit/?id=46e18bc915ac94a81462642cc9d56d29c04d0c46
and follow up patch
http://cgit.freedesktop.org/libreoffice/core/commit/?id=808dd658a265f565a638556322250a0957e8e535
)
sofar the results can be probably best explained by a simple screencast
http://users.freedesktop.org/~noelp/fillformat/financial-cell-format.ogv
thanks,
Noel
From d8171c61a2287a7667c1a04417e4e227015ff0a7 Mon Sep 17 00:00:00 2001
From: Noel Power <noel.power@novell.com>
Date: Tue, 17 Apr 2012 19:53:57 +0100
Subject: [PATCH 1/3] add some new test builtin currency formats
---
i18npool/source/localedata/data/en_GB.xml | 6 ++++++
i18npool/source/localedata/data/en_US.xml | 6 ++++++
2 files changed, 12 insertions(+), 0 deletions(-)
diff --git a/i18npool/source/localedata/data/en_GB.xml b/i18npool/source/localedata/data/en_GB.xml
index 0771e36..941da64 100644
--- a/i18npool/source/localedata/data/en_GB.xml
+++ b/i18npool/source/localedata/data/en_GB.xml
@@ -168,6 +168,12 @@
<FormatElement msgid="CurrencyFormatskey6" default="false" type="medium" usage="CURRENCY"
formatindex="17">
<FormatCode>[CURRENCY]#,##0.--;[RED]-[CURRENCY]#,##0.--</FormatCode>
</FormatElement>
+ <FormatElement msgid="CurrencyFormatskey7" default="false" type="short" usage="CURRENCY"
formatindex="80">
+ <FormatCode>[CURRENCY]* #,##0;-[CURRENCY]* #,##0</FormatCode>
+ </FormatElement>
+ <FormatElement msgid="CurrencyFormatskey8" default="false" type="medium" usage="CURRENCY"
formatindex="81">
+ <FormatCode>[CURRENCY]* #,##0.00;-[CURRENCY]* #,##0.00</FormatCode>
+ </FormatElement>
<FormatElement msgid="PercentFormatskey1" default="true" type="short" usage="PERCENT_NUMBER"
formatindex="8">
<FormatCode>0%</FormatCode>
</FormatElement>
diff --git a/i18npool/source/localedata/data/en_US.xml b/i18npool/source/localedata/data/en_US.xml
index fbf5ac1..5baddea 100644
--- a/i18npool/source/localedata/data/en_US.xml
+++ b/i18npool/source/localedata/data/en_US.xml
@@ -90,6 +90,12 @@
<FormatElement msgid="CurrencyFormatskey6" default="false" type="medium" usage="CURRENCY"
formatindex="17">
<FormatCode>[CURRENCY]#,##0.--;[RED]-[CURRENCY]#,##0.--</FormatCode>
</FormatElement>
+ <FormatElement msgid="CurrencyFormatskey7" default="false" type="short" usage="CURRENCY"
formatindex="80">
+ <FormatCode>[CURRENCY]* #,##0;-[CURRENCY]* #,##0</FormatCode>
+ </FormatElement>
+ <FormatElement msgid="CurrencyFormatskey8" default="false" type="medium" usage="CURRENCY"
formatindex="81">
+ <FormatCode>[CURRENCY]* #,##0.00;-[CURRENCY]* #,##0.00</FormatCode>
+ </FormatElement>
<FormatElement msgid="DateFormatskey1" default="true" type="short" usage="DATE"
formatindex="18">
<FormatCode>M/D/YY</FormatCode>
</FormatElement>
--
1.7.3.4
From 457788903e8057a5ead9bcc3b98607ded5138178 Mon Sep 17 00:00:00 2001
From: Noel Power <noel.power@novell.com>
Date: Wed, 18 Apr 2012 16:03:19 +0100
Subject: [PATCH 3/3] enable preview for 'special' '*' formats
---
cui/source/inc/numfmt.hxx | 3 +-
cui/source/tabpages/numfmt.cxx | 51 +++++++++++++++++++++++++++++++++++----
svl/inc/svl/zforlist.hxx | 3 +-
svl/source/numbers/zforlist.cxx | 11 +++++++-
svx/inc/svx/numfmtsh.hxx | 5 ++-
svx/source/items/numfmtsh.cxx | 12 +++++----
6 files changed, 69 insertions(+), 16 deletions(-)
diff --git a/cui/source/inc/numfmt.hxx b/cui/source/inc/numfmt.hxx
index 3a9e027..c2bde83 100644
--- a/cui/source/inc/numfmt.hxx
+++ b/cui/source/inc/numfmt.hxx
@@ -55,7 +55,8 @@ class SvxNumberPreviewImpl : public Window
private:
String aPrevStr;
Color aPrevCol;
-
+ sal_Int32 mnPos;
+ sal_Unicode mnChar;
void InitSettings( sal_Bool bForeground, sal_Bool bBackground );
protected:
diff --git a/cui/source/tabpages/numfmt.cxx b/cui/source/tabpages/numfmt.cxx
index 798da33..f847ae9 100644
--- a/cui/source/tabpages/numfmt.cxx
+++ b/cui/source/tabpages/numfmt.cxx
@@ -51,6 +51,11 @@
#include <sfx2/basedlgs.hxx>
#include "svx/flagsdef.hxx"
#include <vector>
+#include <com/sun/star/lang/XServiceInfo.hpp>
+
+using ::com::sun::star::uno::Reference;
+using ::com::sun::star::lang::XServiceInfo;
+using ::com::sun::star::uno::UNO_QUERY;
#define NUMKEY_UNDEFINED SAL_MAX_UINT32
@@ -82,8 +87,9 @@ static sal_uInt16 pRanges[] =
SvxNumberPreviewImpl::SvxNumberPreviewImpl( Window* pParent, const ResId& rResId ) :
- Window( pParent, rResId )
-
+ Window( pParent, rResId ),
+ mnPos( STRING_NOTFOUND ),
+ mnChar( 0x0 )
{
Font aFont( GetFont() );
aFont.SetTransparent( sal_True );
@@ -122,7 +128,16 @@ SvxNumberPreviewImpl::~SvxNumberPreviewImpl()
void SvxNumberPreviewImpl::NotifyChange( const String& rPrevStr,
const Color* pColor )
{
+ // detect and strip out '*' related placeholders
aPrevStr = rPrevStr;
+ mnPos = aPrevStr.Search( 0x1B );
+ if ( mnPos != STRING_NOTFOUND )
+ {
+ --mnPos;
+ mnChar = aPrevStr.GetChar( mnPos );
+ // delete placeholder and char to repeat
+ aPrevStr.Erase( mnPos, 2 );
+ }
svtools::ColorConfig aColorConfig;
Color aWindowTextColor( aColorConfig.GetColorValue( svtools::FONTCOLOR ).nColor );
aPrevCol = pColor ? *pColor : aWindowTextColor;
@@ -145,12 +160,26 @@ void SvxNumberPreviewImpl::Paint( const Rectangle& )
{
Font aDrawFont = GetFont();
Size aSzWnd = GetOutputSizePixel();
- Point aPosText = Point( (aSzWnd.Width() - GetTextWidth( aPrevStr )) /2,
- (aSzWnd.Height() - GetTextHeight())/2 );
+ String aTmpStr( aPrevStr );
+ long nLeadSpace = (aSzWnd.Width() - GetTextWidth( aTmpStr )) /2;
aDrawFont.SetColor( aPrevCol );
SetFont( aDrawFont );
- DrawText( aPosText, aPrevStr );
+
+ if ( mnPos != STRING_NOTFOUND )
+ {
+ long nCharWidth = GetTextWidth( rtl::OUString::valueOf( mnChar ) );
+ int nNumCharsToInsert = nLeadSpace / nCharWidth;
+
+ if ( nNumCharsToInsert )
+ {
+ for ( int i = 0; i < nNumCharsToInsert; ++i )
+ aTmpStr.Insert( mnChar, mnPos );
+ }
+ }
+ Point aPosText = Point( ( mnPos != STRING_NOTFOUND ) ? 0 : nLeadSpace,
+ (aSzWnd.Height() - GetTextHeight())/2 );
+ DrawText( aPosText, aTmpStr );
}
// -----------------------------------------------------------------------
@@ -523,6 +552,18 @@ void SvxNumberFormatTabPage::Reset( const SfxItemSet& rSet )
nValDouble,
&aValString );
+
+ bool bUseStarFormat = false;
+ SfxObjectShell* pDocSh = SfxObjectShell::Current();
+ if ( pDocSh )
+ {
+ // is this a calc document
+ Reference< XServiceInfo > xSI( pDocSh->GetModel(), UNO_QUERY );
+ if ( xSI.is() )
+ bUseStarFormat = xSI->supportsService( rtl::OUString(
"com.sun.star.sheet.SpreadsheetDocument" ) );
+ }
+ pNumFmtShell->SetUseStarFormat( bUseStarFormat );
+
FillCurrencyBox();
String aPrevString;
diff --git a/svl/inc/svl/zforlist.hxx b/svl/inc/svl/zforlist.hxx
index 7f2a7ff..989df98 100644
--- a/svl/inc/svl/zforlist.hxx
+++ b/svl/inc/svl/zforlist.hxx
@@ -517,7 +517,8 @@ public:
*/
bool GetPreviewString( const String& sFormatString, double fPreviewNumber,
String& sOutString, Color** ppColor,
- LanguageType eLnge = LANGUAGE_DONTKNOW );
+ LanguageType eLnge = LANGUAGE_DONTKNOW,
+ bool bUseStarFormat = false );
/** Same as <method>GetPreviewString</method> but the format code string
may be either language/country eLnge or en_US english US */
diff --git a/svl/source/numbers/zforlist.cxx b/svl/source/numbers/zforlist.cxx
index d897274..c799570 100644
--- a/svl/source/numbers/zforlist.cxx
+++ b/svl/source/numbers/zforlist.cxx
@@ -1637,7 +1637,8 @@ bool SvNumberFormatter::GetPreviewString(const String& sFormatString,
double fPreviewNumber,
String& sOutString,
Color** ppColor,
- LanguageType eLnge)
+ LanguageType eLnge,
+ bool bUseStarFormat )
{
if (sFormatString.Len() == 0) // keinen Leerstring
return false;
@@ -1660,9 +1661,15 @@ bool SvNumberFormatter::GetPreviewString(const String& sFormatString,
// formate anlegen
nKey = ImpIsEntry(p_Entry->GetFormatstring(),CLOffset, eLnge);
if (nKey != NUMBERFORMAT_ENTRY_NOT_FOUND) // schon vorhanden
- GetOutputString(fPreviewNumber,nKey,sOutString,ppColor);
+ GetOutputString(fPreviewNumber,nKey,sOutString,ppColor, bUseStarFormat);
else
+ {
+ if ( bUseStarFormat )
+ p_Entry->SetStarFormatSupport( true );
p_Entry->GetOutputString(fPreviewNumber,sOutString, ppColor);
+ if ( bUseStarFormat )
+ p_Entry->SetStarFormatSupport( false );
+ }
delete p_Entry;
return true;
}
diff --git a/svx/inc/svx/numfmtsh.hxx b/svx/inc/svx/numfmtsh.hxx
index d6005ab..3cd1df5 100644
--- a/svx/inc/svx/numfmtsh.hxx
+++ b/svx/inc/svx/numfmtsh.hxx
@@ -184,7 +184,8 @@ public:
sal_uInt16 FindCurrencyTableEntry( const String& rFmtString, bool &bTestBanking );
bool IsInTable(sal_uInt16 nPos,bool bTmpBanking,const String &rFmtString);
-
+ void SetUseStarFormat( bool bUse ) { bUseStarFormat = bUse; }
+ bool IsUseStarFormat( void ) { return bUseStarFormat; }
private:
static const double DEFAULT_NUMVALUE;
@@ -206,7 +207,7 @@ private:
bool bBankingSymbol;
sal_uInt16 nCurCurrencyEntryPos;
std::vector<String*> aCurrencyFormatList;
-
+ bool bUseStarFormat;
#ifdef _SVX_NUMFMTSH_CXX
SVX_DLLPRIVATE short FillEntryList_Impl( std::vector<String*>& rList );
SVX_DLLPRIVATE void FillEListWithStd_Impl( std::vector<String*>& rList,sal_uInt16 aPrivCat,
short &Pos);
diff --git a/svx/source/items/numfmtsh.cxx b/svx/source/items/numfmtsh.cxx
index d696123..7530982 100644
--- a/svx/source/items/numfmtsh.cxx
+++ b/svx/source/items/numfmtsh.cxx
@@ -84,7 +84,8 @@ SvxNumberFormatShell::SvxNumberFormatShell( SvNumberFormatter* pNumFormatter,
nCurFormatKey ( nFormatKey ),
pCurCurrencyEntry(NULL),
bBankingSymbol (false),
- nCurCurrencyEntryPos((sal_uInt16) SELPOS_NONE)
+ nCurCurrencyEntryPos((sal_uInt16) SELPOS_NONE),
+ bUseStarFormat (false)
{
nValNum = DEFAULT_NUMVALUE;
@@ -115,7 +116,8 @@ SvxNumberFormatShell::SvxNumberFormatShell( SvNumberFormatter* pNumFormatter,
nCurFormatKey ( nFormatKey ),
pCurCurrencyEntry(NULL),
bBankingSymbol (false),
- nCurCurrencyEntryPos((sal_uInt16) SELPOS_NONE)
+ nCurCurrencyEntryPos((sal_uInt16) SELPOS_NONE),
+ bUseStarFormat (false)
{
// #50441# When used in Writer, the SvxNumberInfoItem contains the
// original string in addition to the value
@@ -439,7 +441,7 @@ void SvxNumberFormatShell::MakePreviewString( const String& rFormatStr,
// real preview - not implemented in NumberFormatter for text formats
pFormatter->GetPreviewString( rFormatStr, nValNum, rPreviewStr,
- &rpFontColor, eCurLanguage );
+ &rpFontColor, eCurLanguage, bUseStarFormat );
}
else
{
@@ -453,7 +455,7 @@ void SvxNumberFormatShell::MakePreviewString( const String& rFormatStr,
rPreviewStr, &rpFontColor );
else
pFormatter->GetOutputString( nValNum, nExistingFormat,
- rPreviewStr, &rpFontColor );
+ rPreviewStr, &rpFontColor, bUseStarFormat );
}
}
@@ -1153,7 +1155,7 @@ void SvxNumberFormatShell::GetPreviewString_Impl( String& rString, Color*&
rpCol
if ( bUseText )
pFormatter->GetOutputString( aValStr, nCurFormatKey, rString, &rpColor );
else
- pFormatter->GetOutputString( nValNum, nCurFormatKey, rString, &rpColor );
+ pFormatter->GetOutputString( nValNum, nCurFormatKey, rString, &rpColor, bUseStarFormat );
}
// -----------------------------------------------------------------------
--
1.7.3.4
From 8a2f12168cb450de589853285871874231ec130f Mon Sep 17 00:00:00 2001
From: Noel Power <noel.power@novell.com>
Date: Tue, 17 Apr 2012 20:37:02 +0100
Subject: [PATCH 2/3] support new xml number:repeated elem for number-style namespace
this is used to define the char to be repeated in a number format
e.g repeat ' ' 0 or more times to fill available space
<number:number-style style:name="N130P0" style:volatile="true">
<number:text> $</number:text>
--> <number:repeated> </number:repeated>
---
xmloff/inc/xmloff/xmlnumfe.hxx | 1 +
xmloff/source/style/xmlnumfe.cxx | 12 ++++++++++++
xmloff/source/style/xmlnumfi.cxx | 10 ++++++++++
3 files changed, 23 insertions(+), 0 deletions(-)
diff --git a/xmloff/inc/xmloff/xmlnumfe.hxx b/xmloff/inc/xmloff/xmlnumfe.hxx
index b1f00e7..9998cad 100644
--- a/xmloff/inc/xmloff/xmlnumfe.hxx
+++ b/xmloff/inc/xmloff/xmlnumfe.hxx
@@ -95,6 +95,7 @@ private:
SAL_DLLPRIVATE void WriteMapElement_Impl( sal_Int32 nOp, double fLimit,
sal_Int32 nKey, sal_Int32 nPart );
+ SAL_DLLPRIVATE void WriteRepeatedElement_Impl( sal_Unicode ch );
SAL_DLLPRIVATE sal_Bool WriteTextWithCurrency_Impl( const ::rtl::OUString& rString,
const ::com::sun::star::lang::Locale& rLocale );
SAL_DLLPRIVATE void ExportPart_Impl( const SvNumberformat& rFormat, sal_uInt32 nKey,
diff --git a/xmloff/source/style/xmlnumfe.cxx b/xmloff/source/style/xmlnumfe.cxx
index 714dcda..71aa5ef 100644
--- a/xmloff/source/style/xmlnumfe.cxx
+++ b/xmloff/source/style/xmlnumfe.cxx
@@ -537,6 +537,14 @@ void SvXMLNumFmtExport::WriteMinutesElement_Impl( sal_Bool bLong )
sal_True, sal_False );
}
+void SvXMLNumFmtExport::WriteRepeatedElement_Impl( sal_Unicode nChar )
+{
+ FinishTextElement_Impl();
+ SvXMLElementExport aElem( rExport, XML_NAMESPACE_NUMBER, XML_REPEATED,
+ sal_True, sal_False );
+ rExport.Characters( OUString::valueOf( nChar ) );
+}
+
void SvXMLNumFmtExport::WriteSecondsElement_Impl( sal_Bool bLong, sal_uInt16 nDecimals )
{
FinishTextElement_Impl();
@@ -1567,6 +1575,10 @@ void SvXMLNumFmtExport::ExportPart_Impl( const SvNumberformat& rFormat,
sal_uInt
WriteAMPMElement_Impl(); // short/long?
bAnyContent = sal_True;
break;
+ case NF_SYMBOLTYPE_STAR :
+ if ( pElemStr && pElemStr->Len() > 1 )
+ WriteRepeatedElement_Impl( pElemStr->GetChar( 1 ) );
+ break;
}
nPrevType = nElemType;
++nPos;
diff --git a/xmloff/source/style/xmlnumfi.cxx b/xmloff/source/style/xmlnumfi.cxx
index bd953a3..ecd33b9 100644
--- a/xmloff/source/style/xmlnumfi.cxx
+++ b/xmloff/source/style/xmlnumfi.cxx
@@ -246,6 +246,7 @@ public:
enum SvXMLStyleTokens
{
XML_TOK_STYLE_TEXT,
+ XML_TOK_STYLE_REPEATED,
XML_TOK_STYLE_NUMBER,
XML_TOK_STYLE_SCIENTIFIC_NUMBER,
XML_TOK_STYLE_FRACTION,
@@ -521,6 +522,7 @@ const SvXMLTokenMap& SvXMLNumImpData::GetStyleElemTokenMap()
{
// elements in a style
{ XML_NAMESPACE_NUMBER, XML_TEXT, XML_TOK_STYLE_TEXT },
+ { XML_NAMESPACE_NUMBER, XML_REPEATED, XML_TOK_STYLE_REPEATED },
{ XML_NAMESPACE_NUMBER, XML_NUMBER, XML_TOK_STYLE_NUMBER },
{ XML_NAMESPACE_NUMBER, XML_SCIENTIFIC_NUMBER, XML_TOK_STYLE_SCIENTIFIC_NUMBER },
{ XML_NAMESPACE_NUMBER, XML_FRACTION, XML_TOK_STYLE_FRACTION },
@@ -1104,6 +1106,13 @@ void SvXMLNumFmtElementContext::EndElement()
case XML_TOK_STYLE_TEXT_CONTENT:
rParent.AddToCode( OUString::valueOf((sal_Unicode)'@') );
break;
+ case XML_TOK_STYLE_REPEATED:
+ if ( aContent.getLength() )
+ {
+ rParent.AddToCode( OUString::valueOf((sal_Unicode)'*') );
+ rParent.AddToCode( OUString::valueOf( aContent[0] ) );
+ }
+ break;
case XML_TOK_STYLE_BOOLEAN:
// ignored - only default boolean format is supported
break;
@@ -1436,6 +1445,7 @@ SvXMLImportContext* SvXMLNumFormatContext::CreateChildContext(
switch (nToken)
{
case XML_TOK_STYLE_TEXT:
+ case XML_TOK_STYLE_REPEATED:
case XML_TOK_STYLE_NUMBER:
case XML_TOK_STYLE_SCIENTIFIC_NUMBER:
case XML_TOK_STYLE_FRACTION:
--
1.7.3.4
Context
- support for repeating format code in calc · Noel Power
Privacy Policy |
Impressum (Legal Info) |
Copyright information: Unless otherwise specified, all text and images
on this website are licensed under the
Creative Commons Attribution-Share Alike 3.0 License.
This does not include the source code of LibreOffice, which is
licensed under the Mozilla Public License (
MPLv2).
"LibreOffice" and "The Document Foundation" are
registered trademarks of their corresponding registered owners or are
in actual use as trademarks in one or more countries. Their respective
logos and icons are also subject to international copyright laws. Use
thereof is explained in our
trademark policy.