4 ms·
JSON is to XML what ___ is to SVG. What is in the blank? It's not exciting or clever, but HTML5 Canvas fills in that blank. It'a a minimal API that was design
by pavlov 10y ago
JSON is to XML what ___ is to SVG. What is in the blank?
It's not exciting or clever, but HTML5 Canvas fills in that blank.
It'a a minimal API that was designed by Apple to be just good enough to make Mac OS X 10.4 desktop widgets possible to implement in JavaScript. Canvas has a straightforward mapping to the big platform 2D APIs -- CoreGraphics, Cairo, Direct2D. The bitmap data interfaces are an ugly but in practice mostly satisfactory escape hatch when you need to draw something the API doesn't include.
Both SVG and CSS are failed specs in my mind due to what you succinctly describe as "incredible complexity without matching expressivity". The difference is that CSS doesn't have an alternative, so everyone tries to live with it.
- colanderman 10y agoSVG is a data format; Canvas is an API. They're only interchangeable in limited use cases.
- tyingq 10y agoFabric.js helps a bit with that. It can export/import a canvas to either JSON or SVG. http://fabricjs.com/fabric-intro-part-3#deserialization http://fabricjs.com/fabric-intro-part-3#deserialization
- pavlov 10y agoJavaScript is a programming language, yet its subset JSON is a data format. PostScript is a programming language, yet it looks like a data format to most applications. The web is supposed to be about hyperlinked documents, yet it's mostly about executing JavaScript applications these days. The blurred lines between data and code are the most exciting thing about this whole field, if you ask me!
- colanderman 10y agoJSON is based on (not a subset of) a purely declarative and structural portion of JavaScript. They really have nothing to do with each other except some surface syntax, which is wholly irrelevant. PostScript is a terrible intermediate graphics format. It is not structured like how SVG is, and thus does not lend itself well to editing. Consider the basic example of text: there is no such thing as a "text box" or "flow" in PostScript; rather, individual letters are placed at coordinates. You're right that Canvas is analogous to PostScript; Canvas also would make a terrible intermediate format. Sure, we could use it as one; it would certainly be a more universal final format than SVG; but then, what's wrong with PostScript there? It's certainly less verbose. Blurring the lines between data and code is a tarpit. I look forward to the day it's universally recognized to have been a dead end in the evolution of our field.
- bobajeff 10y agoAren't .psd and .ai formats based off of PostScript?
- ygra 10y ago.PSD certainly not. Why would it? But .AI has originally been PostScript and currently is PDF. Pretty much in the same way as Inkscape uses SVG as its native format – application-specific things are encoded as additional data on objects which can (usually) be safely ignored by other applications rendering the same file format.
- pavlov 10y ago> JSON is based on (not a subset of) a purely declarative and structural portion of JavaScript. They really have nothing to do with each other except some surface syntax, which is wholly irrelevant. That's an ahistorical view that completely ignores the only reason why JSON became popular: it could be loaded into a browser using eval() or script tags at a time when JS engines were slow and limited. If the JS-compatible syntax were irrelevant, surely everyone would have standardized on one of the existing tidier formats? > Consider the basic example of text: there is no such thing as a "text box" or "flow" in PostScript; rather, individual letters are placed at coordinates. This is good. Imagine if Adobe had designed PostScript back in 1983 using the SVG design mentality. They could not have foreseen all the applications for PostScript. The original text flow model would have rapidly become inadequate, and they would have been forced to pile on hacks into the standard -- just as happened with CSS. Between PostScript and HTML+CSS, the former is a much more useful industry standard. It's relatively easy to implement a PostScript interpreter from scratch. It's practically impossible to build a new HTML+CSS renderer. > Blurring the lines between data and code is a tarpit. I look forward to the day it's universally recognized to have been a dead end in the evolution of our field. You'll be waiting for a while. Users will keep wanting applications that do more, not less.
- colanderman 10y ago> it could be loaded into a browser using eval() That's unrelated to the code/data distinction. But it does elucidate an important downfall of blurring code & data: using eval() opened web applications up to major security holes. (Not to mention it was incorrect, JSON won't cleanly round-trip JS even with JSON.parse.) JSON is plain old data, nothing more, nothing less. Sure, I could replace all SVG tags with curly braces; that doesn't make it code. > Users will keep wanting applications that do more, not less. The ability to author vector graphics at a high level being a prime example of something more, that is not possible with a Turing tarpit of a data format like PostScript or JavaScript with lots of Canvas instructions. Applications like Inkscape are only possible because of rich data formats like SVG. Note the lack of authoring tools -- both for vector graphics and documents -- which work natively with unattributed PostScript. That's because its nature, as code, obscures all structure. It makes for a mediocre final format due to (as you point out) its ease of implementation, nothing more. And even there, PDF, which is not interpreted, has proven superior. JS+Canvas would suffer the same issues.
- flukus 10y ago> The web is supposed to be about hyperlinked documents, yet it's mostly about executing JavaScript applications these days. Is it? Most of the content people use the web for is still mostly hyperlinked documents. Although it's often obfuscated by a bunch of javascript.
- rspeer 10y agoHTML5 Canvas is the least accessible thing to be put on the Web since Flash. If you render text inside a canvas element, you end up with a picture of text. You can't screen-read it, you can't re-flow it, you can't even select it!
- euroclydon 10y agoIt's easy enough to overlay text in HTML though.
- m_fayer 10y agoThat your solution to the problem is a truly hideous hack, speaks volumes.
- euroclydon 10y agoHideous hack? Use abs positioning, and overlay. Let's see, you have a scripting language host in the presentation layer and built-in first class methods to draw HTML elements and to canvas. The horror!
- BinaryIdiot 10y agoSorry but I'm also going to consider that a pretty awful hack. If you're going through the trouble of setting up an animation loop for rendering graphics you need to have your text in the same space. If you don't now you have to bridge this gap of two different rendering worlds. There are abstractions and techniques to overlay html elements over the canvas and sorta meld them together, sure. But they're rendered and updated in astonishingly different fashions that don't really go well together. This is sorta like writing a game using a rendering technology like OpenGL but then sticking, say, a win32 label control on top of the rendered OpenGL screen. They both have very different patterns of control.
- euroclydon 10y agoThen just write the text in canvas, if it's a game. The original poster said that canvas text was not accessible and didn't wrap. I don't think screen readers and tightly synced game loops go together well. And is wrapping text some big problem in the game world?
- jancsika 10y agoHTML5 canvas doesn't fill in the blank IMO because it's too low-level. (Plus, its performance scales with canvas size where SVG's performance scales with the number of objects.) Example: suppose I inject the following innerHTML into an svg: <rect width="80" height="80"><title>The incredible disappearing rect!</title></rect>. Now I set rectElem to that rect element and do this: rectElem.animate( { opacity: [1, 0, 1] }, { duration: 5000, iterations: Infinity } ); That's actually pretty expressive. The unnecessary complexity is unfortunately even apparent here, though: a) the interrelationship between xml attrs for width/height and css property for opacity (SVG2 apparently simplifies this by making all attrs available as css properties), and b) the <title> tag points to the fact that SVG is in its own separate XML namespace, which causes all kinds of pain.
- paulddraper 10y agoCanvas is written with a imperative (Turning complete) language. SVG is declarative. Pretty large difference.
- pavlov 10y agoPostScript/PDF is also an imperative language. Yet it works for billions of documents. Users don't care about Turing completeness. "Declarative" is one of those concepts that sounds highly desirable until you start thinking about extensibility and future inter-implementation compatibility. The sad tale of the SVG 2 standard, as told in the original post, is a textbook example.
- xioxox 10y agoPDF is not a Turing-complete, but Postscript is. PDF removed several features which made Postscript a programming language.
- pavlov 10y agoThat was a great approach IMO. First build a flexible toolset that allowed the market explore the problem space, then, a decade later, collect the learnings into a new, narrower standard. If SVG 2 were like that, it probably would have got a warmer reception from browser vendors. But standards committees creating declarative formats have never been very interested in removing features.
- tonyedgecombe 10y agoI'm not sure I would call PDF a narrower standard, one of the problems with it is Adobe couldn't stop themselves adding new features.
- bryanrasmussen 10y agoSVG is a declarative markup language that can include a Turing complete scripting language. I mean it is a pretty large difference, and it's even a pretty large difference between how you described SVG and how I did it, and neither one of us is complete.