From 235a33ac0d166718d2a6f07069a6ffb2c5acaf34 Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Fri, 4 Feb 2005 11:44:22 +0000 Subject: [PATCH] * lily/parser.yy (assignment_id): allow LYRICS_STRING as identifier definition too, so foo = \lyrics { ... } bar = #1 doesn't complain about "bar" being LYRICS_STRING. * lily/paper-def.cc (find_pango_font): new routine; Store pango_fonts in hash tab too. This is necessary for retrieving Pango_fonts::physical_font_tab() later on. * lily/pango-font.cc (pango_item_string_stencil): bugfix: don't crash if psname is null. * lily/lily-guile.cc (ly_hash2alist): new function * Documentation/user/changing-defaults.itely (Text encoding): rewrite. * lily/pango-font.cc (physical_font_tab): new member. Store PSname -> font_filename mapping. * lily/pango-font-scheme.cc (LY_DEFINE): new file. New function ly_pango_font_physical_fonts * scm/framework-ps.scm (supplies-or-needs): extract names from physical Pango_fonts. * utf8.ly: new file. --- ChangeLog | 16 +++++ Documentation/user/changing-defaults.itely | 73 ++++++++-------------- input/regression/utf8.ly | 64 +++++++++++++++++++ lily/font-select.cc | 14 ++--- lily/include/lily-guile.hh | 2 + lily/include/output-def.hh | 5 +- lily/include/pango-font.hh | 6 +- lily/lily-guile.cc | 20 ++++++ lily/main.cc | 7 ++- lily/object-key-undumper.cc | 1 + lily/output-def-scheme.cc | 52 +++++++++------ lily/pango-font-scheme.cc | 48 ++++++++++++++ lily/pango-font.cc | 53 ++++++++-------- lily/paper-def.cc | 55 ++++++++++++---- lily/parser.yy | 14 +++-- scm/framework-ps.scm | 27 +++++--- 16 files changed, 328 insertions(+), 129 deletions(-) create mode 100644 input/regression/utf8.ly create mode 100644 lily/pango-font-scheme.cc diff --git a/ChangeLog b/ChangeLog index f8ca8ec8dd..51ca633961 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2005-02-04 Han-Wen Nienhuys + + * Documentation/user/changing-defaults.itely (Text encoding): + rewrite. + + * lily/pango-font.cc (physical_font_tab): new member. Store PSname + -> font_filename mapping. + + * lily/pango-font-scheme.cc (LY_DEFINE): new file. New function + ly_pango_font_physical_fonts + + * scm/framework-ps.scm (supplies-or-needs): extract names from + physical Pango_fonts. + + * utf8.ly: new file. + 2005-02-02 Han-Wen Nienhuys * Documentation/user/changing-defaults.itely (Page layout): add diff --git a/Documentation/user/changing-defaults.itely b/Documentation/user/changing-defaults.itely index a0ab14bff6..455fa43ee3 100644 --- a/Documentation/user/changing-defaults.itely +++ b/Documentation/user/changing-defaults.itely @@ -1,4 +1,4 @@ -@c -*- coding: latin-1; mode: texinfo; -*- +@c -*- coding: utf-8; mode: texinfo; -*- @node Changing defaults @chapter Changing defaults @@ -1123,7 +1123,6 @@ does not amount to much. The initialization file (self-alignment-X . 0) (self-alignment-Y . 0) (script-priority . 100) - (font-encoding . number) (font-size . -5) (meta . ((interfaces . (finger-interface font-interface text-script-interface text-interface @@ -1394,11 +1393,12 @@ fonts. @itemize @bullet @item @code{font-encoding} -is a symbol that sets layout of the glyphs. Choices include @code{ec} -for @TeX{} EC font encoding, @code{fetaBraces} for piano staff -braces, @code{fetaMusic} the standard music font, including ancient -glyphs, @code{fetaDynamic} for dynamic signs and @code{fetaNumber} -for the number font. +is a symbol that sets layout of the glyphs. This should only be set to +select different types of non-text fonts, eg. + +@code{fetaBraces} for piano staff braces, @code{fetaMusic} the +standard music font, including ancient glyphs, @code{fetaDynamic} for +dynamic signs and @code{fetaNumber} for the number font. @item @code{font-family} is a symbol indicating the general class of the typeface. Supported are @@ -1552,59 +1552,36 @@ Syntax errors for markup mode are confusing. @node Text encoding @subsection Text encoding -[FIXME: OBSOLETE, use UTF8 for input files.] +LilyPond uses the Pango library to format multi-lingual texts. This +means that any text, be it title, lyric text, or musical instruction +contaning non-ASCII characters should be entered as Unicode. +@lilypondfile[utf8.ly] -Texts can be entered in different encodings. The encoding of the -file can be set with @code{\encoding}. +The @TeX{} backend does not handle encoding specially at all. Strings +in the input are put in the output as-is. Extents of text items in the +@TeX{} backend, are determined by reading a file created via the +@file{texstr} backend, @example -\encoding "latin1" + lilypond -b texstr input/les-nereides.ly + latex les-nereides.texstr @end example -This command may be placed anywhere in the input file. The current -encoding is passed as an extra argument to @code{\markup} commands, -and is passed similarly to lyric syllables. - -If no @code{\encoding} has been specified, then the encoding is taken -from the @code{\layout} block (or @code{\paper}, if @code{\layout} -does not specify encoding). The variable @code{inputencoding} may be -set to a string or symbol specifying the encoding, e.g., +The last command produces @file{les-nereides.textmetrics}, which is +read when you execute @example -\layout @{ - inputencoding = "latin1" -@} + lilypond -b tex input/les-nereides.ly @end example -Normal strings are unaffected by @code{\encoding}. This means that -the following will usually not produce `Baßtuba' in the title. - -@example -\header @{ - title = "Grazing cow" - instrument = "Baßtuba" -@} -@end example +Both @file{les-nereides.texstr} and @file{les-nereides.tex} need +suitable LaTeX wrappers to load appropriate La@TeX{} packages for +interpreting non-ASCII strings. -@noindent -Rather, you should say -@example -instrument = \markup @{ Baßtuba @} -@end example - -@noindent -or set @code{inputencoding} in the @code{\paper} block. - -There is a special encoding, called @code{TeX}. This encoding does not -reencode text for the font used. Rather, it tries to guess the width -of @TeX{} commands, such as @code{\"}. Strings encoded with @code{TeX} -are passed to the output back-end verbatim. +@seealso -@cindex encoding -@cindex @code{\encoding} -@cindex inputencoding -@cindex @TeX{} commands in strings +@inputfileref{input/regression/,utf8.ly} @node Nested scores diff --git a/input/regression/utf8.ly b/input/regression/utf8.ly new file mode 100644 index 0000000000..89e5f76d50 --- /dev/null +++ b/input/regression/utf8.ly @@ -0,0 +1,64 @@ +\version "2.5.10" + +% Edit this file using a Unicode aware editor, such as GVIM, GEDIT, Emacs + +%{ + +I installed some additional font packages to get this working. + +taipeifonts +fonts-xorg-truetype +ttfonts-ja +fonts-arabic +ttfonts-zh_CN +fonts-ja +fonts-hebrew + +%} + +\header { + + texidoc = "Various scripts may be used for texts (like titles and +lyrics) introduced by entering them in UTF-8 encoding, and using a +Pango based backend. Depending on the fonts installed, this fragment +will render Japanese, Hebrew and Cyrillic. + +" + +} + + +japanese = \lyricsto "melody" \new Lyrics { + + いろはにほへど ちりぬるを + わがよたれぞ つねならむ + うゐのおくやまけふこえて + あさきゆめみじ ゑひもせず + + } + + +bulgarian = \lyricsto "melody" \new Lyrics { + + Жълтата дюля беше щастлива, че пухът, който цъфна, замръзна като гьон. + +} + +hebrew = \lyricsto "melody" \new Lyrics { +זה כיף סתם לשמוע איך תנצח קרפד ×¢×¥ טוב בגן. +} + +% latin1 section start + + << + \context Voice = "melody" \relative { + c2 d e f g f e + } + \hebrew + \bulgarian + + %% no support for TTF yet. + +% \japanese + +>> diff --git a/lily/font-select.cc b/lily/font-select.cc index d698cae60f..189421e339 100644 --- a/lily/font-select.cc +++ b/lily/font-select.cc @@ -26,7 +26,7 @@ get_font_by_design_size (Output_def *layout, Real requested, Real last_size = -1e6; int i = 0; - String pango_description_string; + SCM pango_description_string = SCM_EOL; for (; i < n; i++) { SCM entry = scm_c_vector_ref (font_vector, i); @@ -43,7 +43,7 @@ get_font_by_design_size (Output_def *layout, Real requested, { size = scm_to_double (scm_car (entry)); pango_description_string - = ly_scm2string (scm_cdr (entry)); + = scm_cdr (entry); } #endif @@ -64,14 +64,12 @@ get_font_by_design_size (Output_def *layout, Real requested, } Font_metric *fm = 0; - if (pango_description_string != "") + if (scm_is_string (pango_description_string)) { #if HAVE_PANGO_FT2 - PangoFontDescription *description - = pango_font_description_from_string (pango_description_string.to_str0 ()); - return all_fonts_global->find_pango_font (description, - requested / size, - output_scale (layout)); + return find_pango_font (layout, + pango_description_string, + requested / size); #else error ("Trying to retrieve pango font without HAVE_PANGO_FT2."); #endif diff --git a/lily/include/lily-guile.hh b/lily/include/lily-guile.hh index 4b23c23ad1..01c6646a06 100644 --- a/lily/include/lily-guile.hh +++ b/lily/include/lily-guile.hh @@ -61,6 +61,8 @@ SCM parse_symbol_list (char const *); SCM robust_list_ref(int i, SCM l); SCM alist_to_hashq (SCM); +SCM ly_alist_vals (SCM alist); +SCM ly_hash2alist (SCM tab); /* inserts at front, removing dublicates */ inline SCM ly_assoc_front_x(SCM alist, SCM key, SCM val) diff --git a/lily/include/output-def.hh b/lily/include/output-def.hh index ee5d459d72..b5c60c0c59 100644 --- a/lily/include/output-def.hh +++ b/lily/include/output-def.hh @@ -74,9 +74,10 @@ Font_metric *select_font (Output_def *layout, SCM chain); DECLARE_UNSMOB (Output_def, output_def); -Font_metric *find_scaled_font (Output_def *od, - Font_metric *f, Real magnification); +Font_metric* find_pango_font (Output_def *layout, SCM descr, Real factor); +Font_metric *find_scaled_font (Output_def *od, Font_metric *f, Real magnification); Output_def *scale_output_def (Output_def *def, Real scale); + Real output_scale (Output_def*); #endif /* MUSIC_OUTPUT_DEF_HH */ diff --git a/lily/include/pango-font.hh b/lily/include/pango-font.hh index 08e21edc55..31b858f143 100644 --- a/lily/include/pango-font.hh +++ b/lily/include/pango-font.hh @@ -25,9 +25,10 @@ class Pango_font : public Font_metric PangoFontDescription *pango_description_; PangoAttrList *attribute_list_; Real scale_; - SCM subfonts_; - + SCM physical_font_tab_; + public: + SCM physical_font_tab () const; Pango_font (PangoFT2FontMap *, Direction leftright, PangoFontDescription *, @@ -39,7 +40,6 @@ public: Stencil text_stencil (String) const; Stencil pango_item_string_stencil (PangoItem*, String, Real) const; - virtual SCM sub_fonts () const; virtual void derived_mark () const; }; diff --git a/lily/lily-guile.cc b/lily/lily-guile.cc index e0aeccaf3e..50bb49e841 100644 --- a/lily/lily-guile.cc +++ b/lily/lily-guile.cc @@ -722,3 +722,23 @@ alist_equal_p (SCM a, SCM b) } return true; } + + + +SCM +ly_alist_vals (SCM alist) +{ + SCM x = SCM_EOL; + for (SCM p = alist; scm_is_pair (p); p = scm_cdr (p)) + { + x = scm_cons (scm_cdar (p), x); + } + return x; +} + +SCM +ly_hash2alist (SCM tab) +{ + SCM func = ly_lily_module_constant ("hash-table->alist"); + return scm_call_1 (func, tab); +} diff --git a/lily/main.cc b/lily/main.cc index d89bfcd1ea..514d266d07 100644 --- a/lily/main.cc +++ b/lily/main.cc @@ -275,6 +275,10 @@ main_with_guile (void *, int, char **) init_global_tweak_registry (); init_fontconfig (); init_freetype (); + + is_pango_format_global = (output_backend_global != "tex" + && output_backend_global != "texstr"); + all_fonts_global = new All_font_metrics (global_path.to_string ()); init_scheme_code_string += ")"; @@ -380,10 +384,9 @@ parse_argv (int argc, char **argv) warranty (); exit (0); break; + case 'b': output_backend_global = option_parser->optional_argument_str0_; - is_pango_format_global = (output_backend_global != "tex" - &&output_backend_global != "texstr"); break; case 'f': diff --git a/lily/object-key-undumper.cc b/lily/object-key-undumper.cc index 55f17f923c..f990a0fb3d 100644 --- a/lily/object-key-undumper.cc +++ b/lily/object-key-undumper.cc @@ -30,6 +30,7 @@ Object_key_undumper::mark_smob (SCM smob) int Object_key_undumper::print_smob (SCM s, SCM port, scm_print_state*) { + (void) s; scm_puts ("#", port); return 1; } diff --git a/lily/output-def-scheme.cc b/lily/output-def-scheme.cc index b22f434071..65505c9b2f 100644 --- a/lily/output-def-scheme.cc +++ b/lily/output-def-scheme.cc @@ -131,28 +131,42 @@ LY_DEFINE (ly_paper_fonts, "ly:paper-fonts", { Output_def *b = unsmob_output_def (bp); - SCM font_table = b->lookup_variable (ly_symbol2scm ("scaled-fonts")); SCM_ASSERT_TYPE (b, bp, SCM_ARG1, __FUNCTION__, "paper"); - SCM ell = SCM_EOL; - if (scm_hash_table_p (font_table) == SCM_BOOL_T) + SCM tab1 = b->lookup_variable (ly_symbol2scm ("scaled-fonts")); + SCM tab2 = b->lookup_variable (ly_symbol2scm ("pango-fonts")); + + SCM alist1 = SCM_EOL; + if (scm_hash_table_p (tab1) == SCM_BOOL_T) + { + alist1 = scm_append (ly_alist_vals (ly_hash2alist (tab1))); + + alist1 = ly_alist_vals (alist1); + } + + SCM alist2 = SCM_EOL; + if (scm_hash_table_p (tab2) == SCM_BOOL_T) { - SCM func = ly_lily_module_constant ("hash-table->alist"); - - for (SCM s = scm_call_1 (func, font_table); scm_is_pair (s); - s = scm_cdr (s)) - { - SCM entry = scm_car (s); - for (SCM t = scm_cdr (entry); scm_is_pair (t); t = scm_cdr (t)) - { - Font_metric *fm = unsmob_metrics (scm_cdar (t)); - - if (dynamic_cast (fm) - || dynamic_cast (fm)) - ell = scm_cons (fm->self_scm (), ell); - } - } + // strip original-fonts/pango-font-descriptions + alist2 = scm_append (ly_alist_vals (ly_hash2alist (tab2))); + + // strip size factors + alist2 = ly_alist_vals (alist2); } - return ell; + + SCM alist = scm_append (scm_list_2 (alist1, alist2)); + SCM font_list = SCM_EOL; + for (SCM s = alist; scm_is_pair (s); s = scm_cdr (s)) + { + SCM entry = scm_car (s); + + Font_metric *fm = unsmob_metrics (entry); + + if (dynamic_cast (fm) + || dynamic_cast (fm)) + font_list = scm_cons (fm->self_scm (), font_list); + } + + return font_list; } diff --git a/lily/pango-font-scheme.cc b/lily/pango-font-scheme.cc new file mode 100644 index 0000000000..2138e95e5a --- /dev/null +++ b/lily/pango-font-scheme.cc @@ -0,0 +1,48 @@ +/* + pango-font-scheme.cc -- implement Pango_font + + source file of the GNU LilyPond music typesetter + + (c) 2004--2005 Han-Wen Nienhuys + +*/ + + +#define PANGO_ENABLE_BACKEND // ugh, why necessary? + +#include + +#include "main.hh" +#include "lookup.hh" +#include "dimensions.hh" +#include "pango-font.hh" +#include "warn.hh" + +#if HAVE_PANGO_FT2 +#include "stencil.hh" + + +LY_DEFINE (ly_pango_font_p, "ly:pango-font?", + 1, 0, 0, + (SCM f), + "Is @var{f} a pango font?") +{ + return scm_from_bool (dynamic_cast (unsmob_metrics (f))); +} + + + +LY_DEFINE (ly_pango_font_physical_fonts, "ly:pango-font-physical-fonts", + 1, 0, 0, + (SCM f), + "Return alist of (PSNAME . FILENAME) tuples.") +{ + Pango_font *pf = dynamic_cast (unsmob_metrics (f)); + + SCM alist = SCM_EOL; + if (pf) + alist = ly_hash2alist (pf->physical_font_tab ()); + + return alist; +} +#endif diff --git a/lily/pango-font.cc b/lily/pango-font.cc index 8ff54d23ab..22dfb6b47f 100644 --- a/lily/pango-font.cc +++ b/lily/pango-font.cc @@ -16,6 +16,7 @@ #include "lookup.hh" #include "dimensions.hh" #include "pango-font.hh" +#include "warn.hh" #if HAVE_PANGO_FT2 #include "stencil.hh" @@ -26,7 +27,7 @@ Pango_font::Pango_font (PangoFT2FontMap *fontmap, PangoFontDescription *description, Real output_scale) { - subfonts_ = SCM_EOL; + physical_font_tab_ = scm_c_make_hash_table (11); PangoDirection pango_dir = (dir == RIGHT) ? PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL; @@ -61,14 +62,15 @@ Pango_font::~Pango_font () void Pango_font::register_font_file (String filename, String ps_name) { - subfonts_ = scm_cons (scm_makfrom0str (filename.to_str0 ()), - subfonts_); + scm_hash_set_x (physical_font_tab_, + scm_makfrom0str (ps_name.to_str0()), + scm_makfrom0str (filename.to_str0())); } void Pango_font::derived_mark () const { - scm_gc_mark (subfonts_); + scm_gc_mark (physical_font_tab_); } Stencil @@ -124,21 +126,35 @@ Pango_font::pango_item_string_stencil (PangoItem *item, String str, Real dx) con char *filename = 0; FcPatternGetString(fcpat, FC_FILE, 0, (FcChar8 **) &filename); char const *ps_name = FT_Get_Postscript_Name (ftface); - ((Pango_font *) this)->register_font_file (filename, ps_name); - pango_fc_font_unlock_face (fcfont); + + if (ps_name) + { + ((Pango_font *) this)->register_font_file (filename, ps_name); + pango_fc_font_unlock_face (fcfont); - SCM expr = scm_list_4 (ly_symbol2scm ("glyph-string"), - scm_makfrom0str (ps_name), - scm_from_double (size), - ly_quote_scm (glyph_exprs)); + SCM expr = scm_list_4 (ly_symbol2scm ("glyph-string"), + scm_makfrom0str (ps_name), + scm_from_double (size), + ly_quote_scm (glyph_exprs)); - Stencil item_stencil (b, expr); + return Stencil (b, expr); + } + else + { + warning (_ ("FreeType face has no PostScript font name.")); + return Stencil(); + } +} - return item_stencil; +SCM +Pango_font::physical_font_tab () const +{ + return physical_font_tab_; } Stencil + Pango_font::text_stencil (String str) const { GList *items = pango_itemize (context_, @@ -195,11 +211,6 @@ Pango_font::text_stencil (String str) const return dest; } -SCM -Pango_font::sub_fonts () const -{ - return subfonts_; -} SCM Pango_font::font_file_name () const @@ -207,14 +218,6 @@ Pango_font::font_file_name () const return SCM_BOOL_F; } -LY_DEFINE (ly_pango_font_p, "ly:pango-font?", - 1, 0, 0, - (SCM f), - "Is @var{f} a pango font?") -{ - return scm_from_bool (dynamic_cast (unsmob_metrics (f))); -} - #endif diff --git a/lily/paper-def.cc b/lily/paper-def.cc index 6dd082f9f6..62b585bb5a 100644 --- a/lily/paper-def.cc +++ b/lily/paper-def.cc @@ -10,6 +10,8 @@ #include "output-def.hh" #include "modified-font-metric.hh" #include "pango-font.hh" +#include "all-font-metrics.hh" + Real output_scale (Output_def *od) @@ -17,7 +19,6 @@ output_scale (Output_def *od) return scm_to_double (od->lookup_variable (ly_symbol2scm ("outputscale"))); } - SCM get_font_table (Output_def *def) { @@ -29,8 +30,18 @@ get_font_table (Output_def *def) } return font_table; } - +SCM +get_pango_font_table (Output_def *def) +{ + SCM font_table = def->lookup_variable (ly_symbol2scm ("pango-fonts")); + if (scm_hash_table_p (font_table) != SCM_BOOL_T) + { + font_table = scm_c_make_hash_table (11); + def->set_variable (ly_symbol2scm ("pango-fonts"), font_table); + } + return font_table; +} /* TODO: should add nesting for Output_def here too. */ Font_metric * @@ -42,15 +53,10 @@ find_scaled_font (Output_def *mod, Font_metric *f, Real m) Real lookup_mag = m / output_scale (mod); SCM font_table = get_font_table (mod); - SCM sizes = scm_hashq_ref (font_table, f->self_scm (), SCM_BOOL_F); - if (sizes != SCM_BOOL_F) - { - SCM met = scm_assoc (scm_make_real (lookup_mag), sizes); - if (scm_is_pair (met)) - return unsmob_metrics (scm_cdr (met)); - } - else - sizes = SCM_EOL; + SCM sizes = scm_hashq_ref (font_table, f->self_scm (), SCM_EOL); + SCM handle = scm_assoc (scm_make_real (lookup_mag), sizes); + if (scm_is_pair (handle)) + return unsmob_metrics (scm_cdr (handle)); SCM val = Modified_font_metric::make_scaled_font_metric (f, lookup_mag); @@ -60,6 +66,33 @@ find_scaled_font (Output_def *mod, Font_metric *f, Real m) return unsmob_metrics (val); } +Font_metric* +find_pango_font (Output_def *layout, SCM descr, Real factor) +{ + if (layout->parent_) + return find_pango_font (layout->parent_, descr, factor); + + SCM table = get_pango_font_table (layout); + SCM sizes = scm_hash_ref (table, descr, SCM_EOL); + SCM size_key = scm_from_double (factor); + SCM handle = scm_assoc (size_key, sizes); + if (scm_is_pair (handle)) + { + return unsmob_metrics (scm_cdr (handle)); + } + + PangoFontDescription *description + = pango_font_description_from_string (scm_i_string_chars (descr)); + Font_metric *fm = all_fonts_global->find_pango_font (description, + factor, + output_scale (layout)); + + sizes = scm_acons (size_key, fm->self_scm(), sizes); + scm_hash_set_x (table, descr, sizes); + + return fm; +} + /* TODO: this is a nasty interface. During formatting, the Output_def should be scaled to the output_scale_ specified in the toplevel Output_def. */ diff --git a/lily/parser.yy b/lily/parser.yy index 23407d2539..722f299c83 100644 --- a/lily/parser.yy +++ b/lily/parser.yy @@ -418,6 +418,7 @@ or %type output_def_body output_def_head %type output_def paper_block +%type assignment_id %type Music_list %type chord_body_elements %type chord_item chord_items chord_separator new_chord @@ -554,8 +555,13 @@ lilypond_header: /* DECLARATIONS */ +assignment_id: + STRING { $$ = $1; } + | LYRICS_STRING { $$ = $1; } + ; + assignment: - STRING '=' identifier_init { + assignment_id '=' identifier_init { if (! is_regular_identifier ($1)) { @1.warning (_ ("Identifier should have alphabetic characters only")); @@ -1280,12 +1286,12 @@ re_rhythmed_music: $$ = all; scm_gc_unprotect_object (voice->self_scm ()); } - | LYRICSTO { + | LYRICSTO simple_string { THIS->lexer_->push_lyric_state (); - } simple_string Music { + } Music { THIS->lexer_->pop_state (); Music *music = $4; - SCM name = $3; + SCM name = $2; $$ = make_lyric_combine_music (name, music); scm_gc_unprotect_object (music->self_scm ()); } diff --git a/scm/framework-ps.scm b/scm/framework-ps.scm index a1acc277cf..ed57823b43 100644 --- a/scm/framework-ps.scm +++ b/scm/framework-ps.scm @@ -83,6 +83,7 @@ (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))) @@ -136,16 +137,25 @@ (ly:outputter-dump-stencil outputter page) (ly:outputter-dump-string outputter "} stop-system \nshowpage\n")) + (define (supplies-or-needs paper load-fonts?) - (let* ((fonts (ly:paper-fonts paper))) + (define (extract-names font) + (if (ly:pango-font? font) + (map car (ly:pango-font-physical-fonts font)) + (list (ly:font-name font)))) + + (let* ((fonts (ly:paper-fonts paper)) + (names (apply append (map extract-names fonts))) + ) + (apply string-append (map (lambda (f) (format (if load-fonts? "%%DocumentSuppliedResources: font ~a\n" "%%DocumentNeededResources: font ~a\n") - (ly:font-name f))) - fonts)))) + f)) + names)))) (define (eps-header paper bbox load-fonts?) (string-append "%!PS-Adobe-2.0 EPSF-2.0\n" @@ -197,11 +207,14 @@ (all-font-names (map (lambda (font) - (if (string? (ly:font-file-name font)) - (list (ly:font-file-name font)) - (ly:font-sub-fonts font))) - + (cond + ((string? (ly:font-file-name font)) (list (ly:font-file-name font))) + ((ly:pango-font? font) + (map cdr (ly:pango-font-physical-fonts font))) + (else (ly:font-sub-fonts font)))) + fonts)) + (font-names (uniq-list (sort (apply append all-font-names) string