Skip to content

Add Type 3 Fonts Functionality and Support for Color Fonts 🎨#1305

Merged
andersonhc merged 8 commits intopy-pdf:masterfrom
andersonhc:color-fonts
Aug 28, 2025
Merged

Add Type 3 Fonts Functionality and Support for Color Fonts 🎨#1305
andersonhc merged 8 commits intopy-pdf:masterfrom
andersonhc:color-fonts

Conversation

@andersonhc
Copy link
Copy Markdown
Collaborator

@andersonhc andersonhc commented Nov 20, 2024

Initial Draft: Type 3 Fonts and Color Fonts Support

Fixes #224 #1446

This PR introduces the initial implementation for Type 3 fonts and Color Fonts in PDFs. 🚀

Features:

  • Type 3 Fonts:
    • Type 3 fonts can now be added to a PDF, enabling custom, embedded font glyphs.
  • Color Fonts:
    • Added support for bitmap/raster color font formats (CBDT+CBLC, SBIX)
    • Added support for vector based color font formats (SVG, COLRv0, COLRv1).

Checklist:

  • A unit test is covering the code added / modified by this PR

  • This PR is ready to be merged

  • In case of a new feature, docstrings have been added, with also some documentation in the docs/ folder

  • A mention of the change is present in CHANGELOG.md

By submitting this pull request, I confirm that my contribution is made under the terms of the GNU LGPL 3.0 license.

@andersonhc andersonhc marked this pull request as draft November 20, 2024 02:43
@andersonhc andersonhc mentioned this pull request Dec 24, 2024
7 tasks
@andersonhc andersonhc force-pushed the color-fonts branch 3 times, most recently from 858140e to da535dc Compare January 10, 2025 02:53
@Lucas-C
Copy link
Copy Markdown
Member

Lucas-C commented Jan 18, 2025

I'm no expert on fonts, but feel free to ping me if you want a review on this PR at some point 🙂

And thank you for working on this feature! 👍

@andersonhc
Copy link
Copy Markdown
Collaborator Author

I'm no expert on fonts, but feel free to ping me if you want a review on this PR at some point 🙂

And thank you for working on this feature! 👍

Only missing COLRv1 support and some housekeeping... we should have a reviewable version soon.

@Oripy
Copy link
Copy Markdown

Oripy commented May 21, 2025

I don't know if this is the right place to report this, but I found a regression in the font_color branch linked to offset_rendering():

The following code fails with an AttributeError: 'FPDF' object has no attribute '_current_draw_context'

import fpdf

pdf = fpdf.FPDF()
pdf.add_page()

pdf.add_font(fname='DejaVuSans.ttf')
pdf.add_font(fname='NotoColorEmoji.ttf')

pdf.set_font('DejaVuSans', size=14)
pdf.set_fallback_fonts(['NotoColorEmoji'])

pdf.multi_cell(text='abcdefghijklmnoqrtuvwxyz é 0123456789 🔴🟢🔵💀☠️', w=0)

with pdf.offset_rendering() as dummy:
    dummy.multi_cell(100, None, "test")

pdf.output('issue_1446.pdf')

@andersonhc andersonhc changed the title (Draft) Add Type 3 Fonts Functionality and Support for Color Fonts 🎨 Add Type 3 Fonts Functionality and Support for Color Fonts 🎨 Aug 28, 2025
@andersonhc andersonhc requested review from Lucas-C and removed request for gmischler August 28, 2025 03:05
@andersonhc andersonhc self-assigned this Aug 28, 2025
@andersonhc andersonhc linked an issue Aug 28, 2025 that may be closed by this pull request
@andersonhc andersonhc marked this pull request as ready for review August 28, 2025 11:28
@andersonhc andersonhc merged commit b743196 into py-pdf:master Aug 28, 2025
40 of 42 checks passed
@Lucas-C
Copy link
Copy Markdown
Member

Lucas-C commented Sep 1, 2025

Good job @andersonhc 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Font fallback issue CBDT/CBLC font support for color emojis

3 participants