Private font finished.

This commit is contained in:
Sergiotarxz 2024-10-17 23:26:33 +02:00
parent d3e4e0565c
commit 0164723fbf
3 changed files with 37 additions and 1 deletions

View File

@ -15,8 +15,14 @@ use Exd::Utils;
use Digest::SHA qw/sha256_hex/;
use Exd::FileFormat::DB;
use Exd::FileFormat::Fontconfig;
has dir => ( is => 'rw' );
has _fontconfig => (is => 'lazy');
sub _build__fontconfig($self) {
return Exd::FileFormat::Fontconfig->new(exd => $self);
}
sub new_tmp($class) {
my $tempdir = Path::Tiny->tempdir();
@ -135,6 +141,7 @@ sub from_zip_file( $class, $zip_file ) {
sub execute( $self, $printer ) {
my $script = $self->get_script;
$self->_dbh;
my $sub =
eval
'use v5.40.0; use strict; use warnings; use utf8; no Carp::Always; use Cairo; use Pango;'
@ -142,6 +149,7 @@ sub execute( $self, $printer ) {
if ($@) {
die $@;
}
$self->_fontconfig->set_current;
$sub->( $self, $printer );
}

View File

@ -8,13 +8,38 @@ use warnings;
use Moo;
use Path::Tiny;
use Inline C => DATA => LIBS => '-lfontconfig -lfreetype';
has exd => (is => 'ro', required => 1, weak_ref => 1);
sub set_current($self) {
my $exd_font_dir = $self->_font_dir;
my $dir = $exd_font_dir->child('dir');
my $config = $exd_font_dir->child('config');
$self->_set_current_c(''.$dir);
}
sub _font_dir($self) {
return $self->exd->dir->child('fonts');
}
sub migration1($self) {
my $exd = $self->exd;
my $app_font_dir = path(__FILE__)->parent->parent->parent->parent->child('fonts/dir');
my $exd_font_dir = $self->exd->dir->child('fonts/dir');
my $exd_font_dir = $self->_font_dir->child('dir');
$exd_font_dir->mkpath;
system 'cp', '-r', $app_font_dir, $exd_font_dir;
}
1;
__DATA__
__C__
#include <stdio.h>
#include <fontconfig/fontconfig.h>
void
_set_current_c(SV *self, char *font_dir) {
FcConfig *new_config = FcConfigCreate();
FcConfigAppFontAddDir(new_config, font_dir);
FcConfigBuildFonts(new_config);
FcConfigSetCurrent(new_config);
}

View File

@ -622,6 +622,9 @@ sub _open_gallery($self) {
}
sub _log( $self, $message ) {
if ($message =~ /Fontconfig error: No writable cache directories/) {
return;
}
$self->_write_to_parent->say(
JSON::to_json(
{