Add gtk_css_style_snapshot_layout
authorMatthias Clasen <mclasen@redhat.com>
Sat, 8 Oct 2022 19:02:33 +0000 (15:02 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Wed, 12 Oct 2022 19:35:00 +0000 (15:35 -0400)
This function renders a PangoLayout at a given
position, using text shadows and color from css.

gtk/gtkrenderlayout.c [new file with mode: 0644]
gtk/gtkrenderlayoutprivate.h [new file with mode: 0644]
gtk/meson.build

diff --git a/gtk/gtkrenderlayout.c b/gtk/gtkrenderlayout.c
new file mode 100644 (file)
index 0000000..1d38ff0
--- /dev/null
@@ -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 (file)
index 0000000..ec4d13b
--- /dev/null
@@ -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__ */
index cbde78d38a50d25c49a4f13926098d1bc7018e3a..4286d14e3107995207b27efcf27ac3853c08a0c0 100644 (file)
@@ -316,6 +316,7 @@ gtk_public_sources = files([
   'gtkrenderbackground.c',
   'gtkrenderborder.c',
   'gtkrendericon.c',
+  'gtkrenderlayout.c',
   'gtkrendernodepaintable.c',
   'gtkrevealer.c',
   'gtkroot.c',