mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-20 22:39:50 -05:00
Define CharacterStyle#getFontStyle()
And use it in PointText.
This commit is contained in:
parent
cc26fdc5d1
commit
e30a0ae26d
2 changed files with 7 additions and 3 deletions
|
@ -43,7 +43,7 @@ var CharacterStyle = this.CharacterStyle = PathStyle.extend(/** @lends Character
|
||||||
font: 'sans-serif'
|
font: 'sans-serif'
|
||||||
}),
|
}),
|
||||||
_owner: TextItem,
|
_owner: TextItem,
|
||||||
_style: 'style',
|
_style: 'style'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CharacterStyle objects don't need to be created directly. Just pass an
|
* CharacterStyle objects don't need to be created directly. Just pass an
|
||||||
|
@ -74,5 +74,9 @@ var CharacterStyle = this.CharacterStyle = PathStyle.extend(/** @lends Character
|
||||||
// Override leading to return fontSize * 1.2 by default, when undefined
|
// Override leading to return fontSize * 1.2 by default, when undefined
|
||||||
var leading = this.base();
|
var leading = this.base();
|
||||||
return leading != null ? leading : this.getFontSize() * 1.2;
|
return leading != null ? leading : this.getFontSize() * 1.2;
|
||||||
|
},
|
||||||
|
|
||||||
|
getFontStyle: function() {
|
||||||
|
return this._fontSize + 'px ' + this._font;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -72,7 +72,7 @@ var PointText = this.PointText = TextItem.extend(/** @lends PointText# */{
|
||||||
if (!this._content)
|
if (!this._content)
|
||||||
return;
|
return;
|
||||||
this._setStyles(ctx);
|
this._setStyles(ctx);
|
||||||
ctx.font = this.getFontSize() + 'px ' + this.getFont();
|
ctx.font = style.getFontStyle();
|
||||||
ctx.textAlign = this.getJustification();
|
ctx.textAlign = this.getJustification();
|
||||||
var leading = this.getLeading();
|
var leading = this.getLeading();
|
||||||
for (var i = 0, l = this._lines.length; i < l; i++) {
|
for (var i = 0, l = this._lines.length; i < l; i++) {
|
||||||
|
@ -97,7 +97,7 @@ var PointText = this.PointText = TextItem.extend(/** @lends PointText# */{
|
||||||
x = 0;
|
x = 0;
|
||||||
// Measure the real width of the text. Unfortunately, there is no
|
// Measure the real width of the text. Unfortunately, there is no
|
||||||
// sane way to measure text height with canvas
|
// sane way to measure text height with canvas
|
||||||
context.font = this.getFontSize() + 'px ' + this.getFont();
|
context.font = this._style.getFontStyle();
|
||||||
var width = 0;
|
var width = 0;
|
||||||
for (var i = 0, l = this._lines.length; i < l; i++)
|
for (var i = 0, l = this._lines.length; i < l; i++)
|
||||||
width = Math.max(width, context.measureText(
|
width = Math.max(width, context.measureText(
|
||||||
|
|
Loading…
Reference in a new issue