mirror of
https://github.com/konvajs/konva.git
synced 2025-09-19 19:02:08 +08:00
Text fontSize unit is now in pixels (used to be points). Default text lineHeight attr is now 1 (used to be 1.2)
This commit is contained in:
@@ -8,7 +8,7 @@
|
|||||||
* @param {String} config.textStroke
|
* @param {String} config.textStroke
|
||||||
* @param {Number} config.textStrokeWidth
|
* @param {Number} config.textStrokeWidth
|
||||||
* @param {String} config.fontFamily default is Calibri
|
* @param {String} config.fontFamily default is Calibri
|
||||||
* @param {Number} config.fontSize default is 12
|
* @param {Number} config.fontSize in pixels. Default is 12
|
||||||
* @param {String} config.fontStyle can be normal, bold, or italic. Default is normal
|
* @param {String} config.fontStyle can be normal, bold, or italic. Default is normal
|
||||||
* @param {String} config.text
|
* @param {String} config.text
|
||||||
* @param {String} config.align can be left, center, or right
|
* @param {String} config.align can be left, center, or right
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
* @param {Number} config.padding
|
* @param {Number} config.padding
|
||||||
* @param {Number} config.width default is auto
|
* @param {Number} config.width default is auto
|
||||||
* @param {Number} config.height default is auto
|
* @param {Number} config.height default is auto
|
||||||
* @param {Number} config.lineHeight default is 1.2
|
* @param {Number} config.lineHeight default is 1
|
||||||
*/
|
*/
|
||||||
Kinetic.Text = function(config) {
|
Kinetic.Text = function(config) {
|
||||||
this._initText(config);
|
this._initText(config);
|
||||||
@@ -34,7 +34,7 @@
|
|||||||
padding: 0,
|
padding: 0,
|
||||||
width: 'auto',
|
width: 'auto',
|
||||||
height: 'auto',
|
height: 'auto',
|
||||||
lineHeight: 1.2
|
lineHeight: 1
|
||||||
});
|
});
|
||||||
|
|
||||||
this.dummyCanvas = document.createElement('canvas');
|
this.dummyCanvas = document.createElement('canvas');
|
||||||
@@ -56,7 +56,7 @@
|
|||||||
drawFunc: function(canvas) {
|
drawFunc: function(canvas) {
|
||||||
var context = canvas.getContext(), p = this.attrs.padding, lineHeightPx = this.attrs.lineHeight * this.getTextHeight(), textArr = this.textArr;
|
var context = canvas.getContext(), p = this.attrs.padding, lineHeightPx = this.attrs.lineHeight * this.getTextHeight(), textArr = this.textArr;
|
||||||
|
|
||||||
context.font = this.attrs.fontStyle + ' ' + this.attrs.fontSize + 'pt ' + this.attrs.fontFamily;
|
context.font = this.attrs.fontStyle + ' ' + this.attrs.fontSize + 'px ' + this.attrs.fontFamily;
|
||||||
context.textBaseline = 'middle';
|
context.textBaseline = 'middle';
|
||||||
context.textAlign = 'left';
|
context.textAlign = 'left';
|
||||||
context.save();
|
context.save();
|
||||||
@@ -137,7 +137,7 @@
|
|||||||
var context = dummyCanvas.getContext('2d');
|
var context = dummyCanvas.getContext('2d');
|
||||||
|
|
||||||
context.save();
|
context.save();
|
||||||
context.font = this.attrs.fontStyle + ' ' + this.attrs.fontSize + 'pt ' + this.attrs.fontFamily;
|
context.font = this.attrs.fontStyle + ' ' + this.attrs.fontSize + 'px ' + this.attrs.fontFamily;
|
||||||
var metrics = context.measureText(text);
|
var metrics = context.measureText(text);
|
||||||
context.restore();
|
context.restore();
|
||||||
return {
|
return {
|
||||||
@@ -277,7 +277,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* set font size
|
* set font size in pixels
|
||||||
* @name setFontSize
|
* @name setFontSize
|
||||||
* @methodOf Kinetic.Text.prototype
|
* @methodOf Kinetic.Text.prototype
|
||||||
* @param {int} fontSize
|
* @param {int} fontSize
|
||||||
@@ -308,7 +308,7 @@
|
|||||||
* set line height
|
* set line height
|
||||||
* @name setLineHeight
|
* @name setLineHeight
|
||||||
* @methodOf Kinetic.Text.prototype
|
* @methodOf Kinetic.Text.prototype
|
||||||
* @param {Number} lineHeight default is 1.2
|
* @param {Number} lineHeight default is 1
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -177,10 +177,6 @@ Test.Modules.Text = {
|
|||||||
//width: 200,
|
//width: 200,
|
||||||
padding: 20,
|
padding: 20,
|
||||||
align: 'center',
|
align: 'center',
|
||||||
shadowColor: 'black',
|
|
||||||
shadowBlur: 1,
|
|
||||||
shadowOffset: [10, 10],
|
|
||||||
shadowOpacity: 0.2,
|
|
||||||
draggable: true
|
draggable: true
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -189,6 +185,8 @@ Test.Modules.Text = {
|
|||||||
|
|
||||||
layer.add(text);
|
layer.add(text);
|
||||||
stage.add(layer);
|
stage.add(layer);
|
||||||
|
|
||||||
|
test(text.getLineHeight() === 1, 'text line height should be defaulted to 1');
|
||||||
|
|
||||||
/*
|
/*
|
||||||
text.transitionTo({
|
text.transitionTo({
|
||||||
|
Reference in New Issue
Block a user