From ff7af498a361ec4a77dee0b681ff973d09d60b86 Mon Sep 17 00:00:00 2001 From: Alexis Deveria Date: Tue, 20 Apr 2010 20:29:30 +0000 Subject: [PATCH] Made lines follow 45 degree angles when holding shift, made selection box fit better on zoom, updated canvg git-svn-id: http://svg-edit.googlecode.com/svn/trunk@1531 eee81c28-f429-11dd-99c0-75d572ba1ddd --- editor/canvg/canvg.js | 236 +++++++++++++++++++++++++++++++++++------- editor/svgcanvas.js | 75 ++++++++++++-- 2 files changed, 262 insertions(+), 49 deletions(-) diff --git a/editor/canvg/canvg.js b/editor/canvg/canvg.js index d3aa73e7..d22d84ac 100644 --- a/editor/canvg/canvg.js +++ b/editor/canvg/canvg.js @@ -159,7 +159,19 @@ if(!window.console) { getDefinition: function() { var name = that.value.replace(/^(url\()?#([^\)]+)\)?$/, '$2'); return svg.Definitions[name]; - } + }, + + isUrl: function() { + return that.value.indexOf('url(') == 0 + }, + + getGradient: function(e) { + var grad = this.getDefinition(); + if (grad != null && grad.createGradient) { + return grad.createGradient(svg.ctx, e); + } + return null; + } } // length extensions @@ -171,7 +183,7 @@ if(!window.console) { EM: function(viewPort) { var em = 12; - var fontSize = new svg.Property('fontSize', svg.ctx.font.match(/[0-9][^\s\t\n\r\/]*/g)[0]); + var fontSize = new svg.Property('fontSize', svg.Font.Parse(svg.ctx.font).fontSize); if (fontSize.hasValue()) em = fontSize.Length.toPixels(viewPort); return em; @@ -220,6 +232,41 @@ if(!window.console) { } } + // fonts + svg.Font = new (function() { + this.Styles = ['normal','italic','oblique','inherit']; + this.Variants = ['normal','small-caps','inherit']; + this.Weights = ['normal','bold','bolder','lighter','100','200','300','400','500','600','700','800','900','inherit']; + + this.CreateFont = function(fontStyle, fontVariant, fontWeight, fontSize, fontFamily, inherit) { + var f = inherit != null ? this.Parse(inherit) : this.CreateFont('', '', '', '', '', svg.ctx.font); + return { + fontFamily: fontFamily || f.fontFamily, + fontSize: fontSize || f.fontSize, + fontStyle: fontStyle || f.fontStyle, + fontWeight: fontWeight || f.fontWeight, + fontVariant: fontVariant || f.fontVariant, + toString: function () { return [this.fontStyle, this.fontVariant, this.fontWeight, this.fontSize, this.fontFamily].join(' ') } + } + } + + var that = this; + this.Parse = function(s) { + var f = {}; + var d = svg.trim(svg.compressSpaces(s || '')).split(' '); + var set = { fontSize: false, fontStyle: false, fontWeight: false, fontVariant: false } + var ff = ''; + for (var i=0; i= 360-22.5 || angle < 22.5) { + x2 = start_x; + } else if(angle >= 22.5 && angle < 22.5 + 45) { + diagonal = true; + } else if(angle >= 22.5 + 45 && angle < 22.5 + 90) { + y2 = start_y; + } else if(angle >= 22.5 + 90 && angle < 22.5 + 135) { + diagonal = true; + } else if(angle >= 22.5 + 135 && angle < 22.5 + 180) { + x2 = start_x; + } else if(angle >= 22.5 + 180 && angle < 22.5 + 225) { + diagonal = true; + } else if(angle >= 22.5 + 225 && angle < 22.5 + 270) { + y2 = start_y; + } else if(angle >= 22.5 + 270 && angle < 22.5 + 315) { + diagonal = true; + } + + if(diagonal) { + if(y2 < start_y) { + y2 = start_y - val; + } else { + y2 = start_y + val; + } + + if(x2 < start_x) { + x2 = start_x - val; + } else { + x2 = start_x + val; + } + } + } + + + shape.setAttributeNS(null, "x2", x2); + shape.setAttributeNS(null, "y2", y2); if (!window.opera) svgroot.unsuspendRedraw(handle); break; case "foreignObject": @@ -6203,15 +6253,18 @@ function BatchCommand(text) { // Selector and notice var issue_list = { 'feGaussianBlur': 'Blurred elements will appear as un-blurred', - 'text': 'Text may not appear as expected', 'image': 'Image elements will not appear', 'foreignObject': 'foreignObject elements will not appear', - 'marker': 'Marker elements (arrows, etc) will not appear', - '[stroke-dasharray]': 'Strokes will appear filled', - '[stroke^=url]': 'Strokes with gradients will not appear' + 'marker': 'Marker elements (arrows, etc) may not appear as expected', // waiting for marker-mid and marker-end support + '[stroke-dasharray]': 'Strokes will appear filled' }; var content = $(svgcontent); + // Add font/text check if Canvas Text API is not implemented + if(!("font" in $('')[0].getContext('2d'))) { + issue_list['text'] = 'Text may not appear as expected'; + } + $.each(issue_list, function(sel, descr) { if(content.find(sel).length) { issues.push(descr);