diff options
| author | YAMAMOTO Mitsuharu | 2019-07-01 16:58:53 +0900 |
|---|---|---|
| committer | YAMAMOTO Mitsuharu | 2019-07-01 16:58:53 +0900 |
| commit | 6cabb698f99a6b9e931cdac7347b18c44fde6041 (patch) | |
| tree | eaccdb78e9ca1103e55afc0939c93fc665f44700 /src | |
| parent | fd9ea1e511ba3b1f5d338c3fc8faf0b85df951f9 (diff) | |
| download | emacs-6cabb698f99a6b9e931cdac7347b18c44fde6041.tar.gz emacs-6cabb698f99a6b9e931cdac7347b18c44fde6041.zip | |
Implement the otf_capability method for HarfBuzz
* src/hbfont.c: Include hb-ot.h.
[HAVE_NTGUI]: Add DEF_DLL_FN and #define for hb_tag_to_string,
hb_font_get_face, hb_ot_layout_table_get_script_tags,
hb_ot_layout_table_get_feature_tags, hb_ot_layout_script_get_language_tags,
and hb_ot_layout_language_get_feature_tags.
(hbfont_init_w32_funcs) [HAVE_NTGUI]: Add LOAD_DLL_FN for them.
(hbfont_otf_features, hbfont_otf_capability): New functions.
* src/font.h (hbfont_otf_capability) [HAVE_HARFBUZZ]: Add extern.
* src/ftcrfont.c (syms_of_ftcrfont_for_pdumper) [HAVE_HARFBUZZ]:
* src/ftfont.c (syms_of_ftfont_for_pdumper) [HAVE_HARFBUZZ]:
* src/w32uniscribe.c (syms_of_w32uniscribe_for_pdumper) [HAVE_HARFBUZZ]:
* src/xftfont.c (syms_of_xftfont_for_pdumper) [HAVE_HARFBUZZ]: Populate
otf_capability method with hbfont_otf_capability.
Diffstat (limited to 'src')
| -rw-r--r-- | src/font.h | 1 | ||||
| -rw-r--r-- | src/ftcrfont.c | 1 | ||||
| -rw-r--r-- | src/ftfont.c | 1 | ||||
| -rw-r--r-- | src/hbfont.c | 112 | ||||
| -rw-r--r-- | src/w32uniscribe.c | 1 | ||||
| -rw-r--r-- | src/xftfont.c | 1 |
6 files changed, 117 insertions, 0 deletions
diff --git a/src/font.h b/src/font.h index 1f35744642b..3387878ad30 100644 --- a/src/font.h +++ b/src/font.h | |||
| @@ -891,6 +891,7 @@ extern Lisp_Object font_put_extra (Lisp_Object font, Lisp_Object prop, | |||
| 891 | Lisp_Object val); | 891 | Lisp_Object val); |
| 892 | 892 | ||
| 893 | #ifdef HAVE_HARFBUZZ | 893 | #ifdef HAVE_HARFBUZZ |
| 894 | extern Lisp_Object hbfont_otf_capability (struct font *); | ||
| 894 | extern Lisp_Object hbfont_shape (Lisp_Object, Lisp_Object); | 895 | extern Lisp_Object hbfont_shape (Lisp_Object, Lisp_Object); |
| 895 | extern Lisp_Object hbfont_combining_capability (struct font *); | 896 | extern Lisp_Object hbfont_combining_capability (struct font *); |
| 896 | #endif | 897 | #endif |
diff --git a/src/ftcrfont.c b/src/ftcrfont.c index f15e79334ac..ff61ecfe313 100644 --- a/src/ftcrfont.c +++ b/src/ftcrfont.c | |||
| @@ -621,6 +621,7 @@ syms_of_ftcrfont_for_pdumper (void) | |||
| 621 | ftcrhbfont_driver.type = Qftcrhb; | 621 | ftcrhbfont_driver.type = Qftcrhb; |
| 622 | ftcrhbfont_driver.list = ftcrhbfont_list; | 622 | ftcrhbfont_driver.list = ftcrhbfont_list; |
| 623 | ftcrhbfont_driver.match = ftcrhbfont_match; | 623 | ftcrhbfont_driver.match = ftcrhbfont_match; |
| 624 | ftcrhbfont_driver.otf_capability = hbfont_otf_capability, | ||
| 624 | ftcrhbfont_driver.shape = hbfont_shape; | 625 | ftcrhbfont_driver.shape = hbfont_shape; |
| 625 | ftcrhbfont_driver.combining_capability = hbfont_combining_capability; | 626 | ftcrhbfont_driver.combining_capability = hbfont_combining_capability; |
| 626 | ftcrhbfont_driver.begin_hb_font = ftcrhbfont_begin_hb_font; | 627 | ftcrhbfont_driver.begin_hb_font = ftcrhbfont_begin_hb_font; |
diff --git a/src/ftfont.c b/src/ftfont.c index 384279f616b..6f03d966606 100644 --- a/src/ftfont.c +++ b/src/ftfont.c | |||
| @@ -3012,6 +3012,7 @@ syms_of_ftfont_for_pdumper (void) | |||
| 3012 | #ifdef HAVE_HARFBUZZ | 3012 | #ifdef HAVE_HARFBUZZ |
| 3013 | fthbfont_driver = ftfont_driver; | 3013 | fthbfont_driver = ftfont_driver; |
| 3014 | fthbfont_driver.type = Qfreetypehb; | 3014 | fthbfont_driver.type = Qfreetypehb; |
| 3015 | fthbfont_driver.otf_capability = hbfont_otf_capability, | ||
| 3015 | fthbfont_driver.shape = hbfont_shape; | 3016 | fthbfont_driver.shape = hbfont_shape; |
| 3016 | fthbfont_driver.combining_capability = hbfont_combining_capability; | 3017 | fthbfont_driver.combining_capability = hbfont_combining_capability; |
| 3017 | fthbfont_driver.begin_hb_font = fthbfont_begin_hb_font; | 3018 | fthbfont_driver.begin_hb_font = fthbfont_begin_hb_font; |
diff --git a/src/hbfont.c b/src/hbfont.c index 623bee61cc8..455c1a7a554 100644 --- a/src/hbfont.c +++ b/src/hbfont.c | |||
| @@ -19,6 +19,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ | |||
| 19 | #include <config.h> | 19 | #include <config.h> |
| 20 | #include <math.h> | 20 | #include <math.h> |
| 21 | #include <hb.h> | 21 | #include <hb.h> |
| 22 | #include <hb-ot.h> | ||
| 22 | 23 | ||
| 23 | #include "lisp.h" | 24 | #include "lisp.h" |
| 24 | #include "frame.h" | 25 | #include "frame.h" |
| @@ -69,6 +70,18 @@ DEF_DLL_FN (hb_glyph_info_t *, hb_buffer_get_glyph_infos, | |||
| 69 | (hb_buffer_t *, unsigned int *)); | 70 | (hb_buffer_t *, unsigned int *)); |
| 70 | DEF_DLL_FN (hb_glyph_position_t *, hb_buffer_get_glyph_positions, | 71 | DEF_DLL_FN (hb_glyph_position_t *, hb_buffer_get_glyph_positions, |
| 71 | (hb_buffer_t *, unsigned int *)); | 72 | (hb_buffer_t *, unsigned int *)); |
| 73 | DEF_DLL_FN (void, hb_tag_to_string, (hb_tag_t, char *)); | ||
| 74 | DEF_DLL_FN (hb_face_t *, hb_font_get_face, (hb_font_t *font)); | ||
| 75 | DEF_DLL_FN (unsigned int, hb_ot_layout_table_get_script_tags, | ||
| 76 | (hb_face_t *, hb_tag_t, unsigned int, unsigned int *, hb_tag_t *)); | ||
| 77 | DEF_DLL_FN (unsigned int, hb_ot_layout_table_get_feature_tags, | ||
| 78 | (hb_face_t *, hb_tag_t, unsigned int, unsigned int *, hb_tag_t *)); | ||
| 79 | DEF_DLL_FN (unsigned int, hb_ot_layout_script_get_language_tags, | ||
| 80 | (hb_face_t *, hb_tag_t, unsigned int, unsigned int, unsigned int *, | ||
| 81 | hb_tag_t *)); | ||
| 82 | DEF_DLL_FN (unsigned int, hb_ot_layout_language_get_feature_tags, | ||
| 83 | (hb_face_t *, hb_tag_t, unsigned int, unsigned int, unsigned int, | ||
| 84 | unsigned int *, hb_tag_t *)); | ||
| 72 | 85 | ||
| 73 | #define hb_unicode_funcs_create fn_hb_unicode_funcs_create | 86 | #define hb_unicode_funcs_create fn_hb_unicode_funcs_create |
| 74 | #define hb_unicode_funcs_get_default fn_hb_unicode_funcs_get_default | 87 | #define hb_unicode_funcs_get_default fn_hb_unicode_funcs_get_default |
| @@ -92,6 +105,12 @@ DEF_DLL_FN (hb_glyph_position_t *, hb_buffer_get_glyph_positions, | |||
| 92 | #define hb_buffer_reverse_clusters fn_hb_buffer_reverse_clusters | 105 | #define hb_buffer_reverse_clusters fn_hb_buffer_reverse_clusters |
| 93 | #define hb_buffer_get_glyph_infos fn_hb_buffer_get_glyph_infos | 106 | #define hb_buffer_get_glyph_infos fn_hb_buffer_get_glyph_infos |
| 94 | #define hb_buffer_get_glyph_positions fn_hb_buffer_get_glyph_positions | 107 | #define hb_buffer_get_glyph_positions fn_hb_buffer_get_glyph_positions |
| 108 | #define hb_tag_to_string fn_hb_tag_to_string | ||
| 109 | #define hb_font_get_face fn_hb_font_get_face | ||
| 110 | #define hb_ot_layout_table_get_script_tags fn_hb_ot_layout_table_get_script_tags | ||
| 111 | #define hb_ot_layout_table_get_feature_tags fn_hb_ot_layout_table_get_feature_tags | ||
| 112 | #define hb_ot_layout_script_get_language_tags fn_hb_ot_layout_script_get_language_tags | ||
| 113 | #define hb_ot_layout_language_get_feature_tags fn_hb_ot_layout_language_get_feature_tags | ||
| 95 | 114 | ||
| 96 | /* This function is called from syms_of_w32uniscribe_for_pdumper to | 115 | /* This function is called from syms_of_w32uniscribe_for_pdumper to |
| 97 | initialize the above function pointers. */ | 116 | initialize the above function pointers. */ |
| @@ -120,10 +139,103 @@ hbfont_init_w32_funcs (HMODULE library) | |||
| 120 | LOAD_DLL_FN (library, hb_buffer_reverse_clusters); | 139 | LOAD_DLL_FN (library, hb_buffer_reverse_clusters); |
| 121 | LOAD_DLL_FN (library, hb_buffer_get_glyph_infos); | 140 | LOAD_DLL_FN (library, hb_buffer_get_glyph_infos); |
| 122 | LOAD_DLL_FN (library, hb_buffer_get_glyph_positions); | 141 | LOAD_DLL_FN (library, hb_buffer_get_glyph_positions); |
| 142 | LOAD_DLL_FN (library, hb_tag_to_string); | ||
| 143 | LOAD_DLL_FN (library, hb_font_get_face); | ||
| 144 | LOAD_DLL_FN (library, hb_ot_layout_table_get_script_tags); | ||
| 145 | LOAD_DLL_FN (library, hb_ot_layout_table_get_feature_tags); | ||
| 146 | LOAD_DLL_FN (library, hb_ot_layout_script_get_language_tags); | ||
| 147 | LOAD_DLL_FN (library, hb_ot_layout_language_get_feature_tags); | ||
| 123 | return true; | 148 | return true; |
| 124 | } | 149 | } |
| 125 | #endif /* HAVE_NTGUI */ | 150 | #endif /* HAVE_NTGUI */ |
| 126 | 151 | ||
| 152 | static Lisp_Object | ||
| 153 | hbfont_otf_features (hb_face_t *face, hb_tag_t table_tag) | ||
| 154 | { | ||
| 155 | hb_tag_t *language_tags = NULL, *feature_tags = NULL; | ||
| 156 | char buf[4]; | ||
| 157 | unsigned int script_count | ||
| 158 | = hb_ot_layout_table_get_script_tags (face, table_tag, 0, NULL, NULL); | ||
| 159 | hb_tag_t *script_tags = xnmalloc (script_count, sizeof *script_tags); | ||
| 160 | hb_ot_layout_table_get_script_tags (face, table_tag, 0, &script_count, | ||
| 161 | script_tags); | ||
| 162 | Lisp_Object scripts = Qnil; | ||
| 163 | for (int i = script_count - 1; i >= 0; i--) | ||
| 164 | { | ||
| 165 | unsigned int language_count | ||
| 166 | = hb_ot_layout_script_get_language_tags (face, table_tag, i, 0, | ||
| 167 | NULL, NULL); | ||
| 168 | language_tags = xnrealloc (language_tags, language_count, | ||
| 169 | sizeof *language_tags); | ||
| 170 | hb_ot_layout_script_get_language_tags (face, table_tag, i, 0, | ||
| 171 | &language_count, language_tags); | ||
| 172 | Lisp_Object langsyses = Qnil; | ||
| 173 | for (int j = language_count - 1; j >= -1; j--) | ||
| 174 | { | ||
| 175 | unsigned int language_index | ||
| 176 | = j >= 0 ? j : HB_OT_LAYOUT_DEFAULT_LANGUAGE_INDEX; | ||
| 177 | unsigned int feature_count | ||
| 178 | = hb_ot_layout_language_get_feature_tags (face, table_tag, | ||
| 179 | i, language_index, 0, | ||
| 180 | NULL, NULL); | ||
| 181 | if (feature_count == 0) | ||
| 182 | continue; | ||
| 183 | feature_tags = xnrealloc (feature_tags, feature_count, | ||
| 184 | sizeof *feature_tags); | ||
| 185 | hb_ot_layout_language_get_feature_tags (face, table_tag, | ||
| 186 | i, language_index, 0, | ||
| 187 | &feature_count, feature_tags); | ||
| 188 | Lisp_Object features = Qnil; | ||
| 189 | for (int k = feature_count - 1; k >= 0; k--) | ||
| 190 | { | ||
| 191 | hb_tag_to_string (feature_tags[k], buf); | ||
| 192 | features = Fcons (font_intern_prop (buf, 4, 1), features); | ||
| 193 | } | ||
| 194 | |||
| 195 | Lisp_Object sym = Qnil; | ||
| 196 | if (j >= 0) | ||
| 197 | { | ||
| 198 | hb_tag_to_string (language_tags[j], buf); | ||
| 199 | sym = font_intern_prop (buf, 4, 1); | ||
| 200 | } | ||
| 201 | langsyses = Fcons (Fcons (sym, features), langsyses); | ||
| 202 | } | ||
| 203 | |||
| 204 | hb_tag_to_string (script_tags[i], buf); | ||
| 205 | scripts = Fcons (Fcons (font_intern_prop (buf, 4, 1), langsyses), | ||
| 206 | scripts); | ||
| 207 | } | ||
| 208 | xfree (feature_tags); | ||
| 209 | xfree (language_tags); | ||
| 210 | xfree (script_tags); | ||
| 211 | |||
| 212 | return scripts; | ||
| 213 | } | ||
| 214 | |||
| 215 | Lisp_Object | ||
| 216 | hbfont_otf_capability (struct font *font) | ||
| 217 | { | ||
| 218 | double position_unit; | ||
| 219 | hb_font_t *hb_font | ||
| 220 | = font->driver->begin_hb_font | ||
| 221 | ? font->driver->begin_hb_font (font, &position_unit) | ||
| 222 | : NULL; | ||
| 223 | if (!hb_font) | ||
| 224 | return Qnil; | ||
| 225 | |||
| 226 | Lisp_Object gsub_gpos = Fcons (Qnil, Qnil); | ||
| 227 | hb_face_t *face = hb_font_get_face (hb_font); | ||
| 228 | if (hb_ot_layout_table_get_feature_tags (face, HB_OT_TAG_GSUB, 0, NULL, NULL)) | ||
| 229 | XSETCAR (gsub_gpos, hbfont_otf_features (face, HB_OT_TAG_GSUB)); | ||
| 230 | if (hb_ot_layout_table_get_feature_tags (face, HB_OT_TAG_GPOS, 0, NULL, NULL)) | ||
| 231 | XSETCDR (gsub_gpos, hbfont_otf_features (face, HB_OT_TAG_GPOS)); | ||
| 232 | |||
| 233 | if (font->driver->end_hb_font) | ||
| 234 | font->driver->end_hb_font (font, hb_font); | ||
| 235 | |||
| 236 | return gsub_gpos; | ||
| 237 | } | ||
| 238 | |||
| 127 | /* Support functions for HarfBuzz shaper. */ | 239 | /* Support functions for HarfBuzz shaper. */ |
| 128 | 240 | ||
| 129 | static bool combining_class_loaded = false; | 241 | static bool combining_class_loaded = false; |
diff --git a/src/w32uniscribe.c b/src/w32uniscribe.c index d59d564abb4..aa6bebdc024 100644 --- a/src/w32uniscribe.c +++ b/src/w32uniscribe.c | |||
| @@ -1540,6 +1540,7 @@ syms_of_w32uniscribe_for_pdumper (void) | |||
| 1540 | harfbuzz_font_driver.list = w32hb_list; | 1540 | harfbuzz_font_driver.list = w32hb_list; |
| 1541 | harfbuzz_font_driver.match = w32hb_match; | 1541 | harfbuzz_font_driver.match = w32hb_match; |
| 1542 | harfbuzz_font_driver.encode_char = w32hb_encode_char; | 1542 | harfbuzz_font_driver.encode_char = w32hb_encode_char; |
| 1543 | harfbuzz_font_driver.otf_capability = hbfont_otf_capability, | ||
| 1543 | harfbuzz_font_driver.shape = hbfont_shape; | 1544 | harfbuzz_font_driver.shape = hbfont_shape; |
| 1544 | harfbuzz_font_driver.get_variation_glyphs = w32hb_get_variation_glyphs; | 1545 | harfbuzz_font_driver.get_variation_glyphs = w32hb_get_variation_glyphs; |
| 1545 | harfbuzz_font_driver.combining_capability = hbfont_combining_capability; | 1546 | harfbuzz_font_driver.combining_capability = hbfont_combining_capability; |
diff --git a/src/xftfont.c b/src/xftfont.c index 4d2a5f520e0..2cad6db933b 100644 --- a/src/xftfont.c +++ b/src/xftfont.c | |||
| @@ -700,6 +700,7 @@ syms_of_xftfont_for_pdumper (void) | |||
| 700 | xfthbfont_driver.type = Qxfthb; | 700 | xfthbfont_driver.type = Qxfthb; |
| 701 | xfthbfont_driver.list = xfthbfont_list; | 701 | xfthbfont_driver.list = xfthbfont_list; |
| 702 | xfthbfont_driver.match = xfthbfont_match; | 702 | xfthbfont_driver.match = xfthbfont_match; |
| 703 | xfthbfont_driver.otf_capability = hbfont_otf_capability, | ||
| 703 | xfthbfont_driver.shape = hbfont_shape; | 704 | xfthbfont_driver.shape = hbfont_shape; |
| 704 | xfthbfont_driver.combining_capability = hbfont_combining_capability; | 705 | xfthbfont_driver.combining_capability = hbfont_combining_capability; |
| 705 | xfthbfont_driver.begin_hb_font = xfthbfont_begin_hb_font; | 706 | xfthbfont_driver.begin_hb_font = xfthbfont_begin_hb_font; |