From 42eda94675bd5190a4ae88beb9475f5baa8d3f21 Mon Sep 17 00:00:00 2001 From: Anton Lavrenov Date: Sun, 26 Apr 2015 08:34:28 +0700 Subject: [PATCH] Repair fill gradient for text. close #39 --- CHANGELOG.md | 1 + src/Context.js | 2 +- src/shapes/Text.js | 6 +++++- test/unit/shapes/Text-test.js | 24 ++++++++++++++++++++++++ 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d263ecb2..08de3bef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - Fix bug when filters are not correct for HDPI - Fix bug when hit area is not correct for HDPI - Fix bug for incorrect `getClientRect` calculation +- Repair fill gradient for text ### Changed - context wrapper is more capable with native context. diff --git a/src/Context.js b/src/Context.js index b404e12e..1d139e98 100644 --- a/src/Context.js +++ b/src/Context.js @@ -494,7 +494,7 @@ grd.addColorStop(colorStops[n], colorStops[n + 1]); } this.setAttr('fillStyle', grd); - this.fill(); + shape._fillFunc(this); } }, _fillRadialGradient: function(shape) { diff --git a/src/shapes/Text.js b/src/shapes/Text.js index 59976fa8..1b2fdb34 100644 --- a/src/shapes/Text.js +++ b/src/shapes/Text.js @@ -66,8 +66,12 @@ Konva.Text.prototype = { ___init: function(config) { config = config || {}; - config.fill = config.fill || 'black'; + // set default color to black + if (!config.fillLinearGradientColorStops && !config.fillRadialGradientColorStops) { + config.fill = config.fill || 'black'; + } + if (config.width === undefined) { config.width = AUTO; } diff --git a/test/unit/shapes/Text-test.js b/test/unit/shapes/Text-test.js index 775be9cd..d671268b 100644 --- a/test/unit/shapes/Text-test.js +++ b/test/unit/shapes/Text-test.js @@ -396,5 +396,29 @@ suite('Text', function(){ stage.add(layer); }); + test('gradient', function(){ + var stage = addStage(); + var layer = new Konva.Layer(); + + var text = new Konva.Text({ + fontSize: 50, + y : 10, + x : 10, + fillLinearGradientStartPoint: { x : -50, y : -50}, + fillLinearGradientEndPoint: { x : 50, y : 50}, + fillLinearGradientColorStops: [0, 'yellow', 1, 'yellow'], + text: 'Text with gradient!!', + draggable : true + }); + layer.add(text); + stage.add(layer); + + var data = layer.getContext().getImageData(79, 37, 1, 1).data; + assert.equal(data[0], 255); + assert.equal(data[1], 255); + assert.equal(data[2], 0); + assert.equal(data[3], 255); + }); + }); \ No newline at end of file