fixed up some text shadow issues

This commit is contained in:
Eric Rowell
2012-11-24 09:15:02 -08:00
parent 0e514f7810
commit 0e6eb3ffe4
8 changed files with 16 additions and 19 deletions

View File

@@ -136,26 +136,26 @@ Kinetic.Text.prototype = {
}; };
}, },
fillText: function(context, text, skipShadow) { fillText: function(context, text, skipShadow) {
var textFill = this.getTextFill(), shadow = this.getShadow(); var textFill = this.getTextFill(), textShadow = this.getTextShadow();
if(textFill) { if(textFill) {
context.save(); context.save();
if(!skipShadow && shadow) { if(!skipShadow && textShadow) {
this._applyTextShadow(context); this._applyTextShadow(context);
} }
context.fillStyle = textFill; context.fillStyle = textFill;
context.fillText(text, 0, 0); context.fillText(text, 0, 0);
context.restore(); context.restore();
if(!skipShadow && shadow && shadow.opacity) { if(!skipShadow && textShadow && textShadow.opacity) {
this.fillText(context, text, true); this.fillText(context, text, true);
} }
} }
}, },
strokeText: function(context, text, skipShadow) { strokeText: function(context, text, skipShadow) {
var textStroke = this.getTextStroke(), textStrokeWidth = this.getTextStrokeWidth(), shadow = this.getShadow(); var textStroke = this.getTextStroke(), textStrokeWidth = this.getTextStrokeWidth(), textShadow = this.getTextShadow();
if(textStroke || textStrokeWidth) { if(textStroke || textStrokeWidth) {
context.save(); context.save();
if(!skipShadow && shadow) { if(!skipShadow && textShadow) {
this._applyTextShadow(context); this._applyTextShadow(context);
} }
@@ -164,7 +164,7 @@ Kinetic.Text.prototype = {
context.strokeText(text, 0, 0); context.strokeText(text, 0, 0);
context.restore(); context.restore();
if(!skipShadow && shadow && shadow.opacity) { if(!skipShadow && textShadow && textShadow.opacity) {
this.strokeText(context, text, true); this.strokeText(context, text, true);
} }
} }

View File

@@ -303,9 +303,10 @@ Kinetic.Global.extend(Kinetic.TextPath, Kinetic.Shape);
// add setters and getters // add setters and getters
Kinetic.Node.addGettersSetters(Kinetic.TextPath, ['fontFamily', 'fontSize', 'fontStyle', 'textFill', 'textStroke', 'textStrokeWidth']); Kinetic.Node.addGettersSetters(Kinetic.TextPath, ['fontFamily', 'fontSize', 'fontStyle', 'textFill', 'textStroke', 'textStrokeWidth']);
Kinetic.Node.addGetters(Kinetic.TextPath, ['text']); Kinetic.Node.addGetters(Kinetic.TextPath, ['text', 'textShadow']);
// reference Text methods // reference Text methods
Kinetic.TextPath.prototype.setTextShadow = Kinetic.Text.prototype.setTextShadow;
Kinetic.TextPath.prototype.fillText = Kinetic.Text.prototype.fillText; Kinetic.TextPath.prototype.fillText = Kinetic.Text.prototype.fillText;
Kinetic.TextPath.prototype.strokeText = Kinetic.Text.prototype.strokeText; Kinetic.TextPath.prototype.strokeText = Kinetic.Text.prototype.strokeText;
Kinetic.TextPath.prototype.fillStrokeText = Kinetic.Text.prototype.strokeText; Kinetic.TextPath.prototype.fillStrokeText = Kinetic.Text.prototype.strokeText;

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -13,6 +13,7 @@
<script src="../dataUrls/customShapeTwoFills.js"></script> <script src="../dataUrls/customShapeTwoFills.js"></script>
<script src="../dataUrls/cloneGroup.js"></script> <script src="../dataUrls/cloneGroup.js"></script>
<script src="../dataUrls/nodeShapeTypeSelector.js"></script> <script src="../dataUrls/nodeShapeTypeSelector.js"></script>
<script src="../dataUrls/multiLineTextWithShadows.js"></script>
<script src="../js/Test.js"></script> <script src="../js/Test.js"></script>

View File

@@ -647,7 +647,7 @@ Test.Modules.CONTAINER = {
test(group.get('Group').length === 0, 'group should have 0 groups'); test(group.get('Group').length === 0, 'group should have 0 groups');
}, },
'*node and shape type selector': function(containerId) { 'node and shape type selector': function(containerId) {
var stage = new Kinetic.Stage({ var stage = new Kinetic.Stage({
container: containerId, container: containerId,
width: 578, width: 578,

View File

@@ -771,7 +771,7 @@ Test.Modules.NODE = {
cachedShape.createImageBuffer(function() { cachedShape.createImageBuffer(function() {
console.log(111)
layer.draw(); layer.draw();
//console.log(layer.toDataURL()); //console.log(layer.toDataURL());
warn(dataUrls['regular and cahced polygon'] === layer.toDataURL(), 'regular and cached polygon layer data url is incorrect'); warn(dataUrls['regular and cahced polygon'] === layer.toDataURL(), 'regular and cached polygon layer data url is incorrect');

View File

@@ -308,7 +308,7 @@ Test.Modules.Text = {
//width: 200, //width: 200,
padding: 20, padding: 20,
align: 'center', align: 'center',
shadow: { textShadow: {
color: 'red', color: 'red',
blur: 1, blur: 1,
offset: [10, 10], offset: [10, 10],
@@ -322,9 +322,7 @@ Test.Modules.Text = {
layer.add(text); layer.add(text);
stage.add(layer); stage.add(layer);
//console.log(layer.toDataURL()); warn(layer.toDataURL() === multiLineTextWithShadows, 'multi line text with shadows data url is incorrect');
warn(layer.toDataURL() === dataUrls['multi line text with shadows'], 'multi line text with shadows data url is incorrect');
}, },
'change font size should update text data': function(containerId) { 'change font size should update text data': function(containerId) {
var stage = new Kinetic.Stage({ var stage = new Kinetic.Stage({