[evince/wip/gpoo/gtk4-rebase-port: 8/96] libgd: Port GdTwoLinesRenderer to gtk4
- From: Germán Poo-Caamaño <gpoo src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evince/wip/gpoo/gtk4-rebase-port: 8/96] libgd: Port GdTwoLinesRenderer to gtk4
- Date: Sun, 20 Mar 2022 21:50:28 +0000 (UTC)
commit 903fa5b4cc2e0c08aaf3a081bfce42ea502e24a9
Author: Qiu Wenbo <qiuwenbo kylinos com cn>
Date: Wed Dec 8 10:24:03 2021 +0800
libgd: Port GdTwoLinesRenderer to gtk4
Signed-off-by: Qiu Wenbo <qiuwenbo kylinos com cn>
cut-n-paste/libgd/gd-two-lines-renderer.c | 50 +++++++++++++++++--------------
1 file changed, 27 insertions(+), 23 deletions(-)
---
diff --git a/cut-n-paste/libgd/gd-two-lines-renderer.c b/cut-n-paste/libgd/gd-two-lines-renderer.c
index f5e1ce53a..0e2a9e9fe 100644
--- a/cut-n-paste/libgd/gd-two-lines-renderer.c
+++ b/cut-n-paste/libgd/gd-two-lines-renderer.c
@@ -2,16 +2,16 @@
* Copyright (c) 2011 Red Hat, Inc.
*
* This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
+ * it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
- * You should have received a copy of the GNU Lesser General Public License
+ * You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
@@ -92,6 +92,7 @@ apply_subtitle_style_to_layout (GtkStyleContext *context,
PangoAttrList *layout_attr;
PangoAttribute *attr_alpha;
+#if 0
gtk_style_context_save (context);
gtk_style_context_set_state (context, flags);
gtk_style_context_get (context, gtk_style_context_get_state (context),
@@ -104,6 +105,7 @@ apply_subtitle_style_to_layout (GtkStyleContext *context,
pango_layout_set_font_description (layout, desc);
pango_font_description_free (desc);
+#endif
/* Set the font alpha */
layout_attr = pango_attr_list_new ();
attr_alpha = pango_attr_foreground_alpha_new (SUBTITLE_DIM_PERCENTAGE * 65535);
@@ -229,7 +231,7 @@ gd_two_lines_renderer_get_size (GtkCellRenderer *cell,
{
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
*x_offset_1 = (1.0 - xalign) * (cell_area->width - (layout_one_rect.width + (2 * xpad)));
- else
+ else
*x_offset_1 = xalign * (cell_area->width - (layout_one_rect.width + (2 * xpad)));
*x_offset_1 = MAX (*x_offset_1, 0);
@@ -240,7 +242,7 @@ gd_two_lines_renderer_get_size (GtkCellRenderer *cell,
{
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
*x_offset_2 = (1.0 - xalign) * (cell_area->width - (layout_two_rect.width + (2 * xpad)));
- else
+ else
*x_offset_2 = xalign * (cell_area->width - (layout_two_rect.width + (2 * xpad)));
*x_offset_2 = MAX (*x_offset_2, 0);
@@ -275,12 +277,12 @@ gd_two_lines_renderer_get_size (GtkCellRenderer *cell,
}
static void
-gd_two_lines_renderer_render (GtkCellRenderer *cell,
- cairo_t *cr,
- GtkWidget *widget,
- const GdkRectangle *background_area,
- const GdkRectangle *cell_area,
- GtkCellRendererState flags)
+gd_two_lines_renderer_snapshot (GtkCellRenderer *cell,
+ GtkSnapshot *snapshot,
+ GtkWidget *widget,
+ const GdkRectangle *background_area,
+ const GdkRectangle *cell_area,
+ GtkCellRendererState flags)
{
GdTwoLinesRenderer *self = GD_TWO_LINES_RENDERER (cell);
GtkStyleContext *context;
@@ -312,10 +314,10 @@ gd_two_lines_renderer_render (GtkCellRenderer *cell,
render_area.x += x_offset_1 - layout_rect.x;
render_area.y += y_offset;
- gtk_render_layout (context, cr,
- render_area.x,
- render_area.y,
- layout_one);
+ gtk_snapshot_render_layout (snapshot, context,
+ render_area.x,
+ render_area.y,
+ layout_one);
/* render the second layout */
if (layout_two != NULL)
@@ -336,10 +338,10 @@ gd_two_lines_renderer_render (GtkCellRenderer *cell,
render_area.x += x_offset_2 - layout_rect.x;
render_area.y += y_offset + line_one_height;
- gtk_render_layout (context, cr,
- render_area.x,
- render_area.y,
- layout_two);
+ gtk_snapshot_render_layout (snapshot, context,
+ render_area.x,
+ render_area.y,
+ layout_two);
gtk_style_context_restore (context);
}
@@ -373,11 +375,12 @@ gd_two_lines_renderer_get_preferred_width (GtkCellRenderer *cell,
gd_two_lines_renderer_get_size (cell, widget,
NULL, NULL,
&text_width, NULL,
- NULL,
+ NULL,
NULL, NULL, NULL);
/* Fetch the average size of a character */
context = gtk_widget_get_pango_context (widget);
+#if 0
gtk_style_context_save (style_context);
gtk_style_context_set_state (style_context, 0);
gtk_style_context_get (style_context, gtk_style_context_get_state (style_context),
@@ -390,6 +393,7 @@ gd_two_lines_renderer_get_preferred_width (GtkCellRenderer *cell,
pango_font_metrics_unref (metrics);
pango_font_description_free (font_desc);
+#endif
/* enforce minimum width for ellipsized labels at ~3 chars */
ellipsize_chars = 3;
@@ -445,7 +449,7 @@ gd_two_lines_renderer_get_preferred_height_for_width (GtkCellRenderer *cell,
gd_two_lines_renderer_get_size (cell, widget,
layout_one, layout_two,
NULL, &text_height,
- NULL,
+ NULL,
NULL, NULL, NULL);
text_height += 2 * ypad;
@@ -593,7 +597,7 @@ gd_two_lines_renderer_class_init (GdTwoLinesRendererClass *klass)
GtkCellRendererClass *cclass = GTK_CELL_RENDERER_CLASS (klass);
GObjectClass *oclass = G_OBJECT_CLASS (klass);
- cclass->render = gd_two_lines_renderer_render;
+ cclass->snapshot = gd_two_lines_renderer_snapshot;
cclass->get_preferred_width = gd_two_lines_renderer_get_preferred_width;
cclass->get_preferred_height = gd_two_lines_renderer_get_preferred_height;
cclass->get_preferred_height_for_width = gd_two_lines_renderer_get_preferred_height_for_width;
@@ -602,7 +606,7 @@ gd_two_lines_renderer_class_init (GdTwoLinesRendererClass *klass)
oclass->set_property = gd_two_lines_renderer_set_property;
oclass->get_property = gd_two_lines_renderer_get_property;
oclass->finalize = gd_two_lines_renderer_finalize;
-
+
properties[PROP_TEXT_LINES] =
g_param_spec_int ("text-lines",
"Lines of text",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]