;; $Id: dbsect.dsl 0.90 1997/08/18 12:38:27 nwalsh Exp $

;; ============================== SECTIONS ==============================

;; BRIDGEHEAD isn't a proper section, but appears to be a section title
(element BRIDGEHEAD ($lowtitle$ 2))

(define (SECTLEVEL)
  (if (have-ancestor? "SIMPLESECT")
      ;; SimpleSect is special, it should be level "n+1", where "n" is
      ;; the level of the numbered section that contains it.  If it is
      ;; the *first* sectioning element in a chapter, make it 
      ;; %default-simplesect-level%
      (cond
       ((have-ancestor? "SECT5") 6)
       ((have-ancestor? "SECT4") 5)
       ((have-ancestor? "SECT3") 4)
       ((have-ancestor? "SECT2") 3)
       ((have-ancestor? "SECT1") 2)
       (else %default-simplesect-level%))
      (cond
       ((have-ancestor? "SECT5") 5)
       ((have-ancestor? "SECT4") 4)
       ((have-ancestor? "SECT3") 3)
       ((have-ancestor? "SECT2") 2)
       ((have-ancestor? "SECT1") 1)
       ((have-ancestor? "REFERENCE") 1)
       (else 0)))) ;; 0 is the component (chapter/appendix) level

(define ($section$) ($block-container$))
(define ($sectitle$)
  (let* ((sect (parent (current-node)))
	 (renderas (inherited-attribute-string "renderas" sect))
	 (hlevel                         ;; the apparent section level;
	  (if renderas                  ;; if not real section level,
	      (string->number             ;;   then get the apparent level
	       (substring renderas 4 5)) ;;   from "renderas",
	      (SECTLEVEL)))               ;; else use the real level
	 (hs (HSIZE (- 4 hlevel)))
	 (label (element-label sect))
	 (nsep (gentext-label-title-sep (gi sect))))
    (make paragraph
      font-family-name: %title-font-family%
      font-weight:  (if (< hlevel 5) 'bold 'medium)
      font-posture: (if (< hlevel 5) 'upright 'italic)
      font-size: hs
      line-spacing: (* hs %line-spacing-factor%)
      space-before: (* hs %head-before-factor%)
      space-after: (* hs %head-after-factor%)
      start-indent:
      (if (< hlevel 3)
	  0pt
	  %body-start-indent%)
      first-line-start-indent: 0pt
      quadding: 'start
      keep-with-next?: #t
       ;; SimpleSects are never AUTO numbered...they aren't hierarchical
       (if (and (not (equal? label ""))
		(not (equal? (gi sect) "SIMPLESECT")))
	   (literal (string-append label nsep))
	   (empty-sosofo))
       (process-children-trim))))

(element SECT1 ($section$))
(element (SECT1 TITLE) ($sectitle$))
(element SECT2 ($section$))
(element (SECT2 TITLE) ($sectitle$))
(element SECT3 ($section$))
(element (SECT3 TITLE) ($sectitle$))
(element SECT4 ($section$))
(element (SECT4 TITLE) ($sectitle$))
(element SECT5 ($section$))
(element (SECT5 TITLE) ($sectitle$))

(element SIMPLESECT ($section$))
(element (SIMPLESECT TITLE) ($sectitle$))

