~ubuntu-branches/ubuntu/precise/lilypond/precise

« back to all changes in this revision

Viewing changes to lily/font-config-scheme.cc

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Bushnell, BSG
  • Date: 2006-12-19 10:18:12 UTC
  • mfrom: (3.1.4 feisty)
  • Revision ID: james.westby@ubuntu.com-20061219101812-7awtjkp0i393wxty
Tags: 2.8.7-3
scripts/midi2ly.py: When setting DATADIR, find Lilypond python files
in the @TOPLEVEL_VERSION@ directory, not 'current'.  Patch thanks to
Chris Lamb (chris@chris-lamb.co.uk).  (Closes: #400550)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  font-config-scheme.cc -- implement FontConfig bindings.
 
3
 
 
4
  source file of the GNU LilyPond music typesetter
 
5
 
 
6
  (c) 2005--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
 
7
 
 
8
*/
 
9
 
 
10
#include "lily-guile.hh"
 
11
#include "std-string.hh"
 
12
 
 
13
#include <fontconfig/fontconfig.h>
 
14
 
 
15
void
 
16
display_fontset (FcFontSet *fs)
 
17
{
 
18
  int j;
 
19
  for (j = 0; j < fs->nfont; j++)
 
20
    {
 
21
      FcChar8 *font;
 
22
      FcChar8 *str;
 
23
 
 
24
      font = FcNameUnparse (fs->fonts[j]);
 
25
      if (FcPatternGetString (fs->fonts[j], FC_FILE, 0, &str) == FcResultMatch)
 
26
        printf ("FILE %s\n", str);
 
27
      if (FcPatternGetString (fs->fonts[j], FC_FAMILY, 0, &str) == FcResultMatch)
 
28
        printf ("family %s\n ", str);
 
29
      if (FcPatternGetString (fs->fonts[j],
 
30
                              "designsize", 0, &str) == FcResultMatch)
 
31
        printf ("designsize %s\n ", str);
 
32
      
 
33
      printf ("%s\n", (const char*) font);
 
34
      free (font);
 
35
    }
 
36
}
 
37
 
 
38
void
 
39
display_strlist (char const*what, FcStrList *slist)
 
40
{
 
41
  while (FcChar8 *dir = FcStrListNext (slist))
 
42
    {
 
43
      printf("%s: %s\n", what, dir);
 
44
    }
 
45
}
 
46
 
 
47
void
 
48
display_config (FcConfig *fcc)
 
49
{
 
50
  display_strlist ("Config files", FcConfigGetConfigFiles(fcc));
 
51
  display_strlist ("Config dir", FcConfigGetConfigDirs(fcc));
 
52
  display_strlist ("Font dir", FcConfigGetFontDirs(fcc));
 
53
}
 
54
 
 
55
void
 
56
display_list (FcConfig *fcc)
 
57
{
 
58
  FcPattern*pat = FcPatternCreate ();
 
59
 
 
60
  FcObjectSet *os = 0;
 
61
  if (!os)
 
62
    os = FcObjectSetBuild (FC_FAMILY, FC_STYLE, (char *) 0);
 
63
 
 
64
  FcFontSet *fs = FcFontList (fcc, pat, os);
 
65
  FcObjectSetDestroy (os);
 
66
  if (pat)
 
67
    FcPatternDestroy (pat);
 
68
 
 
69
  if (fs)
 
70
    {
 
71
      display_fontset (fs);
 
72
      FcFontSetDestroy (fs);
 
73
    }
 
74
}
 
75
 
 
76
 
 
77
LY_DEFINE (ly_font_config_get_font_file, "ly:font-config-get-font-file", 1, 0, 0,
 
78
           (SCM name),
 
79
           "Get the file for font @var{name}")
 
80
{
 
81
  SCM_ASSERT_TYPE (scm_is_string (name), name,
 
82
                   SCM_ARG1, __FUNCTION__, "string");
 
83
 
 
84
  
 
85
  FcPattern*pat = FcPatternCreate ();
 
86
  FcValue val;
 
87
  
 
88
  val.type = FcTypeString;
 
89
  val.u.s = (const FcChar8*)ly_scm2string (name).c_str (); // FC_SLANT_ITALIC;
 
90
  FcPatternAdd(pat, FC_FAMILY, val, FcFalse);
 
91
 
 
92
  FcResult result;
 
93
  SCM scm_result = SCM_BOOL_F;
 
94
 
 
95
  FcConfigSubstitute (NULL, pat, FcMatchFont);
 
96
  FcDefaultSubstitute (pat);
 
97
  
 
98
  pat = FcFontMatch(NULL, pat, &result);
 
99
  FcChar8 *str = 0;
 
100
  if (FcPatternGetString (pat, FC_FILE, 0, &str) == FcResultMatch)
 
101
    scm_result = scm_makfrom0str ((char const*) str);
 
102
 
 
103
  FcPatternDestroy (pat);
 
104
 
 
105
  return scm_result;
 
106
}
 
107
           
 
108
LY_DEFINE (ly_font_config_display_fonts, "ly:font-config-display-fonts", 0, 0, 0,
 
109
           (),
 
110
           "Dump a list of all fonts visible to FontConfig.")
 
111
{
 
112
  display_list (NULL);
 
113
  display_config (NULL);
 
114
  
 
115
  return SCM_UNSPECIFIED;
 
116
}
 
117
 
 
118