From 458dbb8c7a5f3d3950529e05728b9327e50d7025 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Mitsuharu Date: Mon, 1 May 2006 01:13:06 +0000 Subject: [PATCH] (mac_draw_line, mac_draw_line_to_pixmap): Adjust endpoints of strictly horizontal/vertical lines. (mac_set_clip_rectangles) [USE_CG_DRAWING]: Set clip_rects. (pcm_init, pcm_get_status): New functions. (x_per_char_metric, XLoadQueryFont): Use them instead of XCharStructRow and related macros. (x_draw_relief_rect): Don't adjust arguments of mac_draw_line. (x_free_frame_resources) [TARGET_API_MAC_CARBON]: Free FRAME_FILE_NAME. (XTread_socket) [TARGET_API_MAC_CARBON]: Handle proxy icon drag and window path pop-up menu on title bar. (mac_use_core_graphics) [USE_CG_DRAWING]: Set default to 1. --- src/macterm.c | 119 +++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 98 insertions(+), 21 deletions(-) diff --git a/src/macterm.c b/src/macterm.c index cbef67c3be..60b5545d51 100644 --- a/src/macterm.c +++ b/src/macterm.c @@ -389,16 +389,37 @@ mac_draw_line (f, gc, x1, y1, x2, y2) { #if USE_CG_DRAWING CGContextRef context; + float gx1 = x1, gy1 = y1, gx2 = x2, gy2 = y2; + + if (y1 != y2) + gx1 += 0.5f, gx2 += 0.5f; + if (x1 != x2) + gy1 += 0.5f, gy2 += 0.5f; context = mac_begin_cg_clip (f, gc); CG_SET_STROKE_COLOR (context, gc->xgcv.foreground); CGContextBeginPath (context); - CGContextMoveToPoint (context, x1 + 0.5f, y1 + 0.5f); - CGContextAddLineToPoint (context, x2 + 0.5f, y2 + 0.5f); + CGContextMoveToPoint (context, gx1, gy1); + CGContextAddLineToPoint (context, gx2, gy2); CGContextClosePath (context); CGContextStrokePath (context); mac_end_cg_clip (f); #else + if (x1 == x2) + { + if (y1 > y2) + y1--; + else if (y2 > y1) + y2--; + } + else if (y1 == y2) + { + if (x1 > x2) + x1--; + else + x2--; + } + SetPortWindowPort (FRAME_MAC_WINDOW (f)); RGBForeColor (GC_FORE_COLOR (gc)); @@ -420,6 +441,21 @@ mac_draw_line_to_pixmap (display, p, gc, x1, y1, x2, y2) CGrafPtr old_port; GDHandle old_gdh; + if (x1 == x2) + { + if (y1 > y2) + y1--; + else if (y2 > y1) + y2--; + } + else if (y1 == y2) + { + if (x1 > x2) + x1--; + else + x2--; + } + GetGWorld (&old_port, &old_gdh); SetGWorld (p, NULL); @@ -1625,7 +1661,7 @@ mac_set_clip_rectangles (display, gc, rectangles, n) DisposeRgn (region); } } -#if defined (MAC_OSX) && USE_ATSUI +#if defined (MAC_OSX) && (USE_ATSUI || USE_CG_DRAWING) for (i = 0; i < n; i++) { Rect *rect = rectangles + i; @@ -2136,6 +2172,29 @@ static XCharStruct *x_per_char_metric P_ ((XFontStruct *, XChar2b *)); static int mac_encode_char P_ ((int, XChar2b *, struct font_info *, int *)); +static void +pcm_init (pcm, count) + XCharStruct *pcm; + int count; +{ + bzero (pcm, sizeof (XCharStruct) * count); + while (--count >= 0) + { + pcm->descent = PCM_INVALID; + pcm++; + } +} + +static enum pcm_status +pcm_get_status (pcm) + XCharStruct *pcm; +{ + int height = pcm->ascent + pcm->descent; + + /* Negative height means some special status. */ + return height >= 0 ? PCM_VALID : height; +} + /* Get metrics of character CHAR2B in FONT. Value is null if CHAR2B is not contained in the font. */ @@ -2152,22 +2211,21 @@ x_per_char_metric (font, char2b) #if USE_ATSUI if (font->mac_style) { - XCharStructRow **row = font->bounds.rows + char2b->byte1; + XCharStruct **row = font->bounds.rows + char2b->byte1; if (*row == NULL) { - *row = xmalloc (sizeof (XCharStructRow)); - bzero (*row, sizeof (XCharStructRow)); + *row = xmalloc (sizeof (XCharStruct) * 0x100); + pcm_init (*row, 0x100); } - pcm = (*row)->per_char + char2b->byte2; - if (!XCHARSTRUCTROW_CHAR_VALID_P (*row, char2b->byte2)) + pcm = *row + char2b->byte2; + if (pcm_get_status (pcm) != PCM_VALID) { BLOCK_INPUT; mac_query_char_extents (font->mac_style, (char2b->byte1 << 8) + char2b->byte2, NULL, NULL, pcm, NULL); UNBLOCK_INPUT; - XCHARSTRUCTROW_SET_CHAR_VALID (*row, char2b->byte2); } } else @@ -3122,13 +3180,13 @@ x_draw_relief_rect (f, left_x, top_y, right_x, bottom_y, width, for (i = 0; i < width; ++i) mac_draw_line (f, gc, left_x + i * left_p, top_y + i, - right_x - i * right_p, top_y + i); + right_x + 1 - i * right_p, top_y + i); /* Left. */ if (left_p) for (i = 0; i < width; ++i) mac_draw_line (f, gc, - left_x + i, top_y + i, left_x + i, bottom_y - i); + left_x + i, top_y + i, left_x + i, bottom_y - i + 1); mac_reset_clip_rectangles (dpy, gc); if (raised_p) @@ -3142,13 +3200,13 @@ x_draw_relief_rect (f, left_x, top_y, right_x, bottom_y, width, for (i = 0; i < width; ++i) mac_draw_line (f, gc, left_x + i * left_p, bottom_y - i, - right_x - i * right_p, bottom_y - i); + right_x + 1 - i * right_p, bottom_y - i); /* Right. */ if (right_p) for (i = 0; i < width; ++i) mac_draw_line (f, gc, - right_x - i, top_y + i + 1, right_x - i, bottom_y - i - 1); + right_x - i, top_y + i + 1, right_x - i, bottom_y - i); mac_reset_clip_rectangles (dpy, gc); } @@ -6300,6 +6358,11 @@ x_free_frame_resources (f) if (FRAME_SIZE_HINTS (f)) xfree (FRAME_SIZE_HINTS (f)); +#if TARGET_API_MAC_CARBON + if (FRAME_FILE_NAME (f)) + xfree (FRAME_FILE_NAME (f)); +#endif + xfree (f->output_data.mac); f->output_data.mac = NULL; @@ -7746,10 +7809,10 @@ XLoadQueryFont (Display *dpy, char *fontname) font->min_char_or_byte2 = 0; font->max_char_or_byte2 = 0xff; - font->bounds.rows = xmalloc (sizeof (XCharStructRow *) * 0x100); - bzero (font->bounds.rows, sizeof (XCharStructRow *) * 0x100); - font->bounds.rows[0] = xmalloc (sizeof (XCharStructRow)); - bzero (font->bounds.rows[0], sizeof (XCharStructRow)); + font->bounds.rows = xmalloc (sizeof (XCharStruct *) * 0x100); + bzero (font->bounds.rows, sizeof (XCharStruct *) * 0x100); + font->bounds.rows[0] = xmalloc (sizeof (XCharStruct) * 0x100); + pcm_init (font->bounds.rows[0], 0x100); #if USE_CG_TEXT_DRAWING { @@ -7775,7 +7838,7 @@ XLoadQueryFont (Display *dpy, char *fontname) bzero (font->cg_glyphs, sizeof (CGGlyph) * 0x100); } #endif - space_bounds = font->bounds.rows[0]->per_char + 0x20; + space_bounds = font->bounds.rows[0] + 0x20; err = mac_query_char_extents (font->mac_style, 0x20, &font->ascent, &font->descent, space_bounds, @@ -7791,9 +7854,8 @@ XLoadQueryFont (Display *dpy, char *fontname) mac_unload_font (&one_mac_display_info, font); return NULL; } - XCHARSTRUCTROW_SET_CHAR_VALID (font->bounds.rows[0], 0x20); - pcm = font->bounds.rows[0]->per_char; + pcm = font->bounds.rows[0]; for (c = 0x21; c <= 0xff; c++) { if (c == 0xad) @@ -7813,7 +7875,6 @@ XLoadQueryFont (Display *dpy, char *fontname) NULL #endif ); - XCHARSTRUCTROW_SET_CHAR_VALID (font->bounds.rows[0], c); #if USE_CG_TEXT_DRAWING if (font->cg_glyphs && font->cg_glyphs[c] == 0) @@ -9997,8 +10058,20 @@ XTread_socket (sd, expected, hold_quit) } break; +#if TARGET_API_MAC_CARBON + case inProxyIcon: + if (TrackWindowProxyDrag (window_ptr, er.where) + != errUserWantsToDragWindow) + break; + /* fall through */ +#endif case inDrag: #if TARGET_API_MAC_CARBON + if (IsWindowPathSelectClick (window_ptr, &er)) + { + WindowPathSelect (window_ptr, NULL, NULL); + break; + } DragWindow (window_ptr, er.where, NULL); #else /* not TARGET_API_MAC_CARBON */ DragWindow (window_ptr, er.where, &qd.screenBits.bounds); @@ -11049,7 +11122,11 @@ button will be mouse-3. */); doc: /* *If non-nil, allow anti-aliasing. The text will be rendered using Core Graphics text rendering which may anti-alias the text. */); +#if USE_CG_DRAWING + mac_use_core_graphics = 1; +#else mac_use_core_graphics = 0; +#endif /* Register an entry for `mac-roman' so that it can be used when creating the terminal frame on Mac OS 9 before loading -- 2.39.2