115 lines
3.3 KiB
Plaintext
115 lines
3.3 KiB
Plaintext
#define PERL_NO_GET_CONTEXT
|
|
#include "EXTERN.h"
|
|
#include "perl.h"
|
|
#include "XSUB.h"
|
|
|
|
#include <stdio.h>
|
|
#include <fontconfig/fontconfig.h>
|
|
#include "glib-2.0/gio/gio.h"
|
|
|
|
FcConfig *old_system_config = NULL;
|
|
|
|
void
|
|
exd_fileformat_fontconfig__set_current_c(SV *self, char *font_dir) {
|
|
if (old_system_config == NULL) {
|
|
old_system_config = FcConfigGetCurrent();
|
|
}
|
|
FcConfig *new_config = FcConfigCreate();
|
|
FcConfigAppFontAddDir(new_config, font_dir);
|
|
FcConfigBuildFonts(new_config);
|
|
FcConfigSetCurrent(new_config);
|
|
}
|
|
|
|
AV *
|
|
exd_fileformat_fontconfig__list_fonts_c(SV *self, char *font_dir) {
|
|
AV *return_array = newAV();
|
|
FcConfig *config = FcConfigCreate();
|
|
FcConfigAppFontAddDir(config, font_dir);
|
|
FcConfigBuildFonts(config);
|
|
FcFontSet *fonts = FcConfigGetFonts(config, FcSetApplication);
|
|
if (fonts == NULL) {
|
|
return return_array;
|
|
}
|
|
for (int i = 0; i < fonts->nfont; i++) {
|
|
FcPattern *pattern = fonts->fonts[i];
|
|
FcChar8 *family;
|
|
FcChar8 *style;
|
|
FcChar8 *file;
|
|
FcPatternGetString(pattern, FC_FAMILY, 0, &family);
|
|
FcPatternGetString(pattern, FC_STYLE, 0, &style);
|
|
FcPatternGetString(pattern, FC_FILE, 0, &file);
|
|
char *familyKey;
|
|
HV *hash = newHV();
|
|
SV *hash_ref = newRV_noinc((SV *) hash);
|
|
hv_stores(hash, "family", newSVpv(family, 0));
|
|
hv_stores(hash, "style", newSVpv(style, 0));
|
|
hv_stores(hash, "file", newSVpv(file, 0));
|
|
av_push(return_array, hash_ref);
|
|
}
|
|
return return_array;
|
|
}
|
|
|
|
AV *
|
|
exd_fontconfig__list_fonts_c(SV *self) {
|
|
AV *return_array = newAV();
|
|
FcConfig *config = FcConfigGetCurrent();
|
|
FcFontSet *fonts = FcConfigGetFonts(config, FcSetSystem);
|
|
if (fonts == NULL) {
|
|
return return_array;
|
|
}
|
|
for (int i = 0; i < fonts->nfont; i++) {
|
|
FcPattern *pattern = fonts->fonts[i];
|
|
FcChar8 *family;
|
|
FcChar8 *style;
|
|
FcChar8 *file;
|
|
FcPatternGetString(pattern, FC_FAMILY, 0, &family);
|
|
FcPatternGetString(pattern, FC_STYLE, 0, &style);
|
|
FcPatternGetString(pattern, FC_FILE, 0, &file);
|
|
char *familyKey;
|
|
HV *hash = newHV();
|
|
SV *hash_ref = newRV_noinc((SV *) hash);
|
|
hv_stores(hash, "family", newSVpv(family, 0));
|
|
hv_stores(hash, "style", newSVpv(style, 0));
|
|
hv_stores(hash, "file", newSVpv(file, 0));
|
|
av_push(return_array, hash_ref);
|
|
}
|
|
return return_array;
|
|
}
|
|
|
|
void
|
|
exd_gui__get_first_file(SV *class, size_t int_files) {
|
|
dSP;
|
|
ENTER;
|
|
SAVETMPS;
|
|
|
|
GFile *file = (((GFile **)int_files)[0]);
|
|
char *path = g_file_get_path(file);
|
|
|
|
PUSHMARK(SP);
|
|
EXTEND(SP, 2);
|
|
PUSHs(class);
|
|
PUSHs(sv_2mortal(newSVpv(path, 0)));
|
|
PUTBACK;
|
|
|
|
call_pv("_activate", G_DISCARD);
|
|
|
|
FREETMPS;
|
|
LEAVE;
|
|
}
|
|
|
|
MODULE = Exd PACKAGE = Exd::FileFormat::Fontconfig PREFIX = exd_fileformat_fontconfig_
|
|
|
|
AV * exd_fileformat_fontconfig__list_fonts_c(SV *self, char *font_dir)
|
|
|
|
void exd_fileformat_fontconfig__set_current_c(SV *self, char *font_dir)
|
|
|
|
MODULE = Exd PACKAGE = Exd::Fontconfig PREFIX = exd_fontconfig_
|
|
|
|
AV * exd_fontconfig__list_fonts_c(SV *self)
|
|
|
|
MODULE = Exd PACKAGE = Exd::Gui PREFIX = exd_gui_
|
|
|
|
void exd_gui__get_first_file(SV *class, size_t int_files)
|
|
|
|
MODULE = Exd PACKAGE = Exd PREFIX = exd_
|