-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
storing context settings before scaling and restore after
- Loading branch information
Showing
5 changed files
with
25 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "canvas-text-wrapper", | ||
"version": "0.5.1", | ||
"version": "0.6.4", | ||
"ignore": [ | ||
"**/.*", | ||
"**/*.log", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/*! canvas-text-wrapper | ||
* https://github.com/namniak/canvas-text-wrapper | ||
* Version: 0.6.3 | ||
* Version: 0.6.4 | ||
* MIT License (http://www.opensource.org/licenses/mit-license.html) | ||
*/ | ||
|
||
|
@@ -38,8 +38,13 @@ | |
|
||
var scale = 1; | ||
if (opts.renderHDPI && window.devicePixelRatio) { | ||
var lineWidth = context.lineWidth; | ||
var strokeStyle = context.strokeStyle; | ||
var tempCtx = {}; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
namniak
Author
Owner
|
||
|
||
// store context settings in a temp object before scaling otherwise they will be lost | ||
for (var key in context) { | ||
tempCtx[key] = context[key]; | ||
} | ||
|
||
var canvasWidth = canvas.width; | ||
var canvasHeight = canvas.height; | ||
scale = window.devicePixelRatio; | ||
|
@@ -50,8 +55,14 @@ | |
canvas.style.height = canvasHeight * scale * 0.5 + 'px'; | ||
context.scale(scale, scale); | ||
|
||
context.lineWidth = lineWidth; | ||
context.strokeStyle = strokeStyle; | ||
// restore context settings | ||
for (var key in tempCtx) { | ||
try { | ||
context[key] = tempCtx[key]; | ||
} catch (e) { | ||
|
||
} | ||
} | ||
} | ||
|
||
var EL_WIDTH = (!opts.fitParent ? canvas.width : canvas.parentNode.clientWidth) / scale; | ||
|
@@ -285,8 +296,8 @@ | |
if (typeof opts.strokeText !== 'boolean') | ||
throw new TypeError('Property "strokeText" must be a Boolean.'); | ||
|
||
if (typeof opts.renderHDPI !== 'boolean') | ||
throw new TypeError('Property "renderHDPI" must be a Boolean.'); | ||
if (typeof opts.renderHDPI !== 'boolean') | ||
throw new TypeError('Property "renderHDPI" must be a Boolean.'); | ||
} | ||
} | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
could maybe the same be done through context's save() and restore() methods?