aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Zaretskii2014-12-18 18:07:26 +0200
committerEli Zaretskii2014-12-18 18:07:26 +0200
commitb1978229162b0d4c3b14d8ad8bff383eb3511969 (patch)
treed441fe077f75d8b962a24536edcc09f7af65a26d
parent687ae680bd12b0353e313808253e7a07c0828ebe (diff)
downloademacs-b1978229162b0d4c3b14d8ad8bff383eb3511969.tar.gz
emacs-b1978229162b0d4c3b14d8ad8bff383eb3511969.zip
Allow querying font by name for its height and other info. (Bug#19395)
src/font.c (Ffont_info): Add more font information to the vector returned by the function, inspired by query-font. Doc fix. doc/lispref/display.texi (Low-Level Font): Document font-info and query-font. lisp/international/mule-diag.el (describe-font-internal): Display additional info returned by font-info. lisp/linum.el (linum--face-width): Rename from linum--face-height, and use the new functionality of font-info. (linum-update-window): Use linum--face-width and frame-char-width, instead of approximating with height. etc/NEWS: Mention the enhancement in font-info.
-rw-r--r--doc/lispref/ChangeLog4
-rw-r--r--doc/lispref/display.texi124
-rw-r--r--etc/NEWS26
-rw-r--r--lisp/ChangeLog10
-rw-r--r--lisp/international/mule-diag.el10
-rw-r--r--lisp/linum.el15
-rw-r--r--src/ChangeLog6
-rw-r--r--src/font.c47
8 files changed, 217 insertions, 25 deletions
diff --git a/doc/lispref/ChangeLog b/doc/lispref/ChangeLog
index a48289c3b80..7424ab07cdf 100644
--- a/doc/lispref/ChangeLog
+++ b/doc/lispref/ChangeLog
@@ -1,3 +1,7 @@
12014-12-18 Eli Zaretskii <eliz@gnu.org>
2
3 * display.texi (Low-Level Font): Document font-info and query-font.
4
12014-12-16 Nicolas Petton <petton.nicolas@gmail.com> 52014-12-16 Nicolas Petton <petton.nicolas@gmail.com>
2 6
3 * sequences.texi (Seq Library): Add documentation for seq.el. 7 * sequences.texi (Seq Library): Add documentation for seq.el.
diff --git a/doc/lispref/display.texi b/doc/lispref/display.texi
index 90aa9797a59..48860c8ebef 100644
--- a/doc/lispref/display.texi
+++ b/doc/lispref/display.texi
@@ -3349,9 +3349,9 @@ The script that the font must support (a symbol).
3349@item :otf 3349@item :otf
3350@cindex OpenType font 3350@cindex OpenType font
3351The font must be an OpenType font that supports these OpenType 3351The font must be an OpenType font that supports these OpenType
3352features, provided Emacs is compiled with support for @samp{libotf} (a 3352features, provided Emacs is compiled with a library, such as
3353library for performing complex text layout in certain scripts). The 3353@samp{libotf} on GNU/Linux, that supports complex text layout for
3354value must be a list of the form 3354scripts which need that. The value must be a list of the form
3355 3355
3356@smallexample 3356@smallexample
3357@code{(@var{script-tag} @var{langsys-tag} @var{gsub} @var{gpos})} 3357@code{(@var{script-tag} @var{langsys-tag} @var{gsub} @var{gpos})}
@@ -3450,6 +3450,124 @@ If the optional argument @var{fold-wildcards} is non-@code{nil},
3450consecutive wildcards in the XLFD are folded into one. 3450consecutive wildcards in the XLFD are folded into one.
3451@end defun 3451@end defun
3452 3452
3453The following two functions return important information about a font.
3454
3455@defun font-info name &optional frame
3456This function returns information about a font specified by its
3457@var{name}, a string, as it is used on @var{frame}. If @var{frame} is
3458omitted or @code{nil}, it defaults to the selected frame.
3459
3460The value returned by the function is a vector of the form
3461@code{[@var{opened-name} @var{full-name} @var{size} @var{height}
3462@var{baseline-offset} @var{relative-compose} @var{default-ascent}
3463@var{max-width} @var{ascent} @var{descent} @var{space-width}
3464@var{average-width} @var{filename} @var{capability}]}. Here's the
3465description of each components of this vector:
3466
3467@table @var
3468@item opened-name
3469The name used to open the font, a string.
3470
3471@item full-name
3472The full name of the font, a string.
3473
3474@item size
3475The pixel size of the font.
3476
3477@item height
3478The height of the font in pixels.
3479
3480@item baseline-offset
3481The offset in pixels from the @acronym{ASCII} baseline, positive
3482upward.
3483
3484@item relative-compose
3485@itemx default-ascent
3486Numbers controlling how to compose characters.
3487
3488@item ascent
3489@itemx descent
3490The ascent and descent of this font. The sum of these two numbers
3491should be equal to the value of @var{height} above.
3492
3493@item space-width
3494The width, in pixels, of the font's space character.
3495
3496@item average-width
3497The average width of the font characters. If this is zero, Emacs uses
3498the value of @var{space-width} instead, when it calculates text layout
3499on display.
3500
3501@item filename
3502The file name of the font as a string. This can be @code{nil} if the
3503font back-end does not provide a way to find out the font's file name.
3504
3505@item capability
3506A list whose first element is a symbol representing the font type, one
3507of @code{x}, @code{opentype}, @code{truetype}, @code{type1},
3508@code{pcf}, or @code{bdf}. For OpenType fonts, the list includes 2
3509additional elements describing the @sc{gsub} and @sc{gpos} features
3510supported by the font. Each of these elements is a list of the form
3511@code{((@var{script} (@var{langsys} @var{feature} @dots{}) @dots{})
3512@dots{})}, where @var{script} is a symbol representing an OpenType
3513script tag, @var{langsys} is a symbol representing an OpenType langsys
3514tag (or @code{nil}, which stands for the default langsys), and each
3515@var{feature} is a symbol representing an OpenType feature tag.
3516@end table
3517@end defun
3518
3519@defun query-font font-object
3520This function returns information about a @var{font-object}. (This is
3521in contrast to @code{font-info}, which takes the font name, a string,
3522as its argument.)
3523
3524The value returned by the function is a vector of the form
3525@code{[@var{name} @var{filename} @var{pixel-size} @var{max-width}
3526@var{ascent} @var{descent} @var{space-width} @var{average-width}
3527@var{capability}]}. Here's the description of each components of this
3528vector:
3529
3530@table @var
3531@item name
3532The font name, a string.
3533
3534@item filename
3535The file name of the font as a string. This can be @code{nil} if the
3536font back-end does not provide a way to find out the font's file name.
3537
3538@item pixel-size
3539The pixel size of the font used to open the font.
3540
3541@item max-width
3542The maximum advance width of the font.
3543
3544@item ascent
3545@itemx descent
3546The ascent and descent of this font. The sum of these two numbers
3547gives the font height.
3548
3549@item space-width
3550The width, in pixels, of the font's space character.
3551
3552@item average-width
3553The average width of the font characters. If this is zero, Emacs uses
3554the value of @var{space-width} instead, when it calculates text layout
3555on display.
3556
3557@item capability
3558A list whose first element is a symbol representing the font type, one
3559of @code{x}, @code{opentype}, @code{truetype}, @code{type1},
3560@code{pcf}, or @code{bdf}. For OpenType fonts, the list includes 2
3561additional elements describing the @sc{gsub} and @sc{gpos} features
3562supported by the font. Each of these elements is a list of the form
3563@code{((@var{script} (@var{langsys} @var{feature} @dots{}) @dots{})
3564@dots{})}, where @var{script} is a symbol representing an OpenType
3565script tag, @var{langsys} is a symbol representing an OpenType langsys
3566tag (or @code{nil}, which stands for the default langsys), and each
3567@var{feature} is a symbol representing an OpenType feature tag.
3568@end table
3569@end defun
3570
3453@node Fringes 3571@node Fringes
3454@section Fringes 3572@section Fringes
3455@cindex fringes 3573@cindex fringes
diff --git a/etc/NEWS b/etc/NEWS
index a17cef62998..865ae074ae8 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -108,6 +108,17 @@ environment. For the time being this is implemented for modern POSIX
108systems and for MS-Windows, for other systems they fall back to their 108systems and for MS-Windows, for other systems they fall back to their
109counterparts `string-lessp' and `string-equal'. 109counterparts `string-lessp' and `string-equal'.
110 110
111*** The ls-lisp package uses `string-collate-lessp' to sort file names.
112If you want the old, locale-independent sorting, customize the new
113option `ls-lisp-use-string-collate' to a nil value.
114
115*** The MS-Windows specific variable `w32-collate-ignore-punctuation',
116if set to a non-nil value, causes the above 2 functions to ignore
117symbol and punctuation characters when collating strings. This
118emulates the behavior of modern Posix platforms when the locale's
119codeset is "UTF-8" (as in "en_US.UTF-8"). This is needed because
120MS-Windows doesn't support UTF-8 as codeset in its locales.
121
111+++ 122+++
112** The new function `bidi-find-overridden-directionality' allows to 123** The new function `bidi-find-overridden-directionality' allows to
113find characters whose directionality was, perhaps maliciously, 124find characters whose directionality was, perhaps maliciously,
@@ -122,17 +133,6 @@ the visual appearance both of the copied text and the text at
122destination, even when the copied text includes mixed bidirectional 133destination, even when the copied text includes mixed bidirectional
123text and directional control characters. 134text and directional control characters.
124 135
125*** The ls-lisp package uses `string-collate-lessp' to sort file names.
126If you want the old, locale-independent sorting, customize the new
127option `ls-lisp-use-string-collate' to a nil value.
128
129*** The MS-Windows specific variable `w32-collate-ignore-punctuation',
130if set to a non-nil value, causes the above 2 functions to ignore
131symbol and punctuation characters when collating strings. This
132emulates the behavior of modern Posix platforms when the locale's
133codeset is "UTF-8" (as in "en_US.UTF-8"). This is needed because
134MS-Windows doesn't support UTF-8 as codeset in its locales.
135
136** New variable `ns-use-fullscreen-animation' controls animation for 136** New variable `ns-use-fullscreen-animation' controls animation for
137non-native NS fullscreen. The default is nil. Set to t to enable 137non-native NS fullscreen. The default is nil. Set to t to enable
138animation when entering and leaving fullscreen. For native OSX fullscreen 138animation when entering and leaving fullscreen. For native OSX fullscreen
@@ -159,6 +159,10 @@ fontification during full screen scrolling operations, giving less
159hesitant operation during auto-repeat of C-v, M-v at the cost of 159hesitant operation during auto-repeat of C-v, M-v at the cost of
160possible inaccuracies in the end position. 160possible inaccuracies in the end position.
161 161
162** The function `font-info' now returns more details about a font.
163In particular, it now returns the average width of the font's
164characters, which can be used for geometry-related calculations.
165
162 166
163* Editing Changes in Emacs 25.1 167* Editing Changes in Emacs 25.1
164 168
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 89a92f6454f..cb8348e1d51 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,13 @@
12014-12-18 Eli Zaretskii <eliz@gnu.org>
2
3 * international/mule-diag.el (describe-font-internal): Display
4 additional info returned by font-info.
5
6 * linum.el (linum--face-width): Rename from linum--face-height,
7 and use the new functionality of font-info.
8 (linum-update-window): Use linum--face-width and frame-char-width,
9 instead of approximating with height.
10
12014-12-18 Dmitry Gutov <dgutov@yandex.ru> 112014-12-18 Dmitry Gutov <dgutov@yandex.ru>
2 12
3 * vc/vc-svn.el (vc-svn-dir-status-files): Revert the 2014-12-02 13 * vc/vc-svn.el (vc-svn-dir-status-files): Revert the 2014-12-02
diff --git a/lisp/international/mule-diag.el b/lisp/international/mule-diag.el
index 13a178531bc..ead2decb771 100644
--- a/lisp/international/mule-diag.el
+++ b/lisp/international/mule-diag.el
@@ -825,10 +825,18 @@ but still contains full information about each coding system."
825The IGNORED argument is ignored." 825The IGNORED argument is ignored."
826 (print-list "name (opened by):" (aref font-info 0)) 826 (print-list "name (opened by):" (aref font-info 0))
827 (print-list " full name:" (aref font-info 1)) 827 (print-list " full name:" (aref font-info 1))
828 (and (aref font-info 12)
829 (print-list " file name:" (aref font-info 12)))
828 (print-list " size:" (format "%2d" (aref font-info 2))) 830 (print-list " size:" (format "%2d" (aref font-info 2)))
829 (print-list " height:" (format "%2d" (aref font-info 3))) 831 (print-list " height:" (format "%2d" (aref font-info 3)))
830 (print-list " baseline-offset:" (format "%2d" (aref font-info 4))) 832 (print-list " baseline-offset:" (format "%2d" (aref font-info 4)))
831 (print-list "relative-compose:" (format "%2d" (aref font-info 5)))) 833 (print-list "relative-compose:" (format "%2d" (aref font-info 5)))
834 (print-list " default-ascent:" (format "%2d" (aref font-info 6)))
835 (print-list " ascent:" (format "%2d" (aref font-info 8)))
836 (print-list " descent:" (format "%2d" (aref font-info 9)))
837 (print-list " average-width:" (format "%2d" (aref font-info 11)))
838 (print-list " space-width:" (format "%2d" (aref font-info 10)))
839 (print-list " max-width:" (format "%2d" (aref font-info 7))))
832 840
833;;;###autoload 841;;;###autoload
834(defun describe-font (fontname) 842(defun describe-font (fontname)
diff --git a/lisp/linum.el b/lisp/linum.el
index b13bd8dbbb6..fb2cda6c506 100644
--- a/lisp/linum.el
+++ b/lisp/linum.el
@@ -138,8 +138,13 @@ Linum mode is a buffer-local minor mode."
138 (mapc #'delete-overlay linum-available) 138 (mapc #'delete-overlay linum-available)
139 (setq linum-available nil)))) 139 (setq linum-available nil))))
140 140
141(defun linum--face-height (face) 141(defun linum--face-width (face)
142 (aref (font-info (face-font face)) 2)) 142 (let ((info (font-info (face-font face)))
143 width)
144 (setq width (aref info 11))
145 (if (<= width 0)
146 (setq width (aref info 10)))
147 width))
143 148
144(defun linum-update-window (win) 149(defun linum-update-window (win)
145 "Update line numbers for the portion visible in window WIN." 150 "Update line numbers for the portion visible in window WIN."
@@ -183,10 +188,8 @@ Linum mode is a buffer-local minor mode."
183 (setq line (1+ line))) 188 (setq line (1+ line)))
184 (when (display-graphic-p) 189 (when (display-graphic-p)
185 (setq width (ceiling 190 (setq width (ceiling
186 ;; We'd really want to check the widths rather than the 191 (/ (* width 1.0 (linum--face-width 'linum))
187 ;; heights, but it's a start. 192 (frame-char-width)))))
188 (/ (* width 1.0 (linum--face-height 'linum))
189 (frame-char-height)))))
190 (set-window-margins win width (cdr (window-margins win))))) 193 (set-window-margins win width (cdr (window-margins win)))))
191 194
192(defun linum-after-change (beg end _len) 195(defun linum-after-change (beg end _len)
diff --git a/src/ChangeLog b/src/ChangeLog
index 16e99aec99a..2b125d52723 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,9 @@
12014-12-18 Eli Zaretskii <eliz@gnu.org>
2
3 * font.c (Ffont_info): Add more font information to the vector
4 returned by the function, inspired by query-font. Doc fix.
5 (Bug#19395)
6
12014-12-18 Stefan Monnier <monnier@iro.umontreal.ca> 72014-12-18 Stefan Monnier <monnier@iro.umontreal.ca>
2 8
3 * keyboard.c (input_was_pending): New var. 9 * keyboard.c (input_was_pending): New var.
diff --git a/src/font.c b/src/font.c
index 70e63164a34..d10d2280a5b 100644
--- a/src/font.c
+++ b/src/font.c
@@ -4921,8 +4921,11 @@ If FRAME is omitted or nil, use the selected frame. */)
4921DEFUN ("font-info", Ffont_info, Sfont_info, 1, 2, 0, 4921DEFUN ("font-info", Ffont_info, Sfont_info, 1, 2, 0,
4922 doc: /* Return information about a font named NAME on frame FRAME. 4922 doc: /* Return information about a font named NAME on frame FRAME.
4923If FRAME is omitted or nil, use the selected frame. 4923If FRAME is omitted or nil, use the selected frame.
4924The returned value is a vector of OPENED-NAME, FULL-NAME, SIZE, 4924
4925 HEIGHT, BASELINE-OFFSET, RELATIVE-COMPOSE, and DEFAULT-ASCENT, 4925The returned value is a vector:
4926 [ OPENED-NAME FULL-NAME SIZE HEIGHT BASELINE-OFFSET RELATIVE-COMPOSE
4927 DEFAULT-ASCENT MAX-WIDTH ASCENT DESCENT SPACE-WIDTH AVERAGE-WIDTH
4928 CAPABILITY ]
4926where 4929where
4927 OPENED-NAME is the name used for opening the font, 4930 OPENED-NAME is the name used for opening the font,
4928 FULL-NAME is the full name of the font, 4931 FULL-NAME is the full name of the font,
@@ -4930,7 +4933,33 @@ where
4930 HEIGHT is the pixel-height of the font (i.e., ascent + descent), 4933 HEIGHT is the pixel-height of the font (i.e., ascent + descent),
4931 BASELINE-OFFSET is the upward offset pixels from ASCII baseline, 4934 BASELINE-OFFSET is the upward offset pixels from ASCII baseline,
4932 RELATIVE-COMPOSE and DEFAULT-ASCENT are the numbers controlling 4935 RELATIVE-COMPOSE and DEFAULT-ASCENT are the numbers controlling
4933 how to compose characters. 4936 how to compose characters,
4937 MAX-WIDTH is the maximum advance width of the font,
4938 ASCENT, DESCENT, SPACE-WIDTH, AVERAGE-WIDTH are metrics of the font
4939 in pixels,
4940 FILENAME is the font file name, a string (or nil if the font backend
4941 doesn't provide a file name).
4942 CAPABILITY is a list whose first element is a symbol representing the
4943 font format, one of x, opentype, truetype, type1, pcf, or bdf.
4944 The remaining elements describe the details of the font capabilities,
4945 as follows:
4946
4947 If the font is OpenType font, the form of the list is
4948 \(opentype GSUB GPOS)
4949 where GSUB shows which "GSUB" features the font supports, and GPOS
4950 shows which "GPOS" features the font supports. Both GSUB and GPOS are
4951 lists of the form:
4952 \((SCRIPT (LANGSYS FEATURE ...) ...) ...)
4953
4954 where
4955 SCRIPT is a symbol representing OpenType script tag.
4956 LANGSYS is a symbol representing OpenType langsys tag, or nil
4957 representing the default langsys.
4958 FEATURE is a symbol representing OpenType feature tag.
4959
4960 If the font is not an OpenType font, there are no elements
4961 in CAPABILITY except the font format symbol.
4962
4934If the named font is not yet loaded, return nil. */) 4963If the named font is not yet loaded, return nil. */)
4935 (Lisp_Object name, Lisp_Object frame) 4964 (Lisp_Object name, Lisp_Object frame)
4936{ 4965{
@@ -4966,7 +4995,7 @@ If the named font is not yet loaded, return nil. */)
4966 return Qnil; 4995 return Qnil;
4967 font = XFONT_OBJECT (font_object); 4996 font = XFONT_OBJECT (font_object);
4968 4997
4969 info = make_uninit_vector (7); 4998 info = make_uninit_vector (14);
4970 ASET (info, 0, AREF (font_object, FONT_NAME_INDEX)); 4999 ASET (info, 0, AREF (font_object, FONT_NAME_INDEX));
4971 ASET (info, 1, AREF (font_object, FONT_FULLNAME_INDEX)); 5000 ASET (info, 1, AREF (font_object, FONT_FULLNAME_INDEX));
4972 ASET (info, 2, make_number (font->pixel_size)); 5001 ASET (info, 2, make_number (font->pixel_size));
@@ -4974,6 +5003,16 @@ If the named font is not yet loaded, return nil. */)
4974 ASET (info, 4, make_number (font->baseline_offset)); 5003 ASET (info, 4, make_number (font->baseline_offset));
4975 ASET (info, 5, make_number (font->relative_compose)); 5004 ASET (info, 5, make_number (font->relative_compose));
4976 ASET (info, 6, make_number (font->default_ascent)); 5005 ASET (info, 6, make_number (font->default_ascent));
5006 ASET (info, 7, make_number (font->max_width));
5007 ASET (info, 8, make_number (font->ascent));
5008 ASET (info, 9, make_number (font->descent));
5009 ASET (info, 10, make_number (font->space_width));
5010 ASET (info, 11, make_number (font->average_width));
5011 ASET (info, 12, AREF (font_object, FONT_FILE_INDEX));
5012 if (font->driver->otf_capability)
5013 ASET (info, 13, Fcons (Qopentype, font->driver->otf_capability (font)));
5014 else
5015 ASET (info, 13, Qnil);
4977 5016
4978#if 0 5017#if 0
4979 /* As font_object is still in FONT_OBJLIST of the entity, we can't 5018 /* As font_object is still in FONT_OBJLIST of the entity, we can't