Refactor and re-use the font query mechanism from framework-ps.scm.
"%" "_" name)))
"m" (string-encode-integer (inexact->exact (round (* 1000 magnify)))))))
-(define (define-fonts paper)
- (define font-list (ly:paper-fonts paper))
-
- (define (define-font command fontname scaling)
- (string-append
- "/" command
- " { /" fontname
- " " (ly:number->string scaling) " output-scale div selectfont }"
- " bind def\n"))
-
- (define (font-load-command font)
- (let* ((specced-font-name (ly:font-name font))
- (fontname (if specced-font-name
- specced-font-name
- (ly:font-file-name font)))
- (command (ps-font-command font))
-
- ;; FIXME -- see (ps-font-command)
- (plain (ps-font-command font))
- (designsize (ly:font-design-size font))
- (magnification (* (ly:font-magnification font)))
- (ops (ly:output-def-lookup paper 'output-scale))
- (scaling (* ops magnification designsize)))
- (if (equal? fontname "unknown")
- (display (list font fontname)))
- (define-font plain fontname scaling)))
-
- (apply string-append
- (map (lambda (x) (font-load-command x))
- (filter (lambda (x) (not (ly:pango-font? x)))
- font-list))))
+(define (ps-define-font font font-name scaling)
+ (string-append
+ "/" (ps-font-command font)
+ " { /" font-name
+ " " (ly:number->string scaling) " output-scale div selectfont }"
+ " bind def\n"))
;; FIXME: duplicated in other output backends
;; FIXME: silly interface name
(define (setup-variables paper)
(string-append
"\n"
- (define-fonts paper)
+ (define-fonts paper ps-define-font)
(output-variables paper)))
(define (cff-font? font)
(define (svg-end)
(ec 'svg))
-(define (woff-header)
+(define (svg-define-font font font-name scaling)
+ (string-append
+ "@font-face {
+font-family: '"
+ font-name
+"';
+font-weight: normal;
+font-style: normal;
+src: url('"
+ (string-downcase font-name)
+ ".woff');
+}
+"))
+
+(define (woff-header paper)
"TODO:
- * dynamically add fonts based on usage
* add (ly:version) to font name
* copy woff font with version alongside svg output
"
(string-append
(eo 'defs)
(eo 'style '(text . "style/css"))
- " <![CDATA[
- @font-face {
- font-family: 'emmentaler-20';
- font-weight: normal;
- font-style: normal;
- src: url('emmentaler-20.woff');
- }
- ]]>
- "
+ "<![CDATA[
+"
+ (define-fonts paper svg-define-font)
+ "]]>
+"
(ec 'style)
(ec 'defs)))
-
+
(define (dump-page paper filename page page-number page-count)
(let* ((outputter (ly:make-paper-outputter (open-file filename "wb") 'svg))
(dump (lambda (str) (display str (ly:outputter-port outputter))))
(dump (svg-begin page-width page-height
0 0 device-width device-height))
(if (ly:get-option 'svg-woff)
- (dump (woff-header)))
+ (dump (woff-header paper)))
(dump (comment (format "Page: ~S/~S" page-number page-count)))
(ly:outputter-output-scheme outputter
`(begin (set! lily-unit-length ,unit-length)
(dump (svg-begin svg-width svg-height
left-x (- top-y) device-width device-height))
(if (ly:get-option svg-woff)
- (dump (woff-header)))
+ (dump (woff-header paper)))
(ly:outputter-output-scheme outputter
`(begin (set! lily-unit-length ,unit-length)
""))
;;
(define-public (laissez-vibrer::print grob)
(ly:tie::print grob))
+
+(define-public (define-fonts paper define-font)
+ "Return a string of all fonts used in PAPER, invoking the function
+DEFINE-FONT for procuding the actual font definition."
+
+ (define font-list (ly:paper-fonts paper))
+
+ (define (font-load-command font)
+ (let* ((font-name (ly:font-name font))
+ (designsize (ly:font-design-size font))
+ (magnification (* (ly:font-magnification font)))
+ (ops (ly:output-def-lookup paper 'output-scale))
+ (scaling (* ops magnification designsize)))
+ (if (equal? font-name "unknown")
+ (display (list font font-name)))
+ (define-font font font-name scaling)))
+
+ (apply string-append
+ (map (lambda (x) (font-load-command x))
+ (filter (lambda (x) (not (ly:pango-font? x)))
+ font-list))))
(make-regexp "^(<[a-z]+ transform=\")(scale.[-0-9. ]+,[-0-9. ]+.\" .*>)"))
(define pango-description-regexp-comma
- (make-regexp ",( Bold)?( Italic)?( Small-Caps)? ([0-9.]+)$"))
+ (make-regexp ",( Bold)?( Italic)?( Small-Caps)?[ -]([0-9.]+)$"))
(define pango-description-regexp-nocomma
- (make-regexp "( Bold)?( Italic)?( Small-Caps)? ([0-9.]+)$"))
+ (make-regexp "( Bold)?( Italic)?( Small-Caps)?[ -]([0-9.]+)$"))
(define (pango-description-to-text str expr)
(define alist '())
(cache-font font-file scaled-size glyph)
(ly:warning (_ "cannot find SVG font ~S") font-file))))
-(define embedded #f)
-
(define (woff-font-smob-to-text font expr)
(let* ((name-style (font-name-style font))
(scaled-size (modified-font-metric-font-scaling font))
(font-file (ly:find-file (string-append name-style ".woff")))
(charcode (ly:font-glyph-name-to-charcode font expr))
- (text (format #f "&#~S;" charcode)))
+ (char-lookup (format #f "&#~S;" charcode))
+ (glyph-by-name (eoc 'altglyph `(glyphname . ,expr)))
+ (apparently-broken
+ (comment "FIXME: how to select glyph by name, altglyph is broken?"))
+ (text (string-regexp-substitute "\n" ""
+ (string-append glyph-by-name apparently-broken char-lookup))))
(define alist '())
(define (set-attribute attr val)
(set! alist (assoc-set! alist attr val)))
path)
(define (woff-glyph-string font size cid glyphs)
- (named-glyph font glyphs))
+ (if (list? glyphs)
+ (named-glyph font (last (car glyphs)))
+ (named-glyph font glyphs)))
(define glyph-string
(if (not (ly:get-option 'svg-woff)) embedded-glyph-string woff-glyph-string))