README

Name

PDF::Font::Loader::CSS

Synopsis

use CSS::Stylesheet;
use PDF::Font::Loader::FontObj;
use PDF::Font::Loader::CSS;

my CSS::Stylesheet $css .= parse: q:to<END>;
    @font-face {
        font-family: "DejaVu Sans";
        src: url("fonts/DejaVuSans.ttf");
    }
    @font-face {
        font-family: "DejaVu Sans";
        src: url("fonts/DejaVuSans-Bold.ttf");
        font-weight: bold;
    }
    @font-face {
        font-family: "DejaVu Sans";
        src: url("fonts/DejaVuSans-Oblique.ttf");
        font-style: oblique;
    }
    @font-face {
        font-family: "DejaVu Sans";
        src: url("fonts/DejaVuSans-BoldOblique.ttf");
        font-weight: bold;
        font-style: oblique;
    }
    END

my CSS::Font::Descriptor @font-face = $css.font-face;

my PDF::Font::Loader::CSS $font-loader .= new: :@font-face, :base-url<t/>;

my CSS::Font() $font = "bold italic 12pt DejaVu Sans";
say $font-loader.find-font(:$font); # t/fonts/DejaVuSans-BoldOblique.ttf';
my PDF::Loader::FontObj $font-obj = $font-loader.load-font: :$font;
say $font-obj.font-name; # DejaVuSans-BoldOblique;

Description

This module extends PDF::Font::Loader, adding @font-face attributes and rules to enable CSS compatible font selection.

In particular, it extends the find-font() and load-font() methods; adding multi candidates to handle CSS font properties and select from a list of @font-face font descriptors.

Methods

find-font

multi method find-font( CSS::Font:D() :$font) returns Str

Returns a matching font file name. This will either been a local file, or a temporary file, fetched from a remote URI.

load-font

multi method load-font( CSS::Font:D() :$font) returns Font::Loader::FontObj

Returns a matching font file name. This will either been a local file, or a temporary file, fetched from a remote URI.

source

method source CSS::Font:D() :$font() returns CSS::Font::Resources::Source

Returns a matching source for the font. This is the first matching font of an acceptable PDF format (opentype, truetype, postscript, or cff).

PDF::Font::Loader::CSS v0.0.1

CSS driven font loading for the PDF tool-chain

Authors

  • David Warring

License

Artistic-2.0

Dependencies

CSS::Properties:ver<0.7.6+>PDF::Font::LoaderCSS::Font::Resources:v<0.0.6+>URI

Test Dependencies

Provides

  • PDF::Font::Loader::CSS

Documentation

The Camelia image is copyright 2009 by Larry Wall. "Raku" is trademark of the Yet Another Society. All rights reserved.