2 #include "international.hh"
3 #include "program-option.hh"
4 #include "source-file.hh"
5 #include "memory-stream.hh"
6 #include "open-type-font.hh"
10 LY_DEFINE (ly_type1_2_pfa, "ly:type1->pfa",
11 1, 0, 0, (SCM type1_file_name),
12 "Convert the contents of a Type@tie{}1 font in PFB format"
13 " to PFA format. If the file is already in PFA format,"
16 LY_ASSERT_TYPE (scm_is_string, type1_file_name, 1);
18 string file_name = ly_scm2string (type1_file_name);
20 debug_output ("[" + file_name); // start message on a new line
22 vector<char> type1_string = gulp_file (file_name, 0);
25 if ((Byte) type1_string[0] == 0x80)
27 /* The file is in PFB format. Convert it to PFA format. */
28 vector<char> pfa = pfb2pfa (type1_string);
29 pfa_scm = scm_from_latin1_stringn (&pfa[0], pfa.size ());
33 /* The file is in PFA format. Pass it through. */
34 pfa_scm = scm_from_latin1_stringn (&type1_string[0],
35 type1_string.size ());
38 debug_output ("]", false);
43 LY_DEFINE (ly_otf_2_cff, "ly:otf->cff",
44 1, 1, 0, (SCM otf_file_name, SCM idx),
45 "Convert the contents of an OTF file to a CFF file,"
46 " returning it as a string. The optional"
47 " @var{idx} argument is useful for OpenType/CFF collections (OTC)"
48 " only; it specifies the font index within the OTC. The default"
49 " value of @var{idx} is@tie{}0.")
51 LY_ASSERT_TYPE (scm_is_string, otf_file_name, 1);
54 if (!SCM_UNBNDP (idx))
56 LY_ASSERT_TYPE (scm_is_integer, idx, 2);
60 warning (_ ("font index must be non-negative, using index 0"));
65 string file_name = ly_scm2string (otf_file_name);
66 debug_output ("[" + file_name); // start message on a new line
69 /* check whether font index is valid */
72 face = open_ft_face (file_name, -1);
73 if (i >= face->num_faces)
75 warning (_f ("font index %d too large for font `%s', using index 0",
76 i, file_name.c_str ()));
82 face = open_ft_face (file_name, i);
83 string table = get_otf_table (face, "CFF ");
85 SCM asscm = scm_from_latin1_stringn ((char *) table.data (),
89 debug_output ("]", false);