Mercurial > hg > xemacs-beta
comparison lisp/w3/css.el @ 44:8d2a9b52c682 r19-15prefinal
Import from CVS: tag r19-15prefinal
author | cvs |
---|---|
date | Mon, 13 Aug 2007 08:55:10 +0200 |
parents | c53a95d3c46d |
children | 7d55a9ba150c |
comparison
equal
deleted
inserted
replaced
43:23cafc5d2038 | 44:8d2a9b52c682 |
---|---|
1 ;;; css.el -- Cascading Style Sheet parser | 1 ;;; css.el -- Cascading Style Sheet parser |
2 ;; Author: wmperry | 2 ;; Author: wmperry |
3 ;; Created: 1997/03/14 22:02:39 | 3 ;; Created: 1997/03/25 03:35:09 |
4 ;; Version: 1.30 | 4 ;; Version: 1.33 |
5 ;; Keywords: | 5 ;; Keywords: |
6 | 6 |
7 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 7 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
8 ;;; Copyright (c) 1996 by William M. Perry (wmperry@cs.indiana.edu) | 8 ;;; Copyright (c) 1996 by William M. Perry (wmperry@cs.indiana.edu) |
9 ;;; Copyright (c) 1996, 1997 Free Software Foundation, Inc. | 9 ;;; Copyright (c) 1996, 1997 Free Software Foundation, Inc. |
42 ;; Font properties, Section 5.2 | 42 ;; Font properties, Section 5.2 |
43 [font-family t string-list] | 43 [font-family t string-list] |
44 [font-style t symbol] | 44 [font-style t symbol] |
45 [font-variant t symbol] | 45 [font-variant t symbol] |
46 [font-weight t weight] | 46 [font-weight t weight] |
47 [font-size t length] | 47 [font-size t height] |
48 [font nil font] | 48 [font nil font] |
49 | 49 |
50 ;; Color and background properties, Section 5.3 | 50 ;; Color and background properties, Section 5.3 |
51 [color t color] | 51 [color t color] |
52 [background nil color-shorthand] | 52 [background nil color-shorthand] |
315 (setq classes (cons (substring rest 0 (match-end 0)) classes))) | 315 (setq classes (cons (substring rest 0 (match-end 0)) classes))) |
316 (setq rest (substring rest (match-end 0) nil))) | 316 (setq rest (substring rest (match-end 0) nil))) |
317 (setq classes (sort classes 'string-lessp)) | 317 (setq classes (sort classes 'string-lessp)) |
318 (cons tag classes))) | 318 (cons tag classes))) |
319 ((string-match "^#" tag) ; id selector | 319 ((string-match "^#" tag) ; id selector |
320 (cons '*document tag)) | 320 (cons '*document (list tag))) |
321 (t | 321 (t |
322 (cons (intern (downcase tag)) t) | 322 (cons (intern (downcase tag)) t) |
323 ) | 323 ) |
324 ) | 324 ) |
325 ) | 325 ) |
359 (if weight | 359 (if weight |
360 (push (cons 'font-weight (css-expand-value 'weight weight)) retval)) | 360 (push (cons 'font-weight (css-expand-value 'weight weight)) retval)) |
361 (if size | 361 (if size |
362 (push (cons 'font-size (css-expand-length size)) retval)) | 362 (push (cons 'font-size (css-expand-length size)) retval)) |
363 (if height | 363 (if height |
364 (push (cons 'line-height (css-expand-length height)) retval)) | 364 (push (cons 'line-height (css-expand-length height t)) retval)) |
365 (if family | 365 (if family |
366 (push (cons 'font-family (css-expand-value 'string-list family)) retval)) | 366 (push (cons 'font-family (css-expand-value 'string-list family)) retval)) |
367 retval)) | 367 retval)) |
368 | 368 |
369 (defun css-expand-length (spec) | 369 (if (not (fboundp 'frame-char-height)) |
370 (defun frame-char-height (&optional frame) | |
371 "Height in pixels of a line in the font in frame FRAME. | |
372 If FRAME is omitted, the selected frame is used. | |
373 For a terminal frame, the value is always 1." | |
374 (font-height (face-font 'default frame)))) | |
375 | |
376 (defun css-expand-length (spec &optional height) | |
370 (cond | 377 (cond |
371 ((not (stringp spec)) spec) | 378 ((not (stringp spec)) spec) |
372 ((string-equal spec "auto") nil) | 379 ((string-equal spec "auto") nil) |
373 ((string-match "\\([+-]?\\([0-9]+\\|[0-9]*\\.[0-9]+\\)\\)%" spec) ; A percentage | 380 ((string-match "\\([+-]?\\([0-9]+\\|[0-9]*\\.[0-9]+\\)\\)%" spec) ; A percentage |
374 nil) | 381 (setq spec (/ (string-to-int (match-string 1 spec)) 100.0)) |
382 (if height | |
383 (round (* (frame-char-height) spec)) | |
384 (max 0 (round (* (frame-width) spec))))) | |
375 ((string-match "\\([+-]?\\([0-9]+\\|[0-9]*\\.[0-9]+\\)\\)e[mx]" spec) ; Character based | 385 ((string-match "\\([+-]?\\([0-9]+\\|[0-9]*\\.[0-9]+\\)\\)e[mx]" spec) ; Character based |
376 (max 0 (round (string-to-number (match-string 1 spec))))) | 386 (max 0 (round (string-to-number (match-string 1 spec))))) |
377 (t | 387 (t |
378 (truncate (font-spatial-to-canonical spec))) | 388 (truncate (font-spatial-to-canonical spec))) |
379 ) | 389 ) |
461 (defun css-expand-value (type value) | 471 (defun css-expand-value (type value) |
462 (if value | 472 (if value |
463 (case type | 473 (case type |
464 (length ; CSS, Section 6.1 | 474 (length ; CSS, Section 6.1 |
465 (setq value (css-expand-length value))) | 475 (setq value (css-expand-length value))) |
476 (height | |
477 (setq value (css-expand-length value t))) | |
466 (percentage ; CSS, Section 6.2 | 478 (percentage ; CSS, Section 6.2 |
467 (setq value (/ (string-to-number value) | 479 (setq value (/ (string-to-number value) |
468 (if (fboundp 'float) (float 100) 1)))) | 480 (if (fboundp 'float) (float 100) 1)))) |
469 (color ; CSS, Section 6.3 | 481 (color ; CSS, Section 6.3 |
470 (setq value (css-expand-color value))) | 482 (setq value (css-expand-color value))) |
575 (setq value (/ (string-to-number value) 100) | 587 (setq value (/ (string-to-number value) 100) |
576 value (or (nth value css-weights) :bold))) | 588 value (or (nth value css-weights) :bold))) |
577 ((string-match (css-symbol-list-as-regexp normal bold bolder lighter) | 589 ((string-match (css-symbol-list-as-regexp normal bold bolder lighter) |
578 value) | 590 value) |
579 (setq value (intern (downcase (concat ":" value))))) | 591 (setq value (intern (downcase (concat ":" value))))) |
580 (t setq value (intern ":bold")))) | 592 (t (setq value (intern ":bold"))))) |
581 | |
582 ;; The rest of these deal with how we handle things internally | 593 ;; The rest of these deal with how we handle things internally |
583 ((symbol integer) ; Read it in | 594 ((symbol integer) ; Read it in |
584 (setq value (read (downcase value)))) | 595 (setq value (read (downcase value)))) |
585 (symbol-list ; A space/comma delimited symlist | 596 (symbol-list ; A space/comma delimited symlist |
586 (setq value (downcase value) | 597 (setq value (downcase value) |