[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
scheme system stdout and markup predicates
From: |
Jan-Peter Voigt |
Subject: |
scheme system stdout and markup predicates |
Date: |
Tue, 23 Aug 2011 13:32:38 +0200 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.18) Gecko/20110617 Lightning/1.0b2 Thunderbird/3.1.11 |
Hello List,
I am using the scheme system command (on linux) to generate barcodes to
include in the PDF:
--snip--
\version "2.14.2"
% use barcode command to produce temporary eps and include it
#(define-markup-command (barcode layout props type str size
nums)(string-or-symbol? string? number-pair? boolean?)
(let ((width (car size))
(height (cdr size)))
; create temporary file name and empty stencil
(let ((tmp (format "~A-~2A.eps" (strftime "%Y%m%d%H%M%S"
(localtime (current-time))) (random 100)))
(barcode-stencil (interpret-markup layout props (markup
#:with-color red #:filled-box (cons 0 width) (cons 0 height) 0.7))))
; if str is a symbol like 'header:ismn get the property
(if (symbol? str)(let ((tmp (chain-assoc-get str props #f)))
(if tmp (set! str tmp))))
; execute command
(system (format "barcode ~A -e \"~A\" -g ~Ax~A+0+0 -o
\"~A\" -E -b \"~A\"" (if nums "" "-n") type (* 100 width) (* 100 height)
tmp str))
; create EPS stencil
(set! barcode-stencil (eps-file->stencil X (car size) tmp))
; remove temporary file
(system (format "rm -v \"~A\"" tmp))
barcode-stencil
)))
% define stencil cache, to produce it only once, when used several times
e.g. in footer markup
#(define-public (get-stencil symbol) #f)
#(define-public (put-stencil symbol stencil) #f)
#(define-public (rem-stencil symbol) #f)
#(let ((cache (list)))
(set! put-stencil (lambda (symbol stencil)
(set! cache (assoc-set! cache symbol stencil))
stencil))
(set! get-stencil (lambda (symbol)
(assoc-get symbol cache)))
(set! rem-stencil (lambda (symbol)
(set! cache (assoc-set! cache symbol #f))
empty-stencil))
)
#(define-markup-command (cache layout props sym text)(symbol? markup?)
(let ((stencil (get-stencil sym)))
(if (not stencil)
(set! stencil (interpret-markup layout props text)))
(put-stencil sym stencil)
stencil)
)
#(define-markup-command (cache-clear layout props sym)(symbol?)
(rem-stencil sym)
)
% include ISMN barcode
\markup \column {
\cache #'ismn \barcode #"EAN" #"979000000121" #'(30 . 8) ##t
\cache #'ismn \barcode #"EAN" #"979000000122" #'(35 . 8) ##t
\cache-clear #'ismn
\cache #'ismn \barcode #"EAN" #"979000000123" #'(40 . 8) ##t
}
--snip--
I have two questions:
To (system "...")
1: There are several commands, wich can write the generated EPS to
stdout. Is there a possibility to catch that and integrate it without
creating a temporary file?
2: Is there a way to get the result code and see if the command succeded?
Now have fun, playing around with (system "echo Hello World")!
Cheers,
Jan-Peter
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- scheme system stdout and markup predicates,
Jan-Peter Voigt <=