X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fvirtual-font-metric.cc;h=a2fd658558fc7913a325682b0e4d9e4895476ec9;hb=97ebd8b72cdd2db28ad8eb38629d51f285afff22;hp=7b66c5bfc126b130474aa50d1c9a2e292b6eaf07;hpb=7aabfb20c46e0a1de41698ddc6859ccd3a6dea85;p=lilypond.git diff --git a/lily/virtual-font-metric.cc b/lily/virtual-font-metric.cc index 7b66c5bfc1..a2fd658558 100644 --- a/lily/virtual-font-metric.cc +++ b/lily/virtual-font-metric.cc @@ -3,37 +3,56 @@ source file of the GNU LilyPond music typesetter -(c) 2002--2003 Han-Wen Nienhuys +(c) 2002--2004 Han-Wen Nienhuys */ #include "virtual-font-metric.hh" -#include "all-font-metrics.hh" -#include "main.hh" -#include "molecule.hh" -#include "paper-def.hh" +#include "all-font-metrics.hh" +#include "stencil.hh" +#include "output-def.hh" +#include "warn.hh" /* - passing DEF is ughish. Should move into paperdef? + passing DEF is ughish. Should move into layoutdef? */ -Virtual_font_metric::Virtual_font_metric (SCM name_list, - Real mag,Paper_def*def) +Virtual_font_metric::Virtual_font_metric (SCM font_list) { font_list_ = SCM_EOL; SCM *tail = &font_list_; - for (SCM s = name_list; gh_pair_p (s); s = gh_cdr (s)) + + SCM mag = SCM_EOL; + SCM name_list = SCM_EOL; + SCM *name_tail = &name_list; + + for (SCM s = font_list; scm_is_pair (s); s = scm_cdr (s)) { - SCM nm = gh_car (s); + if (Font_metric *fm = unsmob_metrics (scm_car (s))) + { + *tail = scm_cons (scm_car (s),SCM_EOL); + tail = SCM_CDRLOC (*tail); + + if (!scm_is_number (mag)) + /* Ugh. */ + mag = scm_cdr (fm->description_); - Font_metric *fm = def->find_font (nm, mag); - *tail = scm_cons (fm->self_scm(),SCM_EOL); - tail = SCM_CDRLOC (*tail); + *name_tail = scm_cons (scm_car (fm->description_), SCM_EOL); + name_tail = SCM_CDRLOC (*name_tail); + } } + + description_ = scm_cons (name_list, mag); +} + +Real +Virtual_font_metric::design_size () const +{ + return unsmob_metrics (scm_car (font_list_))-> design_size (); } void -Virtual_font_metric::derived_mark()const +Virtual_font_metric::derived_mark ()const { scm_gc_mark (font_list_); } @@ -42,65 +61,119 @@ int Virtual_font_metric::count () const { int k = 0; - for (SCM s = font_list_; gh_pair_p (s); s = gh_cdr (s)) - { - k+= unsmob_metrics (gh_car (s))->count (); - } - + for (SCM s = font_list_; scm_is_pair (s); s = scm_cdr (s)) + k += unsmob_metrics (scm_car (s))->count (); return k; } -Molecule +Stencil Virtual_font_metric::find_by_name (String glyph) const { - Molecule m; - for (SCM s = font_list_; m.empty_b () && gh_pair_p (s); s = gh_cdr (s)) - { - m = unsmob_metrics (gh_car (s))->find_by_name (glyph); - } + Stencil m; + for (SCM s = font_list_; m.is_empty () && scm_is_pair (s); s = scm_cdr (s)) + m = unsmob_metrics (scm_car (s))->find_by_name (glyph); return m; } - - Box -Virtual_font_metric::get_char (int code) const +Virtual_font_metric::get_ascii_char (int) const { - int last_k = 0; - for (SCM s = font_list_; gh_pair_p (s); s = gh_cdr (s)) + programming_error ("Virtual font metric cannot be indexed by ASCII."); + return Box (); +} + +Stencil +Virtual_font_metric::get_ascii_char_stencil (int ) const +{ + programming_error ("Virtual font metric cannot be indexed by ASCII."); + return Stencil (); +} + +Offset +Virtual_font_metric::get_indexed_wxwy (int code) const +{ + int total = 0; + for (SCM s = font_list_; scm_is_pair (s); s = scm_cdr (s)) { - Font_metric* fm = unsmob_metrics (gh_car (s)); - int k = last_k + fm->count (); - if (last_k <= code && code < k) - { - return fm->get_char (code - last_k); - } - last_k = k; + Font_metric *fm = unsmob_metrics (scm_car (s)); + if (code < total + fm->count ()) + return fm->get_indexed_wxwy (code - total); + total += fm->count (); } + return Offset (0,0); +} - - return Box(); +Box +Virtual_font_metric::get_indexed_char (int code) const +{ + int total = 0; + for (SCM s = font_list_; scm_is_pair (s); s = scm_cdr (s)) + { + Font_metric *fm = unsmob_metrics (scm_car (s)); + if (code < total + fm->count ()) + return fm->get_indexed_char (code - total); + total += fm->count (); + } + return Box (); +} + +int +Virtual_font_metric::name_to_index (String glyph) const +{ + Stencil m; + int total = 0; + for (SCM s = font_list_; m.is_empty () && scm_is_pair (s); s = scm_cdr (s)) + { + Font_metric *m = unsmob_metrics (scm_car (s)); + int k = m->name_to_index (glyph); + if (k >= 0) + return total + k; + + total += m->count (); + } + return -1; } - -Molecule -Virtual_font_metric::get_char_molecule (int code) const +Stencil +Virtual_font_metric::get_indexed_char_stencil (int code) const { - Molecule m ; - int last_k = 0; - for (SCM s = font_list_; gh_pair_p (s); s = gh_cdr (s)) + Stencil m ; + int total = 0; + + for (SCM s = font_list_; scm_is_pair (s); s = scm_cdr (s)) { - Font_metric* fm = unsmob_metrics (gh_car (s)); - int k = last_k + fm->count (); - if (last_k <= code && code < k) + Font_metric *fm = unsmob_metrics (scm_car (s)); + if (code < total + fm->count ()) { - m = fm->get_char_molecule (code - last_k); + /* Ugh. */ + m = fm->get_indexed_char_stencil (code - total); break; } - last_k = k; + total += fm->count (); } - return m; } - + + +SCM +Virtual_font_metric::get_font_list () const +{ + return font_list_; +} + +LY_DEFINE (ly_make_virtual_font, "ly:make-virtual-font", 0, 0, 1, + (SCM args), + "Make a virtual font metric from @var{args}, " + "a list of font objects.") +{ + Virtual_font_metric *fm = new Virtual_font_metric (args); + return scm_gc_unprotect_object (fm->self_scm ()); +} + +String +Virtual_font_metric::coding_scheme () const +{ + Font_metric *fm = unsmob_metrics (scm_car (font_list_)); + return fm->coding_scheme (); +}