[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#35468: [PATCH] Refactor draw_glyph_string on X and w32

From: Alex Gramiak
Subject: bug#35468: [PATCH] Refactor draw_glyph_string on X and w32
Date: Fri, 03 May 2019 13:01:18 -0600
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (gnu/linux)

address@hidden writes:

> Unlike the NS port, the terminal code in the Mac port is much like the X11
> version.

I looked at your code and fortunately it indeed looks like the same
abstractions for glyph drawing that would work for the X11 version would
work for the Mac port.

> But there is one notable difference in the above respect.
> It defines mac_erase_rectangle, which is like mac_fill_rectangle (the
> XFillRectangle counterpart)
> but uses the background color of GC and also handles stipples:
> /* Mac replacement for XFillRectangle.  */
> static void
> mac_fill_rectangle (struct frame *f, GC gc, int x, int y, int width, int
> height)
> {
>   MAC_BEGIN_DRAW_TO_FRAME (f, gc, context);
>   CGContextSetFillColorWithColor (context, gc->cg_fore_color);
>   {
>     CGRect rect = mac_rect_make (f, x, y, width, height);
>     CGContextFillRects (context, &rect, 1);
>   }
> }
> static void
> mac_erase_rectangle (struct frame *f, GC gc, int x, int y,
>                    int width, int height)
> {
>   MAC_BEGIN_DRAW_TO_FRAME (f, gc, context);
>   {
>     CGRect rect = mac_rect_make (f, x, y, width, height);
>     CG_CONTEXT_FILL_RECT_WITH_GC_BACKGROUND (f, context, rect, gc);
>     if (gc->xgcv.fill_style == FillOpaqueStippled && gc->xgcv.stipple)
>       {
>       CGContextClipToRects (context, &rect, 1);
>       CGContextSetFillColorWithColor (context, gc->cg_fore_color);
>       int scale = CFArrayGetCount (gc->xgcv.stipple);
>       if (FRAME_BACKING_SCALE_FACTOR (f) < scale)
>         scale = FRAME_BACKING_SCALE_FACTOR (f);
>       CGImageRef image_mask =
>         (CGImageRef) CFArrayGetValueAtIndex (gc->xgcv.stipple, scale - 1);
>       rect = CGRectMake (0, 0, CGImageGetWidth (image_mask) / (CGFloat) scale,
>                          CGImageGetHeight (image_mask) / (CGFloat) scale);
>       CGContextScaleCTM (context, 1, -1);
>       CGContextSetInterpolationQuality (context, kCGInterpolationNone);
>       CGContextDrawTiledImage (context, rect, image_mask);
>       }
>   }
> }

Why does it use the background color of GC? It appears that the
Cairo version uses the foreground color of GC; is that because the Cairo
version doesn't handle stippling?

> I guess introducing the erase_rectagle handler makes things simpler and
> efficient.

Looking over the code, and considering that stippling is quite uncommon
nowadays (GTK 3 removed it, AFAIK), I think the best approach would be
to define 3 separate interface procedures:

1) fill_rectangle: handles x_fill_rectangle/mac_fill_rectangle

2) fill_rectangle_with_color: handles (1), but also with the temporary
overriding of the GC that's done frequently for mac_erase_rectangle.

3) fill_rectangle_with_stipple: handles the temporary XFillStyle
overriding of the GC.

A third procedure wouldn't be inelegant in comparison to the
alternatives, since otherwise I would need a set_context_stipple
procedure to indicate stippling.

Then mac_fill_rectangle can be assigned to fill_rectangle, and
mac_erase_rectangle can be assigned to fill_rectangle_with_stipple.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]