Skip to content

Commit 2884808

Browse files
committed
Use dominant-baseline if alignment-baseline is missing (#80) & ctx fix
Fixes #80 Applies the current context before rendering a text node
1 parent 70a70ea commit 2884808

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/applyparseattributes.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ export function parseAttributes(context: Context, svgNode: SvgNode, node?: Eleme
125125

126126
const alignmentBaseline =
127127
getAttribute(domNode, context.styleSheets, 'vertical-align') ||
128-
getAttribute(domNode, context.styleSheets, 'alignment-baseline')
128+
getAttribute(domNode, context.styleSheets, 'alignment-baseline') ||
129+
getAttribute(domNode, context.styleSheets, 'dominant-baseline')
129130
if (alignmentBaseline) {
130131
const matchArr = alignmentBaseline.match(
131132
/(baseline|text-bottom|alphabetic|ideographic|middle|central|mathematical|text-top|bottom|center|top|hanging)/

src/nodes/text.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { GraphicsNode } from './graphicsnode'
1616
import { Rect } from '../utils/geometry'
1717
import { Matrix } from 'jspdf'
1818
import { SvgNode } from './svgnode'
19-
import { parseAttributes } from '../applyparseattributes'
19+
import { parseAttributes, applyContext } from '../applyparseattributes'
2020

2121
interface TrimInfo {
2222
prevText: string
@@ -153,6 +153,7 @@ export class TextNode extends GraphicsNode {
153153
if (visibility === 'visible') {
154154
const alignmentBaseline = context.attributeState.alignmentBaseline
155155
const textRenderingMode = getTextRenderingMode(context.attributeState)
156+
applyContext(context)
156157
context.pdf.text(transformedText, textX + dx - xOffset, textY + dy, {
157158
baseline: mapAlignmentBaseline(alignmentBaseline),
158159
angle: context.transform,

0 commit comments

Comments
 (0)