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
)
187 struct uniscribe_font_info
* uniscribe_font
;
189 int nitems
, max_items
, i
, max_glyphs
, done_glyphs
;
191 WORD
*glyphs
, *clusters
;
193 SCRIPT_VISATTR
*attributes
;
198 struct frame
* f
= NULL
;
200 HFONT old_font
= NULL
;
202 CHECK_FONT_GET_OBJECT (LGSTRING_FONT (lgstring
), font
);
203 uniscribe_font
= (struct uniscribe_font_info
*) font
;
205 /* Get the chars from lgstring in a form we can use with uniscribe. */
206 max_glyphs
= nchars
= LGSTRING_GLYPH_LEN (lgstring
);
208 chars
= (wchar_t *) alloca (nchars
* sizeof (wchar_t));
209 /* FIXME: This loop assumes that characters in the input LGSTRING
210 are all inside the BMP. Need to encode characters beyond the BMP
212 for (i
= 0; i
< nchars
; i
++)
214 /* lgstring can be bigger than the number of characters in it, in
215 the case where more glyphs are required to display those characters.
216 If that is the case, note the real number of characters. */
217 if (NILP (LGSTRING_GLYPH (lgstring
, i
)))
220 chars
[i
] = LGLYPH_CHAR (LGSTRING_GLYPH (lgstring
, i
));
223 /* First we need to break up the glyph string into runs of glyphs that
224 can be treated together. First try a single run. */
226 items
= xmalloc (sizeof (SCRIPT_ITEM
) * max_items
+ 1);
228 while ((result
= ScriptItemize (chars
, nchars
, max_items
, NULL
, NULL
,
229 items
, &nitems
)) == E_OUTOFMEMORY
)
231 /* If that wasn't enough, keep trying with one more run. */
233 items
= (SCRIPT_ITEM
*) xrealloc (items
,
234 sizeof (SCRIPT_ITEM
) * max_items
+ 1);
243 glyphs
= alloca (max_glyphs
* sizeof (WORD
));
244 clusters
= alloca (nchars
* sizeof (WORD
));
245 attributes
= alloca (max_glyphs
* sizeof (SCRIPT_VISATTR
));
246 advances
= alloca (max_glyphs
* sizeof (int));
247 offsets
= alloca (max_glyphs
* sizeof (GOFFSET
));
249 for (i
= 0; i
< nitems
; i
++)
251 int nglyphs
, nchars_in_run
;
252 nchars_in_run
= items
[i
+1].iCharPos
- items
[i
].iCharPos
;
253 /* Force ScriptShape to generate glyphs in the same order as
254 they are in the input LGSTRING, which is in the logical
256 items
[i
].a
.fLogicalOrder
= 1;
258 /* Context may be NULL here, in which case the cache should be
259 used without needing to select the font. */
260 result
= ScriptShape (context
, &(uniscribe_font
->cache
),
261 chars
+ items
[i
].iCharPos
, nchars_in_run
,
262 max_glyphs
- done_glyphs
, &(items
[i
].a
),
263 glyphs
, clusters
, attributes
, &nglyphs
);
265 if (result
== E_PENDING
&& !context
)
267 /* This assumes the selected frame is on the same display as the
268 one we are drawing. It would be better for the frame to be
270 f
= XFRAME (selected_frame
);
271 context
= get_frame_dc (f
);
272 old_font
= SelectObject (context
, FONT_HANDLE (font
));
274 result
= ScriptShape (context
, &(uniscribe_font
->cache
),
275 chars
+ items
[i
].iCharPos
, nchars_in_run
,
276 max_glyphs
- done_glyphs
, &(items
[i
].a
),
277 glyphs
, clusters
, attributes
, &nglyphs
);
280 if (result
== E_OUTOFMEMORY
)
282 /* Need a bigger lgstring. */
286 else if (FAILED (result
))
288 /* Can't shape this run - return results so far if any. */
291 else if (items
[i
].a
.fNoGlyphIndex
)
293 /* Glyph indices not supported by this font (or OS), means we
294 can't really do any meaningful shaping. */
299 result
= ScriptPlace (context
, &(uniscribe_font
->cache
),
300 glyphs
, nglyphs
, attributes
, &(items
[i
].a
),
301 advances
, offsets
, &overall_metrics
);
302 if (result
== E_PENDING
&& !context
)
304 /* Cache not complete... */
305 f
= XFRAME (selected_frame
);
306 context
= get_frame_dc (f
);
307 old_font
= SelectObject (context
, FONT_HANDLE (font
));
309 result
= ScriptPlace (context
, &(uniscribe_font
->cache
),
310 glyphs
, nglyphs
, attributes
, &(items
[i
].a
),
311 advances
, offsets
, &overall_metrics
);
313 if (SUCCEEDED (result
))
315 int j
, from
, to
, adj_offset
= 0;
320 for (j
= 0; j
< nglyphs
; j
++)
322 int lglyph_index
= j
+ done_glyphs
;
323 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, lglyph_index
);
329 lglyph
= LGLYPH_NEW ();
330 LGSTRING_SET_GLYPH (lgstring
, lglyph_index
, lglyph
);
332 /* Copy to a 32-bit data type to shut up the
333 compiler warning in LGLYPH_SET_CODE about
334 comparison being always false. */
336 LGLYPH_SET_CODE (lglyph
, gl
);
338 /* Detect clusters, for linking codes back to
340 if (attributes
[j
].fClusterStart
)
342 while (from
< nchars_in_run
&& clusters
[from
] < j
)
344 if (from
>= nchars_in_run
)
345 from
= to
= nchars_in_run
- 1;
349 to
= nchars_in_run
- 1;
350 for (k
= from
+ 1; k
< nchars_in_run
; k
++)
360 /* For RTL text, the Uniscribe shaper prepares
361 the values in ADVANCES array for layout in
362 reverse order, whereby "advance width" is
363 applied to move the pen in reverse direction
364 and _before_ drawing the glyph. Since we
365 draw glyphs in their normal left-to-right
366 order, we need to adjust the coordinates of
367 each non-base glyph in a grapheme cluster via
368 X-OFF component of the gstring's ADJUSTMENT
369 sub-vector. This loop computes, for each
370 grapheme cluster, the initial value of the
371 adjustment for the base character, which is
372 then updated for each successive glyph in the
379 while (j1
< nglyphs
&& !attributes
[j1
].fClusterStart
)
381 adj_offset
+= advances
[j1
];
387 LGLYPH_SET_CHAR (lglyph
, chars
[items
[i
].iCharPos
389 LGLYPH_SET_FROM (lglyph
, items
[i
].iCharPos
+ from
);
390 LGLYPH_SET_TO (lglyph
, items
[i
].iCharPos
+ to
);
393 LGLYPH_SET_WIDTH (lglyph
, advances
[j
]);
394 LGLYPH_SET_ASCENT (lglyph
, font
->ascent
);
395 LGLYPH_SET_DESCENT (lglyph
, font
->descent
);
397 result
= ScriptGetGlyphABCWidth (context
,
398 &(uniscribe_font
->cache
),
399 glyphs
[j
], &char_metric
);
400 if (result
== E_PENDING
&& !context
)
402 /* Cache incomplete... */
403 f
= XFRAME (selected_frame
);
404 context
= get_frame_dc (f
);
405 old_font
= SelectObject (context
, FONT_HANDLE (font
));
406 result
= ScriptGetGlyphABCWidth (context
,
407 &(uniscribe_font
->cache
),
408 glyphs
[j
], &char_metric
);
411 if (SUCCEEDED (result
))
413 int lbearing
= char_metric
.abcA
;
414 int rbearing
= char_metric
.abcA
+ char_metric
.abcB
;
416 LGLYPH_SET_LBEARING (lglyph
, lbearing
);
417 LGLYPH_SET_RBEARING (lglyph
, rbearing
);
421 LGLYPH_SET_LBEARING (lglyph
, 0);
422 LGLYPH_SET_RBEARING (lglyph
, advances
[j
]);
425 if (offsets
[j
].du
|| offsets
[j
].dv
426 /* For non-base glyphs of RTL grapheme clusters,
427 adjust the X offset even if both DU and DV
429 || (!attributes
[j
].fClusterStart
&& items
[i
].a
.fRTL
))
431 Lisp_Object vec
= make_uninit_vector (3);
435 /* Empirically, it looks like Uniscribe
436 interprets DU in reverse direction for
437 RTL clusters. E.g., if we don't reverse
438 the direction, the Hebrew point HOLAM is
439 drawn above the right edge of the base
440 consonant, instead of above the left edge. */
441 ASET (vec
, 0, make_number (-offsets
[j
].du
443 /* Update the adjustment value for the width
444 advance of the glyph we just emitted. */
445 adj_offset
-= 2 * advances
[j
];
448 ASET (vec
, 0, make_number (offsets
[j
].du
+ adj_offset
));
449 /* In the font definition coordinate system, the
450 Y coordinate points up, while in our screen
451 coordinates Y grows downwards. So we need to
452 reverse the sign of Y-OFFSET here. */
453 ASET (vec
, 1, make_number (-offsets
[j
].dv
));
454 /* Based on what ftfont.c does... */
455 ASET (vec
, 2, make_number (advances
[j
]));
456 LGLYPH_SET_ADJUSTMENT (lglyph
, vec
);
460 LGLYPH_SET_ADJUSTMENT (lglyph
, Qnil
);
461 /* Update the adjustment value to compensate for
462 the width of the base character. */
464 adj_offset
-= advances
[j
];
469 done_glyphs
+= nglyphs
;
476 SelectObject (context
, old_font
);
477 release_frame_dc (f
, context
);
483 return make_number (done_glyphs
);
486 /* Uniscribe implementation of encode_char for font backend.
487 Return a glyph code of FONT for character C (Unicode code point).
488 If FONT doesn't have such a glyph, return FONT_INVALID_CODE. */
490 uniscribe_encode_char (struct font
*font
, int c
)
493 struct frame
*f
= NULL
;
494 HFONT old_font
= NULL
;
495 unsigned code
= FONT_INVALID_CODE
;
500 struct uniscribe_font_info
*uniscribe_font
501 = (struct uniscribe_font_info
*)font
;
510 DWORD surrogate
= c
- 0x10000;
512 /* High surrogate: U+D800 - U+DBFF. */
513 ch
[0] = 0xD800 + ((surrogate
>> 10) & 0x03FF);
514 /* Low surrogate: U+DC00 - U+DFFF. */
515 ch
[1] = 0xDC00 + (surrogate
& 0x03FF);
519 /* Non BMP characters must be handled by the uniscribe shaping
520 engine as GDI functions (except blindly displaying lines of
521 Unicode text) and the promising looking ScriptGetCMap do not
522 convert surrogate pairs to glyph indexes correctly. */
524 items
= (SCRIPT_ITEM
*) alloca (sizeof (SCRIPT_ITEM
) * 2 + 1);
525 if (SUCCEEDED (ScriptItemize (ch
, len
, 2, NULL
, NULL
, items
, &nitems
)))
528 /* Surrogates seem to need 2 here, even though only one glyph is
529 returned. Indic characters can also produce 2 or more glyphs for
530 a single code point, but they need to use uniscribe_shape
531 above for correct display. */
532 WORD glyphs
[2], clusters
[2];
533 SCRIPT_VISATTR attrs
[2];
536 /* Force ScriptShape to generate glyphs in the logical
538 items
[0].a
.fLogicalOrder
= 1;
540 result
= ScriptShape (context
, &(uniscribe_font
->cache
),
541 ch
, len
, 2, &(items
[0].a
),
542 glyphs
, clusters
, attrs
, &nglyphs
);
544 if (result
== E_PENDING
)
546 /* Use selected frame until API is updated to pass
548 f
= XFRAME (selected_frame
);
549 context
= get_frame_dc (f
);
550 old_font
= SelectObject (context
, FONT_HANDLE (font
));
551 result
= ScriptShape (context
, &(uniscribe_font
->cache
),
552 ch
, len
, 2, &(items
[0].a
),
553 glyphs
, clusters
, attrs
, &nglyphs
);
556 if (SUCCEEDED (result
) && nglyphs
== 1)
558 /* Some fonts return .notdef glyphs instead of failing.
559 (TrueType spec reserves glyph code 0 for .notdef) */
563 else if (SUCCEEDED (result
) || result
== E_OUTOFMEMORY
)
565 /* This character produces zero or more than one glyph
566 when shaped. But we still need the return from here
567 to be valid for the shaping engine to be invoked
569 result
= ScriptGetCMap (context
, &(uniscribe_font
->cache
),
571 if (SUCCEEDED (result
) && glyphs
[0])
578 SelectObject (context
, old_font
);
579 release_frame_dc (f
, context
);
587 Lisp_Object uniscribe_get_cache (Lisp_Object frame);
588 void uniscribe_free_entity (Lisp_Object font_entity);
589 int uniscribe_has_char (Lisp_Object entity, int c);
590 void uniscribe_text_extents (struct font *font, unsigned *code,
591 int nglyphs, struct font_metrics *metrics);
592 int uniscribe_draw (struct glyph_string *s, int from, int to,
593 int x, int y, int with_background);
596 int uniscribe_prepare_face (struct frame *f, struct face *face);
597 void uniscribe_done_face (struct frame *f, struct face *face);
598 int uniscribe_get_bitmap (struct font *font, unsigned code,
599 struct font_bitmap *bitmap, int bits_per_pixel);
600 void uniscribe_free_bitmap (struct font *font, struct font_bitmap *bitmap);
601 int uniscribe_anchor_point (struct font *font, unsigned code,
602 int index, int *x, int *y);
603 int uniscribe_start_for_frame (struct frame *f);
604 int uniscribe_end_for_frame (struct frame *f);
609 /* Callback function for EnumFontFamiliesEx.
610 Adds the name of opentype fonts to a Lisp list (passed in as the
612 static int CALLBACK ALIGN_STACK
613 add_opentype_font_name_to_list (ENUMLOGFONTEX
*logical_font
,
614 NEWTEXTMETRICEX
*physical_font
,
615 DWORD font_type
, LPARAM list_object
)
617 Lisp_Object
* list
= (Lisp_Object
*) list_object
;
620 /* Skip vertical fonts (intended only for printing) */
621 if (logical_font
->elfLogFont
.lfFaceName
[0] == '@')
624 /* Skip non opentype fonts. Count old truetype fonts as opentype,
625 as some of them do contain GPOS and GSUB data that Uniscribe
627 if (!(physical_font
->ntmTm
.ntmFlags
& NTMFLAGS_OPENTYPE
)
628 && font_type
!= TRUETYPE_FONTTYPE
)
631 /* Skip fonts that have no Unicode coverage. */
632 if (!physical_font
->ntmFontSig
.fsUsb
[3]
633 && !physical_font
->ntmFontSig
.fsUsb
[2]
634 && !physical_font
->ntmFontSig
.fsUsb
[1]
635 && !(physical_font
->ntmFontSig
.fsUsb
[0] & 0x3fffffff))
638 family
= intern_font_name (logical_font
->elfLogFont
.lfFaceName
);
639 if (! memq_no_quit (family
, *list
))
640 *list
= Fcons (family
, *list
);
646 /* :otf property handling.
647 Since the necessary Uniscribe APIs for getting font tag information
648 are only available in Vista, we need to parse the font data directly
649 according to the OpenType Specification. */
651 /* Push into DWORD backwards to cope with endianness. */
652 #define OTF_TAG(STR) \
653 ((STR[3] << 24) | (STR[2] << 16) | (STR[1] << 8) | STR[0])
655 #define OTF_INT16_VAL(TABLE, OFFSET, PTR) \
657 BYTE temp, data[2]; \
658 if (GetFontData (context, TABLE, OFFSET, data, 2) != 2) \
659 goto font_table_error; \
660 temp = data[0], data[0] = data[1], data[1] = temp; \
661 memcpy (PTR, data, 2); \
664 /* Do not reverse the bytes, because we will compare with a OTF_TAG value
665 that has them reversed already. */
666 #define OTF_DWORDTAG_VAL(TABLE, OFFSET, PTR) \
668 if (GetFontData (context, TABLE, OFFSET, PTR, 4) != 4) \
669 goto font_table_error; \
672 #define OTF_TAG_VAL(TABLE, OFFSET, STR) \
674 if (GetFontData (context, TABLE, OFFSET, STR, 4) != 4) \
675 goto font_table_error; \
679 #define SNAME(VAL) SDATA (SYMBOL_NAME (VAL))
681 /* Check if font supports the otf script/language/features specified.
682 OTF_SPEC is in the format
683 (script lang [(gsub_feature ...)|nil] [(gpos_feature ...)]?) */
685 uniscribe_check_otf (LOGFONT
*font
, Lisp_Object otf_spec
)
687 Lisp_Object script
, lang
, rest
;
688 Lisp_Object features
[2];
689 DWORD feature_tables
[2];
690 DWORD script_tag
, default_script
, lang_tag
= 0;
693 HFONT check_font
, old_font
;
697 /* Check the spec is in the right format. */
698 if (!CONSP (otf_spec
) || XINT (Flength (otf_spec
)) < 3)
701 /* Break otf_spec into its components. */
702 script
= XCAR (otf_spec
);
703 rest
= XCDR (otf_spec
);
708 features
[0] = XCAR (rest
);
713 features
[1] = XCAR (rest
);
715 /* Set up tags we will use in the search. */
716 feature_tables
[0] = OTF_TAG ("GSUB");
717 feature_tables
[1] = OTF_TAG ("GPOS");
718 default_script
= OTF_TAG ("DFLT");
720 script_tag
= default_script
;
722 script_tag
= OTF_TAG (SNAME (script
));
724 lang_tag
= OTF_TAG (SNAME (lang
));
726 /* Set up graphics context so we can use the font. */
727 f
= XFRAME (selected_frame
);
728 context
= get_frame_dc (f
);
729 check_font
= CreateFontIndirect (font
);
730 old_font
= SelectObject (context
, check_font
);
732 /* Everything else is contained within otf_spec so should get
733 marked along with it. */
736 /* Scan GSUB and GPOS tables. */
737 for (i
= 0; i
< 2; i
++)
739 int j
, n_match_features
;
740 unsigned short scriptlist_table
, feature_table
, n_scripts
;
741 unsigned short script_table
, langsys_table
, n_langs
;
742 unsigned short feature_index
, n_features
;
743 DWORD tbl
= feature_tables
[i
];
745 /* Skip if no features requested from this table. */
746 if (NILP (features
[i
]))
749 /* If features is not a cons, this font spec is messed up. */
750 if (!CONSP (features
[i
]))
753 /* Read GPOS/GSUB header. */
754 OTF_INT16_VAL (tbl
, 4, &scriptlist_table
);
755 OTF_INT16_VAL (tbl
, 6, &feature_table
);
756 OTF_INT16_VAL (tbl
, scriptlist_table
, &n_scripts
);
758 /* Find the appropriate script table. */
760 for (j
= 0; j
< n_scripts
; j
++)
763 OTF_DWORDTAG_VAL (tbl
, scriptlist_table
+ 2 + j
* 6, &script_id
);
764 if (script_id
== script_tag
)
766 OTF_INT16_VAL (tbl
, scriptlist_table
+ 6 + j
* 6, &script_table
);
769 #if 0 /* Causes false positives. */
770 /* If there is a DFLT script defined in the font, use it
771 if the specified script is not found. */
772 else if (script_id
== default_script
)
773 OTF_INT16_VAL (tbl
, scriptlist_table
+ 6 + j
* 6, &script_table
);
776 /* If no specific or default script table was found, then this font
777 does not support the script. */
781 /* Offset is from beginning of scriptlist_table. */
782 script_table
+= scriptlist_table
;
784 /* Get default langsys table. */
785 OTF_INT16_VAL (tbl
, script_table
, &langsys_table
);
787 /* If lang was specified, see if font contains a specific entry. */
790 OTF_INT16_VAL (tbl
, script_table
+ 2, &n_langs
);
792 for (j
= 0; j
< n_langs
; j
++)
795 OTF_DWORDTAG_VAL (tbl
, script_table
+ 4 + j
* 6, &lang_id
);
796 if (lang_id
== lang_tag
)
798 OTF_INT16_VAL (tbl
, script_table
+ 8 + j
* 6, &langsys_table
);
807 /* Offset is from beginning of script table. */
808 langsys_table
+= script_table
;
810 /* Check the features. Features may contain nil according to
811 documentation in font_prop_validate_otf, so count them. */
812 n_match_features
= 0;
813 for (rest
= features
[i
]; CONSP (rest
); rest
= XCDR (rest
))
815 Lisp_Object feature
= XCAR (rest
);
820 /* If there are no features to check, skip checking. */
821 if (!n_match_features
)
824 /* First check required feature (if any). */
825 OTF_INT16_VAL (tbl
, langsys_table
+ 2, &feature_index
);
826 if (feature_index
!= 0xFFFF)
829 OTF_TAG_VAL (tbl
, feature_table
+ 2 + feature_index
* 6, feature_id
);
830 OTF_TAG_VAL (tbl
, feature_table
+ 2 + feature_index
* 6, feature_id
);
831 /* Assume no duplicates in the font table. This allows us to mark
832 the features off by simply decrementing a counter. */
833 if (!NILP (Fmemq (intern (feature_id
), features
[i
])))
836 /* Now check all the other features. */
837 OTF_INT16_VAL (tbl
, langsys_table
+ 4, &n_features
);
838 for (j
= 0; j
< n_features
; j
++)
841 OTF_INT16_VAL (tbl
, langsys_table
+ 6 + j
* 2, &feature_index
);
842 OTF_TAG_VAL (tbl
, feature_table
+ 2 + feature_index
* 6, feature_id
);
843 /* Assume no duplicates in the font table. This allows us to mark
844 the features off by simply decrementing a counter. */
845 if (!NILP (Fmemq (intern (feature_id
), features
[i
])))
849 if (n_match_features
> 0)
857 /* restore graphics context. */
858 SelectObject (context
, old_font
);
859 DeleteObject (check_font
);
860 release_frame_dc (f
, context
);
866 otf_features (HDC context
, char *table
)
868 Lisp_Object script_list
= Qnil
;
869 unsigned short scriptlist_table
, n_scripts
, feature_table
;
870 DWORD tbl
= OTF_TAG (table
);
873 /* Look for scripts in the table. */
874 OTF_INT16_VAL (tbl
, 4, &scriptlist_table
);
875 OTF_INT16_VAL (tbl
, 6, &feature_table
);
876 OTF_INT16_VAL (tbl
, scriptlist_table
, &n_scripts
);
878 for (i
= 0; i
< n_scripts
; i
++)
880 char script
[5], lang
[5];
881 unsigned short script_table
, lang_count
, langsys_table
, feature_count
;
882 Lisp_Object script_tag
, langsys_list
, langsys_tag
, feature_list
;
883 unsigned short record_offset
= scriptlist_table
+ 2 + i
* 6;
884 OTF_TAG_VAL (tbl
, record_offset
, script
);
885 OTF_INT16_VAL (tbl
, record_offset
+ 4, &script_table
);
887 /* Offset is from beginning of script table. */
888 script_table
+= scriptlist_table
;
890 script_tag
= intern (script
);
893 /* Optional default lang. */
894 OTF_INT16_VAL (tbl
, script_table
, &langsys_table
);
897 /* Offset is from beginning of script table. */
898 langsys_table
+= script_table
;
902 OTF_INT16_VAL (tbl
, langsys_table
+ 4, &feature_count
);
903 for (k
= 0; k
< feature_count
; k
++)
906 unsigned short index
;
907 OTF_INT16_VAL (tbl
, langsys_table
+ 6 + k
* 2, &index
);
908 OTF_TAG_VAL (tbl
, feature_table
+ 2 + index
* 6, feature
);
909 feature_list
= Fcons (intern (feature
), feature_list
);
911 langsys_list
= Fcons (Fcons (langsys_tag
, feature_list
),
915 /* List of supported languages. */
916 OTF_INT16_VAL (tbl
, script_table
+ 2, &lang_count
);
918 for (j
= 0; j
< lang_count
; j
++)
920 record_offset
= script_table
+ 4 + j
* 6;
921 OTF_TAG_VAL (tbl
, record_offset
, lang
);
922 OTF_INT16_VAL (tbl
, record_offset
+ 4, &langsys_table
);
924 /* Offset is from beginning of script table. */
925 langsys_table
+= script_table
;
927 langsys_tag
= intern (lang
);
929 OTF_INT16_VAL (tbl
, langsys_table
+ 4, &feature_count
);
930 for (k
= 0; k
< feature_count
; k
++)
933 unsigned short index
;
934 OTF_INT16_VAL (tbl
, langsys_table
+ 6 + k
* 2, &index
);
935 OTF_TAG_VAL (tbl
, feature_table
+ 2 + index
* 6, feature
);
936 feature_list
= Fcons (intern (feature
), feature_list
);
938 langsys_list
= Fcons (Fcons (langsys_tag
, feature_list
),
943 script_list
= Fcons (Fcons (script_tag
, langsys_list
), script_list
);
957 struct font_driver uniscribe_font_driver
=
959 LISP_INITIALLY_ZERO
, /* Quniscribe */
960 0, /* case insensitive */
964 uniscribe_list_family
,
965 NULL
, /* free_entity */
968 NULL
, /* prepare_face */
969 NULL
, /* done_face */
971 uniscribe_encode_char
,
972 w32font_text_extents
,
974 NULL
, /* get_bitmap */
975 NULL
, /* free_bitmap */
976 NULL
, /* anchor_point */
977 uniscribe_otf_capability
, /* Defined so (font-get FONTOBJ :otf) works. */
978 NULL
, /* otf_drive - use shape instead. */
979 NULL
, /* start_for_frame */
980 NULL
, /* end_for_frame */
983 NULL
, /* get_variation_glyphs */
984 NULL
, /* filter_properties */
985 NULL
, /* cached_font_ok */
988 /* Note that this should be called at every startup, not just when dumping,
989 as it needs to test for the existence of the Uniscribe library. */
991 syms_of_w32uniscribe (void)
995 /* Don't init uniscribe when dumping */
999 /* Don't register if uniscribe is not available. */
1000 uniscribe
= GetModuleHandle ("usp10");
1004 uniscribe_font_driver
.type
= Quniscribe
;
1005 uniscribe_available
= 1;
1007 register_font_driver (&uniscribe_font_driver
, NULL
);