]> git.donarmstrong.com Git - lilypond.git/commitdiff
* scm/lily.scm: Register sodipodi output module.
authorJan Nieuwenhuizen <janneke@gnu.org>
Mon, 14 Oct 2002 22:12:35 +0000 (22:12 +0000)
committerJan Nieuwenhuizen <janneke@gnu.org>
Mon, 14 Oct 2002 22:12:35 +0000 (22:12 +0000)
* 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
buildscripts/mf-to-table.py
lily/afm.cc
scm/lily.scm
scm/sodipodi.scm [new file with mode: 0644]

index 356346077e2d89d90f3f3b10a0674a3466cf8a6a..db068ee2b6ef2c401875efc6945dcf152b048176 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2002-10-14  Jan Nieuwenhuizen  <janneke@gnu.org>
+
+       * 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  <rune@zedeler.dk>
 
        * lily/rest.cc (after_line_breaking): bugfix: dots after half
index 4d325a4e33336e3f044fa8a401121dc029159ced..af1e1cb9440dbdb2818d3572db1d8977d86d1fb4 100644 (file)
@@ -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)
        
index 8c7e7b2e3f489613e5953750b869e4be6f6dfd2e..b20336967a0e75cdd069ab975d36333e9ecc0986 100644 (file)
@@ -6,6 +6,12 @@
   (c) 2000--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
   
  */
+
+#ifndef _GNU_SOURCE // we want memmem
+#define _GNU_SOURCE
+#endif
+#include <string.h>
+#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);
index 86243a87cfb22f4a454510278a8e4151f474ed5c..9980da2c38293af40a25e5e9f9cafc36a6452649 100644 (file)
@@ -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 (file)
index 0000000..a3e369d
--- /dev/null
@@ -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 <janneke@gnu.org>
+
+;;;; 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</" tag ">\n"))
+
+
+;; Interface functions
+
+(define (char i)
+  (tagify "tspan" (make-string 1 (integer->char i))))
+
+(define (end-output)
+  "</svg>")
+
+
+(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)
+"<?xml version='1.0' standalone='no'?>
+<!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 20010904//EN'
+'http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd'
+[
+ <!ATTLIST svg
+ xmlns:xlink CDATA #FIXED 'http://www.w3.org/1999/xlink'>
+]>
+<!-- Created with Sodipodi ('http://www.sodipodi.com/') -->
+<svg
+   id='svg1'
+   sodipodi:version='0.26'
+   xmlns='http://www.w3.org/2000/svg'
+   xmlns:sodipodi='http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd'
+   xmlns:xlink='http://www.w3.org/1999/xlink'
+   width='210mm'
+   height='297mm'
+   sodipodi:docbase='/tmp/'
+   sodipodi:docname='/tmp/x'>
+  <defs
+     id='defs3' />
+  <sodipodi:namedview
+     id='base' />")
+
+
+(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)))
+                                           ")"))))
+