NAME

Text::Amuse::Compile::Fonts - class for fonts management

SYNOPSIS

# hash to hold the fonts file, where $wd is the font directory
my %fontfiles = map { $_ => File::Spec->catfile($wd, $_ . '.otf') } (qw/regular italic
                                                                        bold bolditalic/);
my $fonts = Text::Amuse::Compile::Fonts->new([
                                              {
                                               name => 'Example Serif',
                                               type => 'serif',
                                               desc => 'example font',
                                               regular => $fontfiles{regular},
                                               italic => $fontfiles{italic},
                                               bold => $fontfiles{bold},
                                               bolditalic => $fontfiles{bolditalic},
                                              },
                                              # more fonts here
                                             ]);
# or you can pass the same structure if you got it serialized to
# json and saved to a file.
my $fonts = Text::Amuse::Compile::Fonts->new($json_file);
my @fonts = $fonts->all_fonts;

DESCRIPTION

This class has the purpose to hold the list of available fonts, which has to be provided to the constructor via a json file or as an arrayref of Text::Amuse::Compile::Fonts::Family objects.

To build a json file with some default fonts, you may want to try "the muse-create-font-file.pl" script installed with this distribution.

CONSTRUCTOR

new($file_or_arrayref_with_fonts)

The constructor accept either a file or an arrayref with fonts specifications.

Each font specification is used to construct a Text::Amuse::Compile::Fonts::Family object, which in turn may contain Text::Amuse::Compile::Fonts::File objects.

Keys of the hashref inside the arrayref:

name

The name of the font. This is the system name, something that fontconfig will understand. You can try with fc-list to see if you can find it. Mandatory.

type

The type of the file. Can be either serif, sans or mono. Mandatory.

desc

An optional free form description.

regular

The path to the regular font file (.ttf or .otf or .woff)

italic

The path to the italic font file (.ttf or .otf or .woff)

bold

The path to the bold font file (.ttf or .otf or .woff)

bolditalic

The path to the bolditalic font file (.ttf or .otf or .woff)

Please note that the paths to the files are optional. They are used only for the EPUB generation, when the files are embedded in the final file.

Also note that the name of the fonts is not arbitrary. Fontconfig needs to recognize it for a successful LaTeX compilation.

ACCESSORS

list

The arrayref with the Text::Amuse::Compile::Fonts::Family objects.

METHODS

all_fonts

Return the list of fonts, as a plain list

serif_fonts

As above, but only the serif fonts

mono_fonts

As above, but only the mono fonts

sans_fonts

As above, but only the sans fonts

all_fonts_with_files

Return the list of fonts which have the paths to the font file.

serif_fonts_with_files

As above, but only the serif fonts

mono_fonts_with_files

As above, but only the mono fonts

sans_fonts_with_files

As above, but only the sans fonts

default_font_list

Return an arrayref with the default font definitions

INTERNALS

BUILDARGS

Construct the font list from either the data structure or the file path.