Skip to content

Conversation

@sciurius
Copy link
Contributor

@sciurius sciurius commented May 8, 2025

This simple patch enhances font to take an existing Font::TTF::Font object instead of a file name. This is useful in cases you aready have such an object, e.g. manually created, or derived from other sources.

The relevant code changes are in lib/PDF/API2/Resource/CIDFont/TrueType/FontFile.pm. The other changes are to propagate the functionality to the ttfont and font functions. And documentation.

@sciurius sciurius closed this May 8, 2025
@sciurius sciurius deleted the ttf branch May 8, 2025 20:33
@sciurius sciurius restored the ttf branch May 8, 2025 20:34
@sciurius sciurius reopened this May 8, 2025
@sciurius
Copy link
Contributor Author

sciurius commented May 9, 2025

A couple of use cases:

  • Using fonts from font collection (.ttc) files. Font::TTF::Ttc provides access to these files and essentially presents them in the form of a list of Font::TTF::Font objects.
  • When converting SVG to PDF, the fonts are often specified as URLs or inlined data. It is easier to create a Font::TTF::Font object from such a font than to jump the hoops of extracting and creating temporary font files so these can be passed to PDF::API2.

lib/PDF/API2.pm Outdated
Comment on lines 1949 to 1950
Setting format to C<truetype> is mandatory if the C<$name> argument is a
C<Font::TTF::Font> object.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove this requirement? It seems like this is something that can be inferred.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.

@ssimms ssimms merged commit e848471 into ssimms:master Jul 2, 2025
ssimms added a commit that referenced this pull request Jul 2, 2025
@sciurius sciurius deleted the ttf branch July 2, 2025 05:41
ssimms added a commit that referenced this pull request Aug 29, 2025
    - [GH-85] Fix default_page_size when called without arguments (patch by
      Johan Vromans).

    - [GH-90] Fix deprecated option -noembed (reported by Bernhard Schmalhofer).

    - [GH-91] Support annotation links to a named external destination (patch by
      Johan Vromans).

    - [GH-92] Allow Font::TTF::Font objects to be used as fonts (patch by Johan
      Vromans).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants