summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorNoel Power <noel.power@suse.com>2013-01-22 11:58:20 +0000
committerNoel Power <noel.power@suse.com>2013-01-22 12:05:50 +0000
commitf54ce3e7f6d6aab7e34c54ad8eff06650e076fef (patch)
tree94d3e9094751f98b376b3f9f4ada7b44b1a934c4 /sc
parentaab9c9deee38de1776acebaa8c0877cf945dca83 (diff)
lose uno api for font related xlsx import
also fixes a bug where the font format of the first portion of a rich text string gets to be set as the default cell style for that cell Change-Id: Ib2e85e6f2a971940b94100c2bf45d85d8afa2869
Diffstat (limited to 'sc')
-rw-r--r--sc/source/filter/inc/richstring.hxx7
-rw-r--r--sc/source/filter/inc/workbookhelper.hxx2
-rw-r--r--sc/source/filter/oox/richstring.cxx58
-rw-r--r--sc/source/filter/oox/stylesbuffer.cxx60
-rw-r--r--sc/source/filter/oox/workbookhelper.cxx26
-rw-r--r--sc/source/filter/oox/worksheethelper.cxx15
6 files changed, 141 insertions, 27 deletions
diff --git a/sc/source/filter/inc/richstring.hxx b/sc/source/filter/inc/richstring.hxx
index a279429e0c6b..4815fa261799 100644
--- a/sc/source/filter/inc/richstring.hxx
+++ b/sc/source/filter/inc/richstring.hxx
@@ -23,6 +23,10 @@
#include "oox/helper/refvector.hxx"
#include "stylesbuffer.hxx"
+class EditTextObject;
+class ESelection;
+class ScEditEngineDefaulter;
+
namespace com { namespace sun { namespace star {
namespace text { class XText; }
} } }
@@ -68,7 +72,9 @@ public:
/** Converts the portion and replaces or appends to the passed XText. */
void convert(
const ::com::sun::star::uno::Reference< ::com::sun::star::text::XText >& rxText,
+
const Font* pFont, bool bReplace );
+ void convert( ScEditEngineDefaulter& rEE, ESelection& rSelection, const Font* pFont );
void writeFontProperties(
const ::com::sun::star::uno::Reference< ::com::sun::star::text::XText >& rxText,
@@ -250,6 +256,7 @@ public:
const ::com::sun::star::uno::Reference< ::com::sun::star::text::XText >& rxText,
bool bReplaceOld,
const Font* pFirstPortionFont = 0 ) const;
+ ::EditTextObject* convert( ScEditEngineDefaulter& rEE, const Font* pFont ) const;
private:
/** Creates, appends, and returns a new empty string portion. */
diff --git a/sc/source/filter/inc/workbookhelper.hxx b/sc/source/filter/inc/workbookhelper.hxx
index a4265dcd8169..0e1b87d70a70 100644
--- a/sc/source/filter/inc/workbookhelper.hxx
+++ b/sc/source/filter/inc/workbookhelper.hxx
@@ -55,6 +55,7 @@ namespace oox { namespace core {
} }
class ScDocument;
+class ScEditEngineDefaulter;
namespace oox {
namespace xls {
@@ -146,6 +147,7 @@ public:
// document model ---------------------------------------------------------
ScDocument& getScDocument() const;
+ ScEditEngineDefaulter& getEditEngine() const;
/** Returns a reference to the source/target spreadsheet document model. */
::com::sun::star::uno::Reference< ::com::sun::star::sheet::XSpreadsheetDocument >
getDocument() const;
diff --git a/sc/source/filter/oox/richstring.cxx b/sc/source/filter/oox/richstring.cxx
index f262598ca914..acbaea6cc13f 100644
--- a/sc/source/filter/oox/richstring.cxx
+++ b/sc/source/filter/oox/richstring.cxx
@@ -21,9 +21,11 @@
#include <com/sun/star/text/XText.hpp>
#include <rtl/ustrbuf.hxx>
+#include <editeng/editobj.hxx>
#include "oox/helper/attributelist.hxx"
#include "oox/helper/propertyset.hxx"
#include "biffinputstream.hxx"
+#include "editutil.hxx"
namespace oox {
namespace xls {
@@ -112,6 +114,41 @@ void RichStringPortion::convert( const Reference< XText >& rxText, const Font* p
}
}
+void RichStringPortion::convert( ScEditEngineDefaulter& rEE, ESelection& rSelection, const Font* pFont )
+{
+ rSelection.nStartPos = rSelection.nEndPos;
+ rSelection.nStartPara = rSelection.nEndPara;
+ SfxItemSet aItemSet( rEE.GetEmptyItemSet() );
+
+ const Font* pFontToUse = mxFont.get() ? mxFont.get() : lclNeedsRichTextFormat( pFont ) ? pFont : NULL;
+
+ if ( pFontToUse )
+ pFontToUse->fillToItemSet( aItemSet, FONT_PROPTYPE_TEXT );
+
+ // #TODO need to manually adjust nEndPos ( and nEndPara ) to cater for any paragraphs
+ sal_Int32 nLastParaLoc = -1;
+ sal_Int32 nSearchIndex = maText.indexOf( '\n' );
+ sal_Int32 nParaOccurence = 0;
+ while ( nSearchIndex != -1 )
+ {
+ nLastParaLoc = nSearchIndex;
+ ++nParaOccurence;
+ rSelection.nEndPos = 0;
+ nSearchIndex = maText.indexOf( '\n', nSearchIndex + 1);
+ }
+
+ rSelection.nEndPara += nParaOccurence;
+ if ( nLastParaLoc != -1 )
+ {
+ rSelection.nEndPos = maText.getLength() - 1 - nLastParaLoc;
+ }
+ else
+ {
+ rSelection.nEndPos = rSelection.nStartPos + maText.getLength();
+ }
+ rEE.QuickSetAttribs( aItemSet, rSelection );
+}
+
void RichStringPortion::writeFontProperties( const Reference<XText>& rxText, const Font* pFont ) const
{
PropertySet aPropSet(rxText);
@@ -378,6 +415,27 @@ void RichString::convert( const Reference< XText >& rxText, bool bReplaceOld, co
}
}
+::EditTextObject* RichString::convert( ScEditEngineDefaulter& rEE, const Font* pFirstPortionFont ) const
+{
+ EditTextObject* pTextObj = NULL;
+ ESelection aSelection;
+
+ OUString sString;
+ for( PortionVector::const_iterator aIt = maTextPortions.begin(), aEnd = maTextPortions.end(); aIt != aEnd; ++aIt )
+ sString += (*aIt)->getText();
+
+ rEE.SetText( sString );
+
+ for( PortionVector::const_iterator aIt = maTextPortions.begin(), aEnd = maTextPortions.end(); aIt != aEnd; ++aIt )
+ {
+ (*aIt)->convert( rEE, aSelection, pFirstPortionFont );
+ pFirstPortionFont = 0;
+ }
+
+ pTextObj = rEE.CreateTextObject();
+ return pTextObj;
+}
+
// private --------------------------------------------------------------------
RichStringPortionRef RichString::createPortion()
diff --git a/sc/source/filter/oox/stylesbuffer.cxx b/sc/source/filter/oox/stylesbuffer.cxx
index 58b9a7f53878..bb3672d4b4c5 100644
--- a/sc/source/filter/oox/stylesbuffer.cxx
+++ b/sc/source/filter/oox/stylesbuffer.cxx
@@ -75,6 +75,7 @@
#include "scitems.hxx"
#include "attrib.hxx"
#include "globstr.hrc"
+#include "xlconst.hxx"
using ::com::sun::star::table::BorderLine2;
namespace oox {
@@ -1019,58 +1020,75 @@ bool Font::needsRichTextFormat() const
void Font::fillToItemSet( SfxItemSet& rItemSet, FontPropertyType ePropType, bool bSkipPoolDefs ) const
{
+ bool bEdit = ( ePropType == FONT_PROPTYPE_TEXT );
namespace cssawt = ::com::sun::star::awt;
if ( maUsedFlags.mbNameUsed )
{
if( !maApiData.maLatinFont.maName.isEmpty() )
{
rtl_TextEncoding eFontEnc = maApiData.maLatinFont.mnTextEnc;
+ // taken from binary importer
+ rtl_TextEncoding eTempTextEnc = (bEdit && (eFontEnc == getTextEncoding())) ?
+ ScfTools::GetSystemTextEncoding() : eFontEnc;
+
SvxFontItem aFontItem( lcl_getFontFamily( maApiData.maLatinFont.mnFamily ), maApiData.maLatinFont.maName, rtl::OUString(),
- PITCH_DONTKNOW, eFontEnc, ATTR_FONT );
+ PITCH_DONTKNOW, eTempTextEnc, ATTR_FONT );
+ ScfTools::PutItem( rItemSet, aFontItem, bEdit ? EE_CHAR_FONTINFO : ATTR_FONT, bSkipPoolDefs );
}
if( !maApiData.maAsianFont.maName.isEmpty() )
{
rtl_TextEncoding eFontEnc = maApiData.maAsianFont.mnTextEnc;
+ // taken from binary importer
+ rtl_TextEncoding eTempTextEnc = (bEdit && (eFontEnc == getTextEncoding())) ?
+ ScfTools::GetSystemTextEncoding() : eFontEnc;
SvxFontItem aFontItem( lcl_getFontFamily( maApiData.maAsianFont.mnFamily ), maApiData.maAsianFont.maName, rtl::OUString(),
- PITCH_DONTKNOW, eFontEnc, ATTR_FONT );
+ PITCH_DONTKNOW, eTempTextEnc, ATTR_FONT );
+ ScfTools::PutItem( rItemSet, aFontItem, bEdit ? EE_CHAR_FONTINFO_CJK : ATTR_CJK_FONT, bSkipPoolDefs );
}
if( !maApiData.maCmplxFont.maName.isEmpty() )
{
rtl_TextEncoding eFontEnc = maApiData.maCmplxFont.mnTextEnc;
+ // taken from binary importer
+ rtl_TextEncoding eTempTextEnc = (bEdit && (eFontEnc == getTextEncoding())) ?
+ ScfTools::GetSystemTextEncoding() : eFontEnc;
SvxFontItem aFontItem( lcl_getFontFamily( maApiData.maCmplxFont.mnFamily ), maApiData.maCmplxFont.maName, rtl::OUString(),
- PITCH_DONTKNOW, eFontEnc, ATTR_FONT );
+ PITCH_DONTKNOW, eTempTextEnc, ATTR_FONT );
+ ScfTools::PutItem( rItemSet, aFontItem, bEdit ? EE_CHAR_FONTINFO_CTL : ATTR_CTL_FONT, bSkipPoolDefs );
}
}
// font height
if( maUsedFlags.mbHeightUsed )
{
- // leave in twips ?
- SvxFontHeightItem aHeightItem( maApiData.maDesc.Height, 100, ATTR_FONT_HEIGHT );
- ScfTools::PutItem( rItemSet, aHeightItem, ATTR_FONT_HEIGHT, bSkipPoolDefs );
- ScfTools::PutItem( rItemSet, aHeightItem, ATTR_CJK_FONT_HEIGHT, bSkipPoolDefs );
- ScfTools::PutItem( rItemSet, aHeightItem, ATTR_CTL_FONT_HEIGHT, bSkipPoolDefs );
+ sal_Int32 nHeight = maApiData.maDesc.Height;
+ // do we use EXC_FONTITEM_HF ( or is it just relevant for the binary filter )
+ if( bEdit/* && (eType != EXC_FONTITEM_HF) */) // do not convert header/footer height
+ nHeight = (nHeight * 127 + 36) / EXC_POINTS_PER_INCH; // 1 in == 72 pt
+ SvxFontHeightItem aHeightItem( nHeight, 100, ATTR_FONT_HEIGHT );
+ ScfTools::PutItem( rItemSet, aHeightItem, bEdit ? EE_CHAR_FONTHEIGHT : ATTR_FONT_HEIGHT, bSkipPoolDefs );
+ ScfTools::PutItem( rItemSet, aHeightItem, bEdit ? EE_CHAR_FONTHEIGHT_CJK : ATTR_CJK_FONT_HEIGHT, bSkipPoolDefs );
+ ScfTools::PutItem( rItemSet, aHeightItem, bEdit ? EE_CHAR_FONTHEIGHT_CTL : ATTR_CTL_FONT_HEIGHT, bSkipPoolDefs );
}
// font weight
if( maUsedFlags.mbWeightUsed )
{
::FontWeight fWeight = VCLUnoHelper::ConvertFontWeight( maApiData.maDesc.Weight );
SvxWeightItem aWeightItem( fWeight, ATTR_FONT_WEIGHT );
- ScfTools::PutItem( rItemSet, aWeightItem, ATTR_FONT_WEIGHT, bSkipPoolDefs );
- ScfTools::PutItem( rItemSet, aWeightItem, ATTR_CTL_FONT_WEIGHT, bSkipPoolDefs );
- ScfTools::PutItem( rItemSet, aWeightItem, ATTR_CJK_FONT_WEIGHT, bSkipPoolDefs );
+ ScfTools::PutItem( rItemSet, aWeightItem, bEdit ? EE_CHAR_WEIGHT : ATTR_FONT_WEIGHT, bSkipPoolDefs );
+ ScfTools::PutItem( rItemSet, aWeightItem, bEdit ? EE_CHAR_WEIGHT_CTL : ATTR_CTL_FONT_WEIGHT, bSkipPoolDefs );
+ ScfTools::PutItem( rItemSet, aWeightItem, bEdit ? EE_CHAR_WEIGHT_CJK : ATTR_CJK_FONT_WEIGHT, bSkipPoolDefs );
}
// font posture
if( maUsedFlags.mbPostureUsed )
{
SvxPostureItem aPostItem( ( maApiData.maDesc.Slant == cssawt::FontSlant_ITALIC ) ? ITALIC_NORMAL : ITALIC_NONE, ATTR_FONT_POSTURE);
- ScfTools::PutItem( rItemSet, aPostItem, ATTR_FONT_POSTURE, bSkipPoolDefs );
- ScfTools::PutItem( rItemSet, aPostItem, ATTR_CJK_FONT_POSTURE, bSkipPoolDefs );
- ScfTools::PutItem( rItemSet, aPostItem, ATTR_CTL_FONT_POSTURE, bSkipPoolDefs );
+ ScfTools::PutItem( rItemSet, aPostItem, bEdit ? EE_CHAR_ITALIC : ATTR_FONT_POSTURE, bSkipPoolDefs );
+ ScfTools::PutItem( rItemSet, aPostItem, bEdit ? EE_CHAR_ITALIC_CJK : ATTR_CJK_FONT_POSTURE, bSkipPoolDefs );
+ ScfTools::PutItem( rItemSet, aPostItem, bEdit ? EE_CHAR_ITALIC_CTL : ATTR_CTL_FONT_POSTURE, bSkipPoolDefs );
}
// character color
if( maUsedFlags.mbColorUsed )
{
- ScfTools::PutItem( rItemSet,SvxColorItem( maApiData.mnColor, ATTR_FONT_COLOR ) , bSkipPoolDefs );
+ ScfTools::PutItem( rItemSet,SvxColorItem( maApiData.mnColor, bEdit ? EE_CHAR_COLOR : ATTR_FONT_COLOR ) , bSkipPoolDefs );
}
// underline style
if( maUsedFlags.mbUnderlineUsed )
@@ -1083,24 +1101,24 @@ void Font::fillToItemSet( SfxItemSet& rItemSet, FontPropertyType ePropType, bool
else
eScUnderl = UNDERLINE_NONE;
SvxUnderlineItem aUnderlItem( eScUnderl, ATTR_FONT_UNDERLINE );
- ScfTools::PutItem( rItemSet, aUnderlItem, ATTR_FONT_UNDERLINE, bSkipPoolDefs );
+ ScfTools::PutItem( rItemSet, aUnderlItem, bEdit ? EE_CHAR_UNDERLINE : ATTR_FONT_UNDERLINE, bSkipPoolDefs );
}
// strike out style
if( maUsedFlags.mbStrikeoutUsed )
{
- ScfTools::PutItem( rItemSet, SvxCrossedOutItem( maModel.mbStrikeout ? STRIKEOUT_SINGLE : STRIKEOUT_NONE, ATTR_FONT_CROSSEDOUT ), ATTR_FONT_CROSSEDOUT, bSkipPoolDefs );
+ ScfTools::PutItem( rItemSet, SvxCrossedOutItem( maModel.mbStrikeout ? STRIKEOUT_SINGLE : STRIKEOUT_NONE, bEdit ? EE_CHAR_STRIKEOUT : ATTR_FONT_CROSSEDOUT ), ATTR_FONT_CROSSEDOUT, bSkipPoolDefs );
}
// outline style
if( maUsedFlags.mbOutlineUsed )
{
- ScfTools::PutItem( rItemSet, SvxContourItem( maApiData.mbOutline, ATTR_FONT_CONTOUR ), ATTR_FONT_CONTOUR, bSkipPoolDefs );
+ ScfTools::PutItem( rItemSet, SvxContourItem( maApiData.mbOutline, ATTR_FONT_CONTOUR ), bEdit ? EE_CHAR_OUTLINE : ATTR_FONT_CONTOUR, bSkipPoolDefs );
}
// shadow style
if( maUsedFlags.mbShadowUsed )
{
- ScfTools::PutItem( rItemSet, SvxShadowedItem( maApiData.mbShadow, ATTR_FONT_SHADOWED ), ATTR_FONT_SHADOWED, bSkipPoolDefs );
+ ScfTools::PutItem( rItemSet, SvxShadowedItem( maApiData.mbShadow, ATTR_FONT_SHADOWED ), bEdit ? EE_CHAR_SHADOW : ATTR_FONT_SHADOWED, bSkipPoolDefs );
}
if( maUsedFlags.mbEscapementUsed )
{
@@ -1109,10 +1127,10 @@ void Font::fillToItemSet( SfxItemSet& rItemSet, FontPropertyType ePropType, bool
eScEscapem = SVX_ESCAPEMENT_SUPERSCRIPT;
else if ( maApiData.mnEscapement == API_ESCAPE_SUBSCRIPT )
eScEscapem = SVX_ESCAPEMENT_SUBSCRIPT;
- rItemSet.Put( SvxEscapementItem( eScEscapem, EE_CHAR_ESCAPEMENT ) );
- if( ePropType == FONT_PROPTYPE_TEXT )
+ if( ePropType == FONT_PROPTYPE_TEXT && bEdit )
{
// #TODO handle EscapementHeight
+ rItemSet.Put( SvxEscapementItem( eScEscapem, EE_CHAR_ESCAPEMENT ) );
}
}
}
diff --git a/sc/source/filter/oox/workbookhelper.cxx b/sc/source/filter/oox/workbookhelper.cxx
index 53d4aded9f07..ca89dccb2dcf 100644
--- a/sc/source/filter/oox/workbookhelper.cxx
+++ b/sc/source/filter/oox/workbookhelper.cxx
@@ -73,6 +73,10 @@
#include "globalnames.hxx"
#include "formulabuffer.hxx"
+#include "vcl/mapmod.hxx"
+#include "editutil.hxx"
+#include "editeng/editstat.hxx"
+
namespace oox {
namespace xls {
@@ -135,6 +139,11 @@ public:
// document model ---------------------------------------------------------
+ inline ScEditEngineDefaulter& getEditEngine() const
+ {
+ return *mxEditEngine.get();
+ }
+
inline ScDocument& getScDocument() const
{
if ( !mpDoc )
@@ -235,6 +244,7 @@ private:
void finalize();
private:
+ typedef ::std::auto_ptr< ScEditEngineDefaulter > EditEngineDefaulterPtr;
typedef ::std::auto_ptr< FormulaBuffer > FormulaBufferPtr;
typedef ::std::auto_ptr< SegmentProgressBar > ProgressBarPtr;
typedef ::std::auto_ptr< WorkbookSettings > WorkbookSettPtr;
@@ -293,6 +303,8 @@ private:
ExcelChartConvPtr mxChartConverter; /// Chart object converter.
PageSettConvPtr mxPageSettConverter; /// Page/print settings converter.
+ EditEngineDefaulterPtr mxEditEngine;
+
// OOXML/BIFF12 specific
XmlFilterBase* mpOoxFilter; /// Base OOXML/BIFF12 filter object.
@@ -535,6 +547,15 @@ void WorkbookGlobals::initialize( bool bWorkbookFile )
mxChartConverter.reset( new ExcelChartConverter( *this ) );
mxPageSettConverter.reset( new PageSettingsConverter( *this ) );
+ // initialise edit engine
+ ScDocument& rDoc = getScDocument();
+ mxEditEngine.reset( new ScEditEngineDefaulter( rDoc.GetEnginePool() ) );
+ mxEditEngine->SetRefMapMode( MAP_100TH_MM );
+ mxEditEngine->SetEditTextObjectPool( rDoc.GetEditPool() );
+ mxEditEngine->SetUpdateMode( false );
+ mxEditEngine->EnableUndo( false );
+ mxEditEngine->SetControlWord( mxEditEngine->GetControlWord() & ~EE_CNTRL_ALLOWBIGOBJS );
+
// set some document properties needed during import
if( mrBaseFilter.isImportFilter() )
{
@@ -701,6 +722,11 @@ ScDocument& WorkbookHelper::getScDocument() const
return mrBookGlob.getScDocument();
}
+ScEditEngineDefaulter& WorkbookHelper::getEditEngine() const
+{
+ return mrBookGlob.getEditEngine();
+}
+
Reference< XSpreadsheetDocument > WorkbookHelper::getDocument() const
{
return mrBookGlob.getDocument();
diff --git a/sc/source/filter/oox/worksheethelper.cxx b/sc/source/filter/oox/worksheethelper.cxx
index 449306ad8967..bfa76787c32c 100644
--- a/sc/source/filter/oox/worksheethelper.cxx
+++ b/sc/source/filter/oox/worksheethelper.cxx
@@ -68,6 +68,7 @@
#include "formulabuffer.hxx"
#include "scitems.hxx"
#include <svl/stritem.hxx>
+#include "editutil.hxx"
namespace oox {
namespace xls {
@@ -1547,12 +1548,14 @@ void WorksheetHelper::putString( const CellAddress& rAddress, const OUString& rT
void WorksheetHelper::putRichString( const CellAddress& rAddress, const RichString& rString, const Font* pFirstPortionFont ) const
{
- Reference< XText > xText( getCell( rAddress ), UNO_QUERY );
- OSL_ENSURE( xText.is(), "WorksheetHelper::putRichString - missing text interface" );
- /* Passing false will always append the portions to the XText. This is
- essential for special rich formatting attributes at the leading text
- portion supported by edit cells only, e.g. font escapement. */
- rString.convert( xText, false, pFirstPortionFont );
+ ScDocument& rDoc = getScDocument();
+ ScEditEngineDefaulter& rEE = getEditEngine();
+
+ ::std::auto_ptr< ::EditTextObject > pTextObj( rString.convert( rEE, pFirstPortionFont ) );
+ ScBaseCell* pNewCell = new ScEditCell( pTextObj.get(), &rDoc, rEE.GetEditTextObjectPool() );
+ ScAddress aAddress;
+ ScUnoConversion::FillScAddress( aAddress, rAddress );
+ rDoc.PutCell( aAddress, pNewCell );
}
void WorksheetHelper::putFormulaTokens( const CellAddress& rAddress, const ApiTokenSequence& rTokens ) const