]> git.donarmstrong.com Git - lilypond.git/blob - lily/open-type-font.cc
*** empty log message ***
[lilypond.git] / lily / open-type-font.cc
1 /*
2   open-type-font.cc --  implement Open_type_font
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2004 Han-Wen Nienhuys <hanwen@xs4all.nl>
7
8 */
9
10 #include "warn.hh"
11 #include "open-type-font.hh"
12
13 #include <stdio.h>
14
15 SCM
16 Open_type_font::make_otf (String str)
17 {
18   Open_type_font * otf = new Open_type_font;
19   int error_code = FT_New_Face(freetype2_library, str.to_str0(),
20                                0, &(otf->face_));
21   
22   if (error_code == FT_Err_Unknown_File_Format)
23     {
24       error("Unsupported font format");
25     }
26   else if (error_code)
27     {
28       error ("Unknown error reading font file.");
29     }
30
31   return otf->self_scm ();
32 }
33
34 Open_type_font::~Open_type_font()
35 {
36   FT_Done_Face (face_);
37 }
38
39
40 Box
41 Open_type_font::get_indexed_char (int signed_idx) const
42 {
43   FT_UInt idx = signed_idx;
44   FT_Load_Glyph (face_,
45                    idx,
46                    FT_LOAD_NO_SCALE);
47
48   FT_Glyph_Metrics m = face_->glyph->metrics;
49   int hb = m.horiBearingX;
50   int vb = m.horiBearingY;
51   Box b (Interval (-hb, m.width - hb),
52          Interval (-vb, m.height - vb));
53   
54   return b;
55 }
56
57 int
58 Open_type_font::name_to_index (String nm) const
59 {
60   char * nm_str = (char * )nm.to_str0 ();
61   int idx = FT_Get_Name_Index (face_, nm_str);
62
63   if (idx == 0)
64     return -1;
65   else
66     return idx;
67 }
68
69
70 Real
71 Open_type_font::design_size () const
72 {
73   return 20.0;
74 }