From f1c598ebe9d6d505817d44ccd9a018e38248e55e Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Mon, 13 Dec 2004 20:00:08 +0000 Subject: [PATCH] * scm/output-gnome.scm (text): Hello world, again. * scm/output-svg.scm (named-glyph): New function. Hello world! * lily/modified-font-metric.cc (index_to_charcode): New method. * lily/font-metric.cc (ly:font-glyph-name-to-charcode): Use it in new function. (ly:font-glyph-to-index): Remove. --- ChangeLog | 9 ++- lily/font-metric.cc | 25 +-------- lily/include/modified-font-metric.hh | 1 + lily/modified-font-metric.cc | 6 ++ scm/lily-library.scm | 8 +++ scm/output-gnome.scm | 83 +++++++++++----------------- scm/output-svg.scm | 38 ++++--------- 7 files changed, 67 insertions(+), 103 deletions(-) diff --git a/ChangeLog b/ChangeLog index b339b7e0f4..989cd1c79f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,14 +1,17 @@ 2004-12-13 Jan Nieuwenhuizen + * scm/output-gnome.scm (text): Hello world, again. + + * scm/output-svg.scm (named-glyph): New function. Hello world! + + * lily/modified-font-metric.cc (index_to_charcode): New method. + * lily/include/font-metric.hh (index_to_charcode): New function. * lily/font-metric.cc (ly:font-glyph-name-to-charcode): Use it in new function. (ly:font-glyph-to-index): Remove. - * lily/font-metric.cc ("ly:font-glyph-name-to-charcode"): Bugfix: - use original font. - 2004-12-12 Han-Wen Nienhuys * lily/open-type-font.cc (make_index_to_charcode_map): new method. diff --git a/lily/font-metric.cc b/lily/font-metric.cc index bbb38dc91a..9686b7b54d 100644 --- a/lily/font-metric.cc +++ b/lily/font-metric.cc @@ -183,13 +183,7 @@ LY_DEFINE (ly_font_index_to_charcode, "ly:font-index-to-charcode", SCM_ASSERT_TYPE (fm, font, SCM_ARG1, __FUNCTION__, "font-metric"); SCM_ASSERT_TYPE (scm_is_integer (index), index, SCM_ARG2, __FUNCTION__, "index"); - unsigned charcode; - if (Modified_font_metric* mfm = dynamic_cast (fm)) - charcode = mfm->original_font ()->index_to_charcode (ly_scm2int (index)); - else - charcode = fm->index_to_charcode (ly_scm2int (index)); - - return scm_from_unsigned_integer (charcode); + return scm_from_unsigned_integer (fm->index_to_charcode (ly_scm2int (index))); } LY_DEFINE (ly_font_glyph_name_to_charcode, "ly:font-glyph-name-to-charcode", @@ -201,20 +195,10 @@ LY_DEFINE (ly_font_glyph_name_to_charcode, "ly:font-glyph-name-to-charcode", SCM_ASSERT_TYPE (fm, font, SCM_ARG1, __FUNCTION__, "font-metric"); SCM_ASSERT_TYPE (scm_is_string (name), name, SCM_ARG2, __FUNCTION__, "string"); #if 1 - unsigned charcode; - if (Modified_font_metric* mfm = dynamic_cast (fm)) - charcode = mfm->original_font ()->index_to_charcode (mfm->original_font ()->name_to_index (ly_scm2string (name))); - else - charcode = fm->index_to_charcode (fm->name_to_index (ly_scm2string (name))); + return scm_from_unsigned_integer (fm->index_to_charcode (fm->name_to_index (ly_scm2string (name)))); #else - unsigned charcode; - if (Modified_font_metric* mfm = dynamic_cast (fm)) - charcode = mfm->original_font ()->glyph_name_to_charcode (ly_scm2string (name)); - else - charcode = fm->glyph_name_to_charcode (ly_scm2string (name)); + return scm_from_unsigned_integer (fm->glyph_name_to_charcode (ly_scm2string (name))); #endif - - return scm_from_unsigned_integer (charcode); } LY_DEFINE (ly_text_dimension,"ly:text-dimension", @@ -259,7 +243,6 @@ LY_DEFINE (ly_font_name,"ly:font-name", SCM_ASSERT_TYPE (fm, font, SCM_ARG1, __FUNCTION__, "font-metric"); - if (Modified_font_metric* mfm = dynamic_cast (fm)) return ly_font_name (mfm->original_font ()->self_scm ()); else if (Adobe_font_metric* afm = dynamic_cast (fm)) @@ -267,8 +250,6 @@ LY_DEFINE (ly_font_name,"ly:font-name", return SCM_BOOL_F; } - - LY_DEFINE (ly_font_magnification,"ly:font-magnification", 1 , 0, 0, (SCM font), "Given the font metric @var{font}, return the " diff --git a/lily/include/modified-font-metric.hh b/lily/include/modified-font-metric.hh index 79ade2db86..277d61f894 100644 --- a/lily/include/modified-font-metric.hh +++ b/lily/include/modified-font-metric.hh @@ -23,6 +23,7 @@ public: virtual Offset get_indexed_wxwy (int) const; virtual Offset attachment_point (String) const; virtual int name_to_index (String) const; + virtual unsigned index_to_charcode (int) const; virtual String coding_scheme () const; virtual Font_metric *original_font () const; diff --git a/lily/modified-font-metric.cc b/lily/modified-font-metric.cc index f92b534ad4..bac7d43993 100644 --- a/lily/modified-font-metric.cc +++ b/lily/modified-font-metric.cc @@ -154,6 +154,12 @@ Modified_font_metric::name_to_index (String s) const return orig_->name_to_index (s); } +unsigned +Modified_font_metric::index_to_charcode (int i) const +{ + return orig_->index_to_charcode (i); +} + int Modified_font_metric::index_to_ascii (int k) const { diff --git a/scm/lily-library.scm b/scm/lily-library.scm index 5dafe99744..fa5e93d5c4 100644 --- a/scm/lily-library.scm +++ b/scm/lily-library.scm @@ -344,3 +344,11 @@ possibly turned off." (define-public (char->unicode-index font char) (ly:font-index-to-charcode font (char->integer char))) + +(define-public (otf-name-mangling font family) + ;; Hmm, family is bigcheese20/26? + (if (string=? (substring family 0 (min (string-length family) 9)) + "bigcheese") + "LilyPond" + family)) + diff --git a/scm/output-gnome.scm b/scm/output-gnome.scm index 92744346ca..e44781a6a2 100644 --- a/scm/output-gnome.scm +++ b/scm/output-gnome.scm @@ -18,12 +18,6 @@ ;;; - lilylib. ;;; * Release schedule and packaging of dependencies. This hack ;;; depends on several CVS and TLA development sources. In the works. -;;; * Maybe we need to have a unicode mapping somehow, we could -;;; - use OpenType instead of Type1 -;;; http://lists.gnu.org/archive/html/lilypond-devel/2004-05/msg00098.html -;;; - or fix the pangofc-afm-decoder and add it to Pango (no chance?) -;;; or have fontconfig read AFM files -;;; http://lists.gnu.org/archive/html/lilypond-devel/2004-05/msg00103.html ;;; You need: ;;; @@ -132,14 +126,10 @@ lilypond -fgnome input/simple-song.ly ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; globals -;; junkme -(define system-origin '(0 . 0)) - ;;; set by framework-gnome.scm (define canvas-root #f) (define output-scale #f) - ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; helper functions @@ -148,9 +138,15 @@ lilypond -fgnome input/simple-song.ly (force-output (current-error-port))) (define (debugf string . rest) - (if #t + (if #f (apply stderr (cons string rest)))) +(define (list->offsets accum coords) + (if (null? coords) + accum + (cons (cons (car coords) (cadr coords)) + (list->offsets accum (cddr coords))))) + (define (utf8 i) (cond ((< i #x80) (list (integer->char i))) @@ -177,6 +173,13 @@ lilypond -fgnome input/simple-song.ly string-append (map (lambda (x) (char->utf8-string font x)) (string->list string)))) +(define (music-font? font) + (let ((encoding (ly:font-encoding font)) + (family (font-family font))) + (or (memq encoding '(fetaMusic fetaBraces)) + (string=? (substring family 0 (min (string-length family) 9)) + "bigcheese")))) + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; stencil outputters ;;; @@ -270,7 +273,7 @@ lilypond -fgnome input/simple-song.ly bezier)) (define (char font i) - (text font (integer->char i))) + (text font (ly:font-index-to-charcode (integer->char i)))) ;; FIXME: naming (define (filledbox breapth width depth height) @@ -293,9 +296,7 @@ lilypond -fgnome input/simple-song.ly ;; FIXME ugly hack to skip #unspecified ... (if (and item (not (eq? item (if #f #f)))) (begin - (move item - (* output-scale (+ (car system-origin) x)) - (* output-scale (- (car system-origin) y))) + (move item (* output-scale x) (* output-scale (- y))) (affine-relative item output-scale 0 0 output-scale 0 0) item) #f))) @@ -318,16 +319,7 @@ lilypond -fgnome input/simple-song.ly (set-path-def props def) props)) -(define (list->offsets accum coords) - (if (null? coords) - accum - (cons (cons (car coords) (cadr coords)) - (list->offsets accum (cddr coords))))) - (define (named-glyph font name) - (debugf "glyph:~S\n" name) - (debugf "index:~S\n" (ly:font-glyph-name-to-charcode font name)) - (debugf "font:~S\n" (font-family font)) (text font (ly:font-glyph-name-to-charcode font name))) (define (polygon coords blotdiameter) @@ -362,21 +354,11 @@ lilypond -fgnome input/simple-song.ly #:join-style 'round))) (define (text font s) + (define (pango-font-name font) (stderr "FONT-NAME:~S:~S\n" (ly:font-name font) (ly:font-design-size font)) - - (let ((family (font-family font))) - ;; Hmm, family is bigcheese20? - (if (string=? (substring family 0 (min (string-length family) 9)) - "bigcheese") - (begin - ;; FIXME: FONT-NAME:#f:8.85678704856787 - ;;(format #f "~S, ~S" (ly:font-name font) (ly:font-design-size font)) - (stderr "BIGCHEESE\n") - "LilyPond 20" - ) - family))) - + (otf-name-mangling font (font-family font))) + (define (pango-font-size font) (let* ((designsize (ly:font-design-size font)) (magnification (* (ly:font-magnification font))) @@ -402,18 +384,15 @@ lilypond -fgnome input/simple-song.ly scaling)) - (let ((encoding (ly:font-encoding font))) - (make - #:parent (canvas-root) - ;; ugh, experimental placement corections - ;; #:x 0.0 #:y 0.0 - #:x 0.0 #:y (if (memq encoding '(fetaMusic fetaBraces)) 0.15 0.69) - #:anchor (if (memq encoding '(fetaMusic fetaBraces)) 'west 'south-west) - #:font (pango-font-name font) - #:size-points (pango-font-size font) - #:size-set #t - #:text (if (char? s) - (char->utf8-string font s) - (if (integer? s) - (integer->utf8-string font s) - (string->utf8-string font s)))))) + (make + #:parent (canvas-root) + ;; ugh, experimental placement corections + ;; #:x 0.0 #:y 0.0 + #:x 0.0 #:y (if (music-font? font) 0.15 0.69) + #:anchor (if (music-font? font) 'west 'south-west) + #:font (pango-font-name font) + #:size-points (pango-font-size font) + #:size-set #t + #:text (if (integer? s) + (integer->utf8-string font s) + (string->utf8-string font s)))) diff --git a/scm/output-svg.scm b/scm/output-svg.scm index 6b4cf35dcc..ab923e94a2 100644 --- a/scm/output-svg.scm +++ b/scm/output-svg.scm @@ -6,26 +6,6 @@ ;;;; http://www.w3.org/TR/SVG11 -;;; FIXME - -;;; * sodipodi gets confuseed by dashes in font names. -;;; -;;; removing feta-nummer*.pfa (LilyPond-feta-nummer), -;;; feta-braces*.pfa (LilyPond-feta-braces), feta-din*.pfa -;;; (LilyPond-feta-din) from font path shows feta fonts in sodipodi. -;;; -;;; * inkscape fails to map Feta fonts to private use area (PUA) E000 -;;; (sodipodi is fine). - -;;; * maybe we need to have a unicode mapping somehow, we could -;;; - use OpenType instead of Type1 -;;; http://lists.gnu.org/archive/html/lilypond-devel/2004-05/msg00098.html -;;; -;;; - or fix the pangofc-afm-decoder and add it to Pango (no chance?) -;;; or have fontconfig read AFM files -;;; http://lists.gnu.org/archive/html/lilypond-devel/2004-05/msg00103.html - - (debug-enable 'backtrace) (define-module (scm output-svg)) (define this-module (current-module)) @@ -47,7 +27,6 @@ (if #f (apply stderr (cons string rest)))) - (define (dispatch expr) (let ((keyword (car expr))) (cond @@ -115,8 +94,11 @@ (debugf "design:~S\n" designsize) scaling)) +(define (integer->entity integer) + (format #f "&#x~x;" integer)) + (define (char->entity font char) - (format #f "&#x~x;" (char->unicode-index font char))) + (integer->entity (char->unicode-index font char))) (define (string->entities font string) (apply string-append @@ -126,14 +108,12 @@ (let* ((encoding (ly:font-encoding font)) (anchor (if (memq encoding '(fetaMusic fetaBraces)) 'start 'start))) (format #f "font-family:~a;font-size:~a;text-anchor:~S;" - (font-family font) (font-size font) anchor))) + (otf-name-mangling font (font-family font)) + (font-size font) anchor))) (define (fontify font expr) (tagify "text" expr (cons 'style (svg-font font)))) -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - - ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; stencil outputters ;;; @@ -184,6 +164,12 @@ (define (filledbox breapth width depth height) (round-filled-box breapth width depth height 0)) +(define (named-glyph font name) + (dispatch + `(fontify ,font ,(tagify "tspan" + (integer->entity + (ly:font-glyph-name-to-charcode font name)))))) + (define (placebox x y expr) (tagify "g" ;; FIXME -- JCN -- 2.39.2