Dict

[Raku PDF Project] / [PDF-Font-Loader Module] / PDF::Font::Loader :: Dict

class PDF::Font::Loader::Dict

Loads a font from a PDF font dictionary

Description

Loads fonts from PDF font dictionaries.

This an internal class, usually invoked from the PDF::Font::Loader load-font method to facilitate font loading from PDF font dictionaries.

Example

The following example loads and summarizes page-level fonts:

use PDF::Lite;
use PDF::Font::Loader;
use PDF::Content::Font;
use PDF::Content::FontObj;

constant Fmt = "%-30s %-8s %-10s %-3s %-3s";
sub yn($_) {.so ?? 'yes' !! 'no' }

my %SeenFont{PDF::Content::Font};
my PDF::Lite $pdf .= open: "t/fontobj.pdf";
say sprintf(Fmt, |<name type encode emb sub>);
say sprintf(Fmt, |<-------------------------- ------- ---------- --- --->);
for 1 .. $pdf.page-count {
    my PDF::Content::Font %fonts = $pdf.page($_).gfx.resources('Font');

    for %fonts.values -> $dict {
        unless %SeenFont{$dict}++ {
            my PDF::Content::FontObj $font = PDF::Font::Loader.load-font: :$dict, :quiet;
            say sprintf(Fmt, .font-name, .type, .enc, .is-embedded.&yn, .is-subset.&yn)
                given $font;
        }
    }
}

Produces:

name                      |     type    |  encode    | emb | sub
--------------------------+-------------+------------+-----+---
DejaVuSans                |    Type0    | identity-h | yes | no
Times-Roman               |    Type1    | win        | no  | no
WenQuanYiMicroHei         |    TrueType | win        | no  | no
NimbusRoman-Regular       |    Type1    | win        | yes | no
Cantarell-Oblique         |    Type1    | win        | yes | no

Methods

load-font-opts

method load-font-opts(Hash :$dict!, Bool :$embed) returns Hash

Produces a set of PDF::Font::Loader load-font() options for the font dictionary.

is-core-font

method is-core-font(Hash $dict) returns Bool

Determine if the dictionary describes a PDF core font.

PDF::Font::Loader v0.7.5

Font loading and embedding for the PDF tool-chain

Authors

  • David Warring

License

Artistic-2.0

Dependencies

Font::AFM:ver<1.24.6+>Font::FreeType:ver<0.4.3+>Hash::intNative::PackingPDF::Content:ver<0.6.12+>PDF::Lite:ver<0.0.11+>PDF:ver<0.5.4+>

Test Dependencies

Provides

  • PDF::Font::Loader
  • PDF::Font::Loader::Dict
  • PDF::Font::Loader::Enc
  • PDF::Font::Loader::Enc::CMap
  • PDF::Font::Loader::Enc::Glyphic
  • PDF::Font::Loader::Enc::Identity16
  • PDF::Font::Loader::Enc::Type1
  • PDF::Font::Loader::Enc::Unicode
  • PDF::Font::Loader::FontObj
  • PDF::Font::Loader::FontObj::CID
  • PDF::Font::Loader::Glyph
  • PDF::Font::Loader::Type1::Stream

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