]> git.donarmstrong.com Git - lilypond.git/blob - lily/modified-font-metric.cc
Issue 4550 (1/2) Avoid "using namespace std;" in included files
[lilypond.git] / lily / modified-font-metric.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1999--2015 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 using std::string;
30
31 Modified_font_metric::Modified_font_metric (Font_metric *fm,
32                                             Real magnification)
33 {
34   magnification_ = magnification;
35
36   SCM desc = fm->description_;
37
38   Real total_mag = magnification * scm_to_double (scm_cdr (desc));
39   assert (total_mag);
40
41   description_ = scm_cons (scm_car (desc), scm_from_double (total_mag));
42   orig_ = fm;
43 }
44
45 SCM
46 Modified_font_metric::make_scaled_font_metric (Font_metric *fm, Real scaling)
47 {
48   Modified_font_metric *sfm = new Modified_font_metric (fm, scaling);
49   return sfm->self_scm ();
50 }
51
52 Real
53 Modified_font_metric::design_size () const
54 {
55   return orig_->design_size ();
56 }
57
58 Box
59 Modified_font_metric::get_indexed_char_dimensions (vsize i) const
60 {
61   Box b = orig_->get_indexed_char_dimensions (i);
62   b.scale (magnification_);
63   return b;
64 }
65
66 Real
67 Modified_font_metric::get_magnification () const
68 {
69   return magnification_;
70 }
71
72 vsize
73 Modified_font_metric::count () const
74 {
75   return orig_->count ();
76 }
77
78 Offset
79 Modified_font_metric::attachment_point (const string &s) const
80 {
81   Offset o = orig_->attachment_point (s);
82   return o * magnification_;
83 }
84
85 Offset
86 Modified_font_metric::get_indexed_wxwy (vsize k) const
87 {
88   Offset o = orig_->get_indexed_wxwy (k);
89   return o * magnification_;
90 }
91
92 size_t
93 Modified_font_metric::name_to_index (string s) const
94 {
95   return orig_->name_to_index (s);
96 }
97
98 vsize
99 Modified_font_metric::index_to_charcode (vsize i) const
100 {
101   return orig_->index_to_charcode (i);
102 }
103
104 void
105 Modified_font_metric::derived_mark () const
106 {
107 }
108
109 Stencil
110 Modified_font_metric::text_stencil (Output_def *state,
111                                     const string &text, bool feta) const
112 {
113   Box b;
114   if (Pango_font *pf = dynamic_cast<Pango_font *> (orig_))
115     {
116       Stencil stc = pf->text_stencil (state, text, feta);
117
118       Box b = stc.extent_box ();
119
120       b.scale (magnification_);
121       Stencil scaled (b, stc.expr ());
122       return scaled;
123     }
124
125   return Font_metric::text_stencil (state, text, feta);
126 }
127
128 Font_metric *
129 Modified_font_metric::original_font () const
130 {
131   return orig_;
132 }
133
134 SCM
135 Modified_font_metric::sub_fonts () const
136 {
137   return orig_->sub_fonts ();
138 }
139
140 string
141 Modified_font_metric::font_name () const
142 {
143   return original_font ()->font_name ();
144 }