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/pitfall/pitfall/core.rkt

42 lines
1.1 KiB
Racket

6 years ago
#lang racket/base
6 years ago
(require racket/match racket/port)
6 years ago
(provide (all-defined-out))
;; structs
(struct String (string) #:transparent)
;; for JPEG and PNG
(struct image (label width height obj) #:transparent #:mutable)
6 years ago
;; for page
(struct margin (top left bottom right) #:transparent #:mutable)
6 years ago
;; params
(define test-mode (make-parameter #f))
(define current-compress-streams? (make-parameter #f))
(define current-pdf-version (make-parameter 1.3))
(define current-auto-first-page (make-parameter #t))
6 years ago
(define current-default-margins (make-parameter (margin 72 72 72 72)))
6 years ago
;; helpers
(define (numberizer x #:round [round? #true])
(unless (and (number? x) (< -1e21 x 1e21))
(raise-argument-error 'number "valid number" x))
(let ([x (if round? (/ (round (* x 1e6)) 1e6) x)])
(number->string (if (integer? x)
(inexact->exact x)
6 years ago
x))))
(define (to-bytes x)
(match x
[(? bytes?) x]
[(? input-port?) (port->bytes x)]
[_ (string->bytes/latin-1 (string-append x "\n"))]))
(define (write-bytes-out x)
(void (write-bytes (to-bytes x))))