Function: internal-char-font
internal-char-font is a function defined in font.c.
Signature
(internal-char-font POSITION &optional CH)
Documentation
For internal use only.
Source Code
// Defined in /usr/src/emacs/src/font.c
{
ptrdiff_t pos, pos_byte, dummy;
int face_id;
int c;
struct frame *f;
if (NILP (position))
{
CHECK_CHARACTER (ch);
c = XFIXNUM (ch);
f = XFRAME (selected_frame);
face_id = lookup_basic_face (NULL, f, DEFAULT_FACE_ID);
pos = -1;
}
else
{
Lisp_Object window;
struct window *w;
EMACS_INT fixed_pos = fix_position (position);
if (! (BEGV <= fixed_pos && fixed_pos < ZV))
args_out_of_range_3 (position, make_fixnum (BEGV), make_fixnum (ZV));
pos = fixed_pos;
pos_byte = CHAR_TO_BYTE (pos);
if (NILP (ch))
c = FETCH_CHAR (pos_byte);
else
{
CHECK_FIXNAT (ch);
c = XFIXNUM (ch);
}
window = Fget_buffer_window (Fcurrent_buffer (), Qnil);
if (NILP (window))
return Qnil;
w = XWINDOW (window);
f = XFRAME (w->frame);
face_id = face_at_buffer_position (w, pos, &dummy,
pos + 100, false, -1, 0);
}
if (! CHAR_VALID_P (c))
return Qnil;
if (! FRAME_WINDOW_P (f))
return terminal_glyph_code (FRAME_TERMINAL (f), c);
/* We need the basic faces to be valid below, so recompute them if
some code just happened to clear the face cache. */
if (FRAME_FACE_CACHE (f)->used == 0)
recompute_basic_faces (f);
face_id = FACE_FOR_CHAR (f, FACE_FROM_ID (f, face_id), c, pos, Qnil);
struct face *face = FACE_FROM_ID (f, face_id);
if (! face->font)
return Qnil;
unsigned code = face->font->driver->encode_char (face->font, c);
if (code == FONT_INVALID_CODE)
return Qnil;
Lisp_Object font_object;
XSETFONT (font_object, face->font);
return Fcons (font_object, INT_TO_INTEGER (code));
}