From 174b7dcf1333aa1410245406d2a0c09ad6ff4b6e Mon Sep 17 00:00:00 2001 From: giroletm <112472361+giroletm@users.noreply.github.com> Date: Tue, 7 May 2024 15:23:36 +0200 Subject: [PATCH] Use dominant-baseline if alignment-baseline is missing (#80) & ctx fix Fixes #80 Applies the current context before rendering a text node --- src/applyparseattributes.ts | 3 ++- src/nodes/text.ts | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/applyparseattributes.ts b/src/applyparseattributes.ts index 501cc726..04b0e26d 100644 --- a/src/applyparseattributes.ts +++ b/src/applyparseattributes.ts @@ -133,7 +133,8 @@ export function parseAttributes(context: Context, svgNode: SvgNode, node?: Eleme const alignmentBaseline = getAttribute(domNode, context.styleSheets, 'vertical-align') || - getAttribute(domNode, context.styleSheets, 'alignment-baseline') + getAttribute(domNode, context.styleSheets, 'alignment-baseline') || + getAttribute(domNode, context.styleSheets, 'dominant-baseline') if (alignmentBaseline) { const matchArr = alignmentBaseline.match( /(baseline|text-bottom|alphabetic|ideographic|middle|central|mathematical|text-top|bottom|center|top|hanging)/ diff --git a/src/nodes/text.ts b/src/nodes/text.ts index 4cd0c07e..ef8bf8cc 100644 --- a/src/nodes/text.ts +++ b/src/nodes/text.ts @@ -16,7 +16,7 @@ import { GraphicsNode } from './graphicsnode' import { Rect } from '../utils/geometry' import { Matrix } from 'jspdf' import { SvgNode } from './svgnode' -import { parseAttributes } from '../applyparseattributes' +import { parseAttributes, applyContext } from '../applyparseattributes' interface TrimInfo { prevText: string @@ -153,6 +153,7 @@ export class TextNode extends GraphicsNode { if (visibility === 'visible') { const alignmentBaseline = context.attributeState.alignmentBaseline const textRenderingMode = getTextRenderingMode(context.attributeState) + applyContext(context) context.pdf.text(transformedText, textX + dx - xOffset, textY + dy, { baseline: mapAlignmentBaseline(alignmentBaseline), angle: context.transform,