Kaydet (Commit) f39f7ba6 authored tarafından Zhe Wang's avatar Zhe Wang Kaydeden (comit) Xisco Fauli

Fix issue #i120723#: Table style is lost when import PPTX by AOO

* subversion/main/oox/inc/oox/drawingml/table/tableproperties.hxx
* subversion/main/oox/source/drawingml/table/tableproperties.cxx
[]if the imported table in pptx just have tableStyleId, should fill the tablestyle's content.

Patch by: Ma Bingbing <jiazema@gmail.com>
Suggested by: Wang Zhe <kingwisemmx@gmail.com>
Found by:Ma Bingbing <jiazema@gmail.com>
Review by: Wang Zhe <kingwisemmx@gmail.com>(cherry picked from commit 74b1435a)

Conflicts:
	oox/inc/oox/drawingml/table/tableproperties.hxx
	oox/source/drawingml/table/tableproperties.cxx

Change-Id: I554169522a95343662781c3f169c6485c38a6800
üst 8c39c42c
...@@ -57,7 +57,7 @@ public: ...@@ -57,7 +57,7 @@ public:
private: private:
const TableStyle& getUsedTableStyle( const ::oox::core::XmlFilterBase& rFilterBase ); const TableStyle& getUsedTableStyle( const ::oox::core::XmlFilterBase& rFilterBase, sal_Bool &isCreateTabStyle);
OUString maStyleId; // either StyleId is available OUString maStyleId; // either StyleId is available
boost::shared_ptr< TableStyle > mpTableStyle; // or the complete TableStyle boost::shared_ptr< TableStyle > mpTableStyle; // or the complete TableStyle
......
/**************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*************************************************************/
#ifndef OOX_DRAWINGML_TABLEPROPERTIES_HXX
#define OOX_DRAWINGML_TABLEPROPERTIES_HXX
#include "oox/drawingml/table/tablerow.hxx"
#include "oox/drawingml/table/tablestyle.hxx"
#include "oox/helper/propertymap.hxx"
#include "oox/drawingml/color.hxx"
#include <boost/shared_ptr.hpp>
#include <boost/optional.hpp>
#include <vector>
#include <map>
namespace oox { namespace drawingml { namespace table {
class TableProperties
{
public:
TableProperties();
~TableProperties();
std::vector< sal_Int32 >& getTableGrid() { return mvTableGrid; };
std::vector< TableRow >& getTableRows() { return mvTableRows; };
rtl::OUString& getStyleId(){ return maStyleId; };
boost::shared_ptr< TableStyle >& getTableStyle(){ return mpTableStyle; };
sal_Bool& isRtl(){ return mbRtl; };
sal_Bool& isFirstRow(){ return mbFirstRow; };
sal_Bool& isFirstCol(){ return mbFirstCol; };
sal_Bool& isLastRow(){ return mbLastRow; };
sal_Bool& isLastCol(){ return mbLastCol; };
sal_Bool& isBandRow(){ return mbBandRow; };
sal_Bool& isBandCol(){ return mbBandCol; };
void apply( const TablePropertiesPtr& );
void pushToPropSet( const ::oox::core::XmlFilterBase& rFilterBase,
const ::com::sun::star::uno::Reference < ::com::sun::star::beans::XPropertySet > & xPropSet, ::oox::drawingml::TextListStylePtr pMasterTextListStyle );
private:
const TableStyle& getUsedTableStyle( const ::oox::core::XmlFilterBase& rFilterBase, sal_Bool &isCreateTabStyle);
rtl::OUString maStyleId; // either StyleId is available
boost::shared_ptr< TableStyle > mpTableStyle; // or the complete TableStyle
std::vector< sal_Int32 > mvTableGrid;
std::vector< TableRow > mvTableRows;
sal_Bool mbRtl;
sal_Bool mbFirstRow;
sal_Bool mbFirstCol;
sal_Bool mbLastRow;
sal_Bool mbLastCol;
sal_Bool mbBandRow;
sal_Bool mbBandCol;
};
} } }
#endif // OOX_DRAWINGML_TABLEPROPERTIES_HXX
...@@ -99,7 +99,132 @@ namespace ...@@ -99,7 +99,132 @@ namespace
struct theDefaultTableStyle : public ::rtl::Static< TableStyle, theDefaultTableStyle > {}; struct theDefaultTableStyle : public ::rtl::Static< TableStyle, theDefaultTableStyle > {};
} }
const TableStyle& TableProperties::getUsedTableStyle( const ::oox::core::XmlFilterBase& rFilterBase ) //for pptx just has table style id
static void SetTableStyleProperties(TableStyle* &pTableStyle , const sal_Int32& tblFillClr,const sal_Int32& tblTextClr, const sal_Int32& lineBdrClr)
{
//whole table fill style and color
oox::drawingml::FillPropertiesPtr pWholeTabFillProperties( new oox::drawingml::FillProperties );
pWholeTabFillProperties->moFillType.set(XML_solidFill);
pWholeTabFillProperties->maFillColor.setSchemeClr(tblFillClr);
pWholeTabFillProperties->maFillColor.addTransformation(XML_tint,20000);
pTableStyle->getWholeTbl().getFillProperties() = pWholeTabFillProperties;
//whole table text color
::oox::drawingml::Color tableTextColor;
tableTextColor.setSchemeClr(tblTextClr);
pTableStyle->getWholeTbl().getTextColor() = tableTextColor;
//whole table line border
oox::drawingml::LinePropertiesPtr pLeftBorder( new oox::drawingml::LineProperties);
pLeftBorder->moLineWidth = 12700;
pLeftBorder->moPresetDash = XML_sng;
pLeftBorder->maLineFill.moFillType.set(XML_solidFill);
pLeftBorder->maLineFill.maFillColor.setSchemeClr(lineBdrClr);
pTableStyle->getWholeTbl().getLineBorders().insert(std::pair<sal_Int32, ::oox::drawingml::LinePropertiesPtr>(XML_left,pLeftBorder));
pTableStyle->getWholeTbl().getLineBorders().insert(std::pair<sal_Int32, ::oox::drawingml::LinePropertiesPtr>(XML_right,pLeftBorder));
pTableStyle->getWholeTbl().getLineBorders().insert(std::pair<sal_Int32, ::oox::drawingml::LinePropertiesPtr>(XML_top,pLeftBorder));
pTableStyle->getWholeTbl().getLineBorders().insert(std::pair<sal_Int32, ::oox::drawingml::LinePropertiesPtr>(XML_bottom,pLeftBorder));
pTableStyle->getWholeTbl().getLineBorders().insert(std::pair<sal_Int32, ::oox::drawingml::LinePropertiesPtr>(XML_insideH,pLeftBorder));
pTableStyle->getWholeTbl().getLineBorders().insert(std::pair<sal_Int32, ::oox::drawingml::LinePropertiesPtr>(XML_insideV,pLeftBorder));
//Band1H style
oox::drawingml::FillPropertiesPtr pBand1HFillProperties( new oox::drawingml::FillProperties );
pBand1HFillProperties->moFillType.set(XML_solidFill);
pBand1HFillProperties->maFillColor.setSchemeClr(tblFillClr);
pBand1HFillProperties->maFillColor.addTransformation(XML_tint,40000);
pTableStyle->getBand1H().getFillProperties() = pBand1HFillProperties;
//Band1V style
pTableStyle->getBand1V().getFillProperties() = pBand1HFillProperties;
//tet bold for 1st row/last row/column
::boost::optional< sal_Bool > textBoldStyle(sal_True);
pTableStyle->getFirstRow().getTextBoldStyle() = textBoldStyle;
pTableStyle->getLastRow().getTextBoldStyle() = textBoldStyle;
pTableStyle->getFirstCol().getTextBoldStyle() = textBoldStyle;
pTableStyle->getLastCol().getTextBoldStyle() = textBoldStyle;
}
sal_Bool CreateTableStyle(TableStyle* &pTableStyle , const OUString& styleId)
{
sal_Bool createdTblStyle = sal_False;
if(!styleId.compareToAscii("{5C22544A-7EE6-4342-B048-85BDC9FD1C3A}")){ //Medium Style 2 Accenat 1
pTableStyle = new TableStyle();
createdTblStyle = sal_True;
//first row style
//fill color and type
oox::drawingml::FillPropertiesPtr pFstRowFillProperties( new oox::drawingml::FillProperties );
pFstRowFillProperties->moFillType.set(XML_solidFill);
pFstRowFillProperties->maFillColor.setSchemeClr(XML_accent1);
pTableStyle->getFirstRow().getFillProperties() = pFstRowFillProperties;
//text color
::oox::drawingml::Color fstRowTextColor;
fstRowTextColor.setSchemeClr(XML_lt1);
pTableStyle->getFirstRow().getTextColor() = fstRowTextColor;
//bottom line border
oox::drawingml::LinePropertiesPtr pFstBottomBorder( new oox::drawingml::LineProperties);
pFstBottomBorder->moLineWidth = 38100;
pFstBottomBorder->moPresetDash = XML_sng;
pFstBottomBorder->maLineFill.moFillType.set(XML_solidFill);
pFstBottomBorder->maLineFill.maFillColor.setSchemeClr(XML_lt1);
pTableStyle->getFirstRow().getLineBorders().insert(std::pair<sal_Int32, ::oox::drawingml::LinePropertiesPtr>(XML_bottom,pFstBottomBorder));
//last row style
pTableStyle->getLastRow().getFillProperties() = pFstRowFillProperties;
pTableStyle->getLastRow().getTextColor() = fstRowTextColor;
pTableStyle->getLastRow().getLineBorders().insert(std::pair<sal_Int32, ::oox::drawingml::LinePropertiesPtr>(XML_top,pFstBottomBorder));
//first column style
pTableStyle->getFirstRow().getFillProperties() = pFstRowFillProperties;
pTableStyle->getFirstRow().getTextColor() = fstRowTextColor;
//last column style
pTableStyle->getLastCol().getFillProperties() = pFstRowFillProperties;
pTableStyle->getLastCol().getTextColor() = fstRowTextColor;
SetTableStyleProperties(pTableStyle, XML_accent1, XML_dk1, XML_lt1);
}
else if (!styleId.compareToAscii("{21E4AEA4-8DFA-4A89-87EB-49C32662AFE0}")) //Medium Style 2 Accent 2
{
pTableStyle = new TableStyle();
createdTblStyle = sal_True;
oox::drawingml::FillPropertiesPtr pFstRowFillProperties( new oox::drawingml::FillProperties );
pFstRowFillProperties->moFillType.set(XML_solidFill);
pFstRowFillProperties->maFillColor.setSchemeClr(XML_accent2);
pTableStyle->getFirstRow().getFillProperties() = pFstRowFillProperties;
::oox::drawingml::Color fstRowTextColor;
fstRowTextColor.setSchemeClr(XML_lt1);
pTableStyle->getFirstRow().getTextColor() = fstRowTextColor;
oox::drawingml::LinePropertiesPtr pFstBottomBorder( new oox::drawingml::LineProperties);
pFstBottomBorder->moLineWidth = 38100;
pFstBottomBorder->moPresetDash = XML_sng;
pFstBottomBorder->maLineFill.moFillType.set(XML_solidFill);
pFstBottomBorder->maLineFill.maFillColor.setSchemeClr(XML_lt1);
pTableStyle->getFirstRow().getLineBorders().insert(std::pair<sal_Int32, ::oox::drawingml::LinePropertiesPtr>(XML_bottom,pFstBottomBorder));
pTableStyle->getLastRow().getFillProperties() = pFstRowFillProperties;
pTableStyle->getLastRow().getTextColor() = fstRowTextColor;
pTableStyle->getLastRow().getLineBorders().insert(std::pair<sal_Int32, ::oox::drawingml::LinePropertiesPtr>(XML_top,pFstBottomBorder));
pTableStyle->getFirstCol().getFillProperties() = pFstRowFillProperties;
pTableStyle->getFirstCol().getTextColor() = fstRowTextColor;
pTableStyle->getLastCol().getFillProperties() = pFstRowFillProperties;
pTableStyle->getLastCol().getTextColor() = fstRowTextColor;
SetTableStyleProperties(pTableStyle, XML_accent2, XML_dk1, XML_lt1);
}
else if (!styleId.compareToAscii("{C4B1156A-380E-4F78-BDF5-A606A8083BF9}")) //Medium Style 4 Accent 4
{
pTableStyle = new TableStyle();
createdTblStyle = sal_True;
SetTableStyleProperties(pTableStyle, XML_accent4, XML_dk1, XML_accent4);
}
return createdTblStyle;
}
const TableStyle& TableProperties::getUsedTableStyle( const ::oox::core::XmlFilterBase& rFilterBase, sal_Bool &isCreateTabStyle )
{ {
::oox::core::XmlFilterBase& rBase( const_cast< ::oox::core::XmlFilterBase& >( rFilterBase ) ); ::oox::core::XmlFilterBase& rBase( const_cast< ::oox::core::XmlFilterBase& >( rFilterBase ) );
...@@ -120,6 +245,11 @@ const TableStyle& TableProperties::getUsedTableStyle( const ::oox::core::XmlFilt ...@@ -120,6 +245,11 @@ const TableStyle& TableProperties::getUsedTableStyle( const ::oox::core::XmlFilt
} }
++aIter; ++aIter;
} }
//if the pptx just has table style id, but no table style content, we will create the table style ourselves
if ( !pTableStyle )
{
isCreateTabStyle = CreateTableStyle(pTableStyle , aStyleId);
}
} }
if ( !pTableStyle ) if ( !pTableStyle )
...@@ -137,7 +267,8 @@ void TableProperties::pushToPropSet( const ::oox::core::XmlFilterBase& rFilterBa ...@@ -137,7 +267,8 @@ void TableProperties::pushToPropSet( const ::oox::core::XmlFilterBase& rFilterBa
CreateTableColumns( xColumnRowRange->getColumns(), mvTableGrid ); CreateTableColumns( xColumnRowRange->getColumns(), mvTableGrid );
CreateTableRows( xColumnRowRange->getRows(), mvTableRows ); CreateTableRows( xColumnRowRange->getRows(), mvTableRows );
const TableStyle& rTableStyle( getUsedTableStyle( rFilterBase ) ); sal_Bool mbOwnTblStyle = sal_False;
const TableStyle& rTableStyle( getUsedTableStyle( rFilterBase, mbOwnTblStyle ) );
sal_Int32 nRow = 0; sal_Int32 nRow = 0;
const std::vector< TableRow >::const_iterator aTableRowEnd( mvTableRows.end() ); const std::vector< TableRow >::const_iterator aTableRowEnd( mvTableRows.end() );
for (std::vector< TableRow >::iterator aTableRowIter( mvTableRows.begin() ); for (std::vector< TableRow >::iterator aTableRowIter( mvTableRows.begin() );
...@@ -161,6 +292,17 @@ void TableProperties::pushToPropSet( const ::oox::core::XmlFilterBase& rFilterBa ...@@ -161,6 +292,17 @@ void TableProperties::pushToPropSet( const ::oox::core::XmlFilterBase& rFilterBa
} }
} }
} }
if(mbOwnTblStyle == sal_True)
{
TableStyle* pTableStyle = (TableStyle*)&rTableStyle;
if(pTableStyle != NULL)
{
delete pTableStyle;
pTableStyle = NULL;
}
mbOwnTblStyle = sal_False;
}
} }
} } } } } }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment