]> 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 #if 0
16
17 void
18 enumerate_glyphs (FT_Face face)
19 {
20   FT_UInt glyph_index;
21   FT_ULong char_code = FT_Get_First_Char (face, &glyph_index);
22   while (gindex != 0)                                       
23   {                                                                
24     // ... do something with (charcode,gindex) pair ...               
25     FT_Get
26     charcode = FT_Get_Next_Char( face, charcode, &gindex );        
27   }                                                                
28 }
29
30 #endif
31
32 SCM
33 Open_type_font::make_otf (String str)
34 {
35   Open_type_font * otf = new Open_type_font;
36   int error_code = FT_New_Face(freetype2_library, str.to_str0(),
37                                0, &(otf->face_));
38
39   //  int code = FT_Set_Charmap (otf->face_, );   
40
41   
42   if (error_code == FT_Err_Unknown_File_Format)
43     {
44       error("Unsupported font format");
45     }
46   else if (error_code)
47     {
48       error ("Unknown error reading font file.");
49     }
50
51   return otf->self_scm ();
52 }
53
54 Open_type_font::~Open_type_font()
55 {
56   FT_Done_Face (face_);
57 }
58
59
60 Box
61 Open_type_font::get_indexed_char (int signed_idx)
62 {
63   FT_UInt idx = signed_idx;
64   int code = 
65     FT_Load_Glyph (face_,
66                    idx,
67                    FT_LOAD_NO_SCALE);
68
69   FT_Glyph_Metrics m = face->glyph->metrics;
70   Box b (Interval (0, m->width) - m->horiBearingX,
71          Interval (0, m->height) - m->horiBearingY);
72   
73   return b;
74 }
75
76 int
77 Open_type_font::name_to_index (String nm)
78 {
79   FT_String * nm_str = nm.to_str0 ();
80   int idx = FT_Get_Name_Index (face_, nm_str);
81
82   if (idx == 0)
83     return -1;
84   else
85     return idx;
86 }
87
88
89 Real
90 Open_type_font::get_design_size () const
91 {
92   return 20.0;
93 }