Merge pull request #42 from Janpot/fix-font
Fix __parseFont to not crash
This commit is contained in:
commit
db62162a47
@ -880,7 +880,7 @@
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
ctx.prototype.__parseFont = function() {
|
ctx.prototype.__parseFont = function() {
|
||||||
var regex = /^\s*(?=(?:(?:[-a-z]+\s*){0,2}(italic|oblique))?)(?=(?:(?:[-a-z]+\s*){0,2}(small-caps))?)(?=(?:(?:[-a-z]+\s*){0,2}(bold(?:er)?|lighter|[1-9]00))?)(?:(?:normal|\1|\2|\3)\s*){0,3}((?:xx?-)?(?:small|large)|medium|smaller|larger|[.\d]+(?:\%|in|[cem]m|ex|p[ctx]))(?:\s*\/\s*(normal|[.\d]+(?:\%|in|[cem]m|ex|p[ctx])))?\s*([-,\"\sa-z]+?)\s*$/i;
|
var regex = /^\s*(?=(?:(?:[-a-z]+\s*){0,2}(italic|oblique))?)(?=(?:(?:[-a-z]+\s*){0,2}(small-caps))?)(?=(?:(?:[-a-z]+\s*){0,2}(bold(?:er)?|lighter|[1-9]00))?)(?:(?:normal|\1|\2|\3)\s*){0,3}((?:xx?-)?(?:small|large)|medium|smaller|larger|[.\d]+(?:\%|in|[cem]m|ex|p[ctx]))(?:\s*\/\s*(normal|[.\d]+(?:\%|in|[cem]m|ex|p[ctx])))?\s*([-,\'\"\sa-z]+?)\s*$/i;
|
||||||
var fontPart = regex.exec( this.font );
|
var fontPart = regex.exec( this.font );
|
||||||
var data = {
|
var data = {
|
||||||
style : fontPart[1] || 'normal',
|
style : fontPart[1] || 'normal',
|
||||||
|
@ -297,6 +297,19 @@ describe('canvas2svg', function() {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("supports fonts", function () {
|
||||||
|
it("doesn't crash when using a font", function () {
|
||||||
|
var ctx = new C2S();
|
||||||
|
ctx.font = "normal 12px 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif";
|
||||||
|
ctx.fillText("A Text Example", 0, 50);
|
||||||
|
var svg = ctx.getSvg();
|
||||||
|
expect(svg.querySelector("text").getAttribute("font-family")).to.equal("\'Helvetica Neue\', \'Helvetica\', \'Arial\', sans-serif");
|
||||||
|
expect(svg.querySelector("text").getAttribute("font-size")).to.equal("12px");
|
||||||
|
expect(svg.querySelector("text").getAttribute("font-weight")).to.equal("normal");
|
||||||
|
expect(svg.querySelector("text").getAttribute("font-style")).to.equal("normal");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("supports globalOpacity", function() {
|
describe("supports globalOpacity", function() {
|
||||||
it("set stroke-opacity when stroking and set fill-opacity when filling",function() {
|
it("set stroke-opacity when stroking and set fill-opacity when filling",function() {
|
||||||
var ctx = new C2S();
|
var ctx = new C2S();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user