aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiles Bader2001-10-28 10:09:29 +0000
committerMiles Bader2001-10-28 10:09:29 +0000
commitcdfaafa9cc7fd972ba8f80aa9e260714fb677923 (patch)
treebe734b012d532dcfb6a6ce78fd7eb83d02b87b6f
parentc2d535587aca9f08bf7e7eeaa9b3141d4749e26d (diff)
downloademacs-cdfaafa9cc7fd972ba8f80aa9e260714fb677923.tar.gz
emacs-cdfaafa9cc7fd972ba8f80aa9e260714fb677923.zip
(merge_face_heights): Handle TO being relative as well.
Remove #ifdef'd-out code. (Fface_attribute_relative_p, Fmerge_face_attribute): New functions. (syms_of_xfaces): Initialize them.
-rw-r--r--src/xfaces.c93
1 files changed, 56 insertions, 37 deletions
diff --git a/src/xfaces.c b/src/xfaces.c
index a21e11d9cf2..bcb97aebb01 100644
--- a/src/xfaces.c
+++ b/src/xfaces.c
@@ -3217,66 +3217,53 @@ set_lface_from_font_name (f, lface, fontname, force_p, may_fail_p)
3217 3217
3218/* Merges the face height FROM with the face height TO, and returns the 3218/* Merges the face height FROM with the face height TO, and returns the
3219 merged height. If FROM is an invalid height, then INVALID is 3219 merged height. If FROM is an invalid height, then INVALID is
3220 returned instead. FROM may be a either an absolute face height or a 3220 returned instead. FROM and TO may be either absolute face heights or
3221 `relative' height, and TO must be an absolute height. The returned 3221 `relative' heights; the returned value is always an absolute height
3222 value is always an absolute height. GCPRO is a lisp value that will 3222 unless both FROM and TO are relative. GCPRO is a lisp value that
3223 be protected from garbage-collection if this function makes a call 3223 will be protected from garbage-collection if this function makes a
3224 into lisp. */ 3224 call into lisp. */
3225 3225
3226Lisp_Object 3226Lisp_Object
3227merge_face_heights (from, to, invalid, gcpro) 3227merge_face_heights (from, to, invalid, gcpro)
3228 Lisp_Object from, to, invalid, gcpro; 3228 Lisp_Object from, to, invalid, gcpro;
3229{ 3229{
3230 int result = 0; 3230 Lisp_Object result = invalid;
3231 3231
3232 if (INTEGERP (from)) 3232 if (INTEGERP (from))
3233 result = XINT (from); 3233 /* FROM is absolute, just use it as is. */
3234 else if (NUMBERP (from)) 3234 result = from;
3235 result = XFLOATINT (from) * XINT (to); 3235 else if (FLOATP (from))
3236#if 0 /* Probably not so useful. */ 3236 /* FROM is a scale, use it to adjust TO. */
3237 else if (CONSP (from) && CONSP (XCDR (from))) 3237 {
3238 { 3238 if (INTEGERP (to))
3239 if (EQ (XCAR(from), Qplus) || EQ (XCAR(from), Qminus)) 3239 /* relative X absolute => absolute */
3240 { 3240 result = make_number (XFLOAT_DATA (from) * XINT (to));
3241 if (INTEGERP (XCAR (XCDR (from)))) 3241 else if (FLOATP (to))
3242 { 3242 /* relative X relative => relative */
3243 int inc = XINT (XCAR (XCDR (from))); 3243 result = make_float (XFLOAT_DATA (from) * XFLOAT_DATA (to));
3244 if (EQ (XCAR (from), Qminus))
3245 inc = -inc;
3246
3247 result = XFASTINT (to);
3248 if (result + inc > 0)
3249 /* Note that `underflows' don't mean FROM is invalid, so
3250 we just pin the result at TO if it would otherwise be
3251 negative or 0. */
3252 result += inc;
3253 }
3254 }
3255 } 3244 }
3256#endif
3257 else if (FUNCTIONP (from)) 3245 else if (FUNCTIONP (from))
3246 /* FROM is a function, which use to adjust TO. */
3258 { 3247 {
3259 /* Call function with current height as argument. 3248 /* Call function with current height as argument.
3260 From is the new height. */ 3249 From is the new height. */
3261 Lisp_Object args[2], height; 3250 Lisp_Object args[2];
3262 struct gcpro gcpro1; 3251 struct gcpro gcpro1;
3263 3252
3264 GCPRO1 (gcpro); 3253 GCPRO1 (gcpro);
3265 3254
3266 args[0] = from; 3255 args[0] = from;
3267 args[1] = to; 3256 args[1] = to;
3268 height = safe_call (2, args); 3257 result = safe_call (2, args);
3269 3258
3270 UNGCPRO; 3259 UNGCPRO;
3271 3260
3272 if (NUMBERP (height)) 3261 /* Ensure that if TO was absolute, so is the result. */
3273 result = XFLOATINT (height); 3262 if (INTEGERP (to) && !INTEGERP (result))
3263 result = invalid;
3274 } 3264 }
3275 3265
3276 if (result > 0) 3266 return result;
3277 return make_number (result);
3278 else
3279 return invalid;
3280} 3267}
3281 3268
3282 3269
@@ -4495,6 +4482,36 @@ x_update_menu_appearance (f)
4495#endif /* HAVE_X_WINDOWS && USE_X_TOOLKIT */ 4482#endif /* HAVE_X_WINDOWS && USE_X_TOOLKIT */
4496 4483
4497 4484
4485DEFUN ("face-attribute-relative-p", Fface_attribute_relative_p,
4486 Sface_attribute_relative_p,
4487 2, 2, 0,
4488 doc: /* Return non-nil if face ATTRIBUTE VALUE is relative. */)
4489 (attribute, value)
4490{
4491 if (EQ (value, Qunspecified))
4492 return Qt;
4493 else if (EQ (attribute, QCheight))
4494 return INTEGERP (value) ? Qnil : Qt;
4495 else
4496 return Qnil;
4497}
4498
4499DEFUN ("merge-face-attribute", Fmerge_face_attribute, Smerge_face_attribute,
4500 3, 3, 0,
4501 doc: /* Return face ATTRIBUTE VALUE1 merged with VALUE2.
4502If VALUE1 or VALUE2 are absolute (see `face-attribute-relative-p'), then
4503the result will be absolute, otherwise it will be relative. */)
4504 (attribute, value1, value2)
4505 Lisp_Object attribute, value1, value2;
4506{
4507 if (EQ (value1, Qunspecified))
4508 return value2;
4509 else if (EQ (attribute, QCheight))
4510 return merge_face_heights (value1, value2, value1, Qnil);
4511 else
4512 return value1;
4513}
4514
4498 4515
4499DEFUN ("internal-get-lisp-face-attribute", Finternal_get_lisp_face_attribute, 4516DEFUN ("internal-get-lisp-face-attribute", Finternal_get_lisp_face_attribute,
4500 Sinternal_get_lisp_face_attribute, 4517 Sinternal_get_lisp_face_attribute,
@@ -7205,6 +7222,8 @@ syms_of_xfaces ()
7205#endif 7222#endif
7206 defsubr (&Scolor_gray_p); 7223 defsubr (&Scolor_gray_p);
7207 defsubr (&Scolor_supported_p); 7224 defsubr (&Scolor_supported_p);
7225 defsubr (&Sface_attribute_relative_p);
7226 defsubr (&Smerge_face_attribute);
7208 defsubr (&Sinternal_get_lisp_face_attribute); 7227 defsubr (&Sinternal_get_lisp_face_attribute);
7209 defsubr (&Sinternal_lisp_face_attribute_values); 7228 defsubr (&Sinternal_lisp_face_attribute_values);
7210 defsubr (&Sinternal_lisp_face_equal_p); 7229 defsubr (&Sinternal_lisp_face_equal_p);