X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fmodified-font-metric.cc;h=e0fb13044d14d239858aa83ccd0fb0e4aa9dae84;hb=25190a4637753e6439c445d2d4fe9323b7945d32;hp=67f30b3f4fd0c4447e6bf993b27e091bf514d832;hpb=df56feefa28914b45532b0a31b24c304c162b497;p=lilypond.git diff --git a/lily/modified-font-metric.cc b/lily/modified-font-metric.cc index 67f30b3f4f..e0fb13044d 100644 --- a/lily/modified-font-metric.cc +++ b/lily/modified-font-metric.cc @@ -1,31 +1,31 @@ /* modified-font-metric.cc -- declare Modified_font_metric - + source file of the GNU LilyPond music typesetter - - (c) 1999--2004 Han-Wen Nienhuys + + (c) 1999--2006 Han-Wen Nienhuys */ #include +using namespace std; #include "modified-font-metric.hh" #include "pango-font.hh" #include "text-metrics.hh" #include "warn.hh" #include "stencil.hh" -#include "lookup.hh" #include "main.hh" Modified_font_metric::Modified_font_metric (Font_metric *fm, Real magnification) { magnification_ = magnification; - + SCM desc = fm->description_; Real total_mag = magnification * scm_to_double (scm_cdr (desc)); assert (total_mag); - - description_ = scm_cons (scm_car (desc), scm_make_real (total_mag)); + + description_ = scm_cons (scm_car (desc), scm_from_double (total_mag)); orig_ = fm; } @@ -42,57 +42,56 @@ Modified_font_metric::design_size () const return orig_->design_size (); } - -Box -Modified_font_metric::get_indexed_char (int i) const +Box +Modified_font_metric::get_indexed_char (vsize i) const { Box b = orig_->get_indexed_char (i); b.scale (magnification_); - return b; + return b; } -Box -Modified_font_metric::get_ascii_char (int i) const +Box +Modified_font_metric::get_ascii_char (vsize i) const { Box b = orig_->get_ascii_char (i); b.scale (magnification_); - return b; + return b; } -int +vsize Modified_font_metric::count () const { return orig_->count (); } Offset -Modified_font_metric::attachment_point (String s) const +Modified_font_metric::attachment_point (string s) const { Offset o = orig_->attachment_point (s); return o * magnification_; } Offset -Modified_font_metric::get_indexed_wxwy (int k) const +Modified_font_metric::get_indexed_wxwy (vsize k) const { Offset o = orig_->get_indexed_wxwy (k); return o * magnification_; } -int -Modified_font_metric::name_to_index (String s) const +vsize +Modified_font_metric::name_to_index (string s) const { return orig_->name_to_index (s); } -unsigned -Modified_font_metric::index_to_charcode (int i) const +vsize +Modified_font_metric::index_to_charcode (vsize i) const { return orig_->index_to_charcode (i); } -int -Modified_font_metric::index_to_ascii (int k) const +vsize +Modified_font_metric::index_to_ascii (vsize k) const { return orig_->index_to_ascii (k); } @@ -102,74 +101,74 @@ Modified_font_metric::derived_mark () const { } -/* TODO: put this klutchness behind ly:option switch. */ +/* TODO: put this klutchness behind ly:option switch. */ Box -Modified_font_metric::tex_kludge (String text) const +Modified_font_metric::tex_kludge (string text) const { Interval ydims; Real w = 0; - for (int i = 0; i < text.length (); i++) + for (ssize i = 0; i < text.length (); i++) { - switch (text[i]) + switch (text[i]) { case '\\': /* Accent marks use width of base letter */ - if (i +1 < text.length ()) - { - if (text[i+1]=='\'' || text[i+1]=='`' || text[i+1]=='"' - || text[i+1]=='^') - { - i++; - break; - } - /* For string width \\ is a \ and \_ is a _. */ - if (text[i+1]=='\\' || text[i+1]=='_') - break; - } - - for (i++; (i < text.length ()) && !isspace (text[i]) + if (i < text.length () - 1) + { + if (text[i + 1]=='\'' || text[i + 1]=='`' || text[i + 1]=='"' + || text[i + 1]=='^') + { + i++; + break; + } + /* For string width \\ is a \ and \_ is a _. */ + if (text[i + 1]=='\\' || text[i + 1]=='_') + break; + } + + for (i++; (i < text.length ()) && !isspace (text[i]) && text[i]!='{' && text[i]!='}'; i++) ; - + /* Compensate for the auto-increment in the outer loop. */ i--; break; - case '{': // Skip '{' and '}' + case '{': // Skip '{' and '}' case '}': break; - - default: + + default: Box b = get_ascii_char ((unsigned char)text[i]); - + /* Use the width of 'x' for unknown characters */ - if (b[X_AXIS].length () == 0) + if (b[X_AXIS].length () == 0) b = get_ascii_char ((unsigned char)'x'); - + w += b[X_AXIS].length (); ydims.unite (b[Y_AXIS]); break; } } - + if (ydims.is_empty ()) ydims = Interval (0, 0); - + return Box (Interval (0, w), ydims); } Stencil -Modified_font_metric::text_stencil (String text) const +Modified_font_metric::text_stencil (string text) const { - Box b; - if (Pango_font * pf = dynamic_cast (orig_)) + Box b; + if (Pango_font *pf = dynamic_cast (orig_)) { Stencil stc = pf->text_stencil (text); Box b = stc.extent_box (); b.scale (magnification_); - Stencil scaled(b, stc.expr()); + Stencil scaled (b, stc.expr ()); return scaled; } @@ -177,18 +176,21 @@ Modified_font_metric::text_stencil (String text) const } Box -Modified_font_metric::text_dimension (String text) const +Modified_font_metric::text_dimension (string text) const { - SCM stext = scm_makfrom0str (text.to_str0 ()); - Box b = lookup_tex_text_dimension (orig_, stext); - if (!b[Y_AXIS].is_empty ()) + SCM stext = scm_makfrom0str (text.c_str ()); + + Box b; + if (output_backend_global == "tex") { - b.scale (magnification_); - return b; - } + b = lookup_tex_text_dimension (orig_, stext); + + if (!b[Y_AXIS].is_empty ()) + { + b.scale (magnification_); + return b; + } - if (output_format_global == "tex") - { b = tex_kludge (text); return b; } @@ -197,21 +199,21 @@ Modified_font_metric::text_dimension (String text) const Real w = 0.0; - for (int i = 0; i < text.length (); i++) + for (ssize i = 0; i < text.length (); i++) { Box b = get_ascii_char ((unsigned char)text[i]); - + w += b[X_AXIS].length (); - ydims.unite (b[Y_AXIS]); + ydims.unite (b[Y_AXIS]); } if (ydims.is_empty ()) ydims = Interval (0, 0); - b = Box(Interval(0,w), ydims); + b = Box (Interval (0, w), ydims); return b; } -Font_metric* +Font_metric * Modified_font_metric::original_font () const { return orig_; @@ -220,11 +222,11 @@ Modified_font_metric::original_font () const SCM Modified_font_metric::sub_fonts () const { - return orig_->sub_fonts(); + return orig_->sub_fonts (); } - -String + +string Modified_font_metric::font_name () const { - return original_font ()->font_name(); + return original_font ()->font_name (); }