[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
feature/pgtk be47e34 077/100: Re-port image drawing code from X
From: |
Yuuki Harano |
Subject: |
feature/pgtk be47e34 077/100: Re-port image drawing code from X |
Date: |
Tue, 24 Nov 2020 08:02:41 -0500 (EST) |
branch: feature/pgtk
commit be47e34e40d4a330e59c8dfabdf8b44a57905973
Author: Yuuki Harano <masm+github@masm11.me>
Commit: Jeff Walsh <jeff.walsh@drtusers-MacBook-Pro.local>
Re-port image drawing code from X
* src/pgtkterm.c (x_cr_draw_image): Re-port X code.
(x_draw_image_foreground): Re-port X code.
(x_draw_image_glyph_string): Re-port X code.
---
src/pgtkterm.c | 103 +++++++++++++++++++++++++++++++++++++++++----------------
1 file changed, 74 insertions(+), 29 deletions(-)
diff --git a/src/pgtkterm.c b/src/pgtkterm.c
index dc36f38..aeec3f5 100644
--- a/src/pgtkterm.c
+++ b/src/pgtkterm.c
@@ -1971,6 +1971,42 @@ x_draw_glyph_string_bg_rect (struct glyph_string *s, int
x, int y, int w,
x_clear_glyph_string_rect (s, x, y, w, h);
}
+static void
+x_cr_draw_image (struct frame *f, Emacs_GC *gc, cairo_pattern_t *image,
+ int src_x, int src_y, int width, int height,
+ int dest_x, int dest_y, bool overlay_p)
+{
+ cairo_t *cr = pgtk_begin_cr_clip (f);
+
+ if (overlay_p)
+ cairo_rectangle (cr, dest_x, dest_y, width, height);
+ else
+ {
+ pgtk_set_cr_source_with_gc_background (f, gc);
+ cairo_rectangle (cr, dest_x, dest_y, width, height);
+ cairo_fill_preserve (cr);
+ }
+
+ cairo_translate (cr, dest_x - src_x, dest_y - src_y);
+
+ cairo_surface_t *surface;
+ cairo_pattern_get_surface (image, &surface);
+ cairo_format_t format = cairo_image_surface_get_format (surface);
+ if (format != CAIRO_FORMAT_A8 && format != CAIRO_FORMAT_A1)
+ {
+ cairo_set_source (cr, image);
+ cairo_fill (cr);
+ }
+ else
+ {
+ pgtk_set_cr_source_with_gc_foreground (f, gc);
+ cairo_clip (cr);
+ cairo_mask (cr, image);
+ }
+
+ pgtk_end_cr_clip (f);
+}
+
/* Draw foreground of image glyph string S. */
static void
@@ -1982,7 +2018,8 @@ x_draw_image_foreground (struct glyph_string *s)
/* If first glyph of S has a left box line, start drawing it to the
right of that line. */
if (s->face->box != FACE_NO_BOX
- && s->first_glyph->left_box_line_p && s->slice.x == 0)
+ && s->first_glyph->left_box_line_p
+ && s->slice.x == 0)
x += max (s->face->box_vertical_line_width, 0);
/* If there is a margin around the image, adjust x- and y-position
@@ -1992,9 +2029,35 @@ x_draw_image_foreground (struct glyph_string *s)
if (s->slice.y == 0)
y += s->img->vmargin;
- /* Draw a rectangle if image could not be loaded. */
- pgtk_draw_rectangle (s->f, s->xgcv.foreground, x, y,
- s->slice.width - 1, s->slice.height - 1);
+ if (s->img->cr_data)
+ {
+ cairo_t *cr = pgtk_begin_cr_clip (s->f);
+ x_set_glyph_string_clipping (s, cr);
+ x_cr_draw_image (s->f, &s->xgcv, s->img->cr_data,
+ s->slice.x, s->slice.y, s->slice.width, s->slice.height,
+ x, y, true);
+ if (!s->img->mask)
+ {
+ /* When the image has a mask, we can expect that at
+ least part of a mouse highlight or a block cursor will
+ be visible. If the image doesn't have a mask, make
+ a block cursor visible by drawing a rectangle around
+ the image. I believe it's looking better if we do
+ nothing here for mouse-face. */
+ if (s->hl == DRAW_CURSOR)
+ {
+ int relief = eabs (s->img->relief);
+ pgtk_draw_rectangle (s->f, s->xgcv.foreground, x - relief, y -
relief,
+ s->slice.width + relief*2 - 1,
+ s->slice.height + relief*2 - 1);
+ }
+ }
+ pgtk_end_cr_clip (s->f);
+ }
+ else
+ /* Draw a rectangle if image could not be loaded. */
+ pgtk_draw_rectangle (s->f, s->xgcv.foreground, x, y,
+ s->slice.width - 1, s->slice.height - 1);
}
/* Draw image glyph string S.
@@ -2033,19 +2096,15 @@ x_draw_image_glyph_string (struct glyph_string *s)
|| s->img->vmargin
|| s->img->mask
|| s->img->pixmap == 0
- || s->stippled_p || s->width != s->background_width)
+ || s->width != s->background_width)
{
- if (s->img->mask)
- {
- fill_background (s, s->x, s->y, s->background_width, s->height);
- }
- else
{
int x = s->x;
int y = s->y;
int width = s->background_width;
- if (s->first_glyph->left_box_line_p && s->slice.x == 0)
+ if (s->first_glyph->left_box_line_p
+ && s->slice.x == 0)
{
x += box_line_hwidth;
width -= box_line_hwidth;
@@ -2054,33 +2113,19 @@ x_draw_image_glyph_string (struct glyph_string *s)
if (s->slice.y == 0)
y += box_line_vwidth;
- fill_background (s, x, y, width, height);
+ x_draw_glyph_string_bg_rect (s, x, y, width, height);
}
s->background_filled_p = true;
}
/* Draw the foreground. */
- if (s->img->cr_data)
- {
- cairo_t *cr = pgtk_begin_cr_clip (s->f);
-
- int x = s->x + s->img->hmargin;
- int y = s->y + s->img->vmargin;
- int width = s->background_width;
-
- cairo_translate (cr, x - s->slice.x, y - s->slice.y);
- cairo_set_source (cr, s->img->cr_data);
- cairo_rectangle (cr, 0, 0, width, height);
- cairo_fill (cr);
- pgtk_end_cr_clip (s->f);
- }
- else
- x_draw_image_foreground (s);
+ x_draw_image_foreground (s);
/* If we must draw a relief around the image, do it. */
if (s->img->relief
- || s->hl == DRAW_IMAGE_RAISED || s->hl == DRAW_IMAGE_SUNKEN)
+ || s->hl == DRAW_IMAGE_RAISED
+ || s->hl == DRAW_IMAGE_SUNKEN)
x_draw_image_relief (s);
}
- feature/pgtk c9e6b44 044/100: Some work toward posframe on wayland, (continued)
- feature/pgtk c9e6b44 044/100: Some work toward posframe on wayland, Yuuki Harano, 2020/11/24
- feature/pgtk 964dfcf 062/100: * src/pgtkgui.h: change coding style, Yuuki Harano, 2020/11/24
- feature/pgtk da3c351 019/100: border_color/pixel width, Yuuki Harano, 2020/11/24
- feature/pgtk 014d56f 052/100: * src/pgtkterm.c: Remove incorrect mark_object call., Yuuki Harano, 2020/11/24
- feature/pgtk bc35a1e 032/100: Make multipdisplay work by limiting selection while enabed, Yuuki Harano, 2020/11/24
- feature/pgtk d68633b 056/100: * src/pgtkterm.c (pgtk_defined_color): support gtk special colors, Yuuki Harano, 2020/11/24
- feature/pgtk 6957f94 024/100: Add PGTK support for fullscreen, Yuuki Harano, 2020/11/24
- feature/pgtk ae3bb14 029/100: implement restacking and cleanup frame z order, Yuuki Harano, 2020/11/24
- feature/pgtk 49645df 047/100: minimize gtkutil.c differences., Yuuki Harano, 2020/11/24
- feature/pgtk d2a29e8 040/100: emacsclient should use both of DISPLAY and WAYLAND_DISPLAY., Yuuki Harano, 2020/11/24
- feature/pgtk be47e34 077/100: Re-port image drawing code from X,
Yuuki Harano <=
- feature/pgtk 0b69b73 085/100: Fix crash when child frame updates toolbar, Yuuki Harano, 2020/11/24
- feature/pgtk 1d549fa 015/100: Add support for make-frame-(in)visible, Yuuki Harano, 2020/11/24
- feature/pgtk 19da22e 018/100: Add support for handing the internal border, Yuuki Harano, 2020/11/24
- feature/pgtk e021e23 043/100: End Resize flickering by copying surface rather than just clearing, Yuuki Harano, 2020/11/24
- feature/pgtk fd61a86 030/100: improve some efficiency - simplify draws, Yuuki Harano, 2020/11/24
- feature/pgtk 330a346 012/100: Migrate to Emacs_GC, Yuuki Harano, 2020/11/24
- feature/pgtk b1cc62c 037/100: Add support for Jpeglib, Yuuki Harano, 2020/11/24
- feature/pgtk fe2297c 055/100: * pgtkmenu.c (set_frame_menubar): fix empty menu., Yuuki Harano, 2020/11/24
- feature/pgtk a167e23 057/100: * src/pgtkmenu.c (set_frame_menubar): Suppress gcc warning, Yuuki Harano, 2020/11/24
- feature/pgtk 5a72a07 053/100: * pgtk-win.el: fix compile-time warnings., Yuuki Harano, 2020/11/24