Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When the system has a ttf file, the exported PDF font is type3 #203

Open
loveloki opened this issue Dec 9, 2024 · 3 comments
Open

When the system has a ttf file, the exported PDF font is type3 #203

loveloki opened this issue Dec 9, 2024 · 3 comments

Comments

@loveloki
Copy link

loveloki commented Dec 9, 2024

Use SourceHanSerifSC-VF.ttf

import {Canvas, FontLibrary} from 'skia-canvas'

const family = 'Source Han Serif SC VF'

console.log(FontLibrary.family(family))

const width = 400
const height = 400
let canvas = new Canvas(width, height)
let ctx = canvas.getContext("2d")

ctx.fillStyle = "purple"
const text = "测试"
ctx.font = `normal 20pt ${family}`
ctx.fillText(text, 10, 50)

await canvas.saveAs("output.pdf")

FontLibrary output:

{
  family: 'Source Han Serif SC VF',
  weights: [
    250, 300, 400,
    500, 600, 700,
    800, 900
  ],
  widths: [ 'normal' ],
  styles: [ 'normal' ]
}

The fc-list | grep 'Source Han Serif SC VF' output:

/home/test/.fonts/SourceHanSerifSC-VF.ttf: Source Han Serif SC VF:style=Medium
/home/test/.fonts/SourceHanSerifSC-VF.ttf: Source Han Serif SC VF,思源宋体 VF:style=ExtraLight,Regular
/home/test/.fonts/SourceHanSerifSC-VF.ttf: Source Han Serif SC VF:style=SemiBold
/home/test/.fonts/SourceHanSerifSC-VF.ttf: Source Han Serif SC VF,思源宋体 VF:style=Light
/home/test/.fonts/SourceHanSerifSC-VF.ttf: Source Han Serif SC VF:style=Bold
/home/test/.fonts/SourceHanSerifSC-VF.ttf: Source Han Serif SC VF:style=Heavy
/home/test/.fonts/SourceHanSerifSC-VF.ttf: Source Han Serif SC VF

The result is a type 3 font:
image

Why is this result? I'm using a TTF font, I guess which should be embeddable normally

@loveloki
Copy link
Author

loveloki commented Dec 9, 2024

Is there a way to know when fillText whether to use the given font family? If type3 fonts are used like this, it cannot be determined from the generated PDF.

@samizdatco
Copy link
Owner

According to the Skia docs, TrueType fonts will be converted to Type3 if the "do not embed" flag is set within the font's metadata. Maybe that's what's happening with your font?

@loveloki
Copy link
Author

image

It looks like there not Subsetting Forbidden.

Maybe there's something about this font that skia doesn't support?

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

No branches or pull requests

2 participants