summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Mohrhard <markus.mohrhard@googlemail.com>2015-04-14 17:52:49 +0200
committerMarkus Mohrhard <markus.mohrhard@googlemail.com>2015-04-14 18:16:07 +0200
commit853bfc68b93427f105d2c8c0ed959b3971861755 (patch)
treeaff7c7b4a7c91155be097829dec967ea7be40deb
parent533add1c73b7d8cd6aa43c942821daf3f529df75 (diff)
implement a sane and working dxf font export, tdf#81918
Dxf font export needs a lot of special handling to detect which parts are set in the itemset and only export these. The old code only checked for font name, font family and text encoding and exported the whole font as dxf font in that case. The new approach just exports the necessary bits. Change-Id: Ic9a9c547723a65f26ebb6c88040a51f04f3cc42b
-rw-r--r--sc/inc/patattr.hxx3
-rw-r--r--sc/source/core/data/patattr.cxx151
-rw-r--r--sc/source/filter/excel/xestyle.cxx190
-rw-r--r--sc/source/filter/inc/xestyle.hxx23
4 files changed, 328 insertions, 39 deletions
diff --git a/sc/inc/patattr.hxx b/sc/inc/patattr.hxx
index dfba0e23629e..cbc37d1034fe 100644
--- a/sc/inc/patattr.hxx
+++ b/sc/inc/patattr.hxx
@@ -25,6 +25,7 @@
#include <unotools/fontcvt.hxx>
#include <editeng/svxenum.hxx>
#include "scdllapi.h"
+#include "fonthelper.hxx"
namespace vcl { class Font; }
class OutputDevice;
@@ -87,6 +88,8 @@ public:
const SfxItemSet* pCondSet = NULL,
sal_uInt8 nScript = 0, const Color* pBackConfigColor = NULL,
const Color* pTextConfigColor = NULL );
+
+ static ScDxfFont GetDxfFont(const SfxItemSet& rSet, sal_uInt8 nScript);
/** Fills a font object from the own item set. */
void GetFont( vcl::Font& rFont, ScAutoFontColorMode eAutoMode,
OutputDevice* pOutDev = NULL,
diff --git a/sc/source/core/data/patattr.cxx b/sc/source/core/data/patattr.cxx
index dfcfa705e4c4..878f8afd3af9 100644
--- a/sc/source/core/data/patattr.cxx
+++ b/sc/source/core/data/patattr.cxx
@@ -215,30 +215,11 @@ SvxCellOrientation ScPatternAttr::GetCellOrientation( const SfxItemSet* pCondSet
return GetCellOrientation( GetItemSet(), pCondSet );
}
-void ScPatternAttr::GetFont(
- vcl::Font& rFont, const SfxItemSet& rItemSet, ScAutoFontColorMode eAutoMode,
- OutputDevice* pOutDev, const Fraction* pScale,
- const SfxItemSet* pCondSet, sal_uInt8 nScript,
- const Color* pBackConfigColor, const Color* pTextConfigColor )
-{
- // Read items
-
- const SvxFontItem* pFontAttr;
- sal_uInt32 nFontHeight;
- FontWeight eWeight;
- FontItalic eItalic;
- FontUnderline eUnder;
- FontUnderline eOver;
- bool bWordLine;
- FontStrikeout eStrike;
- bool bOutline;
- bool bShadow;
- FontEmphasisMark eEmphasis;
- FontRelief eRelief;
- Color aColor;
- LanguageType eLang;
+namespace {
- sal_uInt16 nFontId, nHeightId, nWeightId, nPostureId, nLangId;
+void getFontIDsByScriptType(sal_uInt8 nScript,
+sal_uInt16& nFontId, sal_uInt16& nHeightId, sal_uInt16& nWeightId, sal_uInt16& nPostureId, sal_uInt16& nLangId)
+{
if ( nScript == SCRIPTTYPE_ASIAN )
{
nFontId = ATTR_CJK_FONT;
@@ -263,6 +244,35 @@ void ScPatternAttr::GetFont(
nPostureId = ATTR_FONT_POSTURE;
nLangId = ATTR_FONT_LANGUAGE;
}
+}
+
+}
+
+void ScPatternAttr::GetFont(
+ vcl::Font& rFont, const SfxItemSet& rItemSet, ScAutoFontColorMode eAutoMode,
+ OutputDevice* pOutDev, const Fraction* pScale,
+ const SfxItemSet* pCondSet, sal_uInt8 nScript,
+ const Color* pBackConfigColor, const Color* pTextConfigColor )
+{
+ // Read items
+
+ const SvxFontItem* pFontAttr;
+ sal_uInt32 nFontHeight;
+ FontWeight eWeight;
+ FontItalic eItalic;
+ FontUnderline eUnder;
+ FontUnderline eOver;
+ bool bWordLine;
+ FontStrikeout eStrike;
+ bool bOutline;
+ bool bShadow;
+ FontEmphasisMark eEmphasis;
+ FontRelief eRelief;
+ Color aColor;
+ LanguageType eLang;
+
+ sal_uInt16 nFontId, nHeightId, nWeightId, nPostureId, nLangId;
+ getFontIDsByScriptType(nScript, nFontId, nHeightId, nWeightId, nPostureId, nLangId);
if ( pCondSet )
{
@@ -489,6 +499,101 @@ void ScPatternAttr::GetFont(
GetFont( rFont, GetItemSet(), eAutoMode, pOutDev, pScale, pCondSet, nScript, pBackConfigColor, pTextConfigColor );
}
+ScDxfFont ScPatternAttr::GetDxfFont(const SfxItemSet& rItemSet, sal_uInt8 nScript)
+{
+ sal_uInt16 nFontId, nHeightId, nWeightId, nPostureId, nLangId;
+ getFontIDsByScriptType(nScript, nFontId, nHeightId, nWeightId, nPostureId, nLangId);
+ const SfxPoolItem* pItem;
+
+ ScDxfFont aReturn;
+
+ if ( rItemSet.GetItemState( nFontId, true, &pItem ) == SfxItemState::SET )
+ {
+ pItem = &rItemSet.Get( nFontId );
+ aReturn.pFontAttr = static_cast<const SvxFontItem*>(pItem);
+ }
+
+ if ( rItemSet.GetItemState( nHeightId, true, &pItem ) == SfxItemState::SET )
+ {
+ pItem = &rItemSet.Get( nHeightId );
+ aReturn.nFontHeight = static_cast<const SvxFontHeightItem*>(pItem)->GetHeight();
+ }
+
+ if ( rItemSet.GetItemState( nWeightId, true, &pItem ) == SfxItemState::SET )
+ {
+ pItem = &rItemSet.Get( nWeightId );
+ aReturn.eWeight = (FontWeight)static_cast<const SvxWeightItem*>(pItem)->GetValue();
+ }
+
+ if ( rItemSet.GetItemState( nPostureId, true, &pItem ) == SfxItemState::SET )
+ {
+ pItem = &rItemSet.Get( nPostureId );
+ aReturn.eItalic = (FontItalic)static_cast<const SvxPostureItem*>(pItem)->GetValue();
+ }
+
+ if ( rItemSet.GetItemState( ATTR_FONT_UNDERLINE, true, &pItem ) == SfxItemState::SET )
+ {
+ pItem = &rItemSet.Get( ATTR_FONT_UNDERLINE );
+ aReturn.eUnder = (FontUnderline)static_cast<const SvxUnderlineItem*>(pItem)->GetValue();
+ }
+
+ if ( rItemSet.GetItemState( ATTR_FONT_OVERLINE, true, &pItem ) == SfxItemState::SET )
+ {
+ pItem = &rItemSet.Get( ATTR_FONT_OVERLINE );
+ aReturn.eOver = (FontUnderline)static_cast<const SvxOverlineItem*>(pItem)->GetValue();
+ }
+
+ if ( rItemSet.GetItemState( ATTR_FONT_WORDLINE, true, &pItem ) == SfxItemState::SET )
+ {
+ pItem = &rItemSet.Get( ATTR_FONT_WORDLINE );
+ aReturn.bWordLine = static_cast<const SvxWordLineModeItem*>(pItem)->GetValue();
+ }
+
+ if ( rItemSet.GetItemState( ATTR_FONT_CROSSEDOUT, true, &pItem ) == SfxItemState::SET )
+ {
+ pItem = &rItemSet.Get( ATTR_FONT_CROSSEDOUT );
+ aReturn.eStrike = (FontStrikeout)static_cast<const SvxCrossedOutItem*>(pItem)->GetValue();
+ }
+
+ if ( rItemSet.GetItemState( ATTR_FONT_CONTOUR, true, &pItem ) == SfxItemState::SET )
+ {
+ pItem = &rItemSet.Get( ATTR_FONT_CONTOUR );
+ aReturn.bOutline = static_cast<const SvxContourItem*>(pItem)->GetValue();
+ }
+
+ if ( rItemSet.GetItemState( ATTR_FONT_SHADOWED, true, &pItem ) == SfxItemState::SET )
+ {
+ pItem = &rItemSet.Get( ATTR_FONT_SHADOWED );
+ aReturn.bShadow = static_cast<const SvxShadowedItem*>(pItem)->GetValue();
+ }
+
+ if ( rItemSet.GetItemState( ATTR_FONT_EMPHASISMARK, true, &pItem ) == SfxItemState::SET )
+ {
+ pItem = &rItemSet.Get( ATTR_FONT_EMPHASISMARK );
+ aReturn.eEmphasis = static_cast<const SvxEmphasisMarkItem*>(pItem)->GetEmphasisMark();
+ }
+
+ if ( rItemSet.GetItemState( ATTR_FONT_RELIEF, true, &pItem ) == SfxItemState::SET )
+ {
+ pItem = &rItemSet.Get( ATTR_FONT_RELIEF );
+ aReturn.eRelief = (FontRelief)static_cast<const SvxCharReliefItem*>(pItem)->GetValue();
+ }
+
+ if ( rItemSet.GetItemState( ATTR_FONT_COLOR, true, &pItem ) == SfxItemState::SET )
+ {
+ pItem = &rItemSet.Get( ATTR_FONT_COLOR );
+ aReturn.aColor = static_cast<const SvxColorItem*>(pItem)->GetValue();
+ }
+
+ if ( rItemSet.GetItemState( nLangId, true, &pItem ) == SfxItemState::SET )
+ {
+ pItem = &rItemSet.Get( nLangId );
+ aReturn.eLang = static_cast<const SvxLanguageItem*>(pItem)->GetLanguage();
+ }
+
+ return aReturn;
+}
+
void ScPatternAttr::FillToEditItemSet( SfxItemSet& rEditSet, const SfxItemSet& rSrcSet, const SfxItemSet* pCondSet )
{
// Read Items
diff --git a/sc/source/filter/excel/xestyle.cxx b/sc/source/filter/excel/xestyle.cxx
index f4cf4cf63d92..e391a3f3f85d 100644
--- a/sc/source/filter/excel/xestyle.cxx
+++ b/sc/source/filter/excel/xestyle.cxx
@@ -37,6 +37,7 @@
#include <editeng/colritem.hxx>
#include <editeng/brushitem.hxx>
#include <editeng/frmdiritem.hxx>
+#include <editeng/fontitem.hxx>
#include <editeng/eeitem.hxx>
#include <editeng/escapementitem.hxx>
#include <editeng/justifyitem.hxx>
@@ -872,15 +873,12 @@ sal_Int16 XclExpFontHelper::GetFirstUsedScript( const XclExpRoot& rRoot, const S
return nScript;
}
-vcl::Font XclExpFontHelper::GetFontFromItemSet( const XclExpRoot& rRoot, const SfxItemSet& rItemSet, sal_Int16 nScript )
+namespace {
+
+sal_uInt8 getCoreScriptType(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
sal_uInt8 nScScript = SCRIPTTYPE_LATIN;
switch( nScript )
{
@@ -890,12 +888,37 @@ vcl::Font XclExpFontHelper::GetFontFromItemSet( const XclExpRoot& rRoot, const S
default: OSL_FAIL( "XclExpFontHelper::GetFontFromItemSet - unknown script type" );
}
+ return nScScript;
+}
+
+}
+
+vcl::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
+ sal_uInt8 nScScript = getCoreScriptType(nScript);
+
// fill the font object
vcl::Font aFont;
ScPatternAttr::GetFont( aFont, rItemSet, SC_AUTOCOL_RAW, 0, 0, 0, nScScript );
return aFont;
}
+ScDxfFont XclExpFontHelper::GetDxfFontFromItemSet(const XclExpRoot& rRoot, const SfxItemSet& rItemSet)
+{
+ sal_Int16 nScript = GetFirstUsedScript(rRoot, rItemSet);
+
+ // convert to core script type constants
+ sal_uInt8 nScScript = getCoreScriptType(nScript);
+ return ScPatternAttr::GetDxfFont(rItemSet, nScScript);
+}
+
bool XclExpFontHelper::CheckItems( const XclExpRoot& rRoot, const SfxItemSet& rItemSet, sal_Int16 nScript, bool bDeep )
{
static const sal_uInt16 pnCommonIds[] = {
@@ -1006,6 +1029,151 @@ void XclExpFont::WriteBody( XclExpStream& rStrm )
<< aFontName;
}
+XclExpDxfFont::XclExpDxfFont(const XclExpRoot& rRoot,
+ const SfxItemSet& rItemSet):
+ XclExpRoot(rRoot)
+{
+ maDxfData = XclExpFontHelper::GetDxfFontFromItemSet(rRoot, rItemSet);
+}
+
+namespace {
+
+const char* getUnderlineOOXValue(FontUnderline eUnderline)
+{
+ switch (eUnderline)
+ {
+ case UNDERLINE_NONE:
+ case UNDERLINE_DONTKNOW:
+ return "none";
+ case UNDERLINE_DOUBLE:
+ case UNDERLINE_DOUBLEWAVE:
+ return "double";
+ default:
+ return "single";
+ }
+}
+
+const char* getFontFamilyOOXValue(FontFamily eValue)
+{
+ switch (eValue)
+ {
+ case FAMILY_DONTKNOW:
+ return "0";
+ break;
+ case FAMILY_SWISS:
+ case FAMILY_SYSTEM:
+ return "2";
+ case FAMILY_ROMAN:
+ return "1";
+ case FAMILY_SCRIPT:
+ return "4";
+ case FAMILY_MODERN:
+ return "3";
+ case FAMILY_DECORATIVE:
+ return "5";
+ default:
+ return "0";
+ }
+}
+
+}
+
+void XclExpDxfFont::SaveXml(XclExpXmlStream& rStrm)
+{
+ if (maDxfData.isEmpty())
+ return;
+
+ sax_fastparser::FSHelperPtr& rStyleSheet = rStrm.GetCurrentStream();
+ rStyleSheet->startElement(XML_font, FSEND);
+
+ if (maDxfData.pFontAttr)
+ {
+ OUString aFontName = (*maDxfData.pFontAttr)->GetFamilyName();
+ if (!aFontName.isEmpty())
+ {
+ rStyleSheet->singleElement(XML_name,
+ XML_val, XclXmlUtils::ToOString(aFontName).getStr(),
+ FSEND);
+ }
+
+ rtl_TextEncoding eTextEnc = (*maDxfData.pFontAttr)->GetCharSet();
+ sal_uInt8 nExcelCharSet = rtl_getBestWindowsCharsetFromTextEncoding(eTextEnc);
+ if (nExcelCharSet)
+ {
+ rStyleSheet->singleElement(XML_charset,
+ XML_val, OString::number(nExcelCharSet).getStr(),
+ FSEND);
+ }
+
+ FontFamily eFamily = (*maDxfData.pFontAttr)->GetFamily();
+ const char* pVal = getFontFamilyOOXValue(eFamily);
+ if (pVal)
+ {
+ rStyleSheet->singleElement(XML_family,
+ XML_val, pVal,
+ FSEND);
+ }
+ }
+
+ if (maDxfData.eWeight)
+ {
+ rStyleSheet->singleElement(XML_b,
+ XML_val, XclXmlUtils::ToPsz10(maDxfData.eWeight.get() != WEIGHT_NORMAL),
+ FSEND);
+ }
+
+ if (maDxfData.eItalic)
+ {
+ bool bItalic = (maDxfData.eItalic.get() == ITALIC_OBLIQUE) || (maDxfData.eItalic.get() == ITALIC_NORMAL);
+ rStyleSheet->singleElement(XML_i,
+ XML_val, XclXmlUtils::ToPsz10(bItalic),
+ FSEND);
+ }
+
+ if (maDxfData.eStrike)
+ {
+ bool bStrikeout =
+ (maDxfData.eStrike.get() == STRIKEOUT_SINGLE) || (maDxfData.eStrike.get() == STRIKEOUT_DOUBLE) ||
+ (maDxfData.eStrike.get() == STRIKEOUT_BOLD) || (maDxfData.eStrike.get() == STRIKEOUT_SLASH) ||
+ (maDxfData.eStrike.get() == STRIKEOUT_X);
+
+ rStyleSheet->singleElement(XML_strike,
+ XML_val, XclXmlUtils::ToPsz10(bStrikeout),
+ FSEND);
+ }
+
+ if (maDxfData.bOutline)
+ {
+ rStyleSheet->singleElement(XML_outline,
+ XML_val, XclXmlUtils::ToPsz10(maDxfData.bOutline.get()),
+ FSEND);
+ }
+
+ if (maDxfData.bShadow)
+ {
+ rStyleSheet->singleElement(XML_shadow,
+ XML_val, XclXmlUtils::ToPsz10(maDxfData.bShadow.get()),
+ FSEND);
+ }
+
+ if (maDxfData.aColor)
+ {
+ rStyleSheet->singleElement(XML_color,
+ XML_rgb, XclXmlUtils::ToOString(maDxfData.aColor.get()).getStr(),
+ FSEND);
+ }
+
+ if (maDxfData.eUnder)
+ {
+ const char* pVal = getUnderlineOOXValue(maDxfData.eUnder.get());
+ rStyleSheet->singleElement(XML_u,
+ XML_val, pVal,
+ FSEND);
+ }
+
+ rStyleSheet->endElement(XML_font);
+}
+
XclExpBlindFont::XclExpBlindFont( const XclExpRoot& rRoot ) :
XclExpFont( rRoot, XclFontData(), EXC_COLOR_CELLTEXT )
{
@@ -2918,13 +3086,7 @@ XclExpDxfs::XclExpDxfs( const XclExpRoot& rRoot )
pColor = NULL;
}
- XclExpFont* pFont = NULL;
- // check if non default font is set and only export then
- if (rSet.GetItemState(rSet.GetPool()->GetWhich( SID_ATTR_CHAR_FONT )) == SfxItemState::SET )
- {
- vcl::Font aFont = XclExpFontHelper::GetFontFromItemSet( GetRoot(), rSet, com::sun::star::i18n::ScriptType::WEAK );
- pFont = new XclExpFont( GetRoot(), XclFontData( aFont ), EXC_COLOR_CELLTEXT );
- }
+ XclExpDxfFont* pFont = new XclExpDxfFont(rRoot, rSet);
XclExpNumFmt* pNumFormat = NULL;
const SfxPoolItem *pPoolItem = NULL;
@@ -2972,7 +3134,7 @@ void XclExpDxfs::SaveXml( XclExpXmlStream& rStrm )
}
XclExpDxf::XclExpDxf( const XclExpRoot& rRoot, XclExpCellAlign* pAlign, XclExpCellBorder* pBorder,
- XclExpFont* pFont, XclExpNumFmt* pNumberFmt, XclExpCellProt* pProt, XclExpColor* pColor)
+ XclExpDxfFont* pFont, XclExpNumFmt* pNumberFmt, XclExpCellProt* pProt, XclExpColor* pColor)
: XclExpRoot( rRoot ),
mpAlign(pAlign),
mpBorder(pBorder),
diff --git a/sc/source/filter/inc/xestyle.hxx b/sc/source/filter/inc/xestyle.hxx
index f17e9dacbfc8..0899d3395de9 100644
--- a/sc/source/filter/inc/xestyle.hxx
+++ b/sc/source/filter/inc/xestyle.hxx
@@ -29,6 +29,7 @@
#include "xlstyle.hxx"
#include "xeroot.hxx"
#include "conditio.hxx"
+#include "fonthelper.hxx"
#include <boost/shared_ptr.hpp>
#include <boost/scoped_ptr.hpp>
#include <boost/ptr_container/ptr_vector.hpp>
@@ -143,6 +144,13 @@ namespace XclExpFontHelper
const SfxItemSet& rItemSet,
sal_Int16 nScript );
+ /**
+ * Get a dxf related font object from the item set.
+ * Only items that are explicitly set in the item set
+ * are also set in the returned object.
+ */
+ ScDxfFont GetDxfFontFromItemSet(const XclExpRoot& rRoot, const SfxItemSet& rSet);
+
/** 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. */
bool CheckItems(
@@ -179,6 +187,17 @@ private:
sal_uInt32 mnHash; /// Hash value for fast comparison.
};
+class XclExpDxfFont : public XclExpRecordBase, protected XclExpRoot
+{
+public:
+ XclExpDxfFont(const XclExpRoot& rRoot, const SfxItemSet& rItemSet);
+
+ virtual void SaveXml(XclExpXmlStream& rStrm) SAL_OVERRIDE;
+private:
+
+ ScDxfFont maDxfData;
+};
+
/** Used as placeholder for font index 4, which is not used in Excel. */
class XclExpBlindFont : public XclExpFont
{
@@ -695,7 +714,7 @@ class XclExpDxf : public XclExpRecordBase, protected XclExpRoot
{
public:
XclExpDxf( const XclExpRoot& rRoot, XclExpCellAlign* pAlign, XclExpCellBorder* pBorder,
- XclExpFont* pFont, XclExpNumFmt* pNumberFmt, XclExpCellProt* pProt, XclExpColor* pColor);
+ XclExpDxfFont* pFont, XclExpNumFmt* pNumberFmt, XclExpCellProt* pProt, XclExpColor* pColor);
virtual ~XclExpDxf();
virtual void SaveXml( XclExpXmlStream& rStrm ) SAL_OVERRIDE;
@@ -703,7 +722,7 @@ public:
private:
boost::scoped_ptr<XclExpCellAlign> mpAlign;
boost::scoped_ptr<XclExpCellBorder> mpBorder;
- boost::scoped_ptr<XclExpFont> mpFont;
+ boost::scoped_ptr<XclExpDxfFont> mpFont;
boost::scoped_ptr<XclExpNumFmt> mpNumberFmt;
boost::scoped_ptr<XclExpCellProt> mpProt;
boost::scoped_ptr<XclExpColor> mpColor;