X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fmodified-font-metric.cc;h=a3beb4daefa0665be7fd0bacef73fe19571e49ef;hb=8cf69a467ad7650f5ca9da6fe2dfd4c7c088b239;hp=ad43d756bc38f4dd74846abc50707dbcdb293f9d;hpb=a3765e1d290e5e49093e7ca7791bf3fe20be1726;p=lilypond.git diff --git a/lily/modified-font-metric.cc b/lily/modified-font-metric.cc index ad43d756bc..a3beb4daef 100644 --- a/lily/modified-font-metric.cc +++ b/lily/modified-font-metric.cc @@ -1,23 +1,38 @@ /* - modified-font-metric.cc -- declare Modified_font_metric + This file is part of LilyPond, the GNU music typesetter. - source file of the GNU LilyPond music typesetter + Copyright (C) 1999--2015 Han-Wen Nienhuys - (c) 1999--2007 Han-Wen Nienhuys + LilyPond is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + LilyPond is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with LilyPond. If not, see . */ #include using namespace std; #include "modified-font-metric.hh" #include "pango-font.hh" -#include "text-metrics.hh" #include "warn.hh" #include "stencil.hh" #include "main.hh" #include "program-option.hh" +Preinit_Modified_font_metric::Preinit_Modified_font_metric () +{ + orig_ = 0; +} + Modified_font_metric::Modified_font_metric (Font_metric *fm, - Real magnification) + Real magnification) { magnification_ = magnification; @@ -44,19 +59,17 @@ Modified_font_metric::design_size () const } Box -Modified_font_metric::get_indexed_char (vsize i) const +Modified_font_metric::get_indexed_char_dimensions (vsize i) const { - Box b = orig_->get_indexed_char (i); + Box b = orig_->get_indexed_char_dimensions (i); b.scale (magnification_); return b; } -Box -Modified_font_metric::get_ascii_char (vsize i) const +Real +Modified_font_metric::get_magnification () const { - Box b = orig_->get_ascii_char (i); - b.scale (magnification_); - return b; + return magnification_; } vsize @@ -66,7 +79,7 @@ Modified_font_metric::count () const } Offset -Modified_font_metric::attachment_point (string s) const +Modified_font_metric::attachment_point (const string &s) const { Offset o = orig_->attachment_point (s); return o * magnification_; @@ -79,7 +92,7 @@ Modified_font_metric::get_indexed_wxwy (vsize k) const return o * magnification_; } -vsize +size_t Modified_font_metric::name_to_index (string s) const { return orig_->name_to_index (s); @@ -91,80 +104,23 @@ Modified_font_metric::index_to_charcode (vsize i) const return orig_->index_to_charcode (i); } -vsize -Modified_font_metric::index_to_ascii (vsize k) const -{ - return orig_->index_to_ascii (k); -} - void Modified_font_metric::derived_mark () const { -} - -/* TODO: put this klutchness behind ly:option switch. */ -Box -Modified_font_metric::tex_kludge (string text) const -{ - Interval ydims; - Real w = 0; - for (ssize i = 0; i < text.length (); i++) - { - switch (text[i]) - { - case '\\': - /* Accent marks use width of base letter */ - 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 '}': - break; - - default: - Box b = get_ascii_char ((unsigned char)text[i]); - - /* Use the width of 'x' for unknown characters */ - 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); + if (orig_) + scm_gc_mark (orig_->self_scm ()); } Stencil -Modified_font_metric::text_stencil (string text) const +Modified_font_metric::text_stencil (Output_def *state, + const string &text, + bool feta, + const string &features_str) const { Box b; if (Pango_font *pf = dynamic_cast (orig_)) { - Stencil stc = pf->text_stencil (text); + Stencil stc = pf->text_stencil (state, text, feta, features_str); Box b = stc.extent_box (); @@ -173,45 +129,7 @@ Modified_font_metric::text_stencil (string text) const return scaled; } - return Font_metric::text_stencil (text); -} - -Box -Modified_font_metric::text_dimension (string text) const -{ - SCM stext = ly_string2scm (text); - - Box b; - if (get_output_backend_name () == "tex") - { - b = lookup_tex_text_dimension (orig_, stext); - - if (!b[Y_AXIS].is_empty ()) - { - b.scale (magnification_); - return b; - } - - b = tex_kludge (text); - return b; - } - - Interval ydims; - - Real w = 0.0; - - 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]); - } - if (ydims.is_empty ()) - ydims = Interval (0, 0); - - b = Box (Interval (0, w), ydims); - return b; + return Font_metric::text_stencil (state, text, feta, features_str); } Font_metric *