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