Skip to content

Commit

Permalink
fix: baseline
Browse files Browse the repository at this point in the history
  • Loading branch information
qq15725 committed Jan 27, 2024
1 parent ea57a04 commit 4451001
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ export interface Metrics {
}

export class Text {
// eslint-disable-next-line no-misleading-character-class
static punctuationRegex = /[\s\n\t\u200B\u200C\u200D\u200E\u200F.,?!:;"'(){}\[\]<>\/\\|~#\$%\*\+=&^,。?!:;“”‘’()【】《》……——]/

static get defaultStyle(): TextStyle {
return {
width: 'auto',
Expand Down Expand Up @@ -213,11 +216,13 @@ export class Text {
contentWidth,
contentHeight,
)
const xGlyphHeight = context.measureText('X').actualBoundingBoxAscent
const diffHeight = (fragment.contentBox.height - xGlyphHeight) / 2
const glyphBoxWidth = result.actualBoundingBoxLeft + result.actualBoundingBoxRight
const glyphBoxHeight = result.actualBoundingBoxAscent + result.actualBoundingBoxDescent
fragment.glyphBox = this._createBox(
fragment.contentBox.left + (fragment.contentBox.width - glyphBoxWidth) / 2,
fragment.contentBox.top + (fragment.contentBox.height - glyphBoxHeight) / 2,
fragment.contentBox.top + diffHeight + (xGlyphHeight - result.actualBoundingBoxAscent),
glyphBoxWidth,
glyphBoxHeight,
)
Expand Down

0 comments on commit 4451001

Please sign in to comment.