diff options
author | Caolán McNamara <caolanm@redhat.com> | 2021-09-29 15:13:28 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2021-10-04 13:21:44 +0200 |
commit | feb1cdd5bcbdf8dfe350551ab84d89a43d6fde8c (patch) | |
tree | 3ef914cb5bf5db1874c7e381d1c68e2b046edf86 | |
parent | tdf#144674 no context menu in SQL Query (diff) | |
download | core-feb1cdd5bcbdf8dfe350551ab84d89a43d6fde8c.tar.gz core-feb1cdd5bcbdf8dfe350551ab84d89a43d6fde8c.zip |
tdf#141633 set correct font sizes in tableview child widgets
Change-Id: Ic96a0ad8203bf3903546c0c2f07d96254ca01e4c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122832
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
(cherry picked from commit 61050c6d7b8bceef2704eba0bfe4473ee75e669d)
contains...
Related: tdf#141633 PointFont gets overwritten by ControlFont
Change-Id: I26ffffe7917d109ddc61fd2d2646db0988937c7c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122827
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
(cherry picked from commit 4e2306a5e336e2b43759c9712535626d0f2c168f)
Related: tdf#141633 support setting a custom font for TextView
Change-Id: I4c27a21c5c682fc73c37594749627e4cc7c0822d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122833
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
(cherry picked from commit 4d445ac9aa43b3399a579e3dbb1aac94507c9520)
tdf#141633 multiple line entry font size/zoom not taking effect
The "sample db" example (Mockup.odb) has multiline entries used in its
"Journal Entry" column. Those are painted by taking snapshots of a
never-really-shown textview widget. But the textview is always drawn
using its original default font size and changing the page zoom and/or
font size had no effect on the size of text in the "Journal Entry"
column.
explicitly emit style_updated to get the GtkTextView to sync its font
size from the css changed by the set_font
Change-Id: Ic7d644b13c28f30a2c646b9d4098ea6e7f0dab81
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122889
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
(cherry picked from commit 36d5e26549b273118cea8969c43ef5ad3845f8df)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/123041
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
-rw-r--r-- | include/svtools/editbrowsebox.hxx | 12 | ||||
-rw-r--r-- | include/vcl/weld.hxx | 3 | ||||
-rw-r--r-- | svtools/source/brwbox/ebbcontrols.cxx | 4 | ||||
-rw-r--r-- | svx/source/fmcomp/gridcell.cxx | 30 | ||||
-rw-r--r-- | vcl/inc/salvtables.hxx | 2 | ||||
-rw-r--r-- | vcl/source/app/salvtables.cxx | 12 | ||||
-rw-r--r-- | vcl/unx/gtk3/gtkinst.cxx | 121 |
7 files changed, 169 insertions, 15 deletions
diff --git a/include/svtools/editbrowsebox.hxx b/include/svtools/editbrowsebox.hxx index c012414ded51..a758d1142a88 100644 --- a/include/svtools/editbrowsebox.hxx +++ b/include/svtools/editbrowsebox.hxx @@ -172,6 +172,8 @@ namespace svt virtual bool ProcessKey(const KeyEvent& rKEvt); + virtual void SetPointFont(const vcl::Font& rFont); + // chain after the FocusInHdl void SetFocusInHdl(const Link<LinkParamNone*,void>& rHdl) { @@ -224,6 +226,11 @@ namespace svt m_pEntry->set_editable(!bReadOnly); } + virtual void SetPointFont(const vcl::Font& rFont) override + { + m_pEntry->set_font(rFont); + } + virtual void dispose() override; weld::Entry& get_widget() { return *m_pEntry; } @@ -388,6 +395,11 @@ namespace svt m_xWidget->set_editable(!bReadOnly); } + virtual void SetPointFont(const vcl::Font& rFont) override + { + m_xWidget->set_font(rFont); + } + virtual void GetFocus() override; virtual void dispose() override; diff --git a/include/vcl/weld.hxx b/include/vcl/weld.hxx index 4546da76b18e..9038351c2715 100644 --- a/include/vcl/weld.hxx +++ b/include/vcl/weld.hxx @@ -2133,6 +2133,9 @@ public: return get_text_height() * nRows; } + // font size is in points, not pixels, e.g. see Window::[G]etPointFont + virtual void set_font(const vcl::Font& rFont) = 0; + /* Typically you want to avoid the temptation of customizing font colors diff --git a/svtools/source/brwbox/ebbcontrols.cxx b/svtools/source/brwbox/ebbcontrols.cxx index 04ba4b489f08..de2cf8ffb021 100644 --- a/svtools/source/brwbox/ebbcontrols.cxx +++ b/svtools/source/brwbox/ebbcontrols.cxx @@ -361,6 +361,10 @@ namespace svt return static_cast<BrowserDataWin*>(GetParent())->GetParent()->ProcessKey(rKEvt); } + void ControlBase::SetPointFont(const vcl::Font& /*rFont*/) + { + } + IMPL_LINK(ControlBase, KeyInputHdl, const KeyEvent&, rKEvt, bool) { return ProcessKey(rKEvt); diff --git a/svx/source/fmcomp/gridcell.cxx b/svx/source/fmcomp/gridcell.cxx index 3e5796bb5fb6..e1cf6d4e0570 100644 --- a/svx/source/fmcomp/gridcell.cxx +++ b/svx/source/fmcomp/gridcell.cxx @@ -59,6 +59,7 @@ #include <svx/dialmgr.hxx> #include <toolkit/helper/vclunohelper.hxx> #include <tools/debug.hxx> +#include <tools/fract.hxx> #include <tools/diagnose_ex.h> #include <vcl/settings.hxx> #include <vcl/svapp.hxx> @@ -693,11 +694,11 @@ bool DbCellControl::Commit() void DbCellControl::ImplInitWindow( vcl::Window const & rParent, const InitWindowFacet _eInitWhat ) { - vcl::Window* pWindows[] = { m_pPainter, m_pWindow }; + svt::ControlBase* pWindows[] = { m_pPainter, m_pWindow }; if (_eInitWhat & InitWindowFacet::WritingMode) { - for (vcl::Window* pWindow : pWindows) + for (svt::ControlBase* pWindow : pWindows) { if (pWindow) pWindow->EnableRTL(rParent.IsRTLEnabled()); @@ -706,26 +707,29 @@ void DbCellControl::ImplInitWindow( vcl::Window const & rParent, const InitWindo if (_eInitWhat & InitWindowFacet::Font) { - for (vcl::Window* pWindow : pWindows) + const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings(); + const Fraction& rZoom = rParent.GetZoom(); + + for (svt::ControlBase* pWindow : pWindows) { if (!pWindow) continue; - pWindow->SetZoom(rParent.GetZoom()); - - const StyleSettings& rStyleSettings = pWindow->GetSettings().GetStyleSettings(); vcl::Font aFont = rStyleSettings.GetFieldFont(); aFont.SetTransparent(isTransparent()); if (rParent.IsControlFont()) - { - pWindow->SetControlFont(rParent.GetControlFont()); aFont.Merge(rParent.GetControlFont()); + + if (rZoom.GetNumerator() != rZoom.GetDenominator()) + { + Size aSize = aFont.GetFontSize(); + aSize.setWidth(std::round(double(aSize.Width() * rZoom))); + aSize.setHeight(std::round(double(aSize.Height() * rZoom))); + aFont.SetFontSize(aSize); } - else - pWindow->SetControlFont(); - pWindow->SetZoomedPointFont(*pWindow->GetOutDev(), aFont); // FIXME RenderContext + pWindow->SetPointFont(aFont); } } @@ -736,7 +740,7 @@ void DbCellControl::ImplInitWindow( vcl::Window const & rParent, const InitWindo bool bTextLineColor = rParent.IsTextLineColor(); Color aTextLineColor(rParent.GetTextLineColor()); - for (vcl::Window* pWindow : pWindows) + for (svt::ControlBase* pWindow : pWindows) { if (pWindow) { @@ -758,7 +762,7 @@ void DbCellControl::ImplInitWindow( vcl::Window const & rParent, const InitWindo if (rParent.IsControlBackground()) { Color aColor(rParent.GetControlBackground()); - for (vcl::Window* pWindow : pWindows) + for (svt::ControlBase* pWindow : pWindows) { if (pWindow) { diff --git a/vcl/inc/salvtables.hxx b/vcl/inc/salvtables.hxx index d3789a9e75d8..1574a3a144c6 100644 --- a/vcl/inc/salvtables.hxx +++ b/vcl/inc/salvtables.hxx @@ -1298,6 +1298,8 @@ public: virtual void set_monospace(bool bMonospace) override; + virtual void set_font(const vcl::Font& rFont) override; + virtual void set_font_color(const Color& rColor) override; virtual void connect_cursor_position(const Link<TextView&, void>& rLink) override; diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx index 3638db349676..3efdb345e1ea 100644 --- a/vcl/source/app/salvtables.cxx +++ b/vcl/source/app/salvtables.cxx @@ -3333,6 +3333,7 @@ void SalInstanceEntry::set_message_type(weld::EntryMessageType eType) void SalInstanceEntry::set_font(const vcl::Font& rFont) { m_xEntry->SetPointFont(*m_xEntry->GetOutDev(), rFont); + m_xEntry->SetControlFont(rFont); m_xEntry->Invalidate(); } @@ -5808,8 +5809,7 @@ void SalInstanceTextView::set_monospace(bool bMonospace) else aFont = Application::GetSettings().GetStyleSettings().GetFieldFont(); aFont.SetFontHeight(aOrigFont.GetFontHeight()); - m_xTextView->SetFont(aFont); - m_xTextView->SetControlFont(aFont); + set_font(aFont); } void SalInstanceTextView::set_font_color(const Color& rColor) @@ -5820,6 +5820,13 @@ void SalInstanceTextView::set_font_color(const Color& rColor) m_xTextView->SetControlForeground(); } +void SalInstanceTextView::set_font(const vcl::Font& rFont) +{ + m_xTextView->SetFont(rFont); + m_xTextView->SetControlFont(rFont); + m_xTextView->Invalidate(); +} + void SalInstanceTextView::connect_cursor_position(const Link<TextView&, void>& rLink) { assert(!m_aCursorPositionHdl.IsSet()); @@ -6559,6 +6566,7 @@ public: { Edit& rEntry = m_pEntry->getEntry(); rEntry.SetPointFont(*rEntry.GetOutDev(), rFont); + rEntry.SetControlFont(rFont); rEntry.Invalidate(); } diff --git a/vcl/unx/gtk3/gtkinst.cxx b/vcl/unx/gtk3/gtkinst.cxx index 213ccfb8624c..f9d079b6b734 100644 --- a/vcl/unx/gtk3/gtkinst.cxx +++ b/vcl/unx/gtk3/gtkinst.cxx @@ -3214,6 +3214,16 @@ private: GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); } +#if !GTK_CHECK_VERSION(4, 0, 0) + static void update_style(GtkWidget* pWidget, gpointer pData) + { + if (GTK_IS_CONTAINER(pWidget)) + gtk_container_foreach(GTK_CONTAINER(pWidget), update_style, pData); + GtkWidgetClass* pWidgetClass = GTK_WIDGET_GET_CLASS(pWidget); + pWidgetClass->style_updated(pWidget); + } +#endif + public: GtkInstanceWidget(GtkWidget* pWidget, GtkInstanceBuilder* pBuilder, bool bTakeOwnership) : m_pWidget(pWidget) @@ -4173,7 +4183,20 @@ public: bool bAlreadyMapped = gtk_widget_get_mapped(m_pWidget); if (!bAlreadyRealized) + { +#if !GTK_CHECK_VERSION(4, 0, 0) + /* + tdf#141633 The "sample db" example (Mockup.odb) has multiline + entries used in its "Journal Entry" column. Those are painted by + taking snapshots of a never-really-shown textview widget. + Without this style_updated then the textview is always drawn + using its original default font size and changing the page zoom + has no effect on the size of text in the "Journal Entry" column. + */ + update_style(m_pWidget, nullptr); +#endif gtk_widget_realize(m_pWidget); + } if (!bAlreadyVisible) gtk_widget_show(m_pWidget); if (!bAlreadyMapped) @@ -8573,6 +8596,80 @@ public: } }; +OUString vcl_font_to_css(const vcl::Font& rFont) +{ + OUStringBuffer sCSS; + sCSS.append("font-family: \"" + rFont.GetFamilyName() + "\"; "); + sCSS.append("font-size: " + OUString::number(rFont.GetFontSize().Height()) + "pt; "); + switch (rFont.GetItalic()) + { + case ITALIC_NONE: + sCSS.append("font-style: normal; "); + break; + case ITALIC_NORMAL: + sCSS.append("font-style: italic; "); + break; + case ITALIC_OBLIQUE: + sCSS.append("font-style: oblique; "); + break; + default: + break; + } + switch (rFont.GetWeight()) + { + case WEIGHT_ULTRALIGHT: + sCSS.append("font-weight: 200; "); + break; + case WEIGHT_LIGHT: + sCSS.append("font-weight: 300; "); + break; + case WEIGHT_NORMAL: + sCSS.append("font-weight: 400; "); + break; + case WEIGHT_BOLD: + sCSS.append("font-weight: 700; "); + break; + case WEIGHT_ULTRABOLD: + sCSS.append("font-weight: 800; "); + break; + default: + break; + } + switch (rFont.GetWidthType()) + { + case WIDTH_ULTRA_CONDENSED: + sCSS.append("font-stretch: ultra-condensed; "); + break; + case WIDTH_EXTRA_CONDENSED: + sCSS.append("font-stretch: extra-condensed; "); + break; + case WIDTH_CONDENSED: + sCSS.append("font-stretch: condensed; "); + break; + case WIDTH_SEMI_CONDENSED: + sCSS.append("font-stretch: semi-condensed; "); + break; + case WIDTH_NORMAL: + sCSS.append("font-stretch: normal; "); + break; + case WIDTH_SEMI_EXPANDED: + sCSS.append("font-stretch: semi-expanded; "); + break; + case WIDTH_EXPANDED: + sCSS.append("font-stretch: expanded; "); + break; + case WIDTH_EXTRA_EXPANDED: + sCSS.append("font-stretch: extra-expanded; "); + break; + case WIDTH_ULTRA_EXPANDED: + sCSS.append("font-stretch: ultra-expanded; "); + break; + default: + break; + } + return sCSS.toString(); +} + void update_attr_list(PangoAttrList* pAttrList, const vcl::Font& rFont) { pango_attr_list_change(pAttrList, pango_attr_family_new(OUStringToOString(rFont.GetFamilyName(), RTL_TEXTENCODING_UTF8).getStr())); @@ -16041,6 +16138,8 @@ private: GtkTextBuffer* m_pTextBuffer; GtkAdjustment* m_pVAdjustment; GtkCssProvider* m_pFgCssProvider; + GtkCssProvider* m_pFontCssProvider; + std::optional<vcl::Font> m_xFont; int m_nMaxTextLength; gulong m_nChangedSignalId; // we don't disable/enable this one, it's to implement max-length gulong m_nInsertTextSignalId; @@ -16132,6 +16231,7 @@ public: , m_pTextBuffer(gtk_text_view_get_buffer(pTextView)) , m_pVAdjustment(gtk_scrollable_get_vadjustment(GTK_SCROLLABLE(pTextView))) , m_pFgCssProvider(nullptr) + , m_pFontCssProvider(nullptr) , m_nMaxTextLength(0) , m_nChangedSignalId(g_signal_connect(m_pTextBuffer, "changed", G_CALLBACK(signalChanged), this)) , m_nInsertTextSignalId(g_signal_connect_after(m_pTextBuffer, "insert-text", G_CALLBACK(signalInserText), this)) @@ -16246,6 +16346,27 @@ public: GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); } + virtual vcl::Font get_font() override + { + if (m_xFont) + return *m_xFont; + return GtkInstanceWidget::get_font(); + } + + virtual void set_font(const vcl::Font& rFont) override + { + m_xFont = rFont; + GtkStyleContext *pWidgetContext = gtk_widget_get_style_context(GTK_WIDGET(m_pTextView)); + if (m_pFontCssProvider) + gtk_style_context_remove_provider(pWidgetContext, GTK_STYLE_PROVIDER(m_pFontCssProvider)); + m_pFontCssProvider = gtk_css_provider_new(); + OUString aBuffer = "textview { " + vcl_font_to_css(rFont) + "}"; + OString aResult = OUStringToOString(aBuffer, RTL_TEXTENCODING_UTF8); + css_provider_load_from_data(m_pFontCssProvider, aResult.getStr(), aResult.getLength()); + gtk_style_context_add_provider(pWidgetContext, GTK_STYLE_PROVIDER(m_pFontCssProvider), + GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); + } + virtual void disable_notify_events() override { g_signal_handler_block(m_pVAdjustment, m_nVAdjustChangedSignalId); |