;;; -*- mode: Lisp; Syntax: Common-Lisp; -*- ;;; ;;; Copyright (c) 2009 by the authors. ;;; ;;; See LICENCE for details. (in-package :hu.dwim.projectional-editor) ;;;;;;;; ;;;; Book domain provides: ;;;; - book ;;;; - chapter (def class* book/base () ()) (def class* book/book (book/base) ((title :type string) (authors :type sequence) (elements :type sequence))) (def class* book/chapter (book/base) ((title :type string) (elements :type sequence))) ;;;;;; ;;; Book document constructors (def (function e) make-book/book (title authors elements) (make-instance 'book/book :title title :authors authors :elements elements)) (def (function e) make-book/chapter (title elements) (make-instance 'book/chapter :title title :elements elements)) ;;;;;; ;;; Book provider (def special-variable *book-title-font* (sdl:initialise-font (make-instance 'sdl:ttf-font-definition :size 36 :filename (system-relative-pathname :hu.dwim.projectional-editor "etc/Ubuntu-B.ttf")))) (def special-variable *chapter-title-font* (sdl:initialise-font (make-instance 'sdl:ttf-font-definition :size 24 :filename (system-relative-pathname :hu.dwim.projectional-editor "etc/Ubuntu-B.ttf")))) (def special-variable *text-font* (sdl:initialise-font (make-instance 'sdl:ttf-font-definition :size 18 :filename (system-relative-pathname :hu.dwim.projectional-editor "etc/Ubuntu-R.ttf")))) (def (function e) book-color-provider (iomap reference) (map-backward iomap reference (lambda (iomap reference) (declare (ignore iomap)) (pattern-case reference ((the character (elt (the string (title-of (the book/book ?a))) ?b)) (return-from book-color-provider (sdl:color :r 196 :g 0 :b 0))) ((the character (elt (the string (title-of (the book/chapter ?a))) ?b)) (return-from book-color-provider (sdl:color :r 0 :g 0 :b 196))) ((the character (elt (the string (elt (the list (elements-of (the book/chapter ?a))) ?b)) ?c)) (return-from book-color-provider (sdl:color :r 0 :g 0 :b 0))))))) (def (function e) book-font-provider (iomap reference) (map-backward iomap reference (lambda (iomap reference) (declare (ignore iomap)) (pattern-case reference ((the character (elt (the string (title-of (the book/book ?a))) ?b)) (return-from book-font-provider *book-title-font*)) ((the character (elt (the string (title-of (the book/chapter ?a))) ?b)) (return-from book-font-provider *chapter-title-font*)) ((the character (elt (the string (elt (the list (elements-of (the book/chapter ?a))) ?b)) ?c)) (return-from book-font-provider *text-font*)))))) (def (function e) book-delimiter-provider (iomap reference) (map-backward iomap reference (lambda (iomap reference) (declare (ignore iomap)) (pattern-case reference ((the string (elt (the list (elements-of (the book/chapter ?a))) ?b)) (return-from book-delimiter-provider "")))))) (def (function e) book-separator-provider (iomap previous-child-reference next-child-reference) (declare (ignore next-child-reference)) (map-backward iomap previous-child-reference (lambda (iomap reference) (declare (ignore iomap)) (pattern-case reference ((the string (elt (the list (elements-of (the book/chapter ?a))) ?b)) (return-from book-separator-provider "")))))) (def (function e) book-indentation-provider (iomap previous-child-reference next-child-reference) (declare (ignore next-child-reference)) (map-backward iomap previous-child-reference (lambda (iomap reference) (declare (ignore iomap)) (pattern-case reference ;; new line after title ((the string (title-of (the (?or book/book book/chapter) ?a))) (return-from book-indentation-provider 1)) ;; new line after paragraph ((the ?a (elt (the list (elements-of (the book/chapter ?b))) ?c)) (return-from book-indentation-provider 1))))))