1 /* Font backend for the Microsoft W32 Uniscribe API.
2 Copyright (C) 2008-2012 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
35 #include "dispextern.h"
36 #include "character.h"
38 #include "composite.h"
43 struct uniscribe_font_info
45 struct w32font_info w32_font
;
49 int uniscribe_available
= 0;
51 /* Defined in w32font.c, since it is required there as well. */
52 extern Lisp_Object Quniscribe
;
53 extern Lisp_Object Qopentype
;
55 /* EnumFontFamiliesEx callback. */
56 static int CALLBACK
add_opentype_font_name_to_list (ENUMLOGFONTEX
*,
59 /* Used by uniscribe_otf_capability. */
60 static Lisp_Object
otf_features (HDC context
, char *table
);
63 memq_no_quit (Lisp_Object elt
, Lisp_Object list
)
65 while (CONSP (list
) && ! EQ (XCAR (list
), elt
))
67 return (CONSP (list
));
71 /* Font backend interface implementation. */
73 uniscribe_list (Lisp_Object frame
, Lisp_Object font_spec
)
75 Lisp_Object fonts
= w32font_list_internal (frame
, font_spec
, 1);
76 FONT_ADD_LOG ("uniscribe-list", font_spec
, fonts
);
81 uniscribe_match (Lisp_Object frame
, Lisp_Object font_spec
)
83 Lisp_Object entity
= w32font_match_internal (frame
, font_spec
, 1);
84 FONT_ADD_LOG ("uniscribe-match", font_spec
, entity
);
89 uniscribe_list_family (Lisp_Object frame
)
91 Lisp_Object list
= Qnil
;
92 LOGFONT font_match_pattern
;
94 FRAME_PTR f
= XFRAME (frame
);
96 memset (&font_match_pattern
, 0, sizeof (font_match_pattern
));
97 /* Limit enumerated fonts to outline fonts to save time. */
98 font_match_pattern
.lfOutPrecision
= OUT_OUTLINE_PRECIS
;
100 dc
= get_frame_dc (f
);
102 EnumFontFamiliesEx (dc
, &font_match_pattern
,
103 (FONTENUMPROC
) add_opentype_font_name_to_list
,
105 release_frame_dc (f
, dc
);
111 uniscribe_open (FRAME_PTR f
, Lisp_Object font_entity
, int pixel_size
)
113 Lisp_Object font_object
114 = font_make_object (VECSIZE (struct uniscribe_font_info
),
115 font_entity
, pixel_size
);
116 struct uniscribe_font_info
*uniscribe_font
117 = (struct uniscribe_font_info
*) XFONT_OBJECT (font_object
);
119 ASET (font_object
, FONT_TYPE_INDEX
, Quniscribe
);
121 if (!w32font_open_internal (f
, font_entity
, pixel_size
, font_object
))
126 /* Initialize the cache for this font. */
127 uniscribe_font
->cache
= NULL
;
129 /* Uniscribe backend uses glyph indices. */
130 uniscribe_font
->w32_font
.glyph_idx
= ETO_GLYPH_INDEX
;
132 /* Mark the format as opentype */
133 uniscribe_font
->w32_font
.font
.props
[FONT_FORMAT_INDEX
] = Qopentype
;
134 uniscribe_font
->w32_font
.font
.driver
= &uniscribe_font_driver
;
140 uniscribe_close (FRAME_PTR f
, struct font
*font
)
142 struct uniscribe_font_info
*uniscribe_font
143 = (struct uniscribe_font_info
*) font
;
145 if (uniscribe_font
->cache
)
146 ScriptFreeCache (&(uniscribe_font
->cache
));
148 w32font_close (f
, font
);
151 /* Return a list describing which scripts/languages FONT supports by
152 which GSUB/GPOS features of OpenType tables. */
154 uniscribe_otf_capability (struct font
*font
)
159 Lisp_Object capability
= Fcons (Qnil
, Qnil
);
160 Lisp_Object features
;
162 f
= XFRAME (selected_frame
);
163 context
= get_frame_dc (f
);
164 old_font
= SelectObject (context
, FONT_HANDLE (font
));
166 features
= otf_features (context
, "GSUB");
167 XSETCAR (capability
, features
);
168 features
= otf_features (context
, "GPOS");
169 XSETCDR (capability
, features
);
171 SelectObject (context
, old_font
);
172 release_frame_dc (f
, context
);
177 /* Uniscribe implementation of shape for font backend.
179 Shape text in LGSTRING. See the docstring of
180 `composition-get-gstring' for the format of LGSTRING. If the
181 (N+1)th element of LGSTRING is nil, input of shaping is from the
182 1st to (N)th elements. In each input glyph, FROM, TO, CHAR, and
183 CODE are already set.
185 This function updates all fields of the input glyphs. If the
186 output glyphs (M) are more than the input glyphs (N), (N+1)th
187 through (M)th elements of LGSTRING are updated possibly by making
188 a new glyph object and storing it in LGSTRING. If (M) is greater
189 than the length of LGSTRING, nil should be returned. In that case,
190 this function is called again with a larger LGSTRING. */
192 uniscribe_shape (Lisp_Object lgstring
)
195 struct uniscribe_font_info
* uniscribe_font
;
197 int nitems
, max_items
, i
, max_glyphs
, done_glyphs
;
199 WORD
*glyphs
, *clusters
;
201 SCRIPT_VISATTR
*attributes
;
206 struct frame
* f
= NULL
;
208 HFONT old_font
= NULL
;
210 CHECK_FONT_GET_OBJECT (LGSTRING_FONT (lgstring
), font
);
211 uniscribe_font
= (struct uniscribe_font_info
*) font
;
213 /* Get the chars from lgstring in a form we can use with uniscribe. */
214 max_glyphs
= nchars
= LGSTRING_GLYPH_LEN (lgstring
);
216 chars
= (wchar_t *) alloca (nchars
* sizeof (wchar_t));
217 /* FIXME: This loop assumes that characters in the input LGSTRING
218 are all inside the BMP. Need to encode characters beyond the BMP
220 for (i
= 0; i
< nchars
; i
++)
222 /* lgstring can be bigger than the number of characters in it, in
223 the case where more glyphs are required to display those characters.
224 If that is the case, note the real number of characters. */
225 if (NILP (LGSTRING_GLYPH (lgstring
, i
)))
228 chars
[i
] = LGLYPH_CHAR (LGSTRING_GLYPH (lgstring
, i
));
231 /* First we need to break up the glyph string into runs of glyphs that
232 can be treated together. First try a single run. */
234 items
= xmalloc (sizeof (SCRIPT_ITEM
) * max_items
+ 1);
236 while ((result
= ScriptItemize (chars
, nchars
, max_items
, NULL
, NULL
,
237 items
, &nitems
)) == E_OUTOFMEMORY
)
239 /* If that wasn't enough, keep trying with one more run. */
241 items
= (SCRIPT_ITEM
*) xrealloc (items
,
242 sizeof (SCRIPT_ITEM
) * max_items
+ 1);
251 glyphs
= alloca (max_glyphs
* sizeof (WORD
));
252 clusters
= alloca (nchars
* sizeof (WORD
));
253 attributes
= alloca (max_glyphs
* sizeof (SCRIPT_VISATTR
));
254 advances
= alloca (max_glyphs
* sizeof (int));
255 offsets
= alloca (max_glyphs
* sizeof (GOFFSET
));
257 for (i
= 0; i
< nitems
; i
++)
259 int nglyphs
, nchars_in_run
;
260 nchars_in_run
= items
[i
+1].iCharPos
- items
[i
].iCharPos
;
261 /* Force ScriptShape to generate glyphs in the same order as
262 they are in the input LGSTRING, which is in the logical
264 items
[i
].a
.fLogicalOrder
= 1;
266 /* Context may be NULL here, in which case the cache should be
267 used without needing to select the font. */
268 result
= ScriptShape (context
, &(uniscribe_font
->cache
),
269 chars
+ items
[i
].iCharPos
, nchars_in_run
,
270 max_glyphs
- done_glyphs
, &(items
[i
].a
),
271 glyphs
, clusters
, attributes
, &nglyphs
);
273 if (result
== E_PENDING
&& !context
)
275 /* This assumes the selected frame is on the same display as the
276 one we are drawing. It would be better for the frame to be
278 f
= XFRAME (selected_frame
);
279 context
= get_frame_dc (f
);
280 old_font
= SelectObject (context
, FONT_HANDLE (font
));
282 result
= ScriptShape (context
, &(uniscribe_font
->cache
),
283 chars
+ items
[i
].iCharPos
, nchars_in_run
,
284 max_glyphs
- done_glyphs
, &(items
[i
].a
),
285 glyphs
, clusters
, attributes
, &nglyphs
);
288 if (result
== E_OUTOFMEMORY
)
290 /* Need a bigger lgstring. */
294 else if (FAILED (result
))
296 /* Can't shape this run - return results so far if any. */
299 else if (items
[i
].a
.fNoGlyphIndex
)
301 /* Glyph indices not supported by this font (or OS), means we
302 can't really do any meaningful shaping. */
307 result
= ScriptPlace (context
, &(uniscribe_font
->cache
),
308 glyphs
, nglyphs
, attributes
, &(items
[i
].a
),
309 advances
, offsets
, &overall_metrics
);
310 if (result
== E_PENDING
&& !context
)
312 /* Cache not complete... */
313 f
= XFRAME (selected_frame
);
314 context
= get_frame_dc (f
);
315 old_font
= SelectObject (context
, FONT_HANDLE (font
));
317 result
= ScriptPlace (context
, &(uniscribe_font
->cache
),
318 glyphs
, nglyphs
, attributes
, &(items
[i
].a
),
319 advances
, offsets
, &overall_metrics
);
321 if (SUCCEEDED (result
))
323 int j
, from
, to
, adj_offset
= 0;
328 for (j
= 0; j
< nglyphs
; j
++)
330 int lglyph_index
= j
+ done_glyphs
;
331 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, lglyph_index
);
337 lglyph
= Fmake_vector (make_number (LGLYPH_SIZE
), Qnil
);
338 LGSTRING_SET_GLYPH (lgstring
, lglyph_index
, lglyph
);
340 /* Copy to a 32-bit data type to shut up the
341 compiler warning in LGLYPH_SET_CODE about
342 comparison being always false. */
344 LGLYPH_SET_CODE (lglyph
, gl
);
346 /* Detect clusters, for linking codes back to
348 if (attributes
[j
].fClusterStart
)
350 while (from
< nchars_in_run
&& clusters
[from
] < j
)
352 if (from
>= nchars_in_run
)
353 from
= to
= nchars_in_run
- 1;
357 to
= nchars_in_run
- 1;
358 for (k
= from
+ 1; k
< nchars_in_run
; k
++)
368 /* For RTL text, the Uniscribe shaper prepares
369 the values in ADVANCES array for layout in
370 reverse order, whereby "advance width" is
371 applied to move the pen in reverse direction
372 and _before_ drawing the glyph. Since we
373 draw glyphs in their normal left-to-right
374 order, we need to adjust the coordinates of
375 each non-base glyph in a grapheme cluster via
376 X-OFF component of the gstring's ADJUSTMENT
377 sub-vector. This loop computes, for each
378 grapheme cluster, the initial value of the
379 adjustment for the base character, which is
380 then updated for each successive glyph in the
387 while (j1
< nglyphs
&& !attributes
[j1
].fClusterStart
)
389 adj_offset
+= advances
[j1
];
395 LGLYPH_SET_CHAR (lglyph
, chars
[items
[i
].iCharPos
397 LGLYPH_SET_FROM (lglyph
, items
[i
].iCharPos
+ from
);
398 LGLYPH_SET_TO (lglyph
, items
[i
].iCharPos
+ to
);
401 LGLYPH_SET_WIDTH (lglyph
, advances
[j
]);
402 LGLYPH_SET_ASCENT (lglyph
, font
->ascent
);
403 LGLYPH_SET_DESCENT (lglyph
, font
->descent
);
405 result
= ScriptGetGlyphABCWidth (context
,
406 &(uniscribe_font
->cache
),
407 glyphs
[j
], &char_metric
);
408 if (result
== E_PENDING
&& !context
)
410 /* Cache incomplete... */
411 f
= XFRAME (selected_frame
);
412 context
= get_frame_dc (f
);
413 old_font
= SelectObject (context
, FONT_HANDLE (font
));
414 result
= ScriptGetGlyphABCWidth (context
,
415 &(uniscribe_font
->cache
),
416 glyphs
[j
], &char_metric
);
419 if (SUCCEEDED (result
))
421 int lbearing
= char_metric
.abcA
;
422 int rbearing
= char_metric
.abcA
+ char_metric
.abcB
;
424 LGLYPH_SET_LBEARING (lglyph
, lbearing
);
425 LGLYPH_SET_RBEARING (lglyph
, rbearing
);
429 LGLYPH_SET_LBEARING (lglyph
, 0);
430 LGLYPH_SET_RBEARING (lglyph
, advances
[j
]);
433 if (offsets
[j
].du
|| offsets
[j
].dv
434 /* For non-base glyphs of RTL grapheme clusters,
435 adjust the X offset even if both DU and DV
437 || (!attributes
[j
].fClusterStart
&& items
[i
].a
.fRTL
))
440 vec
= Fmake_vector (make_number (3), Qnil
);
443 /* Empirically, it looks like Uniscribe
444 interprets DU in reverse direction for
445 RTL clusters. E.g., if we don't reverse
446 the direction, the Hebrew point HOLAM is
447 drawn above the right edge of the base
448 consonant, instead of above the left edge. */
449 ASET (vec
, 0, make_number (-offsets
[j
].du
451 /* Update the adjustment value for the width
452 advance of the glyph we just emitted. */
453 adj_offset
-= 2 * advances
[j
];
456 ASET (vec
, 0, make_number (offsets
[j
].du
+ adj_offset
));
457 /* In the font definition coordinate system, the
458 Y coordinate points up, while in our screen
459 coordinates Y grows downwards. So we need to
460 reverse the sign of Y-OFFSET here. */
461 ASET (vec
, 1, make_number (-offsets
[j
].dv
));
462 /* Based on what ftfont.c does... */
463 ASET (vec
, 2, make_number (advances
[j
]));
464 LGLYPH_SET_ADJUSTMENT (lglyph
, vec
);
468 LGLYPH_SET_ADJUSTMENT (lglyph
, Qnil
);
469 /* Update the adjustment value to compensate for
470 the width of the base character. */
472 adj_offset
-= advances
[j
];
477 done_glyphs
+= nglyphs
;
484 SelectObject (context
, old_font
);
485 release_frame_dc (f
, context
);
491 return make_number (done_glyphs
);
494 /* Uniscribe implementation of encode_char for font backend.
495 Return a glyph code of FONT for character C (Unicode code point).
496 If FONT doesn't have such a glyph, return FONT_INVALID_CODE. */
498 uniscribe_encode_char (struct font
*font
, int c
)
501 struct frame
*f
= NULL
;
502 HFONT old_font
= NULL
;
503 unsigned code
= FONT_INVALID_CODE
;
508 struct uniscribe_font_info
*uniscribe_font
509 = (struct uniscribe_font_info
*)font
;
518 DWORD surrogate
= c
- 0x10000;
520 /* High surrogate: U+D800 - U+DBFF. */
521 ch
[0] = 0xD800 + ((surrogate
>> 10) & 0x03FF);
522 /* Low surrogate: U+DC00 - U+DFFF. */
523 ch
[1] = 0xDC00 + (surrogate
& 0x03FF);
527 /* Non BMP characters must be handled by the uniscribe shaping
528 engine as GDI functions (except blindly displaying lines of
529 Unicode text) and the promising looking ScriptGetCMap do not
530 convert surrogate pairs to glyph indexes correctly. */
532 items
= (SCRIPT_ITEM
*) alloca (sizeof (SCRIPT_ITEM
) * 2 + 1);
533 if (SUCCEEDED (ScriptItemize (ch
, len
, 2, NULL
, NULL
, items
, &nitems
)))
536 /* Surrogates seem to need 2 here, even though only one glyph is
537 returned. Indic characters can also produce 2 or more glyphs for
538 a single code point, but they need to use uniscribe_shape
539 above for correct display. */
540 WORD glyphs
[2], clusters
[2];
541 SCRIPT_VISATTR attrs
[2];
544 /* Force ScriptShape to generate glyphs in the logical
546 items
[0].a
.fLogicalOrder
= 1;
548 result
= ScriptShape (context
, &(uniscribe_font
->cache
),
549 ch
, len
, 2, &(items
[0].a
),
550 glyphs
, clusters
, attrs
, &nglyphs
);
552 if (result
== E_PENDING
)
554 /* Use selected frame until API is updated to pass
556 f
= XFRAME (selected_frame
);
557 context
= get_frame_dc (f
);
558 old_font
= SelectObject (context
, FONT_HANDLE (font
));
559 result
= ScriptShape (context
, &(uniscribe_font
->cache
),
560 ch
, len
, 2, &(items
[0].a
),
561 glyphs
, clusters
, attrs
, &nglyphs
);
564 if (SUCCEEDED (result
) && nglyphs
== 1)
566 /* Some fonts return .notdef glyphs instead of failing.
567 (TrueType spec reserves glyph code 0 for .notdef) */
571 else if (SUCCEEDED (result
) || result
== E_OUTOFMEMORY
)
573 /* This character produces zero or more than one glyph
574 when shaped. But we still need the return from here
575 to be valid for the shaping engine to be invoked
577 result
= ScriptGetCMap (context
, &(uniscribe_font
->cache
),
579 if (SUCCEEDED (result
) && glyphs
[0])
586 SelectObject (context
, old_font
);
587 release_frame_dc (f
, context
);
595 Lisp_Object uniscribe_get_cache (Lisp_Object frame);
596 void uniscribe_free_entity (Lisp_Object font_entity);
597 int uniscribe_has_char (Lisp_Object entity, int c);
598 int uniscribe_text_extents (struct font *font, unsigned *code,
599 int nglyphs, struct font_metrics *metrics);
600 int uniscribe_draw (struct glyph_string *s, int from, int to,
601 int x, int y, int with_background);
604 int uniscribe_prepare_face (FRAME_PTR f, struct face *face);
605 void uniscribe_done_face (FRAME_PTR f, struct face *face);
606 int uniscribe_get_bitmap (struct font *font, unsigned code,
607 struct font_bitmap *bitmap, int bits_per_pixel);
608 void uniscribe_free_bitmap (struct font *font, struct font_bitmap *bitmap);
609 void * uniscribe_get_outline (struct font *font, unsigned code);
610 void uniscribe_free_outline (struct font *font, void *outline);
611 int uniscribe_anchor_point (struct font *font, unsigned code,
612 int index, int *x, int *y);
613 int uniscribe_start_for_frame (FRAME_PTR f);
614 int uniscribe_end_for_frame (FRAME_PTR f);
619 /* Callback function for EnumFontFamiliesEx.
620 Adds the name of opentype fonts to a Lisp list (passed in as the
623 add_opentype_font_name_to_list (ENUMLOGFONTEX
*logical_font
,
624 NEWTEXTMETRICEX
*physical_font
,
625 DWORD font_type
, LPARAM list_object
)
627 Lisp_Object
* list
= (Lisp_Object
*) list_object
;
630 /* Skip vertical fonts (intended only for printing) */
631 if (logical_font
->elfLogFont
.lfFaceName
[0] == '@')
634 /* Skip non opentype fonts. Count old truetype fonts as opentype,
635 as some of them do contain GPOS and GSUB data that Uniscribe
637 if (!(physical_font
->ntmTm
.ntmFlags
& NTMFLAGS_OPENTYPE
)
638 && font_type
!= TRUETYPE_FONTTYPE
)
641 /* Skip fonts that have no Unicode coverage. */
642 if (!physical_font
->ntmFontSig
.fsUsb
[3]
643 && !physical_font
->ntmFontSig
.fsUsb
[2]
644 && !physical_font
->ntmFontSig
.fsUsb
[1]
645 && !(physical_font
->ntmFontSig
.fsUsb
[0] & 0x3fffffff))
648 family
= intern_font_name (logical_font
->elfLogFont
.lfFaceName
);
649 if (! memq_no_quit (family
, *list
))
650 *list
= Fcons (family
, *list
);
656 /* :otf property handling.
657 Since the necessary Uniscribe APIs for getting font tag information
658 are only available in Vista, we need to parse the font data directly
659 according to the OpenType Specification. */
661 /* Push into DWORD backwards to cope with endianness. */
662 #define OTF_TAG(STR) \
663 ((STR[3] << 24) | (STR[2] << 16) | (STR[1] << 8) | STR[0])
665 #define OTF_INT16_VAL(TABLE, OFFSET, PTR) \
667 BYTE temp, data[2]; \
668 if (GetFontData (context, TABLE, OFFSET, data, 2) != 2) \
669 goto font_table_error; \
670 temp = data[0], data[0] = data[1], data[1] = temp; \
671 memcpy (PTR, data, 2); \
674 /* Do not reverse the bytes, because we will compare with a OTF_TAG value
675 that has them reversed already. */
676 #define OTF_DWORDTAG_VAL(TABLE, OFFSET, PTR) \
678 if (GetFontData (context, TABLE, OFFSET, PTR, 4) != 4) \
679 goto font_table_error; \
682 #define OTF_TAG_VAL(TABLE, OFFSET, STR) \
684 if (GetFontData (context, TABLE, OFFSET, STR, 4) != 4) \
685 goto font_table_error; \
689 #define SNAME(VAL) SDATA (SYMBOL_NAME (VAL))
691 /* Check if font supports the otf script/language/features specified.
692 OTF_SPEC is in the format
693 (script lang [(gsub_feature ...)|nil] [(gpos_feature ...)]?) */
695 uniscribe_check_otf (LOGFONT
*font
, Lisp_Object otf_spec
)
697 Lisp_Object script
, lang
, rest
;
698 Lisp_Object features
[2];
699 DWORD feature_tables
[2];
700 DWORD script_tag
, default_script
, lang_tag
= 0;
703 HFONT check_font
, old_font
;
707 /* Check the spec is in the right format. */
708 if (!CONSP (otf_spec
) || XINT (Flength (otf_spec
)) < 3)
711 /* Break otf_spec into its components. */
712 script
= XCAR (otf_spec
);
713 rest
= XCDR (otf_spec
);
718 features
[0] = XCAR (rest
);
723 features
[1] = XCAR (rest
);
725 /* Set up tags we will use in the search. */
726 feature_tables
[0] = OTF_TAG ("GSUB");
727 feature_tables
[1] = OTF_TAG ("GPOS");
728 default_script
= OTF_TAG ("DFLT");
730 script_tag
= default_script
;
732 script_tag
= OTF_TAG (SNAME (script
));
734 lang_tag
= OTF_TAG (SNAME (lang
));
736 /* Set up graphics context so we can use the font. */
737 f
= XFRAME (selected_frame
);
738 context
= get_frame_dc (f
);
739 check_font
= CreateFontIndirect (font
);
740 old_font
= SelectObject (context
, check_font
);
742 /* Everything else is contained within otf_spec so should get
743 marked along with it. */
746 /* Scan GSUB and GPOS tables. */
747 for (i
= 0; i
< 2; i
++)
749 int j
, n_match_features
;
750 unsigned short scriptlist_table
, feature_table
, n_scripts
;
751 unsigned short script_table
, langsys_table
, n_langs
;
752 unsigned short feature_index
, n_features
;
753 DWORD tbl
= feature_tables
[i
];
755 /* Skip if no features requested from this table. */
756 if (NILP (features
[i
]))
759 /* If features is not a cons, this font spec is messed up. */
760 if (!CONSP (features
[i
]))
763 /* Read GPOS/GSUB header. */
764 OTF_INT16_VAL (tbl
, 4, &scriptlist_table
);
765 OTF_INT16_VAL (tbl
, 6, &feature_table
);
766 OTF_INT16_VAL (tbl
, scriptlist_table
, &n_scripts
);
768 /* Find the appropriate script table. */
770 for (j
= 0; j
< n_scripts
; j
++)
773 OTF_DWORDTAG_VAL (tbl
, scriptlist_table
+ 2 + j
* 6, &script_id
);
774 if (script_id
== script_tag
)
776 OTF_INT16_VAL (tbl
, scriptlist_table
+ 6 + j
* 6, &script_table
);
779 #if 0 /* Causes false positives. */
780 /* If there is a DFLT script defined in the font, use it
781 if the specified script is not found. */
782 else if (script_id
== default_script
)
783 OTF_INT16_VAL (tbl
, scriptlist_table
+ 6 + j
* 6, &script_table
);
786 /* If no specific or default script table was found, then this font
787 does not support the script. */
791 /* Offset is from beginning of scriptlist_table. */
792 script_table
+= scriptlist_table
;
794 /* Get default langsys table. */
795 OTF_INT16_VAL (tbl
, script_table
, &langsys_table
);
797 /* If lang was specified, see if font contains a specific entry. */
800 OTF_INT16_VAL (tbl
, script_table
+ 2, &n_langs
);
802 for (j
= 0; j
< n_langs
; j
++)
805 OTF_DWORDTAG_VAL (tbl
, script_table
+ 4 + j
* 6, &lang_id
);
806 if (lang_id
== lang_tag
)
808 OTF_INT16_VAL (tbl
, script_table
+ 8 + j
* 6, &langsys_table
);
817 /* Offset is from beginning of script table. */
818 langsys_table
+= script_table
;
820 /* Check the features. Features may contain nil according to
821 documentation in font_prop_validate_otf, so count them. */
822 n_match_features
= 0;
823 for (rest
= features
[i
]; CONSP (rest
); rest
= XCDR (rest
))
825 Lisp_Object feature
= XCAR (rest
);
830 /* If there are no features to check, skip checking. */
831 if (!n_match_features
)
834 /* First check required feature (if any). */
835 OTF_INT16_VAL (tbl
, langsys_table
+ 2, &feature_index
);
836 if (feature_index
!= 0xFFFF)
839 OTF_TAG_VAL (tbl
, feature_table
+ 2 + feature_index
* 6, feature_id
);
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
])))
846 /* Now check all the other features. */
847 OTF_INT16_VAL (tbl
, langsys_table
+ 4, &n_features
);
848 for (j
= 0; j
< n_features
; j
++)
851 OTF_INT16_VAL (tbl
, langsys_table
+ 6 + j
* 2, &feature_index
);
852 OTF_TAG_VAL (tbl
, feature_table
+ 2 + feature_index
* 6, feature_id
);
853 /* Assume no duplicates in the font table. This allows us to mark
854 the features off by simply decrementing a counter. */
855 if (!NILP (Fmemq (intern (feature_id
), features
[i
])))
859 if (n_match_features
> 0)
867 /* restore graphics context. */
868 SelectObject (context
, old_font
);
869 DeleteObject (check_font
);
870 release_frame_dc (f
, context
);
876 otf_features (HDC context
, char *table
)
878 Lisp_Object script_list
= Qnil
;
879 unsigned short scriptlist_table
, n_scripts
, feature_table
;
880 DWORD tbl
= OTF_TAG (table
);
883 /* Look for scripts in the table. */
884 OTF_INT16_VAL (tbl
, 4, &scriptlist_table
);
885 OTF_INT16_VAL (tbl
, 6, &feature_table
);
886 OTF_INT16_VAL (tbl
, scriptlist_table
, &n_scripts
);
888 for (i
= 0; i
< n_scripts
; i
++)
890 char script
[5], lang
[5];
891 unsigned short script_table
, lang_count
, langsys_table
, feature_count
;
892 Lisp_Object script_tag
, langsys_list
, langsys_tag
, feature_list
;
893 unsigned short record_offset
= scriptlist_table
+ 2 + i
* 6;
894 OTF_TAG_VAL (tbl
, record_offset
, script
);
895 OTF_INT16_VAL (tbl
, record_offset
+ 4, &script_table
);
897 /* Offset is from beginning of script table. */
898 script_table
+= scriptlist_table
;
900 script_tag
= intern (script
);
903 /* Optional default lang. */
904 OTF_INT16_VAL (tbl
, script_table
, &langsys_table
);
907 /* Offset is from beginning of script table. */
908 langsys_table
+= script_table
;
912 OTF_INT16_VAL (tbl
, langsys_table
+ 4, &feature_count
);
913 for (k
= 0; k
< feature_count
; k
++)
916 unsigned short index
;
917 OTF_INT16_VAL (tbl
, langsys_table
+ 6 + k
* 2, &index
);
918 OTF_TAG_VAL (tbl
, feature_table
+ 2 + index
* 6, feature
);
919 feature_list
= Fcons (intern (feature
), feature_list
);
921 langsys_list
= Fcons (Fcons (langsys_tag
, feature_list
),
925 /* List of supported languages. */
926 OTF_INT16_VAL (tbl
, script_table
+ 2, &lang_count
);
928 for (j
= 0; j
< lang_count
; j
++)
930 record_offset
= script_table
+ 4 + j
* 6;
931 OTF_TAG_VAL (tbl
, record_offset
, lang
);
932 OTF_INT16_VAL (tbl
, record_offset
+ 4, &langsys_table
);
934 /* Offset is from beginning of script table. */
935 langsys_table
+= script_table
;
937 langsys_tag
= intern (lang
);
939 OTF_INT16_VAL (tbl
, langsys_table
+ 4, &feature_count
);
940 for (k
= 0; k
< feature_count
; k
++)
943 unsigned short index
;
944 OTF_INT16_VAL (tbl
, langsys_table
+ 6 + k
* 2, &index
);
945 OTF_TAG_VAL (tbl
, feature_table
+ 2 + index
* 6, feature
);
946 feature_list
= Fcons (intern (feature
), feature_list
);
948 langsys_list
= Fcons (Fcons (langsys_tag
, feature_list
),
953 script_list
= Fcons (Fcons (script_tag
, langsys_list
), script_list
);
967 struct font_driver uniscribe_font_driver
=
970 0, /* case insensitive */
974 uniscribe_list_family
,
975 NULL
, /* free_entity */
978 NULL
, /* prepare_face */
979 NULL
, /* done_face */
981 uniscribe_encode_char
,
982 w32font_text_extents
,
984 NULL
, /* get_bitmap */
985 NULL
, /* free_bitmap */
986 NULL
, /* get_outline */
987 NULL
, /* free_outline */
988 NULL
, /* anchor_point */
989 uniscribe_otf_capability
, /* Defined so (font-get FONTOBJ :otf) works. */
990 NULL
, /* otf_drive - use shape instead. */
991 NULL
, /* start_for_frame */
992 NULL
, /* end_for_frame */
995 NULL
, /* get_variation_glyphs */
996 NULL
, /* filter_properties */
997 NULL
, /* cached_font_ok */
1000 /* Note that this should be called at every startup, not just when dumping,
1001 as it needs to test for the existence of the Uniscribe library. */
1003 syms_of_w32uniscribe (void)
1007 /* Don't init uniscribe when dumping */
1011 /* Don't register if uniscribe is not available. */
1012 uniscribe
= GetModuleHandle ("usp10");
1016 uniscribe_font_driver
.type
= Quniscribe
;
1017 uniscribe_available
= 1;
1019 register_font_driver (&uniscribe_font_driver
, NULL
);