Slashdot Mirror


Lightweight C++ Library For SVG On Windows?

redblue writes "I would like to display vector graphics in my Windows C++ programs with minimal system requirements. Some of the possibilities are: 1. Enhanced Metafile Format format/EMF+, 2. Flash/SWG, 3. Silverlight/XAML, 4. SVG. The non-open proprietary nature of #2 & #3 make them unattractive. Since EMF+ is not amenable to easy editing, it leaves SVG as the only format worth pursuing. The trouble is that the major vendors have a lock on the market with their proprietary formats; leaving SVG high and dry with no easy native OS support. At least not on Windows. From what I could learn on the intertubes, Cairo is the best, if not only, reasonable system that may enable compiled SVG support. Unfortunately, AFAIK, it comes with a price tag of >2MB overhead and the C++ bindings are not straightforward." Read on for the rest of redblue's question; can you improve on his home-brewed solution? "In a flash of the NIH syndrome, I rolled my own SVG processing engine and it has addressed my needs. You can see the result on http://www.arosmagic.com/Solitaire. A simple breakdown is: Framework+CRT(150K), SVG engine(100k), SVG art(350k). My SVG library is sufficient for me for now. But I can't help wonder:
1. Is there a better SVG library out there already available for easy inclusion?
2. If not, is there a need, i.e. market demand, for a lightweight (~200K) C++ SVG library that does not have the baggage of Silverlight or Flash?

If the answers are No/Yes, it may be worth it to make this library fully SVG compliant and release it as an open source alternative to the offerings from the entities that we shall not name but just collectively refer to as The Microbe. Please help out by letting me know if such a component is something that you would personally want to use in your current/future projects."

23 of 130 comments (clear)

  1. Inkscape? by PinkPanther · · Score: 2, Insightful

    I haven't looked at the code, but is there something that you can leverage from Inkscape?

    --
    It's a simple matter of complex programming.
    1. Re:Inkscape? by morgan_greywolf · · Score: 3, Informative

      The Inkscape project is huge, but it almost sounds like you could rip livarot, Inkscape's current renderer, right from the code and use it. Inkscape itself doesn't even use Cairo because they consider it too immature (and, IMHO, it is, at this point).

      OTOH, you could simply use librsvg to render the SVG graphics to PNG (or some other supported format) and display with the appropriate library calls.

      Using librsvg this way always seemed like a bit of a kludge to me, but lots of projects use it for rendering.

      So, to answer the OPs question as to whether or not there is a need for a lightweight C/C++ renderer -- I'd say yes.

  2. Trim cairo? by EkriirkE · · Score: 2, Interesting

    It looks like your needs/game only use basic vectors, nothing fancy like blends, blurs. Could you just strip out much of the code from the SVG source that does stuff you don't foresee using?

    --
    from 09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0
    to 45 2F 6E 40 3C DF 10 71 4E 41 DF AA 25 7D 31 3F
  3. Webkit? by EsbenMoseHansen · · Score: 2, Informative

    IÍ'd say QT/Webkit is the best bet currently. That will give you XML tools and a decent SVG view(er).

    --
    Religion is regarded by the common people as true, by the wise as false, and by rulers as useful.
    1. Re:Webkit? by Carewolf · · Score: 3, Interesting

      Pulling QtWebkit in is not exactly light weight. But Qt actually has another SVG rendered that implements the SVG tiny standard. Using QtSvg is still several megabytes of Qt libraries though, so except for the nice C++ interface, not the solution for the original question.

  4. "The non-open and proprietary..." blah blah by El+Cabri · · Score: 4, Insightful

    That's just ideological drivel. The point is, SVG is a " standard " with a nice w3c.org - hosted spec and a nice diversified, academy-industry panel of contributors, but the fact remains, that in the 10 years since it became a standard, nobody really cares. Even browsers that support it officially only support subsets of it. The pragmatic reality is that it's a standard only in name, not in fact. If you want something with a clean, complete, consistent documentation describing a real, working, complete, multi-platform implementation, then what you call " proprietary" solutions are actually the way to go. Read the actual license terms for them and you'll see there's actually NOTHING that they prevent you to do, that you'll likely to have any interest in doing.

  5. I've been thinking... by Anonymous Coward · · Score: 5, Interesting

    ..about ripping the V8 and Skia engines from Chrome and making a standalone vector graphics system. Skia is light by design. V8 is fast and easy to embed by design. It's all C++ from the ground up. Implement the SVG interpreter in Javascript. Provide a JSON based alternative for the XML haters. Merge ongoing improvements from Chrome et al.

    Just need a year of funding...

  6. TWO WHOLE MEGABYTES? by The+End+Of+Days · · Score: 5, Funny

    2 megabytes of overhead? It ain't 1988 anymore, 2MB barely even registers these days.

    I get the whole Slashdot obsession with bloat, but there's a limit.

    1. Re:TWO WHOLE MEGABYTES? by mpapet · · Score: 4, Informative

      Yeah, 2 whole megabytes may be too much. Remember there are *vastly* more small/dumb computing devices out there than the big-old desktop PC. So, maybe he's programming on a phone platform or some such and making a sincere effort to make something different.

      I don't quite know what you are after, but I'll throw out SDL as a platform and SDL_svg. It may not fit in the requirements, but hey, it's worth a look.

      --
      http://www.maxineudall.com/2010/02/should-economists-be-sued-for-malpractice.html
    2. Re:TWO WHOLE MEGABYTES? by mzs · · Score: 2, Insightful

      But this is solitaire. When I was a kid I wrote a version of solitaire in less than 300 lines. This should not be a 2+ MB program, and see he did it around 650K of object code.

  7. blah blah, I don't know what I am saying blah blah by Kludge · · Score: 4, Interesting

    The pragmatic reality is that SVG is becoming standard very quickly. Have a look at wikipedia.org. (Have you heard of it?)

    " proprietary" solutions are actually the way to go. Read the actual license terms for them and you'll see there's actually NOTHING that they prevent you to do, that you'll likely to have any interest in doing.

    Yes, I'm sure that Adobe will have no problem with him using their library in his program that he gives out to all his friends and clients.

  8. Re:"The non-open and proprietary..." blah blah by theskipper · · Score: 2, Insightful

    Read the actual license terms for them and you'll see there's actually NOTHING that they prevent you to do, that you'll likely to have any interest in doing.

    Maybe not but I'd argue it's a tad naive. Out here in the real world, there's nothing stopping a for-profit company from changing terms on their proprietary format license. After all, it's theirs. If they can make a profit by altering the terms in the future then why shouldn't they?

    And proprietary formats work surprisingly well. Witness .doc as well as AutoDesk's venerable .dwg format. A truly obfuscated mess and they're still number one because of it.

  9. Mobile SVG by SpaceToast · · Score: 2, Interesting

    I'd suggest looking at projects for bringing SVG to smartphones. You may find an SVG library for Windows CE that would compile under (vanilla) Windows -- probably not feature complete, but chances are the Mobile SVG specs are enough for your needs. I believe there is at least one very trim branch of Firefox underway, though SVG support may be one of the things that it trimmed. Good luck.

  10. Re:If you have the time/energy, then yes, please d by erebus24 · · Score: 2, Informative
  11. Antigrain rules by Cyberax · · Score: 4, Informative

    The author of Antigrain is a perfectionist.

    Just look here - http://www.antigrain.com/svg/index.html . And version 2.4 is under BSD license.

    1. Re:Antigrain rules by RAMMS+EIN · · Score: 2, Interesting

      How would you say AGG compares to Cairo?

      --
      Please correct me if I got my facts wrong.
    2. Re:Antigrain rules by ciroknight · · Score: 4, Informative

      Shortlist: AGG is a software renderer, and is a bit faster than Cairo-Pixman, though is less accurate than Cairo (Cairo is designed for correctness over performance, where possible, but does have an extensive regression and performance testing framework).

      Cairo has multiple backends: Pixman which is software, X11 (through XCB or XLib), Windows, Mac OS X, BeOS, PDF/PS/SVG, DirectFB, SDL, OS/2, several OpenGL backends (Glitz though it's unmaintained, and at least two 'plain' OpenGL backends from different hackers), an OpenVG backend and an in-progress DRI2 backend (which directly uses the graphics hardware in Linux). In addition, it has very rich font support, supporting the default font system on the platforms above, and includes support for user-defined fonts. AGG's font support is rather mediocre, supporting only Freetype and Win32. Neither library does much extensive layout code, though Pango uses Cairo to produce (arguably) the best text layout experience in the (FOSS) world.

      AGG has a richer set of vector-related features, such as Gaussian filtering (which has been a todo item for Cairo for quite some time), Type-6/7 meshes with Gouraud shading and image warping, and provides Gamma correction. Some work has been done on adding Gamma and color correction to Cairo, but I don't believe there's anything deliverable at this point.

      Cairo has a richer set of bindings; being written in C, it has bindings to practically every commonly used programming language, and a few uncommonly/rarely used ones, such as OCaml and Keith Packard's Nickel language.

      All-in-all, it's about what you're going to do with the two libraries. AGG is written more towards a graphics package, like Inkscape or the GIMP. Cairo is written more to be the backend of a display system, like Quartz2D.

      --
      "Victory means exit strategy, and it's important for the President to explain to us what the exit strategy is." G.W.Bush
  12. Re:"The non-open and proprietary..." blah blah by Billy+the+Mountain · · Score: 2, Funny

    Yeah, I guess the OP would just have to convert his C++ project over to Java which is pretty much trivial! (since they both use C-based syntax)

    --
    That was the turning point of my life--I went from negative zero to positive zero.
  13. Cairo too immature? by ciroknight · · Score: 3, Insightful

    OTOH, you could simply use librsvg to render the SVG graphics to PNG (or some other supported format) and display with the appropriate library calls.

    You bash Cairo for being "too immature" (wtf, really? It's one of the most advanced 2D vector libraries out there), and then recommend a rendering library that is written exclusively to render to Cairo. Well played sir.

    --
    "Victory means exit strategy, and it's important for the President to explain to us what the exit strategy is." G.W.Bush
  14. Re:"The non-open and proprietary..." blah blah by eggnoglatte · · Score: 3, Insightful

    ...Even browsers that support it officially only support subsets of it.

    Exactly. The root cause is that "lightweight" and "SVG" are mutually exclusive. SVG is an incredibly complex standard, and implementing it to spec is going to take incredibly complex code.

  15. Inkscape uses Cairo by Giant+Electronic+Bra · · Score: 2, Informative

    Inkscape uses Cairo for all its rendering. Thus it is not going to be lighter weight than Cairo. There may be code in there that would provide a more useful interface, especially for C++ code. Reuse is always a good idea...

    --
    "Malo periculosam, libertatem quam quietam servitutem." -- Jefferson
  16. Re:blah blah, I don't know what I am saying blah b by Anonymous+Conrad · · Score: 2, Interesting

    Yes, I'm sure that Adobe will have no problem with him using their library in his program that he gives out to all his friends and clients.

    The Flash player? Go right ahead: "Adobe provides a free license to allow you to redistribute Adobe Flash Player or Adobe Shockwave Player on your company's intranet, or with your software product or service." (here)

    Ditto the XAML solution: the render is included in .NET 3.

    The pragmatic reality, to borrow your phrase, is that more people have a Flash player installed than an SVG renderer.

  17. My SVG Library by JM+Apocalypse · · Score: 2, Interesting

    I've been working on a similar problem in my spare time for quite some time now. I needed a SVG library that was BSD-compatible, could draw any Adobe Illustrator SVG, and selectively enable or disable objects by their ID that was suitable for inclusion in a 3D game.

    I couldn't find any library that fit the requirements, so I ended up writing a C++ library called Donner SVG. It is heavily based on librsvg except written with SVG DOM in mind and for minimal dependencies. It's only dependencies are Cairo, rapidxml, and libcroco, but none of libcroco's dependencies as I wrote a compatibility layer. Additionally, the renderer can be easily swapped out to eliminate the Cairo requirement.

    Some notable features:
    - Ability to access the SVG document tree and modify it after loading an SVG.
    - Supports all shapes and paint server types (radial and linear gradients with stops, solid colors, and transparency).
    - CSS2 selector support.
    - Bounding box calculation.

    It renders static SVGs very well, but I don't consider it to be releasable yet. My goal is to fully implement the #SVG-static feature string and use the library to implement a SVG extension for skeletal animation and inverse kinematics.

    I'm willing to send a copy of the source over if anyone is interested, just contact me at "donner (at) jeffrules (dot) com". It is licensed under the LGPL as parts of it are borrowed from librsvg.

    --

    - - - - - - -
    Orppf urp mf y.ppcxn. yflcbi otcnnov C am yflcbi yr n.apb Ekrpatv (Dvorak -> Qwerty)