1 /* Font backend for the Microsoft W32 Uniscribe API.
2 Copyright (C) 2008-2015 Free Software Foundation, Inc.
4 This file is part of GNU Emacs.
6 GNU Emacs is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
21 /* Override API version - Uniscribe is only available as standard since
22 Windows 2000, though most users of older systems will have it
23 since it installs with Internet Explorer 5.0 and other software.
24 We only enable the feature if it is available, so there is no chance
25 of calling non-existent functions. */
27 #define _WIN32_WINNT 0x500
34 #include "dispextern.h"
35 #include "character.h"
37 #include "composite.h"
42 struct uniscribe_font_info
44 struct w32font_info w32_font
;
48 int uniscribe_available
= 0;
50 /* EnumFontFamiliesEx callback. */
51 static int CALLBACK ALIGN_STACK
add_opentype_font_name_to_list (ENUMLOGFONTEX
*,
54 /* Used by uniscribe_otf_capability. */
55 static Lisp_Object
otf_features (HDC context
, char *table
);
58 memq_no_quit (Lisp_Object elt
, Lisp_Object list
)
60 while (CONSP (list
) && ! EQ (XCAR (list
), elt
))
62 return (CONSP (list
));
66 /* Font backend interface implementation. */
68 uniscribe_list (struct frame
*f
, Lisp_Object font_spec
)
70 Lisp_Object fonts
= w32font_list_internal (f
, font_spec
, 1);
71 FONT_ADD_LOG ("uniscribe-list", font_spec
, fonts
);
76 uniscribe_match (struct frame
*f
, Lisp_Object font_spec
)
78 Lisp_Object entity
= w32font_match_internal (f
, font_spec
, 1);
79 FONT_ADD_LOG ("uniscribe-match", font_spec
, entity
);
84 uniscribe_list_family (struct frame
*f
)
86 Lisp_Object list
= Qnil
;
87 LOGFONT font_match_pattern
;
90 memset (&font_match_pattern
, 0, sizeof (font_match_pattern
));
91 /* Limit enumerated fonts to outline fonts to save time. */
92 font_match_pattern
.lfOutPrecision
= OUT_OUTLINE_PRECIS
;
94 dc
= get_frame_dc (f
);
96 EnumFontFamiliesEx (dc
, &font_match_pattern
,
97 (FONTENUMPROC
) add_opentype_font_name_to_list
,
99 release_frame_dc (f
, dc
);
105 uniscribe_open (struct frame
*f
, Lisp_Object font_entity
, int pixel_size
)
107 Lisp_Object font_object
108 = font_make_object (VECSIZE (struct uniscribe_font_info
),
109 font_entity
, pixel_size
);
110 struct uniscribe_font_info
*uniscribe_font
111 = (struct uniscribe_font_info
*) XFONT_OBJECT (font_object
);
113 ASET (font_object
, FONT_TYPE_INDEX
, Quniscribe
);
115 if (!w32font_open_internal (f
, font_entity
, pixel_size
, font_object
))
120 /* Initialize the cache for this font. */
121 uniscribe_font
->cache
= NULL
;
123 /* Uniscribe backend uses glyph indices. */
124 uniscribe_font
->w32_font
.glyph_idx
= ETO_GLYPH_INDEX
;
126 uniscribe_font
->w32_font
.font
.driver
= &uniscribe_font_driver
;
132 uniscribe_close (struct font
*font
)
134 struct uniscribe_font_info
*uniscribe_font
135 = (struct uniscribe_font_info
*) font
;
137 if (uniscribe_font
->cache
)
138 ScriptFreeCache (&(uniscribe_font
->cache
));
140 w32font_close (font
);
143 /* Return a list describing which scripts/languages FONT supports by
144 which GSUB/GPOS features of OpenType tables. */
146 uniscribe_otf_capability (struct font
*font
)
151 Lisp_Object capability
= Fcons (Qnil
, Qnil
);
152 Lisp_Object features
;
154 f
= XFRAME (selected_frame
);
155 context
= get_frame_dc (f
);
156 old_font
= SelectObject (context
, FONT_HANDLE (font
));
158 features
= otf_features (context
, "GSUB");
159 XSETCAR (capability
, features
);
160 features
= otf_features (context
, "GPOS");
161 XSETCDR (capability
, features
);
163 SelectObject (context
, old_font
);
164 release_frame_dc (f
, context
);
169 /* Uniscribe implementation of shape for font backend.
171 Shape text in LGSTRING. See the docstring of
172 `composition-get-gstring' for the format of LGSTRING. If the
173 (N+1)th element of LGSTRING is nil, input of shaping is from the
174 1st to (N)th elements. In each input glyph, FROM, TO, CHAR, and
175 CODE are already set.
177 This function updates all fields of the input glyphs. If the
178 output glyphs (M) are more than the input glyphs (N), (N+1)th
179 through (M)th elements of LGSTRING are updated possibly by making
180 a new glyph object and storing it in LGSTRING. If (M) is greater
181 than the length of LGSTRING, nil should be returned. In that case,
182 this function is called again with a larger LGSTRING. */
184 uniscribe_shape (Lisp_Object lgstring
)
186 struct font
*font
= CHECK_FONT_GET_OBJECT (LGSTRING_FONT (lgstring
));
187 struct uniscribe_font_info
*uniscribe_font
188 = (struct uniscribe_font_info
*) font
;
190 int nitems
, max_items
, i
, max_glyphs
, done_glyphs
;
192 WORD
*glyphs
, *clusters
;
194 SCRIPT_VISATTR
*attributes
;
199 struct frame
* f
= NULL
;
201 HFONT old_font
= NULL
;
203 /* Get the chars from lgstring in a form we can use with uniscribe. */
204 max_glyphs
= nchars
= LGSTRING_GLYPH_LEN (lgstring
);
206 chars
= (wchar_t *) alloca (nchars
* sizeof (wchar_t));
207 /* FIXME: This loop assumes that characters in the input LGSTRING
208 are all inside the BMP. Need to encode characters beyond the BMP
210 for (i
= 0; i
< nchars
; i
++)
212 /* lgstring can be bigger than the number of characters in it, in
213 the case where more glyphs are required to display those characters.
214 If that is the case, note the real number of characters. */
215 if (NILP (LGSTRING_GLYPH (lgstring
, i
)))
218 chars
[i
] = LGLYPH_CHAR (LGSTRING_GLYPH (lgstring
, i
));
221 /* First we need to break up the glyph string into runs of glyphs that
222 can be treated together. First try a single run. */
224 items
= xmalloc (sizeof (SCRIPT_ITEM
) * max_items
+ 1);
226 while ((result
= ScriptItemize (chars
, nchars
, max_items
, NULL
, NULL
,
227 items
, &nitems
)) == E_OUTOFMEMORY
)
229 /* If that wasn't enough, keep trying with one more run. */
231 items
= (SCRIPT_ITEM
*) xrealloc (items
,
232 sizeof (SCRIPT_ITEM
) * max_items
+ 1);
241 glyphs
= alloca (max_glyphs
* sizeof (WORD
));
242 clusters
= alloca (nchars
* sizeof (WORD
));
243 attributes
= alloca (max_glyphs
* sizeof (SCRIPT_VISATTR
));
244 advances
= alloca (max_glyphs
* sizeof (int));
245 offsets
= alloca (max_glyphs
* sizeof (GOFFSET
));
247 for (i
= 0; i
< nitems
; i
++)
249 int nglyphs
, nchars_in_run
;
250 nchars_in_run
= items
[i
+1].iCharPos
- items
[i
].iCharPos
;
251 /* Force ScriptShape to generate glyphs in the same order as
252 they are in the input LGSTRING, which is in the logical
254 items
[i
].a
.fLogicalOrder
= 1;
256 /* Context may be NULL here, in which case the cache should be
257 used without needing to select the font. */
258 result
= ScriptShape (context
, &(uniscribe_font
->cache
),
259 chars
+ items
[i
].iCharPos
, nchars_in_run
,
260 max_glyphs
- done_glyphs
, &(items
[i
].a
),
261 glyphs
, clusters
, attributes
, &nglyphs
);
263 if (result
== E_PENDING
&& !context
)
265 /* This assumes the selected frame is on the same display as the
266 one we are drawing. It would be better for the frame to be
268 f
= XFRAME (selected_frame
);
269 context
= get_frame_dc (f
);
270 old_font
= SelectObject (context
, FONT_HANDLE (font
));
272 result
= ScriptShape (context
, &(uniscribe_font
->cache
),
273 chars
+ items
[i
].iCharPos
, nchars_in_run
,
274 max_glyphs
- done_glyphs
, &(items
[i
].a
),
275 glyphs
, clusters
, attributes
, &nglyphs
);
278 if (result
== E_OUTOFMEMORY
)
280 /* Need a bigger lgstring. */
284 else if (FAILED (result
))
286 /* Can't shape this run - return results so far if any. */
289 else if (items
[i
].a
.fNoGlyphIndex
)
291 /* Glyph indices not supported by this font (or OS), means we
292 can't really do any meaningful shaping. */
297 result
= ScriptPlace (context
, &(uniscribe_font
->cache
),
298 glyphs
, nglyphs
, attributes
, &(items
[i
].a
),
299 advances
, offsets
, &overall_metrics
);
300 if (result
== E_PENDING
&& !context
)
302 /* Cache not complete... */
303 f
= XFRAME (selected_frame
);
304 context
= get_frame_dc (f
);
305 old_font
= SelectObject (context
, FONT_HANDLE (font
));
307 result
= ScriptPlace (context
, &(uniscribe_font
->cache
),
308 glyphs
, nglyphs
, attributes
, &(items
[i
].a
),
309 advances
, offsets
, &overall_metrics
);
311 if (SUCCEEDED (result
))
313 int j
, from
, to
, adj_offset
= 0;
318 for (j
= 0; j
< nglyphs
; j
++)
320 int lglyph_index
= j
+ done_glyphs
;
321 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, lglyph_index
);
327 lglyph
= LGLYPH_NEW ();
328 LGSTRING_SET_GLYPH (lgstring
, lglyph_index
, lglyph
);
330 /* Copy to a 32-bit data type to shut up the
331 compiler warning in LGLYPH_SET_CODE about
332 comparison being always false. */
334 LGLYPH_SET_CODE (lglyph
, gl
);
336 /* Detect clusters, for linking codes back to
338 if (attributes
[j
].fClusterStart
)
340 while (from
< nchars_in_run
&& clusters
[from
] < j
)
342 if (from
>= nchars_in_run
)
343 from
= to
= nchars_in_run
- 1;
347 to
= nchars_in_run
- 1;
348 for (k
= from
+ 1; k
< nchars_in_run
; k
++)
358 /* For RTL text, the Uniscribe shaper prepares
359 the values in ADVANCES array for layout in
360 reverse order, whereby "advance width" is
361 applied to move the pen in reverse direction
362 and _before_ drawing the glyph. Since we
363 draw glyphs in their normal left-to-right
364 order, we need to adjust the coordinates of
365 each non-base glyph in a grapheme cluster via
366 X-OFF component of the gstring's ADJUSTMENT
367 sub-vector. This loop computes, for each
368 grapheme cluster, the initial value of the
369 adjustment for the base character, which is
370 then updated for each successive glyph in the
377 while (j1
< nglyphs
&& !attributes
[j1
].fClusterStart
)
379 adj_offset
+= advances
[j1
];
385 LGLYPH_SET_CHAR (lglyph
, chars
[items
[i
].iCharPos
387 LGLYPH_SET_FROM (lglyph
, items
[i
].iCharPos
+ from
);
388 LGLYPH_SET_TO (lglyph
, items
[i
].iCharPos
+ to
);
391 LGLYPH_SET_WIDTH (lglyph
, advances
[j
]);
392 LGLYPH_SET_ASCENT (lglyph
, font
->ascent
);
393 LGLYPH_SET_DESCENT (lglyph
, font
->descent
);
395 result
= ScriptGetGlyphABCWidth (context
,
396 &(uniscribe_font
->cache
),
397 glyphs
[j
], &char_metric
);
398 if (result
== E_PENDING
&& !context
)
400 /* Cache incomplete... */
401 f
= XFRAME (selected_frame
);
402 context
= get_frame_dc (f
);
403 old_font
= SelectObject (context
, FONT_HANDLE (font
));
404 result
= ScriptGetGlyphABCWidth (context
,
405 &(uniscribe_font
->cache
),
406 glyphs
[j
], &char_metric
);
409 if (SUCCEEDED (result
))
411 int lbearing
= char_metric
.abcA
;
412 int rbearing
= char_metric
.abcA
+ char_metric
.abcB
;
414 LGLYPH_SET_LBEARING (lglyph
, lbearing
);
415 LGLYPH_SET_RBEARING (lglyph
, rbearing
);
419 LGLYPH_SET_LBEARING (lglyph
, 0);
420 LGLYPH_SET_RBEARING (lglyph
, advances
[j
]);
423 if (offsets
[j
].du
|| offsets
[j
].dv
424 /* For non-base glyphs of RTL grapheme clusters,
425 adjust the X offset even if both DU and DV
427 || (!attributes
[j
].fClusterStart
&& items
[i
].a
.fRTL
))
429 Lisp_Object vec
= make_uninit_vector (3);
433 /* Empirically, it looks like Uniscribe
434 interprets DU in reverse direction for
435 RTL clusters. E.g., if we don't reverse
436 the direction, the Hebrew point HOLAM is
437 drawn above the right edge of the base
438 consonant, instead of above the left edge. */
439 ASET (vec
, 0, make_number (-offsets
[j
].du
441 /* Update the adjustment value for the width
442 advance of the glyph we just emitted. */
443 adj_offset
-= 2 * advances
[j
];
446 ASET (vec
, 0, make_number (offsets
[j
].du
+ adj_offset
));
447 /* In the font definition coordinate system, the
448 Y coordinate points up, while in our screen
449 coordinates Y grows downwards. So we need to
450 reverse the sign of Y-OFFSET here. */
451 ASET (vec
, 1, make_number (-offsets
[j
].dv
));
452 /* Based on what ftfont.c does... */
453 ASET (vec
, 2, make_number (advances
[j
]));
454 LGLYPH_SET_ADJUSTMENT (lglyph
, vec
);
458 LGLYPH_SET_ADJUSTMENT (lglyph
, Qnil
);
459 /* Update the adjustment value to compensate for
460 the width of the base character. */
462 adj_offset
-= advances
[j
];
467 done_glyphs
+= nglyphs
;
474 SelectObject (context
, old_font
);
475 release_frame_dc (f
, context
);
481 return make_number (done_glyphs
);
484 /* Uniscribe implementation of encode_char for font backend.
485 Return a glyph code of FONT for character C (Unicode code point).
486 If FONT doesn't have such a glyph, return FONT_INVALID_CODE. */
488 uniscribe_encode_char (struct font
*font
, int c
)
491 struct frame
*f
= NULL
;
492 HFONT old_font
= NULL
;
493 unsigned code
= FONT_INVALID_CODE
;
498 struct uniscribe_font_info
*uniscribe_font
499 = (struct uniscribe_font_info
*)font
;
508 DWORD surrogate
= c
- 0x10000;
510 /* High surrogate: U+D800 - U+DBFF. */
511 ch
[0] = 0xD800 + ((surrogate
>> 10) & 0x03FF);
512 /* Low surrogate: U+DC00 - U+DFFF. */
513 ch
[1] = 0xDC00 + (surrogate
& 0x03FF);
517 /* Non BMP characters must be handled by the uniscribe shaping
518 engine as GDI functions (except blindly displaying lines of
519 Unicode text) and the promising looking ScriptGetCMap do not
520 convert surrogate pairs to glyph indexes correctly. */
522 items
= (SCRIPT_ITEM
*) alloca (sizeof (SCRIPT_ITEM
) * 2 + 1);
523 if (SUCCEEDED (ScriptItemize (ch
, len
, 2, NULL
, NULL
, items
, &nitems
)))
526 /* Surrogates seem to need 2 here, even though only one glyph is
527 returned. Indic characters can also produce 2 or more glyphs for
528 a single code point, but they need to use uniscribe_shape
529 above for correct display. */
530 WORD glyphs
[2], clusters
[2];
531 SCRIPT_VISATTR attrs
[2];
534 /* Force ScriptShape to generate glyphs in the logical
536 items
[0].a
.fLogicalOrder
= 1;
538 result
= ScriptShape (context
, &(uniscribe_font
->cache
),
539 ch
, len
, 2, &(items
[0].a
),
540 glyphs
, clusters
, attrs
, &nglyphs
);
542 if (result
== E_PENDING
)
544 /* Use selected frame until API is updated to pass
546 f
= XFRAME (selected_frame
);
547 context
= get_frame_dc (f
);
548 old_font
= SelectObject (context
, FONT_HANDLE (font
));
549 result
= ScriptShape (context
, &(uniscribe_font
->cache
),
550 ch
, len
, 2, &(items
[0].a
),
551 glyphs
, clusters
, attrs
, &nglyphs
);
554 if (SUCCEEDED (result
) && nglyphs
== 1)
556 /* Some fonts return .notdef glyphs instead of failing.
557 (TrueType spec reserves glyph code 0 for .notdef) */
561 else if (SUCCEEDED (result
) || result
== E_OUTOFMEMORY
)
563 /* This character produces zero or more than one glyph
564 when shaped. But we still need the return from here
565 to be valid for the shaping engine to be invoked
567 result
= ScriptGetCMap (context
, &(uniscribe_font
->cache
),
569 if (SUCCEEDED (result
) && glyphs
[0])
576 SelectObject (context
, old_font
);
577 release_frame_dc (f
, context
);
585 Lisp_Object uniscribe_get_cache (Lisp_Object frame);
586 void uniscribe_free_entity (Lisp_Object font_entity);
587 int uniscribe_has_char (Lisp_Object entity, int c);
588 void uniscribe_text_extents (struct font *font, unsigned *code,
589 int nglyphs, struct font_metrics *metrics);
590 int uniscribe_draw (struct glyph_string *s, int from, int to,
591 int x, int y, int with_background);
594 int uniscribe_prepare_face (struct frame *f, struct face *face);
595 void uniscribe_done_face (struct frame *f, struct face *face);
596 int uniscribe_get_bitmap (struct font *font, unsigned code,
597 struct font_bitmap *bitmap, int bits_per_pixel);
598 void uniscribe_free_bitmap (struct font *font, struct font_bitmap *bitmap);
599 int uniscribe_anchor_point (struct font *font, unsigned code,
600 int index, int *x, int *y);
601 int uniscribe_start_for_frame (struct frame *f);
602 int uniscribe_end_for_frame (struct frame *f);
607 /* Callback function for EnumFontFamiliesEx.
608 Adds the name of opentype fonts to a Lisp list (passed in as the
610 static int CALLBACK ALIGN_STACK
611 add_opentype_font_name_to_list (ENUMLOGFONTEX
*logical_font
,
612 NEWTEXTMETRICEX
*physical_font
,
613 DWORD font_type
, LPARAM list_object
)
615 Lisp_Object
* list
= (Lisp_Object
*) list_object
;
618 /* Skip vertical fonts (intended only for printing) */
619 if (logical_font
->elfLogFont
.lfFaceName
[0] == '@')
622 /* Skip non opentype fonts. Count old truetype fonts as opentype,
623 as some of them do contain GPOS and GSUB data that Uniscribe
625 if (!(physical_font
->ntmTm
.ntmFlags
& NTMFLAGS_OPENTYPE
)
626 && font_type
!= TRUETYPE_FONTTYPE
)
629 /* Skip fonts that have no Unicode coverage. */
630 if (!physical_font
->ntmFontSig
.fsUsb
[3]
631 && !physical_font
->ntmFontSig
.fsUsb
[2]
632 && !physical_font
->ntmFontSig
.fsUsb
[1]
633 && !(physical_font
->ntmFontSig
.fsUsb
[0] & 0x3fffffff))
636 family
= intern_font_name (logical_font
->elfLogFont
.lfFaceName
);
637 if (! memq_no_quit (family
, *list
))
638 *list
= Fcons (family
, *list
);
644 /* :otf property handling.
645 Since the necessary Uniscribe APIs for getting font tag information
646 are only available in Vista, we need to parse the font data directly
647 according to the OpenType Specification. */
649 /* Push into DWORD backwards to cope with endianness. */
650 #define OTF_TAG(STR) \
651 ((STR[3] << 24) | (STR[2] << 16) | (STR[1] << 8) | STR[0])
653 #define OTF_INT16_VAL(TABLE, OFFSET, PTR) \
655 BYTE temp, data[2]; \
656 if (GetFontData (context, TABLE, OFFSET, data, 2) != 2) \
657 goto font_table_error; \
658 temp = data[0], data[0] = data[1], data[1] = temp; \
659 memcpy (PTR, data, 2); \
662 /* Do not reverse the bytes, because we will compare with a OTF_TAG value
663 that has them reversed already. */
664 #define OTF_DWORDTAG_VAL(TABLE, OFFSET, PTR) \
666 if (GetFontData (context, TABLE, OFFSET, PTR, 4) != 4) \
667 goto font_table_error; \
670 #define OTF_TAG_VAL(TABLE, OFFSET, STR) \
672 if (GetFontData (context, TABLE, OFFSET, STR, 4) != 4) \
673 goto font_table_error; \
677 #define SNAME(VAL) SDATA (SYMBOL_NAME (VAL))
679 /* Check if font supports the otf script/language/features specified.
680 OTF_SPEC is in the format
681 (script lang [(gsub_feature ...)|nil] [(gpos_feature ...)]?) */
683 uniscribe_check_otf (LOGFONT
*font
, Lisp_Object otf_spec
)
685 Lisp_Object script
, lang
, rest
;
686 Lisp_Object features
[2];
687 DWORD feature_tables
[2];
688 DWORD script_tag
, default_script
, lang_tag
= 0;
691 HFONT check_font
, old_font
;
695 /* Check the spec is in the right format. */
696 if (!CONSP (otf_spec
) || XINT (Flength (otf_spec
)) < 3)
699 /* Break otf_spec into its components. */
700 script
= XCAR (otf_spec
);
701 rest
= XCDR (otf_spec
);
706 features
[0] = XCAR (rest
);
711 features
[1] = XCAR (rest
);
713 /* Set up tags we will use in the search. */
714 feature_tables
[0] = OTF_TAG ("GSUB");
715 feature_tables
[1] = OTF_TAG ("GPOS");
716 default_script
= OTF_TAG ("DFLT");
718 script_tag
= default_script
;
720 script_tag
= OTF_TAG (SNAME (script
));
722 lang_tag
= OTF_TAG (SNAME (lang
));
724 /* Set up graphics context so we can use the font. */
725 f
= XFRAME (selected_frame
);
726 context
= get_frame_dc (f
);
727 check_font
= CreateFontIndirect (font
);
728 old_font
= SelectObject (context
, check_font
);
730 /* Everything else is contained within otf_spec so should get
731 marked along with it. */
734 /* Scan GSUB and GPOS tables. */
735 for (i
= 0; i
< 2; i
++)
737 int j
, n_match_features
;
738 unsigned short scriptlist_table
, feature_table
, n_scripts
;
739 unsigned short script_table
, langsys_table
, n_langs
;
740 unsigned short feature_index
, n_features
;
741 DWORD tbl
= feature_tables
[i
];
743 /* Skip if no features requested from this table. */
744 if (NILP (features
[i
]))
747 /* If features is not a cons, this font spec is messed up. */
748 if (!CONSP (features
[i
]))
751 /* Read GPOS/GSUB header. */
752 OTF_INT16_VAL (tbl
, 4, &scriptlist_table
);
753 OTF_INT16_VAL (tbl
, 6, &feature_table
);
754 OTF_INT16_VAL (tbl
, scriptlist_table
, &n_scripts
);
756 /* Find the appropriate script table. */
758 for (j
= 0; j
< n_scripts
; j
++)
761 OTF_DWORDTAG_VAL (tbl
, scriptlist_table
+ 2 + j
* 6, &script_id
);
762 if (script_id
== script_tag
)
764 OTF_INT16_VAL (tbl
, scriptlist_table
+ 6 + j
* 6, &script_table
);
767 #if 0 /* Causes false positives. */
768 /* If there is a DFLT script defined in the font, use it
769 if the specified script is not found. */
770 else if (script_id
== default_script
)
771 OTF_INT16_VAL (tbl
, scriptlist_table
+ 6 + j
* 6, &script_table
);
774 /* If no specific or default script table was found, then this font
775 does not support the script. */
779 /* Offset is from beginning of scriptlist_table. */
780 script_table
+= scriptlist_table
;
782 /* Get default langsys table. */
783 OTF_INT16_VAL (tbl
, script_table
, &langsys_table
);
785 /* If lang was specified, see if font contains a specific entry. */
788 OTF_INT16_VAL (tbl
, script_table
+ 2, &n_langs
);
790 for (j
= 0; j
< n_langs
; j
++)
793 OTF_DWORDTAG_VAL (tbl
, script_table
+ 4 + j
* 6, &lang_id
);
794 if (lang_id
== lang_tag
)
796 OTF_INT16_VAL (tbl
, script_table
+ 8 + j
* 6, &langsys_table
);
805 /* Offset is from beginning of script table. */
806 langsys_table
+= script_table
;
808 /* Check the features. Features may contain nil according to
809 documentation in font_prop_validate_otf, so count them. */
810 n_match_features
= 0;
811 for (rest
= features
[i
]; CONSP (rest
); rest
= XCDR (rest
))
813 Lisp_Object feature
= XCAR (rest
);
818 /* If there are no features to check, skip checking. */
819 if (!n_match_features
)
822 /* First check required feature (if any). */
823 OTF_INT16_VAL (tbl
, langsys_table
+ 2, &feature_index
);
824 if (feature_index
!= 0xFFFF)
827 OTF_TAG_VAL (tbl
, feature_table
+ 2 + feature_index
* 6, feature_id
);
828 OTF_TAG_VAL (tbl
, feature_table
+ 2 + feature_index
* 6, feature_id
);
829 /* Assume no duplicates in the font table. This allows us to mark
830 the features off by simply decrementing a counter. */
831 if (!NILP (Fmemq (intern (feature_id
), features
[i
])))
834 /* Now check all the other features. */
835 OTF_INT16_VAL (tbl
, langsys_table
+ 4, &n_features
);
836 for (j
= 0; j
< n_features
; j
++)
839 OTF_INT16_VAL (tbl
, langsys_table
+ 6 + j
* 2, &feature_index
);
840 OTF_TAG_VAL (tbl
, feature_table
+ 2 + feature_index
* 6, feature_id
);
841 /* Assume no duplicates in the font table. This allows us to mark
842 the features off by simply decrementing a counter. */
843 if (!NILP (Fmemq (intern (feature_id
), features
[i
])))
847 if (n_match_features
> 0)
855 /* restore graphics context. */
856 SelectObject (context
, old_font
);
857 DeleteObject (check_font
);
858 release_frame_dc (f
, context
);
864 otf_features (HDC context
, char *table
)
866 Lisp_Object script_list
= Qnil
;
867 unsigned short scriptlist_table
, n_scripts
, feature_table
;
868 DWORD tbl
= OTF_TAG (table
);
871 /* Look for scripts in the table. */
872 OTF_INT16_VAL (tbl
, 4, &scriptlist_table
);
873 OTF_INT16_VAL (tbl
, 6, &feature_table
);
874 OTF_INT16_VAL (tbl
, scriptlist_table
, &n_scripts
);
876 for (i
= 0; i
< n_scripts
; i
++)
878 char script
[5], lang
[5];
879 unsigned short script_table
, lang_count
, langsys_table
, feature_count
;
880 Lisp_Object script_tag
, langsys_list
, langsys_tag
, feature_list
;
881 unsigned short record_offset
= scriptlist_table
+ 2 + i
* 6;
882 OTF_TAG_VAL (tbl
, record_offset
, script
);
883 OTF_INT16_VAL (tbl
, record_offset
+ 4, &script_table
);
885 /* Offset is from beginning of script table. */
886 script_table
+= scriptlist_table
;
888 script_tag
= intern (script
);
891 /* Optional default lang. */
892 OTF_INT16_VAL (tbl
, script_table
, &langsys_table
);
895 /* Offset is from beginning of script table. */
896 langsys_table
+= script_table
;
900 OTF_INT16_VAL (tbl
, langsys_table
+ 4, &feature_count
);
901 for (k
= 0; k
< feature_count
; k
++)
904 unsigned short index
;
905 OTF_INT16_VAL (tbl
, langsys_table
+ 6 + k
* 2, &index
);
906 OTF_TAG_VAL (tbl
, feature_table
+ 2 + index
* 6, feature
);
907 feature_list
= Fcons (intern (feature
), feature_list
);
909 langsys_list
= Fcons (Fcons (langsys_tag
, feature_list
),
913 /* List of supported languages. */
914 OTF_INT16_VAL (tbl
, script_table
+ 2, &lang_count
);
916 for (j
= 0; j
< lang_count
; j
++)
918 record_offset
= script_table
+ 4 + j
* 6;
919 OTF_TAG_VAL (tbl
, record_offset
, lang
);
920 OTF_INT16_VAL (tbl
, record_offset
+ 4, &langsys_table
);
922 /* Offset is from beginning of script table. */
923 langsys_table
+= script_table
;
925 langsys_tag
= intern (lang
);
927 OTF_INT16_VAL (tbl
, langsys_table
+ 4, &feature_count
);
928 for (k
= 0; k
< feature_count
; k
++)
931 unsigned short index
;
932 OTF_INT16_VAL (tbl
, langsys_table
+ 6 + k
* 2, &index
);
933 OTF_TAG_VAL (tbl
, feature_table
+ 2 + index
* 6, feature
);
934 feature_list
= Fcons (intern (feature
), feature_list
);
936 langsys_list
= Fcons (Fcons (langsys_tag
, feature_list
),
941 script_list
= Fcons (Fcons (script_tag
, langsys_list
), script_list
);
955 struct font_driver uniscribe_font_driver
=
957 LISP_INITIALLY_ZERO
, /* Quniscribe */
958 0, /* case insensitive */
962 uniscribe_list_family
,
963 NULL
, /* free_entity */
966 NULL
, /* prepare_face */
967 NULL
, /* done_face */
969 uniscribe_encode_char
,
970 w32font_text_extents
,
972 NULL
, /* get_bitmap */
973 NULL
, /* free_bitmap */
974 NULL
, /* anchor_point */
975 uniscribe_otf_capability
, /* Defined so (font-get FONTOBJ :otf) works. */
976 NULL
, /* otf_drive - use shape instead. */
977 NULL
, /* start_for_frame */
978 NULL
, /* end_for_frame */
981 NULL
, /* get_variation_glyphs */
982 NULL
, /* filter_properties */
983 NULL
, /* cached_font_ok */
986 /* Note that this should be called at every startup, not just when dumping,
987 as it needs to test for the existence of the Uniscribe library. */
989 syms_of_w32uniscribe (void)
993 /* Don't init uniscribe when dumping */
997 /* Don't register if uniscribe is not available. */
998 uniscribe
= GetModuleHandle ("usp10");
1002 uniscribe_font_driver
.type
= Quniscribe
;
1003 uniscribe_available
= 1;
1005 register_font_driver (&uniscribe_font_driver
, NULL
);