2 modified-font-metric.cc -- declare Modified_font_metric
4 source file of the GNU LilyPond music typesetter
6 (c) 1999--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
11 #include "modified-font-metric.hh"
12 #include "pango-font.hh"
13 #include "text-metrics.hh"
17 #include "program-option.hh"
19 Modified_font_metric::Modified_font_metric (Font_metric
*fm
,
22 magnification_
= magnification
;
24 SCM desc
= fm
->description_
;
26 Real total_mag
= magnification
* scm_to_double (scm_cdr (desc
));
29 description_
= scm_cons (scm_car (desc
), scm_from_double (total_mag
));
34 Modified_font_metric::make_scaled_font_metric (Font_metric
*fm
, Real scaling
)
36 Modified_font_metric
*sfm
= new Modified_font_metric (fm
, scaling
);
37 return sfm
->self_scm ();
41 Modified_font_metric::design_size () const
43 return orig_
->design_size ();
47 Modified_font_metric::get_indexed_char (vsize i
) const
49 Box b
= orig_
->get_indexed_char (i
);
50 b
.scale (magnification_
);
55 Modified_font_metric::get_ascii_char (vsize i
) const
57 Box b
= orig_
->get_ascii_char (i
);
58 b
.scale (magnification_
);
63 Modified_font_metric::count () const
65 return orig_
->count ();
69 Modified_font_metric::attachment_point (string s
) const
71 Offset o
= orig_
->attachment_point (s
);
72 return o
* magnification_
;
76 Modified_font_metric::get_indexed_wxwy (vsize k
) const
78 Offset o
= orig_
->get_indexed_wxwy (k
);
79 return o
* magnification_
;
83 Modified_font_metric::name_to_index (string s
) const
85 return orig_
->name_to_index (s
);
89 Modified_font_metric::index_to_charcode (vsize i
) const
91 return orig_
->index_to_charcode (i
);
95 Modified_font_metric::index_to_ascii (vsize k
) const
97 return orig_
->index_to_ascii (k
);
101 Modified_font_metric::derived_mark () const
105 /* TODO: put this klutchness behind ly:option switch. */
107 Modified_font_metric::tex_kludge (string text
) const
111 for (ssize i
= 0; i
< text
.length (); i
++)
116 /* Accent marks use width of base letter */
117 if (i
< text
.length () - 1)
119 if (text
[i
+ 1]=='\'' || text
[i
+ 1]=='`' || text
[i
+ 1]=='"'
125 /* For string width \\ is a \ and \_ is a _. */
126 if (text
[i
+ 1]=='\\' || text
[i
+ 1]=='_')
130 for (i
++; (i
< text
.length ()) && !isspace (text
[i
])
131 && text
[i
]!='{' && text
[i
]!='}'; i
++)
134 /* Compensate for the auto-increment in the outer loop. */
138 case '{': // Skip '{' and '}'
143 Box b
= get_ascii_char ((unsigned char)text
[i
]);
145 /* Use the width of 'x' for unknown characters */
146 if (b
[X_AXIS
].length () == 0)
147 b
= get_ascii_char ((unsigned char)'x');
149 w
+= b
[X_AXIS
].length ();
150 ydims
.unite (b
[Y_AXIS
]);
155 if (ydims
.is_empty ())
156 ydims
= Interval (0, 0);
158 return Box (Interval (0, w
), ydims
);
162 Modified_font_metric::text_stencil (string text
) const
165 if (Pango_font
*pf
= dynamic_cast<Pango_font
*> (orig_
))
167 Stencil stc
= pf
->text_stencil (text
);
169 Box b
= stc
.extent_box ();
171 b
.scale (magnification_
);
172 Stencil
scaled (b
, stc
.expr ());
176 return Font_metric::text_stencil (text
);
180 Modified_font_metric::text_dimension (string text
) const
182 SCM stext
= ly_string2scm (text
);
185 if (get_output_backend_name () == "tex")
187 b
= lookup_tex_text_dimension (orig_
, stext
);
189 if (!b
[Y_AXIS
].is_empty ())
191 b
.scale (magnification_
);
195 b
= tex_kludge (text
);
203 for (ssize i
= 0; i
< text
.length (); i
++)
205 Box b
= get_ascii_char ((unsigned char)text
[i
]);
207 w
+= b
[X_AXIS
].length ();
208 ydims
.unite (b
[Y_AXIS
]);
210 if (ydims
.is_empty ())
211 ydims
= Interval (0, 0);
213 b
= Box (Interval (0, w
), ydims
);
218 Modified_font_metric::original_font () const
224 Modified_font_metric::sub_fonts () const
226 return orig_
->sub_fonts ();
230 Modified_font_metric::font_name () const
232 return original_font ()->font_name ();