unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#28236: 'configure --with-cairo' causes 'emacs -font' to fail
@ 2017-08-25 19:57 andrei.elkin
  2017-08-26  7:24 ` Eli Zaretskii
  2018-12-11  1:50 ` Dmitry Gutov
  0 siblings, 2 replies; 13+ messages in thread
From: andrei.elkin @ 2017-08-25 19:57 UTC (permalink / raw)
  To: 28236

Hello.

I've been checking out the master branch periodically for quite a while but never
configured it with cairo.
Today I gave it a try, appending the option to my regular option list, as below.

$ git show HEAD
commit 579890f1c7703cd8ecfe2e56f52cc06fcd1b2442
Author: Eli Zaretskii <eliz@gnu.org>
Date:   Fri Aug 25 18:01:19 2017 +0300

  bash# ./configure --with-xft --with-x-toolkit=lucid --with-dbus \
                    --with-cairo && make ...
  => ... [ ok ]
The resulted executable complains about a font that otherwise
"orthodoxically" built one never has done (as the font really exists,
 which xlsfonts double-proves:

  bash# xlsfonts | grep 7x14
  =>7x14
).

  bash# src/emacs -Q -font 7x14
  => Font ‘7x14’ is not defined

This effect is observed in earlier commits as well. (I first suspected the
failure was introduced by a commit in the range started from my last
pull (about two weeks ago)).

I've not investigated any further, still hope this report is not in
vain.

Using this chance, thank you all for working and maintaining this
wonderful piece of software!

Andrelkin.






^ permalink raw reply	[flat|nested] 13+ messages in thread

* bug#28236: 'configure --with-cairo' causes 'emacs -font' to fail
  2017-08-25 19:57 bug#28236: 'configure --with-cairo' causes 'emacs -font' to fail andrei.elkin
@ 2017-08-26  7:24 ` Eli Zaretskii
  2018-12-11  1:50 ` Dmitry Gutov
  1 sibling, 0 replies; 13+ messages in thread
From: Eli Zaretskii @ 2017-08-26  7:24 UTC (permalink / raw)
  To: andrei.elkin; +Cc: 28236

> From: andrei.elkin@pp.inet.fi
> Date: Fri, 25 Aug 2017 22:57:59 +0300
> 
> I've been checking out the master branch periodically for quite a while but never
> configured it with cairo.
> Today I gave it a try, appending the option to my regular option list, as below.
> 
> $ git show HEAD
> commit 579890f1c7703cd8ecfe2e56f52cc06fcd1b2442
> Author: Eli Zaretskii <eliz@gnu.org>
> Date:   Fri Aug 25 18:01:19 2017 +0300
> 
>   bash# ./configure --with-xft --with-x-toolkit=lucid --with-dbus \
>                     --with-cairo && make ...
>   => ... [ ok ]
> The resulted executable complains about a font that otherwise
> "orthodoxically" built one never has done (as the font really exists,
>  which xlsfonts double-proves:
> 
>   bash# xlsfonts | grep 7x14
>   =>7x14
> ).
> 
>   bash# src/emacs -Q -font 7x14
>   => Font ‘7x14’ is not defined
> 
> This effect is observed in earlier commits as well. (I first suspected the
> failure was introduced by a commit in the range started from my last
> pull (about two weeks ago)).
> 
> I've not investigated any further, still hope this report is not in
> vain.

Thanks.  Unfortunately, we don't have Cairo experts on board, and
we've accumulated several known issues with that configuration.  This
is why the configure script says

   --with-cairo            compile with Cairo drawing (experimental)
                                                       ^^^^^^^^^^^^





^ permalink raw reply	[flat|nested] 13+ messages in thread

* bug#28236: 'configure --with-cairo' causes 'emacs -font' to fail
  2017-08-25 19:57 bug#28236: 'configure --with-cairo' causes 'emacs -font' to fail andrei.elkin
  2017-08-26  7:24 ` Eli Zaretskii
@ 2018-12-11  1:50 ` Dmitry Gutov
  2018-12-11  6:25   ` Eli Zaretskii
  1 sibling, 1 reply; 13+ messages in thread
From: Dmitry Gutov @ 2018-12-11  1:50 UTC (permalink / raw)
  To: andrei.elkin, 28236

On 25.08.2017 22:57, andrei.elkin@pp.inet.fi wrote:
>    bash# src/emacs -Q -font 7x14
>    => Font ‘7x14’ is not defined

FWIW, I can confirm with the latest emacs-26 and master.





^ permalink raw reply	[flat|nested] 13+ messages in thread

* bug#28236: 'configure --with-cairo' causes 'emacs -font' to fail
  2018-12-11  1:50 ` Dmitry Gutov
@ 2018-12-11  6:25   ` Eli Zaretskii
  2018-12-12 12:03     ` Ari Roponen
  0 siblings, 1 reply; 13+ messages in thread
From: Eli Zaretskii @ 2018-12-11  6:25 UTC (permalink / raw)
  To: Dmitry Gutov; +Cc: 28236, andrei.elkin

> From: Dmitry Gutov <dgutov@yandex.ru>
> Date: Tue, 11 Dec 2018 03:50:06 +0200
> 
> On 25.08.2017 22:57, andrei.elkin@pp.inet.fi wrote:
> >    bash# src/emacs -Q -font 7x14
> >    => Font ‘7x14’ is not defined
> 
> FWIW, I can confirm with the latest emacs-26 and master.

Thanks for trying.  AFAIU, this is an important user-level feature, so
we should try fixing it if we want to enable Cairo by default.





^ permalink raw reply	[flat|nested] 13+ messages in thread

* bug#28236: 'configure --with-cairo' causes 'emacs -font' to fail
  2018-12-11  6:25   ` Eli Zaretskii
@ 2018-12-12 12:03     ` Ari Roponen
  2018-12-12 15:16       ` Eli Zaretskii
  0 siblings, 1 reply; 13+ messages in thread
From: Ari Roponen @ 2018-12-12 12:03 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 28236, andrei.elkin, Dmitry Gutov

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Dmitry Gutov <dgutov@yandex.ru>
>> Date: Tue, 11 Dec 2018 03:50:06 +0200
>> 
>> On 25.08.2017 22:57, andrei.elkin@pp.inet.fi wrote:
>> >    bash# src/emacs -Q -font 7x14
>> >    => Font ‘7x14’ is not defined
>> 
>> FWIW, I can confirm with the latest emacs-26 and master.
>
> Thanks for trying.  AFAIU, this is an important user-level feature, so
> we should try fixing it if we want to enable Cairo by default.
>

I can get the same result also without Cairo:
    emacs-26.1 --xrm "Emacs.fontBackend: xft" -q -font 7x14

When I copy the font where fontconfig can see it:
    cp /usr/share/X11/fonts/misc/7x14.pcf.gz ~/.local/share/fonts/
    fc-cache -vf
I see this:
    fc-list | grep 7x14
=>  /home/arirop/.local/share/fonts/7x14.pcf.gz: Fixed:style=Regular

After that, using "-font Fixed" seems to work.





^ permalink raw reply	[flat|nested] 13+ messages in thread

* bug#28236: 'configure --with-cairo' causes 'emacs -font' to fail
  2018-12-12 12:03     ` Ari Roponen
@ 2018-12-12 15:16       ` Eli Zaretskii
  2018-12-12 15:41         ` Robert Pluim
  0 siblings, 1 reply; 13+ messages in thread
From: Eli Zaretskii @ 2018-12-12 15:16 UTC (permalink / raw)
  To: Ari Roponen; +Cc: 28236, andrei.elkin, dgutov

> From: Ari Roponen <ari.roponen@gmail.com>
> Cc: Dmitry Gutov <dgutov@yandex.ru>,  28236@debbugs.gnu.org,  andrei.elkin@pp.inet.fi
> Date: Wed, 12 Dec 2018 14:03:48 +0200
> 
> >> On 25.08.2017 22:57, andrei.elkin@pp.inet.fi wrote:
> >> >    bash# src/emacs -Q -font 7x14
> >> >    => Font ‘7x14’ is not defined
> >> 
> >> FWIW, I can confirm with the latest emacs-26 and master.
> >
> > Thanks for trying.  AFAIU, this is an important user-level feature, so
> > we should try fixing it if we want to enable Cairo by default.
> >
> 
> I can get the same result also without Cairo:
>     emacs-26.1 --xrm "Emacs.fontBackend: xft" -q -font 7x14
> 
> When I copy the font where fontconfig can see it:
>     cp /usr/share/X11/fonts/misc/7x14.pcf.gz ~/.local/share/fonts/
>     fc-cache -vf
> I see this:
>     fc-list | grep 7x14
> =>  /home/arirop/.local/share/fonts/7x14.pcf.gz: Fixed:style=Regular
> 
> After that, using "-font Fixed" seems to work.

So you are saying that the problem here is that Cairo can only work
with fonts known fontconfig, and cannot switch to font backend(s) that
bypass fontconfig?  If so, perhaps just an entry in PROBLEMS with the
above recipe would suffice as a workaround?





^ permalink raw reply	[flat|nested] 13+ messages in thread

* bug#28236: 'configure --with-cairo' causes 'emacs -font' to fail
  2018-12-12 15:16       ` Eli Zaretskii
@ 2018-12-12 15:41         ` Robert Pluim
  2018-12-12 16:37           ` Eli Zaretskii
  0 siblings, 1 reply; 13+ messages in thread
From: Robert Pluim @ 2018-12-12 15:41 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 28236, Ari Roponen, andrei.elkin, dgutov

Eli Zaretskii <eliz@gnu.org> writes:

> So you are saying that the problem here is that Cairo can only work
> with fonts known fontconfig, and cannot switch to font backend(s) that
> bypass fontconfig?  If so, perhaps just an entry in PROBLEMS with the
> above recipe would suffice as a workaround?

I find that surprising. The non-Cairo GTK build can use Xft and X font
backends, what's different about Cairo?

(I just tried to set font-backend to '(ftcr x) on my Cairo build, and
failed, so perhaps it really isnʼt supported).

Robert





^ permalink raw reply	[flat|nested] 13+ messages in thread

* bug#28236: 'configure --with-cairo' causes 'emacs -font' to fail
  2018-12-12 15:41         ` Robert Pluim
@ 2018-12-12 16:37           ` Eli Zaretskii
  2018-12-13 11:34             ` Robert Pluim
  0 siblings, 1 reply; 13+ messages in thread
From: Eli Zaretskii @ 2018-12-12 16:37 UTC (permalink / raw)
  To: Robert Pluim; +Cc: 28236, ari.roponen, andrei.elkin, dgutov

> From: Robert Pluim <rpluim@gmail.com>
> Cc: Ari Roponen <ari.roponen@gmail.com>,  28236@debbugs.gnu.org,  andrei.elkin@pp.inet.fi,  dgutov@yandex.ru
> Date: Wed, 12 Dec 2018 16:41:52 +0100
> 
> Eli Zaretskii <eliz@gnu.org> writes:
> 
> > So you are saying that the problem here is that Cairo can only work
> > with fonts known fontconfig, and cannot switch to font backend(s) that
> > bypass fontconfig?  If so, perhaps just an entry in PROBLEMS with the
> > above recipe would suffice as a workaround?
> 
> I find that surprising. The non-Cairo GTK build can use Xft and X font
> backends, what's different about Cairo?
> 
> (I just tried to set font-backend to '(ftcr x) on my Cairo build, and
> failed, so perhaps it really isnʼt supported).

I'm guessing that the other font backends use X calls that cannot be
supported with Cairo drawing, or maybe such support simply wasn't
coded yet.  But I'm not an expert on this stuff, so maybe I'm wrong.





^ permalink raw reply	[flat|nested] 13+ messages in thread

* bug#28236: 'configure --with-cairo' causes 'emacs -font' to fail
  2018-12-12 16:37           ` Eli Zaretskii
@ 2018-12-13 11:34             ` Robert Pluim
  2018-12-13 13:52               ` Eli Zaretskii
  0 siblings, 1 reply; 13+ messages in thread
From: Robert Pluim @ 2018-12-13 11:34 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 28236, ari.roponen, andrei.elkin, dgutov

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Robert Pluim <rpluim@gmail.com>
>> Cc: Ari Roponen <ari.roponen@gmail.com>,  28236@debbugs.gnu.org,  andrei.elkin@pp.inet.fi,  dgutov@yandex.ru
>> Date: Wed, 12 Dec 2018 16:41:52 +0100
>> 
>> Eli Zaretskii <eliz@gnu.org> writes:
>> 
>> > So you are saying that the problem here is that Cairo can only work
>> > with fonts known fontconfig, and cannot switch to font backend(s) that
>> > bypass fontconfig?  If so, perhaps just an entry in PROBLEMS with the
>> > above recipe would suffice as a workaround?
>> 
>> I find that surprising. The non-Cairo GTK build can use Xft and X font
>> backends, what's different about Cairo?
>> 
>> (I just tried to set font-backend to '(ftcr x) on my Cairo build, and
>> failed, so perhaps it really isnʼt supported).
>
> I'm guessing that the other font backends use X calls that cannot be
> supported with Cairo drawing, or maybe such support simply wasn't
> coded yet.  But I'm not an expert on this stuff, so maybe I'm wrong.

So xfns.c only initializes the xfont driver when not using Cairo. I
made the obvious changes there, and 'emacs -Q -fn 7x14' starts up, and
'C-u C-x =' tells me:

 x:-misc-fixed-medium-r-normal--14-130-75-75-c-70-iso8859-1 (#x68)

Unfortunately *scratch* does not (re-)display properly [1], so unless
weʼre feeling really adventurous, we probably shouldn't enable both
Cairo and the X font back on master, etc/PROBLEMS (or NEWS?) might be
better.

Robert

Footnotes:
[1]  Admittedly this is over an ssh forwarded connection. Running it
     locally might look better.






^ permalink raw reply	[flat|nested] 13+ messages in thread

* bug#28236: 'configure --with-cairo' causes 'emacs -font' to fail
  2018-12-13 11:34             ` Robert Pluim
@ 2018-12-13 13:52               ` Eli Zaretskii
  2018-12-13 14:56                 ` Robert Pluim
  0 siblings, 1 reply; 13+ messages in thread
From: Eli Zaretskii @ 2018-12-13 13:52 UTC (permalink / raw)
  To: Robert Pluim; +Cc: 28236, ari.roponen, andrei.elkin, dgutov

> From: Robert Pluim <rpluim@gmail.com>
> Cc: 28236@debbugs.gnu.org,  ari.roponen@gmail.com,  andrei.elkin@pp.inet.fi,  dgutov@yandex.ru
> Date: Thu, 13 Dec 2018 12:34:54 +0100
> 
> So xfns.c only initializes the xfont driver when not using Cairo. I
> made the obvious changes there, and 'emacs -Q -fn 7x14' starts up, and
> 'C-u C-x =' tells me:
> 
>  x:-misc-fixed-medium-r-normal--14-130-75-75-c-70-iso8859-1 (#x68)
> 
> Unfortunately *scratch* does not (re-)display properly

Can you tell more details about this improper redisplay?

Thanks.





^ permalink raw reply	[flat|nested] 13+ messages in thread

* bug#28236: 'configure --with-cairo' causes 'emacs -font' to fail
  2018-12-13 13:52               ` Eli Zaretskii
@ 2018-12-13 14:56                 ` Robert Pluim
  2019-06-04  7:47                   ` YAMAMOTO Mitsuharu
  0 siblings, 1 reply; 13+ messages in thread
From: Robert Pluim @ 2018-12-13 14:56 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 28236, ari.roponen, andrei.elkin, dgutov

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Robert Pluim <rpluim@gmail.com>
>> Cc: 28236@debbugs.gnu.org,  ari.roponen@gmail.com,  andrei.elkin@pp.inet.fi,  dgutov@yandex.ru
>> Date: Thu, 13 Dec 2018 12:34:54 +0100
>> 
>> So xfns.c only initializes the xfont driver when not using Cairo. I
>> made the obvious changes there, and 'emacs -Q -fn 7x14' starts up, and
>> 'C-u C-x =' tells me:
>> 
>>  x:-misc-fixed-medium-r-normal--14-130-75-75-c-70-iso8859-1 (#x68)
>> 
>> Unfortunately *scratch* does not (re-)display properly
>
> Can you tell more details about this improper redisplay?

I see text for the menu-bar, but *scratch* looks empty (and thereʼs no
text displayed in the mode-line). The text is actually there in
*scratch*, though.

I donʼt think this is a viable path to look at, especially given Ari's
workaround of copying the required fonts.

Robert





^ permalink raw reply	[flat|nested] 13+ messages in thread

* bug#28236: 'configure --with-cairo' causes 'emacs -font' to fail
  2018-12-13 14:56                 ` Robert Pluim
@ 2019-06-04  7:47                   ` YAMAMOTO Mitsuharu
  2019-06-08  5:13                     ` YAMAMOTO Mitsuharu
  0 siblings, 1 reply; 13+ messages in thread
From: YAMAMOTO Mitsuharu @ 2019-06-04  7:47 UTC (permalink / raw)
  To: Robert Pluim; +Cc: 28236, ari.roponen, andrei.elkin, dgutov

[-- Attachment #1: Type: text/plain, Size: 1904 bytes --]

On Thu, 13 Dec 2018 23:56:21 +0900,
Robert Pluim wrote:
> 
> >> So xfns.c only initializes the xfont driver when not using Cairo. I
> >> made the obvious changes there, and 'emacs -Q -fn 7x14' starts up, and
> >> 'C-u C-x =' tells me:
> >> 
> >>  x:-misc-fixed-medium-r-normal--14-130-75-75-c-70-iso8859-1 (#x68)
> >> 
> >> Unfortunately *scratch* does not (re-)display properly
> >
> > Can you tell more details about this improper redisplay?
> 
> I see text for the menu-bar, but *scratch* looks empty (and thereʼs no
> text displayed in the mode-line). The text is actually there in
> *scratch*, though.
> 
> I donʼt think this is a viable path to look at, especially given Ari's
> workaround of copying the required fonts.

Previously the cairo drawing code does its own double-buffering using
the image surface, where all the drawing should happen on the client
side and not compatible with X core fonts that are drawn on the server
side.  Copying back the result of server side drawing is not
impossible, but inefficient.

Recently, I've made a change to the cairo drawing code in the master
so it draws into Xlib surfaces instead of image ones if the X Double
Buffer Extension is available.  On top of that, it is rather
straightforward to cope with X core fonts.

I implemented both in the attached patch.  The former corresponds to
the case that the frame parameter `inhibit-double-buffering' is t, and
the latter to nil.  I think the latter is usable, but the former is
not.  The code for the former is not an total waste because we can use
it for exporting displayed contents to bitmap images, i.e.,
(x-export-frames FRAME 'png).  The same approach cannot be used for
exporting to outline images (PDF or SVG), so characters in X core
fonts are replaced with hollow boxes in such cases.

				     YAMAMOTO Mitsuharu
				mituharu@math.s.chiba-u.ac.jp

[-- Attachment #2: cairo-xfont.diff --]
[-- Type: application/octet-stream, Size: 9025 bytes --]

diff --git a/configure.ac b/configure.ac
index 0f1fd5d26ef..90f13b99fc3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -5229,7 +5229,7 @@ AC_DEFUN
   XOBJ="xterm.o xfns.o xselect.o xrdb.o xsmfns.o xsettings.o"
   FONT_OBJ=xfont.o
   if test "$HAVE_CAIRO" = "yes"; then
-    FONT_OBJ="ftfont.o ftcrfont.o"
+    FONT_OBJ="$FONT_OBJ ftfont.o ftcrfont.o"
   elif test "$HAVE_XFT" = "yes"; then
     FONT_OBJ="$FONT_OBJ ftfont.o xftfont.o ftxfont.o"
   elif test "$HAVE_FREETYPE" = "yes"; then
diff --git a/src/font.c b/src/font.c
index 5ca89c97dcf..52bf5dae95b 100644
--- a/src/font.c
+++ b/src/font.c
@@ -5489,10 +5489,10 @@ cause Xft crashes.  Only has an effect in Xft builds.  */);
 #ifdef HAVE_FREETYPE
   syms_of_ftfont ();
 #ifdef HAVE_X_WINDOWS
+  syms_of_xfont ();
 #ifdef USE_CAIRO
   syms_of_ftcrfont ();
 #else
-  syms_of_xfont ();
   syms_of_ftxfont ();
 #ifdef HAVE_XFT
   syms_of_xftfont ();
diff --git a/src/xfns.c b/src/xfns.c
index 4195980d33e..1dcad6f3db1 100644
--- a/src/xfns.c
+++ b/src/xfns.c
@@ -3788,8 +3788,8 @@ This function is an internal primitive--use `make-frame' instead.  */)
   register_font_driver (&ftxfont_driver, f);
 #endif	/* not HAVE_XFT */
 #endif	/* HAVE_FREETYPE */
-  register_font_driver (&xfont_driver, f);
 #endif	/* not USE_CAIRO */
+  register_font_driver (&xfont_driver, f);
 
   image_cache_refcount =
     FRAME_IMAGE_CACHE (f) ? FRAME_IMAGE_CACHE (f)->refcount : 0;
diff --git a/src/xterm.c b/src/xterm.c
index ccc84dcc716..8c4df4efb01 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -357,6 +357,25 @@ x_cr_update_surface_desired_size (struct frame *f, int width, int height)
     }
 }
 
+static void
+x_cr_gc_clip (cairo_t *cr, struct frame *f, GC gc)
+{
+  if (gc)
+    {
+      struct x_gc_ext_data *gc_ext = x_gc_get_ext_data (f, gc, 0);
+
+      if (gc_ext && gc_ext->n_clip_rects)
+	{
+	  for (int i = 0; i < gc_ext->n_clip_rects; i++)
+	    cairo_rectangle (cr, gc_ext->clip_rects[i].x,
+			     gc_ext->clip_rects[i].y,
+			     gc_ext->clip_rects[i].width,
+			     gc_ext->clip_rects[i].height);
+	  cairo_clip (cr);
+	}
+    }
+}
+
 cairo_t *
 x_begin_cr_clip (struct frame *f, GC gc)
 {
@@ -379,23 +398,7 @@ x_begin_cr_clip (struct frame *f, GC gc)
       cairo_surface_destroy (surface);
     }
   cairo_save (cr);
-
-  if (gc)
-    {
-      struct x_gc_ext_data *gc_ext = x_gc_get_ext_data (f, gc, 0);
-
-      if (gc_ext && gc_ext->n_clip_rects)
-	{
-	  int i;
-
-	  for (i = 0; i < gc_ext->n_clip_rects; i++)
-	    cairo_rectangle (cr, gc_ext->clip_rects[i].x,
-			     gc_ext->clip_rects[i].y,
-			     gc_ext->clip_rects[i].width,
-			     gc_ext->clip_rects[i].height);
-	  cairo_clip (cr);
-	}
-    }
+  x_cr_gc_clip (cr, f, gc);
 
   return cr;
 }
@@ -434,6 +437,126 @@ x_set_cr_source_with_gc_background (struct frame *f, GC gc)
 			color.green / 65535.0, color.blue / 65535.0);
 }
 
+static const cairo_user_data_key_t xlib_surface_key, saved_drawable_key;
+
+static void
+x_cr_destroy_xlib_surface (cairo_surface_t *xlib_surface)
+{
+  if (xlib_surface)
+    {
+      XFreePixmap (cairo_xlib_surface_get_display (xlib_surface),
+		   cairo_xlib_surface_get_drawable (xlib_surface));
+      cairo_surface_destroy (xlib_surface);
+    }
+}
+
+static bool
+x_try_cr_xlib_drawable (struct frame *f, GC gc)
+{
+  cairo_t *cr = FRAME_CR_CONTEXT (f);
+  if (!cr)
+    return true;
+
+  cairo_surface_t *surface = cairo_get_target (cr);
+  switch (cairo_surface_get_type (surface))
+    {
+    case CAIRO_SURFACE_TYPE_XLIB:
+      cairo_surface_flush (surface);
+      return true;
+
+    case CAIRO_SURFACE_TYPE_IMAGE:
+      break;
+
+    default:
+      return false;
+    }
+
+  /* FRAME_CR_CONTEXT (f) is an image surface we can not draw directly
+     with Xlib.  Set up a Pixmap so we can copy back the result later
+     in x_end_cr_xlib_drawable.  */
+  cairo_surface_t *xlib_surface = cairo_get_user_data (cr, &xlib_surface_key);
+  int width = FRAME_CR_SURFACE_DESIRED_WIDTH (f);
+  int height = FRAME_CR_SURFACE_DESIRED_HEIGHT (f);
+  Pixmap pixmap;
+  if (xlib_surface
+      && cairo_xlib_surface_get_width (xlib_surface) == width
+      && cairo_xlib_surface_get_height (xlib_surface) == height)
+    pixmap = cairo_xlib_surface_get_drawable (xlib_surface);
+  else
+    {
+      pixmap = XCreatePixmap (FRAME_X_DISPLAY (f), FRAME_X_RAW_DRAWABLE (f),
+			      width, height,
+			      DefaultDepthOfScreen (FRAME_X_SCREEN (f)));
+      xlib_surface = cairo_xlib_surface_create (FRAME_X_DISPLAY (f),
+						pixmap, FRAME_X_VISUAL (f),
+						width, height);
+      cairo_set_user_data (cr, &xlib_surface_key, xlib_surface,
+			   (cairo_destroy_func_t) x_cr_destroy_xlib_surface);
+    }
+
+#if 0				/* This seems to be unnecessary.  */
+  if (cairo_image_surface_get_format (surface) == CAIRO_FORMAT_ARGB32)
+    {
+      cairo_surface_flush (xlib_surface);
+      XCopyArea (FRAME_X_DISPLAY (f), FRAME_X_RAW_DRAWABLE (f), pixmap, gc,
+		 0, 0, width, height, 0, 0);
+      cairo_surface_mark_dirty (xlib_surface);
+    }
+#endif
+
+  cairo_t *buf = cairo_create (xlib_surface);
+  cairo_set_source_surface (buf, surface, 0, 0);
+  cairo_matrix_t matrix;
+  cairo_get_matrix (cr, &matrix);
+  cairo_pattern_set_matrix (cairo_get_source (cr), &matrix);
+  cairo_set_operator (buf, CAIRO_OPERATOR_SOURCE);
+  x_cr_gc_clip (buf, f, gc);
+  cairo_paint (buf);
+  cairo_destroy (buf);
+
+  cairo_set_user_data (cr, &saved_drawable_key,
+		       (void *) (uintptr_t) FRAME_X_RAW_DRAWABLE (f), NULL);
+  FRAME_X_RAW_DRAWABLE (f) = pixmap;
+  cairo_surface_flush (xlib_surface);
+
+  return true;
+}
+
+static void
+x_end_cr_xlib_drawable (struct frame *f, GC gc)
+{
+  cairo_t *cr = FRAME_CR_CONTEXT (f);
+  if (!cr)
+    return;
+
+  Drawable saved_drawable
+    = (uintptr_t) cairo_get_user_data (cr, &saved_drawable_key);
+  cairo_surface_t *surface = (saved_drawable
+			      ? cairo_get_user_data (cr, &xlib_surface_key)
+			      : cairo_get_target (cr));
+  struct x_gc_ext_data *gc_ext = x_gc_get_ext_data (f, gc, 0);
+  if (gc_ext && gc_ext->n_clip_rects)
+    for (int i = 0; i < gc_ext->n_clip_rects; i++)
+      cairo_surface_mark_dirty_rectangle (surface, gc_ext->clip_rects[i].x,
+					  gc_ext->clip_rects[i].y,
+					  gc_ext->clip_rects[i].width,
+					  gc_ext->clip_rects[i].height);
+  else
+    cairo_surface_mark_dirty (surface);
+  if (!saved_drawable)
+    return;
+
+  cairo_save (cr);
+  cairo_set_source_surface (cr, surface, 0, 0);
+  cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
+  x_cr_gc_clip (cr, f, gc);
+  cairo_paint (cr);
+  cairo_restore (cr);
+
+  FRAME_X_RAW_DRAWABLE (f) = saved_drawable;
+  cairo_set_user_data (cr, &saved_drawable_key, NULL, NULL);
+}
+
 /* Fringe bitmaps.  */
 
 static int max_fringe_bmp = 0;
@@ -1739,6 +1862,33 @@ x_draw_glyph_string_foreground (struct glyph_string *s)
   else
     {
       struct font *font = s->font;
+#ifdef USE_CAIRO
+      if (EQ (font->driver->type, Qx)
+	  && !x_try_cr_xlib_drawable (s->f, s->gc))
+	{
+	  /* Fallback for the case that no Xlib Drawable is available
+	     for drawing text with X core fonts.  */
+	  if (!(s->for_overlaps
+		|| (s->background_filled_p && s->hl != DRAW_CURSOR)))
+	    {
+	      int box_line_width = max (s->face->box_line_width, 0);
+
+	      x_clear_glyph_string_rect (s, s->x, s->y + box_line_width,
+					 s->background_width,
+					 s->height - 2 * box_line_width);
+	    }
+	  for (i = 0; i < s->nchars; ++i)
+	    {
+	      struct glyph *g = s->first_glyph + i;
+	      x_draw_rectangle (s->f,
+				s->gc, x, s->y, g->pixel_width - 1,
+				s->height - 1);
+	      x += g->pixel_width;
+	    }
+	}
+      else
+	{
+#endif	/* USE_CAIRO */
       int boff = font->baseline_offset;
       int y;
 
@@ -1753,6 +1903,11 @@ x_draw_glyph_string_foreground (struct glyph_string *s)
 	font->driver->draw (s, 0, s->nchars, x, y, true);
       if (s->face->overstrike)
 	font->driver->draw (s, 0, s->nchars, x + 1, y, false);
+#ifdef USE_CAIRO
+	  if (EQ (font->driver->type, Qx))
+	    x_end_cr_xlib_drawable (s->f, s->gc);
+	}
+#endif	/* USE_CAIRO */
     }
 }
 
@@ -1785,7 +1940,21 @@ x_draw_composite_glyph_string_foreground (struct glyph_string *s)
 	x_draw_rectangle (s->f, s->gc, x, s->y,
 			s->width - 1, s->height - 1);
     }
-  else if (! s->first_glyph->u.cmp.automatic)
+  else
+#ifdef USE_CAIRO
+    if (EQ (font->driver->type, Qx)
+	&& !x_try_cr_xlib_drawable (s->f, s->gc))
+      {
+	/* Fallback for the case that no Xlib Drawable is available
+	   for drawing text with X core fonts.  */
+	if (s->cmp_from == 0)
+	  x_draw_rectangle (s->f, s->gc, x, s->y,
+			    s->width - 1, s->height - 1);
+      }
+    else
+      {
+#endif	/* USE_CAIRO */
+  if (! s->first_glyph->u.cmp.automatic)
     {
       int y = s->ybase;
 
@@ -1844,6 +2013,11 @@ x_draw_composite_glyph_string_foreground (struct glyph_string *s)
 	    font->driver->draw (s, j, i, x + 1, y, false);
 	}
     }
+#ifdef USE_CAIRO
+	if (EQ (font->driver->type, Qx))
+	  x_end_cr_xlib_drawable (s->f, s->gc);
+      }
+#endif	/* USE_CAIRO */
 }
 
 

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* bug#28236: 'configure --with-cairo' causes 'emacs -font' to fail
  2019-06-04  7:47                   ` YAMAMOTO Mitsuharu
@ 2019-06-08  5:13                     ` YAMAMOTO Mitsuharu
  0 siblings, 0 replies; 13+ messages in thread
From: YAMAMOTO Mitsuharu @ 2019-06-08  5:13 UTC (permalink / raw)
  To: Robert Pluim; +Cc: 28236-done, ari.roponen, andrei.elkin, dgutov

On Tue, 04 Jun 2019 16:47:56 +0900,
YAMAMOTO Mitsuharu wrote:
> 
> On Thu, 13 Dec 2018 23:56:21 +0900,
> Robert Pluim wrote:
> > 
> > >> So xfns.c only initializes the xfont driver when not using Cairo. I
> > >> made the obvious changes there, and 'emacs -Q -fn 7x14' starts up, and
> > >> 'C-u C-x =' tells me:
> > >> 
> > >>  x:-misc-fixed-medium-r-normal--14-130-75-75-c-70-iso8859-1 (#x68)
> > >> 
> > >> Unfortunately *scratch* does not (re-)display properly
> > >
> > > Can you tell more details about this improper redisplay?
> > 
> > I see text for the menu-bar, but *scratch* looks empty (and thereʼs no
> > text displayed in the mode-line). The text is actually there in
> > *scratch*, though.
> > 
> > I donʼt think this is a viable path to look at, especially given Ari's
> > workaround of copying the required fonts.
> 
> Previously the cairo drawing code does its own double-buffering using
> the image surface, where all the drawing should happen on the client
> side and not compatible with X core fonts that are drawn on the server
> side.  Copying back the result of server side drawing is not
> impossible, but inefficient.
> 
> Recently, I've made a change to the cairo drawing code in the master
> so it draws into Xlib surfaces instead of image ones if the X Double
> Buffer Extension is available.  On top of that, it is rather
> straightforward to cope with X core fonts.
> 
> I implemented both in the attached patch.  The former corresponds to
> the case that the frame parameter `inhibit-double-buffering' is t, and
> the latter to nil.  I think the latter is usable, but the former is
> not.  The code for the former is not an total waste because we can use
> it for exporting displayed contents to bitmap images, i.e.,
> (x-export-frames FRAME 'png).  The same approach cannot be used for
> exporting to outline images (PDF or SVG), so characters in X core
> fonts are replaced with hollow boxes in such cases.

Pushed to master as faf10bd8eb3.

				     YAMAMOTO Mitsuharu
				mituharu@math.s.chiba-u.ac.jp





^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2019-06-08  5:13 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-25 19:57 bug#28236: 'configure --with-cairo' causes 'emacs -font' to fail andrei.elkin
2017-08-26  7:24 ` Eli Zaretskii
2018-12-11  1:50 ` Dmitry Gutov
2018-12-11  6:25   ` Eli Zaretskii
2018-12-12 12:03     ` Ari Roponen
2018-12-12 15:16       ` Eli Zaretskii
2018-12-12 15:41         ` Robert Pluim
2018-12-12 16:37           ` Eli Zaretskii
2018-12-13 11:34             ` Robert Pluim
2018-12-13 13:52               ` Eli Zaretskii
2018-12-13 14:56                 ` Robert Pluim
2019-06-04  7:47                   ` YAMAMOTO Mitsuharu
2019-06-08  5:13                     ` YAMAMOTO Mitsuharu

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).