wente
2024-05-22 686e9cb12978d559130f816e5c2d2854a13c2f48
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/**
 * Package: svgedit.browser
 *
 * Licensed under the Apache License, Version 2
 *
 * Copyright(c) 2010 Jeff Schiller
 * Copyright(c) 2010 Alexis Deveria
 */
 
// Dependencies:
// 1) jQuery (for $.alert())
 
var svgedit = svgedit || {};
 
(function() {
 
if (!svgedit.browser) {
  svgedit.browser = {};
}
var supportsSvg_ = (function() {
        return !!document.createElementNS && !!document.createElementNS('http://www.w3.org/2000/svg', 'svg').createSVGRect;
})();
svgedit.browser.supportsSvg = function() { return supportsSvg_; }
if(!svgedit.browser.supportsSvg()) {
  window.location = "browser-not-supported.html";
}
else{
 
var svgns = 'http://www.w3.org/2000/svg';
var userAgent = navigator.userAgent;
var svg = document.createElementNS(svgns, 'svg');
 
// Note: Browser sniffing should only be used if no other detection method is possible
var isOpera_ = !!window.opera;
var isWebkit_ = userAgent.indexOf("AppleWebKit") >= 0;
var isGecko_ = userAgent.indexOf('Gecko/') >= 0;
var isIE_ = userAgent.indexOf('MSIE') >= 0;
var isChrome_ = userAgent.indexOf('Chrome/') >= 0;
var isWindows_ = userAgent.indexOf('Windows') >= 0;
var isMac_ = userAgent.indexOf('Macintosh') >= 0;
var isTouch_ = 'ontouchstart' in window;
 
var supportsSelectors_ = (function() {
  return !!svg.querySelector;
})();
 
var supportsXpath_ = (function() {
  return !!document.evaluate;
})();
 
// text character positioning (for IE9)
var supportsGoodTextCharPos_ = (function() {
   var retValue = false;
   var svgroot = document.createElementNS(svgns, 'svg');
   var svgcontent = document.createElementNS(svgns, 'svg');
   document.documentElement.appendChild(svgroot);
   svgcontent.setAttribute('x', 5);
   svgroot.appendChild(svgcontent);
   var text = document.createElementNS(svgns,'text');
   text.textContent = 'a';
   svgcontent.appendChild(text);
   var pos = text.getStartPositionOfChar(0)
   pos = pos.x; //if you put it on one line it fails when compiled
   document.documentElement.removeChild(svgroot);
   return (pos === 0);
})();
 
var supportsPathBBox_ = (function() {
  var svgcontent = document.createElementNS(svgns, 'svg');
  document.documentElement.appendChild(svgcontent);
  var path = document.createElementNS(svgns, 'path');
  path.setAttribute('d','M0,0 C0,0 10,10 10,0');
  svgcontent.appendChild(path);
  var bbox = path.getBBox();
  document.documentElement.removeChild(svgcontent);
  return (bbox.height > 4 && bbox.height < 5);
})();
 
// Support for correct bbox sizing on groups with horizontal/vertical lines
var supportsHVLineContainerBBox_ = (function() {
  var svgcontent = document.createElementNS(svgns, 'svg');
  document.documentElement.appendChild(svgcontent);
  var path = document.createElementNS(svgns, 'path');
  path.setAttribute('d','M0,0 10,0');
  var path2 = document.createElementNS(svgns, 'path');
  path2.setAttribute('d','M5,0 15,0');
  var g = document.createElementNS(svgns, 'g');
  g.appendChild(path);
  g.appendChild(path2);
  svgcontent.appendChild(g);
  var bbox = g.getBBox();
  document.documentElement.removeChild(svgcontent);
  // Webkit gives 0, FF gives 10, Opera (correctly) gives 15
  return (bbox.width == 15);
})();
 
var supportsEditableText_ = (function() {
  // TODO: Find better way to check support for this
  return isOpera_;
})();
 
var supportsGoodDecimals_ = (function() {
  // Correct decimals on clone attributes (Opera < 10.5/win/non-en)
  var rect = document.createElementNS(svgns, 'rect');
  rect.setAttribute('x',.1);
  var crect = rect.cloneNode(false);
  var retValue = (crect.getAttribute('x').indexOf(',') == -1);
  if(!retValue) {
    $.alert("NOTE: This version of Opera is known to contain bugs in SVG-edit.\n\
    Please upgrade to the <a href='http://opera.com'>latest version</a> in which the problems have been fixed.");
  }
  return retValue;
})();
 
var supportsNonScalingStroke_ = (function() {
  var rect = document.createElementNS(svgns, 'rect');
  rect.setAttribute('style','vector-effect:non-scaling-stroke');
  return rect.style.vectorEffect === 'non-scaling-stroke';
})();
 
var supportsNativeSVGTransformLists_ = (function() {
  var rect = document.createElementNS(svgns, 'rect');
  var rxform = rect.transform.baseVal;
  
  var t1 = svg.createSVGTransform();
  rxform.appendItem(t1);
  return rxform.getItem(0) == t1;
})();
 
var supportsBlobs_ = (function() {
  if (typeof Blob != 'function') return false;
  // check if download is supported
  var svg = new Blob(
    ["<svg xmlns='http://www.w3.org/2000/svg'></svg>"],
    {type: "image/svg+xml;charset=utf-8"}
  );
  var img = new Image();
  var support = false;
  img.onload = function()  { svgedit.browser.supportsBlobs = function() {return true} };
  img.onerror = function() { svgedit.browser.supportsBlobs = function() {return false} };
  img.src = URL.createObjectURL(svg);
  return false;
})();
 
 
 
// Public API
 
svgedit.browser.isOpera = function() { return isOpera_; }
svgedit.browser.isWebkit = function() { return isWebkit_; }
svgedit.browser.isGecko = function() { return isGecko_; }
svgedit.browser.isIE = function() { return isIE_; }
svgedit.browser.isChrome = function() { return isChrome_; }
svgedit.browser.isWindows = function() { return isWindows_; }
svgedit.browser.isMac = function() { return isMac_; }
svgedit.browser.isTouch = function() { return isTouch_; }
 
svgedit.browser.supportsSelectors = function() { return supportsSelectors_; }
svgedit.browser.supportsXpath = function() { return supportsXpath_; }
 
svgedit.browser.supportsPathBBox = function() { return supportsPathBBox_; }
svgedit.browser.supportsHVLineContainerBBox = function() { return supportsHVLineContainerBBox_; }
svgedit.browser.supportsGoodTextCharPos = function() { return supportsGoodTextCharPos_; }
svgedit.browser.supportsEditableText = function() { return supportsEditableText_; }
svgedit.browser.supportsGoodDecimals = function() { return supportsGoodDecimals_; }
svgedit.browser.supportsNonScalingStroke = function() { return supportsNonScalingStroke_; }
svgedit.browser.supportsNativeTransformLists = function() { return supportsNativeSVGTransformLists_; }
svgedit.browser.supportsBlobs = function() {return supportsBlobs_; }
}
 
})();