[gtk/deprecate-render: 18/36] Add gtk_css_style_snapshot_layout




commit 08df14ca87f3ac0b287e163fc8d469c6eaff909c
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Oct 8 15:02:33 2022 -0400

    Add gtk_css_style_snapshot_layout
    
    This function renders a PangoLayout at a given
    position, using text shadows and color from css.

 gtk/gtkrenderlayout.c        | 62 ++++++++++++++++++++++++++++++++++++++++++++
 gtk/gtkrenderlayoutprivate.h | 39 ++++++++++++++++++++++++++++
 gtk/meson.build              |  1 +
 3 files changed, 102 insertions(+)
---
diff --git a/gtk/gtkrenderlayout.c b/gtk/gtkrenderlayout.c
new file mode 100644
index 0000000000..1d38ff097b
--- /dev/null
+++ b/gtk/gtkrenderlayout.c
@@ -0,0 +1,62 @@
+/* GTK - The GIMP Toolkit
+ * Copyright (C) 2022 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify 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 library 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 License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include "gtkrenderlayoutprivate.h"
+
+#include "gtkcsscolorvalueprivate.h"
+#include "gtkcssshadowvalueprivate.h"
+#include "gtkpangoprivate.h"
+#include "gtksnapshot.h"
+#include "gtktypebuiltins.h"
+
+
+void
+gtk_css_style_snapshot_layout (GtkCssBoxes *boxes,
+                               GtkSnapshot *snapshot,
+                               int          x,
+                               int          y,
+                               PangoLayout *layout)
+{
+  GtkCssStyle *style;
+  const GdkRGBA *color;
+  gboolean has_shadow;
+
+  gtk_snapshot_push_debug (snapshot, "Layout");
+
+  if (x != 0 || y != 0)
+    {
+      gtk_snapshot_save (snapshot);
+      gtk_snapshot_translate (snapshot, &GRAPHENE_POINT_INIT (x, y));
+    }
+
+  style = boxes->style;
+  color = gtk_css_color_value_get_rgba (style->core->color);
+  has_shadow = gtk_css_shadow_value_push_snapshot (style->font->text_shadow, snapshot);
+
+  gtk_snapshot_append_layout (snapshot, layout, color);
+
+  if (has_shadow)
+    gtk_snapshot_pop (snapshot);
+
+  if (x != 0 || y != 0)
+    gtk_snapshot_restore (snapshot);
+
+  gtk_snapshot_pop (snapshot);
+}
+
diff --git a/gtk/gtkrenderlayoutprivate.h b/gtk/gtkrenderlayoutprivate.h
new file mode 100644
index 0000000000..ec4d13b816
--- /dev/null
+++ b/gtk/gtkrenderlayoutprivate.h
@@ -0,0 +1,39 @@
+/* GTK - The GIMP Toolkit
+ * Copyright (C) 2022 Red Hat, Inc
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify 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 library 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 License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GTK_RENDER_LAYOUT_PRIVATE_H__
+#define __GTK_RENDER_LAYOUT_PRIVATE_H__
+
+#include <glib-object.h>
+#include <cairo.h>
+
+#include "gtkcsstypesprivate.h"
+#include "gtkcssboxesprivate.h"
+#include "gtktypes.h"
+
+G_BEGIN_DECLS
+
+void            gtk_css_style_snapshot_layout (GtkCssBoxes *boxes,
+                                               GtkSnapshot *snapshot,
+                                               int          x,
+                                               int          y,
+                                               PangoLayout *layout);
+
+
+G_END_DECLS
+
+#endif /* __GTK_RENDER_LAYOUT_PRIVATE_H__ */
diff --git a/gtk/meson.build b/gtk/meson.build
index cbde78d38a..4286d14e31 100644
--- a/gtk/meson.build
+++ b/gtk/meson.build
@@ -316,6 +316,7 @@ gtk_public_sources = files([
   'gtkrenderbackground.c',
   'gtkrenderborder.c',
   'gtkrendericon.c',
+  'gtkrenderlayout.c',
   'gtkrendernodepaintable.c',
   'gtkrevealer.c',
   'gtkroot.c',


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]