aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPo Lu2023-10-31 18:41:59 +0800
committerPo Lu2023-10-31 18:42:15 +0800
commitd3b0162b8020518e0a8dc7a21f95c20ded317a89 (patch)
tree1fea5b8a0bdad57e730e4439de6af5f2c2ed47bf
parentdd92ccc7ee12807bbc1c30f0d6576fad738bd104 (diff)
downloademacs-d3b0162b8020518e0a8dc7a21f95c20ded317a89.tar.gz
emacs-d3b0162b8020518e0a8dc7a21f95c20ded317a89.zip
Extract underline positions from PostScript metrics tables
* src/sfntfont.c (struct sfnt_font_desc): Introduce fields where the font's underline position is recorded. (sfnt_enum_font_1): Compute the underline position with information in the post table whenever it exists. (sfntfont_open): Scale the recorded position and save it into the font object.
-rw-r--r--src/sfntfont.c37
1 files changed, 30 insertions, 7 deletions
diff --git a/src/sfntfont.c b/src/sfntfont.c
index 8d87df477ea..822e4b20ee7 100644
--- a/src/sfntfont.c
+++ b/src/sfntfont.c
@@ -136,9 +136,6 @@ struct sfnt_font_desc
136 present in the font. */ 136 present in the font. */
137 Lisp_Object char_cache; 137 Lisp_Object char_cache;
138 138
139 /* Whether or not the character map can't be used by Emacs. */
140 bool cmap_invalid;
141
142 /* The header of the cmap being used. May be invalid, in which case 139 /* The header of the cmap being used. May be invalid, in which case
143 platform_id will be 500. */ 140 platform_id will be 500. */
144 struct sfnt_cmap_encoding_subtable subtable; 141 struct sfnt_cmap_encoding_subtable subtable;
@@ -146,6 +143,9 @@ struct sfnt_font_desc
146 /* The offset of the table directory within PATH. */ 143 /* The offset of the table directory within PATH. */
147 off_t offset; 144 off_t offset;
148 145
146 /* List of font tables. */
147 struct sfnt_font_tables *tables;
148
149 /* The number of glyphs in this font. Used to catch invalid cmap 149 /* The number of glyphs in this font. Used to catch invalid cmap
150 tables. This is actually the number of glyphs - 1. */ 150 tables. This is actually the number of glyphs - 1. */
151 int num_glyphs; 151 int num_glyphs;
@@ -153,8 +153,15 @@ struct sfnt_font_desc
153 /* The number of references to the font tables below. */ 153 /* The number of references to the font tables below. */
154 int refcount; 154 int refcount;
155 155
156 /* List of font tables. */ 156 /* The underline position and thickness if a post table supplies
157 struct sfnt_font_tables *tables; 157 this information. */
158 sfnt_fword underline_position, underline_thickness;
159
160 /* Whether an underline position is available. */
161 bool_bf underline_position_set : 1;
162
163 /* Whether or not the character map can't be used by Emacs. */
164 bool cmap_invalid : 1;
158}; 165};
159 166
160/* List of fonts. */ 167/* List of fonts. */
@@ -1050,6 +1057,9 @@ sfnt_enum_font_1 (int fd, const char *file,
1050 if (post) 1057 if (post)
1051 { 1058 {
1052 desc->spacing = (post->is_fixed_pitch ? 100 : 0); 1059 desc->spacing = (post->is_fixed_pitch ? 100 : 0);
1060 desc->underline_position = post->underline_position;
1061 desc->underline_thickness = post->underline_thickness;
1062 desc->underline_position_set = true;
1053 xfree (post); 1063 xfree (post);
1054 } 1064 }
1055 else 1065 else
@@ -3267,8 +3277,21 @@ sfntfont_open (struct frame *f, Lisp_Object font_entity,
3267 font_info->font.relative_compose = 0; 3277 font_info->font.relative_compose = 0;
3268 font_info->font.default_ascent = 0; 3278 font_info->font.default_ascent = 0;
3269 font_info->font.vertical_centering = 0; 3279 font_info->font.vertical_centering = 0;
3270 font_info->font.underline_position = -1; 3280
3271 font_info->font.underline_thickness = 0; 3281 if (!desc->underline_position_set)
3282 {
3283 font_info->font.underline_position = -1;
3284 font_info->font.underline_thickness = 0;
3285 }
3286 else
3287 {
3288 font_info->font.underline_position
3289 = sfnt_coerce_fixed (SFNT_CEIL_FIXED (-desc->underline_position
3290 * font_info->scale));
3291 font_info->font.underline_thickness
3292 = sfnt_coerce_fixed (SFNT_CEIL_FIXED (desc->underline_thickness
3293 * font_info->scale));
3294 }
3272 3295
3273 /* Now try to set up grid fitting for this font. */ 3296 /* Now try to set up grid fitting for this font. */
3274 dpyinfo = FRAME_DISPLAY_INFO (f); 3297 dpyinfo = FRAME_DISPLAY_INFO (f);