diff options
author | Jakub Trzebiatowski <ubap.dev@gmail.com> | 2016-06-11 15:17:48 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2016-06-20 12:08:01 +0000 |
commit | 309bc35559cb823415139044272b10feccdb6ae7 (patch) | |
tree | 0a2533ae40f366e95c84c18b751a877340c0d407 /xmloff | |
parent | 7423629f0abec966bd9403800ca0bd5c96a8b3a6 (diff) |
GSoC Table Styles, Export Cell Styles
Exporting cell-styles
Exporting table-template
To be able to map SwTableAutoFormat to table-template 1:1
extended table-template by the following elements:
loext:first-row-even-column
loext:last-row-even-column
loext:first-row-end-column
loext:first-row-start-column
loext:last-row-end-column
loext:last-row-start-column
Added attributes describing box format to SwXTextCellStyle
Change-Id: I2967ba461dfc6f030c1e5cdbba62e2673d3b232b
Reviewed-on: https://gerrit.libreoffice.org/26185
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Diffstat (limited to 'xmloff')
-rw-r--r-- | xmloff/source/core/xmltoken.cxx | 8 | ||||
-rw-r--r-- | xmloff/source/style/prhdlfac.cxx | 21 | ||||
-rw-r--r-- | xmloff/source/table/XMLTableExport.cxx | 146 | ||||
-rw-r--r-- | xmloff/source/text/txtprhdl.cxx | 19 |
4 files changed, 164 insertions, 30 deletions
diff --git a/xmloff/source/core/xmltoken.cxx b/xmloff/source/core/xmltoken.cxx index 847f61d9eecf..fe35e33ed696 100644 --- a/xmloff/source/core/xmltoken.cxx +++ b/xmloff/source/core/xmltoken.cxx @@ -3065,6 +3065,14 @@ namespace xmloff { namespace token { TOKEN( "odd-rows", XML_ODD_ROWS ), TOKEN( "even-columns", XML_EVEN_COLUMNS ), TOKEN( "odd-columns", XML_ODD_COLUMNS ), + // table styles + TOKEN( "first-row-even-column", XML_FIRST_ROW_EVEN_COLUMN ), + TOKEN( "last-row-even-column", XML_LAST_ROW_EVEN_COLUMN ), + TOKEN( "first-row-end-column", XML_FIRST_ROW_END_COLUMN ), + TOKEN( "first-row-start-column", XML_FIRST_ROW_START_COLUMN ), + TOKEN( "last-row-end-column", XML_LAST_ROW_END_COLUMN ), + TOKEN( "last-row-start-column", XML_LAST_ROW_START_COLUMN ), + TOKEN( "horizontal-on-odd", XML_HORIZONTAL_ON_ODD ), // Password error from 1.4 to 2.0 Beta (#i45874#) TOKEN( "restart-numbering", XML_RESTART_NUMBERING), diff --git a/xmloff/source/style/prhdlfac.cxx b/xmloff/source/style/prhdlfac.cxx index 8e703e3fe778..e70168782d88 100644 --- a/xmloff/source/style/prhdlfac.cxx +++ b/xmloff/source/style/prhdlfac.cxx @@ -22,6 +22,7 @@ #include <com/sun/star/drawing/ColorMode.hpp> #include <com/sun/star/text/HorizontalAdjust.hpp> #include <com/sun/star/text/WritingMode2.hpp> +#include <com/sun/star/text/VertOrientation.hpp> #include <tools/debug.hxx> @@ -98,6 +99,22 @@ static SvXMLEnumMapEntry const aXML_WritingDirection_Enum[] = { XML_TOKEN_INVALID, 0 } }; +static SvXMLEnumMapEntry const pXML_VertPos_Enum[] = +{ + { XML_FROM_TOP, text::VertOrientation::NONE }, + { XML_TOP, text::VertOrientation::TOP }, + { XML_TOP, text::VertOrientation::CHAR_TOP }, // export only + { XML_TOP, text::VertOrientation::LINE_TOP }, // export only + { XML_MIDDLE, text::VertOrientation::CENTER }, + { XML_MIDDLE, text::VertOrientation::CHAR_CENTER }, // export only + { XML_MIDDLE, text::VertOrientation::LINE_CENTER }, // export only + { XML_BOTTOM, text::VertOrientation::BOTTOM }, + { XML_BOTTOM, text::VertOrientation::CHAR_BOTTOM }, // export only + { XML_BOTTOM, text::VertOrientation::LINE_BOTTOM }, // export only + { XML_BELOW, text::VertOrientation::CHAR_BOTTOM }, // import only + { XML_TOKEN_INVALID, 0 } +}; + typedef std::map<sal_Int32, const XMLPropertyHandler*> CacheMap; struct XMLPropertyHandlerFactory::Impl @@ -446,6 +463,10 @@ const XMLPropertyHandler* XMLPropertyHandlerFactory::CreatePropertyHandler( sal_ case XML_TYPE_NUMBER16_AUTO: pPropHdl = new XMLNumberWithAutoInsteadZeroPropHdl(); break; + case XML_TYPE_TEXT_VERTICAL_POS: + pPropHdl = new XMLConstantsPropertyHandler( pXML_VertPos_Enum, XML_TOKEN_INVALID ); + break; + } return pPropHdl; diff --git a/xmloff/source/table/XMLTableExport.cxx b/xmloff/source/table/XMLTableExport.cxx index 913c40c7a8bd..f0f51c7fdd09 100644 --- a/xmloff/source/table/XMLTableExport.cxx +++ b/xmloff/source/table/XMLTableExport.cxx @@ -61,6 +61,7 @@ using namespace ::com::sun::star::style; #define MAP_(name,prefix,token,type,context) { name, sizeof(name)-1, prefix, token, type, context, SvtSaveOptions::ODFVER_010, false } #define CMAP(name,prefix,token,type,context) MAP_(name,prefix,token,type|XML_TYPE_PROP_TABLE_COLUMN,context) #define RMAP(name,prefix,token,type,context) MAP_(name,prefix,token,type|XML_TYPE_PROP_TABLE_ROW,context) +#define CELLMAP(name,prefix,token,type,context) MAP_(name,prefix,token,type|XML_TYPE_PROP_TABLE_CELL,context) #define MAP_END { nullptr, 0, 0, XML_EMPTY, 0, 0, SvtSaveOptions::ODFVER_010, false } const XMLPropertyMapEntry* getColumnPropertiesMap() @@ -88,6 +89,29 @@ const XMLPropertyMapEntry* getRowPropertiesMap() return &aXMLRowProperties[0]; } +const XMLPropertyMapEntry* getSwCellStylePropertiesMap() +{ + static const XMLPropertyMapEntry aXMLSwCellStyleProperties[] = + { + CELLMAP( "BackColor", XML_NAMESPACE_FO, XML_BACKGROUND_COLOR, XML_TYPE_COLORTRANSPARENT|MID_FLAG_MULTI_PROPERTY, 0 ), + CELLMAP( "LeftBorder", XML_NAMESPACE_FO, XML_BORDER_LEFT, XML_TYPE_BORDER, 0 ), + CELLMAP( "RightBorder", XML_NAMESPACE_FO, XML_BORDER_RIGHT, XML_TYPE_BORDER, 0 ), + CELLMAP( "TopBorder", XML_NAMESPACE_FO, XML_BORDER_TOP, XML_TYPE_BORDER, 0 ), + CELLMAP( "BottomBorder", XML_NAMESPACE_FO, XML_BORDER_BOTTOM, XML_TYPE_BORDER, 0 ), + CELLMAP( "BorderDistance", XML_NAMESPACE_FO, XML_PADDING, XML_TYPE_MEASURE|MID_FLAG_MULTI_PROPERTY, 0 ), + CELLMAP( "LeftBorderDistance", XML_NAMESPACE_FO, XML_PADDING_LEFT, XML_TYPE_MEASURE|MID_FLAG_MULTI_PROPERTY, 0 ), + CELLMAP( "RightBorderDistance", XML_NAMESPACE_FO, XML_PADDING_RIGHT, XML_TYPE_MEASURE|MID_FLAG_MULTI_PROPERTY, 0 ), + CELLMAP( "TopBorderDistance", XML_NAMESPACE_FO, XML_PADDING_TOP, XML_TYPE_MEASURE|MID_FLAG_MULTI_PROPERTY, 0 ), + CELLMAP( "BottomBorderDistance", XML_NAMESPACE_FO, XML_PADDING_BOTTOM, XML_TYPE_MEASURE|MID_FLAG_MULTI_PROPERTY, 0 ), + CELLMAP( "VertOrient", XML_NAMESPACE_STYLE, XML_VERTICAL_ALIGN, XML_TYPE_TEXT_VERTICAL_POS, 0 ), + CELLMAP( "WritingMode", XML_NAMESPACE_STYLE, XML_WRITING_MODE, XML_TYPE_TEXT_WRITING_MODE_WITH_DEFAULT, 0 ), + CELLMAP( "NumberFormat", XML_NAMESPACE_STYLE, XML_DATA_STYLE_NAME, XML_TYPE_NUMBER, 0 ), + MAP_END + }; + + return &aXMLSwCellStyleProperties[0]; +} + class StringStatisticHelper { private: @@ -135,6 +159,7 @@ sal_Int32 StringStatisticHelper::getModeString( OUString& rStyleName ) XMLTableExport::XMLTableExport(SvXMLExport& rExp, const rtl::Reference< SvXMLExportPropertyMapper >& xExportPropertyMapper, const rtl::Reference< XMLPropertyHandlerFactory >& xFactoryRef ) : mrExport( rExp ) , mbExportTables( false ) +, mbWriter( false ) { Reference< XMultiServiceFactory > xFac( rExp.GetModel(), UNO_QUERY ); if( xFac.is() ) try @@ -144,19 +169,28 @@ XMLTableExport::XMLTableExport(SvXMLExport& rExp, const rtl::Reference< SvXMLExp const OUString* pSNS( sSNS.getConstArray() ); while( --n > 0 ) { - if( (*pSNS++) == "com.sun.star.drawing.TableShape" ) + if( *pSNS == "com.sun.star.drawing.TableShape" || *pSNS == "com.sun.star.style.TableStyle" ) { mbExportTables = true; + mbWriter = (*pSNS == "com.sun.star.style.TableStyle"); break; } + pSNS++; } } catch(const Exception&) { } - mxCellExportPropertySetMapper = xExportPropertyMapper; - mxCellExportPropertySetMapper->ChainExportMapper(XMLTextParagraphExport::CreateParaExtPropMapper(rExp)); + if (mbWriter) + { + mxCellExportPropertySetMapper = new SvXMLExportPropertyMapper( new XMLPropertySetMapper( getSwCellStylePropertiesMap(), xFactoryRef.get(), true ) ); + } + else + { + mxCellExportPropertySetMapper = xExportPropertyMapper; + mxCellExportPropertySetMapper->ChainExportMapper(XMLTextParagraphExport::CreateParaExtPropMapper(rExp)); + } mxRowExportPropertySetMapper = new SvXMLExportPropertyMapper( new XMLPropertySetMapper( getRowPropertiesMap(), xFactoryRef.get(), true ) ); mxColumnExportPropertySetMapper = new SvXMLExportPropertyMapper( new XMLPropertySetMapper( getColumnPropertiesMap(), xFactoryRef.get(), true ) ); @@ -456,10 +490,21 @@ void XMLTableExport::exportTableStyles() if( !mbExportTables ) return; - rtl::Reference<XMLStyleExport> aStEx(new XMLStyleExport(mrExport, OUString(), mrExport.GetAutoStylePool().get())); + rtl::Reference<XMLStyleExport> aStEx; + OUString sCellStyleName; + if (mbWriter) + { + sCellStyleName = "CellStyles"; + aStEx.set(new XMLStyleExport(mrExport, OUString())); + } + else + { + // write graphic family styles + sCellStyleName = "cell"; + aStEx.set(new XMLStyleExport(mrExport, OUString(), mrExport.GetAutoStylePool().get())); + } - // write graphic family styles - aStEx->exportStyleFamily("cell", OUString(XML_STYLE_FAMILY_TABLE_CELL_STYLES_NAME), mxCellExportPropertySetMapper.get(), true, XML_STYLE_FAMILY_TABLE_CELL); + aStEx->exportStyleFamily(sCellStyleName, OUString(XML_STYLE_FAMILY_TABLE_CELL_STYLES_NAME), mxCellExportPropertySetMapper.get(), true, XML_STYLE_FAMILY_TABLE_CELL); exportTableTemplates(); } @@ -484,17 +529,47 @@ const TableStyleElement* getTableStyleMap() { XML_LAST_ROW, OUString("last-row") }, { XML_FIRST_COLUMN, OUString("first-column") }, { XML_LAST_COLUMN, OUString("last-column") }, + { XML_BODY, OUString("body") }, { XML_EVEN_ROWS, OUString("even-rows") }, { XML_ODD_ROWS, OUString("odd-rows") }, { XML_EVEN_COLUMNS, OUString("even-columns") }, { XML_ODD_COLUMNS, OUString("odd-columns") }, - { XML_BODY, OUString("body") }, { XML_TOKEN_END, OUString() } }; return &gTableStyleElements[0]; } +const TableStyleElement* getWriterSpecificTableStyleMap() +{ + static const struct TableStyleElement gWriterSpecificTableStyleElements[] = + { + { XML_FIRST_ROW_EVEN_COLUMN, OUString("first-row-even-column") }, + { XML_LAST_ROW_EVEN_COLUMN, OUString("last-row-even-column") }, + { XML_FIRST_ROW_END_COLUMN, OUString("first-row-end-column") }, + { XML_FIRST_ROW_START_COLUMN, OUString("first-row-start-column") }, + { XML_LAST_ROW_END_COLUMN, OUString("last-row-end-column") }, + { XML_LAST_ROW_START_COLUMN, OUString("last-row-start-column") }, + { XML_TOKEN_END, OUString() } + }; + + return &gWriterSpecificTableStyleElements[0]; +} + +const TableStyleElement* getWriterSpecificTableStyleAttributes() +{ + static const struct TableStyleElement gWriterSpecifitTableStyleAttributes[] = + { + { XML_FIRST_ROW_END_COLUMN, OUString("FirstRowEndColumn") }, + { XML_FIRST_ROW_START_COLUMN, OUString("FirstRowStartColumn") }, + { XML_LAST_ROW_END_COLUMN, OUString("LastRowEndColumn") }, + { XML_LAST_ROW_START_COLUMN, OUString("LastRowStartColumn") }, + { XML_TOKEN_END, OUString() } + }; + + return &gWriterSpecifitTableStyleAttributes[0]; +} + void XMLTableExport::exportTableTemplates() { if( !mbExportTables ) @@ -504,7 +579,12 @@ void XMLTableExport::exportTableTemplates() { Reference< XStyleFamiliesSupplier > xFamiliesSupp( mrExport.GetModel(), UNO_QUERY_THROW ); Reference< XNameAccess > xFamilies( xFamiliesSupp->getStyleFamilies() ); - const OUString sFamilyName( "table" ); + OUString sFamilyName; + if (mbWriter) + sFamilyName = "TableStyles"; + else + sFamilyName = "table"; + Reference< XIndexAccess > xTableFamily( xFamilies->getByName( sFamilyName ), UNO_QUERY_THROW ); for( sal_Int32 nIndex = 0; nIndex < xTableFamily->getCount(); nIndex++ ) try @@ -513,12 +593,34 @@ void XMLTableExport::exportTableTemplates() if( !xTableStyle->isInUse() ) continue; - Reference< XNameAccess > xStyleNames( xTableStyle, UNO_QUERY_THROW ); + const TableStyleElement* pElements; + if (mbWriter) + { + mrExport.AddAttribute(XML_NAMESPACE_TABLE, XML_NAME, GetExport().EncodeStyleName(xTableStyle->getName())); + Reference<XPropertySet> xTableStylePropSet(xTableStyle.get(), UNO_QUERY_THROW); + pElements = getWriterSpecificTableStyleAttributes(); + while(pElements->meElement != XML_TOKEN_END) + { + try + { + OUString sVal; + xTableStylePropSet->getPropertyValue(pElements->msStyleName) >>= sVal; + mrExport.AddAttribute(XML_NAMESPACE_TABLE, pElements->meElement, sVal); + } + catch(const Exception&) + { + SAL_WARN("xmloff", "XMLTableExport::exportTableTemplates(), export Writer specific attributes, exception caught!"); + } + pElements++; + } + } + else + mrExport.AddAttribute(XML_NAMESPACE_TEXT, XML_STYLE_NAME, GetExport().EncodeStyleName( xTableStyle->getName() ) ); - mrExport.AddAttribute(XML_NAMESPACE_TEXT, XML_STYLE_NAME, GetExport().EncodeStyleName( xTableStyle->getName() ) ); SvXMLElementExport tableTemplate( mrExport, XML_NAMESPACE_TABLE, XML_TABLE_TEMPLATE, true, true ); - const TableStyleElement* pElements = getTableStyleMap(); + Reference< XNameAccess > xStyleNames( xTableStyle, UNO_QUERY_THROW ); + pElements = getTableStyleMap(); while( pElements->meElement != XML_TOKEN_END ) { try @@ -537,6 +639,28 @@ void XMLTableExport::exportTableTemplates() pElements++; } + + if (mbWriter) + { + pElements = getWriterSpecificTableStyleMap(); + while(pElements->meElement != XML_TOKEN_END) + { + try + { + Reference<XStyle> xStyle(xStyleNames->getByName(pElements->msStyleName), UNO_QUERY); + if(xStyle.is()) + { + mrExport.AddAttribute(XML_NAMESPACE_TABLE, XML_STYLE_NAME, GetExport().EncodeStyleName(xStyle->getName())); + SvXMLElementExport element(mrExport, XML_NAMESPACE_LO_EXT, pElements->meElement, true, true); + } + } + catch(const Exception&) + { + SAL_WARN("xmloff", "XMLTableExport::exportTableTemplates(), export Writer specific styles, exception caught!"); + } + pElements++; + } + } } catch(const Exception&) { diff --git a/xmloff/source/text/txtprhdl.cxx b/xmloff/source/text/txtprhdl.cxx index f03edd6eba76..5e7e69939aa0 100644 --- a/xmloff/source/text/txtprhdl.cxx +++ b/xmloff/source/text/txtprhdl.cxx @@ -137,22 +137,6 @@ static SvXMLEnumMapEntry const pXML_HoriMirror_Enum[] = { XML_TOKEN_INVALID, 0 } }; -static SvXMLEnumMapEntry const pXML_VertPos_Enum[] = -{ - { XML_FROM_TOP, VertOrientation::NONE }, - { XML_TOP, VertOrientation::TOP }, - { XML_TOP, VertOrientation::CHAR_TOP }, // export only - { XML_TOP, VertOrientation::LINE_TOP }, // export only - { XML_MIDDLE, VertOrientation::CENTER }, - { XML_MIDDLE, VertOrientation::CHAR_CENTER }, // export only - { XML_MIDDLE, VertOrientation::LINE_CENTER }, // export only - { XML_BOTTOM, VertOrientation::BOTTOM }, - { XML_BOTTOM, VertOrientation::CHAR_BOTTOM }, // export only - { XML_BOTTOM, VertOrientation::LINE_BOTTOM }, // export only - { XML_BELOW, VertOrientation::CHAR_BOTTOM }, // import only - { XML_TOKEN_INVALID, 0 } -}; - static SvXMLEnumMapEntry const pXML_VertPosAtChar_Enum[] = { { XML_FROM_TOP, VertOrientation::NONE }, @@ -1272,9 +1256,6 @@ static const XMLPropertyHandler *GetPropertyHandler case XML_TYPE_TEXT_HORIZONTAL_MIRROR: pHdl = new XMLHoriMirrorPropHdl_Impl; break; - case XML_TYPE_TEXT_VERTICAL_POS: - pHdl = new XMLConstantsPropertyHandler( pXML_VertPos_Enum, XML_TOKEN_INVALID ); - break; case XML_TYPE_TEXT_VERTICAL_POS_AT_CHAR: pHdl = new XMLConstantsPropertyHandler( pXML_VertPosAtChar_Enum, XML_TOKEN_INVALID ); break; |