]> git.donarmstrong.com Git - lilypond.git/blob - lily/pfb-scheme.cc
Merge branch 'master' of /home/jcharles/GIT/Lily/. into translation
[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_pfb_2_pfa, "ly:pfb->pfa",
11            1, 0, 0, (SCM pfb_file_name),
12            "Convert the contents of a Type@tie{}1 font in PFB format"
13            " to PFA format.")
14 {
15   LY_ASSERT_TYPE (scm_is_string, pfb_file_name, 1);
16
17   string file_name = ly_scm2string (pfb_file_name);
18
19   debug_output ("[" + file_name); // start message on a new line
20
21   vector<char> pfb_string = gulp_file (file_name, 0);
22   char *pfa = pfb2pfa ((Byte *) &pfb_string[0], pfb_string.size ());
23
24   SCM pfa_scm = scm_from_latin1_string (pfa);
25   free (pfa);
26
27   debug_output ("]", false);
28
29   return pfa_scm;
30 }
31
32 LY_DEFINE (ly_otf_2_cff, "ly:otf->cff",
33            1, 1, 0, (SCM otf_file_name, SCM idx),
34            "Convert the contents of an OTF file to a CFF file,"
35            " returning it as a string.  The optional"
36            " @var{idx} argument is useful for OpenType/CFF collections (OTC)"
37            " only; it specifies the font index within the OTC.  The default"
38            " value of @var{idx} is@tie{}0.")
39 {
40   LY_ASSERT_TYPE (scm_is_string, otf_file_name, 1);
41
42   int i = 0;
43   if (!SCM_UNBNDP (idx))
44     {
45       LY_ASSERT_TYPE (scm_is_integer, idx, 2);
46       i = scm_to_int (idx);
47       if (i < 0)
48         {
49           warning (_ ("font index must be non-negative, using index 0"));
50           i = 0;
51         }
52     }
53
54   string file_name = ly_scm2string (otf_file_name);
55   debug_output ("[" + file_name); // start message on a new line
56
57   FT_Face face;
58   /* check whether font index is valid */
59   if (i > 0)
60     {
61       face = open_ft_face (file_name, -1);
62       if (i >= face->num_faces)
63         {
64           warning (_f ("font index %d too large for font `%s', using index 0",
65                        i, file_name.c_str ()));
66           i = 0;
67         }
68       FT_Done_Face (face);
69     }
70
71   face = open_ft_face (file_name, i);
72   string table = get_otf_table (face, "CFF ");
73
74   SCM asscm = scm_from_latin1_stringn ((char *) table.data (),
75                                        table.length ());
76   FT_Done_Face (face);
77
78   debug_output ("]", false);
79
80   return asscm;
81 }