]> git.donarmstrong.com Git - lilypond.git/blob - lily/modified-font-metric.cc
1657cf5a9e68722954d8d67f6c4c4661b0206a35
[lilypond.git] / lily / modified-font-metric.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1999--2012 Han-Wen Nienhuys <hanwen@xs4all.nl>
5
6   LilyPond is free software: you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation, either version 3 of the License, or
9   (at your option) any later version.
10
11   LilyPond is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
18 */
19 #include <cctype>
20 using namespace std;
21
22 #include "modified-font-metric.hh"
23 #include "pango-font.hh"
24 #include "warn.hh"
25 #include "stencil.hh"
26 #include "main.hh"
27 #include "program-option.hh"
28
29 Modified_font_metric::Modified_font_metric (Font_metric *fm,
30                                             Real magnification)
31 {
32   magnification_ = magnification;
33
34   SCM desc = fm->description_;
35
36   Real total_mag = magnification * scm_to_double (scm_cdr (desc));
37   assert (total_mag);
38
39   description_ = scm_cons (scm_car (desc), scm_from_double (total_mag));
40   orig_ = fm;
41 }
42
43 SCM
44 Modified_font_metric::make_scaled_font_metric (Font_metric *fm, Real scaling)
45 {
46   Modified_font_metric *sfm = new Modified_font_metric (fm, scaling);
47   return sfm->self_scm ();
48 }
49
50 Real
51 Modified_font_metric::design_size () const
52 {
53   return orig_->design_size ();
54 }
55
56 Box
57 Modified_font_metric::get_indexed_char_dimensions (vsize i) const
58 {
59   Box b = orig_->get_indexed_char_dimensions (i);
60   b.scale (magnification_);
61   return b;
62 }
63
64 Real
65 Modified_font_metric::get_magnification () const
66 {
67   return magnification_;
68 }
69
70 vsize
71 Modified_font_metric::count () const
72 {
73   return orig_->count ();
74 }
75
76 Offset
77 Modified_font_metric::attachment_point (const string &s) const
78 {
79   Offset o = orig_->attachment_point (s);
80   return o * magnification_;
81 }
82
83 Offset
84 Modified_font_metric::get_indexed_wxwy (vsize k) const
85 {
86   Offset o = orig_->get_indexed_wxwy (k);
87   return o * magnification_;
88 }
89
90 size_t
91 Modified_font_metric::name_to_index (string s) const
92 {
93   return orig_->name_to_index (s);
94 }
95
96 vsize
97 Modified_font_metric::index_to_charcode (vsize i) const
98 {
99   return orig_->index_to_charcode (i);
100 }
101
102 void
103 Modified_font_metric::derived_mark () const
104 {
105 }
106
107 Stencil
108 Modified_font_metric::text_stencil (Output_def *state,
109                                     const string &text, bool feta) const
110 {
111   Box b;
112   if (Pango_font *pf = dynamic_cast<Pango_font *> (orig_))
113     {
114       Stencil stc = pf->text_stencil (state, text, feta);
115
116       Box b = stc.extent_box ();
117
118       b.scale (magnification_);
119       Stencil scaled (b, stc.expr ());
120       return scaled;
121     }
122
123   return Font_metric::text_stencil (state, text, feta);
124 }
125
126 Font_metric *
127 Modified_font_metric::original_font () const
128 {
129   return orig_;
130 }
131
132 SCM
133 Modified_font_metric::sub_fonts () const
134 {
135   return orig_->sub_fonts ();
136 }
137
138 string
139 Modified_font_metric::font_name () const
140 {
141   return original_font ()->font_name ();
142 }