From: Dmitry Antipov Date: Mon, 25 Aug 2014 07:00:42 +0000 (+0400) Subject: One more minor cleanup of font subsystem. X-Git-Tag: emacs-25.0.90~2635^2~679^2~437 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=8661ebaa6c0ef3f9517c5288855657b274c723d6;p=emacs.git One more minor cleanup of font subsystem. * font.h (struct font_driver): Convert text_extents to return void because returned value is never actually used. * macfont.c (macfont_text_extents): * w32font.c (w32font_text_extents): * xftfont.c (xftfont_text_extents): Adjust to return void and assume that 'metrics' argument is always non-NULL. * ftfont.c (ftfont_text_extents): * xfont.c (xfont_text_extents): Likewise. Avoid redundant memset. --- diff --git a/src/ChangeLog b/src/ChangeLog index 9b70b8f5411..efd469ad053 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,15 @@ +2014-08-25 Dmitry Antipov + + One more minor cleanup of font subsystem. + * font.h (struct font_driver): Convert text_extents to + return void because returned value is never actually used. + * macfont.c (macfont_text_extents): + * w32font.c (w32font_text_extents): + * xftfont.c (xftfont_text_extents): Adjust to return void + and assume that 'metrics' argument is always non-NULL. + * ftfont.c (ftfont_text_extents): + * xfont.c (xfont_text_extents): Likewise. Avoid redundant memset. + 2014-08-25 Paul Eggert Minor cleanups of str_collate fix (Bug#18051). diff --git a/src/font.h b/src/font.h index cffc035cd49..52783419ebe 100644 --- a/src/font.h +++ b/src/font.h @@ -570,9 +570,9 @@ struct font_driver /* Compute the total metrics of the NGLYPHS glyphs specified by the font FONT and the sequence of glyph codes CODE, and store the result in METRICS. */ - int (*text_extents) (struct font *font, - unsigned *code, int nglyphs, - struct font_metrics *metrics); + void (*text_extents) (struct font *font, + unsigned *code, int nglyphs, + struct font_metrics *metrics); #ifdef HAVE_WINDOW_SYSTEM diff --git a/src/ftfont.c b/src/ftfont.c index 419274a30aa..1cad158065b 100644 --- a/src/ftfont.c +++ b/src/ftfont.c @@ -499,8 +499,8 @@ static Lisp_Object ftfont_open (struct frame *, Lisp_Object, int); static void ftfont_close (struct font *); static int ftfont_has_char (Lisp_Object, int); static unsigned ftfont_encode_char (struct font *, int); -static int ftfont_text_extents (struct font *, unsigned *, int, - struct font_metrics *); +static void ftfont_text_extents (struct font *, unsigned *, int, + struct font_metrics *); static int ftfont_get_bitmap (struct font *, unsigned, struct font_bitmap *, int); static int ftfont_anchor_point (struct font *, unsigned, int, @@ -1371,19 +1371,18 @@ ftfont_encode_char (struct font *font, int c) return (code > 0 ? code : FONT_INVALID_CODE); } -static int -ftfont_text_extents (struct font *font, unsigned int *code, int nglyphs, struct font_metrics *metrics) +static void +ftfont_text_extents (struct font *font, unsigned int *code, + int nglyphs, struct font_metrics *metrics) { struct ftfont_info *ftfont_info = (struct ftfont_info *) font; FT_Face ft_face = ftfont_info->ft_size->face; - int width = 0; - int i; + int i, width = 0; bool first; if (ftfont_info->ft_size != ft_face->size) FT_Activate_Size (ftfont_info->ft_size); - if (metrics) - memset (metrics, 0, sizeof (struct font_metrics)); + for (i = 0, first = 1; i < nglyphs; i++) { if (FT_Load_Glyph (ft_face, code[i], FT_LOAD_DEFAULT) == 0) @@ -1392,39 +1391,28 @@ ftfont_text_extents (struct font *font, unsigned int *code, int nglyphs, struct if (first) { - if (metrics) - { - metrics->lbearing = m->horiBearingX >> 6; - metrics->rbearing = (m->horiBearingX + m->width) >> 6; - metrics->ascent = m->horiBearingY >> 6; - metrics->descent = (m->height - m->horiBearingY) >> 6; - } + metrics->lbearing = m->horiBearingX >> 6; + metrics->rbearing = (m->horiBearingX + m->width) >> 6; + metrics->ascent = m->horiBearingY >> 6; + metrics->descent = (m->height - m->horiBearingY) >> 6; first = 0; } - if (metrics) - { - if (metrics->lbearing > width + (m->horiBearingX >> 6)) - metrics->lbearing = width + (m->horiBearingX >> 6); - if (metrics->rbearing - < width + ((m->horiBearingX + m->width) >> 6)) - metrics->rbearing - = width + ((m->horiBearingX + m->width) >> 6); - if (metrics->ascent < (m->horiBearingY >> 6)) - metrics->ascent = m->horiBearingY >> 6; - if (metrics->descent > ((m->height - m->horiBearingY) >> 6)) - metrics->descent = (m->height - m->horiBearingY) >> 6; - } + if (metrics->lbearing > width + (m->horiBearingX >> 6)) + metrics->lbearing = width + (m->horiBearingX >> 6); + if (metrics->rbearing + < width + ((m->horiBearingX + m->width) >> 6)) + metrics->rbearing + = width + ((m->horiBearingX + m->width) >> 6); + if (metrics->ascent < (m->horiBearingY >> 6)) + metrics->ascent = m->horiBearingY >> 6; + if (metrics->descent > ((m->height - m->horiBearingY) >> 6)) + metrics->descent = (m->height - m->horiBearingY) >> 6; width += m->horiAdvance >> 6; } else - { - width += font->space_width; - } + width += font->space_width; } - if (metrics) - metrics->width = width; - - return width; + metrics->width = width; } static int diff --git a/src/macfont.m b/src/macfont.m index 0d702873220..4bc58229d6e 100644 --- a/src/macfont.m +++ b/src/macfont.m @@ -1553,8 +1553,8 @@ static Lisp_Object macfont_open (struct frame *, Lisp_Object, int); static void macfont_close (struct font *); static int macfont_has_char (Lisp_Object, int); static unsigned macfont_encode_char (struct font *, int); -static int macfont_text_extents (struct font *, unsigned int *, int, - struct font_metrics *); +static void macfont_text_extents (struct font *, unsigned int *, int, + struct font_metrics *); static int macfont_draw (struct glyph_string *, int, int, int, int, bool); static Lisp_Object macfont_shape (Lisp_Object); static int macfont_variation_glyphs (struct font *, int c, @@ -2653,9 +2653,9 @@ macfont_encode_char (struct font *font, int c) return glyph != kCGFontIndexInvalid ? glyph : FONT_INVALID_CODE; } -static int -macfont_text_extents (struct font *font, unsigned int *code, int nglyphs, - struct font_metrics *metrics) +static void +macfont_text_extents (struct font *font, unsigned int *code, + int nglyphs, struct font_metrics *metrics) { int width, i; @@ -2664,28 +2664,21 @@ macfont_text_extents (struct font *font, unsigned int *code, int nglyphs, for (i = 1; i < nglyphs; i++) { struct font_metrics m; - int w = macfont_glyph_extents (font, code[i], metrics ? &m : NULL, - NULL, 0); - - if (metrics) - { - if (width + m.lbearing < metrics->lbearing) - metrics->lbearing = width + m.lbearing; - if (width + m.rbearing > metrics->rbearing) - metrics->rbearing = width + m.rbearing; - if (m.ascent > metrics->ascent) - metrics->ascent = m.ascent; - if (m.descent > metrics->descent) - metrics->descent = m.descent; - } + int w = macfont_glyph_extents (font, code[i], &m, NULL, 0); + + if (width + m.lbearing < metrics->lbearing) + metrics->lbearing = width + m.lbearing; + if (width + m.rbearing > metrics->rbearing) + metrics->rbearing = width + m.rbearing; + if (m.ascent > metrics->ascent) + metrics->ascent = m.ascent; + if (m.descent > metrics->descent) + metrics->descent = m.descent; width += w; } unblock_input (); - if (metrics) - metrics->width = width; - - return width; + metrics->width = width; } static int diff --git a/src/nsfont.m b/src/nsfont.m index 98c25fcdedd..202ebe10c97 100644 --- a/src/nsfont.m +++ b/src/nsfont.m @@ -627,8 +627,8 @@ static Lisp_Object nsfont_open (struct frame *f, Lisp_Object font_entity, static void nsfont_close (struct font *font); static int nsfont_has_char (Lisp_Object entity, int c); static unsigned int nsfont_encode_char (struct font *font, int c); -static int nsfont_text_extents (struct font *font, unsigned int *code, - int nglyphs, struct font_metrics *metrics); +static void nsfont_text_extents (struct font *font, unsigned int *code, + int nglyphs, struct font_metrics *metrics); static int nsfont_draw (struct glyph_string *s, int from, int to, int x, int y, bool with_background); @@ -988,9 +988,9 @@ nsfont_encode_char (struct font *font, int c) /* Perform the size computation of glyphs of FONT and fill in members of METRICS. The glyphs are specified by their glyph codes in CODE (length NGLYPHS). */ -static int -nsfont_text_extents (struct font *font, unsigned int *code, int nglyphs, - struct font_metrics *metrics) +static void +nsfont_text_extents (struct font *font, unsigned int *code, + int nglyphs, struct font_metrics *metrics) { struct nsfont_info *font_info = (struct nsfont_info *)font; struct font_metrics *pcm; @@ -1000,7 +1000,7 @@ nsfont_text_extents (struct font *font, unsigned int *code, int nglyphs, memset (metrics, 0, sizeof (struct font_metrics)); - for (i =0; iwidth = totalWidth; - - return totalWidth; /* not specified in doc, but xfont.c does it */ } diff --git a/src/w32font.c b/src/w32font.c index 81e25eb0856..de0732dd4da 100644 --- a/src/w32font.c +++ b/src/w32font.c @@ -473,7 +473,7 @@ w32font_encode_char (struct font *font, int c) of METRICS. The glyphs are specified by their glyph codes in CODE (length NGLYPHS). Apparently metrics can be NULL, in this case just return the overall width. */ -int +void w32font_text_extents (struct font *font, unsigned *code, int nglyphs, struct font_metrics *metrics) { @@ -487,84 +487,80 @@ w32font_text_extents (struct font *font, unsigned *code, struct w32font_info *w32_font = (struct w32font_info *) font; - if (metrics) - { - memset (metrics, 0, sizeof (struct font_metrics)); - metrics->ascent = font->ascent; - metrics->descent = font->descent; - - for (i = 0; i < nglyphs; i++) - { - struct w32_metric_cache *char_metric; - int block = *(code + i) / CACHE_BLOCKSIZE; - int pos_in_block = *(code + i) % CACHE_BLOCKSIZE; + memset (metrics, 0, sizeof (struct font_metrics)); + metrics->ascent = font->ascent; + metrics->descent = font->descent; - if (block >= w32_font->n_cache_blocks) - { - if (!w32_font->cached_metrics) - w32_font->cached_metrics - = xmalloc ((block + 1) - * sizeof (struct w32_metric_cache *)); - else - w32_font->cached_metrics - = xrealloc (w32_font->cached_metrics, - (block + 1) - * sizeof (struct w32_metric_cache *)); - memset (w32_font->cached_metrics + w32_font->n_cache_blocks, 0, - ((block + 1 - w32_font->n_cache_blocks) - * sizeof (struct w32_metric_cache *))); - w32_font->n_cache_blocks = block + 1; - } + for (i = 0; i < nglyphs; i++) + { + struct w32_metric_cache *char_metric; + int block = *(code + i) / CACHE_BLOCKSIZE; + int pos_in_block = *(code + i) % CACHE_BLOCKSIZE; - if (!w32_font->cached_metrics[block]) - { - w32_font->cached_metrics[block] - = xzalloc (CACHE_BLOCKSIZE * sizeof (struct w32_metric_cache)); - } + if (block >= w32_font->n_cache_blocks) + { + if (!w32_font->cached_metrics) + w32_font->cached_metrics + = xmalloc ((block + 1) + * sizeof (struct w32_metric_cache *)); + else + w32_font->cached_metrics + = xrealloc (w32_font->cached_metrics, + (block + 1) + * sizeof (struct w32_metric_cache *)); + memset (w32_font->cached_metrics + w32_font->n_cache_blocks, 0, + ((block + 1 - w32_font->n_cache_blocks) + * sizeof (struct w32_metric_cache *))); + w32_font->n_cache_blocks = block + 1; + } - char_metric = w32_font->cached_metrics[block] + pos_in_block; + if (!w32_font->cached_metrics[block]) + { + w32_font->cached_metrics[block] + = xzalloc (CACHE_BLOCKSIZE * sizeof (struct w32_metric_cache)); + } - if (char_metric->status == W32METRIC_NO_ATTEMPT) - { - if (dc == NULL) - { - /* TODO: Frames can come and go, and their fonts - outlive them. So we can't cache the frame in the - font structure. Use selected_frame until the API - is updated to pass in a frame. */ - f = XFRAME (selected_frame); - - dc = get_frame_dc (f); - old_font = SelectObject (dc, w32_font->hfont); - } - compute_metrics (dc, w32_font, *(code + i), char_metric); - } + char_metric = w32_font->cached_metrics[block] + pos_in_block; - if (char_metric->status == W32METRIC_SUCCESS) + if (char_metric->status == W32METRIC_NO_ATTEMPT) + { + if (dc == NULL) { - metrics->lbearing = min (metrics->lbearing, - metrics->width + char_metric->lbearing); - metrics->rbearing = max (metrics->rbearing, - metrics->width + char_metric->rbearing); - metrics->width += char_metric->width; + /* TODO: Frames can come and go, and their fonts + outlive them. So we can't cache the frame in the + font structure. Use selected_frame until the API + is updated to pass in a frame. */ + f = XFRAME (selected_frame); + + dc = get_frame_dc (f); + old_font = SelectObject (dc, w32_font->hfont); } - else - /* If we couldn't get metrics for a char, - use alternative method. */ - break; + compute_metrics (dc, w32_font, *(code + i), char_metric); } - /* If we got through everything, return. */ - if (i == nglyphs) - { - if (dc != NULL) - { - /* Restore state and release DC. */ - SelectObject (dc, old_font); - release_frame_dc (f, dc); - } - return metrics->width; - } + if (char_metric->status == W32METRIC_SUCCESS) + { + metrics->lbearing = min (metrics->lbearing, + metrics->width + char_metric->lbearing); + metrics->rbearing = max (metrics->rbearing, + metrics->width + char_metric->rbearing); + metrics->width += char_metric->width; + } + else + /* If we couldn't get metrics for a char, + use alternative method. */ + break; + } + /* If we got through everything, return. */ + if (i == nglyphs) + { + if (dc != NULL) + { + /* Restore state and release DC. */ + SelectObject (dc, old_font); + release_frame_dc (f, dc); + } + return; } /* For non-truetype fonts, GetGlyphOutlineW is not supported, so @@ -620,18 +616,13 @@ w32font_text_extents (struct font *font, unsigned *code, } /* Give our best estimate of the metrics, based on what we know. */ - if (metrics) - { - metrics->width = total_width - w32_font->metrics.tmOverhang; - metrics->lbearing = 0; - metrics->rbearing = total_width; - } + metrics->width = total_width - w32_font->metrics.tmOverhang; + metrics->lbearing = 0; + metrics->rbearing = total_width; /* Restore state and release DC. */ SelectObject (dc, old_font); release_frame_dc (f, dc); - - return total_width; } /* w32 implementation of draw for font backend. diff --git a/src/w32font.h b/src/w32font.h index 1be49bb91c2..5ce3ac7a5f9 100644 --- a/src/w32font.h +++ b/src/w32font.h @@ -74,8 +74,8 @@ int w32font_open_internal (struct frame *f, Lisp_Object font_entity, int pixel_size, Lisp_Object font_object); void w32font_close (struct font *font); int w32font_has_char (Lisp_Object entity, int c); -int w32font_text_extents (struct font *font, unsigned *code, int nglyphs, - struct font_metrics *metrics); +void w32font_text_extents (struct font *font, unsigned *code, int nglyphs, + struct font_metrics *metrics); int w32font_draw (struct glyph_string *s, int from, int to, int x, int y, bool with_background); diff --git a/src/w32uniscribe.c b/src/w32uniscribe.c index d06586f973a..7e6419c4d28 100644 --- a/src/w32uniscribe.c +++ b/src/w32uniscribe.c @@ -591,8 +591,8 @@ uniscribe_encode_char (struct font *font, int c) Lisp_Object uniscribe_get_cache (Lisp_Object frame); void uniscribe_free_entity (Lisp_Object font_entity); int uniscribe_has_char (Lisp_Object entity, int c); - int uniscribe_text_extents (struct font *font, unsigned *code, - int nglyphs, struct font_metrics *metrics); + void uniscribe_text_extents (struct font *font, unsigned *code, + int nglyphs, struct font_metrics *metrics); int uniscribe_draw (struct glyph_string *s, int from, int to, int x, int y, int with_background); diff --git a/src/xfont.c b/src/xfont.c index 8996783541b..c39c8455aa5 100644 --- a/src/xfont.c +++ b/src/xfont.c @@ -124,8 +124,8 @@ static void xfont_close (struct font *); static void xfont_prepare_face (struct frame *, struct face *); static int xfont_has_char (Lisp_Object, int); static unsigned xfont_encode_char (struct font *, int); -static int xfont_text_extents (struct font *, unsigned *, int, - struct font_metrics *); +static void xfont_text_extents (struct font *, unsigned *, int, + struct font_metrics *); static int xfont_draw (struct glyph_string *, int, int, int, int, bool); static int xfont_check (struct frame *, struct font *); @@ -975,15 +975,14 @@ xfont_encode_char (struct font *font, int c) return (xfont_get_pcm (xfont, &char2b) ? code : FONT_INVALID_CODE); } -static int -xfont_text_extents (struct font *font, unsigned int *code, int nglyphs, struct font_metrics *metrics) +static void +xfont_text_extents (struct font *font, unsigned int *code, + int nglyphs, struct font_metrics *metrics) { XFontStruct *xfont = ((struct xfont_info *) font)->xfont; - int width = 0; - int i, first; + int i, width = 0; + bool first; - if (metrics) - memset (metrics, 0, sizeof (struct font_metrics)); for (i = 0, first = 1; i < nglyphs; i++) { XChar2b char2b; @@ -997,34 +996,27 @@ xfont_text_extents (struct font *font, unsigned int *code, int nglyphs, struct f continue; if (first) { - if (metrics) - { - metrics->lbearing = pcm->lbearing; - metrics->rbearing = pcm->rbearing; - metrics->ascent = pcm->ascent; - metrics->descent = pcm->descent; - } + metrics->lbearing = pcm->lbearing; + metrics->rbearing = pcm->rbearing; + metrics->ascent = pcm->ascent; + metrics->descent = pcm->descent; first = 0; } else { - if (metrics) - { - if (metrics->lbearing > width + pcm->lbearing) - metrics->lbearing = width + pcm->lbearing; - if (metrics->rbearing < width + pcm->rbearing) - metrics->rbearing = width + pcm->rbearing; - if (metrics->ascent < pcm->ascent) - metrics->ascent = pcm->ascent; - if (metrics->descent < pcm->descent) - metrics->descent = pcm->descent; - } + if (metrics->lbearing > width + pcm->lbearing) + metrics->lbearing = width + pcm->lbearing; + if (metrics->rbearing < width + pcm->rbearing) + metrics->rbearing = width + pcm->rbearing; + if (metrics->ascent < pcm->ascent) + metrics->ascent = pcm->ascent; + if (metrics->descent < pcm->descent) + metrics->descent = pcm->descent; } width += pcm->width; } - if (metrics) - metrics->width = width; - return width; + + metrics->width = width; } static int diff --git a/src/xftfont.c b/src/xftfont.c index 9726a3b9911..0a883a7b87b 100644 --- a/src/xftfont.c +++ b/src/xftfont.c @@ -557,8 +557,9 @@ xftfont_encode_char (struct font *font, int c) return (code ? code : FONT_INVALID_CODE); } -static int -xftfont_text_extents (struct font *font, unsigned int *code, int nglyphs, struct font_metrics *metrics) +static void +xftfont_text_extents (struct font *font, unsigned int *code, + int nglyphs, struct font_metrics *metrics) { struct xftfont_info *xftfont_info = (struct xftfont_info *) font; XGlyphInfo extents; @@ -567,15 +568,12 @@ xftfont_text_extents (struct font *font, unsigned int *code, int nglyphs, struct XftGlyphExtents (xftfont_info->display, xftfont_info->xftfont, code, nglyphs, &extents); unblock_input (); - if (metrics) - { - metrics->lbearing = - extents.x; - metrics->rbearing = - extents.x + extents.width; - metrics->width = extents.xOff; - metrics->ascent = extents.y; - metrics->descent = extents.height - extents.y; - } - return extents.xOff; + + metrics->lbearing = - extents.x; + metrics->rbearing = - extents.x + extents.width; + metrics->width = extents.xOff; + metrics->ascent = extents.y; + metrics->descent = extents.height - extents.y; } static XftDraw *