2004-04-06 Han-Wen Nienhuys <hanwen@xs4all.nl>
+ * lily/performance.cc (output): remap modulo 16.
+
* lily/text-item.cc (interpret_markup): whoops, variable
shadowing fixed.
* lily/piano-pedal-performer.cc (try_music): Compare symbols to
symbols, not symbols to strings.
+
* lily/piano-pedal-engraver.cc (try_music): Compare symbols to
symbols, not symbols to strings.
return b;
}
+int
+Adobe_font_metric::index_to_ascii (int code) const
+{
+ return font_info_->cmi[code].code;
+}
+
Box
Adobe_font_metric::get_indexed_char (int code) const
{
return 1/1000.0 PT * Offset (mi->wx, mi->wy);
}
-/*
- return a stencil, without fontification
- */
-Stencil
-Adobe_font_metric::find_by_name (String s) const
-{
- AFM_CharMetricInfo const *cm = find_char_metric (s);
-
- if (!cm)
- {
- /* FIXME: Why don't we return empty? */
- Stencil m;
- m.set_empty (false);
- return m;
- }
-
- SCM at = (scm_list_2 (ly_symbol2scm ("char"), scm_int2num (cm->code)));
-
-#if 0
- at = fontify_atom ((Font_metric*) this, at);
-#endif
- Box b = afm_bbox_to_box (cm->charBBox);
- return Stencil (b, at);
-}
-
Real
Adobe_font_metric::design_size () const
{
return "FontSpecific";
}
-
-
+Stencil
+Font_metric::find_by_name (String s) const
+{
+ int idx = name_to_index (s);
+ Box b;
+
+ SCM expr = SCM_EOL;
+ if (idx >= 0)
+ {
+ expr = scm_list_3 (ly_symbol2scm ("char"),
+ self_scm (),
+ gh_int2scm (index_to_ascii (idx)));
+ b = get_indexed_char (idx);
+ }
+
+ Stencil q (b, expr);
+ return q;
+}
Font_metric::Font_metric ()
{
IMPLEMENT_DEFAULT_EQUAL_P (Font_metric);
IMPLEMENT_TYPE_P (Font_metric, "ly:font-metric?");
-Stencil
-Font_metric::find_by_name (String) const
-{
- Stencil m;
- return m;
-}
LY_DEFINE (ly_find_glyph_by_name, "ly:find-glyph-by-name",
2, 0, 0,
return gh_double2scm (fm->design_size ());
}
+
+
+int
+Font_metric::index_to_ascii (int i) const
+{
+ return i;
+}
+
Stencil
Font_metric::get_ascii_char_stencil (int code) const
{
virtual int name_to_index (String) const;
virtual int count () const;
+ virtual int index_to_ascii (int) const;
virtual Box get_ascii_char (int) const;
virtual Box get_indexed_char (int) const;
virtual Offset get_indexed_wxwy (int) const;
virtual String coding_scheme () const;
-
- AFM_CharMetricInfo const *find_char_metric (String name) const;
- AFM_CharMetricInfo const *find_ascii_metric (int) const;
-
- String to_string () const;
static SCM make_afm (AFM_Font_info*, unsigned, Real);
virtual Real design_size () const;
protected:
+ AFM_CharMetricInfo const *find_char_metric (String name) const;
+ AFM_CharMetricInfo const *find_ascii_metric (int) const;
+
Array<int> ascii_to_metric_idx_;
std::map<String,int> name_to_metric_dict_;
Adobe_font_metric (AFM_Font_info*);
- virtual Stencil find_by_name (String) const;
};
SCM read_afm_file (String);
virtual Box get_indexed_char (int index) const;
virtual Box get_ascii_char (int ascii) const;
virtual int name_to_index (String) const;
+ virtual int index_to_ascii (int) const;
virtual Real design_size () const;
virtual Stencil find_by_name (String) const;
virtual Stencil get_indexed_char_stencil (int k) const;
virtual Stencil get_ascii_char_stencil (int k) const;
virtual String coding_scheme () const;
- //static int get_encoded_index (Font_metric *m, String input_coding, int code);
DECLARE_SMOBS (Font_metric,);
Box text_dimension (String);
- virtual Stencil find_by_name (String) const;
- static SCM make_scaled_font_metric (Font_metric*, Real);
+ static SCM make_scaled_font_metric (SCM, Font_metric*, Real);
virtual int count () const;
virtual Offset get_indexed_wxwy (int) const;
virtual int name_to_index (String) const;
virtual String coding_scheme () const;
+ /*should be protected?
+ */
+ SCM coding_vector_;
+ SCM coding_table_;
+ SCM coding_permutation_;
+
protected:
virtual Real design_size () const;
virtual void derived_mark ();
- virtual Box get_indexed_char (int)const;
+ virtual Box get_indexed_char (int) const;
+ virtual int index_to_ascii (int) const;
virtual Box get_ascii_char (int) const;
Font_metric *orig_;
Real magnification_;
String coding_scheme_;
- SCM coding_vector_;
+
- Modified_font_metric (Font_metric*, Real);
+ Modified_font_metric (String, Font_metric*, Real);
Box tex_kludge (String) const;
};
Array<Tfm_kern> kerns_;
Array<Tfm_ligature> ligatures_;
- String to_string () const;
Tex_font_char_metric ();
Box dimensions () const;
virtual Box get_ascii_char (int) const;
virtual Real design_size () const;
virtual String coding_scheme () const;
+ virtual void derived_mark () const;
+ virtual int name_to_index (String) const;
- Tex_font_char_metric const *find_ascii (int ascii, bool warn=true) const;
-
- String to_string () const;
Tfm_info info_;
Tfm_header header_;
Array<Tex_font_char_metric> char_metrics_;
Array<int> ascii_to_metric_idx_;
-
+ SCM encoding_table_;
+
private:
+ Tex_font_char_metric const *find_ascii (int ascii, bool warn=true) const;
Tex_font_metric ();
};
warning (_f ("kpathsea can not find TFM file: `%s'", name));
else
return name_ptr;
-
#endif
+
return "";
}
initialize_kpathsea (char *av0)
{
#if KPATHSEA && HAVE_KPATHSEA_KPATHSEA_H
- /*
- We take two pronged approach to tfms:
-
- * the lilypond tfms (feta*.tfm) are found through our own routines.
-
- * the TeX tfms are found through vanilla kpathsea.
-
- (* other TFMs are not found, i.e. don't use them. )
-
- PRO:
-
- - TFM and AFM checksums always match in Lily.
-
- - less hassle, no kpathsea spaghetti
-
- CON:
-
- - feta PK files are often recreated, locally
- Solution: cache PK files locally?
-
- - need env. vars to make sure that TeX finds the TFMs
-
- - Outdated PK (TFM?) font files are not automatically removed,
- since VERSION is not part of the standard location.
-
-
- ALTERNATIVE
-
- we have tried to come up with schemes that leave this kind of work
- to kpathsea with objective of fixing the CONs, but miserably
- failed. TeX installations and kpathsea itself form a buggy,
- inconsistent, and unorderly mess.
-
- */
/*
initialize kpathsea
else
{
SCM scale_var = ly_module_lookup (scope_, ly_symbol2scm ("outputscale"));
+ SCM coding_var = ly_module_lookup (scope_, ly_symbol2scm ("inputcoding"));
m /= gh_scm2double (scm_variable_ref (scale_var));
-
- val = Modified_font_metric::make_scaled_font_metric (f, m);
+ val = Modified_font_metric::make_scaled_font_metric (scm_variable_ref (coding_var),
+ f, m);
}
sizes = scm_acons (gh_double2scm (m), val, sizes);
MIDI players tend to ignore instrument settings on
channel 10, the percussion channel by default.
*/
- if (channel == 9)
+ if (channel % 16 == 9)
channel++;
*/
if (s->channel_ < 0)
{
- s->channel_ = channel <? 15;
+ s->channel_ = channel % 16;
if (channel > 15)
- warning ("MIDI channel wrapped around. Mapping to channel 15.");
+ warning ("MIDI channel wrapped around. Remapping modulo 16.");
}
s->output (midi_stream, channel++);
#include "string.hh"
#include "stencil.hh"
-Modified_font_metric::Modified_font_metric (Font_metric* m, Real magn)
+Modified_font_metric::Modified_font_metric (String coding, Font_metric* m, Real magn)
{
- coding_vector_ = SCM_EOL;
+ coding_vector_ = SCM_EOL;
+ coding_permutation_ = SCM_EOL;
+ coding_table_ = SCM_EOL;
+
+ coding_scheme_ = coding;
magnification_ = magn;
SCM desc = m->description_;
}
SCM
-Modified_font_metric::make_scaled_font_metric (Font_metric *m, Real s)
+Modified_font_metric::make_scaled_font_metric (SCM coding, Font_metric *m, Real s)
{
- Modified_font_metric *sfm = new Modified_font_metric (m, s);
-
- sfm->coding_scheme_ = "TeX";
+ String scheme = ly_scm2string (coding);
+
+ Modified_font_metric *sfm = new Modified_font_metric (scheme, m, s);
return sfm->self_scm ();
}
return orig_->design_size ();
}
-Stencil
-Modified_font_metric::find_by_name (String s) const
-{
- Stencil m = orig_->find_by_name (s);
- Box b = m.extent_box ();
- b.scale (magnification_);
- Stencil q (b,fontify_atom ((Font_metric*) this, m.get_expr ()));
- return q;
-}
Box
Modified_font_metric::get_indexed_char (int i) const
return b;
}
-
int
Modified_font_metric::count () const
{
}
int
-Modified_font_metric::name_to_index (String s)const
+Modified_font_metric::name_to_index (String s) const
{
return orig_->name_to_index (s);
}
+int
+Modified_font_metric::index_to_ascii (int k) const
+{
+ return orig_->index_to_ascii (k);
+}
+
String
Modified_font_metric::coding_scheme () const
{
Modified_font_metric::derived_mark ()
{
scm_gc_mark (coding_vector_);
+ scm_gc_mark (coding_table_);
+ scm_gc_mark (coding_permutation_);
}
-
Box
Modified_font_metric::tex_kludge (String text) const
{
*/
for (int i = 0; i < text.length (); i++)
{
-
switch (text[i])
{
case '\\':
- // accent marks use width of base letter
+ // accent marks use width of base letter
if (i +1 < text.length ())
{
if (text[i+1]=='\'' || text[i+1]=='`' || text[i+1]=='"' ||
for (i++; (i < text.length ()) && !isspace (text[i])
&& text[i]!='{' && text[i]!='}'; i++)
;
+
// ugh.
i--; // Compensate for the increment in the outer loop!
break;
programming_error ("get-coding-vector should return vector");
coding_vector_ = scm_c_make_vector (256, ly_symbol2scm (".notdef"));
}
+
+ coding_table_ = scm_call_1 (ly_scheme_function ("get-coding-table"),
+ scm_makfrom0str (orig_->coding_scheme ().to_str0 ()));
+
+ coding_permutation_ = scm_call_2 (ly_scheme_function ("make-encoding-permutation"),
+ coding_vector_,
+ coding_table_);
}
Interval ydims;
b.scale (magnification_);
return b;
}
+
+
+LY_DEFINE (ly_font_enccoding, "ly:font-encoding", 1 , 0, 0,
+ (SCM font),
+ "Given the Modified_font_metric @var{font}, return a "
+ "list containing (input-coding, output-coding, permutation).")
+{
+ Modified_font_metric * fm = dynamic_cast<Modified_font_metric *> ( unsmob_metrics (font));
+ SCM_ASSERT_TYPE (fm, font, SCM_ARG1, __FUNCTION__, "Modified_font_metric");
+
+ return scm_list_3 (fm->coding_vector_,
+ fm->coding_table_,
+ fm->coding_permutation_);
+}
Paper_def *pap = unsmob_paper (paper);
Font_metric *fm = select_font (pap, props);
- SCM lst = scm_list_n (ly_symbol2scm ("text"), markup, SCM_UNDEFINED);
-
+ SCM lst = SCM_EOL;
Box b;
if (Modified_font_metric* mf = dynamic_cast<Modified_font_metric*> (fm))
{
- lst = fontify_atom (mf, lst);
+ lst = scm_list_3 (ly_symbol2scm ("text"),
+ mf->self_scm (),
+ markup);
b = mf->text_dimension (str);
}
(d >? height_)*point_constant));
}
-#define APPEND_CHAR_METRIC_ELT(k) \
- outstr += ::to_string (#k) + " " + ::to_string (k ## _) + "; "
-
-String
-Tex_font_char_metric::to_string () const
+Tex_font_metric::Tex_font_metric ()
{
- String outstr;
-
- APPEND_CHAR_METRIC_ELT (exists);
- APPEND_CHAR_METRIC_ELT (code);
- APPEND_CHAR_METRIC_ELT (width);
- APPEND_CHAR_METRIC_ELT (height);
- APPEND_CHAR_METRIC_ELT (depth);
- APPEND_CHAR_METRIC_ELT (italic_correction);
-
- return outstr + "\n";
+ encoding_table_ = SCM_EOL;
}
-Tex_font_metric::Tex_font_metric ()
+
+
+void
+Tex_font_metric::derived_mark () const
{
+ scm_gc_mark (encoding_table_);
}
Tex_font_char_metric const *
return b;
}
-String
-Tex_font_metric::to_string () const
-{
- String outstr;
- for (int i=0; i < char_metrics_.size (); i++)
- outstr += char_metrics_[i].to_string ();
- return outstr;
-}
-
SCM
Tex_font_metric::make_tfm (String filename)
{
tfm->char_metrics_ = reader.char_metrics_;
tfm->ascii_to_metric_idx_ = reader.ascii_to_metric_idx_;
+
+ tfm->encoding_table_ =
+ scm_call_1 (ly_scheme_function ("get-coding-table"),
+ scm_makfrom0str (tfm->info_.coding_scheme.to_str0 ()));
+
return tfm->self_scm ();
}
{
return info_.coding_scheme;
}
+
+int
+Tex_font_metric::name_to_index (String s) const
+{
+ SCM sym = ly_symbol2scm (s.to_str0 ());
+
+ SCM idx = scm_hash_ref (encoding_table_, sym, SCM_BOOL_F);
+ if (scm_integer_p (idx) == SCM_BOOL_T)
+ {
+ return gh_scm2int (idx);
+ }
+ else
+ return -1;
+}
pt = #(/ in 72.27)
cm = #(* 10 mm)
+ inputcoding = #"TeX"
raggedright = ##f
raggedlast = ##f
packed = ##f
+
#(define $is-paper #t)
#(define font-defaults
(vector-ref permutation (char->integer chr)))
str))
-(define-public (encoding-permutation input-encoding
- output-encoding)
+(define-public (make-encoding-permutation input-encoding
+ output-encoding)
"Contruct a permutation by applying output-encoding after input-encoding "
(list->vector
(map
- (lambda (chr)
+ (lambda (byte)
(let*
((new-char (hash-ref output-encoding
- (vector-ref input-encoding (char->integer chr)) #f)))
+ (vector-ref input-encoding byte) #f)))
;; substitute space for unknown characters.
(if (char? new-char)
("latin1" . "cork.enc")
;; LilyPond.
- ("feta braces" . "feta-braces0.enc")
+ ("feta braces" . "feta-braces-a.enc")
("feta number" . "feta-nummer10.enc")
("feta music" . "feta20.enc")
("parmesan music" . "parmesan20.enc"))
(define (get-coding coding-name)
(force (assoc-get coding-name coding-alist )))
-(define (get-coding-vector coding-name)
+(define-public (get-coding-vector coding-name)
(car (get-coding coding-name)))
-(define (get-coding-table coding-name)
+(define-public (get-coding-table coding-name)
(cadr (get-coding coding-name)))
(display "} } \n"))
-
(define default-qualifier-order
'(font-encoding font-family font-shape font-series))
(define (lookup-font node alist-chain)
(g-lookup-font node alist-chain))
-
-
;
; Each size family is a vector of fonts, loaded with a delay.
; The vector should be sorted according to ascending design size.
(list arch_angle arch_width arch_height height arch_thick thick))
" draw_bracket"))
-(define (char i)
+(define (char font i)
(string-append
+ (font-command font) " setfont "
"(\\" (ly:inexact->string i 8) ") show" ))
(define (comment s)
(string-append (ly:numbers->string (list breapth width depth height))
" draw_box"))
-(define (fontify font exp)
- (string-append (font-command font) " setfont " exp))
-
(define (header creator time-stamp page-count-)
(set! page-count page-count-)
(set! page-number 0)
(ly:numbers->string (list h w thick))
" draw_symmetric_x_triangle"))
-(define (text s)
+(define (text font s)
+
;; (string-append "(" (escape-parentheses s) ") show "))
- (string-append "(" (ps-encoding s) ") show"))
+ (string-append
+
+ (font-command font) " setfont "
+ "(" (ps-encoding s) ") show"))
(define (unknown)
"\n unknown\n")
#:re-export (quote)
#:export (define-fonts
font-command
- fontify
unknown
output-paper-def
output-scopes
start-page
stop-page
)
-)
+ )
(use-modules (ice-9 regex)
(ice-9 string-fun)
;;;;;;;; DOCUMENT ME!
;;;;;;;;
+
(define (font-command font)
(string-append
"magfont"
(apply string-append
(map (lambda (x) (font-load-command paper x)) font-list)))
-(define (fontify font exp)
- (string-append "\\" (font-command font) exp))
-
(define (unknown)
"%\n\\unknown\n")
(define (dashed-slur thick dash l)
(embedded-ps (list 'dashed-slur thick dash `(quote ,l))))
-(define (char i)
- (string-append "\\char" (ly:inexact->string i 10) " "))
+(define (char font i)
+ (string-append "\\" (font-command font)
+ "\\char" (ly:inexact->string i 10) " "))
(define (dashed-line thick on off dx dy)
(embedded-ps (list 'dashed-line thick on off dx dy)))
"\\def\\lilypondtagline{Engraved by LilyPond (version "
(lilypond-version)")}\n"))
-(define (invoke-char s i)
- (string-append
- "\n\\" s "{" (ly:inexact->string i 10) "}" ))
-
;; FIXME: explain ploblem: need to do something to make this really safe.
(define (output-tex-string s)
(if safe-mode?
(define (round-filled-box x y width height blotdiam)
(embedded-ps (list 'round-filled-box x y width height blotdiam)))
-(define (text s)
- (string-append "\\hbox{" (output-tex-string s) "}"))
+(define (text font s)
+ (let*
+ ((perm (caddr (ly:font-encoding font))))
+ (display (ly:font-encoding font))
+ (string-append "\\hbox{\\" (font-command font) "{}"
+ (output-tex-string
+ (if (vector? perm)
+ (reencode-string perm s)
+ s))
+ "}")))
(define (tuplet ht gapx dx dy thick dir)
(embedded-ps (list 'tuplet ht gapx dx dy thick dir)))
(string-append "\\special{src:" ;;; \\string ?
(point-and-click line col file)
"}" )
- "")
- )
+ ""))
;; no-origin not yet supported by Xdvi
(define (no-origin) "")