From: Matthias Clasen Date: Sat, 8 Oct 2022 19:02:33 +0000 (-0400) Subject: Add gtk_css_style_snapshot_layout X-Git-Tag: archive/raspbian/4.12.3+ds-1+rpi1~1^2^2^2~22^2~9^2~181^2~25 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=73f991a7fd296f94e9737e680ef0b0eb2c9015ac;p=gtk4.git Add gtk_css_style_snapshot_layout This function renders a PangoLayout at a given position, using text shadows and color from css. --- 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 . + */ + +#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 . + */ + +#ifndef __GTK_RENDER_LAYOUT_PRIVATE_H__ +#define __GTK_RENDER_LAYOUT_PRIVATE_H__ + +#include +#include + +#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',