Implemented font config file lister, except that it doesn't work.

Originally committed to SVN as r1453.
This commit is contained in:
Rodrigo Braz Monteiro 2007-07-29 01:47:18 +00:00
parent fec497a047
commit d256a61703
3 changed files with 34 additions and 11 deletions

View file

@ -43,8 +43,10 @@
#include "standard_paths.h"
#ifdef WIN32
#include "font_file_lister_freetype.h"
#define FontListerClass FreetypeFontFileLister
#else
#include "font_file_lister_fontconfig.h"
#define FontListerClass FontConfigFontFileLister
#endif
@ -68,13 +70,7 @@ FontFileLister::~FontFileLister() {
////////////////
// Get instance
void FontFileLister::GetInstance() {
if (!instance) {
#ifdef WIN32
instance = new FreetypeFontFileLister();
#else
instance = new FontConfigFontFileLister();
#endif
}
if (!instance) instance = new FontListerClass();
}

View file

@ -1,4 +1,4 @@
// Copyright (c) 2007, Rodrigo Braz Monteiro
// Copyright (c) 2007, David Lamparter, Rodrigo Braz Monteiro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
@ -46,7 +46,25 @@
wxArrayString FontConfigFontFileLister::DoGetFilesWithFace(wxString facename) {
wxArrayString results;
// TODO: implement this
// Code stolen from asa
FcPattern *final, *tmp1, *tmp2;
FcResult res;
FcChar8 *filename;
char buffer[1024];
strcpy(buffer,facename.mb_str(wxConvUTF8));
// Get data from fconfig or something
tmp1 = FcPatternBuild(NULL,FC_FAMILY, FcTypeString,buffer,NULL);
if (!tmp1) return results;
tmp2 = FcFontRenderPrepare(fontconf, tmp1, aux);
FcPatternDestroy(tmp1);
final = FcFontMatch(fontconf, tmp2, &res);
FcPatternDestroy(tmp2);
if (!final) return results;
if (FcPatternGetString(final, FC_FILE, 0, &filename) == FcResultMatch) {
results.Add(wxString((char*) filename,wxConvLocal));
}
FcPatternDestroy(final);
return results;
}
@ -55,14 +73,18 @@ wxArrayString FontConfigFontFileLister::DoGetFilesWithFace(wxString facename) {
//////////////
// Initialize
void FontConfigFontFileLister::DoInitialize() {
// TODO: implement this
fontconf = FcInitLoadConfigAndFonts();
aux = FcPatternCreate();
}
////////////
// Clean up
void FontConfigFontFileLister::DoClearData() {
// TODO: implement this
if (aux) FcPatternDestroy(aux);
#ifdef HAVE_FCFINI
FcFini();
#endif
}
#endif

View file

@ -39,6 +39,8 @@
////////////
// Includes
#include <fontconfig/fontconfig.h>
#include <fontconfig/fcfreetype.h>
#include "font_file_lister.h"
@ -47,6 +49,9 @@
class FontConfigFontFileLister : public FontFileLister {
friend class FontFileLister;
private:
FcConfig *fontconf;
FcPattern *aux;
wxArrayString DoGetFilesWithFace(wxString facename);
void DoInitialize();
void DoClearData();