diff options
Diffstat (limited to 'xmloff/source/style/bordrhdl.cxx')
-rw-r--r-- | xmloff/source/style/bordrhdl.cxx | 302 |
1 files changed, 111 insertions, 191 deletions
diff --git a/xmloff/source/style/bordrhdl.cxx b/xmloff/source/style/bordrhdl.cxx index 5611bbd1f472..230f1082fe2e 100644 --- a/xmloff/source/style/bordrhdl.cxx +++ b/xmloff/source/style/bordrhdl.cxx @@ -1,3 +1,4 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /************************************************************************* * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. @@ -34,7 +35,11 @@ #include <xmloff/xmluconv.hxx> #include <rtl/ustrbuf.hxx> #include <com/sun/star/uno/Any.hxx> -#include <com/sun/star/table/BorderLine.hpp> +#include <com/sun/star/table/BorderLine2.hpp> + +#if DEBUG +#include <cstdio> +#endif using ::rtl::OUString; using ::rtl::OUStringBuffer; @@ -42,65 +47,25 @@ using ::rtl::OUStringBuffer; using namespace ::com::sun::star; using namespace ::xmloff::token; -// copied from svx/boxitem.hxx +const sal_uInt16 API_LINE_SOLID = 0; +const sal_uInt16 API_LINE_DOTTED = 1; +const sal_uInt16 API_LINE_DASHED = 2; +const sal_uInt16 API_LINE_DOUBLE = 3; +const sal_uInt16 API_LINE_THINTHICK_SMALLGAP = 4; +const sal_uInt16 API_LINE_THINTHICK_MEDIUMGAP = 5; +const sal_uInt16 API_LINE_THINTHICK_LARGEGAP = 6; +const sal_uInt16 API_LINE_THICKTHIN_SMALLGAP = 7; +const sal_uInt16 API_LINE_THICKTHIN_MEDIUMGAP = 8; +const sal_uInt16 API_LINE_THICKTHIN_LARGEGAP = 9; +const sal_uInt16 API_LINE_EMBOSSED = 10; +const sal_uInt16 API_LINE_ENGRAVED = 11; +const sal_uInt16 API_LINE_OUTSET = 12; +const sal_uInt16 API_LINE_INSET = 13; +const sal_uInt16 API_LINE_NONE = USHRT_MAX; + #define DEF_LINE_WIDTH_0 1 #define DEF_LINE_WIDTH_1 35 #define DEF_LINE_WIDTH_2 88 -#define DEF_LINE_WIDTH_3 141 -#define DEF_LINE_WIDTH_4 176 - -#define DEF_MAX_LINE_WIDHT DEF_LINE_WIDTH_4 -#define DEF_MAX_LINE_DIST DEF_LINE_WIDTH_2 - -#define DEF_DOUBLE_LINE0_OUT DEF_LINE_WIDTH_0 -#define DEF_DOUBLE_LINE0_IN DEF_LINE_WIDTH_0 -#define DEF_DOUBLE_LINE0_DIST DEF_LINE_WIDTH_1 - -#define DEF_DOUBLE_LINE1_OUT DEF_LINE_WIDTH_1 -#define DEF_DOUBLE_LINE1_IN DEF_LINE_WIDTH_1 -#define DEF_DOUBLE_LINE1_DIST DEF_LINE_WIDTH_1 - -#define DEF_DOUBLE_LINE2_OUT DEF_LINE_WIDTH_2 -#define DEF_DOUBLE_LINE2_IN DEF_LINE_WIDTH_2 -#define DEF_DOUBLE_LINE2_DIST DEF_LINE_WIDTH_2 - -#define DEF_DOUBLE_LINE3_OUT DEF_LINE_WIDTH_2 -#define DEF_DOUBLE_LINE3_IN DEF_LINE_WIDTH_1 -#define DEF_DOUBLE_LINE3_DIST DEF_LINE_WIDTH_2 - -#define DEF_DOUBLE_LINE4_OUT DEF_LINE_WIDTH_1 -#define DEF_DOUBLE_LINE4_IN DEF_LINE_WIDTH_2 -#define DEF_DOUBLE_LINE4_DIST DEF_LINE_WIDTH_1 - -#define DEF_DOUBLE_LINE5_OUT DEF_LINE_WIDTH_3 -#define DEF_DOUBLE_LINE5_IN DEF_LINE_WIDTH_2 -#define DEF_DOUBLE_LINE5_DIST DEF_LINE_WIDTH_2 - -#define DEF_DOUBLE_LINE6_OUT DEF_LINE_WIDTH_2 -#define DEF_DOUBLE_LINE6_IN DEF_LINE_WIDTH_3 -#define DEF_DOUBLE_LINE6_DIST DEF_LINE_WIDTH_2 - -#define DEF_DOUBLE_LINE7_OUT DEF_LINE_WIDTH_0 -#define DEF_DOUBLE_LINE7_IN DEF_LINE_WIDTH_0 -#define DEF_DOUBLE_LINE7_DIST DEF_LINE_WIDTH_2 - -#define DEF_DOUBLE_LINE8_OUT DEF_LINE_WIDTH_1 -#define DEF_DOUBLE_LINE8_IN DEF_LINE_WIDTH_0 -#define DEF_DOUBLE_LINE8_DIST DEF_LINE_WIDTH_2 - -#define DEF_DOUBLE_LINE9_OUT DEF_LINE_WIDTH_2 -#define DEF_DOUBLE_LINE9_IN DEF_LINE_WIDTH_0 -#define DEF_DOUBLE_LINE9_DIST DEF_LINE_WIDTH_2 - -#define DEF_DOUBLE_LINE10_OUT DEF_LINE_WIDTH_3 -#define DEF_DOUBLE_LINE10_IN DEF_LINE_WIDTH_0 -#define DEF_DOUBLE_LINE10_DIST DEF_LINE_WIDTH_2 - -// finished copy - -#define SVX_XML_BORDER_STYLE_NONE 0 -#define SVX_XML_BORDER_STYLE_SOLID 1 -#define SVX_XML_BORDER_STYLE_DOUBLE 2 #define SVX_XML_BORDER_WIDTH_THIN 0 #define SVX_XML_BORDER_WIDTH_MIDDLE 1 @@ -108,16 +73,16 @@ using namespace ::xmloff::token; SvXMLEnumMapEntry pXML_BorderStyles[] = { - { XML_NONE, SVX_XML_BORDER_STYLE_NONE }, - { XML_HIDDEN, SVX_XML_BORDER_STYLE_NONE }, - { XML_SOLID, SVX_XML_BORDER_STYLE_SOLID }, - { XML_DOUBLE, SVX_XML_BORDER_STYLE_DOUBLE }, - { XML_DOTTED, SVX_XML_BORDER_STYLE_SOLID }, - { XML_DASHED, SVX_XML_BORDER_STYLE_SOLID }, - { XML_GROOVE, SVX_XML_BORDER_STYLE_SOLID }, - { XML_RIDGE, SVX_XML_BORDER_STYLE_SOLID }, - { XML_INSET, SVX_XML_BORDER_STYLE_SOLID }, - { XML_OUTSET, SVX_XML_BORDER_STYLE_SOLID }, + { XML_NONE, API_LINE_NONE }, + { XML_HIDDEN, API_LINE_NONE }, + { XML_SOLID, API_LINE_SOLID }, + { XML_DOUBLE, API_LINE_DOUBLE }, + { XML_DOTTED, API_LINE_DOTTED }, + { XML_DASHED, API_LINE_DASHED }, + { XML_GROOVE, API_LINE_ENGRAVED }, + { XML_RIDGE, API_LINE_EMBOSSED }, + { XML_INSET, API_LINE_INSET }, + { XML_OUTSET, API_LINE_OUTSET }, { XML_TOKEN_INVALID, 0 } }; @@ -130,98 +95,21 @@ SvXMLEnumMapEntry pXML_NamedBorderWidths[] = }; // mapping tables to map external xml input to intarnal box line widths -// Ein Eintrag besteht aus vier USHORTs. Der erste ist die Gesamtbreite, -// die anderen sind die 3 Einzelbreiten - -#define SBORDER_ENTRY( n ) \ - DEF_LINE_WIDTH_##n, DEF_LINE_WIDTH_##n, 0, 0 - -#define DBORDER_ENTRY( n ) \ - DEF_DOUBLE_LINE##n##_OUT + DEF_DOUBLE_LINE##n##_IN + \ - DEF_DOUBLE_LINE##n##_DIST, \ - DEF_DOUBLE_LINE##n##_OUT, \ - DEF_DOUBLE_LINE##n##_IN, \ - DEF_DOUBLE_LINE##n##_DIST - -#define TDBORDER_ENTRY( n ) \ - DEF_DOUBLE_LINE##n##_OUT, \ - DEF_DOUBLE_LINE##n##_OUT, \ - DEF_DOUBLE_LINE##n##_IN, \ - DEF_DOUBLE_LINE##n##_DIST - - -static sal_uInt16 __READONLY_DATA aSBorderWidths[] = -{ - SBORDER_ENTRY( 0 ), SBORDER_ENTRY( 1 ), SBORDER_ENTRY( 2 ), - SBORDER_ENTRY( 3 ), SBORDER_ENTRY( 4 ) -}; -static sal_uInt16 __READONLY_DATA aDBorderWidths[] = +static sal_uInt16 const aBorderWidths[] = { - DBORDER_ENTRY( 0 ), - DBORDER_ENTRY( 7 ), - DBORDER_ENTRY( 1 ), - DBORDER_ENTRY( 8 ), - DBORDER_ENTRY( 4 ), - DBORDER_ENTRY( 9 ), - DBORDER_ENTRY( 3 ), - DBORDER_ENTRY( 10 ), - DBORDER_ENTRY( 2 ), - DBORDER_ENTRY( 6 ), - DBORDER_ENTRY( 5 ) + DEF_LINE_WIDTH_0, + DEF_LINE_WIDTH_1, + DEF_LINE_WIDTH_2 }; -void lcl_frmitems_setXMLBorderWidth( table::BorderLine &rBorderLine, - sal_uInt16 nWidth, sal_Bool bDouble ) +void lcl_frmitems_setXMLBorderStyle( table::BorderLine2 & rBorderLine, sal_uInt16 nStyle ) { -#ifdef XML_CHECK_UI_CONTSTRAINS - const sal_uInt16 *aWidths; - sal_uInt16 nSize; - if( !bDouble ) - { - aWidths = aSBorderWidths; - nSize = sizeof( aSBorderWidths ); - } - else - { - aWidths = aDBorderWidths; - nSize = sizeof( aDBorderWidths ); - } + sal_Int16 eStyle = -1; // None + if ( nStyle != API_LINE_NONE ) + eStyle = sal_Int16( nStyle ); - sal_uInt16 i = (nSize / sizeof(sal_uInt16)) - 4; - while( i>0 && - nWidth <= ((aWidths[i] + aWidths[i-4]) / 2) ) - { - i -= 4; - } - - rBorderLine.OuterLineWidth = aWidths[i+1]; - rBorderLine.InnerLineWidth = aWidths[i+2]; - rBorderLine.LineDistance = aWidths[i+3]; -#else - if( bDouble ) - { - const sal_uInt16 *aWidths = aDBorderWidths; - sal_uInt16 nSize = sizeof( aDBorderWidths ); - sal_uInt16 i = (nSize / sizeof(sal_uInt16)) - 4; - while( i>0 && - nWidth <= ((aWidths[i] + aWidths[i-4]) / 2) ) - { - i -= 4; - } - - rBorderLine.OuterLineWidth = aWidths[i+1]; - rBorderLine.InnerLineWidth = aWidths[i+2]; - rBorderLine.LineDistance = aWidths[i+3]; - } - else - { - rBorderLine.OuterLineWidth = 0 == nWidth ? DEF_LINE_WIDTH_0 : nWidth; - rBorderLine.InnerLineWidth = 0; - rBorderLine.LineDistance = 0; - - } -#endif + rBorderLine.LineStyle = eStyle; } @@ -260,20 +148,7 @@ sal_Bool XMLBorderWidthHdl::importXML( const OUString& rStrImpValue, uno::Any& r if( !rUnitConverter.convertMeasure( nOutWidth, aToken, 0, 500 ) ) return sal_False; -#ifdef XML_CHECK_UI_CONSTRAINS - sal_uInt16 nSize = sizeof( aDBorderWidths ); - for( sal_uInt16 i=0; i < nSize; i += 4 ) - { - if( aDBorderWidths[i+1] == nOutWidth && - aDBorderWidths[i+2] == nInWidth && - aDBorderWidths[i+3] == nDistance ) - break; - } - - sal_uInt16 nWidth = i < nSize ? 0 : nOutWidth + nInWidth + nDistance; -#endif - - table::BorderLine aBorderLine; + table::BorderLine2 aBorderLine; if(!(rValue >>= aBorderLine)) aBorderLine.Color = 0; @@ -289,11 +164,27 @@ sal_Bool XMLBorderWidthHdl::exportXML( OUString& rStrExpValue, const uno::Any& r { OUStringBuffer aOut; - table::BorderLine aBorderLine; + table::BorderLine2 aBorderLine; if(!(rValue >>= aBorderLine)) return sal_False; - if( aBorderLine.LineDistance == 0 && aBorderLine.InnerLineWidth == 0) + bool bDouble = false; + switch ( aBorderLine.LineStyle ) + { + case API_LINE_DOUBLE: + case API_LINE_THINTHICK_SMALLGAP: + case API_LINE_THINTHICK_MEDIUMGAP: + case API_LINE_THINTHICK_LARGEGAP: + case API_LINE_THICKTHIN_SMALLGAP: + case API_LINE_THICKTHIN_MEDIUMGAP: + case API_LINE_THICKTHIN_LARGEGAP: + bDouble = true; + break; + default: + break; + } + + if( ( aBorderLine.LineDistance == 0 && aBorderLine.InnerLineWidth == 0 ) || !bDouble ) return sal_False; rUnitConverter.convertMeasure( aOut, aBorderLine.InnerLineWidth ); @@ -365,46 +256,44 @@ sal_Bool XMLBorderHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue // if there is no style or a different style than none but no width, // then the declaration is not valid. - if( !bHasStyle || (SVX_XML_BORDER_STYLE_NONE != nStyle && !bHasWidth) ) + if( !bHasStyle || (API_LINE_NONE != nStyle && !bHasWidth) ) return sal_False; - table::BorderLine aBorderLine; + table::BorderLine2 aBorderLine; if(!(rValue >>= aBorderLine)) { aBorderLine.Color = 0; aBorderLine.InnerLineWidth = 0; aBorderLine.OuterLineWidth = 0; aBorderLine.LineDistance = 0; + aBorderLine.LineWidth = 0; } // first of all, delete an empty line - sal_Bool bDouble = SVX_XML_BORDER_STYLE_DOUBLE == nStyle; - if( (bHasStyle && SVX_XML_BORDER_STYLE_NONE == nStyle) || + if( (bHasStyle && API_LINE_NONE == nStyle) || (bHasWidth && USHRT_MAX == nNamedWidth && 0 == nWidth) ) { aBorderLine.InnerLineWidth = 0; aBorderLine.OuterLineWidth = 0; aBorderLine.LineDistance = 0; + aBorderLine.LineWidth = 0; } else if( bHasWidth ) { if( USHRT_MAX != nNamedWidth ) { - const sal_uInt16 *aWidths = bDouble ? aDBorderWidths - : aSBorderWidths; - sal_uInt16 nNWidth = nNamedWidth * 4; - aBorderLine.OuterLineWidth = aWidths[nNWidth+1]; - aBorderLine.InnerLineWidth = aWidths[nNWidth+2]; - aBorderLine.LineDistance = aWidths[nNWidth+3]; + aBorderLine.LineWidth = aBorderWidths[nNamedWidth]; } else { - lcl_frmitems_setXMLBorderWidth( aBorderLine, nWidth, bDouble ); + aBorderLine.LineWidth = nWidth; + lcl_frmitems_setXMLBorderStyle( aBorderLine, nStyle ); } } else { - lcl_frmitems_setXMLBorderWidth( aBorderLine, 0, bDouble ); + aBorderLine.LineWidth = 0; + lcl_frmitems_setXMLBorderStyle( aBorderLine, nStyle ); } // set color @@ -419,17 +308,11 @@ sal_Bool XMLBorderHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue { OUStringBuffer aOut; - table::BorderLine aBorderLine; + table::BorderLine2 aBorderLine; if(!(rValue >>= aBorderLine)) return sal_False; - sal_Int32 nWidth = aBorderLine.OuterLineWidth; - const sal_uInt16 nDistance = aBorderLine.LineDistance; - if( 0 != nDistance ) - { - nWidth += nDistance; - nWidth += aBorderLine.InnerLineWidth; - } + sal_Int32 nWidth = aBorderLine.LineWidth; if( nWidth == 0 ) { @@ -437,11 +320,46 @@ sal_Bool XMLBorderHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue } else { - rUnitConverter.convertMeasure( aOut, nWidth ); + rUnitConverter.convertMeasure( aOut, nWidth, + MAP_100TH_MM, MAP_POINT ); aOut.append( sal_Unicode( ' ' ) ); - aOut.append( GetXMLToken((0 == nDistance) ? XML_SOLID : XML_DOUBLE) ); + XMLTokenEnum eStyleToken = XML_SOLID; + switch ( aBorderLine.LineStyle ) + { + case API_LINE_DASHED: + eStyleToken = XML_DASHED; + break; + case API_LINE_DOTTED: + eStyleToken = XML_DOTTED; + break; + case API_LINE_DOUBLE: + case API_LINE_THINTHICK_SMALLGAP: + case API_LINE_THINTHICK_MEDIUMGAP: + case API_LINE_THINTHICK_LARGEGAP: + case API_LINE_THICKTHIN_SMALLGAP: + case API_LINE_THICKTHIN_MEDIUMGAP: + case API_LINE_THICKTHIN_LARGEGAP: + eStyleToken = XML_DOUBLE; + break; + case API_LINE_EMBOSSED: + eStyleToken = XML_RIDGE; + break; + case API_LINE_ENGRAVED: + eStyleToken = XML_GROOVE; + break; + case API_LINE_OUTSET: + eStyleToken = XML_OUTSET; + break; + case API_LINE_INSET: + eStyleToken = XML_INSET; + break; + case API_LINE_SOLID: + default: + break; + } + aOut.append( GetXMLToken( eStyleToken ) ); aOut.append( sal_Unicode( ' ' ) ); @@ -452,3 +370,5 @@ sal_Bool XMLBorderHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue return sal_True; } + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |