/[suikacvs]/test/html-webhacc/excanvas.js
Suika

Contents of /test/html-webhacc/excanvas.js

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations) (download) (as text)
Sun May 27 10:00:48 2007 UTC (19 years, 1 month ago) by wakaba
Branch: MAIN
CVS Tags: HEAD
File MIME type: application/javascript
++ ChangeLog	27 May 2007 10:00:30 -0000
	* excanvas.js: New (from <http://sourceforge.net/project/showfiles.php?group_id=163391&package_id=184688&release_id=505959>).

	* table.cgi: Remove |$table->{caption}->{element}|
	for table with caption processed correctly.
	Support for WinIE via ExplorerCanvas; note that
	it does not draw path with fill and stroke correctly (stroke
	is hidden?).

2007-05-27  Wakaba  <wakaba@suika.fam.cx>

1 wakaba 1.1 // Copyright 2006 Google Inc.
2     //
3     // Licensed under the Apache License, Version 2.0 (the "License");
4     // you may not use this file except in compliance with the License.
5     // You may obtain a copy of the License at
6     //
7     // http://www.apache.org/licenses/LICENSE-2.0
8     //
9     // Unless required by applicable law or agreed to in writing, software
10     // distributed under the License is distributed on an "AS IS" BASIS,
11     // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12     // See the License for the specific language governing permissions and
13     // limitations under the License.
14    
15    
16     // Known Issues:
17     //
18     // * Patterns are not implemented.
19     // * Radial gradient are not implemented. The VML version of these look very
20     // different from the canvas one.
21     // * Clipping paths are not implemented.
22     // * Coordsize. The width and height attribute have higher priority than the
23     // width and height style values which isn't correct.
24     // * Painting mode isn't implemented.
25     // * Canvas width/height should is using content-box by default. IE in
26     // Quirks mode will draw the canvas using border-box. Either change your
27     // doctype to HTML5
28     // (http://www.whatwg.org/specs/web-apps/current-work/#the-doctype)
29     // or use Box Sizing Behavior from WebFX
30     // (http://webfx.eae.net/dhtml/boxsizing/boxsizing.html)
31     // * Optimize. There is always room for speed improvements.
32    
33     // only add this code if we do not already have a canvas implementation
34     if (!window.CanvasRenderingContext2D) {
35    
36     (function () {
37    
38     // alias some functions to make (compiled) code shorter
39     var m = Math;
40     var mr = m.round;
41     var ms = m.sin;
42     var mc = m.cos;
43    
44     // this is used for sub pixel precision
45     var Z = 10;
46     var Z2 = Z / 2;
47    
48     var G_vmlCanvasManager_ = {
49     init: function (opt_doc) {
50     var doc = opt_doc || document;
51     if (/MSIE/.test(navigator.userAgent) && !window.opera) {
52     var self = this;
53     doc.attachEvent("onreadystatechange", function () {
54     self.init_(doc);
55     });
56     }
57     },
58    
59     init_: function (doc) {
60     if (doc.readyState == "complete") {
61     // create xmlns
62     if (!doc.namespaces["g_vml_"]) {
63     doc.namespaces.add("g_vml_", "urn:schemas-microsoft-com:vml");
64     }
65    
66     // setup default css
67     var ss = doc.createStyleSheet();
68     ss.cssText = "canvas{display:inline-block;overflow:hidden;" +
69     // default size is 300x150 in Gecko and Opera
70     "text-align:left;width:300px;height:150px}" +
71     "g_vml_\\:*{behavior:url(#default#VML)}";
72    
73     // find all canvas elements
74     var els = doc.getElementsByTagName("canvas");
75     for (var i = 0; i < els.length; i++) {
76     if (!els[i].getContext) {
77     this.initElement(els[i]);
78     }
79     }
80     }
81     },
82    
83     fixElement_: function (el) {
84     // in IE before version 5.5 we would need to add HTML: to the tag name
85     // but we do not care about IE before version 6
86     var outerHTML = el.outerHTML;
87    
88     var newEl = el.ownerDocument.createElement(outerHTML);
89     // if the tag is still open IE has created the children as siblings and
90     // it has also created a tag with the name "/FOO"
91     if (outerHTML.slice(-2) != "/>") {
92     var tagName = "/" + el.tagName;
93     var ns;
94     // remove content
95     while ((ns = el.nextSibling) && ns.tagName != tagName) {
96     ns.removeNode();
97     }
98     // remove the incorrect closing tag
99     if (ns) {
100     ns.removeNode();
101     }
102     }
103     el.parentNode.replaceChild(newEl, el);
104     return newEl;
105     },
106    
107     /**
108     * Public initializes a canvas element so that it can be used as canvas
109     * element from now on. This is called automatically before the page is
110     * loaded but if you are creating elements using createElement you need to
111     * make sure this is called on the element.
112     * @param {HTMLElement} el The canvas element to initialize.
113     * @return {HTMLElement} the element that was created.
114     */
115     initElement: function (el) {
116     el = this.fixElement_(el);
117     el.getContext = function () {
118     if (this.context_) {
119     return this.context_;
120