From: Han-Wen Nienhuys Date: Mon, 2 May 2005 23:49:18 +0000 (+0000) Subject: * scm/framework-ps.scm (write-preamble): extract CFF from OTF X-Git-Tag: release/2.5.22~19 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=788b0b0cde1e30d315a212744e8c82b86ecd3614;p=lilypond.git * scm/framework-ps.scm (write-preamble): extract CFF from OTF fonts directly. * buildscripts/gen-emmentaler-scripts.py (i): idem. * mf/GNUmakefile: remove all CFF rules. * scm/framework-ps.scm (ps-embed-cff): reinstate. * lily/open-type-font-scheme.cc (LY_DEFINE): new function ly:otf-font-table-data. (LY_DEFINE): new function otf-font? --- diff --git a/ChangeLog b/ChangeLog index 3d4dac1046..dadebfce79 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,17 @@ 2005-05-03 Han-Wen Nienhuys + * scm/framework-ps.scm (write-preamble): extract CFF from OTF + fonts directly. + + * buildscripts/gen-emmentaler-scripts.py (i): idem. + + * mf/GNUmakefile: remove all CFF rules. + + * scm/framework-ps.scm (ps-embed-cff): reinstate. + * lily/open-type-font-scheme.cc (LY_DEFINE): new function ly:otf-font-table-data. + (LY_DEFINE): new function otf-font? 2005-05-02 Han-Wen Nienhuys diff --git a/buildscripts/gen-emmentaler-scripts.py b/buildscripts/gen-emmentaler-scripts.py index c4f54f6e58..3895d660d7 100644 --- a/buildscripts/gen-emmentaler-scripts.py +++ b/buildscripts/gen-emmentaler-scripts.py @@ -66,7 +66,6 @@ LoadTableFromFile("LILC", "feta%(design_size)d.otf-table") LoadTableFromFile("LILY", "feta%(design_size)d.otf-gtable") Generate("%(filename)s-%(design_size)d.otf"); -Generate("%(filename)s-%(design_size)d.cff"); Generate("%(filename)s-%(design_size)d.svg"); SetFontNames("PFA%(name)s-%(design_size)d", "PFA%(name)s", "PFA%(name)s %(design_size)d", "%(design_size)d", "GNU GPL", "@TOPLEVEL_VERSION@"); diff --git a/lily/open-type-font-scheme.cc b/lily/open-type-font-scheme.cc index 1473205210..d39a7cc9d8 100644 --- a/lily/open-type-font-scheme.cc +++ b/lily/open-type-font-scheme.cc @@ -35,10 +35,10 @@ LY_DEFINE (ly_otf_font_glyph_info, "ly:otf-font-glyph-info", 2, 0, 0, return scm_hashq_ref (otf->get_char_table (), sym, SCM_EOL); } - LY_DEFINE(ly_otf_font_table_data, "ly:otf-font-table-data", 2, 0, 0, (SCM font, SCM tag), - "Extract a table @var{tag} from @var{font}.") + "Extract a table @var{tag} from @var{font}. Return empty string for " + "non-existent @var{tag}.") { Modified_font_metric *fm = dynamic_cast (unsmob_metrics (font)); @@ -46,7 +46,6 @@ LY_DEFINE(ly_otf_font_table_data, "ly:otf-font-table-data", 2, 0, 0, Open_type_font *otf = fm ? dynamic_cast (fm->original_font ()) : dynamic_cast (unsmob_metrics (font)); - SCM_ASSERT_TYPE (otf, font, SCM_ARG1, __FUNCTION__, "Open type font"); SCM_ASSERT_TYPE (scm_is_string (tag), tag, SCM_ARG1, __FUNCTION__, "Open type font"); @@ -59,3 +58,16 @@ LY_DEFINE(ly_otf_font_table_data, "ly:otf-font-table-data", 2, 0, 0, return scm_from_locale_stringn ((char const*) tab.to_bytes (), tab.length ()); } + +LY_DEFINE(ly_otf_font_p, "ly:otf-font?", 1, 0, 0, + (SCM font), + "Is @var{font} an OpenType font?") +{ + Modified_font_metric *fm + = dynamic_cast (unsmob_metrics (font)); + + Open_type_font *otf = fm ? dynamic_cast (fm->original_font ()) + : dynamic_cast (unsmob_metrics (font)); + + return scm_from_bool (otf); +} diff --git a/lily/open-type-font.cc b/lily/open-type-font.cc index df0a23e7d5..6c82e91f21 100644 --- a/lily/open-type-font.cc +++ b/lily/open-type-font.cc @@ -18,6 +18,7 @@ FT_Byte * load_table (char const *tag_str, FT_Face face, FT_ULong *length) { + *length = 0; FT_ULong tag = FT_MAKE_TAG (tag_str[0], tag_str[1], tag_str[2], tag_str[3]); int error_code = FT_Load_Sfnt_Table (face, tag, 0, NULL, length); @@ -33,7 +34,11 @@ load_table (char const *tag_str, FT_Face face, FT_ULong *length) return buffer; } - + else + { + programming_error ("Cannot find OpenType table."); + } + return 0; } @@ -42,7 +47,7 @@ Open_type_font::get_otf_table (String tag) const { FT_ULong len; FT_Byte *tab = load_table (tag.to_str0 (), face_, &len); - + return String (tab, len); } diff --git a/lily/pango-font.cc b/lily/pango-font.cc index 7b0ac74fa7..35dd915ea1 100644 --- a/lily/pango-font.cc +++ b/lily/pango-font.cc @@ -164,7 +164,7 @@ Pango_font::pango_item_string_stencil (PangoItem *item, String str, Real dx) con { ((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.to_str0 ()), scm_from_double (size), diff --git a/mf/GNUmakefile b/mf/GNUmakefile index 52f185ecb6..46a7dd063d 100644 --- a/mf/GNUmakefile +++ b/mf/GNUmakefile @@ -29,8 +29,6 @@ OTF_TABLES = $(STAFF_SIZES:%=$(outdir)/feta%.otf-table)\ $(BRACES:%=$(outdir)/feta-braces-%.otf-table) FETA_FONTS = $(FETA_MF_FILES:.mf=) SVG_FILES = $(OTF_FILES:%.otf=%.svg) $(ALL_FONTS:%=$(outdir)/%.svg) -CFF_FILES = $(OTF_FILES:%.otf=%.cff) -CFF_PS_FILES = $(OTF_FILES:%.otf=%.cff.ps) $(outdir)/aybabtu.otf-table: $(BRACES:%=$(outdir)/feta-braces-%.otf-table) @@ -58,15 +56,14 @@ MFTRACE_FLAGS=$(if $(ENCODING_FILE),--encoding $(ENCODING_FILE),) --no-afm # 2. are not included with teTeX # -$(outdir)/%.cff.ps $(outdir)/$(PFA_PREFIX)%.pfa $(outdir)/%.cff $(outdir)/%.otf $(outdir)/%.svg: $(outdir)/%.pe +$(outdir)/$(PFA_PREFIX)%.pfa $(outdir)/%.otf $(outdir)/%.svg: $(outdir)/%.pe (cd $(outdir) && $(FONTFORGE) -script $(notdir $<)) - $(PYTHON) $(buildscript-dir)/ps-embed-cff.py $(basename $<).cff `cat $(basename $<).fontname` $(basename $<).cff.ps -rm $(outdir)/*.scale.pfa # ugh, this does not work $(outdir)/%.pfa: $(outdir)/%.log $(outdir)/feta-alphabet%.pfa: $(outdir)/feta-alphabet%.log -$(outdir)/emmentaler-%.otf $(outdir)/$(PFA_PREFIX)emmentaler-%.pfa $(outdir)/emmentaler%.cff $(outdir)/emmentaler%.svg: $(outdir)/feta%.pfa $(outdir)/feta-alphabet%.pfa $(outdir)/parmesan%.pfa +$(outdir)/emmentaler-%.otf $(outdir)/$(PFA_PREFIX)emmentaler-%.pfa $(outdir)/emmentaler%.svg: $(outdir)/feta%.pfa $(outdir)/feta-alphabet%.pfa $(outdir)/parmesan%.pfa # AARGH? @@ -114,7 +111,7 @@ $(outdir)/%.otf-table: $(outdir)/%.lisp $(if $(findstring brace,$<),,$(subst fet $(outdir)/aybabtu.otf $(outdir)/$(PFA_PREFIX)aybabtu.pfa: $(outdir)/aybabtu.subfonts $(outdir)/aybabtu.fontname $(outdir)/aybabtu.otf-table $(outdir)/aybabtu.otf-gtable $(outdir)/aybabtu.pe -$(outdir)/aybabtu.otf $(outdir)/$(PFA_PREFIX)aybabtu.pfa $(outdir)/aybabtu.cff $(outdir)/aybabtu.svg: $(BRACES:%=$(outdir)/feta-braces-%.pfa) +$(outdir)/aybabtu.otf $(outdir)/$(PFA_PREFIX)aybabtu.pfa $(outdir)/aybabtu.svg: $(BRACES:%=$(outdir)/feta-braces-%.pfa) $(outdir)/aybabtu.fontname: echo -n 'aybabtu' > $@ @@ -130,7 +127,7 @@ PFA_FILES = $(ALL_FONTS:%=$(outdir)/%.pfa) $(PFA_OTF_FILES) # Make tfm files first, log files last, # so that normally log files aren't made twice -ALL_GEN_FILES= $(TFM_FILES) $(TEXTABLES) $(TFM_FILES) $(LOG_FILES) $(ENC_FILES) $(LISP_FILES) $(FETA_LIST_FILES) $(OTF_TABLES) $(PFA_FILES) $(outdir)/lilypond.map $(OTF_FILES) $(SVG_FILES) $(CFF_PS_FILES) $(CFF_FILES) +ALL_GEN_FILES= $(TFM_FILES) $(TEXTABLES) $(TFM_FILES) $(LOG_FILES) $(ENC_FILES) $(LISP_FILES) $(FETA_LIST_FILES) $(OTF_TABLES) $(PFA_FILES) $(outdir)/lilypond.map $(OTF_FILES) $(SVG_FILES) #PRE_INSTALL=$(MAKE) "$(ALL_GEN_FILES)" INSTALLATION_DIR=$(local_lilypond_datadir)/fonts/source diff --git a/scm/framework-ps.scm b/scm/framework-ps.scm index b7fbae4842..4177cc6242 100644 --- a/scm/framework-ps.scm +++ b/scm/framework-ps.scm @@ -193,14 +193,50 @@ (regexp-substitute/global #f "([eE]mmentaler|[aA]ybabtu)" name 'pre "PFA" 1 'post)) +(define (cff-font? font) + (let* + ((cff-string (ly:otf-font-table-data font "CFF "))) + (> (string-length cff-string) 0))) + +(define-public (ps-embed-cff body font-set-name version) + (let* ((binary-data + (string-append + (format "/~a ~s StartData " font-set-name (string-length body)) + body)) + + (header + (format + "%%BeginResource: font ~a +%!PS-Adobe-3.0 Resource-FontSet +%%DocumentNeededResources: ProcSet (FontSetInit) +%%Title: (FontSet/~a) +%%Version: ~s +%%EndComments +%%IncludeResource: ProcSet (FontSetInit) +%%BeginResource: FontSet (~a) +/FontSetInit /ProcSet findresource begin +%%BeginData: ~s Binary Bytes +" + font-set-name font-set-name version font-set-name + (string-length binary-data))) + (footer "\n%%EndData +%%EndResource +%%EOF +%%EndResource\n")) + + (string-append + header + binary-data + footer))) + + (define (write-preamble paper load-fonts? port) - (define (load-font font-pair) - (let* ((name (car font-pair)) - (file-name (cdr font-pair)) - - (bare-file-name (ly:find-file file-name)) - (cffname (string-append file-name ".cff.ps")) - (cff-file-name (ly:find-file cffname))) + + (define (load-font font-name-filename) + (let* ((font (car font-name-filename)) + (name (cadr font-name-filename)) + (file-name (caddr font-name-filename)) + (bare-file-name (ly:find-file file-name))) (cons (munge-lily-font-name name) @@ -213,20 +249,11 @@ ((string-match "([eE]mmentaler|[Aa]ybabtu)" file-name) (cached-file-contents (format "~a.pfa" (munge-lily-font-name file-name)))) - - ((and bare-file-name - (string-match "\\.(otf|cff)" bare-file-name)) - - ; replace with the CFF.ps, which lives in a - ; separate subdir. - (for-each (lambda (tup) - (set! bare-file-name - (string-regexp-substitute - (car tup) (cdr tup) bare-file-name))) - '(("/fonts/otf/" . "/ps/") - ("/fonts/cff/" . "/ps/") - ("\\.(otf|cff)" . ".cff.ps"))) - + + ((cff-font? font) + (ps-embed-cff (ly:otf-font-table-data font "CFF ") + name + 0)) (cached-file-contents bare-file-name)) ((and bare-file-name (string-match "\\.ttf" bare-file-name)) (ly:ttf->pfa bare-file-name)) @@ -235,6 +262,7 @@ (else (ly:warning (_ "can't find CFF/PFA/PFB font ~S=~S" name file-name)) (cons font-name "")))))) + (define (load-fonts paper) (let* ((fonts (ly:paper-fonts paper)) @@ -244,10 +272,17 @@ (lambda (font) (cond ((string? (ly:font-file-name font)) - (list (cons (ly:font-name font) - (ly:font-file-name font)))) + (list (list + font + (ly:font-name font) + (ly:font-file-name font)))) ((ly:pango-font? font) - (ly:pango-font-physical-fonts font)) + (map + (lambda (name-psname-pair) + (list #f + (car name-psname-pair) + (cdr name-psname-pair))) + (ly:pango-font-physical-fonts font))) (else (ly:font-sub-fonts font)))) @@ -255,7 +290,7 @@ (font-names (uniq-list (sort (apply append all-font-names) - (lambda (x y) (string