summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Mohrhard <markus.mohrhard@googlemail.com>2015-05-20 03:59:49 +0200
committerMarkus Mohrhard <markus.mohrhard@googlemail.com>2015-05-20 04:04:13 +0200
commit16726a1b37df8bdcae02b3c7699df814977222bd (patch)
tree711f1741aa1921069ae81864b8c643f98cc052b0
parent1d2d037b4defa775b164880b56732af2a837f254 (diff)
better algorithm for OOXML column width import, tdf#91267
This patch contains a magic factor of 1.047 that is necessary as the set value and retrieved value are not the same. When we ahve too much time (propably never) we should explore why the value that we set for the column width is not equal to the one that we see on the screen. Change-Id: I317127ea5b8af2d5e8386758e66907a44fe58579
-rw-r--r--sc/source/filter/oox/worksheethelper.cxx23
1 files changed, 22 insertions, 1 deletions
diff --git a/sc/source/filter/oox/worksheethelper.cxx b/sc/source/filter/oox/worksheethelper.cxx
index aaa45a9b79ba..3dfbf8a3b663 100644
--- a/sc/source/filter/oox/worksheethelper.cxx
+++ b/sc/source/filter/oox/worksheethelper.cxx
@@ -78,6 +78,7 @@
#include <svl/stritem.hxx>
#include <editeng/editobj.hxx>
#include <editeng/flditem.hxx>
+#include <vcl/virdev.hxx>
namespace oox {
namespace xls {
@@ -1166,11 +1167,31 @@ void WorksheetGlobals::convertColumns()
convertOutlines( aColLevels, nMaxCol + 1, 0, false, false );
}
+namespace {
+
+sal_Int32 getColumnWidth(UnitConverter& rConverter, double nWidth)
+{
+ double nCoeff = rConverter.getCoefficient(UNIT_DIGIT);
+ VirtualDevice aDev;
+
+ long nPixel = aDev.LogicToPixel(Point(nCoeff, 0), MapMode(MAP_100TH_MM)).getX();
+
+
+ // the 1.047 has been experimentally chosen based on measurements witha screen ruler
+ // TODO: fix the display of cells so that it no longer requires this hack
+ // algorithm from OOXML spec part1: 18.3.1.13
+ sal_Int32 nColWidthPixel= std::floor(((256*nWidth + std::floor(128.0/nPixel))/256.0)*nPixel) * 1.047;
+
+ return aDev.PixelToLogic(Point(nColWidthPixel, 0), MapMode(MAP_100TH_MM)).getX();
+}
+
+}
+
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 = getColumnWidth(getUnitConverter(), rModel.mfWidth);
// macro sheets have double width
if( meSheetType == SHEETTYPE_MACROSHEET )
nWidth *= 2;