aboutsummaryrefslogtreecommitdiff
path: root/src/guile
diff options
context:
space:
mode:
authorLudovic Court`es2007-08-30 16:56:12 +0000
committerLudovic Court`es2007-08-30 16:56:12 +0000
commitd7b35e71841a78456c40e12dc0ef64b5f7a76980 (patch)
tree662529628ce3bbaa2c1743afbc2754640f826f24 /src/guile
parent30c8fb7c54f4586ded4e89ec653edf801268cc8e (diff)
parent57fa8c46016cf60acf6f7893a23829d85191ac19 (diff)
downloadskribilo-d7b35e71841a78456c40e12dc0ef64b5f7a76980.tar.gz
skribilo-d7b35e71841a78456c40e12dc0ef64b5f7a76980.tar.lz
skribilo-d7b35e71841a78456c40e12dc0ef64b5f7a76980.zip
lout: Added support for drop capitals.
* src/guile/skribilo/engine/lout.scm (lout-engine)[drop-capital?, drop-capital-lines]: New customs. (first-paragraph?, make-drop-capital?, output-with-drop-capital): New. (paragraph)[first-paragraph?]: Moved outside. Use an `:action' to support drop capitals. git-archimport-id: skribilo@sv.gnu.org--2006/skribilo--devo--1.2--patch-160
Diffstat (limited to 'src/guile')
-rw-r--r--src/guile/skribilo/engine/lout.scm87
1 files changed, 76 insertions, 11 deletions
diff --git a/src/guile/skribilo/engine/lout.scm b/src/guile/skribilo/engine/lout.scm
index d2a34e2..70d8f97 100644
--- a/src/guile/skribilo/engine/lout.scm
+++ b/src/guile/skribilo/engine/lout.scm
@@ -634,6 +634,15 @@
;; (e.g., the first paragraph of a chapter).
(first-paragraph-gap "\n@LP\n")
+ ;; A boolean or predicate indicating whether drop
+ ;; capitals should be used at the beginning of
+ ;; paragraphs.
+ (drop-capital? #f)
+
+ ;; Number of lines over which drop capitals span.
+ ;; Only 2 and 3 are currently supported.
+ (drop-capital-lines 2)
+
;; For multi-page tables, it may be
;; useful to set this to `#t'. However,
;; this looks kind of buggy.
@@ -1522,6 +1531,65 @@
;*---------------------------------------------------------------------*/
+;* support for paragraphs ... */
+;*---------------------------------------------------------------------*/
+
+(define (first-paragraph? n)
+ ;; Return true if N is the first paragraph in this container.
+ (let* ((parent (ast-parent n))
+ (siblings (markup-body parent)))
+ (and (pair? siblings)
+ (eq? n (find (lambda (n)
+ (is-markup? n 'paragraph))
+ siblings)))))
+
+(define (make-drop-capital? n e)
+ ;; Return true if the first letter of N's body should be output as a drop
+ ;; capital.
+ (let ((pred (engine-custom e 'drop-capital?)))
+ (cond ((procedure? pred)
+ (pred n e))
+ ((not pred)
+ #f)
+ (else
+ (and (is-markup? (ast-parent n) 'chapter)
+ (first-paragraph? n))))))
+
+(define (output-with-drop-capital n e)
+ ;; Assuming N is a paragraph, try producing a drop capital.
+
+ (define (drop-capital-function)
+ (let ((lines (engine-custom e 'drop-capital-lines)))
+ (if (integer? lines)
+ (case lines
+ ((3) "@DropCapThree")
+ (else "@DropCapTwo"))
+ "@DropCapTwo")))
+
+ (define (try)
+ (let loop ((body (markup-body n)))
+ (cond ((string? body)
+ (let ((body (string-trim body)))
+ (and (not (string=? body ""))
+ (begin
+ (display "{ ")
+ (output (string (string-ref body 0)) e)
+ (format #t " } ~a { " (drop-capital-function))
+ (output (string-drop body 1) e)
+ #t))))
+ ((pair? body)
+ (let ((did-it? (loop (car body))))
+ (output (cdr body) e)
+ did-it?))
+ (else
+ (output body e)
+ #f))))
+
+ (let ((did-it? (try)))
+ (if did-it?
+ (display " } "))))
+
+;*---------------------------------------------------------------------*/
;* paragraph ... */
;*---------------------------------------------------------------------*/
(markup-writer 'paragraph
@@ -1532,20 +1600,17 @@
(markup-markup (ast-parent n)))
'(chapter section subsection subsubsection slide))))
:before (lambda (n e)
- (define (first-paragraph?)
- ;; Return true if N is the first paragraph in this container.
- (let* ((parent (ast-parent n))
- (siblings (markup-body parent)))
- (and (pair? siblings)
- (eq? n (find (lambda (n)
- (is-markup? n 'paragraph))
- siblings)))))
-
- (let ((gap (if (first-paragraph?)
+ (let ((gap (if (first-paragraph? n)
(engine-custom e 'first-paragraph-gap)
(engine-custom e 'paragraph-gap))))
- (display (if (string? gap) gap "\n@PP\n")))))
+ (display (if (string? gap) gap "\n@PP\n"))))
+ :action (lambda (n e)
+ (if (make-drop-capital? n e)
+ (output-with-drop-capital n e)
+ (output (markup-body n) e))))
+
+
;*---------------------------------------------------------------------*/
;* footnote ... */
;*---------------------------------------------------------------------*/