aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKenichi Handa2010-07-08 16:56:21 +0900
committerKenichi Handa2010-07-08 16:56:21 +0900
commita7840ffb291e13c2a2386ccbd58089e1d7461c16 (patch)
treeaa87386ffe4eed5fb8bc9fc85549213db10a6d1e /src
parentb32d1614abd91e784a95a34b9979b7ec0c541c9e (diff)
downloademacs-a7840ffb291e13c2a2386ccbd58089e1d7461c16.tar.gz
emacs-a7840ffb291e13c2a2386ccbd58089e1d7461c16.zip
Make font-get to get :otf value dynamically from a font-object.
Diffstat (limited to 'src')
-rw-r--r--src/font.c200
-rw-r--r--src/font.h7
2 files changed, 168 insertions, 39 deletions
diff --git a/src/font.c b/src/font.c
index f9c2381fa70..88ac17f7f66 100644
--- a/src/font.c
+++ b/src/font.c
@@ -3078,7 +3078,7 @@ font_open_entity (f, entity, pixel_size)
3078 return Qnil; 3078 return Qnil;
3079 ASET (entity, FONT_OBJLIST_INDEX, 3079 ASET (entity, FONT_OBJLIST_INDEX,
3080 Fcons (font_object, AREF (entity, FONT_OBJLIST_INDEX))); 3080 Fcons (font_object, AREF (entity, FONT_OBJLIST_INDEX)));
3081 ASET (font_object, FONT_OBJLIST_INDEX, Qnil); 3081 ASET (font_object, FONT_ENTITY_INDEX, entity);
3082 num_fonts++; 3082 num_fonts++;
3083 3083
3084 font = XFONT_OBJECT (font_object); 3084 font = XFONT_OBJECT (font_object);
@@ -4231,16 +4231,25 @@ properties in TO. */)
4231DEFUN ("font-get", Ffont_get, Sfont_get, 2, 2, 0, 4231DEFUN ("font-get", Ffont_get, Sfont_get, 2, 2, 0,
4232 doc: /* Return the value of FONT's property KEY. 4232 doc: /* Return the value of FONT's property KEY.
4233FONT is a font-spec, a font-entity, or a font-object. 4233FONT is a font-spec, a font-entity, or a font-object.
4234KEY must be one of these symbols: 4234KEY is any symbol, but these are reserved for specific meanings:
4235 :family, :weight, :slant, :width, :foundry, :adstyle, :registry, 4235 :family, :weight, :slant, :width, :foundry, :adstyle, :registry,
4236 :size, :name, :script 4236 :size, :name, :script, :otf
4237See the documentation of `font-spec' for their meanings. 4237See the documentation of `font-spec' for their meanings.
4238If FONT is a font-entity or font-object, the value of :script may be 4238In addition, if FONT is a font-entity or a font-object, values of
4239a list of scripts that are supported by the font. */) 4239:script and :otf are different from those of a font-spec as below:
4240
4241The value of :script may be a list of scripts that are supported by the font.
4242
4243The value of :otf is a cons (GSUB . GPOS) where GSUB and GPOS are lists
4244representing the OpenType features supported by the font by this form:
4245 ((SCRIPT (LANGSYS FEATURE ...) ...) ...)
4246SCRIPT, LANGSYS, and FEATURE are all symbols representing OpenType
4247Layout tags. */)
4240 (font, key) 4248 (font, key)
4241 Lisp_Object font, key; 4249 Lisp_Object font, key;
4242{ 4250{
4243 int idx; 4251 int idx;
4252 Lisp_Object val;
4244 4253
4245 CHECK_FONT (font); 4254 CHECK_FONT (font);
4246 CHECK_SYMBOL (key); 4255 CHECK_SYMBOL (key);
@@ -4250,7 +4259,28 @@ a list of scripts that are supported by the font. */)
4250 return font_style_symbolic (font, idx, 0); 4259 return font_style_symbolic (font, idx, 0);
4251 if (idx >= 0 && idx < FONT_EXTRA_INDEX) 4260 if (idx >= 0 && idx < FONT_EXTRA_INDEX)
4252 return AREF (font, idx); 4261 return AREF (font, idx);
4253 return Fcdr (Fassq (key, AREF (font, FONT_EXTRA_INDEX))); 4262 val = Fassq (key, AREF (font, FONT_EXTRA_INDEX));
4263 if (NILP (val) && EQ (key, QCotf) && FONT_OBJECT_P (font))
4264 {
4265 struct font *fontp = XFONT_OBJECT (font);
4266 Lisp_Object entity = AREF (font, FONT_ENTITY_INDEX);
4267
4268 val = Fassq (key, AREF (entity, FONT_EXTRA_INDEX));
4269 if (NILP (val))
4270 {
4271 if (fontp->driver->otf_capability)
4272 val = fontp->driver->otf_capability (fontp);
4273 else
4274 val = Fcons (Qnil, Qnil);
4275 font_put_extra (font, QCotf, val);
4276 font_put_extra (entity, QCotf, val);
4277 }
4278 else
4279 val = Fcdr (val);
4280 }
4281 else
4282 val = Fcdr (val);
4283 return val;
4254} 4284}
4255 4285
4256#ifdef HAVE_WINDOW_SYSTEM 4286#ifdef HAVE_WINDOW_SYSTEM
@@ -4342,18 +4372,37 @@ are to be displayed on. If omitted, the selected frame is used. */)
4342#endif 4372#endif
4343 4373
4344DEFUN ("font-put", Ffont_put, Sfont_put, 3, 3, 0, 4374DEFUN ("font-put", Ffont_put, Sfont_put, 3, 3, 0,
4345 doc: /* Set one property of FONT-SPEC: give property PROP value VAL. */) 4375 doc: /* Set one property of FONT: give property KEY value VAL.
4346 (font_spec, prop, val) 4376FONT is a font-spec, a font-entity, or a font-object.
4347 Lisp_Object font_spec, prop, val; 4377
4378If FONT is a font-spec, KEY can be any symbol. But if KEY is the one
4379accepted by the function `font-spec' (which see), VAL must be what
4380allowed in `font-spec'.
4381
4382If FONT is a font-entity or a font-object, KEY must not be the one
4383accepted by `font-spec'. */)
4384 (font, prop, val)
4385 Lisp_Object font, prop, val;
4348{ 4386{
4349 int idx; 4387 int idx;
4350 4388
4351 CHECK_FONT_SPEC (font_spec);
4352 idx = get_font_prop_index (prop); 4389 idx = get_font_prop_index (prop);
4353 if (idx >= 0 && idx < FONT_EXTRA_INDEX) 4390 if (idx >= 0 && idx < FONT_EXTRA_INDEX)
4354 ASET (font_spec, idx, font_prop_validate (idx, Qnil, val)); 4391 {
4392 CHECK_FONT_SPEC (font);
4393 ASET (font, idx, font_prop_validate (idx, Qnil, val));
4394 }
4355 else 4395 else
4356 font_put_extra (font_spec, prop, font_prop_validate (0, prop, val)); 4396 {
4397 if (EQ (prop, QCname)
4398 || EQ (prop, QCscript)
4399 || EQ (prop, QClang)
4400 || EQ (prop, QCotf))
4401 CHECK_FONT_SPEC (font);
4402 else
4403 CHECK_FONT (font);
4404 font_put_extra (font, prop, font_prop_validate (0, prop, val));
4405 }
4357 return val; 4406 return val;
4358} 4407}
4359 4408
@@ -4906,25 +4955,99 @@ If the font is not OpenType font, CAPABILITY is nil. */)
4906 return val; 4955 return val;
4907} 4956}
4908 4957
4909DEFUN ("get-font-glyphs", Fget_font_glyphs, Sget_font_glyphs, 2, 2, 0, 4958DEFUN ("font-get-glyphs", Ffont_get_glyphs, Sfont_get_glyphs, 3, 4, 0,
4910 doc: /* Return a vector of glyphs of FONT-OBJECT for drawing STRING. 4959 doc:
4911Each element is a vector [GLYPH-CODE LBEARING RBEARING WIDTH ASCENT DESCENT]. */) 4960 /* Return a vector of FONT-OBJECT's glyphs for the specified characters.
4912 (font_object, string) 4961FROM and TO are positions (integers or markers) specifying a region
4913 Lisp_Object font_object, string; 4962of the current buffer.
4963If the optional fourth arg OBJECT is not nil, it is a string or a
4964vector containing the target characters.
4965
4966Each element is a vector containing information of a glyph in this format:
4967 [FROM-IDX TO-IDX C CODE WIDTH LBEARING RBEARING ASCENT DESCENT ADJUSTMENT]
4968where
4969 FROM is an index numbers of a character the glyph corresponds to.
4970 TO is the same as FROM.
4971 C is the character of the glyph.
4972 CODE is the glyph-code of C in FONT-OBJECT.
4973 WIDTH thru DESCENT are the metrics (in pixels) of the glyph.
4974 ADJUSTMENT is always nil.
4975If FONT-OBJECT doesn't have a glyph for a character,
4976the corresponding element is nil. */)
4977 (font_object, from, to, object)
4978 Lisp_Object font_object, from, to, object;
4914{ 4979{
4915 struct font *font; 4980 struct font *font;
4916 int i, len; 4981 int i, len, c;
4917 Lisp_Object vec; 4982 Lisp_Object *chars, vec;
4983 USE_SAFE_ALLOCA;
4918 4984
4919 CHECK_FONT_GET_OBJECT (font_object, font); 4985 CHECK_FONT_GET_OBJECT (font_object, font);
4920 CHECK_STRING (string); 4986 if (NILP (object))
4921 len = SCHARS (string); 4987 {
4988 EMACS_INT charpos, bytepos;
4989
4990 validate_region (&from, &to);
4991 if (EQ (from, to))
4992 return Qnil;
4993 len = XFASTINT (to) - XFASTINT (from);
4994 SAFE_ALLOCA_LISP (chars, len);
4995 charpos = XFASTINT (from);
4996 bytepos = CHAR_TO_BYTE (charpos);
4997 for (i = 0; charpos < XFASTINT (to); i++)
4998 {
4999 FETCH_CHAR_ADVANCE (c, charpos, bytepos);
5000 chars[i] = make_number (c);
5001 }
5002 }
5003 else if (STRINGP (object))
5004 {
5005 const unsigned char *p;
5006
5007 CHECK_NUMBER (from);
5008 CHECK_NUMBER (to);
5009 if (XINT (from) < 0 || XINT (from) > XINT (to)
5010 || XINT (to) > SCHARS (object))
5011 args_out_of_range_3 (object, from, to);
5012 if (EQ (from, to))
5013 return Qnil;
5014 len = XFASTINT (to) - XFASTINT (from);
5015 SAFE_ALLOCA_LISP (chars, len);
5016 p = SDATA (object);
5017 if (STRING_MULTIBYTE (object))
5018 for (i = 0; i < len; i++)
5019 {
5020 c = STRING_CHAR_ADVANCE (p);
5021 chars[i] = make_number (c);
5022 }
5023 else
5024 for (i = 0; i < len; i++)
5025 chars[i] = make_number (p[i]);
5026 }
5027 else
5028 {
5029 CHECK_VECTOR (object);
5030 CHECK_NUMBER (from);
5031 CHECK_NUMBER (to);
5032 if (XINT (from) < 0 || XINT (from) > XINT (to)
5033 || XINT (to) > ASIZE (object))
5034 args_out_of_range_3 (object, from, to);
5035 if (EQ (from, to))
5036 return Qnil;
5037 len = XFASTINT (to) - XFASTINT (from);
5038 for (i = 0; i < len; i++)
5039 {
5040 Lisp_Object elt = AREF (object, XFASTINT (from) + i);
5041 CHECK_CHARACTER (elt);
5042 }
5043 chars = &(AREF (object, XFASTINT (from)));
5044 }
5045
4922 vec = Fmake_vector (make_number (len), Qnil); 5046 vec = Fmake_vector (make_number (len), Qnil);
4923 for (i = 0; i < len; i++) 5047 for (i = 0; i < len; i++)
4924 { 5048 {
4925 Lisp_Object ch = Faref (string, make_number (i)); 5049 Lisp_Object g;
4926 Lisp_Object val; 5050 int c = XFASTINT (chars[i]);
4927 int c = XINT (ch);
4928 unsigned code; 5051 unsigned code;
4929 EMACS_INT cod; 5052 EMACS_INT cod;
4930 struct font_metrics metrics; 5053 struct font_metrics metrics;
@@ -4932,20 +5055,21 @@ Each element is a vector [GLYPH-CODE LBEARING RBEARING WIDTH ASCENT DESCENT]. *
4932 cod = code = font->driver->encode_char (font, c); 5055 cod = code = font->driver->encode_char (font, c);
4933 if (code == FONT_INVALID_CODE) 5056 if (code == FONT_INVALID_CODE)
4934 continue; 5057 continue;
4935 val = Fmake_vector (make_number (6), Qnil); 5058 g = Fmake_vector (make_number (LGLYPH_SIZE), Qnil);
4936 if (cod <= MOST_POSITIVE_FIXNUM) 5059 LGLYPH_SET_FROM (g, i);
4937 ASET (val, 0, make_number (code)); 5060 LGLYPH_SET_TO (g, i);
4938 else 5061 LGLYPH_SET_CHAR (g, c);
4939 ASET (val, 0, Fcons (make_number (code >> 16), 5062 LGLYPH_SET_CODE (g, code);
4940 make_number (code & 0xFFFF)));
4941 font->driver->text_extents (font, &code, 1, &metrics); 5063 font->driver->text_extents (font, &code, 1, &metrics);
4942 ASET (val, 1, make_number (metrics.lbearing)); 5064 LGLYPH_SET_WIDTH (g, metrics.width);
4943 ASET (val, 2, make_number (metrics.rbearing)); 5065 LGLYPH_SET_LBEARING (g, metrics.lbearing);
4944 ASET (val, 3, make_number (metrics.width)); 5066 LGLYPH_SET_RBEARING (g, metrics.rbearing);
4945 ASET (val, 4, make_number (metrics.ascent)); 5067 LGLYPH_SET_ASCENT (g, metrics.ascent);
4946 ASET (val, 5, make_number (metrics.descent)); 5068 LGLYPH_SET_DESCENT (g, metrics.descent);
4947 ASET (vec, i, val); 5069 ASET (vec, i, g);
4948 } 5070 }
5071 if (! VECTORP (object))
5072 SAFE_FREE ();
4949 return vec; 5073 return vec;
4950} 5074}
4951 5075
@@ -5347,7 +5471,7 @@ syms_of_font ()
5347 defsubr (&Sopen_font); 5471 defsubr (&Sopen_font);
5348 defsubr (&Sclose_font); 5472 defsubr (&Sclose_font);
5349 defsubr (&Squery_font); 5473 defsubr (&Squery_font);
5350 defsubr (&Sget_font_glyphs); 5474 defsubr (&Sfont_get_glyphs);
5351 defsubr (&Sfont_match_p); 5475 defsubr (&Sfont_match_p);
5352 defsubr (&Sfont_at); 5476 defsubr (&Sfont_at);
5353#if 0 5477#if 0
diff --git a/src/font.h b/src/font.h
index 952ea269495..0a4839e7791 100644
--- a/src/font.h
+++ b/src/font.h
@@ -159,14 +159,19 @@ enum font_property_index
159 /* This value is the length of font-spec vector. */ 159 /* This value is the length of font-spec vector. */
160 FONT_SPEC_MAX, 160 FONT_SPEC_MAX,
161 161
162 /* The followings are used only for a font-entity. */ 162 /* The followings are used only for a font-entity and a font-object. */
163 163
164 /* List of font-objects opened from the font-entity. */ 164 /* List of font-objects opened from the font-entity. */
165 FONT_OBJLIST_INDEX = FONT_SPEC_MAX, 165 FONT_OBJLIST_INDEX = FONT_SPEC_MAX,
166 166
167 /* Font-entity from which the font-object is opened. */
168 FONT_ENTITY_INDEX = FONT_SPEC_MAX,
169
167 /* This value is the length of font-entity vector. */ 170 /* This value is the length of font-entity vector. */
168 FONT_ENTITY_MAX, 171 FONT_ENTITY_MAX,
169 172
173 /* The followings are used only for a font-object. */
174
170 /* XLFD name of the font (string). */ 175 /* XLFD name of the font (string). */
171 FONT_NAME_INDEX = FONT_ENTITY_MAX, 176 FONT_NAME_INDEX = FONT_ENTITY_MAX,
172 177