[balsa/wip/gtk4: 277/351] balsa-print-object: create_from_pixbuf is no more
- From: Peter Bloomfield <peterb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [balsa/wip/gtk4: 277/351] balsa-print-object: create_from_pixbuf is no more
- Date: Wed, 23 May 2018 21:40:15 +0000 (UTC)
commit 787b088c80914046739d8022cc133166c869445b
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date: Thu Apr 12 12:40:41 2018 -0400
balsa-print-object: create_from_pixbuf is no more
gdk_cairo_surface_create_from_pixbuf has been removed, so we print
directly from a GdkPixbuf instead of creating a cairo_surface_t.
src/balsa-print-object-header.c | 43 ++++++++++++++--------------------
src/balsa-print-object-header.h | 2 +-
src/balsa-print-object.c | 48 ++++++++------------------------------
src/balsa-print-object.h | 4 +--
4 files changed, 30 insertions(+), 67 deletions(-)
---
diff --git a/src/balsa-print-object-header.c b/src/balsa-print-object-header.c
index f0f4c9f..d08bc24 100644
--- a/src/balsa-print-object-header.c
+++ b/src/balsa-print-object-header.c
@@ -106,9 +106,7 @@ balsa_print_object_header_finalize(GObject * self)
BalsaPrintObjectHeader *po = BALSA_PRINT_OBJECT_HEADER(self);
g_free(po->headers);
- if (po->face) {
- g_clear_pointer(&po->face, (GDestroyNotify) cairo_surface_destroy);
- }
+ g_clear_object(&po->face);
G_OBJECT_CLASS(parent_class)->finalize(self);
}
@@ -138,7 +136,7 @@ balsa_print_object_header_new_real(GList * list,
gint p_label_width;
gint p_layout_width;
gdouble c_face_height;
- cairo_surface_t *face;
+ GdkPixbuf *face;
g_return_val_if_fail(headers != NULL, NULL);
@@ -184,7 +182,7 @@ balsa_print_object_header_new_real(GList * list,
/* user headers */
p = headers->user_hdrs;
face = NULL;
- while (p) {
+ while (p != NULL) {
gchar **pair, *curr_hdr;
pair = p->data;
@@ -194,25 +192,19 @@ balsa_print_object_header_new_real(GList * list,
g_free(curr_hdr);
/* check for face and x-face */
- if (!face) {
+ if (face == NULL) {
GError *err = NULL;
- GdkPixbuf *f_pixbuf = NULL;
if (g_ascii_strcasecmp("Face", pair[0]) == 0)
- f_pixbuf = libbalsa_get_pixbuf_from_face_header(pair[1], &err);
+ face = libbalsa_get_pixbuf_from_face_header(pair[1], &err);
#if HAVE_COMPFACE
else if (g_ascii_strcasecmp("X-Face", pair[0]) == 0)
- f_pixbuf = libbalsa_get_pixbuf_from_x_face_header(pair[1], &err);
+ face = libbalsa_get_pixbuf_from_x_face_header(pair[1], &err);
#endif /* HAVE_COMPFACE */
if (err != NULL)
/* FIXME report something? */
g_error_free(err);
- if (f_pixbuf != NULL) {
- face = gdk_cairo_surface_create_from_pixbuf(f_pixbuf, 0, NULL);
- cairo_surface_reference(face);
- g_object_unref(f_pixbuf);
- }
}
/* next */
@@ -246,9 +238,9 @@ balsa_print_object_header_new_real(GList * list,
/* check if we have a face */
c_use_width = psetup->c_width - 2 * psetup->curr_depth * C_LABEL_SEP;
- if (face) {
- p_layout_width = C_TO_P(c_use_width - cairo_image_surface_get_width(face) - C_LABEL_SEP);
- c_face_height = cairo_image_surface_get_height(face);
+ if (face != NULL) {
+ p_layout_width = C_TO_P(c_use_width - gdk_pixbuf_get_width(face) - C_LABEL_SEP);
+ c_face_height = gdk_pixbuf_get_height(face);
} else {
p_layout_width = C_TO_P(c_use_width);
c_face_height = 0;
@@ -299,9 +291,11 @@ balsa_print_object_header_new_real(GList * list,
po->headers = (gchar *) this_chunk->data;
po->p_label_width = p_label_width;
po->p_layout_width = p_layout_width;
- if (face) {
+ if (face != NULL) {
po->face = face;
- if (!this_chunk->next) {
+ face = NULL;
+
+ if (this_chunk->next == NULL) {
gint p_height;
/* verify that the image is not higher than the headers
@@ -312,7 +306,6 @@ balsa_print_object_header_new_real(GList * list,
if (c_face_height > P_TO_C(p_height))
psetup->c_y_pos += c_face_height - P_TO_C(p_height);
}
- face = NULL;
}
list = g_list_append(list, po);
@@ -489,12 +482,12 @@ balsa_print_object_header_draw(BalsaPrintObject * self,
gdouble c_face_h;
gdouble c_face_w;
- c_face_h = cairo_image_surface_get_height(po->face);
- c_face_w = cairo_image_surface_get_width(po->face);
+ c_face_h = gdk_pixbuf_get_height(po->face);
+ c_face_w = gdk_pixbuf_get_width(po->face);
- cairo_print_surface(cairo_ctx, po->face,
- self->c_at_x + self->c_width - c_face_w,
- self->c_at_y, 1.0);
+ cairo_print_pixbuf(cairo_ctx, po->face,
+ self->c_at_x + self->c_width - c_face_w,
+ self->c_at_y, 1.0);
if (c_face_h > self->c_height)
self->c_height = c_face_h;
}
diff --git a/src/balsa-print-object-header.h b/src/balsa-print-object-header.h
index 669fb3e..88eaaec 100644
--- a/src/balsa-print-object-header.h
+++ b/src/balsa-print-object-header.h
@@ -48,7 +48,7 @@ struct _BalsaPrintObjectHeader {
gint p_label_width;
gint p_layout_width;
gchar *headers;
- cairo_surface_t *face;
+ GdkPixbuf *face;
};
diff --git a/src/balsa-print-object.c b/src/balsa-print-object.c
index 4c2a535..2157483 100644
--- a/src/balsa-print-object.c
+++ b/src/balsa-print-object.c
@@ -228,36 +228,34 @@ p_string_height_from_layout(PangoLayout * layout, const gchar * text)
}
-/* print a cairo_surface_t to cairo at the specified position and with the
+/* print a GdkPixbuf to cairo at the specified position and with the
* specified scale */
gboolean
-cairo_print_surface(cairo_t * cairo_ctx, cairo_surface_t * surface,
- gdouble c_at_x, gdouble c_at_y, gdouble scale)
+cairo_print_pixbuf(cairo_t * cairo_ctx, GdkPixbuf * pixbuf,
+ gdouble c_at_x, gdouble c_at_y, gdouble scale)
{
+ gint n_chans;
gint width;
gint height;
- cairo_format_t format;
cairo_pattern_t *pattern;
cairo_matrix_t matrix;
/* paranoia checks */
g_return_val_if_fail(cairo_ctx != NULL, FALSE);
- g_return_val_if_fail(surface != NULL, FALSE);
+ g_return_val_if_fail(pixbuf != NULL, FALSE);
/* must have 3 (no alpha) or 4 (with alpha) channels */
- format = cairo_image_surface_get_format(surface);
- g_return_val_if_fail(format == CAIRO_FORMAT_ARGB32 ||
- format == CAIRO_FORMAT_RGB24,
- FALSE);
+ n_chans = gdk_pixbuf_get_n_channels(pixbuf);
+ g_return_val_if_fail(n_chans == 3 || n_chans == 4, FALSE);
- width = cairo_image_surface_get_width(surface);
- height = cairo_image_surface_get_height(surface);
+ width = gdk_pixbuf_get_width(pixbuf);
+ height = gdk_pixbuf_get_height(pixbuf);
/* save current state */
cairo_save(cairo_ctx);
/* set the curface */
- cairo_set_source_surface(cairo_ctx, surface, c_at_x, c_at_y);
+ gdk_cairo_set_source_pixbuf(cairo_ctx, pixbuf, c_at_x, c_at_y);
/* scale */
pattern = cairo_get_source(cairo_ctx);
@@ -286,32 +284,6 @@ cairo_print_surface(cairo_t * cairo_ctx, cairo_surface_t * surface,
}
-/* print a GdkPixbuf to cairo at the specified position and with the
- * specified scale */
-gboolean
-cairo_print_pixbuf(cairo_t * cairo_ctx, const GdkPixbuf * pixbuf,
- gdouble c_at_x, gdouble c_at_y, gdouble scale)
-{
- gint n_chans;
- cairo_surface_t *surface;
-
- /* paranoia checks */
- g_return_val_if_fail(cairo_ctx && pixbuf, FALSE);
-
- /* must have 8 bpp */
- g_return_val_if_fail(gdk_pixbuf_get_bits_per_sample(pixbuf) == 8,
- FALSE);
-
- /* must have 3 (no alpha) or 4 (with alpha) channels */
- n_chans = gdk_pixbuf_get_n_channels(pixbuf);
- g_return_val_if_fail(n_chans == 3 || n_chans == 4, FALSE);
-
- surface = gdk_cairo_surface_create_from_pixbuf(pixbuf, 1, NULL);
- cairo_print_surface(cairo_ctx, surface, c_at_x, c_at_y, scale);
- cairo_surface_destroy(surface);
-
- return TRUE;
-}
/* split a text buffer into chunks using the passed Pango layout */
diff --git a/src/balsa-print-object.h b/src/balsa-print-object.h
index 524d0fb..85fce30 100644
--- a/src/balsa-print-object.h
+++ b/src/balsa-print-object.h
@@ -58,10 +58,8 @@ typedef struct {
gint p_string_width_from_layout(PangoLayout * layout, const gchar * text);
gint p_string_height_from_layout(PangoLayout * layout, const gchar * text);
-gboolean cairo_print_pixbuf(cairo_t * cairo_ctx, const GdkPixbuf * pixbuf,
+gboolean cairo_print_pixbuf(cairo_t * cairo_ctx, GdkPixbuf * pixbuf,
gdouble c_at_x, gdouble c_at_y, gdouble scale);
-gboolean cairo_print_surface(cairo_t * cairo_ctx, cairo_surface_t * surface,
- gdouble c_at_x, gdouble c_at_y, gdouble scale);
GList *split_for_layout(PangoLayout * layout, const gchar * text,
PangoAttrList * attributes,
BalsaPrintSetup * psetup, gboolean is_header,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]