diff options
author | Caolán McNamara <caolanm@redhat.com> | 2018-03-16 12:03:58 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2018-03-16 21:29:45 +0100 |
commit | ca1ed645036cab9ba5e94a9d2e22ef8110e852e0 (patch) | |
tree | 4f5978e837111a395f7f974ee65e73ea270b78a2 /vcl | |
parent | d416fa9a212e0421a7c925507ddee07132f3cab3 (diff) |
use digit width instead of char width
its the same across backends
Change-Id: I37c83cbf1139babcd014c7cfdee06a13bea845c7
Reviewed-on: https://gerrit.libreoffice.org/51423
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/source/app/salvtables.cxx | 4 | ||||
-rw-r--r-- | vcl/source/outdev/text.cxx | 8 | ||||
-rw-r--r-- | vcl/source/window/builder.cxx | 2 | ||||
-rw-r--r-- | vcl/unx/gtk3/gtk3gtkinst.cxx | 5 |
4 files changed, 13 insertions, 6 deletions
diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx index ffcb468a458e..ed2f3b2d08cf 100644 --- a/vcl/source/app/salvtables.cxx +++ b/vcl/source/app/salvtables.cxx @@ -238,9 +238,9 @@ public: return m_xWidget->get_preferred_size(); } - virtual float get_approximate_char_width() const override + virtual float get_approximate_digit_width() const override { - return m_xWidget->approximate_char_width(); + return m_xWidget->approximate_digit_width(); } virtual int get_text_height() const override diff --git a/vcl/source/outdev/text.cxx b/vcl/source/outdev/text.cxx index f51dbabc558c..204feccc9da6 100644 --- a/vcl/source/outdev/text.cxx +++ b/vcl/source/outdev/text.cxx @@ -935,9 +935,17 @@ long OutputDevice::GetTextHeight() const float OutputDevice::approximate_char_width() const { + //note pango uses "The quick brown fox jumps over the lazy dog." for english + //and has a bunch of per-language strings which corresponds somewhat with + //makeRepresentativeText in include/svtools/sampletext.hxx return GetTextWidth("aemnnxEM") / 8.0; } +float OutputDevice::approximate_digit_width() const +{ + return GetTextWidth("0123456789") / 10.0; +} + void OutputDevice::DrawTextArray( const Point& rStartPt, const OUString& rStr, const long* pDXAry, sal_Int32 nIndex, sal_Int32 nLen, SalLayoutFlags flags ) diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx index 064c91a825f8..1c1f63e7cdf6 100644 --- a/vcl/source/window/builder.cxx +++ b/vcl/source/window/builder.cxx @@ -173,7 +173,7 @@ namespace weld m_xSpinButton->get_range(min, max); auto width = std::max(m_xSpinButton->get_pixel_size(format_number(min)).Width(), m_xSpinButton->get_pixel_size(format_number(max)).Width()); - int chars = ceil(width / m_xSpinButton->get_approximate_char_width()); + int chars = ceil(width / m_xSpinButton->get_approximate_digit_width()); m_xSpinButton->set_width_chars(chars); } diff --git a/vcl/unx/gtk3/gtk3gtkinst.cxx b/vcl/unx/gtk3/gtk3gtkinst.cxx index 3b54fbbb3415..e249a21dc5aa 100644 --- a/vcl/unx/gtk3/gtk3gtkinst.cxx +++ b/vcl/unx/gtk3/gtk3gtkinst.cxx @@ -1238,17 +1238,16 @@ public: return Size(size.width, size.height); } - virtual float get_approximate_char_width() const override + virtual float get_approximate_digit_width() const override { PangoContext* pContext = gtk_widget_get_pango_context(m_pWidget); PangoFontMetrics* pMetrics = pango_context_get_metrics(pContext, pango_context_get_font_description(pContext), pango_context_get_language(pContext)); - float nCharWidth = pango_font_metrics_get_approximate_char_width(pMetrics); float nDigitWidth = pango_font_metrics_get_approximate_digit_width(pMetrics); pango_font_metrics_unref(pMetrics); - return std::max(nCharWidth, nDigitWidth) / PANGO_SCALE; + return nDigitWidth / PANGO_SCALE; } virtual int get_text_height() const override |