summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2021-09-29 15:13:28 +0100
committerCaolán McNamara <caolanm@redhat.com>2021-10-04 13:21:44 +0200
commitfeb1cdd5bcbdf8dfe350551ab84d89a43d6fde8c (patch)
tree3ef914cb5bf5db1874c7e381d1c68e2b046edf86 /vcl
parentc44574f6d28d8bb38e0a54ba079ca76b044bb346 (diff)
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>
Diffstat (limited to 'vcl')
-rw-r--r--vcl/inc/salvtables.hxx2
-rw-r--r--vcl/source/app/salvtables.cxx12
-rw-r--r--vcl/unx/gtk3/gtkinst.cxx121
3 files changed, 133 insertions, 2 deletions
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);