2 pfb.cc -- implement pfb conversion.
4 source file of the GNU LilyPond music typesetter
6 (c) 2004--2005 Han-Wen Nienhuys <hanwen@xs4all.nl>
13 #include "program-option.hh"
14 #include "source-file.hh"
15 #include "memory-stream.hh"
17 #include "open-type-font.hh"
22 pfb2pfa (Byte const *pfb, int length)
24 char *out = new char[1];
28 while (p < pfb + length)
39 | (p[2] << 16) | (p[3] << 24);
44 out = (char *)realloc (out, olen + seglen + 1);
45 char *outp = out + olen;
46 memcpy (outp, p, seglen);
52 unsigned outlength = (seglen * 2) + (seglen / 32) + 2;
54 out = (char *)realloc (out, olen + outlength + 1);
56 char *outp = out + olen;
57 for (int i = seglen; i--;)
59 sprintf (outp, "%02x", *p++);
76 LY_DEFINE (ly_pfb_to_pfa, "ly:pfb->pfa",
77 1, 0, 0, (SCM pfb_file_name),
78 "Convert the contents of a PFB file to PFA.")
80 SCM_ASSERT_TYPE (scm_is_string (pfb_file_name), pfb_file_name,
81 SCM_ARG1, __FUNCTION__, "string");
83 String file_name = ly_scm2string (pfb_file_name);
86 if (be_verbose_global)
87 progress_indication ("[" + file_name);
89 char *str = gulp_file (file_name, &len);
90 char *pfa = pfb2pfa ((Byte *)str, len);
92 SCM pfa_scm = scm_makfrom0str (pfa);
95 if (be_verbose_global)
96 progress_indication ("]");
101 LY_DEFINE (ly_ttf_to_pfa, "ly:ttf->pfa",
102 1, 0, 0, (SCM ttf_file_name),
103 "Convert the contents of a TTF file to Type42 PFA, returning it as "
106 SCM_ASSERT_TYPE (scm_is_string (ttf_file_name), ttf_file_name,
107 SCM_ARG1, __FUNCTION__, "string");
109 String file_name = ly_scm2string (ttf_file_name);
110 if (be_verbose_global)
111 progress_indication ("[" + file_name);
114 Memory_out_stream stream;
116 robust_scm2int (ly_get_option (ly_symbol2scm ("ttf-verbosity")), 0);
118 create_type42 (file_name.to_str0 (), (void*) &stream);
119 SCM asscm = scm_from_locale_stringn (stream.get_string (),
120 stream.get_length ());
122 if (be_verbose_global)
123 progress_indication ("]");
130 LY_DEFINE (ly_otf_to_cff, "ly:otf->cff",
131 1, 0, 0, (SCM otf_file_name),
132 "Convert the contents of a OTF file to CFF file, returning it as "
135 SCM_ASSERT_TYPE (scm_is_string (otf_file_name), otf_file_name,
136 SCM_ARG1, __FUNCTION__, "string");
138 String file_name = ly_scm2string (otf_file_name);
139 if (be_verbose_global)
140 progress_indication ("[" + file_name);
142 FT_Face face = open_ft_face (file_name);
143 String table = get_otf_table (face, "CFF ");
145 SCM asscm = scm_from_locale_stringn ((char*) table.get_bytes (),
148 if (be_verbose_global)
149 progress_indication ("]");