From 6b0735b7dd1f80bd129868da9de8c7fde0f121a2 Mon Sep 17 00:00:00 2001 From: janneke Date: Tue, 16 Nov 2004 22:45:49 +0000 Subject: [PATCH] * scm/lily-library.scm (char->unicode-index): New function. * scm/output-gnome.scm: * scm/output-svg.scm: Cleanup. Map custom fonts to PUA. * lily/modified-font-metric.cc ("ly:font-encoding"): New function. * lily/pangofc-afm-decoder.cc (pango_fc_afm_get_glyph): Map onto PUA. --- ChangeLog | 13 ++++ lily/all-font-metrics.cc | 40 +++++------ lily/binary-source-file.cc | 4 +- lily/font-metric.cc | 2 +- lily/includable-lexer.cc | 4 +- lily/include/binary-source-file.hh | 2 +- lily/include/font-metric.hh | 2 +- lily/include/includable-lexer.hh | 2 +- lily/include/midi-stream.hh | 4 +- lily/include/paper-outputter.hh | 2 +- lily/include/source.hh | 2 +- lily/include/stream.hh | 4 +- lily/include/tfm.hh | 2 +- lily/input-smob.cc | 2 +- lily/kpath.cc | 26 ++++---- lily/midi-stream.cc | 6 +- lily/modified-font-metric.cc | 48 ++++++++------ lily/pangofc-afm-decoder.cc | 66 +++---------------- lily/paper-outputter.cc | 8 +-- lily/score.cc | 2 +- lily/tfm.cc | 4 +- scm/encoding.scm | 16 ++--- scm/font.scm | 2 +- scm/framework-gnome.scm | 2 - scm/framework-ps.scm | 10 +-- scm/framework-tex.scm | 4 +- scm/lily-library.scm | 16 +++++ scm/output-gnome.scm | 72 +++++++------------- scm/output-svg.scm | 102 ++++++++--------------------- scm/safe-lily.scm | 2 +- 30 files changed, 195 insertions(+), 276 deletions(-) diff --git a/ChangeLog b/ChangeLog index f791c80b3e..dc56e53209 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2004-11-16 Jan Nieuwenhuizen + + * scm/lily-library.scm (char->unicode-index): New function. + + * scm/output-gnome.scm: + * scm/output-svg.scm: Cleanup. Map custom fonts to PUA. + + * Proper naming of file name throughout; s/filename/file[-_]name/. + + * lily/modified-font-metric.cc ("ly:font-encoding"): New function. + + * lily/pangofc-afm-decoder.cc (pango_fc_afm_get_glyph): Map onto PUA. + 2004-11-16 Werner Lemberg * scripts/lilypond-book.py: The Lord has commanded me to use only diff --git a/lily/all-font-metrics.cc b/lily/all-font-metrics.cc index 04afa13be6..05a952e81b 100644 --- a/lily/all-font-metrics.cc +++ b/lily/all-font-metrics.cc @@ -49,25 +49,25 @@ All_font_metrics::find_afm (String name) SCM val; if (!afm_p_dict_->try_retrieve (sname, &val)) { - String filename; + String file_name; - if (filename.is_empty ()) - filename = search_path_.find (name + ".afm"); + if (file_name.is_empty ()) + file_name = search_path_.find (name + ".afm"); - if (filename.is_empty ()) + if (file_name.is_empty ()) { String p = kpathsea_find_afm (name.to_str0 ()); if (p.length ()) - filename = p; + file_name = p; } - if (filename.is_empty ()) + if (file_name.is_empty ()) return 0; if (verbose_global_b) - progress_indication ("[" + filename); - val = read_afm_file (filename); - unsmob_metrics (val)->filename_ = filename; + progress_indication ("[" + file_name); + val = read_afm_file (file_name); + unsmob_metrics (val)->file_name_ = file_name; unsmob_metrics (val)->description_ = scm_cons (name_string, scm_make_real (1.0)); @@ -93,9 +93,9 @@ All_font_metrics::find_afm (String name) { // FIXME: broken sentence String s = _f ("checksum mismatch for font file: `%s'", - filename.to_str0 ()); + file_name.to_str0 ()); s += " " + _f ("does not match: `%s'", - tfm->filename_.to_str0 ()); + tfm->file_name_.to_str0 ()); s += "\n"; s += " TFM: " + to_string ((int) tfm->info_.checksum); s += " AFM: " + to_string ((int) afm->checksum_); @@ -124,29 +124,29 @@ All_font_metrics::find_tfm (String name) SCM val; if (!tfm_p_dict_->try_retrieve (sname, &val)) { - String filename; + String file_name; - if (filename.is_empty ()) + if (file_name.is_empty ()) { String p = kpathsea_find_tfm (name.to_str0 ()); if (p.length ()) - filename = p; + file_name = p; } - if (filename.is_empty ()) - filename = search_path_.find (name + ".tfm"); - if (filename.is_empty ()) + if (file_name.is_empty ()) + file_name = search_path_.find (name + ".tfm"); + if (file_name.is_empty ()) return 0; if (verbose_global_b) - progress_indication ("[" + filename); + progress_indication ("[" + file_name); - val = Tex_font_metric::make_tfm (filename); + val = Tex_font_metric::make_tfm (file_name); if (verbose_global_b) progress_indication ("]"); - unsmob_metrics (val)->filename_ = filename; + unsmob_metrics (val)->file_name_ = file_name; unsmob_metrics (val)->description_ = scm_cons (name_string, scm_make_real (1.0)); tfm_p_dict_->set (sname, val); diff --git a/lily/binary-source-file.cc b/lily/binary-source-file.cc index 1eceb65b8a..5d6568f4f9 100644 --- a/lily/binary-source-file.cc +++ b/lily/binary-source-file.cc @@ -16,8 +16,8 @@ #include "binary-source-file.hh" #include "string-convert.hh" -Binary_source_file::Binary_source_file (String& filename_string) - : Source_file (filename_string) +Binary_source_file::Binary_source_file (String& file_name_string) + : Source_file (file_name_string) { } diff --git a/lily/font-metric.cc b/lily/font-metric.cc index 38a1b38969..b47d50b775 100644 --- a/lily/font-metric.cc +++ b/lily/font-metric.cc @@ -178,7 +178,7 @@ LY_DEFINE (ly_text_dimension,"ly:text-dimension", return scm_cons (ly_interval2scm (b[X_AXIS]), ly_interval2scm (b[Y_AXIS])); } -LY_DEFINE (ly_font_filename,"ly:font-filename", +LY_DEFINE (ly_font_file_name,"ly:font-file-name", 1, 0, 0, (SCM font), "Given the font metric @var{font}, " diff --git a/lily/includable-lexer.cc b/lily/includable-lexer.cc index ff48f271aa..195702bf24 100644 --- a/lily/includable-lexer.cc +++ b/lily/includable-lexer.cc @@ -62,7 +62,7 @@ Includable_lexer::new_input (String name, Sources *sources) LexerError (msg.to_str0 ()); return; } - filename_strings_.push (file->name_string ()); + file_name_strings_.push (file->name_string ()); char_count_stack_.push (0); if (yy_current_buffer) @@ -85,7 +85,7 @@ Includable_lexer::new_input (String name, String data, Sources *sources) { Source_file *file = new Source_file (name, data); sources->add (file); - filename_strings_.push (name); + file_name_strings_.push (name); char_count_stack_.push (0); if (yy_current_buffer) diff --git a/lily/include/binary-source-file.hh b/lily/include/binary-source-file.hh index a48ad8c124..5689a80abd 100644 --- a/lily/include/binary-source-file.hh +++ b/lily/include/binary-source-file.hh @@ -11,7 +11,7 @@ class Binary_source_file : public Source_file { public: - Binary_source_file (String& filename_string ); + Binary_source_file (String& file_name_string ); virtual ~Binary_source_file (); U8 get_U8 (); diff --git a/lily/include/font-metric.hh b/lily/include/font-metric.hh index 769a16095a..d6236e042a 100644 --- a/lily/include/font-metric.hh +++ b/lily/include/font-metric.hh @@ -20,7 +20,7 @@ struct Font_metric { public: SCM description_; - String filename_; + String file_name_; virtual int count () const; virtual Offset get_indexed_wxwy (int) const; diff --git a/lily/include/includable-lexer.hh b/lily/include/includable-lexer.hh index ab4f520ac1..fef7ca0ae6 100644 --- a/lily/include/includable-lexer.hh +++ b/lily/include/includable-lexer.hh @@ -40,7 +40,7 @@ public: ~Includable_lexer (); /// store dependencies for Makefile stuff. - Array filename_strings_; + Array file_name_strings_; Source_file* get_source_file () const; void new_input (String s, Sources*); diff --git a/lily/include/midi-stream.hh b/lily/include/midi-stream.hh index 4af7ea9aa9..2622027d6d 100644 --- a/lily/include/midi-stream.hh +++ b/lily/include/midi-stream.hh @@ -12,7 +12,7 @@ /// Midi outputfile struct Midi_stream { - Midi_stream (String filename_string); + Midi_stream (String file_name_string); ~Midi_stream (); Midi_stream& operator << ( String str); @@ -22,7 +22,7 @@ struct Midi_stream { void open (); FILE *out_file_; - String filename_string_; + String file_name_string_; }; #endif // MIDI_STREAM_HH diff --git a/lily/include/paper-outputter.hh b/lily/include/paper-outputter.hh index fc6a20b712..2c1aeb2ed9 100644 --- a/lily/include/paper-outputter.hh +++ b/lily/include/paper-outputter.hh @@ -23,7 +23,7 @@ class Paper_outputter { SCM output_module_; - String filename_; + String file_name_; SCM file_; SCM file (); diff --git a/lily/include/source.hh b/lily/include/source.hh index 5c0774c834..be3a900eaa 100644 --- a/lily/include/source.hh +++ b/lily/include/source.hh @@ -20,7 +20,7 @@ public: Sources (); ~Sources (); - Source_file *get_file (String &filename ); + Source_file *get_file (String &file_name ); Source_file *get_sourcefile (char const*); void add (Source_file* sourcefile ); void set_path (File_path*); diff --git a/lily/include/stream.hh b/lily/include/stream.hh index 96ba397fa6..ea403993e1 100644 --- a/lily/include/stream.hh +++ b/lily/include/stream.hh @@ -16,10 +16,10 @@ source file of the GNU LilyPond music typesetter #include "string.hh" #if __GNUC__ > 2 -std::ostream *open_file_stream (String filename, +std::ostream *open_file_stream (String file_name, std::ios_base::openmode mode=std::ios::out); #else -std::ostream *open_file_stream (String filename, int mode=ios::out); +std::ostream *open_file_stream (String file_name, int mode=ios::out); #endif void close_file_stream (std::ostream *os); diff --git a/lily/include/tfm.hh b/lily/include/tfm.hh index 0ce204a0cf..dd8a679d1e 100644 --- a/lily/include/tfm.hh +++ b/lily/include/tfm.hh @@ -147,7 +147,7 @@ struct Tex_font_char_metric class Tex_font_metric : public Simple_font_metric { public: - static SCM make_tfm (String filename); + static SCM make_tfm (String file_name); virtual int count () const; virtual Box get_ascii_char (int) const; diff --git a/lily/input-smob.cc b/lily/input-smob.cc index b5b5097b62..0c1018fc11 100644 --- a/lily/input-smob.cc +++ b/lily/input-smob.cc @@ -97,7 +97,7 @@ LY_DEFINE (ly_input_message, "ly:input-message", 2, 0, 0, (SCM sip, SCM msg), TODO: rename this function. ly:input-location? vs ly:input-location */ LY_DEFINE (ly_input_location, "ly:input-location", 1, 0, 0, (SCM sip), - "Return input location in @var{sip} as (filename line column).") + "Return input location in @var{sip} as (file-name line column).") { Input *ip = unsmob_input (sip); SCM_ASSERT_TYPE (ip, sip, SCM_ARG1, __FUNCTION__, "input location"); diff --git a/lily/kpath.cc b/lily/kpath.cc index 7ae43ce354..b9755f3ede 100644 --- a/lily/kpath.cc +++ b/lily/kpath.cc @@ -65,9 +65,9 @@ kpathsea_find_afm (char const * name) String kpathsea_find_tfm (char const *name) { - String filename = global_path.find (String (name) + ".tfm"); + String file_name = global_path.find (String (name) + ".tfm"); #if (KPATHSEA && HAVE_KPSE_FIND_FILE) - if (filename.is_empty ()) + if (file_name.is_empty ()) { /* If invoked for a TeX font, we could do TRUE (must exist). We could also do: @@ -82,10 +82,10 @@ kpathsea_find_tfm (char const *name) if (!p) warning (_f ("kpathsea can not find TFM file: `%s'", name)); else - filename = p; + file_name = p; } #endif - return filename; + return file_name; } #if KPATHSEA @@ -116,28 +116,28 @@ kpathsea_find_format (String name) String kpathsea_gulp_file_to_string (String name) { - String filename = global_path.find (name); + String file_name = global_path.find (name); #if (KPATHSEA && HAVE_KPSE_FIND_FILE) - if (filename.is_empty ()) + if (file_name.is_empty ()) { char *p = kpse_find_file (name.to_str0 (), kpathsea_find_format (name), true); if (p) - filename = p; + file_name = p; else warning (_f ("kpathsea can not find file: `%s'", name)); } #endif - if (filename.is_empty ()) + if (file_name.is_empty ()) error (_f ("can't find file: `%s'", name)); if (verbose_global_b) - progress_indication ("[" + filename); + progress_indication ("[" + file_name); int filesize; - char *str = gulp_file (filename, &filesize); + char *str = gulp_file (file_name, &filesize); String string (str); delete[] str; @@ -157,8 +157,8 @@ LY_DEFINE (ly_kpathsea_expand_path, "ly:kpathsea-expand-path", SCM_ASSERT_TYPE (scm_is_string (name), name, SCM_ARG1, __FUNCTION__, "string"); String nm = ly_scm2string (name); - String filename = global_path.find (nm); - if (filename.is_empty ()) + String file_name = global_path.find (nm); + if (file_name.is_empty ()) { char *p = kpse_find_file (nm.to_str0 (), kpathsea_find_format (nm), true); @@ -167,7 +167,7 @@ LY_DEFINE (ly_kpathsea_expand_path, "ly:kpathsea-expand-path", else return SCM_BOOL_F; } - return scm_makfrom0str (filename.to_str0 ()); + return scm_makfrom0str (file_name.to_str0 ()); } diff --git a/lily/midi-stream.cc b/lily/midi-stream.cc index ef88ef9f42..d266391510 100644 --- a/lily/midi-stream.cc +++ b/lily/midi-stream.cc @@ -17,10 +17,10 @@ #include "warn.hh" #include "scm-option.hh" -Midi_stream::Midi_stream (String filename) +Midi_stream::Midi_stream (String file_name) { - filename_string_ = filename; - out_file_ = fopen (filename.to_str0(), "wb"); + file_name_string_ = file_name; + out_file_ = fopen (file_name.to_str0(), "wb"); } Midi_stream::~Midi_stream () diff --git a/lily/modified-font-metric.cc b/lily/modified-font-metric.cc index c6afc58392..70454a3c33 100644 --- a/lily/modified-font-metric.cc +++ b/lily/modified-font-metric.cc @@ -86,23 +86,6 @@ Modified_font_metric::Modified_font_metric (String input_encoding, coding_description_); } } - - - -LY_DEFINE (ly_font_encoding_alist, "ly:font-encoding-alist", - 1, 0, 0, - (SCM font), - "Given the Modified_font_metric @var{font}, return an " - "alist. Keys are input-name, input-vector, " - "output-name, output-table, mapping.") -{ - Modified_font_metric *fm - = dynamic_cast (unsmob_metrics (font)); - - SCM_ASSERT_TYPE (fm, font, SCM_ARG1, __FUNCTION__, "Modified_font_metric"); - return fm->coding_description_; -} - SCM Modified_font_metric::make_scaled_font_metric (SCM coding, Font_metric *m, Real s) @@ -251,7 +234,7 @@ Modified_font_metric::text_dimension (String text) { Interval ydims; - Real w=0.0; + Real w = 0.0; for (int i = 0; i < text.length (); i++) { @@ -280,7 +263,7 @@ Modified_font_metric::text_dimension (String text) if (!scm_is_symbol (sym)) continue; - char const * chars = scm_i_string_chars (scm_symbol_to_string(sym)); + char const *chars = scm_i_string_chars (scm_symbol_to_string (sym)); int idx = orig_->name_to_index (chars); if (idx >= 0) @@ -308,3 +291,30 @@ Modified_font_metric::original_font () const { return orig_; } + + +LY_DEFINE (ly_font_encoding_alist, "ly:font-encoding-alist", + 1, 0, 0, + (SCM font), + "Given the Modified_font_metric @var{font}, return an " + "alist. Keys are input-name, input-vector, " + "output-name, output-table, mapping.") +{ + Modified_font_metric *fm + = dynamic_cast (unsmob_metrics (font)); + + SCM_ASSERT_TYPE (fm, font, SCM_ARG1, __FUNCTION__, "Modified_font_metric"); + return fm->coding_description_; +} + +LY_DEFINE (ly_font_encoding, "ly:font-encoding", + 1, 0, 0, + (SCM font), + "Return encoding of @var{font}.") +{ + Modified_font_metric *fm + = dynamic_cast (unsmob_metrics (font)); + SCM_ASSERT_TYPE (fm, font, SCM_ARG1, __FUNCTION__, "Modified_font_metric"); + return ly_symbol2scm (fm->original_font ()->coding_scheme ().to_str0 ()); +} + diff --git a/lily/pangofc-afm-decoder.cc b/lily/pangofc-afm-decoder.cc index 5da779c5f5..71f2f30667 100644 --- a/lily/pangofc-afm-decoder.cc +++ b/lily/pangofc-afm-decoder.cc @@ -47,7 +47,6 @@ struct _PangoFcAfmDecoderPrivate { GString encoding[256]; - //GString file_name; char const *file_name; PangoFcFont *fc_font; }; @@ -65,39 +64,7 @@ static void pango_fc_afm_decoder_set_file_name (PangoFcAfmDecoder *self, static PangoFcDecoderClass *parent_class; -#if 0 -/* ugly warning */ G_DEFINE_TYPE (PangoFcAfmDecoder, pango_fc_afm_decoder, PANGO_TYPE_FC_DECODER); -#else -GType -pango_fc_afm_decoder_get_type (void) -{ - static GType object_type = 0; - - if (!object_type) - { - static const GTypeInfo object_info = - { - sizeof (PangoFcAfmDecoderClass), - (GBaseInitFunc) 0, - (GBaseFinalizeFunc) 0, - (GClassInitFunc) pango_fc_afm_decoder_class_init, - 0, /* class_finalize */ - 0, /* class_data */ - sizeof (PangoFcAfmDecoder), - 0, /* n_preallocs */ - (GInstanceInitFunc) pango_fc_afm_decoder_init, - 0, /* value table */ - }; - - object_type = g_type_register_static (PANGO_TYPE_FC_DECODER, - "PangoFcAfmDecoder", - &object_info, (GTypeFlags)0); - } - - return object_type; -} -#endif static void pango_fc_afm_decoder_init (PangoFcAfmDecoder *fcafmdecoder) @@ -107,9 +74,6 @@ pango_fc_afm_decoder_init (PangoFcAfmDecoder *fcafmdecoder) = G_TYPE_INSTANCE_GET_PRIVATE (fcafmdecoder, PANGO_TYPE_FC_AFM_DECODER, PangoFcAfmDecoderPrivate); - /* - init members - */ } static void @@ -127,14 +91,6 @@ pango_fc_afm_decoder_class_init (PangoFcAfmDecoderClass *clss) static void pango_fc_afm_decoder_finalize (GObject *object) { -#if 0 - PangoFcAfmDecoder *fcafmdecoder = PANGO_FC_AFM_DECODER (object); - PangoFcAfmDecoderPrivate *priv = fcafmdecoder->priv; -#endif - - /* - destroy members - */ G_OBJECT_CLASS (parent_class)->finalize (object); } @@ -142,17 +98,15 @@ static FcCharSet * pango_fc_afm_get_charset (PangoFcDecoder *decoder, PangoFcFont *fcfont) { (void) decoder; - //dprintf ("get charset: %s\n", fcfont->font_pattern); dprintf ("get charset: \n"); #if 0 FcCharSet *charset = 0; FcPatternGetCharSet (fcfont->font_pattern, FC_CHARSET, 0, &charset); #else /* Return plain, undecoded charset. - TODO: - - actually read AFM? - - caching? - - PUA mapping ? */ + FIXME: + - actually read AFM + - caching */ (void) fcfont; int i; FcChar32 chr = 0; @@ -177,15 +131,11 @@ pango_fc_afm_get_glyph (PangoFcDecoder *decoder, PangoFcFont *fcfont, dprintf ("get glyph! 0x%x --> 0x%x\n", wc, (unsigned)g); #else (void) fcfont; - /* TODO: - - PUA mapping? - - Shortcut PUA mapping/AFM reading: The Feta charsets are encoded - without any gaps, starting at 0x21. *grin* - - FIXME: +1 what has changed? -- jcn - */ - return wc - 0x21 + 1; + /* FIXME + Use direct privat usage area (PUA) mapping as shortcut for + actual AFM reading. The Feta charsets are encoded without any + gaps, and mappend onto PUA. */ + return wc - 0xe000; #endif } diff --git a/lily/paper-outputter.cc b/lily/paper-outputter.cc index 0471b7a180..e871011a6f 100644 --- a/lily/paper-outputter.cc +++ b/lily/paper-outputter.cc @@ -31,13 +31,13 @@ #include "ly-smobs.icc" -Paper_outputter::Paper_outputter (String filename, String format) +Paper_outputter::Paper_outputter (String file_name, String format) { file_ = SCM_EOL; output_module_ = SCM_EOL; smobify_self (); - filename_ = filename; + file_name_ = file_name; String module_name = "scm output-" + format; output_module_ = scm_c_resolve_module (module_name.to_str0 ()); } @@ -70,10 +70,10 @@ SCM Paper_outputter::file () { if (file_ == SCM_EOL) - if (filename_ == "-") + if (file_name_ == "-") file_ = scm_current_output_port(); else - file_ = scm_open_file (scm_makfrom0str (filename_.to_str0 ()), + file_ = scm_open_file (scm_makfrom0str (file_name_.to_str0 ()), scm_makfrom0str ("w")); return file_; } diff --git a/lily/score.cc b/lily/score.cc index 22852d79b8..c308509e0d 100644 --- a/lily/score.cc +++ b/lily/score.cc @@ -160,7 +160,7 @@ LY_DEFINE (ly_format_output, "ly:format-output", { Global_context *g = dynamic_cast (unsmob_context (context)); SCM_ASSERT_TYPE (g, context, SCM_ARG1, __FUNCTION__, "Global context"); - SCM_ASSERT_TYPE (scm_is_string (outname), outname, SCM_ARG2, __FUNCTION__, "output filename"); + SCM_ASSERT_TYPE (scm_is_string (outname), outname, SCM_ARG2, __FUNCTION__, "output file name"); Music_output *output = g->get_output (); progress_indication ("\n"); diff --git a/lily/tfm.cc b/lily/tfm.cc index 942cffb3af..97b2bbfa45 100644 --- a/lily/tfm.cc +++ b/lily/tfm.cc @@ -92,10 +92,10 @@ Tex_font_metric::get_ascii_char (int a) const } SCM -Tex_font_metric::make_tfm (String filename) +Tex_font_metric::make_tfm (String file_name) { Tex_font_metric *tfm = new Tex_font_metric; - Tex_font_metric_reader reader (filename); + Tex_font_metric_reader reader (file_name); tfm->info_ = reader.info_; tfm->header_ = reader.header_; diff --git a/scm/encoding.scm b/scm/encoding.scm index 5d35fe5745..af4ba61afe 100644 --- a/scm/encoding.scm +++ b/scm/encoding.scm @@ -10,10 +10,10 @@ ;; -(define-public (read-encoding-file filename) +(define-public (read-encoding-file file-name) "Read .enc file, return (COMMAND-NAME . VECTOR-OF-SYMBOLS)." - (let* ((path (ly:kpathsea-expand-path filename)) - (unused (if (string? path) #t (ly:warn "can't find ~s" filename))) + (let* ((path (ly:kpathsea-expand-path file-name)) + (unused (if (string? path) #t (ly:warn "can't find ~s" file-name))) (raw (ly:gulp-file path)) (string (regexp-substitute/global #f "%[^\n]*" raw 'pre "" 'post)) (command (match:substring @@ -60,15 +60,15 @@ vector of symbols." (iota 256)))) -(define (get-coding-from-file filename) - "Read FILENAME, return a list containing encoding vector and table" - (let* ((coding (read-encoding-file filename)) +(define (get-coding-from-file file-name) + "Read FILE-NAME, return a list containing encoding vector and table" + (let* ((coding (read-encoding-file file-name)) (com (car coding)) (vec (cdr coding)) (tab (make-encoding-table vec))) (list com vec tab))) -;; coding-alist maps NAME -> (list FILENAME COMMAND VECTOR TAB) +;; coding-alist maps NAME -> (list FILE-NAME COMMAND VECTOR TAB) (define coding-alist (map (lambda (x) @@ -114,7 +114,7 @@ vector of symbols." (ly:programming-error "programming error: cross thumbs, using: ~S:" fallback) (get-coding fallback)))))) -(define-public (get-coding-filename coding-name) +(define-public (get-coding-file-name coding-name) (car (get-coding coding-name))) (define-public (get-coding-command coding-name) diff --git a/scm/font.scm b/scm/font.scm index a17dc3be69..eadad9b3d7 100644 --- a/scm/font.scm +++ b/scm/font.scm @@ -361,7 +361,7 @@ ;; (display (make-font-tree 1.0)) -;; Century Schoolbook fonts filenames on Debian/Sid +;; Century Schoolbook fonts file names on Debian/Sid (define-public (add-century-schoolbook-fonts node factor) (add-font node diff --git a/scm/framework-gnome.scm b/scm/framework-gnome.scm index f49bca32f1..21c03564ec 100644 --- a/scm/framework-gnome.scm +++ b/scm/framework-gnome.scm @@ -209,8 +209,6 @@ "lilypond-feta-braces-g" "lilypond-feta-braces-h" "lilypond-feta-braces-i" - ;; is this necessary? - "lilypond-feta-din" "lilypond-parmesan")) (dump-page go 0) diff --git a/scm/framework-ps.scm b/scm/framework-ps.scm index 630356591c..84a92b30a3 100644 --- a/scm/framework-ps.scm +++ b/scm/framework-ps.scm @@ -25,7 +25,7 @@ (/ 72 25.4)) (define-public (ps-font-command font . override-coding) - (let* ((name (ly:font-filename font)) + (let* ((name (ly:font-file-name font)) (magnify (ly:font-magnification font)) (coding-alist (ly:font-encoding-alist font)) (input-encoding (assoc-get 'input-name coding-alist)) @@ -47,7 +47,7 @@ (define (load-fonts paper) (let* ((fonts (ly:paper-fonts paper)) - (font-names (uniq-list (sort (map ly:font-filename fonts) stringexact (round (* 1000 (ly:font-magnification font))))))) @@ -46,7 +46,7 @@ (font-encoding (assoc-get 'output-name coding-alist))) (string-append "\\font\\lilypond" (tex-font-command font) "=" - (ly:font-filename font) + (ly:font-file-name font) " scaled " (ly:number->string (inexact->exact (round (* 1000 diff --git a/scm/lily-library.scm b/scm/lily-library.scm index 3d3e19c148..0ec8b3195d 100644 --- a/scm/lily-library.scm +++ b/scm/lily-library.scm @@ -324,3 +324,19 @@ possibly turned off." ((equal? (ly:unit) "pt") (/ 72.0 72.27)) (else (error "unknown unit" (ly:unit))))) +;;; font +(define-public (font-family font) + (let ((name (ly:font-name font))) + (if name + (regexp-substitute/global #f "^GNU-(.*)-[.0-9]*$" name 'pre 1 'post) + (begin + ;;(stderr "font-name: ~S\n" (ly:font-name font)) + ;;(stderr "font-file-name: ~S\n" (ly:font-file-name font)) + (ly:font-file-name font))))) + +(define-public (char->unicode-index font char) + (+ (case (ly:font-encoding font) + ((fetaMusic) (- #xe000 #x20)) + ((fetaBraces) (- #xe000 #x40)) + (else 0)) + (char->integer char))) diff --git a/scm/output-gnome.scm b/scm/output-gnome.scm index db03a1189c..a2c1e3aa6b 100644 --- a/scm/output-gnome.scm +++ b/scm/output-gnome.scm @@ -166,17 +166,13 @@ lilypond -fgnome input/simple-song.ly (+ #x80 (modulo y #x40)))))) (else FIXME))) -(define (custom-utf8 i) - (if (< i #x80) - (utf8 i) - (utf8 (+ #xee00 i)))) - -(define (string->utf8-string string) - (list->string - (apply append (map utf8 (map char->integer (string->list string)))))) - -(define (char->utf8-string char) - (list->string (utf8 (char->integer char)))) +(define (char->utf8-string font char) + (list->string (utf8 (char->unicode-index font char)))) + +(define (string->utf8-string font string) + (apply + string-append + (map (lambda (x) (char->utf8-string font x)) (string->list string)))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; stencil outputters @@ -239,7 +235,6 @@ lilypond -fgnome input/simple-song.ly (set-path-def props def) props)) - ;; two beziers (define (bezier-sandwich lst thick) (let* ((def (make )) @@ -360,33 +355,23 @@ lilypond -fgnome input/simple-song.ly #:width-units blot-diameter #:join-style 'round))) -(define (text font string) +(define (text font s) (define (pango-font-name font) - (let ((name (ly:font-name font))) - (if name - (regexp-substitute/global #f "^GNU-(.*)-[.0-9]*$" name 'pre 1 'post) - (begin - (stderr "font-name: ~S\n" (ly:font-name font)) - ;; TODO s/filename/file-name/ - (stderr "font-filename: ~S\n" (ly:font-filename font)) - (stderr "pango-font-size: ~S\n" (pango-font-size font)) - ;;"ecrm12")))) - (ly:font-filename font))))) + (font-family font)) (define (pango-font-size font) (let* ((designsize (ly:font-design-size font)) (magnification (* (ly:font-magnification font))) - ;;font-name: "GNU-LilyPond-feta-20" - ;;font-filename: "feta20" + ;;font-file-name: "feta20" ;;pango-font-name: "lilypond-feta, regular 32" ;;OPS:2.61 ;;scaling:29.7046771653543 ;;magnification:0.569055118110236 ;;design:20.0 - ;; experimental sizing: + ;; ugh, experimental sizing ;; where does factor ops come from? ;; Hmm, design size: 26/20 (ops 2.60) @@ -399,24 +384,17 @@ lilypond -fgnome input/simple-song.ly scaling)) - (make - #:parent (canvas-root) - - #:anchor 'west - #:x 0.0 #:y 0.15 - - #:font (pango-font-name font) - - #:size-points (pango-font-size font) - ;;#:size ... - #:size-set #t - - ;;apparently no effect :-( - ;;#:scale 1.0 - ;;#:scale-set #t - - #:fill-color "black" - #:text (if (string? string) - (string->utf8-string string) - (char->utf8-string string)))) - + (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) + (string->utf8-string font s))))) diff --git a/scm/output-svg.scm b/scm/output-svg.scm index 2b68ecaf3f..88634e7b34 100644 --- a/scm/output-svg.scm +++ b/scm/output-svg.scm @@ -29,7 +29,6 @@ ;; GLobals ;; FIXME: 2? (define output-scale (* 2 scale-to-unit)) -(define line-thickness 0) (define (stderr string . rest) (apply format (cons (current-error-port) (cons string rest))) @@ -77,42 +76,26 @@ (define (control-flip-y c) (cons (car c) (* -1 (cdr c)))) -(define (ly:numbers->string l) +(define (ly:numbers->string lst) (string-append - (number->string (car l)) - (if (null? (cdr l)) + (number->string (car lst)) + (if (null? (cdr lst)) "" - (string-append "," (ly:numbers->string (cdr l)))))) + (string-append "," (ly:numbers->string (cdr lst)))))) -(define (svg-bezier l close) - (let* ((c0 (car (list-tail l 3))) - (c123 (list-head l 3))) +(define (svg-bezier lst close) + (let* ((c0 (car (list-tail lst 3))) + (c123 (list-head lst 3))) (string-append (if (not close) "M " "L ") (control->string c0) "C " (apply string-append (map control->string c123)) (if (not close) "" (string-append - "L " (control->string close))))));; " Z"))))) - + "L " (control->string close)))))) (define (sqr x) (* x x)) -(define (fontify font expr) - (tagify "text" expr (cons 'style (svg-font font)))) -;; (cons 'unicode-range "U+EE00-EEFF")))) - -(define (font-family font) - (let ((name (ly:font-name font))) - (if name - (regexp-substitute/global #f "^GNU-(.*)-[.0-9]*$" name 'pre 1 'post) - (begin - (stderr "font-name: ~S\n" (ly:font-name font)) - ;; TODO s/filename/file-name/ - (stderr "font-filename: ~S\n" (ly:font-filename font)) - (stderr "font-size: ~S\n" (font-size font)) - "ecrm12")))) - (define (font-size font) (let* ((designsize (ly:font-design-size font)) (magnification (* (ly:font-magnification font))) @@ -123,31 +106,22 @@ (debugf "design:~S\n" designsize) scaling)) -(define (integer->entity i) - (format #f "&#x~x;" i)) - -(define (char->entity font c) - (define font-name-base-alist - `(("LilyPond-feta" . ,(- #xe000 #x20)) - ("LilyPond-feta-braces-a" . ,(- #xe000 #x40)) - ("LilyPond-feta-braces-b" . ,(- #xe000 #x40)) - ("LilyPond-feta-braces-c" . ,(- #xe000 #x40)) - ("LilyPond-feta-braces-d" . ,(- #xe000 #x40)) - ("LilyPond-feta-braces-d" . ,(- #xe000 #x40)) - ("LilyPond-feta-braces-e" . ,(- #xe000 #x40)) - ("LilyPond-feta-braces-f" . ,(- #xe000 #x40)) - ("LilyPond-feta-braces-g" . ,(- #xe000 #x40)) - ("LilyPond-feta-braces-h" . ,(- #xe000 #x40)) - ("LilyPond-feta-braces-i" . ,(- #xe000 #x40)) - ("LilyPond-parmesan" . ,(- #xe000 #x20)))) - - (integer->entity (+ (assoc-get (font-family font) font-name-base-alist 0) - (char->integer c)))) - +(define (char->entity font char) + (format #f "&#x~x;" (char->unicode-index font char))) + (define (string->entities font string) (apply string-append (map (lambda (x) (char->entity font x)) (string->list string)))) +(define (svg-font font) + (let* ((encoding (ly:font-encoding font)) + (anchor (if (memq encoding '(fetaMusic fetaBraces)) 'start 'middle))) + (format #f "font-family:~a;font-size:~a;text-anchor:~S;" + (font-family font) (font-size font) anchor))) + +(define (fontify font expr) + (tagify "text" expr (cons 'style (svg-font font)))) + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -168,27 +142,24 @@ (y (* slope width)) (z (sqrt (+ (sqr x) (sqr y))))) (tagify "rect" "" - `(style . ,(format "fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-opacity:1;stroke-width:~f;stroke-linejoin:round;stroke-linecap:round;" line-thickness)) + `(style . ,(format "stroke-linejoin:round;stroke-linecap:round;stroke-width:~f;" blot)) `(x . "0") `(y . ,(number->string (* output-scale (- 0 (/ thick 2))))) `(width . ,(number->string (* output-scale width))) `(height . ,(number->string (* output-scale thick))) - ;;`(ry . ,(number->string (* output-scale half-lt))) - `(ry . ,(number->string (* output-scale (/ line-thickness 2)))) + `(ry . ,(number->string (* output-scale (/ blot 2)))) `(transform . ,(format #f "matrix (~f, ~f, 0, 1, 0, 0) scale (~f, ~f)" (/ x z) (* -1 (/ y z)) 1 1))))) -(define (bezier-sandwich l thick) - (let* (;;(l (eval urg-l this-module)) - (first (list-tail l 4)) +(define (bezier-sandwich lst thick) + (let* ((first (list-tail lst 4)) (first-c0 (car (list-tail first 3))) - (second (list-head l 4))) + (second (list-head lst 4))) (tagify "path" "" - `(stroke . "#000000") - `(stroke-width . ,(number->string line-thickness)) + `(style . ,(format "stroke-linejoin:round;stroke-linecap:round;stroke-width:~f;" thick)) `(transform . ,(format #f "scale (~f, ~f)" output-scale output-scale)) `(d . ,(string-append (svg-bezier first #f) @@ -202,19 +173,7 @@ (string-append "\n")) (define (filledbox breapth width depth height) - (round-filled-box breapth width depth height line-thickness)) - -(define (lily-def key val) - (cond - ((equal? key "lilypondpaperoutputscale") - ;; ugr - ;; If we just use transform scale (output-scale), - ;; all fonts come out scaled too (ie, much too big) - ;; So, we manually scale all other stuff. - (set! output-scale (* scale-to-unit (string->number val)))) - ((equal? key "lilypondpaperlinethickness") - (set! line-thickness (* scale-to-unit (string->number val))))) - "") + (round-filled-box breapth width depth height 0)) (define (placebox x y expr) (tagify "g" @@ -227,18 +186,13 @@ (define (round-filled-box breapth width depth height blot-diameter) (tagify "rect" "" - `(style . ,(format "fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-opacity:1;stroke-width:~f;stroke-linejoin:miter;stroke-linecap:butt;" line-thickness)) + `(style . ,(format "stroke-linejoin:round;stroke-linecap:round;stroke-width:~f;" blot-diameter)) `(x . ,(number->string (* output-scale (- 0 breapth)))) `(y . ,(number->string (* output-scale (- 0 height)))) `(width . ,(number->string (* output-scale (+ breapth width)))) `(height . ,(number->string (* output-scale (+ depth height)))) - ;;`(ry . ,(number->string (* output-scale half-lt))) `(ry . ,(number->string (/ blot-diameter 2))))) -(define (svg-font font) - (format #f "font-family:~a;font-size:~a;fill:black;text-anchor:start;" - (font-family font) (font-size font))) - (define (text font string) (dispatch `(fontify ,font ,(tagify "tspan" (string->entities font string))))) diff --git a/scm/safe-lily.scm b/scm/safe-lily.scm index 31af516b8c..417a77b453 100644 --- a/scm/safe-lily.scm +++ b/scm/safe-lily.scm @@ -36,7 +36,7 @@ ly:find-glyph-by-name ly:font-design-size ly:font-encoding-alist - ly:font-filename + ly:font-file-name ly:font-magnification ly:font-metric? ly:font-name -- 2.39.5