Migrating out of Inline::C

This commit is contained in:
Sergiotarxz 2024-11-10 17:21:36 +01:00
parent 9a358803f3
commit 5f5ab2a043
7 changed files with 39 additions and 17 deletions

View File

@ -23,6 +23,7 @@ my $build = Module::Build->new(
'Crypt::URandom' => 0,
'Inline::C' => 0,
},
extra_linker_flags => ['-lfontconfig', '-lfreetype'],
test_requires => {
'Test::MockModule' => 0,
'Test::Most' => 0,

View File

@ -65,8 +65,12 @@ sub _build_accessibility($self) {
return JapaChar::Accessibility->new(app => $self);
}
sub root($self) {
return path(__FILE__)->parent->parent->parent;
}
sub _build__gresources_path($self) {
my $root = path(__FILE__)->parent->parent;
my $root = $self->root;
my $gresources = $root->child('resources.gresource');
0 == system( 'which', 'glib-compile-resources' )
&& system( 'glib-compile-resources', $root->child('resources.xml') );
@ -84,7 +88,7 @@ sub get_width($self) {
sub config($class) {
my $ypp = YAML::PP->new;
$ypp->load_file( '' . path(__FILE__)->parent->parent->child('config.yml') );
$ypp->load_file( '' . $class->root->child('config.yml') );
}
sub on_resize( $self, $sub ) {

19
lib/JapaChar.xs Normal file
View File

@ -0,0 +1,19 @@
#define PERL_NO_GET_CONTEXT
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include <stdio.h>
#include <fontconfig/fontconfig.h>
void
japachar_fontconfig__set_current_c(SV *self, char *font_dir) {
FcConfig *config = FcConfigGetCurrent();
FcConfigAppFontAddDir(config, font_dir);
FcConfigBuildFonts(config);
FcConfigSetCurrent(config);
}
MODULE = JapaChar PACKAGE = JapaChar::Fontconfig PREFIX = japachar_fontconfig_
void japachar_fontconfig__set_current_c(SV *self, char *font_dir)

View File

@ -53,8 +53,9 @@ sub _populate_type( $self, $type ) {
sub _get_characters_of_type( $self, $type ) {
my $current_file = path __FILE__;
require JapaChar;
my $array =
from_json( $current_file->parent->parent->parent->child("$type.json")
from_json( JapaChar->root->child("$type.json")
->slurp_utf8 );
return $array;
}

View File

@ -11,10 +11,13 @@ use Path::Tiny;
use Data::Dumper;
use Inline C => DATA => LIBS => '-lfontconfig -lfreetype';
require XSLoader;
XSLoader::load('JapaChar');
sub _font_dir($self) {
my $root = path(__FILE__)->parent->parent->parent;
require JapaChar;
my $root = JapaChar->root;
return $root->child('fonts');
}
@ -23,15 +26,4 @@ sub set_current($self) {
$self->_set_current_c( '' . $font_dir );
}
1;
__DATA__
__C__
#include <stdio.h>
#include <fontconfig/fontconfig.h>
void
_set_current_c(SV *self, char *font_dir) {
FcConfig *config = FcConfigGetCurrent();
FcConfigAppFontAddDir(config, font_dir);
FcConfigBuildFonts(config);
FcConfigSetCurrent(config);
}

View File

@ -30,6 +30,11 @@
<developer_name>sergiotarxz</developer_name>
<releases>
<release version="v0.28" date="2024-11-09">
<description>
<p>Migrating to XS because Inline::C is giving compatibility issues.</p>
</description>
</release>
<release version="v0.27" date="2024-11-09">
<description>
<p>Bundling noto-cjk by default to not having to ask users to install

View File

@ -4,7 +4,7 @@ use v5.38.2;
use File::Basename;
use lib dirname(dirname(__FILE__)).'/lib';
use blib;
use JapaChar;