From b2023e711e576d58da3c51a4b3fd5d327a0fe013 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Mon, 14 Oct 2002 22:12:35 +0000 Subject: [PATCH] * scm/lily.scm: Register sodipodi output module. * scm/sodipodi.scm: New file. * lily/afm.cc (read_afm_file): Read TfmCheckSum from comment. * buildscripts/mf-to-table.py (base): Write TfmChecksum in comment, after header. (parse_logfile): Remove invalid key FontFamily. Add mandatory key FullName. Fix FontName key. --- ChangeLog | 13 +++ buildscripts/mf-to-table.py | 31 ++++--- lily/afm.cc | 39 ++++++--- scm/lily.scm | 4 +- scm/sodipodi.scm | 163 ++++++++++++++++++++++++++++++++++++ 5 files changed, 226 insertions(+), 24 deletions(-) create mode 100644 scm/sodipodi.scm diff --git a/ChangeLog b/ChangeLog index 356346077e..db068ee2b6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2002-10-14 Jan Nieuwenhuizen + + * scm/lily.scm: Register sodipodi output module. + + * scm/sodipodi.scm: New file. + + * lily/afm.cc (read_afm_file): Read TfmCheckSum from comment. + + * buildscripts/mf-to-table.py (base): Write TfmChecksum in + comment, after header. + (parse_logfile): Remove invalid key FontFamily. Add mandatory key + FullName. Fix FontName key. + 2002-10-14 Rune Zedeler * lily/rest.cc (after_line_breaking): bugfix: dots after half diff --git a/buildscripts/mf-to-table.py b/buildscripts/mf-to-table.py index 4d325a4e33..af1e1cb944 100644 --- a/buildscripts/mf-to-table.py +++ b/buildscripts/mf-to-table.py @@ -56,7 +56,9 @@ def tfm_checksum (fn): shift = shift - 8 return cs - + +## ugh. What's font_family supposed to be? It's not an afm thing. +font_family = 'feta' def parse_logfile (fn): (autolines, deps) = read_log_file (fn) charmetrics = [] @@ -80,8 +82,10 @@ def parse_logfile (fn): } charmetrics.append (m) elif tags[0] == 'font': - global_info['FontName'] = string.join (tags[1:]) - global_info['FontFamily']=tags[1] + global font_family + font_family = (tags[1]) + global_info['FontName'] = string.join (tags[1:],'') + global_info['FullName'] = string.join (tags[1:],'') global_info['FontBBox'] = '0 0 1000 1000' global_info['Ascender'] = '0' global_info['Descender'] = '0' @@ -103,12 +107,12 @@ def write_afm_char_metric(file, charmetric): file.write ('C %d ; WX %d ; N %s ; B %d %d %d %d ;\n'% tup) - + +def write_afm_header (file): + file.write ("StartFontMetrics 2.0\n") + file.write ("Comment Automatically generated by mf-to-table.py\n") + def write_afm_metric (file, global_info, charmetrics): - file.write (r""" -StartFontMetrics 2.0 -Comment Automatically generated by mf-to-table.py -""") for (k,v) in global_info.items(): file.write ("%s %s\n" % (k,v)) file.write ('StartCharMetrics %d\n' % len(charmetrics )) @@ -119,7 +123,8 @@ Comment Automatically generated by mf-to-table.py def write_tex_defs (file, global_info, charmetrics): - nm = global_info['FontFamily'] + ##nm = global_info['FontFamily'] + nm = font_family for m in charmetrics: file.write (r'''\def\%s%s{\char%d}%%%s''' % (nm, m['tex'], m['code'],'\n')) file.write ('\\endinput\n') @@ -135,7 +140,8 @@ def write_ps_encoding (file, global_info, charmetrics): file.write ('] def\n') def write_fontlist (file, global_info, charmetrics): - nm = global_info['FontFamily'] + ##nm = global_info['FontFamily'] + nm = font_family file.write (r""" % Lilypond file to list all font symbols and the corresponding names % Automatically generated by mf-to-table.py @@ -233,9 +239,10 @@ for filenm in files: cs = tfm_checksum (re.sub ('.log$', '.tfm', filenm)) afm = open (afmfile_nm, 'w') - afm.write ("TfmCheckSum %u\n" % cs) + write_afm_header (afm) + afm.write ("Comment TfmCheckSum %u\n" % cs) + write_afm_metric (afm, g, m) - write_afm_metric (afm, g,m) write_tex_defs (open (texfile_nm, 'w'), g, m) write_ps_encoding (open (enc_nm, 'w'), g, m) diff --git a/lily/afm.cc b/lily/afm.cc index 8c7e7b2e3f..b20336967a 100644 --- a/lily/afm.cc +++ b/lily/afm.cc @@ -6,6 +6,12 @@ (c) 2000--2002 Han-Wen Nienhuys */ + +#ifndef _GNU_SOURCE // we want memmem +#define _GNU_SOURCE +#endif +#include +#include "libc-extension.hh" #include "afm.hh" #include "warn.hh" #include "molecule.hh" @@ -103,19 +109,30 @@ read_afm_file (String nm) { FILE *f = fopen (nm.to_str0 () , "r"); char s[2048]; - char *check_key = "TfmCheckSum"; - fgets (s, sizeof (s), f); - - unsigned int cs = 0; - if (strncmp (s, check_key, strlen (check_key)) == 0) - { - sscanf (s + strlen (check_key), "%ud", &cs); - } - else + char *check_key = "Comment TfmCheckSum"; + + unsigned int cs = 0; + +#if 0 + fread (s, sizeof (s), sizeof (*s), f); + if (char const* p = (char const *) + memmem (s, sizeof (s), check_key, strlen (check_key))) + sscanf (p + strlen (check_key), "%ud", &cs); +#else + s[0] = 0; + /* Assume check_key in first 10 lines */ + for (int i = 0; i < 10; i++) { - rewind (f); + fgets (s, sizeof (s), f); + if (strncmp (s, check_key, strlen (check_key)) == 0) + { + sscanf (s + strlen (check_key), "%ud", &cs); + break; + } } - +#endif + + rewind (f); AFM_Font_info * fi; int ok = AFM_parseFile (f, &fi, ~1); diff --git a/scm/lily.scm b/scm/lily.scm index 86243a87cf..9980da2c38 100644 --- a/scm/lily.scm +++ b/scm/lily.scm @@ -179,6 +179,7 @@ is the first to satisfy CRIT (scm pysk) (scm ascii-script) (scm sketch) + (scm sodipodi) (scm pdftex) ) @@ -188,7 +189,8 @@ is the first to satisfy CRIT ("ps" . ("Direct postscript. Requires setting GS_LIB and GS_FONTPATH" ,ps-output-expression)) ("scm" . ("Scheme dump: debug scheme molecule expressions" ,write)) ("as" . ("Asci-script. Postprocess with as2txt to get ascii art" ,as-output-expression)) - ("sketch" . ("Bare bones Sketch output. Requires sketch 0.7" ,sketch-output-expression)) + ("sketch" . ("Bare bones Sketch output." ,sketch-output-expression)) + ("sodipodi" . ("Bare bones Sodipodi output." ,sodipodi-output-expression)) ("pdftex" . ("PDFTeX output. Was last seen nonfunctioning." ,pdftex-output-expression)) )) diff --git a/scm/sodipodi.scm b/scm/sodipodi.scm new file mode 100644 index 0000000000..a3e369dd50 --- /dev/null +++ b/scm/sodipodi.scm @@ -0,0 +1,163 @@ +;;;; sodipodi.scm -- implement Scheme output routines for PostScript +;;;; +;;;; source file of the GNU LilyPond music typesetter +;;;; +;;;; (c) 1998--2002 Jan Nieuwenhuizen + +;;;; NOTE that Sodipodi +;;;; +;;;; * dumps core on displaying feta characters +;;;; * needs PFBs (ie, not PFAs like sketch) +;;;; * must have (LilyPond/feta) fonts registered through GNOME's +;;;; gnome-font-install (ie, not through X11, like sketch and xfontsel), +;;;; which in turn is very picky about afm files +;;;; * has it's own svg-like language: possibly this file should be +;;;; moved to svg.scm + + +(debug-enable 'backtrace) + + +(define-module (scm sodipodi)) +(define this-module (current-module)) + +(use-modules + (guile) + (lily)) + + + + +;;; Lily output interface --- cleanup and docme + +;;; Bare minimum interface for \score { \notes c } } +;;; should implement: +;;; +;;; xx-output-expression +;;; char +;;; filledbox +;;; placebox + +;;; and should intercept: +;;; +;;; fontify +;;; lily-def +;;; header-end +;;; define-fonts +;;; no-origin +;;; start-system +;;; end-output +;;; header +;;; comment +;;; stop-last-system + + + +;; Module entry +;;(define-public (sodipodi-output-expression expr port) +;; (display (eval expr this-module) port)) + +(define-public (sodipodi-output-expression expr port) + (display (dispatch expr) port)) + + +(define (dispatch expr) + (let ((keyword (car expr))) + (cond + ((eq? keyword 'some-func) "") + ;;((eq? keyword 'placebox) (dispatch (cadddr expr))) + ;;((eq? keyword 'fontify) (dispatch (caddr expr))) + (else + (if (module-defined? this-module keyword) + (apply (eval keyword this-module) (cdr expr)) + (begin + (display + (string-append "undefined: " (symbol->string keyword) "\n")) + "")))))) + + +;; Global vars + +;; alist containing fontname -> fontcommand assoc (both strings) +;;(define font-name-alist '()) + +;; Helper functions +(define (tagify tag string . attribute-alist) + (string-append + "<" tag + (apply string-append (map (lambda (x) (string-append + " " + (symbol->string (car x)) + "='" + (cdr x) + "'")) + attribute-alist)) + ">\n" + string "\n\n")) + + +;; Interface functions + +(define (char i) + (tagify "tspan" (make-string 1 (integer->char i)))) + +(define (end-output) + "") + + +(define (filledbox breapth width depth height) + (tagify "rect" "" + + '(style . "fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-opacity:1;stroke-width:1pt;stroke-linejoin:miter;stroke-linecap:butt;") +;; `(x . "50.0") +;; `(y . "400.0") + `(x . ,(number->string (* 5.5 breapth))) + `(y . ,(number->string (* 5.5 (- 0 depth)))) + `(width . ,(number->string (* 5.5 (+ breapth width)))) + `(height . ,(number->string (* 5.5 (+ depth height)))))) + + +(define (fontify name-mag-pair expr) +;; (dispatch expr)) +;; (tagify "text" (dispatch expr) '(style . "font-family:LilyPond;font-style:feta20;font-size:200;"))) +;; (tagify "text" (dispatch expr) '(style . "fill:black;stroke:none;font-family:feta20;font-style:normal;font-weight:normal;font-size:200;fill-opacity:1;stroke-opacity:1;stroke-width:1pt;stroke-linejoin:miter;stroke-linecap:butt;text-anchor:start;writing-mode:lr;")) + (tagify "text" (dispatch expr) '(style . "fill:black;stroke:none;font-family:futa20;font-style:normal;font-weight:normal;font-size:20;fill-opacity:1;stroke-opacity:1;stroke-width:1pt;stroke-linejoin:miter;stroke-linecap:butt;text-anchor:start;writing-mode:lr;")) + + ) + + +(define (header creator generate) +" + +]> + + + + ") + + +(define (placebox x y expr) +;; (dispatch expr)) + (tagify "g" (dispatch expr) `(transform . + ,(string-append + "translate(" (number->string + (* 5.5 x)) + "," + (number->string (- 700 (* 5.5 y))) + ")")))) + -- 2.39.5