mirror of
https://github.com/ZoiteChat/zoitechat.git
synced 2026-03-10 07:50:19 +00:00
Replaced GTK3 palette font styling with CSS-compliant properties derived from PangoFontDescription, avoiding the deprecated Pango font: syntax in generated CSS.
Added a GTK3-only helper to translate Pango font fields into font-family, font-size, font-style, font-weight, font-variant, and font-stretch CSS declarations while preserving GTK2 behavior under #if !HAVE_GTK3. Reused the GTK3 font CSS helper in the main UI font styling path to eliminate remaining Pango font: shorthand usage that triggers GTK3 theme parsing warnings. Exposed the GTK3 font CSS helper in gtkutil so callers can emit CSS-compliant font properties consistently.
This commit is contained in:
@@ -161,6 +161,118 @@ gtkutil_button_new_from_stock (const char *stock, const char *label)
|
||||
}
|
||||
|
||||
#if HAVE_GTK3
|
||||
void
|
||||
gtkutil_append_font_css (GString *css, const PangoFontDescription *font_desc)
|
||||
{
|
||||
PangoFontMask mask;
|
||||
|
||||
if (!font_desc)
|
||||
return;
|
||||
|
||||
mask = pango_font_description_get_set_fields (font_desc);
|
||||
|
||||
if (mask & PANGO_FONT_MASK_FAMILY)
|
||||
{
|
||||
const char *family = pango_font_description_get_family (font_desc);
|
||||
|
||||
if (family && *family)
|
||||
g_string_append_printf (css, " font-family: \"%s\";", family);
|
||||
}
|
||||
|
||||
if (mask & PANGO_FONT_MASK_STYLE)
|
||||
{
|
||||
const char *style = "normal";
|
||||
|
||||
switch (pango_font_description_get_style (font_desc))
|
||||
{
|
||||
case PANGO_STYLE_ITALIC:
|
||||
style = "italic";
|
||||
break;
|
||||
case PANGO_STYLE_OBLIQUE:
|
||||
style = "oblique";
|
||||
break;
|
||||
default:
|
||||
style = "normal";
|
||||
break;
|
||||
}
|
||||
|
||||
g_string_append_printf (css, " font-style: %s;", style);
|
||||
}
|
||||
|
||||
if (mask & PANGO_FONT_MASK_VARIANT)
|
||||
{
|
||||
const char *variant = "normal";
|
||||
|
||||
if (pango_font_description_get_variant (font_desc) == PANGO_VARIANT_SMALL_CAPS)
|
||||
variant = "small-caps";
|
||||
|
||||
g_string_append_printf (css, " font-variant: %s;", variant);
|
||||
}
|
||||
|
||||
if (mask & PANGO_FONT_MASK_WEIGHT)
|
||||
{
|
||||
int weight = (int) pango_font_description_get_weight (font_desc);
|
||||
|
||||
if (weight < 100)
|
||||
weight = 100;
|
||||
if (weight > 900)
|
||||
weight = 900;
|
||||
|
||||
g_string_append_printf (css, " font-weight: %d;", weight);
|
||||
}
|
||||
|
||||
if (mask & PANGO_FONT_MASK_STRETCH)
|
||||
{
|
||||
const char *stretch = "normal";
|
||||
|
||||
switch (pango_font_description_get_stretch (font_desc))
|
||||
{
|
||||
case PANGO_STRETCH_ULTRA_CONDENSED:
|
||||
stretch = "ultra-condensed";
|
||||
break;
|
||||
case PANGO_STRETCH_EXTRA_CONDENSED:
|
||||
stretch = "extra-condensed";
|
||||
break;
|
||||
case PANGO_STRETCH_CONDENSED:
|
||||
stretch = "condensed";
|
||||
break;
|
||||
case PANGO_STRETCH_SEMI_CONDENSED:
|
||||
stretch = "semi-condensed";
|
||||
break;
|
||||
case PANGO_STRETCH_SEMI_EXPANDED:
|
||||
stretch = "semi-expanded";
|
||||
break;
|
||||
case PANGO_STRETCH_EXPANDED:
|
||||
stretch = "expanded";
|
||||
break;
|
||||
case PANGO_STRETCH_EXTRA_EXPANDED:
|
||||
stretch = "extra-expanded";
|
||||
break;
|
||||
case PANGO_STRETCH_ULTRA_EXPANDED:
|
||||
stretch = "ultra-expanded";
|
||||
break;
|
||||
default:
|
||||
stretch = "normal";
|
||||
break;
|
||||
}
|
||||
|
||||
g_string_append_printf (css, " font-stretch: %s;", stretch);
|
||||
}
|
||||
|
||||
if (mask & PANGO_FONT_MASK_SIZE)
|
||||
{
|
||||
double size = (double) pango_font_description_get_size (font_desc) / PANGO_SCALE;
|
||||
char size_buf[G_ASCII_DTOSTR_BUF_SIZE];
|
||||
const char *unit = "pt";
|
||||
|
||||
if (pango_font_description_get_size_is_absolute (font_desc))
|
||||
unit = "px";
|
||||
|
||||
g_ascii_formatd (size_buf, sizeof (size_buf), "%.2f", size);
|
||||
g_string_append_printf (css, " font-size: %s%s;", size_buf, unit);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
gtkutil_apply_palette (GtkWidget *widget, const GdkRGBA *bg, const GdkRGBA *fg,
|
||||
const PangoFontDescription *font_desc)
|
||||
@@ -183,7 +295,6 @@ gtkutil_apply_palette (GtkWidget *widget, const GdkColor *bg, const GdkColor *fg
|
||||
GString *css;
|
||||
gchar *bg_color = NULL;
|
||||
gchar *fg_color = NULL;
|
||||
gchar *font_str = NULL;
|
||||
|
||||
if (!bg && !fg && !font_desc)
|
||||
{
|
||||
@@ -217,11 +328,7 @@ gtkutil_apply_palette (GtkWidget *widget, const GdkColor *bg, const GdkColor *fg
|
||||
fg_color = gdk_rgba_to_string (fg);
|
||||
g_string_append_printf (css, " color: %s;", fg_color);
|
||||
}
|
||||
if (font_desc)
|
||||
{
|
||||
font_str = pango_font_description_to_string (font_desc);
|
||||
g_string_append_printf (css, " font: %s;", font_str);
|
||||
}
|
||||
gtkutil_append_font_css (css, font_desc);
|
||||
g_string_append (css, " }");
|
||||
|
||||
gtk_css_provider_load_from_data (provider, css->str, -1, NULL);
|
||||
@@ -235,7 +342,6 @@ gtkutil_apply_palette (GtkWidget *widget, const GdkColor *bg, const GdkColor *fg
|
||||
g_string_free (css, TRUE);
|
||||
g_free (bg_color);
|
||||
g_free (fg_color);
|
||||
g_free (font_str);
|
||||
}
|
||||
#else
|
||||
gtk_widget_modify_base (widget, GTK_STATE_NORMAL, bg);
|
||||
|
||||
@@ -53,6 +53,7 @@ gboolean gtkutil_tray_icon_supported (GtkWindow *window);
|
||||
#if HAVE_GTK3
|
||||
void gtkutil_apply_palette (GtkWidget *widget, const GdkRGBA *bg, const GdkRGBA *fg,
|
||||
const PangoFontDescription *font_desc);
|
||||
void gtkutil_append_font_css (GString *css, const PangoFontDescription *font_desc);
|
||||
#else
|
||||
void gtkutil_apply_palette (GtkWidget *widget, const GdkColor *bg, const GdkColor *fg,
|
||||
const PangoFontDescription *font_desc);
|
||||
|
||||
@@ -124,7 +124,6 @@ mg_apply_font_css (GtkWidget *widget, const PangoFontDescription *desc,
|
||||
{
|
||||
GtkStyleContext *context;
|
||||
GtkCssProvider *provider;
|
||||
char *font_str;
|
||||
GString *css;
|
||||
|
||||
if (!widget || !desc)
|
||||
@@ -141,13 +140,13 @@ mg_apply_font_css (GtkWidget *widget, const PangoFontDescription *desc,
|
||||
g_object_set_data_full (G_OBJECT (widget), provider_key, provider, g_object_unref);
|
||||
}
|
||||
|
||||
font_str = pango_font_description_to_string (desc);
|
||||
css = g_string_new (".");
|
||||
g_string_append (css, class_name);
|
||||
g_string_append_printf (css, " { font: %s; }", font_str);
|
||||
g_string_append (css, " {");
|
||||
gtkutil_append_font_css (css, desc);
|
||||
g_string_append (css, " }");
|
||||
gtk_css_provider_load_from_data (provider, css->str, -1, NULL);
|
||||
g_string_free (css, TRUE);
|
||||
g_free (font_str);
|
||||
|
||||
gtk_style_context_add_class (context, class_name);
|
||||
gtk_style_context_add_provider (context, GTK_STYLE_PROVIDER (provider),
|
||||
|
||||
@@ -293,7 +293,7 @@ xtext_surface_from_window (GdkWindow *window)
|
||||
int height;
|
||||
cairo_t *cr;
|
||||
|
||||
if (!window)
|
||||
if (!window || !GDK_IS_WINDOW (window))
|
||||
return NULL;
|
||||
|
||||
width = gdk_window_get_width (window);
|
||||
@@ -925,14 +925,39 @@ gtk_xtext_get_pointer (GdkWindow *window, gint *x, gint *y, GdkModifierType *mas
|
||||
#if !HAVE_GTK3
|
||||
gdk_window_get_pointer (window, x, y, mask);
|
||||
#else
|
||||
GdkDisplay *display = gdk_window_get_display (window);
|
||||
GdkSeat *seat = gdk_display_get_default_seat (display);
|
||||
GdkDevice *device = gdk_seat_get_pointer (seat);
|
||||
GdkDisplay *display;
|
||||
GdkSeat *seat;
|
||||
GdkDevice *device;
|
||||
gint root_x = 0;
|
||||
gint root_y = 0;
|
||||
gint win_x = 0;
|
||||
gint win_y = 0;
|
||||
|
||||
if (!window || !GDK_IS_WINDOW (window))
|
||||
{
|
||||
if (x)
|
||||
*x = 0;
|
||||
if (y)
|
||||
*y = 0;
|
||||
if (mask)
|
||||
*mask = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
display = gdk_window_get_display (window);
|
||||
if (!display)
|
||||
{
|
||||
if (x)
|
||||
*x = 0;
|
||||
if (y)
|
||||
*y = 0;
|
||||
if (mask)
|
||||
*mask = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
seat = gdk_display_get_default_seat (display);
|
||||
device = gdk_seat_get_pointer (seat);
|
||||
if (!device)
|
||||
{
|
||||
if (x)
|
||||
@@ -1049,8 +1074,16 @@ gtk_xtext_realize (GtkWidget * widget)
|
||||
xtext->ts_x = xtext->ts_y = 0;
|
||||
}
|
||||
|
||||
xtext->hand_cursor = gdk_cursor_new_for_display (gdk_window_get_display (window), GDK_HAND1);
|
||||
xtext->resize_cursor = gdk_cursor_new_for_display (gdk_window_get_display (window), GDK_LEFT_SIDE);
|
||||
if (window && GDK_IS_WINDOW (window))
|
||||
{
|
||||
GdkDisplay *display = gdk_window_get_display (window);
|
||||
|
||||
if (display)
|
||||
{
|
||||
xtext->hand_cursor = gdk_cursor_new_for_display (display, GDK_HAND1);
|
||||
xtext->resize_cursor = gdk_cursor_new_for_display (display, GDK_LEFT_SIDE);
|
||||
}
|
||||
}
|
||||
|
||||
gtk_xtext_clear_background (widget);
|
||||
|
||||
@@ -2712,9 +2745,11 @@ gtk_xtext_selection_get (GtkWidget * widget,
|
||||
#if HAVE_GTK3
|
||||
GdkWindow *window = gtk_widget_get_window (widget);
|
||||
|
||||
if (!window)
|
||||
if (!window || !GDK_IS_WINDOW (window))
|
||||
break;
|
||||
display = gdk_window_get_display (window);
|
||||
if (!display)
|
||||
break;
|
||||
#endif
|
||||
#if !HAVE_GTK3
|
||||
display = gdk_window_get_display (widget->window);
|
||||
|
||||
Reference in New Issue
Block a user