14
|
1 ;;; w3-display.el --- display engine v99999
|
|
2 ;; Author: wmperry
|
86
|
3 ;; Created: 1997/01/26 00:16:07
|
|
4 ;; Version: 1.112
|
14
|
5 ;; Keywords: faces, help, hypermedia
|
|
6
|
|
7 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
8 ;;; Copyright (c) 1996 by William M. Perry (wmperry@cs.indiana.edu)
|
82
|
9 ;;; Copyright (c) 1996, 1997 Free Software Foundation, Inc.
|
14
|
10 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
11 ;;;
|
|
12 ;;; This file is part of GNU Emacs.
|
|
13 ;;;
|
|
14 ;;; GNU Emacs is free software; you can redistribute it and/or modify
|
|
15 ;;; it under the terms of the GNU General Public License as published by
|
|
16 ;;; the Free Software Foundation; either version 2, or (at your option)
|
|
17 ;;; any later version.
|
|
18 ;;;
|
|
19 ;;; GNU Emacs is distributed in the hope that it will be useful,
|
|
20 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
21 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
22 ;;; GNU General Public License for more details.
|
|
23 ;;;
|
|
24 ;;; You should have received a copy of the GNU General Public License
|
|
25 ;;; along with GNU Emacs; see the file COPYING. If not, write to the
|
|
26 ;;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
27 ;;; Boston, MA 02111-1307, USA.
|
|
28 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
29 (require 'cl)
|
|
30 (require 'css)
|
|
31 (require 'font)
|
|
32 (require 'w3-widget)
|
|
33 (require 'w3-imap)
|
|
34
|
|
35 (defmacro w3-d-s-var-def (var)
|
|
36 (` (make-variable-buffer-local (defvar (, var) nil))))
|
|
37
|
|
38 (w3-d-s-var-def w3-display-open-element-stack)
|
|
39 (w3-d-s-var-def w3-display-alignment-stack)
|
|
40 (w3-d-s-var-def w3-display-list-stack)
|
82
|
41 (w3-d-s-var-def w3-display-form-id)
|
14
|
42 (w3-d-s-var-def w3-display-whitespace-stack)
|
|
43 (w3-d-s-var-def w3-display-font-family-stack)
|
|
44 (w3-d-s-var-def w3-display-font-weight-stack)
|
|
45 (w3-d-s-var-def w3-display-font-variant-stack)
|
|
46 (w3-d-s-var-def w3-display-font-size-stack)
|
|
47 (w3-d-s-var-def w3-face-color)
|
82
|
48 (w3-d-s-var-def w3-face-background-color)
|
14
|
49 (w3-d-s-var-def w3-active-faces)
|
|
50 (w3-d-s-var-def w3-active-voices)
|
|
51 (w3-d-s-var-def w3-current-form-number)
|
|
52 (w3-d-s-var-def w3-face-font-family)
|
|
53 (w3-d-s-var-def w3-face-font-weight)
|
|
54 (w3-d-s-var-def w3-face-font-variant)
|
|
55 (w3-d-s-var-def w3-face-font-size)
|
|
56 (w3-d-s-var-def w3-face-font-family)
|
|
57 (w3-d-s-var-def w3-face-font-size)
|
|
58 (w3-d-s-var-def w3-face-font-spec)
|
|
59 (w3-d-s-var-def w3-face-text-decoration)
|
|
60 (w3-d-s-var-def w3-face-face)
|
|
61 (w3-d-s-var-def w3-face-descr)
|
|
62 (w3-d-s-var-def w3-face-pixmap)
|
|
63 (w3-d-s-var-def w3-display-css-properties)
|
|
64
|
|
65 (eval-when-compile
|
|
66 (defmacro w3-get-attribute (attr)
|
|
67 (` (cdr-safe (assq (, attr) args))))
|
|
68
|
|
69 (defmacro w3-get-face-info (info)
|
|
70 (let ((var (intern (format "w3-face-%s" info))))
|
|
71 (` (push (w3-get-style-info (quote (, info)) node (car (, var)))
|
|
72 (, var)))))
|
|
73
|
|
74 (defmacro w3-pop-face-info (info)
|
|
75 (let ((var (intern (format "w3-face-%s" info))))
|
|
76 (` (pop (, var)))))
|
|
77
|
|
78 (defmacro w3-get-all-face-info ()
|
|
79 (`
|
|
80 (progn
|
|
81 (w3-get-face-info font-family)
|
|
82 (w3-get-face-info font-weight)
|
|
83 (w3-get-face-info font-variant)
|
|
84 (w3-get-face-info font-size)
|
|
85 (w3-get-face-info text-decoration)
|
|
86 ;;(w3-get-face-info pixmap)
|
|
87 (w3-get-face-info color)
|
82
|
88 (w3-get-face-info background-color)
|
14
|
89 (setq w3-face-font-spec (make-font
|
|
90 :weight (car w3-face-font-weight)
|
|
91 :family (car w3-face-font-family)
|
|
92 :size (car w3-face-font-size))))))
|
|
93
|
|
94 (defmacro w3-pop-all-face-info ()
|
|
95 (`
|
|
96 (progn
|
|
97 (w3-pop-face-info font-family)
|
|
98 (w3-pop-face-info font-weight)
|
|
99 (w3-pop-face-info font-variant)
|
|
100 (w3-pop-face-info font-size)
|
|
101 (w3-pop-face-info text-decoration)
|
|
102 ;;(w3-pop-face-info pixmap)
|
|
103 (w3-pop-face-info color)
|
82
|
104 (w3-pop-face-info background-color))))
|
14
|
105
|
|
106 )
|
|
107
|
82
|
108 (defvar w3-display-same-buffer nil)
|
14
|
109 (defvar w3-face-cache nil "Cache for w3-face-for-element")
|
|
110 (defvar w3-face-index 0)
|
|
111 (defvar w3-image-widgets-waiting nil)
|
|
112
|
|
113 (make-variable-buffer-local 'w3-last-fill-pos)
|
|
114
|
|
115 (defconst w3-fill-prefixes-vector
|
|
116 (let ((len 0)
|
|
117 (prefix-vector (make-vector 80 nil)))
|
|
118 (while (< len 80)
|
|
119 (aset prefix-vector len (make-string len ? ))
|
|
120 (setq len (1+ len)))
|
|
121 prefix-vector))
|
|
122
|
|
123 (defconst w3-line-breaks-vector
|
|
124 (let ((len 0)
|
|
125 (breaks-vector (make-vector 10 nil)))
|
|
126 (while (< len 10)
|
|
127 (aset breaks-vector len (make-string len ?\n))
|
|
128 (setq len (1+ len)))
|
|
129 breaks-vector))
|
|
130
|
|
131 (defun w3-pause ()
|
|
132 (cond
|
|
133 (w3-running-FSF19 (sit-for 0))
|
|
134 (w3-running-xemacs
|
|
135 (sit-for 0))
|
|
136 ;; (if (and (not (sit-for 0)) (input-pending-p))
|
|
137 ;; (condition-case ()
|
|
138 ;; (dispatch-event (next-command-event))
|
|
139 ;; (error nil)))
|
|
140 (t (sit-for 0))))
|
|
141
|
|
142 (defmacro w3-get-pad-string (len)
|
|
143 (` (cond
|
|
144 ((< (, len) 0)
|
|
145 "")
|
|
146 ((< (, len) 80)
|
|
147 (aref w3-fill-prefixes-vector (, len)))
|
|
148 (t (make-string (, len) ? )))))
|
|
149
|
|
150 (defsubst w3-set-fill-prefix-length (len)
|
|
151 (setq fill-prefix (if (< len (- (or w3-strict-width (window-width)) 4))
|
|
152 (w3-get-pad-string len)
|
|
153 (url-warn
|
|
154 'html
|
|
155 "Runaway indentation! Too deep for window width!")
|
|
156 fill-prefix)))
|
|
157
|
|
158 (defsubst w3-get-style-info (info node &optional default)
|
|
159 (or (cdr-safe (assq info w3-display-css-properties)) default))
|
|
160
|
|
161 (defun w3-decode-area-coords (str)
|
|
162 (let (retval)
|
|
163 (while (string-match "\\([ \t0-9]+\\),\\([ \t0-9]+\\)" str)
|
|
164 (setq retval (cons (vector (string-to-int (match-string 1 str))
|
|
165 (string-to-int (match-string 2 str))) retval)
|
|
166 str (substring str (match-end 0) nil)))
|
|
167 (if (string-match "\\([0-9]+\\)" str)
|
|
168 (setq retval (cons (vector (+ (aref (car retval) 0)
|
|
169 (string-to-int (match-string 1 str)))
|
|
170 (aref (car retval) 1)) retval)))
|
|
171 (nreverse retval)))
|
|
172
|
|
173 (defun w3-normalize-color (color)
|
|
174 (cond
|
|
175 ((valid-color-name-p color)
|
|
176 color)
|
|
177 ((valid-color-name-p (concat "#" color))
|
|
178 (concat "#" color))
|
|
179 ((string-match "[ \t\r\n]" color)
|
|
180 (w3-normalize-color
|
|
181 (mapconcat (function (lambda (x) (if (memq x '(?\t ?\r ?\n ? )) ""
|
|
182 (char-to-string x)))) color "")))
|
|
183 ((valid-color-name-p (font-normalize-color color))
|
|
184 (font-normalize-color color))
|
|
185 (t
|
|
186 (w3-warn 'html (format "Bad color specification: %s" color))
|
|
187 nil)))
|
|
188
|
|
189 (defsubst w3-voice-for-element (node)
|
|
190 (if (featurep 'emacspeak)
|
|
191 (let (family gain left right pitch pitch-range stress richness voice)
|
|
192 (setq family (w3-get-style-info 'voice-family node)
|
|
193 gain (w3-get-style-info 'gain node)
|
|
194 left (w3-get-style-info 'left-volume node)
|
|
195 right (w3-get-style-info 'right-volume node)
|
|
196 pitch (w3-get-style-info 'pitch node)
|
|
197 pitch-range (w3-get-style-info 'pitch-range node)
|
|
198 stress (w3-get-style-info 'stress node)
|
|
199 richness (w3-get-style-info 'richness node))
|
|
200 (if (or family gain left right pitch pitch-range stress richness)
|
|
201 (setq voice (dtk-personality-from-speech-style
|
|
202 (make-dtk-speech-style :family (or family 'paul)
|
|
203 :gain (or gain 5)
|
|
204 :left-volume (or left 5)
|
|
205 :right-volume (or right 5)
|
|
206 :average-pitch (or pitch 5)
|
|
207 :pitch-range (or pitch-range 5)
|
|
208 :stress (or stress 5)
|
|
209 :richness (or richness 5))))
|
|
210 (setq voice nil))
|
|
211 (or voice (car w3-active-voices)))))
|
|
212
|
|
213 (defun w3-make-face-emacs19 (name &optional doc-string temporary)
|
|
214 "Defines and returns a new FACE described by DOC-STRING.
|
|
215 If the face already exists, it is unmodified.
|
|
216 If TEMPORARY is non-nil, this face will cease to exist if not in use."
|
|
217 (make-face name))
|
|
218
|
|
219 (cond
|
|
220 ((not (fboundp 'make-face))
|
|
221 (fset 'w3-make-face 'ignore))
|
|
222 (w3-running-xemacs
|
|
223 (fset 'w3-make-face 'make-face))
|
|
224 (t
|
|
225 (fset 'w3-make-face 'w3-make-face-emacs19)))
|
|
226
|
|
227 (defsubst w3-face-for-element (node)
|
|
228 (w3-get-all-face-info)
|
|
229 (if (car w3-face-text-decoration)
|
|
230 (set-font-style-by-keywords w3-face-font-spec
|
|
231 (car w3-face-text-decoration)))
|
|
232 (if w3-face-font-variant
|
|
233 (set-font-style-by-keywords w3-face-font-spec
|
|
234 (car w3-face-font-variant)))
|
|
235 (setq w3-face-descr (list w3-face-font-spec
|
|
236 (car w3-face-color)
|
82
|
237 (car w3-face-background-color))
|
14
|
238 w3-face-face (cdr-safe (assoc w3-face-descr w3-face-cache)))
|
|
239 (if (or w3-face-face (not (or (car w3-face-color)
|
82
|
240 (car w3-face-background-color)
|
14
|
241 w3-face-font-spec)))
|
|
242 nil ; Do nothing, we got it already
|
|
243 (setq w3-face-face
|
|
244 (w3-make-face (intern (format "w3-style-face-%05d" w3-face-index))
|
|
245 "An Emacs-W3 face... don't edit by hand." t)
|
|
246 w3-face-index (1+ w3-face-index))
|
|
247 (if w3-face-font-spec
|
|
248 (set-face-font w3-face-face w3-face-font-spec))
|
|
249 (if (car w3-face-color)
|
|
250 (set-face-foreground w3-face-face (car w3-face-color)))
|
82
|
251 (if (car w3-face-background-color)
|
|
252 (set-face-background w3-face-face (car w3-face-background-color)))
|
14
|
253 ;;(set-face-background-pixmap w3-face-face w3-face-pixmap)
|
|
254 (setq w3-face-cache (cons
|
|
255 (cons w3-face-descr w3-face-face)
|
|
256 w3-face-cache)))
|
|
257 w3-face-face)
|
|
258
|
|
259 (defun w3-normalize-spaces (string)
|
|
260 ;; nuke spaces in the middle
|
|
261 (while (string-match "[ \t\r\n][ \r\t\n]+" string)
|
|
262 (setq string (concat (substring string 0 (1+ (match-beginning 0)))
|
|
263 (substring string (match-end 0)))))
|
|
264
|
|
265 ;; nuke spaces at the beginning
|
|
266 (if (string-match "^[ \t\r\n]+" string)
|
|
267 (setq string (substring string (match-end 0))))
|
|
268
|
|
269 ;; nuke spaces at the end
|
|
270 (if (string-match "[ \t\n\r]+$" string)
|
|
271 (setq string (substring string 0 (match-beginning 0))))
|
|
272 string)
|
|
273
|
|
274 (defvar w3-bullets
|
|
275 '((disc . ?*)
|
|
276 (circle . ?o)
|
|
277 (square . ?#)
|
82
|
278 (none . ? )
|
14
|
279 )
|
|
280 "*An assoc list of unordered list types mapping to characters to use
|
|
281 as the bullet character.")
|
|
282
|
|
283
|
|
284 (defsubst w3-display-line-break (n)
|
|
285 (if (or
|
|
286 (memq (car w3-display-whitespace-stack) '(pre nowrap)) ; Been told
|
|
287 (= w3-last-fill-pos (point))
|
|
288 (> w3-last-fill-pos (point-max)))
|
|
289 (if (/= (preceding-char) ?\n) (setq n (1+ n))) ; at least put one line in
|
|
290 (let ((fill-column (max (1+ (length fill-prefix)) fill-column))
|
|
291 width)
|
|
292 (case (car w3-display-alignment-stack)
|
|
293 (center
|
|
294 (fill-region-as-paragraph w3-last-fill-pos (point))
|
|
295 (center-region w3-last-fill-pos (point-max)))
|
|
296 ((justify full)
|
|
297 (fill-region-as-paragraph w3-last-fill-pos (point) t))
|
|
298 (right
|
|
299 (fill-region-as-paragraph w3-last-fill-pos (point))
|
|
300 (goto-char w3-last-fill-pos)
|
|
301 (catch 'fill-exit
|
|
302 (while (re-search-forward ".$" nil t)
|
|
303 (if (>= (setq width (current-column)) fill-column)
|
|
304 nil ; already justified, or error
|
|
305 (beginning-of-line)
|
|
306 (insert-char ? (- fill-column width))
|
|
307 (end-of-line)
|
|
308 (if (eobp)
|
|
309 (throw 'fill-exit t))
|
|
310 (condition-case ()
|
|
311 (forward-char 1)
|
|
312 (error (throw 'fill-exit t))))))
|
|
313 )
|
|
314 (otherwise ; Default is left justification
|
|
315 (fill-region-as-paragraph w3-last-fill-pos (point)))
|
|
316 ))
|
|
317 (setq n (1- n)))
|
|
318 (setq w3-last-fill-pos (point-max))
|
|
319 (insert (cond
|
|
320 ((<= n 0) "")
|
|
321 ((< n 10)
|
|
322 (aref w3-line-breaks-vector n))
|
|
323 (t
|
|
324 (make-string n ?\n)))))
|
|
325
|
|
326 (defsubst w3-munge-line-breaks-p ()
|
|
327 (eq (car w3-display-whitespace-stack) 'pre))
|
|
328
|
|
329 (defvar w3-display-nil-face (w3-make-face nil "Stub face... don't ask." t))
|
|
330
|
|
331 (defvar w3-scratch-start-point nil)
|
|
332
|
|
333 (defsubst w3-handle-string-content (string)
|
|
334 (setq w3-scratch-start-point (point))
|
|
335 (insert string)
|
|
336 (if (w3-munge-line-breaks-p)
|
|
337 (progn
|
|
338 (goto-char w3-scratch-start-point)
|
|
339 (if (not (search-forward "\n" nil t))
|
|
340 (subst-char-in-region w3-scratch-start-point (point-max) ?\r ?\n)
|
|
341 (subst-char-in-region w3-scratch-start-point (point-max) ?\r ? )))
|
|
342 (goto-char w3-scratch-start-point)
|
|
343 (while (re-search-forward
|
|
344 " [ \t\n\r]+\\|[\t\n\r][ \t\n\r]*"
|
|
345 nil 'move)
|
|
346 (replace-match " "))
|
|
347 (goto-char w3-scratch-start-point)
|
|
348 (if (and (memq (preceding-char) '(? ?\t ?\r ?\n))
|
|
349 (looking-at "[ \t\r\n]"))
|
|
350 (delete-region (point)
|
|
351 (progn
|
|
352 (skip-chars-forward " \t\r\n")
|
|
353 (point)))))
|
|
354 (goto-char (point-max))
|
|
355 (add-text-properties w3-scratch-start-point
|
|
356 (point) (list 'face w3-active-faces 'duplicable t))
|
|
357 (if (car w3-active-voices)
|
|
358 (add-text-properties w3-scratch-start-point (point)
|
|
359 (list 'personality (car w3-active-voices))))
|
|
360 )
|
|
361
|
|
362 (defun w3-widget-echo (widget &rest ignore)
|
82
|
363 (let ((url (widget-get widget 'href))
|
14
|
364 (name (widget-get widget 'name))
|
|
365 (text (buffer-substring (widget-get widget :from)
|
|
366 (widget-get widget :to)))
|
|
367 (title (widget-get widget 'title))
|
82
|
368 (check w3-echo-link)
|
14
|
369 (msg nil))
|
82
|
370 (if url
|
|
371 (setq url (url-truncate-url-for-viewing url)))
|
14
|
372 (if name
|
|
373 (setq name (concat "anchor:" name)))
|
82
|
374 (if (not (listp check))
|
|
375 (setq check (cons check '(title url text name))))
|
|
376 (catch 'exit
|
|
377 (while check
|
|
378 (and (boundp (car check))
|
|
379 (stringp (symbol-value (car check)))
|
|
380 (throw 'exit (symbol-value (car check))))
|
|
381 (pop check)))))
|
14
|
382
|
|
383 (defun w3-follow-hyperlink (widget &rest ignore)
|
|
384 (let* ((target (widget-get widget 'target))
|
|
385 (href (widget-get widget 'href)))
|
|
386 (if target (setq target (intern (downcase target))))
|
|
387 (case target
|
|
388 ((_blank external)
|
|
389 (w3-fetch-other-frame href))
|
|
390 (_top
|
|
391 (delete-other-windows)
|
|
392 (w3-fetch href))
|
|
393 (otherwise
|
|
394 (w3-fetch href)))))
|
|
395
|
|
396 (defun w3-balloon-help-callback (object &optional event)
|
|
397 (let* ((widget (widget-at (extent-start-position object)))
|
|
398 (href (and widget (widget-get widget 'href))))
|
|
399 (if href
|
|
400 (url-truncate-url-for-viewing href)
|
|
401 nil)))
|
|
402
|
|
403
|
|
404 ;; Various macros
|
|
405 (eval-when-compile
|
|
406 (defmacro w3-expand-url (url)
|
|
407 (`
|
|
408 (url-expand-file-name (, url)
|
|
409 (cdr-safe
|
|
410 (assoc
|
|
411 (cdr-safe
|
|
412 (assq 'base args)) w3-base-alist)))))
|
|
413
|
|
414 (defmacro w3-handle-empty-tag ()
|
|
415 (`
|
|
416 (progn
|
|
417 (push (cons tag args) w3-display-open-element-stack)
|
|
418 (push content content-stack)
|
|
419 (setq content nil))))
|
|
420
|
|
421 (defmacro w3-handle-content (node)
|
|
422 (`
|
|
423 (progn
|
|
424 (push (cons tag args) w3-display-open-element-stack)
|
|
425 (push content content-stack)
|
|
426 (setq content (nth 2 node)))))
|
|
427
|
|
428 (defmacro w3-display-handle-list-type ()
|
|
429 (`
|
|
430 (case (car break-style)
|
|
431 (list-item
|
82
|
432 (let ((list-style (w3-get-style-info 'list-style-type node))
|
14
|
433 (list-num (if (car w3-display-list-stack)
|
|
434 (incf (car w3-display-list-stack))
|
|
435 1))
|
|
436 (margin (1- (car left-margin-stack)))
|
|
437 (indent (w3-get-style-info 'text-indent node 0)))
|
|
438 (if (> indent 0)
|
|
439 (setq margin (+ margin indent))
|
|
440 (setq margin (max 0 (- margin indent))))
|
|
441 (beginning-of-line)
|
|
442 (case list-style
|
|
443 ((disc circle square)
|
|
444 (insert (format (format "%%%dc" margin)
|
|
445 (or (cdr-safe (assq list-style w3-bullets))
|
|
446 ?o))))
|
|
447 ((decimal lower-roman upper-roman lower-alpha upper-alpha)
|
|
448 (let ((x (case list-style
|
|
449 (lower-roman
|
|
450 (w3-decimal-to-roman list-num))
|
|
451 (upper-roman
|
|
452 (upcase
|
|
453 (w3-decimal-to-roman list-num)))
|
|
454 (lower-alpha
|
|
455 (w3-decimal-to-alpha list-num))
|
|
456 (upper-alpha
|
|
457 (upcase
|
|
458 (w3-decimal-to-alpha list-num)))
|
|
459 (otherwise
|
|
460 (int-to-string list-num)))))
|
|
461 (insert (format (format "%%%ds." margin) x))
|
|
462 )
|
|
463 )
|
|
464 (otherwise
|
|
465 (insert (w3-get-pad-string margin)))
|
|
466 )
|
|
467 )
|
|
468 )
|
|
469 (otherwise
|
|
470 (insert (w3-get-pad-string (+ (car left-margin-stack)
|
|
471 (w3-get-style-info 'text-indent node 0)))))
|
|
472 )
|
|
473 )
|
|
474 )
|
|
475
|
|
476 (defmacro w3-display-set-margins ()
|
|
477 (`
|
|
478 (progn
|
|
479 (push (+ (w3-get-style-info 'margin-left node 0)
|
|
480 (car left-margin-stack)) left-margin-stack)
|
|
481 (push (-
|
|
482 (car right-margin-stack)
|
|
483 (w3-get-style-info 'margin-right node 0)) right-margin-stack)
|
|
484 (setq fill-column (car right-margin-stack))
|
|
485 (w3-set-fill-prefix-length (car left-margin-stack))
|
|
486 (w3-display-handle-list-type))))
|
|
487
|
|
488 (defmacro w3-display-restore-margins ()
|
|
489 (`
|
|
490 (progn
|
|
491 (pop right-margin-stack)
|
|
492 (pop left-margin-stack))))
|
|
493
|
|
494 (defmacro w3-display-handle-break ()
|
|
495 (`
|
|
496 (case (car break-style)
|
|
497 (block ; Full paragraph break
|
|
498 (if (eq (cadr break-style) 'list-item)
|
|
499 (setf (cadr break-style) 'line)
|
|
500 (w3-display-line-break 1))
|
|
501 (w3-display-set-margins)
|
|
502 (push
|
|
503 (w3-get-style-info 'white-space node
|
|
504 (car w3-display-whitespace-stack))
|
|
505 w3-display-whitespace-stack)
|
|
506 (push
|
|
507 (or (w3-get-attribute 'align)
|
|
508 (w3-get-style-info 'text-align node
|
|
509 (car w3-display-alignment-stack)))
|
|
510 w3-display-alignment-stack)
|
|
511 (and w3-do-incremental-display (w3-pause)))
|
|
512 ((line list-item) ; Single line break
|
|
513 (w3-display-line-break 0)
|
|
514 (w3-display-set-margins)
|
|
515 (push
|
|
516 (w3-get-style-info 'white-space node
|
|
517 (car w3-display-whitespace-stack))
|
|
518 w3-display-whitespace-stack)
|
|
519 (push
|
|
520 (w3-get-style-info 'text-align node
|
|
521 (or (w3-get-attribute 'align)
|
|
522 (car w3-display-alignment-stack)))
|
|
523 w3-display-alignment-stack))
|
|
524 (otherwise ; Assume 'inline' rendering as default
|
|
525 nil))
|
|
526 )
|
|
527 )
|
|
528
|
|
529 (defmacro w3-display-handle-end-break ()
|
|
530 (`
|
|
531 (case (pop break-style)
|
|
532 (block ; Full paragraph break
|
|
533 (w3-display-line-break 1)
|
|
534 (w3-display-restore-margins)
|
|
535 (pop w3-display-whitespace-stack)
|
|
536 (pop w3-display-alignment-stack)
|
|
537 (and w3-do-incremental-display (w3-pause)))
|
|
538 ((line list-item) ; Single line break
|
|
539 (w3-display-restore-margins)
|
|
540 (w3-display-line-break 0)
|
|
541 (pop w3-display-whitespace-stack)
|
|
542 (pop w3-display-alignment-stack))
|
|
543 (otherwise ; Assume 'inline' rendering as default
|
|
544 nil))
|
|
545 )
|
|
546 )
|
|
547 )
|
|
548
|
|
549 ;; <link> handling
|
|
550 (defun w3-parse-link (args)
|
|
551 (let* ((type (if (w3-get-attribute 'rel) 'rel 'rev))
|
|
552 (desc (w3-get-attribute type))
|
|
553 (dc-desc (and desc (downcase desc))) ; canonical case
|
|
554 (dest (w3-get-attribute 'href))
|
|
555 (plist (alist-to-plist args))
|
|
556 (node-1 (assq type w3-current-links))
|
|
557 (node-2 (and node-1 desc (or (assoc desc
|
|
558 (cdr node-1))
|
|
559 (assoc dc-desc
|
|
560 (cdr node-1)))))
|
|
561 )
|
|
562 ;; Canonicalize the case of link types we may look for
|
|
563 ;; specifically (toolbar etc.) since that's done with
|
|
564 ;; assoc. See `w3-mail-document-author' and
|
|
565 ;; `w3-link-toolbar', at least.
|
|
566 (if (member dc-desc w3-defined-link-types)
|
|
567 (setq desc dc-desc))
|
|
568 (if dest ; ignore if HREF missing
|
|
569 (cond
|
|
570 (node-2 ; Add to old value
|
|
571 (setcdr node-2 (cons plist (cdr node-2))))
|
|
572 (node-1 ; first rel/rev
|
|
573 (setcdr node-1 (cons (cons desc (list plist))
|
|
574 (cdr node-1))))
|
|
575 (t (setq w3-current-links
|
|
576 (cons (cons type (list (cons desc (list plist))))
|
|
577 w3-current-links)))))
|
|
578 (setq desc (and desc (intern dc-desc)))
|
|
579 (case desc
|
|
580 ((style stylesheet)
|
82
|
581 (w3-handle-style plist))
|
14
|
582 (otherwise
|
|
583 )
|
|
584 )
|
|
585 )
|
|
586 )
|
|
587
|
|
588
|
|
589 ;; Image handling
|
|
590 (defun w3-maybe-start-image-download (widget)
|
|
591 (let* ((src (widget-get widget 'src))
|
|
592 (cached-glyph (w3-image-cached-p src)))
|
|
593 (if (and cached-glyph (widget-glyphp cached-glyph))
|
|
594 (setq w3-image-widgets-waiting (cons widget w3-image-widgets-waiting))
|
|
595 (cond
|
|
596 ((or w3-delay-image-loads ; Delaying images
|
|
597 (not (fboundp 'valid-specifier-domain-p)) ; Can't do images
|
|
598 (eq (device-type) 'tty)) ; Why bother?
|
|
599 (w3-add-delayed-graphic widget))
|
|
600 ((not (w3-image-loadable-p src nil)) ; Hey, we can't load it!
|
|
601 (w3-warn 'images (format "Skipping image %s" (url-basepath src t)))
|
|
602 (w3-add-delayed-graphic widget))
|
|
603 (t ; Grab the images
|
|
604 (let (
|
|
605 (url-request-method "GET")
|
|
606 (old-asynch url-be-asynchronous)
|
|
607 (url-request-data nil)
|
|
608 (url-request-extra-headers nil)
|
|
609 (url-source t)
|
|
610 (url-mime-accept-string (substring
|
|
611 (mapconcat
|
|
612 (function
|
|
613 (lambda (x)
|
|
614 (if x
|
|
615 (concat (car x) ",")
|
|
616 "")))
|
|
617 w3-allowed-image-types "")
|
|
618 0 -1))
|
|
619 (url-working-buffer (generate-new-buffer-name " *W3GRAPH*")))
|
|
620 (setq-default url-be-asynchronous t)
|
|
621 (setq w3-graphics-list (cons (cons src (make-glyph))
|
|
622 w3-graphics-list))
|
|
623 (save-excursion
|
|
624 (set-buffer (get-buffer-create url-working-buffer))
|
|
625 (setq url-current-callback-data (list widget)
|
|
626 url-be-asynchronous t
|
|
627 url-current-callback-func 'w3-finalize-image-download)
|
|
628 (url-retrieve src))
|
|
629 (setq-default url-be-asynchronous old-asynch)))))))
|
|
630
|
|
631 (defun w3-finalize-image-download (widget)
|
|
632 (let ((glyph nil)
|
|
633 (url (widget-get widget 'src))
|
|
634 (node nil)
|
|
635 (buffer (widget-get widget 'buffer)))
|
|
636 (message "Enhancing image...")
|
|
637 (setq glyph (image-normalize (cdr-safe (assoc url-current-mime-type
|
|
638 w3-image-mappings))
|
|
639 (buffer-string)))
|
|
640 (message "Enhancing image... done")
|
|
641 (kill-buffer (current-buffer))
|
|
642 (cond
|
|
643 ((w3-image-invalid-glyph-p glyph)
|
|
644 (setq glyph nil)
|
|
645 (w3-warn 'image (format "Reading of %s failed." url)))
|
|
646 ((eq (aref glyph 0) 'xbm)
|
|
647 (let ((temp-fname (url-generate-unique-filename "%s.xbm")))
|
|
648 (save-excursion
|
|
649 (set-buffer (generate-new-buffer " *xbm-garbage*"))
|
|
650 (erase-buffer)
|
|
651 (insert (aref glyph 2))
|
|
652 (setq glyph temp-fname)
|
|
653 (write-region (point-min) (point-max) temp-fname)
|
|
654 (kill-buffer (current-buffer)))
|
|
655 (setq glyph (make-glyph (list (cons 'x glyph))))
|
|
656 (condition-case ()
|
|
657 (delete-file temp-fname)
|
|
658 (error nil))))
|
|
659 (t
|
|
660 (setq glyph (make-glyph glyph))))
|
|
661 (setq node (assoc url w3-graphics-list))
|
|
662 (cond
|
|
663 ((and node glyph)
|
|
664 (set-glyph-image (cdr node) (glyph-image glyph)))
|
|
665 (glyph
|
|
666 (setq w3-graphics-list (cons (cons url glyph) w3-graphics-list)))
|
|
667 (t nil))
|
|
668
|
|
669 (if (and (buffer-name buffer) ; Dest. buffer exists
|
|
670 (widget-glyphp glyph)) ; got a valid glyph
|
|
671 (save-excursion
|
|
672 (set-buffer buffer)
|
|
673 (if (eq major-mode 'w3-mode)
|
|
674 (widget-value-set widget glyph)
|
|
675 (setq w3-image-widgets-waiting
|
|
676 (cons widget w3-image-widgets-waiting)))))))
|
|
677
|
|
678 (defmacro w3-node-visible-p ()
|
|
679 (` (not (eq (car break-style) 'none))))
|
|
680
|
|
681 (defmacro w3-handle-image ()
|
|
682 (`
|
|
683 (let* ((height (w3-get-attribute 'height))
|
|
684 (width (w3-get-attribute 'width))
|
|
685 (src (or (w3-get-attribute 'src) "Error Image"))
|
|
686 (our-alt (cond
|
|
687 ((null w3-auto-image-alt) "")
|
|
688 ((eq t w3-auto-image-alt)
|
|
689 (concat "[IMAGE(" (url-basepath src t) ")] "))
|
|
690 ((stringp w3-auto-image-alt)
|
|
691 (format w3-auto-image-alt (url-basepath src t)))))
|
|
692 (alt (or (w3-get-attribute 'alt) our-alt))
|
|
693 (ismap (and (assq 'ismap args) 'ismap))
|
|
694 (usemap (w3-get-attribute 'usemap))
|
|
695 (base (w3-get-attribute 'base))
|
|
696 (href (and hyperlink-info (widget-get (cadr hyperlink-info) 'href)))
|
|
697 (widget nil)
|
|
698 (align (or (w3-get-attribute 'align)
|
|
699 (w3-get-style-info 'vertical-align node))))
|
|
700 (setq widget (widget-create 'image
|
|
701 :value-face w3-active-faces
|
|
702 'src src ; Where to load the image from
|
|
703 'alt alt ; Textual replacement
|
|
704 'ismap ismap ; Is it a server-side map?
|
|
705 'usemap usemap ; Is it a client-side map?
|
|
706 'href href ; Hyperlink destination
|
|
707 ))
|
|
708 (widget-put widget 'buffer (current-buffer))
|
|
709 (w3-maybe-start-image-download widget)
|
|
710 (goto-char (point-max)))))
|
|
711
|
|
712 ;; The table handling
|
|
713
|
|
714 (defvar w3-display-table-cut-words-p nil
|
|
715 "*Whether to cut words that are oversized in table cells")
|
|
716
|
|
717 (defvar w3-display-table-force-borders nil
|
|
718 "*Whether to always draw table borders")
|
|
719
|
|
720 (defun w3-display-table-cut ()
|
|
721 (save-excursion
|
|
722 (goto-char (point-min))
|
|
723 (let ((offset -1))
|
|
724 (while (< offset 0)
|
|
725 (end-of-line)
|
|
726 (setq offset (- fill-column (current-column)))
|
|
727 (cond ((< offset 0)
|
|
728 (condition-case nil
|
|
729 (progn (forward-char offset)
|
|
730 (insert ?\n))
|
|
731 (error (setq offset 0))))
|
|
732 ((not (eobp))
|
|
733 (forward-line 1)
|
|
734 (setq offset -1)))))))
|
|
735
|
|
736
|
|
737 (defun w3-display-fix-widgets ()
|
|
738 ;; Make markers belong to the right buffer
|
|
739 (save-excursion
|
|
740 (let ((st (point-min))
|
|
741 (nd nil)
|
|
742 (widget nil) parent
|
|
743 (to-marker nil)
|
|
744 (from-marker nil))
|
|
745 (while (setq st (next-single-property-change st 'button))
|
|
746 (setq nd (or (next-single-property-change st 'button) (point-max))
|
|
747 widget (widget-at st)
|
|
748 to-marker (and widget (widget-get widget :to))
|
|
749 from-marker (and widget (widget-get widget :from))
|
|
750 parent (and widget (widget-get widget :parent))
|
|
751 )
|
|
752 (if (not widget)
|
|
753 nil
|
|
754 (widget-put widget :from (set-marker (make-marker) st))
|
|
755 (widget-put widget :to (set-marker (make-marker) nd))
|
|
756 (if (not parent)
|
|
757 nil
|
|
758 (widget-put parent :from (set-marker (make-marker) st))
|
|
759 (widget-put parent :to (set-marker (make-marker) nd))))
|
|
760 (if (condition-case ()
|
|
761 (get-text-property (1+ nd) 'button)
|
|
762 (error nil))
|
|
763 (setq st nd)
|
|
764 (setq st (min (point-max) (1+ nd))))))))
|
|
765
|
|
766 (defun w3-size-of-tree (tree minmax)
|
|
767 (save-excursion
|
|
768 (save-restriction
|
|
769 (narrow-to-region (point) (point))
|
|
770 ;; XXX fill-column set to 1 fails when fill-prefix is set
|
|
771 ;; XXX setting fill-column at all isn't really right
|
|
772 ;; for example <hr>s shouldn't be especially wide
|
|
773 ;; we should set a flag that makes w3 never wrap a line
|
|
774 (let ((fill-column (cond ((eq minmax 'min)
|
|
775 3)
|
|
776 ((eq minmax 'max)
|
|
777 400)))
|
|
778 (fill-prefix "")
|
|
779 (w3-last-fill-pos (point-min))
|
|
780 a retval
|
|
781 (w3-do-incremental-display nil)
|
|
782 (hr-regexp (concat "^"
|
|
783 (regexp-quote
|
|
784 (make-string 5 w3-horizontal-rule-char))
|
|
785 "*$"))
|
|
786 )
|
|
787 ;;(push 'left w3-display-alignment-stack)
|
|
788 (push (if (eq minmax 'max) 'nowrap) w3-display-whitespace-stack)
|
|
789 (while tree
|
|
790 (push (cons '*td args) w3-display-open-element-stack)
|
|
791 (w3-display-node (pop tree)))
|
|
792 (pop w3-display-whitespace-stack)
|
|
793 (goto-char (point-min))
|
|
794 (while (re-search-forward hr-regexp nil t)
|
|
795 (replace-match "" t t))
|
|
796 (goto-char (point-min))
|
|
797 (while (not (eobp))
|
|
798 ;; loop invariant: at beginning of uncounted line
|
|
799 (end-of-line)
|
|
800 (skip-chars-backward " ")
|
|
801 (setq retval (cons (current-column)
|
|
802 retval))
|
|
803 (beginning-of-line 2))
|
|
804 (if (= (point-min) (point-max))
|
|
805 (setq retval 0)
|
|
806 (setq retval (apply 'max (cons 0 retval))))
|
|
807 (delete-region (point-min) (point-max))
|
|
808 retval))))
|
|
809
|
|
810 (defun w3-display-table-dimensions (node)
|
|
811 ;; fill-column sets maximum width
|
|
812 (let (min-vector
|
|
813 max-vector
|
|
814 rows cols
|
|
815 ;;(w3-form-elements (and (boundp 'w3-form-elements) w3-form-elements))
|
|
816 (table-info (assq 'w3-table-info (cadr node))))
|
|
817
|
|
818 (if table-info
|
|
819 (setq min-vector (nth 1 table-info)
|
|
820 max-vector (nth 2 table-info)
|
|
821 rows (nth 3 table-info)
|
|
822 cols (nth 4 table-info))
|
|
823
|
|
824 (push (cons '*table-autolayout args) w3-display-open-element-stack)
|
|
825 (let (content
|
|
826 cur
|
|
827 (table-spans (list nil)) ; don't make this '(nil)
|
|
828 ptr
|
|
829 col
|
|
830 constraints
|
|
831
|
|
832 colspan rowspan min max)
|
|
833 (setq content (nth 2 node))
|
|
834 (setq rows 0 cols 0)
|
|
835 (while content
|
|
836 (setq cur (pop content))
|
|
837 (if (stringp cur)
|
|
838 nil
|
|
839 (case (car cur)
|
|
840 (tr
|
|
841 (setq col 0)
|
|
842 (setq rows (1+ rows))
|
|
843 (setq ptr table-spans)
|
|
844 (mapcar
|
|
845 (function
|
|
846 (lambda (td)
|
|
847 (setq colspan (string-to-int (or (cdr-safe (assq 'colspan (nth 1 td))) "1"))
|
|
848 rowspan (string-to-int (or (cdr-safe (assq 'rowspan (nth 1 td))) "1"))
|
|
849 min (w3-size-of-tree (nth 2 td) 'min)
|
|
850 max (w3-size-of-tree (nth 2 td) 'max)
|
|
851 )
|
|
852 (while (eq (car-safe (car-safe (cdr ptr))) col)
|
|
853 (setq col (+ col (cdr (cdr (car (cdr ptr))))))
|
|
854 (if (= 0 (decf (car (cdr (car (cdr ptr))))))
|
|
855 (pop (cdr ptr))
|
|
856 (setq ptr (cdr ptr))))
|
|
857 (push (list col colspan min max)
|
|
858 constraints)
|
|
859 (if (= rowspan 1) nil
|
|
860 (push (cons col (cons (1- rowspan) colspan)) (cdr ptr))
|
|
861 (setq ptr (cdr ptr)))
|
|
862 (setq col (+ col colspan))
|
|
863 ))
|
|
864 (nth 2 cur))
|
|
865 (while (cdr ptr)
|
|
866 (if (= 0 (decf (car (cdr (car (cdr ptr))))))
|
|
867 (pop (cdr ptr))
|
|
868 (setq ptr (cdr ptr))))
|
|
869 (setq cols (max cols col))
|
|
870 )
|
|
871 (caption
|
|
872 nil)
|
|
873 (otherwise
|
|
874 (setq content (nth 2 cur)))
|
|
875 )
|
|
876 )
|
|
877 )
|
|
878 (setq constraints (sort constraints
|
|
879 (function
|
|
880 (lambda (a b)
|
|
881 (< (cadr a) (cadr b)))))
|
|
882 min-vector (make-vector cols 0)
|
|
883 max-vector (make-vector cols 0))
|
|
884 (let (start end i mincellwidth maxcellwidth)
|
|
885 (mapcar (function (lambda (c)
|
|
886 (cond ((= (cadr c) 1)
|
|
887 (aset min-vector (car c)
|
|
888 (max (aref min-vector (car c))
|
|
889 (nth 2 c)))
|
|
890 (aset max-vector (car c)
|
|
891 (max (aref max-vector (car c))
|
|
892 (nth 3 c))))
|
|
893 (t
|
|
894 (setq start (car c)
|
|
895 end (+ (car c) (cadr c))
|
|
896 mincellwidth 0
|
|
897 maxcellwidth 0
|
|
898 i start)
|
|
899 (while (< i end)
|
|
900 (setq mincellwidth (+ mincellwidth
|
|
901 (aref min-vector i))
|
|
902 maxcellwidth (+
|
|
903 maxcellwidth
|
|
904 (aref max-vector i))
|
|
905 i (1+ i)))
|
|
906 (setq i start)
|
|
907 (if (= mincellwidth 0)
|
|
908 ;; if existing width is 0 divide evenly
|
|
909 (while (< i end)
|
|
910 (aset min-vector i
|
|
911 (/ (nth 2 c) (cadr c)))
|
|
912 (aset max-vector i
|
|
913 (/ (nth 3 c) (cadr c)))
|
|
914 (setq i (1+ i)))
|
|
915 ;; otherwise weight it by existing widths
|
|
916 (while (< i end)
|
|
917 (aset min-vector i
|
|
918 (max (aref min-vector i)
|
|
919 (/ (* (nth 2 c)
|
|
920 (aref min-vector i))
|
|
921 mincellwidth)))
|
|
922 (aset max-vector i
|
|
923 (max (aref max-vector i)
|
|
924 (/ (* (nth 3 c)
|
|
925 (aref max-vector i))
|
|
926 maxcellwidth)))
|
|
927 (setq i (1+ i))))
|
|
928 ))))
|
|
929 constraints)))
|
|
930 (push (cons 'w3-table-info
|
|
931 (list min-vector max-vector rows cols))
|
|
932 (cadr node))
|
|
933 (pop w3-display-open-element-stack))
|
|
934
|
|
935 (let (max-width
|
|
936 min-width
|
|
937 ret-vector
|
|
938 col
|
|
939 )
|
|
940
|
|
941
|
|
942 (setq max-width (apply '+ (append max-vector (list cols 1))))
|
|
943 (setq min-width (apply '+ (append min-vector (list cols 1))))
|
|
944
|
|
945 ;; the comments in the cond are excerpts from rfc1942 itself
|
|
946 (cond
|
|
947 ;; 1. The minimum table width is equal to or wider than the available
|
|
948 ;; space. In this case, assign the minimum widths and allow the
|
|
949 ;; user to scroll horizontally. For conversion to braille, it will
|
|
950 ;; be necessary to replace the cells by references to notes
|
|
951 ;; containing their full content. By convention these appear
|
|
952 ;; before the table.
|
|
953 ((>= min-width fill-column)
|
|
954 (setq ret-vector min-vector))
|
|
955
|
|
956 ;; 2. The maximum table width fits within the available space. In
|
|
957 ;; this case, set the columns to their maximum widths.
|
|
958 ((<= max-width fill-column)
|
|
959 (setq ret-vector max-vector))
|
|
960
|
|
961 ;; 3. The maximum width of the table is greater than the available
|
|
962 ;; space, but the minimum table width is smaller. In this case,
|
|
963 ;; find the difference between the available space and the minimum
|
|
964 ;; table width, lets call it W. Lets also call D the difference
|
|
965 ;; between maximum and minimum width of the table.
|
|
966
|
|
967 ;; For each column, let d be the difference between maximum and
|
|
968 ;; minimum width of that column. Now set the column's width to the
|
|
969 ;; minimum width plus d times W over D. This makes columns with
|
|
970 ;; large differences between minimum and maximum widths wider than
|
|
971 ;; columns with smaller differences.
|
|
972 (t
|
|
973 (setq ret-vector (make-vector cols 0))
|
|
974 (let ((W (- fill-column min-width))
|
|
975 (D (- max-width min-width))
|
|
976 d extra)
|
|
977 (setq col 0)
|
|
978 (while (< col (length ret-vector))
|
|
979 (setq d (- (aref max-vector col)
|
|
980 (aref min-vector col)))
|
|
981 (aset ret-vector col
|
|
982 (+ (aref min-vector col)
|
|
983 (/ (* d W) D)))
|
|
984 (setq col (1+ col)))
|
|
985 (setq extra (- fill-column
|
|
986 (apply '+ (append ret-vector
|
|
987 (list (length ret-vector) 1))))
|
|
988 col 0)
|
|
989 (while (and (< col (length ret-vector)) (> extra 0))
|
|
990 (if (= 1 (- (aref max-vector col) (aref ret-vector col) ))
|
|
991 (aset ret-vector col (1+ (aref ret-vector col))))
|
|
992 (setq extra (1- extra)
|
|
993 col (1+ col)))
|
|
994 )))
|
|
995 (list rows cols ret-vector))))
|
|
996
|
|
997 (defvar w3-table-ascii-border-chars
|
|
998 [? ? ? ?/ ? ?- ?\\ ?- ? ?\\ ?| ?| ?/ ?- ?| ?-]
|
|
999 "Vector of ascii characters to use to draw table borders.
|
|
1000 w3-table-unhack-border-chars uses this to restore w3-table-border-chars.")
|
|
1001
|
|
1002 (defvar w3-table-border-chars w3-table-ascii-border-chars
|
|
1003 "Vector of characters to use to draw table borders.
|
|
1004 If you set this you should set w3-table-ascii-border-chars to the same value
|
|
1005 so that w3-table-unhack-borders can restore the value if necessary.
|
|
1006
|
|
1007 A reasonable value is [? ? ? ?/ ? ?- ?\\\\ ?^ ? ?\\\\ ?| ?< ?/ ?- ?> ?-]
|
|
1008 Though i recommend replacing the ^ with - and the < and > with |")
|
|
1009
|
|
1010 (defsubst w3-table-lookup-char (l u r b)
|
|
1011 (aref w3-table-border-chars (logior (if l 1 0)
|
|
1012 (if u 2 0)
|
|
1013 (if r 4 0)
|
|
1014 (if b 8 0))))
|
|
1015
|
|
1016 (defun w3-table-hack-borders nil
|
|
1017 "Try to find the best set of characters to draw table borders with.
|
|
1018 I definitely recommend trying this on X.
|
|
1019 On a console, this can trigger some Emacs display bugs.
|
|
1020
|
|
1021 I haven't tried this on XEmacs or any window-system other than X."
|
|
1022 (interactive)
|
|
1023 (case (device-type)
|
|
1024 (x
|
|
1025 (let ((id (or (and (find-face 'w3-table-hack-x-face)
|
|
1026 (face-id 'w3-table-hack-x-face))
|
|
1027 (progn
|
|
1028 (make-face 'w3-table-hack-x-face)
|
|
1029 (set-face-font 'w3-table-hack-x-face
|
|
1030 (make-font :family "terminal"))
|
|
1031 (face-id 'w3-table-hack-x-face)))))
|
|
1032 (if (not (face-differs-from-default-p 'w3-table-hack-x-face))
|
|
1033 nil
|
|
1034 (aset standard-display-table 1 (vector (+ (* 256 id) ?l)))
|
|
1035 (aset standard-display-table 2 (vector (+ (* 256 id) ?q)))
|
|
1036 (aset standard-display-table 3 (vector (+ (* 256 id) ?k)))
|
|
1037 (aset standard-display-table 4 (vector (+ (* 256 id) ?t)))
|
|
1038 (aset standard-display-table 5 (vector (+ (* 256 id) ?n)))
|
|
1039 (aset standard-display-table 6 (vector (+ (* 256 id) ?u)))
|
|
1040 (aset standard-display-table 7 (vector (+ (* 256 id) ?m)))
|
|
1041 (aset standard-display-table 8 (vector (+ (* 256 id) ?x)))
|
|
1042 (aset standard-display-table 11 (vector (+ (* 256 id) ?j)))
|
|
1043 (aset standard-display-table 14 (vector (+ (* 256 id) ?v)))
|
|
1044 (aset standard-display-table 15 (vector (+ (* 256 id) ?w)))
|
|
1045 (setq w3-table-border-chars [? ? ? 11 ? 2 7 14 ? 3 8 6 1 15 4 5])
|
|
1046 (setq w3-horizontal-rule-char 2))))
|
|
1047 (tty
|
|
1048 (standard-display-g1 1 108) ; ulcorner
|
|
1049 (standard-display-g1 2 113) ; hline
|
|
1050 (standard-display-g1 3 107) ; urcorner
|
|
1051 (standard-display-g1 4 116) ; leftt
|
|
1052 (standard-display-g1 5 110) ; intersection
|
|
1053 (standard-display-g1 6 117) ; rightt
|
|
1054 (standard-display-g1 7 109) ; llcorner
|
|
1055 (standard-display-g1 8 120) ; vline
|
|
1056 (standard-display-g1 11 106) ; lrcorner
|
|
1057 (standard-display-g1 14 118) ; upt
|
|
1058 (standard-display-g1 15 119) ; downt
|
|
1059 (setq w3-table-border-chars [? ? ? 11 ? 2 7 14 ? 3 8 6 1 15 4 5])
|
|
1060 (setq w3-horizontal-rule-char 2))
|
|
1061 (otherwise
|
|
1062 (error "Unknown window-system, can't do any better than ascii borders")))
|
|
1063 )
|
|
1064
|
|
1065 (defun w3-table-unhack-borders nil
|
|
1066 (interactive)
|
|
1067 (w3-table-excise-hack (buffer-list))
|
|
1068 (standard-display-default 1 15)
|
|
1069 (setq w3-table-border-chars w3-table-ascii-border-chars)
|
|
1070 (setq w3-horizontal-rule-char ?-))
|
|
1071
|
|
1072 (defun w3-table-excise-hack (buffs)
|
|
1073 "Replace hacked characters with ascii characters in buffers BUFFS.
|
|
1074 Should be run before restoring w3-table-border-chars to ascii characters."
|
|
1075 (interactive (list (list (current-buffer))))
|
|
1076 (let ((inhibit-read-only t)
|
|
1077 (tr (make-string 16 ? ))
|
|
1078 (i 0))
|
|
1079 (while (< i (length tr))
|
|
1080 (aset tr i i)
|
|
1081 (setq i (1+ i)))
|
|
1082 (setq i 0)
|
|
1083 (while (< i (length w3-table-border-chars))
|
|
1084 (if (< (aref w3-table-border-chars i) 16)
|
|
1085 (aset tr
|
|
1086 (aref w3-table-border-chars i)
|
|
1087 (aref w3-table-ascii-border-chars i)))
|
|
1088 (setq i (1+ i)))
|
|
1089 (mapcar (function (lambda (buf)
|
|
1090 (save-excursion
|
|
1091 (set-buffer buf)
|
|
1092 (if (eq major-mode 'w3-mode)
|
|
1093 (translate-region (point-min)
|
|
1094 (point-max)
|
|
1095 tr)))))
|
|
1096 buffs)))
|
|
1097
|
|
1098 (defun w3-display-table (node)
|
|
1099 (let* ((dimensions (w3-display-table-dimensions node))
|
|
1100 (num-cols (max (cadr dimensions) 1))
|
|
1101 (num-rows (max (car dimensions) 1))
|
|
1102 (column-dimensions (caddr dimensions))
|
|
1103 (table-width (apply '+ (append column-dimensions (list num-cols 1)))))
|
|
1104 (cond
|
|
1105 ((or (<= (cadr dimensions) 0) (<= (car dimensions) 0))
|
|
1106 ;; We have an invalid table
|
|
1107 nil)
|
|
1108 ((assq '*table-autolayout w3-display-open-element-stack)
|
|
1109 ;; don't bother displaying the table if all we really need is the size
|
|
1110 (progn (insert-char ?T table-width) (insert "\n")))
|
|
1111 (t
|
|
1112 (let* ((tag (nth 0 node))
|
|
1113 (args (nth 1 node))
|
|
1114 (border-node (cdr-safe (assq 'border args)))
|
|
1115 (border (or w3-display-table-force-borders
|
|
1116 (and border-node
|
|
1117 (or (/= 0 (string-to-int border-node))
|
|
1118 (string= "border" border-node)))))
|
|
1119 (w3-table-border-chars
|
|
1120 (if border
|
|
1121 w3-table-border-chars
|
|
1122 (make-vector (length w3-table-border-chars) ? )))
|
|
1123 valign align
|
|
1124 (content (nth 2 node))
|
|
1125 (avgwidth (/ (- fill-column num-cols num-cols) num-cols))
|
|
1126 (formatted-cols (make-vector num-cols nil))
|
|
1127 (table-rowspans (make-vector num-cols 0))
|
|
1128 (table-colspans (make-vector num-cols 1))
|
|
1129 (prev-colspans (make-vector num-cols 0))
|
|
1130 (prev-rowspans (make-vector num-cols 0))
|
|
1131 (table-colwidth (make-vector num-cols 0))
|
|
1132 (fill-prefix "")
|
|
1133 (height nil)
|
|
1134 (cur-height nil)
|
|
1135 (cols nil)
|
|
1136 (rows nil)
|
|
1137 (row 0)
|
|
1138 (this-rectangle nil)
|
|
1139 (i 0)
|
|
1140 )
|
|
1141
|
|
1142 (push (cons tag args) w3-display-open-element-stack)
|
|
1143
|
|
1144 (if (memq 'nowrap w3-display-whitespace-stack)
|
|
1145 (setq fill-prefix "")
|
|
1146 (case (car w3-display-alignment-stack)
|
|
1147 (center
|
|
1148 (w3-set-fill-prefix-length
|
|
1149 (max 0 (/ (- fill-column table-width) 2))))
|
|
1150 (right
|
|
1151 (w3-set-fill-prefix-length
|
|
1152 (max 0 (- fill-column table-width))))
|
|
1153 (t
|
|
1154 (setq fill-prefix ""))))
|
|
1155 (while content
|
|
1156 (case (caar content)
|
|
1157 (tr
|
|
1158 (setq w3-display-css-properties (css-get
|
|
1159 (nth 0 (car content))
|
|
1160 (nth 1 (car content))
|
|
1161 w3-current-stylesheet
|
|
1162 w3-display-open-element-stack))
|
|
1163 (setq cols (nth 2 (car content))
|
|
1164 valign (or (cdr-safe (assq 'valign (nth 1 (car content))))
|
|
1165 (w3-get-style-info 'vertical-align node))
|
|
1166 align (or (cdr-safe (assq 'align (nth 1 (car content))))
|
|
1167 (w3-get-style-info 'text-align node))
|
|
1168 content (cdr content)
|
|
1169 row (1+ row))
|
|
1170 (if (and valign (stringp valign))
|
|
1171 (setq valign (intern (downcase valign))))
|
|
1172 ;; this is iffy
|
|
1173 ;;(if align (push (intern (downcase align)) w3-display-alignment-stack))
|
|
1174 (save-excursion
|
|
1175 (save-restriction
|
|
1176 (narrow-to-region (point) (point))
|
|
1177 (setq fill-column avgwidth
|
|
1178 inhibit-read-only t
|
|
1179 w3-last-fill-pos (point-min)
|
|
1180 i 0)
|
|
1181 ;; skip over columns that have leftover content
|
|
1182 (while (and (< i num-cols)
|
|
1183 (/= 0 (aref table-rowspans i)))
|
|
1184 (setq i (+ i (max 1 (aref table-colspans i)))))
|
|
1185 (while cols
|
|
1186 (let* ((node (car cols))
|
|
1187 (attributes (nth 1 node))
|
|
1188 (colspan (string-to-int
|
|
1189 (or (cdr-safe (assq 'colspan attributes))
|
|
1190 "1")))
|
|
1191 (rowspan (string-to-int
|
|
1192 (or (cdr-safe (assq 'rowspan attributes))
|
|
1193 "1")))
|
|
1194 fill-column column-width
|
|
1195 (fill-prefix "")
|
|
1196 (w3-do-incremental-display nil)
|
|
1197 (indent-tabs-mode nil)
|
|
1198 c e
|
|
1199 )
|
|
1200
|
|
1201 (aset table-colspans i colspan)
|
|
1202 (aset table-rowspans i rowspan)
|
|
1203
|
|
1204 (setq fill-column 0)
|
|
1205 (setq c i
|
|
1206 e (+ i colspan))
|
|
1207 (while (< c e)
|
|
1208 (setq fill-column (+ fill-column
|
|
1209 (aref column-dimensions c)
|
|
1210 1)
|
|
1211 c (1+ c)))
|
|
1212 (setq fill-column (1- fill-column))
|
|
1213 (aset table-colwidth i fill-column)
|
|
1214
|
|
1215 (setq w3-last-fill-pos (point-min))
|
|
1216 (push (cons (nth 0 node) (nth 1 node))
|
|
1217 w3-display-open-element-stack)
|
|
1218 (w3-display-node node)
|
|
1219 (setq fill-column (aref table-colwidth i))
|
|
1220 (if w3-display-table-cut-words-p
|
|
1221 (w3-display-table-cut))
|
|
1222 (setq cols (cdr cols))
|
|
1223 (goto-char (point-min))
|
|
1224 (skip-chars-forward "\t\n\r")
|
|
1225 (beginning-of-line)
|
|
1226 (delete-region (point-min) (point))
|
|
1227 (goto-char (point-max))
|
|
1228 (skip-chars-backward " \t\n\r")
|
|
1229 (delete-region (point) (point-max))
|
|
1230 (if (>= fill-column (current-column))
|
|
1231 (insert-char ? (- fill-column (current-column))))
|
|
1232 (aset formatted-cols i (extract-rectangle (point-min) (point-max)))
|
|
1233 (delete-region (point-min) (point-max))
|
|
1234 (let ((j (1- colspan)))
|
|
1235 (while (> j 0)
|
|
1236 (aset table-colspans (+ i j) 0)
|
|
1237 (setq j (1- j))))
|
|
1238 (setq i (+ i colspan))
|
|
1239 ;; skip over columns that have leftover content
|
|
1240 (while (and (< i num-cols)
|
|
1241 (/= 0 (aref table-rowspans i)))
|
|
1242 (setq i (+ i (max 1 (aref table-colspans i)))))
|
|
1243 ))
|
|
1244
|
|
1245 ;; finish off the columns
|
|
1246 (while (< i num-cols)
|
|
1247 (aset table-colwidth i (aref column-dimensions i))
|
|
1248 (aset table-colspans i 1)
|
|
1249 (setq i (1+ i))
|
|
1250 (while (and (< i num-cols)
|
|
1251 (/= 0 (aref table-rowspans i)))
|
|
1252 (setq i (+ i (max 1 (aref table-colspans i))))))
|
|
1253
|
|
1254 ;; on the last row empty any pending rowspans per the rfc
|
|
1255 (if content nil
|
|
1256 (fillarray table-rowspans 1))
|
|
1257
|
|
1258 ;; Find the tallest rectangle that isn't a rowspanning cell
|
|
1259 (setq height 0
|
|
1260 i 0)
|
|
1261 (while (< i num-cols)
|
|
1262 (if (= 1 (aref table-rowspans i))
|
|
1263 (setq height (max height (length (aref formatted-cols i)))))
|
|
1264 (setq i (+ i (max 1 (aref table-colspans i)))))
|
|
1265
|
|
1266 ;; Make all rectangles the same height
|
|
1267 (setq i 0)
|
|
1268 (while (< i num-cols)
|
|
1269 (setq this-rectangle (aref formatted-cols i))
|
|
1270 (if (> height (length this-rectangle))
|
|
1271 (let ((colspan-fill-line
|
|
1272 (make-string (aref table-colwidth i) ? )))
|
|
1273 (case valign
|
|
1274 ((center middle)
|
|
1275 (aset formatted-cols i
|
|
1276 (append (make-list (/ (- height (length this-rectangle)) 2)
|
|
1277 colspan-fill-line)
|
|
1278 this-rectangle)))
|
|
1279 (bottom
|
|
1280 (aset formatted-cols i
|
|
1281 (append (make-list (- height (length this-rectangle))
|
|
1282 colspan-fill-line)
|
|
1283 this-rectangle))))))
|
|
1284 (setq i (+ i (max 1 (aref table-colspans i)))))))
|
|
1285
|
|
1286
|
|
1287 ;; fix broken colspans (this should only matter on illegal tables)
|
|
1288 (setq i 0)
|
|
1289 (while (< i num-cols)
|
|
1290 (if (= (aref table-colspans i) 0)
|
|
1291 (aset table-colspans i 1))
|
|
1292 (setq i (+ i (aref table-colspans i))))
|
|
1293
|
|
1294 ;; Insert a separator
|
|
1295 (insert fill-prefix)
|
|
1296 (setq i 0)
|
|
1297 (let (rflag bflag tflag lflag)
|
|
1298 (while (< i num-cols)
|
|
1299
|
|
1300 (setq rflag (= (aref prev-rowspans i) 0))
|
|
1301 (setq bflag (/= (aref table-colspans i) 0))
|
|
1302 (setq tflag (/= (aref prev-colspans i) 0))
|
|
1303
|
|
1304 (insert (w3-table-lookup-char lflag tflag rflag bflag))
|
|
1305 (setq lflag t)
|
|
1306 (cond ((= (aref prev-rowspans i) 0)
|
|
1307 (insert-char (w3-table-lookup-char t nil t nil)
|
|
1308 (aref column-dimensions i))
|
|
1309 (setq i (1+ i)))
|
|
1310 ((car (aref formatted-cols i))
|
|
1311 (insert (pop (aref formatted-cols i)))
|
|
1312 (setq lflag nil)
|
|
1313 (setq i (+ i (max (aref table-colspans i)
|
|
1314 (aref prev-colspans i) 1))))
|
|
1315 (t
|
|
1316 (insert-char ? (aref table-colwidth i))
|
|
1317 (setq lflag nil)
|
|
1318 (setq i (+ i (max (aref table-colspans i)
|
|
1319 (aref prev-colspans i) 1))))))
|
|
1320 (insert (w3-table-lookup-char lflag (/= row 1) nil t) "\n"))
|
|
1321
|
|
1322 ;; recalculate height (in case we've shortened a rowspanning cell
|
|
1323 (setq height 0
|
|
1324 i 0)
|
|
1325 (while (< i num-cols)
|
|
1326 (if (= 1 (aref table-rowspans i))
|
|
1327 (setq height (max height (length (aref formatted-cols i)))))
|
|
1328 (setq i (+ i (max 1 (aref table-colspans i)))))
|
|
1329
|
|
1330 ;; Insert a row back in original buffer
|
|
1331 (while (> height 0)
|
|
1332 (insert fill-prefix (w3-table-lookup-char nil t nil t))
|
|
1333 (setq i 0)
|
|
1334 (while (< i num-cols)
|
|
1335 (if (car (aref formatted-cols i))
|
|
1336 (insert (pop (aref formatted-cols i)))
|
|
1337 (insert-char ? (aref table-colwidth i)))
|
|
1338 (insert (w3-table-lookup-char nil t nil t))
|
|
1339 (setq i (+ i (max (aref table-colspans i) 1))))
|
|
1340 (insert "\n")
|
|
1341 ;;(and w3-do-incremental-display (w3-pause))
|
|
1342 (setq height (1- height)))
|
|
1343
|
|
1344 (setq i 0)
|
|
1345 (while (< i num-cols)
|
|
1346 (if (> (aref table-rowspans i) 0)
|
|
1347 (decf (aref table-rowspans i)))
|
|
1348 (incf i))
|
|
1349
|
|
1350 (setq prev-rowspans (copy-seq table-rowspans))
|
|
1351 (setq prev-colspans (copy-seq table-colspans))
|
|
1352
|
|
1353 (and w3-do-incremental-display (w3-pause))
|
|
1354
|
|
1355 )
|
|
1356 (caption
|
|
1357 (let ((left (length fill-prefix))
|
|
1358 (fill-prefix "")
|
|
1359 (fill-column table-width)
|
|
1360 (start (point)))
|
|
1361 (w3-display-node (pop content))
|
|
1362 (indent-rigidly start (point) left)))
|
|
1363 (otherwise
|
|
1364 (delete-horizontal-space)
|
|
1365 (setq content (nth 2 (car content))))
|
|
1366 ))
|
|
1367 (if (= (length column-dimensions) 0) nil
|
|
1368 (insert fill-prefix)
|
|
1369 (setq i 0)
|
|
1370 (let (tflag lflag)
|
|
1371 (while (< i num-cols)
|
|
1372 (setq tflag (/= (aref prev-colspans i) 0))
|
|
1373 (insert (w3-table-lookup-char lflag tflag t nil))
|
|
1374 (setq lflag t)
|
|
1375 (insert-char (w3-table-lookup-char t nil t nil)
|
|
1376 (aref column-dimensions i))
|
|
1377 (setq i (1+ i)))
|
|
1378 (insert (w3-table-lookup-char t t nil nil) "\n")))
|
|
1379 )
|
|
1380 (pop w3-display-open-element-stack)))))
|
|
1381
|
|
1382
|
|
1383
|
|
1384 (defun w3-display-create-unique-id ()
|
|
1385 (let* ((date (current-time-string))
|
|
1386 (dateinfo (and date (timezone-parse-date date)))
|
|
1387 (timeinfo (and date (timezone-parse-time (aref dateinfo 3)))))
|
|
1388 (if (and dateinfo timeinfo)
|
|
1389 (concat (aref dateinfo 0) ; Year
|
|
1390 (aref dateinfo 1) ; Month
|
|
1391 (aref dateinfo 2) ; Day
|
|
1392 (aref timeinfo 0) ; Hour
|
|
1393 (aref timeinfo 1) ; Minute
|
|
1394 (aref timeinfo 2) ; Second
|
|
1395 )
|
|
1396 "HoplesSLYCoNfUSED")))
|
|
1397
|
82
|
1398 (defun w3-display-chop-into-table (node cols)
|
|
1399 ;; Chop the content of 'node' up into 'cols' columns suitable for inclusion
|
|
1400 ;; as the content of a table
|
|
1401 (let ((content (nth 2 node))
|
|
1402 (items nil)
|
|
1403 (rows nil))
|
|
1404 (setq cols (max cols 1))
|
|
1405 (while content
|
|
1406 (push (list 'td nil (list (pop content))) items)
|
|
1407 (if (= (length items) cols)
|
|
1408 (setq rows (cons (nreverse items) rows)
|
|
1409 items nil)))
|
|
1410 (if items ; Store any leftovers
|
|
1411 (setq rows (cons (nreverse items) rows)
|
|
1412 items nil))
|
|
1413 (while rows
|
|
1414 (push (list 'tr nil (pop rows)) items))
|
|
1415 items))
|
|
1416
|
86
|
1417 (defun w3-display-normalize-form-info (args)
|
|
1418 (let* ((plist (alist-to-plist args))
|
|
1419 (type (intern (downcase
|
|
1420 (or (plist-get plist 'type) "text"))))
|
|
1421 (name (plist-get plist 'name))
|
|
1422 (value (or (plist-get plist 'value) ""))
|
|
1423 (size (if (plist-get plist 'size)
|
|
1424 (string-to-int (plist-get plist 'size))))
|
|
1425 (maxlength (if (plist-get plist 'maxlength)
|
|
1426 (string-to-int
|
|
1427 (plist-get plist 'maxlength))))
|
|
1428 (default value)
|
|
1429 (checked (assq 'checked args)))
|
|
1430 (if (memq type '(checkbox radio)) (setq default checked))
|
|
1431 (if (and (eq type 'checkbox) (string= value ""))
|
|
1432 (setq value "on"))
|
|
1433 (if (and (not (memq type '(submit reset button)))
|
|
1434 (not name))
|
|
1435 (setq name (symbol-name type)))
|
|
1436 (while (and name (string-match "[\r\n]+" name))
|
|
1437 (setq name (concat (substring name 0 (match-beginning 0))
|
|
1438 (substring name (match-end 0) nil))))
|
|
1439 (setq plist (plist-put plist 'type type)
|
|
1440 plist (plist-put plist 'name name)
|
|
1441 plist (plist-put plist 'value value)
|
|
1442 plist (plist-put plist 'size size)
|
|
1443 plist (plist-put plist 'default default)
|
|
1444 plist (plist-put plist 'internal-form-number w3-current-form-number)
|
|
1445 plist (plist-put plist 'action w3-display-form-id)
|
|
1446 plist (plist-put plist 'maxlength maxlength))
|
|
1447 plist))
|
|
1448
|
14
|
1449 (defun w3-display-node (node &optional nofaces)
|
|
1450 (let (
|
|
1451 (content-stack (list (list node)))
|
|
1452 (right-margin-stack (list fill-column))
|
|
1453 (left-margin-stack (list 0))
|
|
1454 node
|
|
1455 insert-before
|
|
1456 insert-after
|
|
1457 tag
|
|
1458 args
|
|
1459 content
|
|
1460 hyperlink-info
|
|
1461 break-style
|
|
1462 cur
|
|
1463 id
|
|
1464 class
|
|
1465 )
|
|
1466 (while content-stack
|
|
1467 (setq content (pop content-stack))
|
|
1468 (pop w3-active-faces)
|
|
1469 (pop w3-active-voices)
|
|
1470 (case (car (pop w3-display-open-element-stack))
|
|
1471 ;; Any weird, post-display-of-content stuff for specific tags
|
|
1472 ;; goes here. Couldn't think of any better way to do this when we
|
|
1473 ;; are iterative. *sigh*
|
|
1474 (a
|
|
1475 (if (not hyperlink-info)
|
|
1476 nil
|
|
1477 (add-text-properties (car hyperlink-info) (point)
|
|
1478 (list
|
|
1479 'mouse-face 'highlight
|
|
1480 'duplicable t
|
82
|
1481 'start-open t
|
|
1482 'end-open t
|
|
1483 'rear-nonsticky t
|
14
|
1484 'help-echo 'w3-balloon-help-callback
|
|
1485 'balloon-help 'w3-balloon-help-callback))
|
|
1486 (fillin-text-property (car hyperlink-info) (point)
|
|
1487 'button 'button (cadr hyperlink-info))
|
|
1488 (widget-put (cadr hyperlink-info) :to (set-marker
|
|
1489 (make-marker) (point))))
|
|
1490 (setq hyperlink-info nil))
|
|
1491 ((ol ul dl dir menu)
|
|
1492 (pop w3-display-list-stack))
|
|
1493 (otherwise
|
|
1494 nil))
|
|
1495 (if (car insert-after)
|
|
1496 (w3-handle-string-content (car insert-after)))
|
|
1497 (pop insert-after)
|
|
1498 (w3-display-handle-end-break)
|
|
1499 (w3-pop-all-face-info)
|
|
1500 ;; Handle the element's content
|
|
1501 (while content
|
|
1502 (if (stringp (car content))
|
|
1503 (w3-handle-string-content (pop content))
|
|
1504 (setq node (pop content)
|
|
1505 tag (nth 0 node)
|
|
1506 args (nth 1 node)
|
|
1507 id (or (w3-get-attribute 'name)
|
|
1508 (w3-get-attribute 'id))
|
|
1509 )
|
|
1510 ;; This little bit of magic takes care of inline styles.
|
|
1511 ;; Evil Evil Evil, but it appears to work.
|
|
1512 (if (w3-get-attribute 'style)
|
|
1513 (let ((unique-id (or (w3-get-attribute 'id)
|
|
1514 (w3-display-create-unique-id)))
|
82
|
1515 (sheet "")
|
|
1516 (class (assq 'class args)))
|
14
|
1517 (setq sheet (format "%s.%s { %s }\n" tag unique-id
|
|
1518 (w3-get-attribute 'style)))
|
82
|
1519 (if class
|
|
1520 (setcdr class (cons unique-id (cdr class)))
|
|
1521 (setf (nth 1 node) (cons (cons 'class (list unique-id))
|
|
1522 (nth 1 node))))
|
|
1523 (setf (nth 1 node) (cons (cons 'id unique-id) (nth 1 node)))
|
|
1524 (w3-handle-style (list 'data sheet
|
|
1525 'notation "css"))))
|
14
|
1526 (setq w3-display-css-properties (css-get
|
82
|
1527 (nth 0 node)
|
|
1528 (nth 1 node)
|
14
|
1529 w3-current-stylesheet
|
|
1530 w3-display-open-element-stack))
|
|
1531 (if nofaces
|
|
1532 nil
|
|
1533 (push (w3-face-for-element node) w3-active-faces)
|
|
1534 (push (w3-voice-for-element node) w3-active-voices))
|
|
1535 (push (w3-get-style-info 'display node) break-style)
|
|
1536 (push (w3-get-style-info 'insert-after node) insert-after)
|
|
1537 (setq insert-before (w3-get-style-info 'insert-before node))
|
|
1538 (w3-display-handle-break)
|
|
1539 (if (w3-node-visible-p)
|
|
1540 nil
|
|
1541 (setq insert-before nil
|
|
1542 tag '*invisible)
|
|
1543 (setcar insert-after nil))
|
|
1544 (if insert-before
|
|
1545 (w3-handle-string-content insert-before))
|
|
1546 (setq insert-before nil)
|
|
1547 (if id
|
|
1548 (setq w3-id-positions (cons
|
|
1549 (cons (intern id)
|
|
1550 (set-marker (make-marker)
|
|
1551 (point-max)))
|
|
1552 w3-id-positions)))
|
|
1553 (case tag
|
|
1554 (a ; Hyperlinks
|
|
1555 (let* (
|
|
1556 (title (w3-get-attribute 'title))
|
|
1557 (name (or (w3-get-attribute 'id)
|
|
1558 (w3-get-attribute 'name)))
|
|
1559 (btdt nil)
|
|
1560 class
|
|
1561 (before nil)
|
|
1562 (after nil)
|
|
1563 (face nil)
|
|
1564 (voice nil)
|
|
1565 (st nil))
|
|
1566 (setq st (point)
|
|
1567 hyperlink-info (list
|
|
1568 st
|
|
1569 (append
|
|
1570 (list 'link :args nil
|
|
1571 :value "" :tag ""
|
|
1572 :action 'w3-follow-hyperlink
|
|
1573 :from
|
|
1574 (set-marker (make-marker) st)
|
|
1575 :help-echo 'w3-widget-echo
|
|
1576 )
|
|
1577 (alist-to-plist args))))
|
|
1578 (w3-handle-content node)
|
|
1579 )
|
|
1580 )
|
82
|
1581 ((ol ul dl menu)
|
|
1582 (push 0 w3-display-list-stack)
|
|
1583 (w3-handle-content node))
|
|
1584 (dir
|
14
|
1585 (push 0 w3-display-list-stack)
|
82
|
1586 (setq node
|
|
1587 (list tag args
|
|
1588 (list
|
|
1589 (list 'table nil
|
|
1590 (w3-display-chop-into-table node 3)))))
|
|
1591 (w3-handle-content node))
|
|
1592 (multicol
|
|
1593 (setq node (list tag args
|
|
1594 (list
|
|
1595 (list 'table nil
|
|
1596 (w3-display-chop-into-table node 2)))))
|
14
|
1597 (w3-handle-content node))
|
|
1598 (img ; inlined image
|
|
1599 (w3-handle-image)
|
|
1600 (w3-handle-empty-tag))
|
|
1601 (script ; Scripts
|
|
1602 (w3-handle-empty-tag))
|
|
1603 ((embed object) ; Embedded images/content
|
|
1604 (w3-handle-content node)
|
|
1605 )
|
|
1606 (hr ; Cause line break & insert rule
|
|
1607 (let* ((perc (or (w3-get-attribute 'width)
|
|
1608 (w3-get-style-info 'width node)
|
|
1609 "100%"))
|
|
1610 (rule nil)
|
|
1611 (width nil))
|
|
1612 (setq perc (/ (min (string-to-int perc) 100) 100.0)
|
|
1613 width (* fill-column perc)
|
|
1614 rule (make-string (max (truncate width) 0)
|
|
1615 w3-horizontal-rule-char)
|
|
1616 node (list 'hr nil (list rule)))
|
|
1617 (w3-handle-content node)))
|
|
1618 (map ; Client side imagemaps
|
|
1619 (let ((name (or (w3-get-attribute 'name)
|
|
1620 (w3-get-attribute 'id)
|
|
1621 "unnamed"))
|
|
1622 (areas
|
|
1623 (mapcar
|
|
1624 (function
|
|
1625 (lambda (node)
|
|
1626 (let* ((args (nth 1 node))
|
|
1627 (type (downcase (or
|
|
1628 (w3-get-attribute 'shape)
|
|
1629 "rect")))
|
|
1630 (coords (w3-decode-area-coords
|
|
1631 (or (cdr-safe
|
|
1632 (assq 'coords args)) "")))
|
|
1633 (alt (w3-get-attribute 'alt))
|
|
1634 (href (if (assq 'nohref args)
|
|
1635 t
|
|
1636 (or (w3-get-attribute 'src)
|
|
1637 (w3-get-attribute 'href))))
|
|
1638 )
|
|
1639 (vector type coords href alt))
|
|
1640 )
|
|
1641 )
|
|
1642 (nth 2 node))))
|
|
1643 (setq w3-imagemaps (cons (cons name areas) w3-imagemaps)))
|
|
1644 (w3-handle-empty-tag)
|
|
1645 )
|
82
|
1646 (note
|
|
1647 ;; Ewwwwhhh. Looks gross, but it works. This converts a
|
|
1648 ;; <note> into a two-cell table, so that things look all
|
|
1649 ;; pretty.
|
|
1650 (setq node
|
|
1651 (list 'note nil
|
|
1652 (list
|
|
1653 (list 'table nil
|
|
1654 (list
|
|
1655 (list 'tr nil
|
|
1656 (list
|
|
1657 (list 'td (list 'align 'right)
|
|
1658 (list
|
|
1659 (concat
|
|
1660 (or (w3-get-attribute 'role)
|
|
1661 "CAUTION") ":")))
|
|
1662 (list 'td nil
|
|
1663 (nth 2 node)))))))))
|
|
1664 (w3-handle-content node)
|
|
1665 )
|
|
1666 (table
|
14
|
1667 (w3-display-table node)
|
|
1668 (setq w3-last-fill-pos (point))
|
|
1669 (w3-handle-empty-tag)
|
|
1670 )
|
|
1671 (isindex
|
|
1672 (let ((prompt (or (w3-get-attribute 'prompt)
|
|
1673 "Search on (+ separates keywords): "))
|
|
1674 action node)
|
|
1675 (setq action (or (w3-get-attribute 'src)
|
|
1676 (w3-get-attribute 'href)
|
|
1677 (url-view-url t)))
|
|
1678 (if (and prompt (string-match "[^: \t-]+$" prompt))
|
|
1679 (setq prompt (concat prompt ": ")))
|
|
1680 (setq node
|
|
1681 (list 'isindex nil
|
|
1682 (list
|
|
1683 (list 'hr nil nil)
|
|
1684 (list 'form
|
|
1685 (list (cons 'action action)
|
|
1686 (cons 'enctype
|
|
1687 "application/x-w3-isindex")
|
|
1688 (cons 'method "get"))
|
|
1689 (list
|
|
1690 prompt
|
|
1691 (list 'input
|
|
1692 (list (cons 'type "text")
|
|
1693 (cons 'name "isindex"))))))))
|
|
1694 (w3-handle-content node)
|
|
1695 (setq w3-current-isindex (cons action prompt)))
|
|
1696 )
|
|
1697 (*document
|
|
1698 (let ((info (mapcar (lambda (x) (cons x (symbol-value x)))
|
|
1699 w3-persistent-variables)))
|
82
|
1700 (if (not w3-display-same-buffer)
|
|
1701 (set-buffer (generate-new-buffer "Untitled")))
|
14
|
1702 (setq w3-current-form-number 0
|
|
1703 w3-display-open-element-stack nil
|
|
1704 w3-last-fill-pos (point-min)
|
|
1705 fill-column (min (- (or w3-strict-width (window-width))
|
|
1706 w3-right-margin)
|
|
1707 (or w3-maximum-line-length
|
|
1708 (window-width))))
|
|
1709 (switch-to-buffer (current-buffer))
|
|
1710 (buffer-disable-undo (current-buffer))
|
|
1711 (mapcar (function (lambda (x) (set (car x) (cdr x)))) info)
|
|
1712 ;; ACK! We don't like filladapt mode!
|
|
1713 (set (make-local-variable 'filladapt-mode) nil)
|
|
1714 (set (make-local-variable 'adaptive-fill-mode) nil)
|
82
|
1715 (set (make-local-variable 'voice-lock-mode) t)
|
14
|
1716 (setq w3-current-stylesheet (css-copy-stylesheet
|
|
1717 w3-user-stylesheet)
|
|
1718 w3-last-fill-pos (point)
|
|
1719 fill-column (min (- (or w3-strict-width (window-width))
|
|
1720 w3-right-margin)
|
|
1721 (or w3-maximum-line-length
|
|
1722 (window-width)))
|
|
1723 fill-prefix "")
|
|
1724 (set (make-local-variable 'inhibit-read-only) t))
|
|
1725 (w3-handle-content node)
|
|
1726 )
|
|
1727 (*invisible
|
|
1728 (w3-handle-empty-tag))
|
|
1729 (meta
|
|
1730 (let* ((equiv (cdr-safe (assq 'http-equiv args)))
|
|
1731 (value (w3-get-attribute 'content))
|
|
1732 (name (w3-get-attribute 'name))
|
|
1733 (node (and equiv (assoc (setq equiv (downcase equiv))
|
|
1734 url-current-mime-headers))))
|
|
1735 (if equiv
|
|
1736 (setq url-current-mime-headers (cons
|
|
1737 (cons equiv value)
|
|
1738 url-current-mime-headers)))
|
|
1739 (if name
|
|
1740 (setq w3-current-metainfo (cons
|
|
1741 (cons name value)
|
|
1742 w3-current-metainfo)))
|
|
1743
|
|
1744 ;; Special-case the Set-Cookie header
|
|
1745 (if (and equiv (string= (downcase equiv) "set-cookie"))
|
|
1746 (url-cookie-handle-set-cookie value))
|
|
1747 ;; Special-case the refresh header
|
|
1748 (if (and equiv (string= (downcase equiv) "refresh"))
|
|
1749 (url-handle-refresh-header value)))
|
|
1750 (w3-handle-empty-tag)
|
|
1751 )
|
|
1752 (link
|
|
1753 ;; This doesn't handle blank-separated values per the RFC.
|
|
1754 (w3-parse-link args)
|
|
1755 (w3-handle-empty-tag))
|
|
1756 (title
|
|
1757 (let ((potential-title "")
|
|
1758 (content (nth 2 node)))
|
|
1759 (while content
|
|
1760 (setq potential-title (concat potential-title (car content))
|
|
1761 content (cdr content)))
|
|
1762 (setq potential-title (w3-normalize-spaces potential-title))
|
82
|
1763 (if (or w3-display-same-buffer
|
|
1764 (string-match "^[ \t]*$" potential-title))
|
14
|
1765 nil
|
|
1766 (rename-buffer (generate-new-buffer-name
|
|
1767 (w3-fix-spaces potential-title)))))
|
|
1768 (w3-handle-empty-tag))
|
|
1769 (form
|
|
1770 (setq w3-current-form-number (1+ w3-current-form-number))
|
|
1771 (let* (
|
|
1772 (action (w3-get-attribute 'action))
|
|
1773 (url nil))
|
|
1774 (if (not action)
|
|
1775 (setq args (cons (cons 'action (url-view-url t)) args)))
|
82
|
1776 (setq w3-display-form-id (cons
|
|
1777 (cons 'form-number
|
|
1778 w3-current-form-number)
|
|
1779 args))
|
14
|
1780 (w3-handle-content node)))
|
82
|
1781 (keygen
|
|
1782 (w3-form-add-element 'keygen
|
|
1783 (or (w3-get-attribute 'name)
|
|
1784 (w3-get-attribute 'id)
|
|
1785 "keygen")
|
|
1786 nil ; value
|
|
1787 nil ; size
|
|
1788 nil ; maxlength
|
|
1789 nil ; default
|
|
1790 w3-display-form-id ; action
|
|
1791 nil ; options
|
|
1792 w3-current-form-number
|
|
1793 (w3-get-attribute 'id) ; id
|
|
1794 nil ; checked
|
|
1795 (car w3-active-faces)))
|
14
|
1796 (input
|
86
|
1797 (w3-form-add-element
|
|
1798 (w3-display-normalize-form-info args)
|
|
1799 (car w3-active-faces))
|
14
|
1800 (w3-handle-empty-tag)
|
|
1801 )
|
|
1802 (select
|
86
|
1803 (let* ((plist (w3-display-normalize-form-info args))
|
82
|
1804 (tmp nil)
|
|
1805 (multiple (assq 'multiple args))
|
86
|
1806 (value nil)
|
|
1807 (name (plist-get plist 'name))
|
|
1808 (options (mapcar
|
|
1809 (function
|
|
1810 (lambda (n)
|
|
1811 (setq tmp (w3-normalize-spaces
|
|
1812 (apply 'concat (nth 2 n)))
|
|
1813 tmp (cons tmp
|
|
1814 (or
|
|
1815 (cdr-safe
|
|
1816 (assq 'value (nth 1 n)))
|
|
1817 tmp)))
|
|
1818 (if (assq 'selected (nth 1 n))
|
|
1819 (setq value (car tmp)))
|
|
1820 tmp))
|
|
1821 (nth 2 node))))
|
82
|
1822 (if (not value)
|
|
1823 (setq value (caar options)))
|
86
|
1824 (setq plist (plist-put plist 'value value))
|
82
|
1825 (if multiple
|
|
1826 (progn
|
|
1827 (setq options
|
|
1828 (mapcar
|
|
1829 (function
|
|
1830 (lambda (opt)
|
|
1831 (list 'div nil
|
|
1832 (list
|
|
1833 (list 'input
|
|
1834 (list (cons 'name name)
|
|
1835 (cons 'type "checkbox")
|
|
1836 (cons 'value (car opt))))
|
|
1837 " " (car opt) (list 'br nil nil)))))
|
|
1838 options))
|
|
1839 (setq node (list 'p nil options))
|
|
1840 (w3-handle-content node))
|
86
|
1841 (setq plist (plist-put plist 'type 'option)
|
|
1842 plist (plist-put plist 'options options))
|
|
1843 (w3-form-add-element plist (car w3-active-faces))
|
14
|
1844 ;; This should really not be necessary, but some versions
|
|
1845 ;; of the widget library leave point _BEFORE_ the menu
|
|
1846 ;; widget instead of after.
|
|
1847 (goto-char (point-max))
|
82
|
1848 (w3-handle-empty-tag))))
|
14
|
1849 (textarea
|
86
|
1850 (let* ((plist (w3-display-normalize-form-info args))
|
82
|
1851 (value (w3-normalize-spaces
|
86
|
1852 (apply 'concat (nth 2 node)))))
|
|
1853 (setq plist (plist-put plist 'type 'multiline)
|
|
1854 plist (plist-put plist 'value value))
|
|
1855 (w3-form-add-element plist (car w3-active-faces)))
|
14
|
1856 (w3-handle-empty-tag)
|
|
1857 )
|
|
1858 (style
|
82
|
1859 (w3-handle-style (alist-to-plist
|
|
1860 (cons (cons 'data (apply 'concat (nth 2 node)))
|
|
1861 (nth 1 node))))
|
14
|
1862 (w3-handle-empty-tag))
|
|
1863 (otherwise
|
|
1864 ;; Generic formatting
|
|
1865 (w3-handle-content node))
|
|
1866 ) ; case tag
|
|
1867 ) ; stringp content
|
|
1868 ) ; while content
|
|
1869 ) ; while content-stack
|
|
1870 )
|
|
1871 )
|
|
1872
|
|
1873 (defun w3-draw-tree (tree)
|
|
1874 ;; The main entry point - wow complicated
|
|
1875 (setq w3-current-stylesheet w3-user-stylesheet)
|
|
1876 (while tree
|
|
1877 (w3-display-node (car tree))
|
|
1878 (setq tree (cdr tree)))
|
|
1879 (w3-display-fix-widgets)
|
|
1880 (w3-form-resurrect-widgets))
|
|
1881
|
|
1882 (defun time-display (&optional tree)
|
|
1883 ;; Return the # of seconds it took to draw 'tree'
|
|
1884 (let ((st (nth 1 (current-time)))
|
|
1885 (nd nil))
|
|
1886 (w3-draw-tree (or tree w3-last-parse-tree))
|
|
1887 (setq nd (nth 1 (current-time)))
|
|
1888 (- nd st)))
|
|
1889
|
|
1890
|
82
|
1891 (defsubst w3-finish-drawing ()
|
|
1892 (if (and (boundp 'w3-image-widgets-waiting) w3-image-widgets-waiting)
|
|
1893 (let (url glyph widget)
|
|
1894 (while w3-image-widgets-waiting
|
|
1895 (setq widget (car w3-image-widgets-waiting)
|
|
1896 w3-image-widgets-waiting (cdr w3-image-widgets-waiting)
|
|
1897 url (widget-get widget 'src)
|
|
1898 glyph (cdr-safe (assoc url w3-graphics-list)))
|
|
1899 (widget-value-set widget glyph)))
|
|
1900 ;;(w3-handle-annotations)
|
|
1901 ;;(w3-handle-headers)
|
|
1902 )
|
|
1903 )
|
|
1904
|
|
1905 (defun w3-region (st nd)
|
|
1906 (if (not w3-setup-done) (w3-do-setup))
|
|
1907 (let* ((source (buffer-substring st nd))
|
|
1908 (w3-display-same-buffer t)
|
|
1909 (parse nil))
|
|
1910 (save-excursion
|
|
1911 (set-buffer (get-buffer-create " *w3-region*"))
|
|
1912 (erase-buffer)
|
|
1913 (insert source)
|
|
1914 (setq parse (w3-parse-buffer (current-buffer))))
|
|
1915 (narrow-to-region st nd)
|
|
1916 (delete-region (point-min) (point-max))
|
|
1917 (w3-draw-tree parse)
|
|
1918 (w3-finish-drawing)))
|
|
1919
|
|
1920 (defun w3-refresh-buffer ()
|
|
1921 (interactive)
|
|
1922 (let ((parse w3-current-parse)
|
|
1923 (inhibit-read-only t)
|
|
1924 (w3-display-same-buffer t))
|
|
1925 (if (not parse)
|
|
1926 (error "Could not find the parse tree for this buffer. EEEEK!"))
|
|
1927 (erase-buffer)
|
|
1928 (w3-draw-tree parse)
|
|
1929 (w3-finish-drawing)
|
|
1930 (w3-mode)
|
|
1931 (set-buffer-modified-p nil)))
|
|
1932
|
14
|
1933 (defun w3-prepare-buffer (&rest args)
|
|
1934 ;; The text/html viewer - does all the drawing and displaying of the buffer
|
|
1935 ;; that is necessary to go from raw HTML to a good presentation.
|
|
1936 (let* ((source (buffer-string))
|
|
1937 (source-buf (current-buffer))
|
|
1938 (parse (w3-parse-buffer source-buf)))
|
|
1939 (set-buffer-modified-p nil)
|
|
1940 (w3-draw-tree parse)
|
|
1941 (kill-buffer source-buf)
|
|
1942 (set-buffer-modified-p nil)
|
|
1943 (setq w3-current-source source
|
|
1944 w3-current-parse parse)
|
82
|
1945 (w3-finish-drawing)
|
14
|
1946 (w3-mode)
|
|
1947 (set-buffer-modified-p nil)
|
|
1948 (goto-char (point-min))
|
|
1949 (if url-keep-history
|
|
1950 (let ((url (url-view-url t)))
|
|
1951 (if (not url-history-list)
|
|
1952 (setq url-history-list (make-hash-table :size 131 :test 'equal)))
|
|
1953 (cl-puthash url (buffer-name) url-history-list)
|
|
1954 (if (fboundp 'w3-shuffle-history-menu)
|
|
1955 (w3-shuffle-history-menu)))))
|
|
1956 )
|
|
1957
|
|
1958 (provide 'w3-display)
|