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