writerfilter/source/ooxml/OOXMLPropertySet.cxx | 37 ++++++++----------------- 1 file changed, 12 insertions(+), 25 deletions(-)
New commits: commit fd19637cfd4099a96661a071939576bc7db4946a Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Sat Apr 13 16:47:37 2024 +0500 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Sat Apr 13 15:23:36 2024 +0200 Simplify a bit, and use more o3tl::convert Change-Id: I30f619b81d831db9c1e212a1588d5696b9ad3dd0 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166048 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> diff --git a/writerfilter/source/ooxml/OOXMLPropertySet.cxx b/writerfilter/source/ooxml/OOXMLPropertySet.cxx index 2c760519b69f..f29efe875aee 100644 --- a/writerfilter/source/ooxml/OOXMLPropertySet.cxx +++ b/writerfilter/source/ooxml/OOXMLPropertySet.cxx @@ -601,41 +601,28 @@ OOXMLUniversalMeasureValue::OOXMLUniversalMeasureValue(std::string_view pValue, { double val = o3tl::toDouble(pValue); // will ignore the trailing unit - int nLen = pValue.size(); - if (nLen > 2 && - pValue[nLen-2] == 'p' && - pValue[nLen-1] == 't') + if (pValue.ends_with("pt")) { - mnValue = static_cast<int>(val * npPt); + val *= npPt; } - else if (nLen > 2 && - pValue[nLen - 2] == 'c' && - pValue[nLen - 1] == 'm') + else if (pValue.ends_with("cm")) { - mnValue = static_cast<int>(val * npPt * 72 / 2.54); + val = o3tl::convert(val, o3tl::Length::cm, o3tl::Length::pt) * npPt; } - else if (nLen > 2 && - pValue[nLen - 2] == 'm' && - pValue[nLen - 1] == 'm') + else if (pValue.ends_with("mm")) { - mnValue = static_cast<int>(val * npPt * 72 / 25.4); + val = o3tl::convert(val, o3tl::Length::mm, o3tl::Length::pt) * npPt; } - else if (nLen > 2 && - pValue[nLen - 2] == 'i' && - pValue[nLen - 1] == 'n') + else if (pValue.ends_with("in")) { - mnValue = static_cast<int>(val * npPt * 72); + val = o3tl::convert(val, o3tl::Length::in, o3tl::Length::pt) * npPt; } - else if (nLen > 2 && - pValue[nLen - 2] == 'p' && - ( pValue[nLen - 1] == 'c' || pValue[nLen - 1] == 'i' )) + else if (pValue.ends_with("pc") || pValue.ends_with("pi")) { - mnValue = static_cast<int>(val * npPt * 12); - } - else - { - mnValue = static_cast<int>(val); + val = o3tl::convert(val, o3tl::Length::pc, o3tl::Length::pt) * npPt; } + + mnValue = std::round(val); } OOXMLUniversalMeasureValue::~OOXMLUniversalMeasureValue()