diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2021-02-24 10:19:47 +0100 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2021-02-24 13:49:39 +0100 |
commit | 16901e4ccad95d55d4ae0fa2d6f6103b4177592e (patch) | |
tree | 52a37b9c42063e1f88dd2a292301b4cb89158e25 | |
parent | 7400372efb3d279225a966a355644d2a3e7d42c3 (diff) |
Simplify static string generation
Change-Id: I838d3900a6f3ba28fd30cd2e3ec7a7f74a7736b4
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/111431
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
-rw-r--r-- | vcl/source/font/font.cxx | 23 |
1 files changed, 8 insertions, 15 deletions
diff --git a/vcl/source/font/font.cxx b/vcl/source/font/font.cxx index 9c5204d190f5..bdc2c8f0095d 100644 --- a/vcl/source/font/font.cxx +++ b/vcl/source/font/font.cxx @@ -32,6 +32,7 @@ #include <sft.hxx> #include <algorithm> +#include <numeric> #include <string_view> #include <rtl/instance.hxx> @@ -390,23 +391,15 @@ tools::Long Font::GetOrCalculateAverageFontWidth() const // as close as possible (discussion see documentation in task), // so calculate it. For discussion of method used, see task // buffer measure string creation, will always use the same - static OUString aMeasureString; - - if(!aMeasureString.getLength()) - { - const std::size_t nSize(127 - 32); - std::array<sal_Unicode, nSize> aArray; - - for(sal_Unicode a(0); a < nSize; a++) - { - aArray[a] = a + 32; - } - - aMeasureString = OUString(aArray.data()); - } + static const OUStringLiteral aMeasureString = [] { // not constexpr yet because of std::iota + sal_Unicode aArray[127 - 32 + 1]; + std::iota(aArray, aArray + SAL_N_ELEMENTS(aArray) - 1, 32); + aArray[SAL_N_ELEMENTS(aArray) - 1] = u'\0'; + return OUStringLiteral(aArray); + }(); const double fAverageFontWidth( - pTempVirtualDevice->GetTextWidth(aMeasureString, aMeasureString.getLength()) / + pTempVirtualDevice->GetTextWidth(aMeasureString) / static_cast<double>(aMeasureString.getLength())); const_cast<Font*>(this)->mpImplFont->SetCalculatedAverageFontWidth(basegfx::fround(fAverageFontWidth)); #endif |