/* font.c -- "Font" primitives.
-Copyright (C) 2006-2012 Free Software Foundation, Inc.
+Copyright (C) 2006-2013 Free Software Foundation, Inc.
Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011
National Institute of Advanced Industrial Science and Technology (AIST)
Registration Number H13PRO009
}
\f
-/* Font name parser and unparser */
+/* Font name parser and unparser. */
static int parse_matrix (const char *);
static int font_expand_wildcards (Lisp_Object *, int);
f[j] = "*";
else
{
+ int c, k, l;
+ ptrdiff_t alloc;
+
val = SYMBOL_NAME (val);
- f[j] = SSDATA (val);
+ alloc = SBYTES (val) + 1;
+ if (nbytes <= alloc)
+ return -1;
+ f[j] = p = alloca (alloc);
+ /* Copy the name while excluding '-', '?', ',', and '"'. */
+ for (k = l = 0; k < alloc; k++)
+ {
+ c = SREF (val, k);
+ if (c != '-' && c != '?' && c != ',' && c != '"')
+ p[l++] = c;
+ }
}
}
/* This part (through the next ^L) is still experimental and not
tested much. We may drastically change codes. */
-/* OTF handler */
+/* OTF handler. */
#if 0
OTF *otf;
if (! NILP (val))
- otf = XSAVE_VALUE (XCDR (val))->pointer;
+ otf = XSAVE_POINTER (XCDR (val), 0);
else
{
otf = STRINGP (file) ? OTF_open (SSDATA (file)) : NULL;
- val = make_save_value (otf, 0);
+ val = make_save_pointer (otf);
otf_list = Fcons (Fcons (file, val), otf_list);
}
return otf;
#endif /* 0 */
\f
-/* Font sorting */
+/* Font sorting. */
static unsigned font_score (Lisp_Object, Lisp_Object *);
static int font_compare (const void *, const void *);
{
EMACS_INT diff = ((XINT (AREF (entity, i)) >> 8)
- (XINT (spec_prop[i]) >> 8));
- if (diff < 0)
- diff = - diff;
- score |= min (diff, 127) << sort_shift_bits[i];
+ score |= min (eabs (diff), 127) << sort_shift_bits[i];
}
/* Score the size. Maximum difference is 127. */
if (CONSP (Vface_font_rescale_alist))
pixel_size *= font_rescale_ratio (entity);
- diff = pixel_size - XINT (AREF (entity, FONT_SIZE_INDEX));
- if (diff < 0)
- diff = - diff;
- diff <<= 1;
+ diff = eabs (pixel_size - XINT (AREF (entity, FONT_SIZE_INDEX))) << 1;
if (! NILP (spec_prop[FONT_DPI_INDEX])
&& ! EQ (spec_prop[FONT_DPI_INDEX], AREF (entity, FONT_DPI_INDEX)))
diff |= 1;
return val;
}
-static int num_fonts;
static void
font_clear_cache (FRAME_PTR f, Lisp_Object cache, struct font_driver *driver)
{
eassert (font && driver == font->driver);
driver->close (f, font);
- num_fonts--;
}
}
if (driver->free_entity)
{
int diff = XINT (AREF (entity, FONT_SIZE_INDEX)) - size;
- if (diff != 0
- && (diff < 0 ? -diff > FONT_PIXEL_SIZE_QUANTUM
- : diff > FONT_PIXEL_SIZE_QUANTUM))
+ if (eabs (diff) > FONT_PIXEL_SIZE_QUANTUM)
prop = FONT_SPEC_MAX;
}
if (prop < FONT_SPEC_MAX
return Qnil;
ASET (entity, FONT_OBJLIST_INDEX,
Fcons (font_object, AREF (entity, FONT_OBJLIST_INDEX)));
- num_fonts++;
font = XFONT_OBJECT (font_object);
min_width = (font->min_width ? font->min_width
eassert (FRAME_X_DISPLAY_INFO (f)->n_fonts);
FRAME_X_DISPLAY_INFO (f)->n_fonts--;
#endif
- num_fonts--;
}
Lisp_Object it;
int i;
- /* Set boolean values to Qt or Qnil */
+ /* Set boolean values to Qt or Qnil. */
for (i = 0; boolean_properties[i] != NULL; ++i)
for (it = alist; ! NILP (it); it = XCDR (it))
{
#ifdef HAVE_WINDOW_SYSTEM
-/* Check how many characters after POS (at most to *LIMIT) can be
- displayed by the same font in the window W. FACE, if non-NULL, is
- the face selected for the character at POS. If STRING is not nil,
- it is the string to check instead of the current buffer. In that
- case, FACE must be not NULL.
+/* Check how many characters after character/byte position POS/POS_BYTE
+ (at most to *LIMIT) can be displayed by the same font in the window W.
+ FACE, if non-NULL, is the face selected for the character at POS.
+ If STRING is not nil, it is the string to check instead of the current
+ buffer. In that case, FACE must be not NULL.
The return value is the font-object for the character at POS.
*LIMIT is set to the position where that font can't be used.
It is assured that the current buffer (or STRING) is multibyte. */
Lisp_Object
-font_range (ptrdiff_t pos, ptrdiff_t *limit, struct window *w, struct face *face, Lisp_Object string)
+font_range (ptrdiff_t pos, ptrdiff_t pos_byte, ptrdiff_t *limit,
+ struct window *w, struct face *face, Lisp_Object string)
{
- ptrdiff_t pos_byte, ignore;
+ ptrdiff_t ignore;
int c;
Lisp_Object font_object = Qnil;
if (NILP (string))
{
- pos_byte = CHAR_TO_BYTE (pos);
if (! face)
{
int face_id;
}
}
else
- {
- eassert (face);
- pos_byte = string_char_to_byte (string, pos);
- }
+ eassert (face);
while (pos < *limit)
{
#endif
\f
-/* Lisp API */
+/* Lisp API. */
DEFUN ("fontp", Ffontp, Sfontp, 1, 2, 0,
doc: /* Return t if OBJECT is a font-spec, font-entity, or font-object.
are to be displayed on. If omitted, the selected frame is used. */)
(Lisp_Object font, Lisp_Object frame)
{
- struct frame *f;
+ struct frame *f = decode_live_frame (frame);
Lisp_Object plist[10];
Lisp_Object val;
int n = 0;
- if (NILP (frame))
- frame = selected_frame;
- CHECK_LIVE_FRAME (frame);
- f = XFRAME (frame);
-
if (STRINGP (font))
{
int fontset = fs_query_fontset (font, 0);
DEFUN ("font-family-list", Ffont_family_list, Sfont_family_list, 0, 1, 0,
doc: /* List available font families on the current frame.
-Optional argument FRAME, if non-nil, specifies the target frame. */)
+If FRAME is omitted or nil, the selected frame is used. */)
(Lisp_Object frame)
{
- FRAME_PTR f;
+ struct frame *f = decode_live_frame (frame);
struct font_driver_list *driver_list;
- Lisp_Object list;
+ Lisp_Object list = Qnil;
+
+ XSETFRAME (frame, f);
- if (NILP (frame))
- frame = selected_frame;
- CHECK_LIVE_FRAME (frame);
- f = XFRAME (frame);
- list = Qnil;
for (driver_list = f->font_driver_list; driver_list;
driver_list = driver_list->next)
if (driver_list->driver->list_family)
(Lisp_Object font_entity, Lisp_Object size, Lisp_Object frame)
{
EMACS_INT isize;
+ struct frame *f = decode_live_frame (frame);
CHECK_FONT_ENTITY (font_entity);
- if (NILP (frame))
- frame = selected_frame;
- CHECK_LIVE_FRAME (frame);
if (NILP (size))
isize = XINT (AREF (font_entity, FONT_SIZE_INDEX));
{
CHECK_NUMBER_OR_FLOAT (size);
if (FLOATP (size))
- isize = POINT_TO_PIXEL (XFLOAT_DATA (size), XFRAME (frame)->resy);
+ isize = POINT_TO_PIXEL (XFLOAT_DATA (size), f->resy);
else
isize = XINT (size);
if (! (INT_MIN <= isize && isize <= INT_MAX))
if (isize == 0)
isize = 120;
}
- return font_open_entity (XFRAME (frame), font_entity, isize);
+ return font_open_entity (f, font_entity, isize);
}
DEFUN ("close-font", Fclose_font, Sclose_font, 1, 2, 0,
(Lisp_Object font_object, Lisp_Object frame)
{
CHECK_FONT_OBJECT (font_object);
- if (NILP (frame))
- frame = selected_frame;
- CHECK_LIVE_FRAME (frame);
- font_close_object (XFRAME (frame), font_object);
+ font_close_object (decode_live_frame (frame), font_object);
return Qnil;
}
CHECK_FONT_GET_OBJECT (font_object, font);
- val = Fmake_vector (make_number (9), Qnil);
+ val = make_uninit_vector (9);
ASET (val, 0, AREF (font_object, FONT_NAME_INDEX));
ASET (val, 1, AREF (font_object, FONT_FILE_INDEX));
ASET (val, 2, make_number (font->pixel_size));
ASET (val, 7, make_number (font->average_width));
if (font->driver->otf_capability)
ASET (val, 8, Fcons (Qopentype, font->driver->otf_capability (font)));
+ else
+ ASET (val, 8, Qnil);
return val;
}
character at index specified by POSITION. */)
(Lisp_Object position, Lisp_Object window, Lisp_Object string)
{
- struct window *w;
- ptrdiff_t pos;
+ struct window *w = decode_live_window (window);
- if (NILP (window))
- window = selected_window;
- CHECK_LIVE_WINDOW (window);
- w = XWINDOW (window);
if (NILP (string))
{
if (XBUFFER (w->buffer) != current_buffer)
CHECK_NUMBER_COERCE_MARKER (position);
if (! (BEGV <= XINT (position) && XINT (position) < ZV))
args_out_of_range_3 (position, make_number (BEGV), make_number (ZV));
- pos = XINT (position);
}
else
{
CHECK_STRING (string);
if (! (0 <= XINT (position) && XINT (position) < SCHARS (string)))
args_out_of_range (string, position);
- pos = XINT (position);
}
- return font_at (-1, pos, NULL, w, string);
+ return font_at (-1, XINT (position), NULL, w, string);
}
#if 0
OPENED-NAME is the name used for opening the font,
FULL-NAME is the full name of the font,
SIZE is the pixelsize of the font,
- HEIGHT is the pixel-height of the font (i.e ascent + descent),
+ HEIGHT is the pixel-height of the font (i.e., ascent + descent),
BASELINE-OFFSET is the upward offset pixels from ASCII baseline,
RELATIVE-COMPOSE and DEFAULT-ASCENT are the numbers controlling
how to compose characters.
If the named font is not yet loaded, return nil. */)
(Lisp_Object name, Lisp_Object frame)
{
- FRAME_PTR f;
+ struct frame *f;
struct font *font;
Lisp_Object info;
Lisp_Object font_object;
if (! FONTP (name))
CHECK_STRING (name);
- if (NILP (frame))
- frame = selected_frame;
- CHECK_LIVE_FRAME (frame);
- f = XFRAME (frame);
+ f = decode_live_frame (frame);
if (STRINGP (name))
{
return Qnil;
font = XFONT_OBJECT (font_object);
- info = Fmake_vector (make_number (7), Qnil);
+ info = make_uninit_vector (7);
ASET (info, 0, AREF (font_object, FONT_NAME_INDEX));
ASET (info, 1, AREF (font_object, FONT_FULLNAME_INDEX));
ASET (info, 2, make_number (font->pixel_size));
XSYMBOL (intern_c_string ("font-width-table"))->constant = 1;
staticpro (&font_style_table);
- font_style_table = Fmake_vector (make_number (3), Qnil);
+ font_style_table = make_uninit_vector (3);
ASET (font_style_table, 0, Vfont_weight_table);
ASET (font_style_table, 1, Vfont_slant_table);
ASET (font_style_table, 2, Vfont_width_table);