Skip to content

Commit

Permalink
rename fix apply
Browse files Browse the repository at this point in the history
  • Loading branch information
lavrton committed May 16, 2024
1 parent 2587e07 commit 7d5ba3e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/Global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export const Konva = {
_mouseDblClickPointerId: null,
_touchDblClickPointerId: null,
_pointerDblClickPointerId: null,
_fixTextRendering: false,

/**
* Global pixel ratio configuration. KonvaJS automatically detect pixel ratio of current device.
Expand Down
8 changes: 3 additions & 5 deletions src/shapes/Text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,11 @@ export class Text extends Shape<TextConfig> {
direction = direction === INHERIT ? context.direction : direction;

var translateY = lineHeightPx / 2;
const baseline = this.textBaseline();
if (baseline === 'alphabetic') {
var baseline = MIDDLE;
if (Konva._fixTextRendering) {
var metrics = this.measureSize('M'); // Use a sample character to get the ascent

baseline = 'alphabetic';
translateY =
(metrics.fontBoundingBoxAscent - metrics.fontBoundingBoxDescent) / 2 +
lineHeightPx / 2;
Expand Down Expand Up @@ -655,7 +656,6 @@ export class Text extends Shape<TextConfig> {

direction: GetSet<string, this>;
fontFamily: GetSet<string, this>;
textBaseline: GetSet<string, this>;
fontSize: GetSet<number, this>;
fontStyle: GetSet<string, this>;
fontVariant: GetSet<string, this>;
Expand Down Expand Up @@ -752,8 +752,6 @@ Factory.addGetterSetter(Text, 'direction', INHERIT);
*/
Factory.addGetterSetter(Text, 'fontFamily', 'Arial');

Factory.addGetterSetter(Text, 'textBaseline', MIDDLE);

/**
* get/set font size in pixels
* @name Konva.Text#fontSize
Expand Down
2 changes: 2 additions & 0 deletions test/sandbox.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
<script type="module">
import Konva from '../src/index.ts';

Konva._fixTextRendering = true;

var stageWidth = window.innerWidth;
var stageHeight = window.innerHeight;

Expand Down

0 comments on commit 7d5ba3e

Please sign in to comment.