Skip to content

showText doesn't work (out of the box) with EmbeddedFont #22

@artbot1

Description

@artbot1

currently i have the follwing to do

ops.showText(encodeCustom('Hello World', fontCustom)),

with

`// adapted from
// api/pdf-page.ts
// private encodeTextForFont(text: string, font: FontInput): PdfString {
function encodeCustom(text: string, font: FontInput): PdfString {
if (typeof font === "string") {
throw new Error()
}

const gids = font.encodeTextToGids(text)
const bytes = new Uint8Array(gids.length * 2)

for (let i = 0; i < gids.length; i++) {
	const gid = gids[i]
	bytes[i * 2] = (gid >> 8) & 0xff
	bytes[i * 2 + 1] = gid & 0xff
}

return PdfString.fromBytes(bytes)

}`

otherwise the text won't show up ...

what about a second (optional) font parameter to showText

ops.showText('Hello World', fontCustom)

which would do the encoding transparently ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions