» tagged pages
» logout

sorted by: recent | see : popular
Content Tagged with SVG + Ajax

Firefox 3 for developers - メインページ - MDC

Mozilla Developer Center (MDC) へようこそ。このサイトは、プロジェクト名の "Devmo" ("DEVeloper.Mozilla.Org" の略) でも知られていますが、ウェブ開発者のために総合的、便利、正確、価値のあるリソースを提供するように作られています。

XUL: del.icio.us/tag/XUL

SVG working on the iPhone

Dylan Schiemann wrote about how disappointing it was that the iPhone didn't support SVG:

Safari on the iPhone does not currently have support for SVG. Safari 3 beta on Mac and Windows is currently the best browser on the planet for SVG performance, so this is a somewhat disappointing omission. We are hopeful that by the end of the year, the iPhone will receive the Safari 3 upgrade, and along with that native support for SVG. For now, we’ll have to wait on dynamic charting and drawing tools due to no SVG and the lack of mousemove event handlers.

It appears that if you point your iPhone 2.1 browser to SVG content and tests it now works!

Ajax: Ajaxian

SVG Effects on HTML

Sticking with SVG news.... Robert O'Callahan of Mozilla has shown SVG effects for HTML:

A while back, I announced work on applying SVG effects to HTML content. The idea is to make the SVG ‘clip-path‘, ‘mask‘ and ‘filter‘ CSS properties apply to non-SVG elements as well as SVG elements.

This work landed on trunk last week. I’ve also submitted my proposal to the SVG WG for standardization. I hope that they’ll like it; there aren’t many degrees of freedom here, for example there’s no new syntax to decide on, so there’s not much to fight over :-). And it’s good for SVG to be able to use its effects more broadly. We’ll change our implementation to match whatever the WG decides.

Unfortunately we don’t yet support external document references, so the elements describing SVG effects have to live in the same document as the elements to which they’re applied. This limits the usefulness of these effects in regular (non-XHTML) HTML for now. But we’ll fix that so that the effects can live in an external SVG file.

Check out these demos in trunk builds:

Ajax: Ajaxian

Custom fonts thanks to rendering SVG font definitions

Tom Trenka has a fantastic post on custom fonts with dojo.gfx that shows the SVG font definition implementation.

Part one of the article deals with painful, practical issues around the licensing of fonts. Tom discusses the various technical options out there, and then gets to the solution:

In general, the issues surrounding font usage have to do with the ability for someone to visit a web site, grab a specific file, and be able to reuse it without paying for a legitimate copy within any of the most commonly used programs (such as Office). Because of this concern, both the EOT and sIFR techniques work–because the fonts are embedded in a form that is not reusable in a common way.

One approach: the SVG Font Specification

Similarly, the SVG Font specification allows for the same concept—by working with a specific font definition, especially one that can be customized for the specific usage, the spec avoids most of the prickly issues surrounding licensing.

SVG fonts are relatively simple in concept; within the <defs> element, you define the main specifications of a font, and then you include specific glyph definitions. Optionally, you can include character-specific kerning information (the space between letters); some fonts include this type of hinting, and the SVG specification supports it.

JAVASCRIPT:
  1.  
  2. dojo.require("dojox.gfx");
  3. dojo.require("dojox.gfx.VectorText");
  4.  
  5. var myfont = dojox.gfx.getVectorFont(someUri);
  6.  
  7. var s = dojox.gfx.createSurface(someNode, width, height);
  8. var g = s.createGroup();
  9. var phrase = myfont.draw(
  10.     g,
  11.     { text: "The rain in Spain falls mainly on the plain.", align: "middle" },
  12.     { size: "3em" },
  13.     "blue"
  14. );
  15.  

Very impressive. If you are a typography wonk, then you have probably watched Helvetica: The Movie:

Ajax: Ajaxian

The State of SVG Browser Support + Using Flash for SVG in Internet Explorer

As part of the Open Web Advocacy work I've started with Dion and others at Google, one of my goals right now is to help increase awareness and support around doing 2-D/vector graphics on the open web. This includes tools such as the Canvas tag, SVG (Scalable Vector Graphics, an XML markup language for vector graphics), and open source cross-browser drawing toolkits such as Dojo GFX, ExplorerCanvas, and Raphael.

One of the big reasons for this is that 2-D drawing/vector graphics is the top requested feature by double the amount of other feature requests in the recent Open Ajax Alliance Browser Feature Wish List vote-off. As part of this effort I'm doing a bootcamp right now to come up to speed on the latest developments in both Canvas and SVG. I've been using Shelley Powers excellent Painting the Web book to find out the state of vector graphics on the web in 2008. During this education I've run across two interesting things.

First, I wanted to know what the status of SVG support is across the different browsers. I found Jeff Schiller's very complete SVG Test Suite results that are actively kept up to date:

SVG 1.1 became a W3C recommendation on January 13, 2003. Five years later, this page records my results of running various SVG implementations (web browsers and browser plugins) through the official SVG Test Suite. Last updated 2008-06-18.

A screenshot with some of the results:

SVG Test Results Against Browsers for SVG 1.1

SVG Test Results Against Browsers for SVG 1.1

Things are pretty good with Firefox 3, Safari 3, and the winner, Opera. There is a strong subset of SVG that can be used cross-browser with these. Of course, Internet Explorer is the limiting factor here, with a grand score of 0% for all tests:

Internet Explorer SVG Support

Internet Explorer SVG Support

This means that for open web vector graphics to be realistic we need some kind of shim for Internet Explorer (Adobe used to have a browser plugin for IE that had very high quality, but its quite large and was end of lifed in 2007). Internet Explorer actually has an earlier vector graphics standard named VML (Vector Markup Language) that can be used to 'trick' it into having 2-D graphics support that is used by a number of open source toolkits. However, VML can run into some performance issues when you start to get into a large number of nodes and animation with the available open source drawing toolkits.

One natural avenue is to emulate SVG or other 2-D graphics on Internet Explorer using Flash. I had always heard about this possibility but recently found a small company actually doing it to good effect. They have not finished yet, but their demo is impressive:

SVG Render Using Flash

SVG Render Using Flash

Here we are viewing the source of the SVG being rendered by this Flash:

SVG Renderer in Flash (View Source)

SVG Renderer in Flash (View Source)

I emailed the developers to get some more information on this Flash-based renderer and they responded:

Our SVG viewer and editor is not open source. It will be part of the new InputDraw version and with some more features - like draw recognition - will be part of the new Comics Sketch site, so users can create advanced comics strips.

We are part of a small company in Lisbon, Portugal named inEvo that works with a lot of web development, rich interfaces and other areas like computer graphics and artificial intelligence.

While I respect the hard work it took inEvo to create this and their need to charge for it, it looks like using Flash to emulate SVG is a valid approach for Internet Explorer and it would be great to have something similar available open source. Just the basic viewer being available would make sense as open source and would probably even drive more business to them for their higher level tools; it looks like inEvo has created lots of cool things above this that make sense as being commercial-only, such as an SVG editor, drawing recognition, social comics creation and sharing site, etc.

Ajax: Ajaxian

Inkscape: Open Source Drawing for SVG

I recently ran across Inkscape, an open source very high-quality graphics editor that can output SVG that I'm blown away by. Even better, it runs on Linux, Windows, and Mac OS X. From the Inkscape website:

[Inkscape is] an Open Source vector graphics editor, with capabilities similar to Illustrator, CorelDraw, or Xara X, using the W3C standard Scalable Vector Graphics (SVG) file format.

Inkscape supports many advanced SVG features (markers, clones, alpha blending, etc.) and great care is taken in designing a streamlined interface. It is very easy to edit nodes, perform complex path operations, trace bitmaps and much more. We also aim to maintain a thriving user and developer community by using open, community-oriented development.

Here's a screenshot looking at one of the samples, a vector image of a car; there are a huge number of great tools in this beastie:

Screenshot of Inkscape showing vector image of car

Screenshot of Inkscape showing vector image of car

One of the coolest features of Inkscape is it can take a bitmap image, and do tracing of the edges to create a vector representation! Vector images are inherently more "impressionistic"; they are for more illustration type purposes. I decided to take this feature for a spin and took a photograph I have of myself and do edge detection. Here is the photograph before, loaded into Inkscape ready to process:

Inkscape with bitmap, non-vector photograph

Inkscape with bitmap, non-vector photograph

Here are the results after playing around with the various options; on the right-hand side of the screen is the options dialog that you can use to fiddle around with the various settings for edge detection:

Screenshot of Inkscape with traced, vector representation

Screenshot of Inkscape with traced, vector representation

Now, I can save this into an SVG file suitable for the web. I could then edit the markup, or bring it onto a web-page. More on embedding SVG in a future post.

One of the strengths of SVG is that it is a file format suitable for exporting such things; while the Canvas tag is great for having a canvas that JavaScript can draw onto, you can't easily export illustrations into calls to a Canvas as you can with SVG.

Ajax: Ajaxian

Raphaël: Simple graphics wrapper on top of SVG and VML

Dmitry Baranovskiy of Atlassian has created Raphaël "a small JavaScript library that should simplify your work with vector graphics on the web. In case you want to create your own specific chart or image crop-n-rotate widget, you can simply achieve it with this library."

Raphaël uses SVG and VML as a base for graphics creation. Because of that every created object is a DOM object so you can attach JavScript event handlers or modify objects later. Raphaël’s goal is to provide an adapter that will make drawing cross-browser and easy. Currently library supports Firefox 3.0+, Safari 3.0+, Opera 9.5+ and Internet Explorer 6.0+.

The API looks like this:

JAVASCRIPT:
  1.  
  2. // Creates canvas 320 × 200 at 10, 50
  3. var paper = Raphael(10, 50, 320, 200);
  4. // Creates circle at x = 50, y = 40, with radius 10
  5. var circle = paper.circle(50, 40, 10);
  6. // Sets the fill attribute of the circle to red (#f00)
  7. circle.attr("fill", "#f00");
  8. // Sets the stroke attribute of the circle to white (#fff)
  9. circle.attr("stroke", "#fff");
  10.  

Check out demos showing reflection, image rotation, and text rotation.

Here is the reflection:

done via:

JAVASCRIPT:
  1.  
  2. $(function () {
  3.     var src = $(".image img")[0].src;
  4.     var R = Raphael("mirror", 320, 240);
  5.     var gradient2 = {type: "linear", dots: [{color: "#000", opacity: .5}, {color: "#000"}], vector: [0, 0, 0, "100%"]};
  6.     R.image(src, 0, 0, 320, 320).matrix(1, 0, 0, -1, 0, 280);
  7.     R.rect(-2, -2, 322, 83).attr({gradient: gradient2, "stroke-width": 0});
  8.     R.rect(-2, 80, 322, 240).attr({fill: "#000", "stroke-width": 0});
  9. });
  10.  

(via Charles Miller)

Ajax: Ajaxian

Paint Servers: SVG and Canvas

Robert O'Callahan and Dave Hyatt have been chatting about paint servers as Robert creates SVG ones and then arbitary elements.

This continues the meme of taking common use cases and making them easy via CSS (e.g. reflections).

Here is the SVG version:

HTML:
  1.  
  2. <html xmlns="http://www.w3.org/1999/xhtml"
  3.      xmlns:svg="http://www.w3.org/2000/svg">
  4. h1 { background:url(#h); }
  5. p { background:url(#p); }
  6. span { background:url(#h); }
  7. </style>
  8. </head>
  9.   <h1 style="width:95%;">Heading</h1>
  10.   <p style="width:90%; border:1px solid black; margin-left:2em;">
  11.   "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor
  12.   incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud
  13.   exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute
  14.   irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
  15.   pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia
  16.   deserunt mollit anim id est laborum."
  17.   </p>
  18.   <div style="width:200px;">"Lorem ipsum dolor sit amet,
  19.   <span>consectetur adipisicing elit, sed do eiusmod</span>
  20.   tempor incididunt ut labore et dolore magna aliqua.</div>
  21.   <svg :svg style="height:0">
  22.     </svg><svg :linearGradient id="h" x2="1" y2="0">
  23.       <svg :stop stop-color="yellow" offset="0"/>
  24.       <svg :stop stop-color="yellow" stop-opacity="0" offset="1"/>
  25.     </svg>
  26.     <svg :pattern id="p" patternUnits="userSpaceOnUse"
  27.              x="0" y="0" width="50" height="50"
  28.              viewBox="-1 -1 9 5.5">
  29.       <svg :path d="M 0 0 L 7 0 L 3.5 7 z" fill="red" stroke="blue" opacity="0.3"/>
  30.     </svg>
  31.  
  32. </body>
  33. </html>
  34.  

And here for canvas:

HTML:
  1.  
  2. <!DOCTYPE HTML>
  3. p { background:url(#d); }
  4. </style>
  5. </head>
  6. <body style="background:yellow;">
  7.   <p style="width:60%; border:1px solid black; margin-left:100px;">
  8.   "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor
  9.   incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud
  10.   exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute
  11.   irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
  12.   pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia
  13.   deserunt mollit anim id est laborum."
  14.   </p>
  15.   <canvas id="d" width="50" height="50"></canvas>
  16.     var d = document.getElementById("d");
  17.     var iteration = 0;
  18.     function iterate() {
  19.       ++iteration;
  20.       var ctx = d.getContext("2d");
  21.       ctx.save();
  22.       ctx.clearRect(0, 0, 50, 50);
  23.       ctx.translate(25,25);
  24.       ctx.rotate(Math.PI*iteration/180);
  25.       ctx.fillStyle = "lime";
  26.       ctx.fillRect(-10, -10, 20, 20);
  27.       ctx.restore();
  28.       setTimeout(iterate, 10);
  29.     }
  30.     iterate();
  31.   </script>
  32. </body>
  33. </html>
  34.  

Exciting!

Ajax: Ajaxian

Vitamin Features " Create cross browser vector graphics

For years, web developers have asked the question, "How can I draw in the browser?". This simple question has anything but a straightforward answer. While the image tag is great, CSS is amazing, and Flash gets the job done,

Dojo: del.icio.us tag dojo

Mozilla Experiments with Applying SVG Effects to HTML

It seems so obvious once you think about it, but Rob O'Callahan from Mozilla took us by surprise in his blog post demonstrating his experimental branch of Gecko that allows you to apply SVG effects to HTML.

SVG filters applied to HTML content

The code for applying the effects above follows:

XML:
  1.  
  2. <html xmlns="http://www.w3.org/1999/xhtml"
  3.       xmlns:svg="http://www.w3.org/2000/svg">
  4. <body style="background:#ccc; font-size:30px;">
  5.   <style>
  6.     p { width:300px; border:1px solid black; display:inline-block; margin:1em; }
  7.     iframe { width:300px; height:300px; border:none; }
  8.     b { outline:1px dotted blue; }
  9.   </style>
  10.   <p class="target" style="background:lime;">
  11.     Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt
  12.     ut labore et dolore magna aliqua. Ut enim ad minim veniam.</p>
  13.   <iframe class="target" src="http://mozilla.org"/>
  14.   <p>Lorem ipsum dolor sit amet, consectetur adipisicing
  15.     <b class="target">elit, sed do eiusmod tempor incididunt
  16.     ut labore et dolore magna aliqua.</b> Ut enim ad minim veniam.</p>
  17.  
  18.   <style>.target { clip-path: url(#c1); }</style>
  19.   <svg :svg height="0">
  20.     </svg><svg :mask id="m1" maskUnits="objectBoundingBox" maskContentUnits="objectBoundingBox">
  21.       </svg><svg :linearGradient id="g" gradientUnits="objectBoundingBox" x2="0" y2="1">
  22.         <svg :stop stop-color="white" offset="0"/>
  23.         <svg :stop stop-color="white" stop-opacity="0" offset="1"/>
  24.       </svg>
  25.       <svg :circle cx="0.25" cy="0.25" r="0.25" id="circle" fill="white"/>
  26.       <svg :rect x="0.5" y="0.2" width="0.5" height="0.8" fill="url(#g)"/>
  27. </body>
  28. </html>

Rob makes a bunch of good points, such as:

CSS isn't really up to the task [of applying advanced visual effects to HTML]. One problem is that CSS isn't good at manipulating structured values like shapes and filter processing stacks; they're cumbersome to write in CSS expression syntax, or else they require new custom CSS syntax (e.g. @-rules), and there's no standard DOM to let scripts manipulate components of these structured values. Another issue is that we should try to avoid duplicating specification and implementation of complex features.

Contrast that with SVG, which long ago dealt with spec'ing out fancy-pants effects in mark-up and interfacing with JavaScript APIs. In fact, Rob ends his piece with a little snubby-snubby to Flash and Silverlight based both on SVG's status as a standard and its nice integration with page markup:

A nice side effect of providing better SVG-HTML integration is that it gives SVG a leg up on the Web. You can't do these effects using Flash or Silverlight, and since they're not standards they probably won't ever be invited to this party.

Unlike WebKit's shiny new CSS stuff, you can't just yet get a build of this stuff in Gecko:

I'm making tryserver builds right now, and I'll update this post with a link when they're ready. Here's a link to my Mercurial repository.

But it looks like builds are forthcoming. Hats off to Rob for putting together such a cool proof-of-concept.

Ajax: Ajaxian

Fun with SVG and CSS Animations

Torrey Rice took Safari 3.1 and the new CSS Animations feature, and mashed it up with SVG to create a fisheye demo.

All the functionality through CSS:

CSS:
  1.  
  2. .dock img {
  3.    width:50px;
  4.    padding:10px;
  5.    float:left;
  6.    position:relative;
  7.    display:block;
  8.    -webkit-transition:width 0.5s ease-out, top 0.2s ease-out;
  9. }
  10.  
  11. .dock img:hover {
  12.    width:100px;
  13. }
  14.  
  15. .dock img:active {
  16.    top:-40px;
  17. }
  18.  
  19. .dock img:hover + img