aboutsummaryrefslogtreecommitdiff
path: root/src/guile/skribilo/package/slide/base.scm
blob: 0686a7c168446fbb29347003754a9c704d3bdd9a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
;;; base.scm  --  Overhead transparencies, `base' engine.
;;;
;;; Copyright 2003, 2004  Manuel Serrano
;;; Copyright 2006  Ludovic Court�s <ludovic.courtes@laas.fr>
;;;
;;;
;;; This program is free software; you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 2 of the License, or
;;; (at your option) any later version.
;;;
;;; This program is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with this program; if not, write to the Free Software
;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
;;; USA.

(define-module (skribilo package slide base)
  :use-module (skribilo utils syntax)

  :use-module (skribilo package slide)
  :use-module (skribilo writer)
  :use-module (skribilo engine)
  :use-module (skribilo ast)
  :autoload   (skribilo output)        (output)
  :autoload   (skribilo package base)  (symbol color itemize item)

  :use-module (srfi srfi-1)

  :export (%slide-outline-title %slide-outline-itemize-symbols))

(fluid-set! current-reader %skribilo-module-reader)



;;;
;;; Simple markups.
;;;
(let ((be (lookup-engine-class 'base)))

   ;; slide-pause
   (markup-writer 'slide-pause be
      :action #f)
   ;; slide-vspace
   (markup-writer 'slide-vspace be
      :options '()
      :action #f)
   ;; slide-embed
   (markup-writer 'slide-embed be
      :options '(:alt :geometry-opt)
      :action (lambda (n e)
		 (output (markup-option n :alt) e)))
   ;; slide-record
   (markup-writer 'slide-record be
      :options '(:tag :play)
      :action (lambda (n e)
		 (output (markup-body n) e)))
   ;; slide-play
   (markup-writer 'slide-play be
      :options '(:tag :color)
      :action (lambda (n e)
		 (output (markup-option n :alt) e)))
   ;; slide-play*
   (markup-writer 'slide-play* be
      :options '(:tag :color :scolor)
      :action (lambda (n e)
		 (output (markup-option n :alt) e))))


;;;
;;; Helper functions for the default topic/subtopic handling.
;;;

(define (make-subtopic-list node recurse?-proc make-entry-proc
			    itemize-symbols)
  ;; Make a list of the subtopic of `node'.  Go recursive if `recurse?-proc'
  ;; returns true.  `make-entry-proc' is passed a node and returns an entry
  ;; (a markup) for this node.  `itemize-symbols' is a (circular) list
  ;; containing the symbols to be passed to `itemize'.
  (let* ((subtopic? (lambda (n)
                      (or (is-markup? n 'slide-subtopic)
                          (is-markup? n 'slide))))
         (subtopic-types (if (is-markup? node 'slide-topic)
                             '(slide-subtopic slide)
                             '(slide-topic))))
    (if (subtopic? node)
        '()
        (apply itemize
               `(,@(if (is-markup? (car itemize-symbols) 'symbol)
                       `(:symbol ,(car itemize-symbols))
                       '())
                 ,@(map (lambda (t)
                          (item
                           (make-entry-proc t)
                           (if (recurse?-proc t)
                               (make-subtopic-list t recurse?-proc
                                                   make-entry-proc
                                                   (cdr itemize-symbols))
                               '())))
                        (filter (lambda (n)
                                  (and (markup? n)
                                       (member (markup-markup n)
                                               subtopic-types)))
                                (markup-body node))))))))

(define (make-topic-list current-topic recurse? make-entry-proc)
  ;; Make a full topic list of the document which contains
  ;; `current-topic'.  Here, `make-entry-proc' takes a topic node and
  ;; the current topic node as its arguments.
  (let ((doc (ast-document current-topic)))
    (make-subtopic-list doc
                        (lambda (t)
                          (and recurse? (eq? t current-topic)))
                        (lambda (t)
                          (make-entry-proc t current-topic))
                        %slide-outline-itemize-symbols)))

(define (make-topic-entry topic current-topic)
  ;; Produce an entry for `topic'.  Colorize it based on the fact
  ;; that the current topic is `current-topic' (it may need to be
  ;; hightlighted).
  (let ((title (markup-option topic :title))
        (current? (eq? topic current-topic)))
    (color :fg (if current? "#000000" "#666666")
           (apply (if current? bold (lambda (x) x))
                  (list (markup-option topic :title))))))


;;;
;;; Default topic/subtopic handling.
;;;

;; Title for the automatically-generated outline slide.
(define %slide-outline-title "")

;; Circular list of symbols to be passed to `itemize' in outlines.
(define %slide-outline-itemize-symbols
  (let loop ((names '(#t "-" "bullet" "->" "middot")))
    (if (null? names)
	'()
	(cons (if (string? (car names))
		  (symbol (car names))
		  (car names))
	      (loop (cdr names))))))


(define (make-outline-slide topic engine)
  (let ((parent-topic (if (is-markup? topic 'slide-topic)
                          topic
                          (find1-up (lambda (n)
                                      (is-markup? n 'slide-topic))
                                    topic))))
    (output (slide :title %slide-outline-title :toc #f
                   :class (markup-class topic)
                   ;; The mark below is needed for cross-referencing by PDF
                   ;; bookmarks.
                   (if (markup-ident topic) (mark (markup-ident topic)) "")
                   (p (make-topic-list parent-topic #t
                                       make-topic-entry)))
            engine)))


(markup-writer 'slide-topic (lookup-engine-class 'base)
   :options '(:title :outline? :class :ident)
   :action (lambda (n e)
	      (if (markup-option n :outline?)
		  (make-outline-slide n e))

	      (output (markup-body n) e)))

(markup-writer 'slide-subtopic (lookup-engine-class 'base)
   ;; FIXME: Largely untested.
   :options '(:title :outline? :class :ident)
   :action (lambda (n e)
	      (if (markup-option n :outline?)
		  (make-outline-slide n e))

	      (output (markup-body n) e)))


;;; arch-tag: 1187ce0c-3ffc-4248-b68b-a7c77d6598b9