]> git.donarmstrong.com Git - lilypond.git/blob - lily/pfb-scheme.cc
Web-ja: update introduction
[lilypond.git] / lily / pfb-scheme.cc
1
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"
7 #include "main.hh"
8 #include "warn.hh"
9
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,"
14            " pass through it.")
15 {
16   LY_ASSERT_TYPE (scm_is_string, type1_file_name, 1);
17
18   string file_name = ly_scm2string (type1_file_name);
19
20   debug_output ("[" + file_name); // start message on a new line
21
22   vector<char> type1_string = gulp_file (file_name, 0);
23   SCM pfa_scm;
24
25   if ((Byte) type1_string[0] == 0x80)
26     {
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 ());
30     }
31   else
32     {
33       /* The file is in PFA format. Pass it through. */
34       pfa_scm = scm_from_latin1_stringn (&type1_string[0],
35                                          type1_string.size ());
36     }
37
38   debug_output ("]", false);
39
40   return pfa_scm;
41 }
42
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.")
50 {
51   LY_ASSERT_TYPE (scm_is_string, otf_file_name, 1);
52
53   int i = 0;
54   if (!SCM_UNBNDP (idx))
55     {
56       LY_ASSERT_TYPE (scm_is_integer, idx, 2);
57       i = scm_to_int (idx);
58       if (i < 0)
59         {
60           warning (_ ("font index must be non-negative, using index 0"));
61           i = 0;
62         }
63     }
64
65   string file_name = ly_scm2string (otf_file_name);
66   debug_output ("[" + file_name); // start message on a new line
67
68   FT_Face face;
69   /* check whether font index is valid */
70   if (i > 0)
71     {
72       face = open_ft_face (file_name, -1);
73       if (i >= face->num_faces)
74         {
75           warning (_f ("font index %d too large for font `%s', using index 0",
76                        i, file_name.c_str ()));
77           i = 0;
78         }
79       FT_Done_Face (face);
80     }
81
82   face = open_ft_face (file_name, i);
83   string table = get_otf_table (face, "CFF ");
84
85   SCM asscm = scm_from_latin1_stringn ((char *) table.data (),
86                                        table.length ());
87   FT_Done_Face (face);
88
89   debug_output ("]", false);
90
91   return asscm;
92 }