From 254f634d6e541adeea359a557ea9c9ad8860131c Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Wed, 29 Dec 2004 23:46:05 +0000 Subject: [PATCH] * scm/paper.scm (layout-set-staff-size): use text-font-size in dimension less points (ie. 12 = 12 point) * lily/pango-select.cc (select_pango_font): use find_scaled_font(). * lily/all-font-metrics.cc (find_pango_font): set description_ * lily/pango-font.cc (text_stencil): export size as well. (text_stencil): fix scaling and extents box. --- ChangeLog | 12 ++++++++ lily/all-font-metrics.cc | 11 +++++-- lily/include/dimensions.hh | 4 +++ lily/include/pango-font.hh | 10 ++---- lily/pango-font.cc | 62 ++++++++++++++------------------------ lily/pango-select.cc | 29 ++++++------------ ly/property-init.ly | 2 +- scm/output-ps.scm | 8 +++-- scm/paper.scm | 3 +- 9 files changed, 68 insertions(+), 73 deletions(-) diff --git a/ChangeLog b/ChangeLog index dcebb01733..889635c3e9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2004-12-30 Han-Wen Nienhuys + + * scm/paper.scm (layout-set-staff-size): use text-font-size in + dimension less points (ie. 12 = 12 point) + + * lily/pango-select.cc (select_pango_font): use find_scaled_font(). + + * lily/all-font-metrics.cc (find_pango_font): set description_ + + * lily/pango-font.cc (text_stencil): export size as well. + (text_stencil): fix scaling and extents box. + 2004-12-29 Han-Wen Nienhuys * Documentation/topdocs/NEWS.texi (Top): add -f texstr diff --git a/lily/all-font-metrics.cc b/lily/all-font-metrics.cc index c681c03c9d..5425542816 100644 --- a/lily/all-font-metrics.cc +++ b/lily/all-font-metrics.cc @@ -26,7 +26,7 @@ All_font_metrics::All_font_metrics (String path) otf_dict_ = new Scheme_hash_table; #if HAVE_PANGO_FT2 - PangoFontMap*pfm = pango_ft2_font_map_new (); + PangoFontMap*pfm = pango_ft2_font_map_new (); pango_ft2_fontmap_ = G_TYPE_CHECK_INSTANCE_CAST(pfm, @@ -47,6 +47,11 @@ All_font_metrics::~All_font_metrics () scm_gc_unprotect_object (afm_dict_->self_scm ()); scm_gc_unprotect_object (tfm_dict_->self_scm ()); scm_gc_unprotect_object (otf_dict_->self_scm ()); + +#if HAVE_PANGO_FT2 + scm_gc_unprotect_object (pango_dict_->self_scm ()); + g_object_unref (pango_ft2_fontmap_); +#endif } All_font_metrics::All_font_metrics (All_font_metrics const&) @@ -66,7 +71,6 @@ All_font_metrics::find_pango_font (PangoFontDescription*description) if (verbose_global_b) progress_indication ("[" + String (fn)); Pango_font *pf = new Pango_font (pango_ft2_fontmap_, - pango_dpi_, RIGHT, description); val = pf->self_scm (); @@ -75,6 +79,9 @@ All_font_metrics::find_pango_font (PangoFontDescription*description) if (verbose_global_b) progress_indication ("]"); + + pf->description_ = scm_cons (SCM_BOOL_F, + scm_make_real (1.0)); } g_free (fn); return dynamic_cast (unsmob_metrics (val)); diff --git a/lily/include/dimensions.hh b/lily/include/dimensions.hh index e50c40f46b..bc93a975ae 100644 --- a/lily/include/dimensions.hh +++ b/lily/include/dimensions.hh @@ -40,6 +40,10 @@ const Real PT_TO_MM = (1.0 / MM_TO_PT); String print_dimen (Real); const Real point_constant = 1 PT; +const Real inch_constant = 1 INCH; +const Real cm_constant = 1 CM; +const Real mm_constant = 1 MM; +const Real bigpoint_constant = 1 BIGPOINT; #endif /* DIMENSIONS_HH */ diff --git a/lily/include/pango-font.hh b/lily/include/pango-font.hh index 13038a6ee5..36aa04c391 100644 --- a/lily/include/pango-font.hh +++ b/lily/include/pango-font.hh @@ -21,17 +21,12 @@ class Pango_font : public Font_metric { - /** handle to face object */ - FT_Face face_; PangoContext *context_; PangoAttrList *attribute_list_; Real scale_; SCM subfonts_; - Index_to_charcode_map index_to_charcode_map_; - public: Pango_font (PangoFT2FontMap *, - int dpi, Direction leftright, PangoFontDescription *); ~Pango_font (); @@ -42,8 +37,6 @@ public: virtual SCM sub_fonts () const; virtual void derived_mark () const; - virtual int name_to_index (String) const; - virtual unsigned index_to_charcode (int) const; }; PangoFontDescription * @@ -57,7 +50,8 @@ symbols_to_pango_font_description (SCM family, Font_metric * select_pango_font (Output_def *layout, SCM chain); -#endif /* HAVE_PANGO16 */ +const int PANGO_DPI = 1200; +#endif /* HAVE_PANGO16 */ #endif /* PANGO_FONT_HH */ diff --git a/lily/pango-font.cc b/lily/pango-font.cc index 4e9dfd8061..dd93df8d6a 100644 --- a/lily/pango-font.cc +++ b/lily/pango-font.cc @@ -12,6 +12,7 @@ #include +#include "dimensions.hh" #include "pango-font.hh" #if HAVE_PANGO_FT2 @@ -19,7 +20,6 @@ Pango_font::Pango_font (PangoFT2FontMap *fontmap, - int resolution, Direction dir, PangoFontDescription *description) { @@ -27,9 +27,11 @@ Pango_font::Pango_font (PangoFT2FontMap *fontmap, PangoDirection pango_dir = (dir == RIGHT) ? PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL; - context_ = pango_ft2_font_map_create_context (fontmap); + context_ = + pango_ft2_get_context (PANGO_DPI, PANGO_DPI); + // context_ = pango_ft2_font_map_create_context (fontmap); attribute_list_= pango_attr_list_new(); - scale_ = 1.0 / (PANGO_SCALE * resolution * 72.27); + scale_ = inch_constant / (Real (PANGO_SCALE) * Real (PANGO_DPI)); pango_context_set_language (context_, pango_language_from_string ("en_US")); pango_context_set_base_dir (context_, pango_dir); @@ -45,8 +47,7 @@ Pango_font::~Pango_font () void Pango_font::register_font_file (String filename, String ps_name) { - subfonts_ = scm_cons (//scm_cons (scm_makfrom0str (ps_name.to_str0 ()), - scm_makfrom0str (filename.to_str0 ()), + subfonts_ = scm_cons (scm_makfrom0str (filename.to_str0 ()), subfonts_); } @@ -77,30 +78,23 @@ Pango_font::text_stencil (String str) const PangoAnalysis *pa = &(item->analysis); PangoGlyphString *pgs = pango_glyph_string_new (); - pango_shape (str.to_str0 (), str.length (), pa, pgs); + pango_shape (str.to_str0 () + item->offset, + item->length, pa, pgs); PangoRectangle logical_rect; - pango_glyph_string_extents (pgs, pa->font, NULL, &logical_rect); + PangoRectangle ink_rect; + pango_glyph_string_extents (pgs, pa->font, &ink_rect, &logical_rect); PangoFcFont *fcfont = G_TYPE_CHECK_INSTANCE_CAST(pa->font, PANGO_TYPE_FC_FONT, PangoFcFont); - FT_Face ftface = pango_fc_font_lock_face (fcfont); - Box b (Interval (0, logical_rect.width), - Interval (0, logical_rect.height)); - - if (!face_) - { - /* FIXME. This obvious shortcut apparently does not work. - It seems there are different faces per text string and a - map of face_ and charcode mapping is needed. */ - Pango_font *barf = (Pango_font*) this; - barf->face_ = ftface; - barf->index_to_charcode_map_ = make_index_to_charcode_map (face_); - } - - b.translate (Offset (- logical_rect.x, -logical_rect.y)); + FT_Face ftface = pango_fc_font_lock_face (fcfont); + Box b (Interval (PANGO_LBEARING(logical_rect), + PANGO_RBEARING(logical_rect)), + Interval (-PANGO_DESCENT(logical_rect), + PANGO_ASCENT(logical_rect))); + b.scale (scale_); SCM glyph_exprs = SCM_EOL; @@ -111,7 +105,7 @@ Pango_font::text_stencil (String str) const PangoGlyph pg = pgi->glyph; PangoGlyphGeometry ggeo = pgi->geometry; - + FT_Get_Glyph_Name (ftface, pg, glyph_name, GLYPH_NAME_LEN); *tail = scm_cons (scm_list_3 (scm_from_double (ggeo.x_offset * scale_), scm_from_double (ggeo.y_offset * scale_), @@ -119,7 +113,10 @@ Pango_font::text_stencil (String str) const SCM_EOL); tail = SCM_CDRLOC (*tail); } - + PangoFontDescription *descr = pango_font_describe (pa->font); + Real size = pango_font_description_get_size (descr) + / (Real (PANGO_SCALE)) ; + FcPattern *fcpat = fcfont->font_pattern; char *filename = 0; FcPatternGetString(fcpat, FC_FILE, 0, (FcChar8 **) &filename); @@ -127,8 +124,8 @@ Pango_font::text_stencil (String str) const ((Pango_font *) this)->register_font_file (filename, ps_name); SCM expr = scm_list_4 (ly_symbol2scm ("glyph-string"), - self_scm (), scm_makfrom0str (ps_name), + scm_from_double (size), ly_quote_scm (glyph_exprs)); Stencil item_stencil (b, expr); @@ -154,21 +151,6 @@ Pango_font::font_file_name () const return SCM_BOOL_F; } -int -Pango_font::name_to_index (String nm) const -{ - char *nm_str = (char*) nm.to_str0 (); - if (int idx = FT_Get_Name_Index (face_, nm_str)) - return idx; - return -1; -} - -unsigned -Pango_font::index_to_charcode (int i) const -{ - return ((Pango_font*) this)->index_to_charcode_map_[i]; -} - LY_DEFINE (ly_pango_font_p, "ly:pango-font?", 1, 0, 0, (SCM f), diff --git a/lily/pango-select.cc b/lily/pango-select.cc index 0e1aa8929c..71553a1a91 100644 --- a/lily/pango-select.cc +++ b/lily/pango-select.cc @@ -22,6 +22,13 @@ select_pango_font (Output_def *layout, SCM chain) { String name_str = ly_scm2string (scm_cdr (name)); description = pango_font_description_from_string (name_str.to_str0 ()); + + + Real step = robust_scm2double (ly_symbol2scm ("font-size"), 0.0); + Real size = layout->get_dimension (ly_symbol2scm ("text-font-size")) + * pow (2.0, step / 6.0); + pango_font_description_set_size (description, + gint (size * PANGO_SCALE)); } else { @@ -47,25 +54,9 @@ select_pango_font (Output_def *layout, SCM chain) Font_metric * fm = all_fonts_global->find_pango_font (description); - /* - Klutz the pango font into font table, otherwise it doesn't show up - in the output. - */ - SCM font_table = get_font_table (layout); - SCM sizes = scm_hashq_ref (font_table, fm->self_scm (), SCM_BOOL_F); - if (sizes != SCM_BOOL_F) - { - SCM met = scm_assoc (scm_make_real (1.0), sizes); - if (scm_is_pair (met)) - return unsmob_metrics (scm_cdr (met)); - } - else - sizes = SCM_EOL; - - sizes = scm_acons (scm_make_real (1.0), fm->self_scm(), sizes); - scm_hashq_set_x (font_table, fm->self_scm (), sizes); - - return fm; + return find_scaled_font (layout, fm, 1.0, + ly_symbol2scm ("latin1"), + ly_symbol2scm ("latin1")); } diff --git a/ly/property-init.ly b/ly/property-init.ly index f8fc46ef4e..8103849c65 100644 --- a/ly/property-init.ly +++ b/ly/property-init.ly @@ -135,7 +135,7 @@ arpeggioBracket = \sequential { glissando = #(make-music 'GlissandoEvent) -fermataMarkup = \markup { \musicglyph #"scripts-ufermata" } +fermataMarkup = \markup { \musicglyph #"scripts.ufermata" } hideNotes =\sequential { % hide notes, accidentals, etc. diff --git a/scm/output-ps.scm b/scm/output-ps.scm index 6899b74780..de24d38063 100644 --- a/scm/output-ps.scm +++ b/scm/output-ps.scm @@ -169,11 +169,15 @@ (string-append (ly:numbers->string (list breapth width depth height)) " draw_box")) -(define (glyph-string font postscript-font-name x-y-named-glyphs) + +(define (glyph-string + postscript-font-name + size + x-y-named-glyphs) (apply string-append (cons - (format #f " /~a findfont setfont " postscript-font-name) + (format #f " /~a findfont ~a output-scale div scalefont setfont " postscript-font-name size) (map (lambda (item) (format #f " ~a ~a rmoveto /~a glyphshow " (car item) diff --git a/scm/paper.scm b/scm/paper.scm index 8fd0b9a2f2..3f997b0885 100644 --- a/scm/paper.scm +++ b/scm/paper.scm @@ -32,7 +32,8 @@ (mm (eval 'mm m))) - (module-define! m 'text-font-size (* 12 (/ sz 20))) + (module-define! m 'text-font-size (* 12 (/ sz (* 20 pt)))) + (module-define! m 'outputscale ss) (module-define! m 'fonts (make-cmr-tree (/ sz (* 20 pt)))) (module-define! m 'staffheight sz) -- 2.39.2