+
+/* Return ASCII font name of the fontset with ID. */
+
+Lisp_Object
+fontset_ascii (id)
+ int id;
+{
+ Lisp_Object fontset, elt;
+ fontset= FONTSET_FROM_ID (id);
+ elt = FONTSET_ASCII (fontset);
+ return XCDR (elt);
+}
+
+
+/* Free fontset of FACE. Called from free_realized_face. */
+
+void
+free_face_fontset (f, face)
+ FRAME_PTR f;
+ struct face *face;
+{
+ if (fontset_id_valid_p (face->fontset))
+ {
+ AREF (Vfontset_table, face->fontset) = Qnil;
+ if (face->fontset < next_fontset_id)
+ next_fontset_id = face->fontset;
+ }
+}
+
+
+/* Return 1 iff FACE is suitable for displaying character C.
+ Otherwise return 0. Called from the macro FACE_SUITABLE_FOR_CHAR_P
+ when C is not a single byte character.. */
+
+int
+face_suitable_for_char_p (face, c)
+ struct face *face;
+ int c;
+{
+ Lisp_Object fontset, elt;
+
+ if (SINGLE_BYTE_CHAR_P (c))
+ return (face == face->ascii_face);
+
+ xassert (fontset_id_valid_p (face->fontset));
+ fontset = FONTSET_FROM_ID (face->fontset);
+ xassert (!BASE_FONTSET_P (fontset));
+
+ elt = FONTSET_REF_VIA_BASE (fontset, c);
+ return (!NILP (elt) && face->id == XFASTINT (elt));
+}
+
+
+/* Return ID of face suitable for displaying character C on frame F.
+ The selection of face is done based on the fontset of FACE. FACE
+ should already have been realized for ASCII characters. Called
+ from the macro FACE_FOR_CHAR when C is not a single byte character. */
+
+int
+face_for_char (f, face, c)
+ FRAME_PTR f;
+ struct face *face;
+ int c;
+{
+ Lisp_Object fontset, elt;
+ int face_id;
+
+ xassert (fontset_id_valid_p (face->fontset));
+ fontset = FONTSET_FROM_ID (face->fontset);
+ xassert (!BASE_FONTSET_P (fontset));
+
+ elt = FONTSET_REF_VIA_BASE (fontset, c);
+ if (!NILP (elt))
+ return XINT (elt);
+
+ /* No face is recorded for C in the fontset of FACE. Make a new
+ realized face for C that has the same fontset. */
+ face_id = lookup_face (f, face->lface, c, face);
+
+ /* Record the face ID in FONTSET at the same index as the
+ information in the base fontset. */
+ FONTSET_SET (fontset, c, make_number (face_id));
+ return face_id;
+}
+
+
+/* Make a realized fontset for ASCII face FACE on frame F from the
+ base fontset BASE_FONTSET_ID. If BASE_FONTSET_ID is -1, use the
+ default fontset as the base. Value is the id of the new fontset.
+ Called from realize_x_face. */
+
+int
+make_fontset_for_ascii_face (f, base_fontset_id)
+ FRAME_PTR f;
+ int base_fontset_id;
+{
+ Lisp_Object base_fontset, fontset, frame;
+
+ XSETFRAME (frame, f);
+ if (base_fontset_id >= 0)
+ {
+ base_fontset = FONTSET_FROM_ID (base_fontset_id);
+ if (!BASE_FONTSET_P (base_fontset))
+ base_fontset = FONTSET_BASE (base_fontset);
+ xassert (BASE_FONTSET_P (base_fontset));
+ }
+ else
+ base_fontset = Vdefault_fontset;
+
+ fontset = make_fontset (frame, Qnil, base_fontset);
+ return XINT (FONTSET_ID (fontset));
+}
+
+
+/* Return the font name pattern for C that is recorded in the fontset
+ with ID. If a font name pattern is specified (instead of a cons of
+ family and registry), check if a font can be opened by that pattern
+ to get the fullname. If a font is opened, return that name.
+ Otherwise, return nil. If ID is -1, or the fontset doesn't contain
+ information about C, get the registry and encoding of C from the
+ default fontset. Called from choose_face_font. */
+
+Lisp_Object
+fontset_font_pattern (f, id, c)
+ FRAME_PTR f;
+ int id, c;
+{
+ Lisp_Object fontset, elt;
+ struct font_info *fontp;
+
+ elt = Qnil;
+ if (fontset_id_valid_p (id))
+ {
+ fontset = FONTSET_FROM_ID (id);
+ xassert (!BASE_FONTSET_P (fontset));
+ fontset = FONTSET_BASE (fontset);
+ elt = FONTSET_REF (fontset, c);
+ }
+ if (NILP (elt))
+ elt = FONTSET_REF (Vdefault_fontset, c);
+
+ if (!CONSP (elt))
+ return Qnil;
+ if (CONSP (XCDR (elt)))
+ return XCDR (elt);
+
+ /* The fontset specifies only a font name pattern (not cons of
+ family and registry). If a font can be opened by that pattern,
+ return the name of opened font. Otherwise return nil. The
+ exception is a font for single byte characters. In that case, we
+ return a cons of FAMILY and REGISTRY extracted from the opened
+ font name. */
+ elt = XCDR (elt);
+ xassert (STRINGP (elt));
+ fontp = FS_LOAD_FONT (f, c, SDATA (elt), -1);
+ if (!fontp)
+ return Qnil;
+
+ return font_family_registry (build_string (fontp->full_name),
+ SINGLE_BYTE_CHAR_P (c));
+}
+
+
+#if defined(WINDOWSNT) && defined (_MSC_VER)
+#pragma optimize("", off)
+#endif
+
+/* Load a font named FONTNAME to display character C on frame F.
+ Return a pointer to the struct font_info of the loaded font. If
+ loading fails, return NULL. If FACE is non-zero and a fontset is
+ assigned to it, record FACE->id in the fontset for C. If FONTNAME
+ is NULL, the name is taken from the fontset of FACE or what
+ specified by ID. */