Fix Debian #368733: implement fontconfig support
[synfig.git] / synfig-core / trunk / src / modules / lyr_freetype / lyr_freetype.cpp
index d4c244d..bd98e85 100644 (file)
@@ -3,16 +3,18 @@
 ** Template File
 ** $Id: lyr_freetype.cpp,v 1.5 2005/01/24 05:00:18 darco Exp $
 **
-** Copyright (c) 2002 Robert B. Quattlebaum Jr.
+**     Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
+**     Copyright (c) 2006 Paul Wise
 **
-** This software and associated documentation
-** are CONFIDENTIAL and PROPRIETARY property of
-** the above-mentioned copyright holder.
+**     This package is free software; you can redistribute it and/or
+**     modify it under the terms of the GNU General Public License as
+**     published by the Free Software Foundation; either version 2 of
+**     the License, or (at your option) any later version.
 **
-** You may not copy, print, publish, or in any
-** other way distribute this software without
-** a prior written agreement with
-** the copyright holder.
+**     This package is distributed in the hope that it will be useful,
+**     but WITHOUT ANY WARRANTY; without even the implied warranty of
+**     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+**     General Public License for more details.
 **
 ** === N O T E S ===========================================================
 **
@@ -28,6 +30,9 @@
 #ifdef HAVE_CONFIG_H
 #      include <config.h>
 #endif
+#ifdef WITH_FONTCONFIG
+#include <fontconfig/fontconfig.h>
+#endif
 
 #include "lyr_freetype.h"
 
@@ -365,6 +370,37 @@ lyr_freetype::new_face(const String &newfont)
        }
 #endif
 
+#ifdef WITH_FONTCONFIG
+       if(error)
+       {
+               FcFontSet *fs;
+               FcResult result;
+               if( !FcInit() )
+               {
+                       synfig::warning("lyr_freetype: fontconfig: %s",_("unable to initialise")));
+                       error = 1;
+               } else {
+                       FcPattern* pat = FcNameParse((FcChar8 *) newfont.c_str());
+                       FcConfigSubstitute(0, pat, FcMatchPattern);
+                       FcDefaultSubstitute(pat);
+                       FcPattern *match;
+                       fs = FcFontSetCreate();
+                       match = FcFontMatch(0, pat, &result);
+                       if (match)
+                               FcFontSetAdd(fs, match);
+                       if (pat)
+                               FcPatternDestroy(pat);
+                       if(fs){
+                               FcChar8* file;
+                               if( FcPatternGetString (fs->fonts[0], FC_FILE, 0, &file) == FcResultMatch )
+                                       error=FT_New_Face(ft_library,(const char*)file,face_index,&face);
+                               FcFontSetDestroy(fs);
+                       } else
+                               synfig::warning("lyr_freetype: fontconfig: %s",_("empty font set")));
+               }
+       }
+#endif
+
 #ifdef WIN32
        if(error)error=FT_New_Face(ft_library,("C:\\WINDOWS\\FONTS\\"+newfont).c_str(),face_index,&face);
        if(error)error=FT_New_Face(ft_library,("C:\\WINDOWS\\FONTS\\"+newfont+".ttf").c_str(),face_index,&face);