X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/6ddd819467d1d9d0e78f13e5a15c1af9125ae67b..d3155315c85212f224fc5df0239182dafdfd6284:/src/font.c diff --git a/src/font.c b/src/font.c index d10d2280a5..2ccfd15d43 100644 --- a/src/font.c +++ b/src/font.c @@ -1,6 +1,6 @@ /* font.c -- "Font" primitives. -Copyright (C) 2006-2014 Free Software Foundation, Inc. +Copyright (C) 2006-2015 Free Software Foundation, Inc. Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 National Institute of Advanced Industrial Science and Technology (AIST) Registration Number H13PRO009 @@ -41,16 +41,8 @@ along with GNU Emacs. If not, see . */ #include TERM_HEADER #endif /* HAVE_WINDOW_SYSTEM */ -Lisp_Object Qopentype; - -/* Important character set strings. */ -Lisp_Object Qascii_0, Qiso8859_1, Qiso10646_1, Qunicode_bmp, Qunicode_sip; - #define DEFAULT_ENCODING Qiso8859_1 -/* Unicode category `Cf'. */ -static Lisp_Object QCf; - /* Vector of Vfont_weight_table, Vfont_slant_table, and Vfont_width_table. */ static Lisp_Object font_style_table; @@ -110,21 +102,6 @@ static const struct table_entry width_table[] = { 200, { "ultra-expanded", "ultraexpanded", "wide" }} }; -Lisp_Object QCfoundry; -static Lisp_Object QCadstyle, QCregistry; -/* Symbols representing keys of font extra info. */ -Lisp_Object QCspacing, QCdpi, QCscalable, QCotf, QClang, QCscript, QCavgwidth; -Lisp_Object QCantialias, QCfont_entity; -static Lisp_Object QCfc_unknown_spec; -/* Symbols representing values of font spacing property. */ -static Lisp_Object Qc, Qm, Qd; -Lisp_Object Qp; -/* Special ADSTYLE properties to avoid fonts used for Latin - characters; used in xfont.c and ftfont.c. */ -Lisp_Object Qja, Qko; - -static Lisp_Object QCuser_spec; - /* Alist of font registry symbols and the corresponding charset information. The information is retrieved from Vfont_encoding_alist on demand. @@ -179,7 +156,7 @@ font_make_spec (void) struct font_spec *spec = ((struct font_spec *) allocate_pseudovector (VECSIZE (struct font_spec), - FONT_SPEC_MAX, PVEC_FONT)); + FONT_SPEC_MAX, FONT_SPEC_MAX, PVEC_FONT)); XSETFONT (font_spec, spec); return font_spec; } @@ -191,7 +168,7 @@ font_make_entity (void) struct font_entity *entity = ((struct font_entity *) allocate_pseudovector (VECSIZE (struct font_entity), - FONT_ENTITY_MAX, PVEC_FONT)); + FONT_ENTITY_MAX, FONT_ENTITY_MAX, PVEC_FONT)); XSETFONT (font_entity, entity); return font_entity; } @@ -204,7 +181,8 @@ font_make_object (int size, Lisp_Object entity, int pixelsize) { Lisp_Object font_object; struct font *font - = (struct font *) allocate_pseudovector (size, FONT_OBJECT_MAX, PVEC_FONT); + = (struct font *) allocate_pseudovector (size, FONT_OBJECT_MAX, + FONT_OBJECT_MAX, PVEC_FONT); int i; /* GC can happen before the driver is set up, @@ -309,7 +287,7 @@ font_intern_prop (const char *str, ptrdiff_t len, bool force_symbol) return tem; name = make_specified_string (str, nchars, len, len != nchars && len == nbytes); - return intern_driver (name, obarray, XINT (tem)); + return intern_driver (name, obarray, tem); } /* Return a pixel size of font-spec SPEC on frame F. */ @@ -396,8 +374,7 @@ font_style_to_value (enum font_property_index prop, Lisp_Object val, elt = Fmake_vector (make_number (2), make_number (100)); ASET (elt, 1, val); ASET (font_style_table, prop - FONT_WEIGHT_INDEX, - Fvconcat (2, ((Lisp_Object []) - { table, Fmake_vector (make_number (1), elt) }))); + CALLN (Fvconcat, table, Fmake_vector (make_number (1), elt))); return (100 << 8) | (i << 4); } else @@ -662,30 +639,30 @@ font_prop_validate_otf (Lisp_Object prop, Lisp_Object val) values. */ static const struct { - /* Pointer to the key symbol. */ - Lisp_Object *key; + /* Index of the key symbol. */ + int key; /* Function to validate PROP's value VAL, or NULL if any value is ok. The value is VAL or its regularized value if VAL is valid, and Qerror if not. */ Lisp_Object (*validator) (Lisp_Object prop, Lisp_Object val); } font_property_table[] = - { { &QCtype, font_prop_validate_symbol }, - { &QCfoundry, font_prop_validate_symbol }, - { &QCfamily, font_prop_validate_symbol }, - { &QCadstyle, font_prop_validate_symbol }, - { &QCregistry, font_prop_validate_symbol }, - { &QCweight, font_prop_validate_style }, - { &QCslant, font_prop_validate_style }, - { &QCwidth, font_prop_validate_style }, - { &QCsize, font_prop_validate_non_neg }, - { &QCdpi, font_prop_validate_non_neg }, - { &QCspacing, font_prop_validate_spacing }, - { &QCavgwidth, font_prop_validate_non_neg }, + { { SYMBOL_INDEX (QCtype), font_prop_validate_symbol }, + { SYMBOL_INDEX (QCfoundry), font_prop_validate_symbol }, + { SYMBOL_INDEX (QCfamily), font_prop_validate_symbol }, + { SYMBOL_INDEX (QCadstyle), font_prop_validate_symbol }, + { SYMBOL_INDEX (QCregistry), font_prop_validate_symbol }, + { SYMBOL_INDEX (QCweight), font_prop_validate_style }, + { SYMBOL_INDEX (QCslant), font_prop_validate_style }, + { SYMBOL_INDEX (QCwidth), font_prop_validate_style }, + { SYMBOL_INDEX (QCsize), font_prop_validate_non_neg }, + { SYMBOL_INDEX (QCdpi), font_prop_validate_non_neg }, + { SYMBOL_INDEX (QCspacing), font_prop_validate_spacing }, + { SYMBOL_INDEX (QCavgwidth), font_prop_validate_non_neg }, /* The order of the above entries must match with enum font_property_index. */ - { &QClang, font_prop_validate_symbol }, - { &QCscript, font_prop_validate_symbol }, - { &QCotf, font_prop_validate_otf } + { SYMBOL_INDEX (QClang), font_prop_validate_symbol }, + { SYMBOL_INDEX (QCscript), font_prop_validate_symbol }, + { SYMBOL_INDEX (QCotf), font_prop_validate_otf } }; /* Return an index number of font property KEY or -1 if KEY is not an @@ -697,7 +674,7 @@ get_font_prop_index (Lisp_Object key) int i; for (i = 0; i < ARRAYELTS (font_property_table); i++) - if (EQ (key, *font_property_table[i].key)) + if (EQ (key, builtin_lisp_symbol (font_property_table[i].key))) return i; return -1; } @@ -714,7 +691,7 @@ font_prop_validate (int idx, Lisp_Object prop, Lisp_Object val) if (NILP (val)) return val; if (NILP (prop)) - prop = *font_property_table[idx].key; + prop = builtin_lisp_symbol (font_property_table[idx].key); else { idx = get_font_prop_index (prop); @@ -1011,15 +988,14 @@ font_expand_wildcards (Lisp_Object *field, int n) if (i == 0 || ! NILP (tmp[i - 1])) /* None of TMP[X] corresponds to Jth field. */ return -1; - for (; j < range[i].from; j++) - field[j] = Qnil; + memclear (field + j, (range[i].from - j) * word_size); + j = range[i].from; } field[j++] = tmp[i]; } if (! NILP (tmp[n - 1]) && j < XLFD_REGISTRY_INDEX) return -1; - for (; j < XLFD_LAST_INDEX; j++) - field[j] = Qnil; + memclear (field + j, (XLFD_LAST_INDEX - j) * word_size); if (INTEGERP (field[XLFD_ENCODING_INDEX])) field[XLFD_ENCODING_INDEX] = Fintern (Fnumber_to_string (field[XLFD_ENCODING_INDEX]), Qnil); @@ -2160,7 +2136,6 @@ font_score (Lisp_Object entity, Lisp_Object *spec_prop) } /* Score the size. Maximum difference is 127. */ - i = FONT_SIZE_INDEX; if (! NILP (spec_prop[FONT_SIZE_INDEX]) && XINT (AREF (entity, FONT_SIZE_INDEX)) > 0) { @@ -3423,16 +3398,11 @@ font_open_by_spec (struct frame *f, Lisp_Object spec) Lisp_Object font_open_by_name (struct frame *f, Lisp_Object name) { - Lisp_Object args[2]; - Lisp_Object spec, ret; - - args[0] = QCname; - args[1] = name; - spec = Ffont_spec (2, args); - ret = font_open_by_spec (f, spec); + Lisp_Object spec = CALLN (Ffont_spec, QCname, name); + Lisp_Object ret = font_open_by_spec (f, spec); /* Do not lose name originally put in. */ if (!NILP (ret)) - font_put_extra (ret, QCuser_spec, args[1]); + font_put_extra (ret, QCuser_spec, name); return ret; } @@ -3736,10 +3706,10 @@ font_at (int c, ptrdiff_t pos, struct face *face, struct window *w, if (STRINGP (string)) face_id = face_at_string_position (w, string, pos, 0, &endptr, - DEFAULT_FACE_ID, 0); + DEFAULT_FACE_ID, false); else face_id = face_at_buffer_position (w, pos, &endptr, - pos + 100, 0, -1); + pos + 100, false, -1); face = FACE_FROM_ID (f, face_id); } if (multibyte) @@ -3783,7 +3753,7 @@ font_range (ptrdiff_t pos, ptrdiff_t pos_byte, ptrdiff_t *limit, int face_id; face_id = face_at_buffer_position (w, pos, &ignore, - *limit, 0, -1); + *limit, false, -1); face = FACE_FROM_ID (XFRAME (w->frame), face_id); } } @@ -3852,17 +3822,17 @@ They are the same as face attributes of the same name. See `:foundry' -VALUE must be a string or a symbol specifying the font foundry, e.g. ``misc''. +VALUE must be a string or a symbol specifying the font foundry, e.g. `misc'. `:adstyle' VALUE must be a string or a symbol specifying the additional -typographic style information of a font, e.g. ``sans''. +typographic style information of a font, e.g. `sans'. `:registry' VALUE must be a string or a symbol specifying the charset registry and -encoding of a font, e.g. ``iso8859-1''. +encoding of a font, e.g. `iso8859-1'. `:size' @@ -3896,7 +3866,7 @@ required OpenType features. GSUB: List of OpenType GSUB feature tag symbols, or nil if none required. GPOS: List of OpenType GPOS feature tag symbols, or nil if none required. -GSUB and GPOS may contain `nil' element. In such a case, the font +GSUB and GPOS may contain nil elements. In such a case, the font must not have any of the remaining elements. For instance, if the VALUE is `(thai nil nil (mark))', the font must @@ -4204,13 +4174,7 @@ how close they are to PREFER. */) else vec = font_vconcat_entity_vectors (list); if (n == 0 || n >= ASIZE (vec)) - { - Lisp_Object args[2]; - - args[0] = vec; - args[1] = Qnil; - list = Fappend (2, args); - } + list = CALLN (Fappend, vec, Qnil); else { for (list = Qnil, n--; n >= 0; n--) @@ -4555,12 +4519,11 @@ character code corresponding to the glyph or nil if there's no corresponding character. */) (Lisp_Object font_object, Lisp_Object character, Lisp_Object otf_features) { - struct font *font; + struct font *font = CHECK_FONT_GET_OBJECT (font_object); Lisp_Object gstring_in, gstring_out, g; Lisp_Object alternates; int i, num; - CHECK_FONT_GET_OBJECT (font_object, font); if (! font->driver->otf_drive) error ("Font backend %s can't drive OpenType GSUB table", SDATA (SYMBOL_NAME (font->driver->type))); @@ -4670,12 +4633,9 @@ FEATURE is a symbol representing OpenType feature tag. If the font is not OpenType font, CAPABILITY is nil. */) (Lisp_Object font_object) { - struct font *font; - Lisp_Object val; - - CHECK_FONT_GET_OBJECT (font_object, font); + struct font *font = CHECK_FONT_GET_OBJECT (font_object); + Lisp_Object val = make_uninit_vector (9); - 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)); @@ -4714,12 +4674,11 @@ the corresponding element is nil. */) (Lisp_Object font_object, Lisp_Object from, Lisp_Object to, Lisp_Object object) { - struct font *font; + struct font *font = CHECK_FONT_GET_OBJECT (font_object); ptrdiff_t i, len; Lisp_Object *chars, vec; USE_SAFE_ALLOCA; - CHECK_FONT_GET_OBJECT (font_object, font); if (NILP (object)) { ptrdiff_t charpos, bytepos; @@ -5052,7 +5011,7 @@ build_style_table (const struct table_entry *entry, int nelement) static Lisp_Object Vfont_log_deferred; /* Prepend the font-related logging data in Vfont_log if it is not - `t'. ACTION describes a kind of font-related action (e.g. listing, + t. ACTION describes a kind of font-related action (e.g. listing, opening), ARG is the argument for the action, and RESULT is the result of the action. */ void @@ -5169,19 +5128,21 @@ syms_of_font (void) DEFSYM (Qopentype, "opentype"); + /* Important character set symbols. */ DEFSYM (Qascii_0, "ascii-0"); DEFSYM (Qiso8859_1, "iso8859-1"); DEFSYM (Qiso10646_1, "iso10646-1"); DEFSYM (Qunicode_bmp, "unicode-bmp"); DEFSYM (Qunicode_sip, "unicode-sip"); + /* Unicode category `Cf'. */ DEFSYM (QCf, "Cf"); + /* Symbols representing keys of font extra info. */ DEFSYM (QCotf, ":otf"); DEFSYM (QClang, ":lang"); DEFSYM (QCscript, ":script"); DEFSYM (QCantialias, ":antialias"); - DEFSYM (QCfoundry, ":foundry"); DEFSYM (QCadstyle, ":adstyle"); DEFSYM (QCregistry, ":registry"); @@ -5192,11 +5153,14 @@ syms_of_font (void) DEFSYM (QCfont_entity, ":font-entity"); DEFSYM (QCfc_unknown_spec, ":fc-unknown-spec"); + /* Symbols representing values of font spacing property. */ DEFSYM (Qc, "c"); DEFSYM (Qm, "m"); DEFSYM (Qp, "p"); DEFSYM (Qd, "d"); + /* Special ADSTYLE properties to avoid fonts used for Latin + characters; used in xfont.c and ftfont.c. */ DEFSYM (Qja, "ja"); DEFSYM (Qko, "ko"); @@ -5316,11 +5280,15 @@ EMACS_FONT_LOG is set. Otherwise, it is set to t. */); #ifdef HAVE_FREETYPE syms_of_ftfont (); #ifdef HAVE_X_WINDOWS +#ifdef USE_CAIRO + syms_of_ftcrfont (); +#else syms_of_xfont (); syms_of_ftxfont (); #ifdef HAVE_XFT syms_of_xftfont (); #endif /* HAVE_XFT */ +#endif /* not USE_CAIRO */ #endif /* HAVE_X_WINDOWS */ #else /* not HAVE_FREETYPE */ #ifdef HAVE_X_WINDOWS