You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
typesetting/quad2/main.rkt

83 lines
2.8 KiB
Racket

3 years ago
#lang debug racket/base
(require "layout.rkt"
"render.rkt"
"quad.rkt"
3 years ago
"pipeline.rkt"
"linearize.rkt"
"layout.rkt"
"draw.rkt"
"struct.rkt"
"attr.rkt"
"font.rkt"
"constants.rkt"
"param.rkt"
racket/string
racket/match)
(define-pass (bootstrap-input x)
3 years ago
;; turn a simple string into a quad for testing layout.
#:pre string?
3 years ago
#:post quad?
(match x
3 years ago
[(or (? quad? q) (list (? quad? q))) q]
[(and (list (? quad?) ...) qs) (make-quad #:elems qs)]
[other (make-quad #:elems (list other))]))
(define-pass (split-into-single-char-quads qs)
3 years ago
;; break list of quads into single characters (keystrokes)
3 years ago
#:pre (list-of simple-quad?)
#:post (list-of simple-quad?)
(apply append
(for/list ([q (in-list qs)])
(match q
[(quad _ _ (list (? string? str)) _)
(for/list ([c (in-string str)])
(struct-copy quad q [elems (list (string c))]))]
[_ (list q)]))))
3 years ago
(define quad-compile
(make-pipeline (list
bootstrap-input
linearize-quad
3 years ago
;; attribute sanitizing =============
;; all attrs start out as symbol-string pairs.
;; we convert keys & values to corresponding higher-level types.
upgrade-attr-keys
downcase-attr-values
convert-boolean-attr-values
convert-numeric-attr-values
;; resolutions & parsings =============
resolve-font-paths
complete-attr-paths
;; TODO: resolve font sizes
;; we resolve dimension strings after font size
;; because they can be denoted relative to em size
parse-dimension-strings
;; TODO: parse feature strings
mark-text-runs
merge-adjacent-strings
split-whitespace
split-into-single-char-quads
;; TODO: missing glyphs
layout
make-drawing-insts
stackify)))
(define insts (parameterize ([current-wrap-width 13]
[current-attrs all-attrs]
[current-strict-attrs? #t]
[current-show-timing? #f]
[current-use-preconditions? #t]
[current-use-postconditions? #t])
(quad-compile "Hello this is the earth")))
3 years ago
(when (string? insts)
(render insts #:using text-renderer)
(render insts #:using drr-renderer)
#;(render-to-html drawing-insts)
#;(render-to-pdf drawing-insts))