diff options
author | Vladimir Glazunov <vg@openoffice.org> | 2009-12-14 11:09:26 +0100 |
---|---|---|
committer | Vladimir Glazunov <vg@openoffice.org> | 2009-12-14 11:09:26 +0100 |
commit | c4fa6c6f7af6167bea78a404f34c40fbe2dde1b6 (patch) | |
tree | d505fc29fe029f1d820452aec329d2fcf04de30d /sc/source/filter | |
parent | 5e2a3643fa7d4adb72268c4908c71faaac433f0d (diff) | |
parent | 1379d7408a3b327575eff4c937507beb14d96239 (diff) |
CWS-TOOLING: integrate CWS calc32stopper6_DEV300
Diffstat (limited to 'sc/source/filter')
-rw-r--r-- | sc/source/filter/excel/xehelper.cxx | 6 | ||||
-rw-r--r-- | sc/source/filter/excel/xestyle.cxx | 230 | ||||
-rw-r--r-- | sc/source/filter/inc/xestyle.hxx | 43 |
3 files changed, 166 insertions, 113 deletions
diff --git a/sc/source/filter/excel/xehelper.cxx b/sc/source/filter/excel/xehelper.cxx index 76fac622d..30b30639f 100644 --- a/sc/source/filter/excel/xehelper.cxx +++ b/sc/source/filter/excel/xehelper.cxx @@ -1,7 +1,7 @@ /************************************************************************* * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * + * * Copyright 2008 by Sun Microsystems, Inc. * * OpenOffice.org - a multi-platform office productivity suite @@ -415,7 +415,7 @@ XclExpStringRef lclCreateFormattedString( nScript = nLastScript; // construct font from current text portion - SvxFont aFont( XclExpFontBuffer::GetFontFromItemSet( rItemSet, nScript ) ); + SvxFont aFont( XclExpFontHelper::GetFontFromItemSet( rRoot, rItemSet, nScript ) ); // Excel start position of this portion sal_uInt16 nXclPortionStart = xString->Len(); @@ -529,7 +529,7 @@ XclExpStringRef lclCreateFormattedString( sal_Int16 nScript = xBreakIt->getScriptType( aXclPortionText, 0 ); if( nScript == ApiScriptType::WEAK ) nScript = nLastScript; - SvxFont aFont( XclExpFontBuffer::GetFontFromItemSet( aItemSet, nScript ) ); + SvxFont aFont( XclExpFontHelper::GetFontFromItemSet( rRoot, aItemSet, nScript ) ); nLastScript = nScript; // add escapement diff --git a/sc/source/filter/excel/xestyle.cxx b/sc/source/filter/excel/xestyle.cxx index df21765e7..f70452461 100644 --- a/sc/source/filter/excel/xestyle.cxx +++ b/sc/source/filter/excel/xestyle.cxx @@ -823,6 +823,120 @@ void XclExpPalette::WriteBody( XclExpStream& rStrm ) namespace { +typedef ::std::pair< USHORT, sal_Int16 > WhichAndScript; + +sal_Int16 lclCheckFontItems( const SfxItemSet& rItemSet, + const WhichAndScript& rWAS1, const WhichAndScript& rWAS2, const WhichAndScript& rWAS3 ) +{ + if( ScfTools::CheckItem( rItemSet, rWAS1.first, false ) ) return rWAS1.second; + if( ScfTools::CheckItem( rItemSet, rWAS2.first, false ) ) return rWAS2.second; + if( ScfTools::CheckItem( rItemSet, rWAS3.first, false ) ) return rWAS3.second; + return 0; +}; + +} // namespace + +/*static*/ sal_Int16 XclExpFontHelper::GetFirstUsedScript( const XclExpRoot& rRoot, const SfxItemSet& rItemSet ) +{ + namespace ApiScriptType = ::com::sun::star::i18n::ScriptType; + + /* #i17050# #i107170# We need to determine which font items are set in the + item set, and which script type we should prefer according to the + current language settings. */ + + static const WhichAndScript WAS_LATIN( ATTR_FONT, ::com::sun::star::i18n::ScriptType::LATIN ); + static const WhichAndScript WAS_ASIAN( ATTR_CJK_FONT, ::com::sun::star::i18n::ScriptType::ASIAN ); + static const WhichAndScript WAS_CMPLX( ATTR_CTL_FONT, ::com::sun::star::i18n::ScriptType::COMPLEX ); + + /* #114008# do not let a font from a parent style override an explicit + cell font. */ + + sal_Int16 nDefScript = rRoot.GetDefApiScript(); + sal_Int16 nScript = 0; + const SfxItemSet* pCurrSet = &rItemSet; + + while( (nScript == 0) && pCurrSet ) + { + switch( nDefScript ) + { + case ApiScriptType::LATIN: + nScript = lclCheckFontItems( *pCurrSet, WAS_LATIN, WAS_CMPLX, WAS_ASIAN ); + break; + case ApiScriptType::ASIAN: + nScript = lclCheckFontItems( *pCurrSet, WAS_ASIAN, WAS_CMPLX, WAS_LATIN ); + break; + case ApiScriptType::COMPLEX: + nScript = lclCheckFontItems( *pCurrSet, WAS_CMPLX, WAS_ASIAN, WAS_LATIN ); + break; + default: + DBG_ERRORFILE( "XclExpFontHelper::GetFirstUsedScript - unknown script type" ); + nScript = ApiScriptType::LATIN; + }; + pCurrSet = pCurrSet->GetParent(); + } + + return nScript; +} + +/*static*/ Font XclExpFontHelper::GetFontFromItemSet( const XclExpRoot& rRoot, const SfxItemSet& rItemSet, sal_Int16 nScript ) +{ + namespace ApiScriptType = ::com::sun::star::i18n::ScriptType; + + // if WEAK is passed, guess script type from existing items in the item set + if( nScript == ApiScriptType::WEAK ) + nScript = GetFirstUsedScript( rRoot, rItemSet ); + + // convert to core script type constants + BYTE nScScript = SCRIPTTYPE_LATIN; + switch( nScript ) + { + case ApiScriptType::LATIN: nScScript = SCRIPTTYPE_LATIN; break; + case ApiScriptType::ASIAN: nScScript = SCRIPTTYPE_ASIAN; break; + case ApiScriptType::COMPLEX: nScScript = SCRIPTTYPE_COMPLEX; break; + default: DBG_ERRORFILE( "XclExpFontHelper::GetFontFromItemSet - unknown script type" ); + } + + // fill the font object + Font aFont; + ScPatternAttr::GetFont( aFont, rItemSet, SC_AUTOCOL_RAW, 0, 0, 0, nScScript ); + return aFont; +} + +/*static*/ bool XclExpFontHelper::CheckItems( const XclExpRoot& rRoot, const SfxItemSet& rItemSet, sal_Int16 nScript, bool bDeep ) +{ + static const USHORT pnCommonIds[] = { + ATTR_FONT_UNDERLINE, ATTR_FONT_CROSSEDOUT, ATTR_FONT_CONTOUR, + ATTR_FONT_SHADOWED, ATTR_FONT_COLOR, ATTR_FONT_LANGUAGE, 0 }; + static const USHORT pnLatinIds[] = { + ATTR_FONT, ATTR_FONT_HEIGHT, ATTR_FONT_WEIGHT, ATTR_FONT_POSTURE, 0 }; + static const USHORT pnAsianIds[] = { + ATTR_CJK_FONT, ATTR_CJK_FONT_HEIGHT, ATTR_CJK_FONT_WEIGHT, ATTR_CJK_FONT_POSTURE, 0 }; + static const USHORT pnComplexIds[] = { + ATTR_CTL_FONT, ATTR_CTL_FONT_HEIGHT, ATTR_CTL_FONT_WEIGHT, ATTR_CTL_FONT_POSTURE, 0 }; + + bool bUsed = ScfTools::CheckItems( rItemSet, pnCommonIds, bDeep ); + if( !bUsed ) + { + namespace ApiScriptType = ::com::sun::star::i18n::ScriptType; + // if WEAK is passed, guess script type from existing items in the item set + if( nScript == ApiScriptType::WEAK ) + nScript = GetFirstUsedScript( rRoot, rItemSet ); + // check the correct items + switch( nScript ) + { + case ApiScriptType::LATIN: bUsed = ScfTools::CheckItems( rItemSet, pnLatinIds, bDeep ); break; + case ApiScriptType::ASIAN: bUsed = ScfTools::CheckItems( rItemSet, pnAsianIds, bDeep ); break; + case ApiScriptType::COMPLEX: bUsed = ScfTools::CheckItems( rItemSet, pnComplexIds, bDeep ); break; + default: DBG_ERRORFILE( "XclExpFontHelper::CheckItems - unknown script type" ); + } + } + return bUsed; +} + +// ---------------------------------------------------------------------------- + +namespace { + sal_uInt32 lclCalcHash( const XclFontData& rFontData ) { sal_uInt32 nHash = rFontData.maName.Len(); @@ -993,7 +1107,8 @@ sal_uInt16 XclExpFontBuffer::Insert( const SfxItemSet& rItemSet, sal_Int16 nScript, XclExpColorType eColorType, bool bAppFont ) { // #i17050# #114008# #115495# script type now provided by caller - return Insert( GetFontFromItemSet( rItemSet, nScript ), eColorType, bAppFont ); + Font aFont = XclExpFontHelper::GetFontFromItemSet( GetRoot(), rItemSet, nScript ); + return Insert( aFont, eColorType, bAppFont ); } sal_uInt16 XclExpFontBuffer::Insert( const ScPatternAttr& rPattern, @@ -1022,90 +1137,6 @@ void XclExpFontBuffer::SaveXml( XclExpXmlStream& rStrm ) rStyleSheet->endElement( XML_fonts ); } -sal_Int16 XclExpFontBuffer::GetFirstUsedScript( const SfxItemSet& rItemSet ) -{ - /* #i17050# We need to determine if a CJK or CTL font item is set in the - item set. It is possible that both may be present. In this case, - we will choose CJK. Either option is equally correct. */ - - namespace ApiScriptType = ::com::sun::star::i18n::ScriptType; - sal_Int16 nScript = ApiScriptType::LATIN; - - // #114008# do not let a font from a parent style override an explicit cell font - const SfxItemSet* pCurrSet = &rItemSet; - bool bFound = false; - while( !bFound && pCurrSet ) - { - bFound = true; - if( ScfTools::CheckItem( *pCurrSet, ATTR_CJK_FONT, false ) ) - nScript = ApiScriptType::ASIAN; - else if( ScfTools::CheckItem( *pCurrSet, ATTR_CTL_FONT, false ) ) - nScript = ApiScriptType::COMPLEX; - else if( ScfTools::CheckItem( *pCurrSet, ATTR_FONT, false ) ) - nScript = ApiScriptType::LATIN; - else - bFound = false; - pCurrSet = pCurrSet->GetParent(); - } - - return nScript; -} - -Font XclExpFontBuffer::GetFontFromItemSet( const SfxItemSet& rItemSet, sal_Int16 nScript ) -{ - namespace ApiScriptType = ::com::sun::star::i18n::ScriptType; - - // if WEAK is passed, guess script type from existing items in the item set - if( nScript == ApiScriptType::WEAK ) - nScript = GetFirstUsedScript( rItemSet ); - - // convert to core script type constants - BYTE nScScript = SCRIPTTYPE_LATIN; - switch( nScript ) - { - case ApiScriptType::LATIN: nScScript = SCRIPTTYPE_LATIN; break; - case ApiScriptType::ASIAN: nScScript = SCRIPTTYPE_ASIAN; break; - case ApiScriptType::COMPLEX: nScScript = SCRIPTTYPE_COMPLEX; break; - default: DBG_ERRORFILE( "XclExpFontBuffer::GetFontFromItemSet - unknown script type" ); - } - - // fill the font object - Font aFont; - ScPatternAttr::GetFont( aFont, rItemSet, SC_AUTOCOL_RAW, 0, 0, 0, nScScript ); - return aFont; -} - -bool XclExpFontBuffer::CheckItems( const SfxItemSet& rItemSet, sal_Int16 nScript, bool bDeep ) -{ - static const USHORT pnCommonIds[] = { - ATTR_FONT_UNDERLINE, ATTR_FONT_CROSSEDOUT, ATTR_FONT_CONTOUR, - ATTR_FONT_SHADOWED, ATTR_FONT_COLOR, ATTR_FONT_LANGUAGE, 0 }; - static const USHORT pnLatinIds[] = { - ATTR_FONT, ATTR_FONT_HEIGHT, ATTR_FONT_WEIGHT, ATTR_FONT_POSTURE, 0 }; - static const USHORT pnAsianIds[] = { - ATTR_CJK_FONT, ATTR_CJK_FONT_HEIGHT, ATTR_CJK_FONT_WEIGHT, ATTR_CJK_FONT_POSTURE, 0 }; - static const USHORT pnComplexIds[] = { - ATTR_CTL_FONT, ATTR_CTL_FONT_HEIGHT, ATTR_CTL_FONT_WEIGHT, ATTR_CTL_FONT_POSTURE, 0 }; - - bool bUsed = ScfTools::CheckItems( rItemSet, pnCommonIds, bDeep ); - if( !bUsed ) - { - namespace ApiScriptType = ::com::sun::star::i18n::ScriptType; - // if WEAK is passed, guess script type from existing items in the item set - if( nScript == ApiScriptType::WEAK ) - nScript = GetFirstUsedScript( rItemSet ); - // check the correct items - switch( nScript ) - { - case ApiScriptType::LATIN: bUsed = ScfTools::CheckItems( rItemSet, pnLatinIds, bDeep ); break; - case ApiScriptType::ASIAN: bUsed = ScfTools::CheckItems( rItemSet, pnAsianIds, bDeep ); break; - case ApiScriptType::COMPLEX: bUsed = ScfTools::CheckItems( rItemSet, pnComplexIds, bDeep ); break; - default: DBG_ERRORFILE( "XclExpFontBuffer::CheckItems - unknown script type" ); - } - } - return bUsed; -} - // private -------------------------------------------------------------------- void XclExpFontBuffer::InitDefaultFonts() @@ -1696,7 +1727,7 @@ static void lcl_WriteBorder( XclExpXmlStream& rStrm, sal_Int32 nElement, sal_uIn if( nLineStyle == EXC_LINE_NONE ) rStyleSheet->singleElement( nElement, FSEND ); else if( rColor == Color( 0, 0, 0, 0 ) ) - rStyleSheet->singleElement( nElement, + rStyleSheet->singleElement( nElement, XML_style, ToLineStyle( nLineStyle ), FSEND ); else @@ -1844,7 +1875,7 @@ void XclExpCellArea::SaveXml( XclExpXmlStream& rStrm ) const FSEND ); rStyleSheet->endElement( XML_patternFill ); } - + rStyleSheet->endElement( XML_fill ); } @@ -1885,7 +1916,8 @@ XclExpXF::XclExpXF( const XclExpRoot& rRoot, const SfxStyleSheetBase& rStyleShee mnParentXFId( XclExpXFBuffer::GetXFIdFromIndex( EXC_XF_STYLEPARENT ) ) { bool bDefStyle = (rStyleSheet.GetName() == ScGlobal::GetRscString( STR_STYLENAME_STANDARD )); - Init( const_cast< SfxStyleSheetBase& >( rStyleSheet ).GetItemSet(), ::com::sun::star::i18n::ScriptType::WEAK, + sal_Int16 nScript = bDefStyle ? GetDefApiScript() : ::com::sun::star::i18n::ScriptType::WEAK; + Init( const_cast< SfxStyleSheetBase& >( rStyleSheet ).GetItemSet(), nScript, NUMBERFORMAT_ENTRY_NOT_FOUND, EXC_FONT_NOTFOUND, false, bDefStyle ); } @@ -1947,7 +1979,7 @@ void XclExpXF::Init( const SfxItemSet& rItemSet, sal_Int16 nScript, if( nForceXclFont == EXC_FONT_NOTFOUND ) { mnXclFont = GetFontBuffer().Insert( rItemSet, nScript, EXC_COLOR_CELLTEXT, bDefStyle ); - mbFontUsed = XclExpFontBuffer::CheckItems( rItemSet, nScript, IsStyleXF() ); + mbFontUsed = XclExpFontHelper::CheckItems( GetRoot(), rItemSet, nScript, IsStyleXF() ); } else { @@ -2089,7 +2121,7 @@ XclExpDefaultXF::XclExpDefaultXF( const XclExpRoot& rRoot, bool bCellXF ) : //UNUSED2008-05 if( IsCellXF() ) //UNUSED2008-05 mnParentXFId = nParentXFId; //UNUSED2008-05 } -//UNUSED2008-05 +//UNUSED2008-05 //UNUSED2008-05 void XclExpDefaultXF::SetUsedFlags( //UNUSED2008-05 bool bProtUsed, bool bFontUsed, bool bFmtUsed, //UNUSED2008-05 bool bAlignUsed, bool bBorderUsed, bool bAreaUsed ) @@ -2101,25 +2133,25 @@ XclExpDefaultXF::XclExpDefaultXF( const XclExpRoot& rRoot, bool bCellXF ) : //UNUSED2008-05 mbBorderUsed = bBorderUsed; //UNUSED2008-05 mbAreaUsed = bAreaUsed; //UNUSED2008-05 } -//UNUSED2008-05 +//UNUSED2008-05 //UNUSED2008-05 void XclExpDefaultXF::SetProtection( const XclExpCellProt& rProtection ) //UNUSED2008-05 { //UNUSED2008-05 maProtection = rProtection; //UNUSED2008-05 mbProtUsed = true; //UNUSED2008-05 } -//UNUSED2008-05 +//UNUSED2008-05 //UNUSED2008-05 void XclExpDefaultXF::SetAlignment( const XclExpCellAlign& rAlignment ) //UNUSED2008-05 { //UNUSED2008-05 maAlignment = rAlignment; //UNUSED2008-05 mbAlignUsed = true; //UNUSED2008-05 } -//UNUSED2008-05 +//UNUSED2008-05 //UNUSED2008-05 void XclExpDefaultXF::SetBorder( const XclExpCellBorder& rBorder ) //UNUSED2008-05 { //UNUSED2008-05 maBorder = rBorder; //UNUSED2008-05 mbBorderUsed = true; //UNUSED2008-05 } -//UNUSED2008-05 +//UNUSED2008-05 //UNUSED2008-05 void XclExpDefaultXF::SetArea( const XclExpCellArea& rArea ) //UNUSED2008-05 { //UNUSED2008-05 maArea = rArea; @@ -2259,7 +2291,7 @@ struct XclExpBorderPred bool XclExpBorderPred::operator()( const XclExpCellBorder& rBorder ) const { - return + return mrBorder.mnLeftColor == rBorder.mnLeftColor && mrBorder.mnRightColor == rBorder.mnRightColor && mrBorder.mnTopColor == rBorder.mnTopColor && @@ -2560,10 +2592,10 @@ void XclExpXFBuffer::SaveXml( XclExpXmlStream& rStrm ) void XclExpXFBuffer::SaveXFXml( XclExpXmlStream& rStrm, XclExpXF& rXF ) { - XclExpBorderList::iterator aBorderPos = + XclExpBorderList::iterator aBorderPos = std::find_if( maBorders.begin(), maBorders.end(), XclExpBorderPred( rXF.GetBorderData() ) ); DBG_ASSERT( aBorderPos != maBorders.end(), "XclExpXFBuffer::SaveXml - Invalid @borderId!" ); - XclExpFillList::iterator aFillPos = + XclExpFillList::iterator aFillPos = std::find_if( maFills.begin(), maFills.end(), XclExpFillPred( rXF.GetAreaData() ) ); DBG_ASSERT( aFillPos != maFills.end(), "XclExpXFBuffer::SaveXml - Invalid @fillId!" ); @@ -2847,7 +2879,7 @@ XclExpXmlStyleSheet::XclExpXmlStyleSheet( const XclExpRoot& rRoot ) void XclExpXmlStyleSheet::SaveXml( XclExpXmlStream& rStrm ) { - sax_fastparser::FSHelperPtr aStyleSheet = rStrm.CreateOutputStream( + sax_fastparser::FSHelperPtr aStyleSheet = rStrm.CreateOutputStream( OUString::createFromAscii( "xl/styles.xml" ), OUString::createFromAscii( "styles.xml" ), rStrm.GetCurrentStream()->getOutputStream(), @@ -2856,7 +2888,7 @@ void XclExpXmlStyleSheet::SaveXml( XclExpXmlStream& rStrm ) rStrm.PushStream( aStyleSheet ); aStyleSheet->startElement( XML_styleSheet, - XML_xmlns, "http://schemas.openxmlformats.org/spreadsheetml/2006/main", + XML_xmlns, "http://schemas.openxmlformats.org/spreadsheetml/2006/main", FSEND ); CreateRecord( EXC_ID_FORMATLIST )->SaveXml( rStrm ); diff --git a/sc/source/filter/inc/xestyle.hxx b/sc/source/filter/inc/xestyle.hxx index 4e8fc4773..d26739b86 100644 --- a/sc/source/filter/inc/xestyle.hxx +++ b/sc/source/filter/inc/xestyle.hxx @@ -1,7 +1,7 @@ /************************************************************************* * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * + * * Copyright 2008 by Sun Microsystems, Inc. * * OpenOffice.org - a multi-platform office productivity suite @@ -139,6 +139,36 @@ const size_t EXC_FONTLIST_NOTFOUND = static_cast< size_t >( -1 ); // ---------------------------------------------------------------------------- +/** Static helper functions for font export. */ +class XclExpFontHelper +{ +public: + /** Returns the script type of the first font item found in the item set and its parents. */ + static sal_Int16 GetFirstUsedScript( + const XclExpRoot& rRoot, + const SfxItemSet& rItemSet ); + + /** Returns a VCL font object filled from the passed item set. */ + static Font GetFontFromItemSet( + const XclExpRoot& rRoot, + const SfxItemSet& rItemSet, + sal_Int16 nScript ); + + /** Returns true, if at least one font related item is set in the passed item set. + @param bDeep true = Searches in parent item sets too. */ + static bool CheckItems( + const XclExpRoot& rRoot, + const SfxItemSet& rItemSet, + sal_Int16 nScript, + bool bDeep ); + +private: + XclExpFontHelper(); + ~XclExpFontHelper(); +}; + +// ---------------------------------------------------------------------------- + /** Stores all data of an Excel font and provides export of FONT records. */ class XclExpFont : public XclExpRecord, protected XclExpRoot { @@ -228,15 +258,6 @@ public: virtual void Save( XclExpStream& rStrm ); virtual void SaveXml( XclExpXmlStream& rStrm ); - /** Returns the script type of the first font item found in the item set and its parents. */ - static sal_Int16 GetFirstUsedScript( const SfxItemSet& rItemSet ); - - /** Returns a VCL font object filled from the passed item set. */ - static Font GetFontFromItemSet( const SfxItemSet& rItemSet, sal_Int16 nScript ); - /** Returns true, if at least one font related item is set in the passed item set. - @param bDeep true = Searches in parent item sets too. */ - static bool CheckItems( const SfxItemSet& rItemSet, sal_Int16 nScript, bool bDeep ); - private: /** Initializes the default fonts for the current BIFF version. */ void InitDefaultFonts(); @@ -552,7 +573,7 @@ public: //UNUSED2008-05 /** Sets the parent XF ID. Only allowed for cell XFs. */ //UNUSED2008-05 void SetParent( sal_uInt32 nParentXFId ); -//UNUSED2008-05 +//UNUSED2008-05 //UNUSED2008-05 /** Sets all "attribute used" flags explicitely. //UNUSED2008-05 @descr The following Set***() functions set the appropriate flag too. */ //UNUSED2008-05 void SetUsedFlags( |