change font resolution rules

main
Matthew Butterick 5 years ago
parent b72467b97d
commit 3b178dfa5a

@ -1,8 +1,17 @@
#lang quadwriter/markdown
text
```
one
two
```
A _macro_ is a syntactic form with an associated _transformer_ that
_expands_ the original form into existing forms. To put it another way,
a macro is an extension to the Racket compiler. Most of the syntactic
forms of `racket/base` and `racket` are actually macros that expand into
a small set of core constructs.
Like many languages, Racket provides pattern-based macros that make
simple transformations easy to implement and reliable to use. Racket
also supports arbitrary macro transformers that are implemented in
Racket—or in a macro-extended variant of Racket.
This chapter provides an introduction to Racket macros, but see [_Fear
of Macros_](http://www.greghendershott.com/fear-of-macros/) for an
introduction from a different perspective.

@ -6,8 +6,8 @@
(provide (all-defined-out))
(define-runtime-path quadwriter-fonts-dir "fonts")
(define-runtime-path default-font-face "fonts/source-serif/SourceSerifPro-Regular.otf")
(define default-font-family "source-serif")
(define-runtime-path default-font-face "fonts/default/regular/SourceSerifPro-Regular.otf")
(define default-font-family "default-serif")
(define default-font-size 12)
(define default-line-height 16)
@ -26,6 +26,12 @@
;; though it also creates the potential for mischief,
;; if a font is named something that doesn't reflect its visual reality.
;; but we are not the font police.
;; rules for font naming
;; "fonts" subdirectory on top
;; family directories inside: each named with font family name
;; this makes it possible to give font families generic names (e.g., "body-text")
;; and change the font files without disturbing anything else.
(hash-clear! font-paths)
(define-values (dir path _) (split-path base-path))
(define doc-fonts-dir (build-path dir "fonts"))
@ -38,13 +44,14 @@
#:when (member (path-get-extension font-path) '(#".otf" #".ttf")))
(match-define (list font-path-string family-name)
(map (λ (x) (path->string (find-relative-path fonts-dir x))) (list font-path font-family-subdir)))
(define path-parts (map path->string (explode-path (string->path (string-downcase font-path-string)))))
(define key
(cons family-name
(match (string-downcase font-path-string)
[(and (regexp "bold") (regexp "it(alic)?")) 'bi]
[(regexp "bold") 'b]
[(regexp "it(alic)?") 'i]
[_ 'r])))
(cond
[(member "bold italic" path-parts) 'bi]
[(member "bold" path-parts) 'b]
[(member "italic" path-parts) 'i]
[else 'r])))
;; only set value if there's not one there already.
;; this means that we only use the first eligible font we find.
(hash-ref! font-paths key font-path)))

@ -17,6 +17,7 @@
(page-margin-left "120")
(page-margin-top "80")
(page-margin-bottom "120")
(font-family "default-serif")
(line-height "17")
#;(line-align-last "center")) attrs) exprs))
@ -31,7 +32,7 @@
(qexpr (append '((display "block")
(first-line-indent "0")
(background-color "#eee")
(font-family "fira-sans") (font-size "10") (line-height "14")
(font-family "default-sans") (font-size "10") (line-height "14")
(border-width-top "0.5") (border-color-top "gray") (border-inset-top "8")
(border-width-left "3") (border-color-left "gray") (border-inset-left "20")
(border-width-bottom "0.5") (border-color-bottom "gray") (border-inset-bottom "-2")
@ -57,7 +58,7 @@
(define-syntax-rule (attr-list . attrs) 'attrs)
(define (heading-base font-size attrs exprs)
(qexpr (append `((font-family "fira-sans-light") (first-line-indent "0") (display "block") (font-size ,(number->string font-size))(line-height ,(number->string (* 1.2 font-size))) (border-width-top "0.5")(border-inset-top "9") (inset-bottom "-3") (inset-top "6") (keep-with-next "true")) attrs) exprs))
(qexpr (append `((font-family "default-sans-light") (first-line-indent "0") (display "block") (font-size ,(number->string font-size))(line-height ,(number->string (* 1.2 font-size))) (border-width-top "0.5")(border-inset-top "9") (inset-bottom "-3") (inset-top "6") (keep-with-next "true")) attrs) exprs))
(define-tag-function (h1 attrs exprs)
(heading-base 20 (append '() attrs) exprs))
@ -70,7 +71,7 @@
(define h6 h3)
(define-tag-function (code attrs exprs)
(qexpr (append '((font-family "fira-mono")#;(line-align "right")(font-size "10")(bg "aliceblue")) attrs) exprs))
(qexpr (append '((font-family "default-mono")#;(line-align "right")(font-size "10")(bg "aliceblue")) attrs) exprs))
(define-tag-function (pre attrs exprs)
;; pre needs to convert white space to equivalent layout elements
@ -81,7 +82,7 @@
qexpr-line-break))
(qexpr (list* '(display "block") '(background-color "aliceblue")
'(first-line-indent "0")
'(font-family "fira-mono") '(font-size "11") '(line-height "14")
'(font-family "default-mono") '(font-size "11") '(line-height "14")
'(border-inset-top "10")
'(border-width-left "2") '(border-color-left "#669") '(border-inset-left "0")
'(border-inset-bottom "-4")

Loading…
Cancel
Save