summaryrefslogtreecommitdiff
path: root/writerfilter
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2018-10-16 18:00:45 +0300
committerMiklos Vajna <vmiklos@collabora.co.uk>2018-10-17 18:02:33 +0200
commit2c541ea901369f0267921e1e73de0d74dd2a8fc9 (patch)
tree79c79bf07982d3872632ee63c4b916ccb2f27d10 /writerfilter
parent7d17e8e1798b7120b9e8559d042de2afc0a078e3 (diff)
tdf#119885: OOXML import: try to get cell paddings as Word does
Change-Id: I7abd715b6bb71d6e2e01939c4cf849d94eb6a103 Reviewed-on: https://gerrit.libreoffice.org/61843 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/61877 Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Diffstat (limited to 'writerfilter')
-rw-r--r--writerfilter/source/dmapper/DomainMapperTableHandler.cxx54
1 files changed, 44 insertions, 10 deletions
diff --git a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx
index 40a9e9bbdb62..e8f44771b030 100644
--- a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx
+++ b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx
@@ -295,8 +295,6 @@ void lcl_extractHoriOrient(std::vector<beans::PropertyValue>& rFrameProperties,
}
}
-}
-
void lcl_DecrementHoriOrientPosition(std::vector<beans::PropertyValue>& rFrameProperties, sal_Int32 nAmount)
{
// Shifts the frame left by the given value.
@@ -312,6 +310,42 @@ void lcl_DecrementHoriOrientPosition(std::vector<beans::PropertyValue>& rFramePr
}
}
+void lcl_adjustBorderDistance(TableInfo& rInfo, const table::BorderLine2& rLeftBorder,
+ const table::BorderLine2& rRightBorder)
+{
+ // MS Word appears to do these things to adjust the cell horizontal area:
+ //
+ // bll = left borderline width
+ // blr = right borderline width
+ // cea = cell's edit area rectangle
+ // cea_w = cea width
+ // cml = cell's left margin (padding) defined in cell settings
+ // cmr = cell's right margin (padding) defined in cell settings
+ // cw = cell width (distance between middles of left borderline and right borderline)
+ // pad_l = actual cea left padding = (its left pos relative to middle of bll)
+ // pad_r = actual cea right padding = abs (its right pos relative to middle of blr)
+ //
+ // pad_l = max(bll/2, cml) -> cea does not overlap left borderline
+ // cea_w = cw-max(pad_l+blr/2, cml+cmr) -> cea does not overlap right borderline
+ // pad_r = max(pad_l+blr/2, cml+cmr) - pad_l
+ //
+ // It means that e.g. for border widths of 6 pt (~2.12 mm), left margin 0 mm, and right margin
+ // 2 mm, actual left and right margins will (unexpectedly) coincide with inner edges of cell's
+ // borderlines - the right margin won't create spacing between right of edit rectangle and the
+ // inner edge of right borderline.
+
+ const sal_Int32 nActualL
+ = std::max<sal_Int32>(rLeftBorder.LineWidth / 2, rInfo.nLeftBorderDistance);
+ const sal_Int32 nActualR
+ = std::max<sal_Int32>(nActualL + rRightBorder.LineWidth / 2,
+ rInfo.nLeftBorderDistance + rInfo.nRightBorderDistance)
+ - nActualL;
+ rInfo.nLeftBorderDistance = nActualL;
+ rInfo.nRightBorderDistance = nActualR;
+}
+
+}
+
TableStyleSheetEntry * DomainMapperTableHandler::endTableGetTableStyle(TableInfo & rInfo, std::vector<beans::PropertyValue>& rFrameProperties)
{
// will receive the table style if any
@@ -489,7 +523,7 @@ TableStyleSheetEntry * DomainMapperTableHandler::endTableGetTableStyle(TableInfo
//table border settings
table::TableBorder aTableBorder;
- table::BorderLine2 aBorderLine, aLeftBorder;
+ table::BorderLine2 aBorderLine, aLeftBorder, aRightBorder;
if (lcl_extractTableBorderProperty(m_aTableProperties, PROP_TOP_BORDER, rInfo, aBorderLine))
{
@@ -506,17 +540,15 @@ TableStyleSheetEntry * DomainMapperTableHandler::endTableGetTableStyle(TableInfo
aTableBorder.LeftLine = aLeftBorder;
aTableBorder.IsLeftLineValid = true;
// Only top level table position depends on border width
- if (rInfo.nNestLevel == 1)
+ if (rInfo.nNestLevel == 1 && !rFrameProperties.empty())
{
- if (rFrameProperties.empty())
- rInfo.nLeftBorderDistance += aLeftBorder.LineWidth * 0.5;
- else
- lcl_DecrementHoriOrientPosition(rFrameProperties, aLeftBorder.LineWidth * 0.5);
+ lcl_DecrementHoriOrientPosition(rFrameProperties, aLeftBorder.LineWidth * 0.5);
}
}
- if (lcl_extractTableBorderProperty(m_aTableProperties, PROP_RIGHT_BORDER, rInfo, aBorderLine))
+ if (lcl_extractTableBorderProperty(m_aTableProperties, PROP_RIGHT_BORDER, rInfo,
+ aRightBorder))
{
- aTableBorder.RightLine = aBorderLine;
+ aTableBorder.RightLine = aRightBorder;
aTableBorder.IsRightLineValid = true;
}
if (lcl_extractTableBorderProperty(m_aTableProperties, META_PROP_HORIZONTAL_BORDER, rInfo, aBorderLine))
@@ -544,6 +576,8 @@ TableStyleSheetEntry * DomainMapperTableHandler::endTableGetTableStyle(TableInfo
// so table's position depends on table's cells margin
// - nested tables: the goal is to have left-most border starting at table_indent pos
+ lcl_adjustBorderDistance(rInfo, aLeftBorder, aRightBorder);
+
// tdf#106742: since MS Word 2013 (compatibilityMode >= 15), top-level tables are handled the same as nested tables;
// this is also the default behavior in LO when DOCX doesn't define "compatibilityMode" option
sal_Int32 nMode = m_rDMapper_Impl.GetSettingsTable()->GetWordCompatibilityMode();