From edf9d00fea686457b4469b82a435d5dc3bf09a56 Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Sat, 13 Mar 2010 03:03:47 -0300 Subject: [PATCH] Add Output_def argument to Font_metric::text_stencil(). Side effects: - remove fontify-text, fontify-white-text - remove ly:text-dimension - remove output-ps.scm (text ) output expression. --- lily/font-metric-scheme.cc | 19 ------------------- lily/font-metric.cc | 5 ++++- lily/include/font-metric.hh | 5 ++++- lily/include/modified-font-metric.hh | 2 +- lily/include/pango-font.hh | 3 ++- lily/modified-font-metric.cc | 7 ++++--- lily/pango-font.cc | 3 ++- lily/text-interface.cc | 6 ++---- scm/output-ps.scm | 23 ----------------------- scm/safe-lily.scm | 1 - scm/stencil.scm | 15 --------------- 11 files changed, 19 insertions(+), 70 deletions(-) diff --git a/lily/font-metric-scheme.cc b/lily/font-metric-scheme.cc index 7f57e5d1c3..faa007aac5 100644 --- a/lily/font-metric-scheme.cc +++ b/lily/font-metric-scheme.cc @@ -119,25 +119,6 @@ LY_DEFINE (ly_font_glyph_name_to_charcode, "ly:font-glyph-name-to-charcode", return scm_from_unsigned_integer (fm->index_to_charcode (fm->name_to_index (ly_scm2string (name)))); } -LY_DEFINE (ly_text_dimension, "ly:text-dimension", - 2, 0, 0, - (SCM font, SCM text), - "Given the font metric in @var{font} and the string @var{text}," - " compute the extents of that text in that font. The return" - " value is a pair of number-pairs.") -{ - Box b; - Modified_font_metric *fm = dynamic_cast - (unsmob_metrics (font)); - - LY_ASSERT_SMOB (Font_metric, font, 1); - LY_ASSERT_TYPE (scm_is_string, text, 2); - Stencil stc (fm->text_stencil (ly_scm2string (text), false)); - return scm_cons (ly_interval2scm (stc.extent (X_AXIS)), - ly_interval2scm (stc.extent (Y_AXIS))); -} - - /* TODO: when are non string retvals allowed? */ diff --git a/lily/font-metric.cc b/lily/font-metric.cc index 291aa2333a..1ff7e47fc0 100644 --- a/lily/font-metric.cc +++ b/lily/font-metric.cc @@ -189,8 +189,11 @@ Font_metric::sub_fonts () const } Stencil -Font_metric::text_stencil (string, bool) const +Font_metric::text_stencil (Output_def* state, + string, bool) const { + (void) state; + programming_error ("Cannot get a text stencil from this font"); return Stencil (Box (), SCM_EOL); } diff --git a/lily/include/font-metric.hh b/lily/include/font-metric.hh index 7c83f94095..04e78f8e37 100644 --- a/lily/include/font-metric.hh +++ b/lily/include/font-metric.hh @@ -39,7 +39,10 @@ public: SCM description_; string file_name_; - virtual Stencil text_stencil (string, bool) const; + // Return stencil for given string. output_state may be modified to + // record the font. + virtual Stencil text_stencil (Output_def* output_state, + string text, bool music) const; // ugh. virtual Box text_dimension (string) const; diff --git a/lily/include/modified-font-metric.hh b/lily/include/modified-font-metric.hh index 7fa70e365d..35b7d5b4cc 100644 --- a/lily/include/modified-font-metric.hh +++ b/lily/include/modified-font-metric.hh @@ -28,7 +28,7 @@ struct Modified_font_metric : public Font_metric public: Box text_dimension (string) const; Box word_dimension (string) const; - Stencil text_stencil (string, bool) const; + Stencil text_stencil (Output_def* output_state, string, bool) const; static SCM make_scaled_font_metric (Font_metric *fm, Real magnification); size_t count () const; diff --git a/lily/include/pango-font.hh b/lily/include/pango-font.hh index b87550f716..31ce425485 100644 --- a/lily/include/pango-font.hh +++ b/lily/include/pango-font.hh @@ -53,7 +53,8 @@ public: Stencil pango_item_string_stencil (PangoGlyphItem const *, bool) const; - virtual Stencil text_stencil (string, bool) const; + virtual Stencil text_stencil (Output_def* output_state, + string text, bool music) const; virtual void derived_mark () const; }; diff --git a/lily/modified-font-metric.cc b/lily/modified-font-metric.cc index 47b19618bd..539a27173d 100644 --- a/lily/modified-font-metric.cc +++ b/lily/modified-font-metric.cc @@ -113,12 +113,13 @@ Modified_font_metric::derived_mark () const } Stencil -Modified_font_metric::text_stencil (string text, bool feta) const +Modified_font_metric::text_stencil (Output_def* state, + string text, bool feta) const { Box b; if (Pango_font *pf = dynamic_cast (orig_)) { - Stencil stc = pf->text_stencil (text, feta); + Stencil stc = pf->text_stencil (state, text, feta); Box b = stc.extent_box (); @@ -127,7 +128,7 @@ Modified_font_metric::text_stencil (string text, bool feta) const return scaled; } - return Font_metric::text_stencil (text, feta); + return Font_metric::text_stencil (state, text, feta); } Box diff --git a/lily/pango-font.cc b/lily/pango-font.cc index d08a9c8f40..6d18820b97 100644 --- a/lily/pango-font.cc +++ b/lily/pango-font.cc @@ -301,7 +301,8 @@ Pango_font::physical_font_tab () const } Stencil -Pango_font::text_stencil (string str, bool music_string) const +Pango_font::text_stencil (Output_def* state, + string str, bool music_string) const { return text_stencil (str, music_string, false); } diff --git a/lily/text-interface.cc b/lily/text-interface.cc index 5d20d6383f..abd31a2c69 100644 --- a/lily/text-interface.cc +++ b/lily/text-interface.cc @@ -75,10 +75,8 @@ Text_interface::interpret_string (SCM layout_smob, SCM_BOOL_F); SCM music_encodings = ly_lily_module_constant ("all-music-font-encodings"); - if (scm_memq (encoding, music_encodings) != SCM_BOOL_F) - return fm->text_stencil (str, true).smobbed_copy (); - else - return fm->text_stencil (str, false).smobbed_copy (); + bool is_music = (scm_memq (encoding, music_encodings) != SCM_BOOL_F); + return fm->text_stencil (layout, str, is_music).smobbed_copy (); } MAKE_SCHEME_CALLBACK_WITH_OPTARGS (Text_interface, interpret_markup, 3, 0, diff --git a/scm/output-ps.scm b/scm/output-ps.scm index 5b5a21c7f3..06b324b799 100644 --- a/scm/output-ps.scm +++ b/scm/output-ps.scm @@ -239,29 +239,6 @@ (define (resetrotation ang x y) "grestore ") - -(define (text font s) - ;; (ly:warning (_ "TEXT backend-command encountered in Pango backend")) - ;; (ly:warning (_ "Arguments: ~a ~a"" font str)) - - (let* ((space-length (cdar (ly:text-dimension font " "))) - (space-move (string-append (number->string space-length) - ;; how much precision do we need here? - " 0.0 rmoveto ")) - (out-vec (decode-byte-string s))) - - (string-append - (ps-font-command font) " " - (string-join - (vector->list - (vector-for-each - - (lambda (sym) - (if (eq? sym 'space) - space-move - (string-append "/" (symbol->string sym) " glyphshow"))) - out-vec)))))) - (define (unknown) "\n unknown\n") diff --git a/scm/safe-lily.scm b/scm/safe-lily.scm index 894680ffc3..8a8faeba13 100644 --- a/scm/safe-lily.scm +++ b/scm/safe-lily.scm @@ -139,7 +139,6 @@ ly:stencil-translate ly:stencil-translate-axis ly:stencil? - ly:text-dimension ly:translator-description ly:translator-name ly:translator? diff --git a/scm/stencil.scm b/scm/stencil.scm index ce544ef66b..5e32f1efbb 100644 --- a/scm/stencil.scm +++ b/scm/stencil.scm @@ -316,21 +316,6 @@ encloses the contents. (set! stencil (ly:stencil-add outer inner)) stencil)) - -(define-public (fontify-text font-metric text) - "Set TEXT with font FONT-METRIC, returning a stencil." - (let* ((b (ly:text-dimension font-metric text))) - (ly:make-stencil - `(text ,font-metric ,text) (car b) (cdr b)))) - -(define-public (fontify-text-white scale font-metric text) - "Set TEXT with scale factor SCALE" - (let* ((b (ly:text-dimension font-metric text)) - ;;urg -- workaround for using ps font - (c `(white-text ,(* 2 scale) ,text))) - ;;urg -- extent is not from ps font, but we hope it's close - (ly:make-stencil c (car b) (cdr b)))) - (define-public (stencil-with-color stencil color) (ly:make-stencil (list 'color color (ly:stencil-expr stencil)) -- 2.39.2