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<Modified_font_metric *>
- (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?
*/
}
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);
}
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;
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;
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;
};
}
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<Pango_font *> (orig_))
{
- Stencil stc = pf->text_stencil (text, feta);
+ Stencil stc = pf->text_stencil (state, text, feta);
Box b = stc.extent_box ();
return scaled;
}
- return Font_metric::text_stencil (text, feta);
+ return Font_metric::text_stencil (state, text, feta);
}
Box
}
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);
}
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,
(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")
ly:stencil-translate
ly:stencil-translate-axis
ly:stencil?
- ly:text-dimension
ly:translator-description
ly:translator-name
ly:translator?
(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))