[Libreoffice-commits] core.git: compilerplugins/clang sc/source
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Sat Nov 24 20:24:18 UTC 2018
compilerplugins/clang/unusedenumconstants.readonly.results | 4 -
sc/source/filter/inc/unitconverter.hxx | 26 ++++-----
sc/source/filter/oox/drawingbase.cxx | 4 -
sc/source/filter/oox/drawingfragment.cxx | 2
sc/source/filter/oox/pagesettings.cxx | 12 ++--
sc/source/filter/oox/stylesbuffer.cxx | 2
sc/source/filter/oox/unitconverter.cxx | 35 ++++---------
sc/source/filter/oox/worksheethelper.cxx | 6 +-
8 files changed, 38 insertions(+), 53 deletions(-)
New commits:
commit 61d21e79e681753599b395f224ed48172e808bc4
Author: Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Thu Nov 22 15:47:57 2018 +0200
Commit: Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Sat Nov 24 21:23:54 2018 +0100
convert Unit to scoped enum
and drop unused UNIT_REFDEVX,UNIT_REFDEVY values
Change-Id: I4e516f2c51672f6541f3cf7c03a87aebc4a1f1f6
Reviewed-on: https://gerrit.libreoffice.org/63944
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
diff --git a/compilerplugins/clang/unusedenumconstants.readonly.results b/compilerplugins/clang/unusedenumconstants.readonly.results
index 88093da091b3..139c7cc8932d 100644
--- a/compilerplugins/clang/unusedenumconstants.readonly.results
+++ b/compilerplugins/clang/unusedenumconstants.readonly.results
@@ -1172,10 +1172,6 @@ sc/inc/types.hxx:56
enum ScFormulaVectorState FormulaVectorDisabledNotInSoftwareSubset
sc/inc/types.hxx:123
enum sc::ListenerGroupType Single
-sc/source/filter/inc/unitconverter.hxx:43
- enum oox::xls::Unit UNIT_REFDEVX
-sc/source/filter/inc/unitconverter.hxx:44
- enum oox::xls::Unit UNIT_REFDEVY
sc/source/filter/lotus/lotread.cxx:41
enum STATE S_WK1
sc/source/ui/inc/viewdata.hxx:43
diff --git a/sc/source/filter/inc/unitconverter.hxx b/sc/source/filter/inc/unitconverter.hxx
index 87d19577bec8..ec22a34a19de 100644
--- a/sc/source/filter/inc/unitconverter.hxx
+++ b/sc/source/filter/inc/unitconverter.hxx
@@ -22,6 +22,7 @@
#include <map>
#include <vector>
+#include <o3tl/enumarray.hxx>
#include "workbookhelper.hxx"
namespace com { namespace sun { namespace star {
@@ -32,20 +33,17 @@ namespace oox {
namespace xls {
/** Units supported by the UnitConverter class. */
-enum Unit
+enum class Unit
{
- UNIT_INCH, /// Inches.
- UNIT_POINT, /// Points.
- UNIT_TWIP, /// Twips (1/20 point).
- UNIT_EMU, /// English Metric Unit (1/360,000 cm).
- UNIT_SCREENX, /// Horizontal screen pixels.
- UNIT_SCREENY, /// Vertical screen pixels.
- UNIT_REFDEVX, /// Horizontal pixels in Calc reference device.
- UNIT_REFDEVY, /// Vertical pixels in Calc reference device.
- UNIT_DIGIT, /// Digit width of document default font.
- UNIT_SPACE, /// Space character width of document default font.
-
- UNIT_ENUM_SIZE
+ Inch, /// Inches.
+ Point, /// Points.
+ Twip, /// Twips (1/20 point).
+ Emu, /// English Metric Unit (1/360,000 cm).
+ ScreenX, /// Horizontal screen pixels.
+ ScreenY, /// Vertical screen pixels.
+ Digit, /// Digit width of document default font.
+ Space, /// Space character width of document default font.
+ LAST
};
/** Helper class that provides functions to convert values from and to
@@ -97,7 +95,7 @@ private:
void addErrorCode( sal_uInt8 nErrorCode, const OUString& rErrorCode );
private:
- std::vector<double> maCoeffs; /// Coefficients for unit conversion.
+ o3tl::enumarray<Unit, double> maCoeffs; /// Coefficients for unit conversion.
std::map<OUString, sal_uInt8> maOoxErrCodes; /// Maps error code strings to BIFF error constants.
sal_Int32 mnNullDate; /// Nulldate of this workbook (number of days since 0000-01-01).
};
diff --git a/sc/source/filter/oox/drawingbase.cxx b/sc/source/filter/oox/drawingbase.cxx
index 92723180ffd7..9b6e0aba70b1 100644
--- a/sc/source/filter/oox/drawingbase.cxx
+++ b/sc/source/filter/oox/drawingbase.cxx
@@ -278,8 +278,8 @@ EmuPoint ShapeAnchor::calcCellAnchorEmu( const CellAnchorModel& rModel ) const
case CellAnchorType::Pixel:
{
const UnitConverter& rUnitConv = getUnitConverter();
- aEmuPoint.X += static_cast< sal_Int64 >( rUnitConv.scaleValue( static_cast< double >( rModel.mnColOffset ), UNIT_SCREENX, UNIT_EMU ) );
- aEmuPoint.Y += static_cast< sal_Int64 >( rUnitConv.scaleValue( static_cast< double >( rModel.mnRowOffset ), UNIT_SCREENY, UNIT_EMU ) );
+ aEmuPoint.X += static_cast< sal_Int64 >( rUnitConv.scaleValue( static_cast< double >( rModel.mnColOffset ), Unit::ScreenX, Unit::Emu ) );
+ aEmuPoint.Y += static_cast< sal_Int64 >( rUnitConv.scaleValue( static_cast< double >( rModel.mnRowOffset ), Unit::ScreenY, Unit::Emu ) );
}
break;
}
diff --git a/sc/source/filter/oox/drawingfragment.cxx b/sc/source/filter/oox/drawingfragment.cxx
index 012cf615a342..70701e193c28 100644
--- a/sc/source/filter/oox/drawingfragment.cxx
+++ b/sc/source/filter/oox/drawingfragment.cxx
@@ -512,7 +512,7 @@ Reference< XShape > VmlDrawing::createAndInsertClientXShape( const ::oox::vml::S
instead the top border of the caption text. */
if( const ::oox::vml::TextFontModel* pFontModel = pTextBox ? pTextBox->getFirstFont() : nullptr )
{
- sal_Int32 nFontHeightHmm = getUnitConverter().scaleToMm100( pFontModel->monSize.get( 160 ), UNIT_TWIP );
+ sal_Int32 nFontHeightHmm = getUnitConverter().scaleToMm100( pFontModel->monSize.get( 160 ), Unit::Twip );
sal_Int32 nYDiff = ::std::min< sal_Int32 >( nFontHeightHmm / 2, aShapeRect.Y );
aShapeRect.Y -= nYDiff;
aShapeRect.Height += nYDiff;
diff --git a/sc/source/filter/oox/pagesettings.cxx b/sc/source/filter/oox/pagesettings.cxx
index bae8c61f6034..c650a538a497 100644
--- a/sc/source/filter/oox/pagesettings.cxx
+++ b/sc/source/filter/oox/pagesettings.cxx
@@ -965,12 +965,12 @@ void PageSettingsConverter::writePageSettingsProperties(
aPropMap.setProperty( PROP_CenterVertically, rModel.mbVerCenter);
aPropMap.setProperty( PROP_PrintGrid, (!bChartSheet && rModel.mbPrintGrid)); // no gridlines in chart sheets
aPropMap.setProperty( PROP_PrintHeaders, (!bChartSheet && rModel.mbPrintHeadings)); // no column/row headings in chart sheets
- aPropMap.setProperty( PROP_LeftMargin, rUnitConv.scaleToMm100( rModel.mfLeftMargin, UNIT_INCH ));
- aPropMap.setProperty( PROP_RightMargin, rUnitConv.scaleToMm100( rModel.mfRightMargin, UNIT_INCH ));
+ aPropMap.setProperty( PROP_LeftMargin, rUnitConv.scaleToMm100( rModel.mfLeftMargin, Unit::Inch ));
+ aPropMap.setProperty( PROP_RightMargin, rUnitConv.scaleToMm100( rModel.mfRightMargin, Unit::Inch ));
// #i23296# In Calc, "TopMargin" property is distance to top of header if enabled
- aPropMap.setProperty( PROP_TopMargin, rUnitConv.scaleToMm100( maHeaderData.mbHasContent ? rModel.mfHeaderMargin : rModel.mfTopMargin, UNIT_INCH ));
+ aPropMap.setProperty( PROP_TopMargin, rUnitConv.scaleToMm100( maHeaderData.mbHasContent ? rModel.mfHeaderMargin : rModel.mfTopMargin, Unit::Inch ));
// #i23296# In Calc, "BottomMargin" property is distance to bottom of footer if enabled
- aPropMap.setProperty( PROP_BottomMargin, rUnitConv.scaleToMm100( maFooterData.mbHasContent ? rModel.mfFooterMargin : rModel.mfBottomMargin, UNIT_INCH ));
+ aPropMap.setProperty( PROP_BottomMargin, rUnitConv.scaleToMm100( maFooterData.mbHasContent ? rModel.mfFooterMargin : rModel.mfBottomMargin, Unit::Inch ));
aPropMap.setProperty( PROP_HeaderIsOn, maHeaderData.mbHasContent);
aPropMap.setProperty( PROP_HeaderIsShared, maHeaderData.mbShareOddEven);
aPropMap.setProperty( PROP_HeaderIsDynamicHeight, maHeaderData.mbDynamicHeight);
@@ -1015,7 +1015,7 @@ void PageSettingsConverter::convertHeaderFooterData(
/* Calc contains distance between bottom of header and top of page
body in "HeaderBodyDistance" property, and distance between bottom
of page body and top of footer in "FooterBodyDistance" property */
- orHFData.mnBodyDist = getUnitConverter().scaleToMm100( fPageMargin - fContentMargin, UNIT_INCH ) - orHFData.mnHeight;
+ orHFData.mnBodyDist = getUnitConverter().scaleToMm100( fPageMargin - fContentMargin, Unit::Inch ) - orHFData.mnHeight;
/* #i23296# Distance less than 0 means, header or footer overlays page
body. As this is not possible in Calc, set fixed header or footer
height (crop header/footer) to get correct top position of page body. */
@@ -1042,7 +1042,7 @@ sal_Int32 PageSettingsConverter::writeHeaderFooter(
{
double fTotalHeight = mxHFParser->parse( xHFContent, rContent );
rPropSet.setProperty( nPropId, xHFContent );
- nHeight = getUnitConverter().scaleToMm100( fTotalHeight, UNIT_POINT );
+ nHeight = getUnitConverter().scaleToMm100( fTotalHeight, Unit::Point );
}
}
return nHeight;
diff --git a/sc/source/filter/oox/stylesbuffer.cxx b/sc/source/filter/oox/stylesbuffer.cxx
index 6d39a82d0bcd..9a21ff49fefa 100644
--- a/sc/source/filter/oox/stylesbuffer.cxx
+++ b/sc/source/filter/oox/stylesbuffer.cxx
@@ -1183,7 +1183,7 @@ void Alignment::finalizeImport()
/* indentation: expressed as number of blocks of 3 space characters in
OOXML. */
- sal_Int32 nIndent = getUnitConverter().scaleToMm100( 3.0 * maModel.mnIndent, UNIT_SPACE );
+ sal_Int32 nIndent = getUnitConverter().scaleToMm100( 3.0 * maModel.mnIndent, Unit::Space );
if( (0 <= nIndent) && (nIndent <= SAL_MAX_INT16) )
maApiData.mnIndent = static_cast< sal_Int16 >( nIndent );
diff --git a/sc/source/filter/oox/unitconverter.cxx b/sc/source/filter/oox/unitconverter.cxx
index 94ab7906a977..4baee2d4b08e 100644
--- a/sc/source/filter/oox/unitconverter.cxx
+++ b/sc/source/filter/oox/unitconverter.cxx
@@ -91,21 +91,18 @@ sal_Int32 lclGetDays( const util::Date& rDate )
UnitConverter::UnitConverter( const WorkbookHelper& rHelper ) :
WorkbookHelper( rHelper ),
- maCoeffs( UNIT_ENUM_SIZE, 1.0 ),
mnNullDate( lclGetDays( util::Date( 30, 12, 1899 ) ) )
{
// initialize constant and default coefficients
const DeviceInfo& rDeviceInfo = getBaseFilter().getGraphicHelper().getDeviceInfo();
- maCoeffs[ UNIT_INCH ] = MM100_PER_INCH;
- maCoeffs[ UNIT_POINT ] = MM100_PER_POINT;
- maCoeffs[ UNIT_TWIP ] = MM100_PER_TWIP;
- maCoeffs[ UNIT_EMU ] = MM100_PER_EMU;
- maCoeffs[ UNIT_SCREENX ] = (rDeviceInfo.PixelPerMeterX > 0) ? (100000.0 / rDeviceInfo.PixelPerMeterX) : 50.0;
- maCoeffs[ UNIT_SCREENY ] = (rDeviceInfo.PixelPerMeterY > 0) ? (100000.0 / rDeviceInfo.PixelPerMeterY) : 50.0;
- maCoeffs[ UNIT_REFDEVX ] = 12.5; // default: 1 px = 0.125 mm
- maCoeffs[ UNIT_REFDEVY ] = 12.5; // default: 1 px = 0.125 mm
- maCoeffs[ UNIT_DIGIT ] = 200.0; // default: 1 digit = 2 mm
- maCoeffs[ UNIT_SPACE ] = 100.0; // default 1 space = 1 mm
+ maCoeffs[ Unit::Inch ] = MM100_PER_INCH;
+ maCoeffs[ Unit::Point ] = MM100_PER_POINT;
+ maCoeffs[ Unit::Twip ] = MM100_PER_TWIP;
+ maCoeffs[ Unit::Emu ] = MM100_PER_EMU;
+ maCoeffs[ Unit::ScreenX ] = (rDeviceInfo.PixelPerMeterX > 0) ? (100000.0 / rDeviceInfo.PixelPerMeterX) : 50.0;
+ maCoeffs[ Unit::ScreenY ] = (rDeviceInfo.PixelPerMeterY > 0) ? (100000.0 / rDeviceInfo.PixelPerMeterY) : 50.0;
+ maCoeffs[ Unit::Digit ] = 200.0; // default: 1 digit = 2 mm
+ maCoeffs[ Unit::Space ] = 100.0; // default 1 space = 1 mm
// error code maps
addErrorCode( BIFF_ERR_NULL, "#NULL!" );
@@ -123,11 +120,6 @@ void UnitConverter::finalizeImport()
Reference< XDevice > xDevice( aDocProps.getAnyProperty( PROP_ReferenceDevice ), UNO_QUERY );
if( xDevice.is() )
{
- // get reference device metric first, needed to get character widths below
- DeviceInfo aInfo = xDevice->getInfo();
- maCoeffs[ UNIT_REFDEVX ] = 100000.0 / aInfo.PixelPerMeterX;
- maCoeffs[ UNIT_REFDEVY ] = 100000.0 / aInfo.PixelPerMeterY;
-
// get character widths from default font
if( const oox::xls::Font* pDefFont = getStyles().getDefaultFont().get() )
{
@@ -139,13 +131,13 @@ void UnitConverter::finalizeImport()
// get maximum width of all digits
sal_Int32 nDigitWidth = 0;
for( sal_Unicode cChar = '0'; cChar <= '9'; ++cChar )
- nDigitWidth = ::std::max( nDigitWidth, scaleToMm100( xFont->getCharWidth( cChar ), UNIT_TWIP ) );
+ nDigitWidth = ::std::max( nDigitWidth, scaleToMm100( xFont->getCharWidth( cChar ), Unit::Twip ) );
if( nDigitWidth > 0 )
- maCoeffs[ UNIT_DIGIT ] = nDigitWidth;
+ maCoeffs[ Unit::Digit ] = nDigitWidth;
// get width of space character
- sal_Int32 nSpaceWidth = scaleToMm100( xFont->getCharWidth( ' ' ), UNIT_TWIP );
+ sal_Int32 nSpaceWidth = scaleToMm100( xFont->getCharWidth( ' ' ), Unit::Twip );
if( nSpaceWidth > 0 )
- maCoeffs[ UNIT_SPACE ] = nSpaceWidth;
+ maCoeffs[ Unit::Space ] = nSpaceWidth;
}
}
}
@@ -241,8 +233,7 @@ void UnitConverter::addErrorCode( sal_uInt8 nErrorCode, const OUString& rErrorCo
double UnitConverter::getCoefficient( Unit eUnit ) const
{
- OSL_ENSURE( static_cast< size_t >( eUnit ) < UNIT_ENUM_SIZE, "UnitConverter::getCoefficient - invalid unit" );
- return maCoeffs[ static_cast< size_t >( eUnit ) ];
+ return maCoeffs[ eUnit ];
}
} // namespace xls
diff --git a/sc/source/filter/oox/worksheethelper.cxx b/sc/source/filter/oox/worksheethelper.cxx
index 3ce9e7699c2f..a9fcf454df8a 100644
--- a/sc/source/filter/oox/worksheethelper.cxx
+++ b/sc/source/filter/oox/worksheethelper.cxx
@@ -744,7 +744,7 @@ void WorksheetGlobals::setBaseColumnWidth( sal_Int32 nWidth )
// #i3006# add 5 pixels padding to the width
const UnitConverter& rUnitConv = getUnitConverter();
maDefColModel.mfWidth = rUnitConv.scaleFromMm100(
- rUnitConv.scaleToMm100( nWidth, UNIT_DIGIT ) + rUnitConv.scaleToMm100( 5, UNIT_SCREENX ), UNIT_DIGIT );
+ rUnitConv.scaleToMm100( nWidth, Unit::Digit ) + rUnitConv.scaleToMm100( 5, Unit::ScreenX ), Unit::Digit );
}
}
@@ -1176,7 +1176,7 @@ void WorksheetGlobals::convertColumns( OutlineLevelVec& orColLevels,
const ValueRange& rColRange, const ColumnModel& rModel )
{
// column width: convert 'number of characters' to column width in 1/100 mm
- sal_Int32 nWidth = getUnitConverter().scaleToMm100( rModel.mfWidth, UNIT_DIGIT );
+ sal_Int32 nWidth = getUnitConverter().scaleToMm100( rModel.mfWidth, Unit::Digit );
// macro sheets have double width
if( meSheetType == WorksheetType::Macro )
@@ -1236,7 +1236,7 @@ void WorksheetGlobals::convertRows( OutlineLevelVec& orRowLevels,
{
// row height: convert points to row height in 1/100 mm
double fHeight = (rModel.mfHeight >= 0.0) ? rModel.mfHeight : fDefHeight;
- sal_Int32 nHeight = getUnitConverter().scaleToMm100( fHeight, UNIT_POINT );
+ sal_Int32 nHeight = getUnitConverter().scaleToMm100( fHeight, Unit::Point );
SCROW nStartRow = rRowRange.mnFirst;
SCROW nEndRow = rRowRange.mnLast;
SCTAB nTab = getSheetIndex();
More information about the Libreoffice-commits
mailing list