Use SVG Icons with wxDataViewCtrl (and others)

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
User avatar
evstevemd
Part Of The Furniture
Part Of The Furniture
Posts: 2409
Joined: Wed Jan 28, 2009 11:57 am
Location: United Republic of Tanzania

Use SVG Icons with wxDataViewCtrl (and others)

Post by evstevemd »

Hi,
I want to replace my png icons with SVG ones. I have tried to google and I could not find any useful information so far. Have anyone tried that? How far does wxWidgets support it?

Thanks!
Chief Justice: We have trouble dear citizens!
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Use SVG Icons with wxDataViewCtrl (and others)

Post by doublemax »

wxWidgets itself has no SVG reading support. There is http://wxsvg.sourceforge.net/ but unfortunately it requires Cairo under Windows, so that's not an option for me.

For simple SVGs you can use https://github.com/memononen/nanosvg
It's very easy to integrate as it only consists of two header files. But it only supports a part of the SVG standard, so some SVGs may look broken or imcomplete. Most of the Tango icons look fine though.
Use the source, Luke!
User avatar
evstevemd
Part Of The Furniture
Part Of The Furniture
Posts: 2409
Joined: Wed Jan 28, 2009 11:57 am
Location: United Republic of Tanzania

Re: Use SVG Icons with wxDataViewCtrl (and others)

Post by evstevemd »

doublemax wrote:wxWidgets itself has no SVG reading support. There is http://wxsvg.sourceforge.net/ but unfortunately it requires Cairo under Windows, so that's not an option for me.

For simple SVGs you can use https://github.com/memononen/nanosvg
It's very easy to integrate as it only consists of two header files. But it only supports a part of the SVG standard, so some SVGs may look broken or imcomplete. Most of the Tango icons look fine though.
Thanks DM.
I will try nanosvg.
Cairo is a no-go for me too
Chief Justice: We have trouble dear citizens!
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Use SVG Icons with wxDataViewCtrl (and others)

Post by doublemax »

Here is the source for my SVG_panel i used for testing nanosvg. Maybe it helps.
Attachments
svg_panel.h
(484 Bytes) Downloaded 215 times
svg_panel.cpp
(3.06 KiB) Downloaded 271 times
Use the source, Luke!
ollydbg23
Super wx Problem Solver
Super wx Problem Solver
Posts: 438
Joined: Fri Dec 12, 2008 10:31 am

Re: Use SVG Icons with wxDataViewCtrl (and others)

Post by ollydbg23 »

FYI:

If you use Msys2, you will see there are already some SVG library packages, you can easily install them by the pacman command:

Package: mingw-w64-x86_64-wxsvg - MSYS2 Packages

Package: mingw-w64-x86_64-librsvg - MSYS2 Packages

Once you install this package, all the appendices are also installed.
ollydbg23
Super wx Problem Solver
Super wx Problem Solver
Posts: 438
Joined: Fri Dec 12, 2008 10:31 am

Re: Use SVG Icons with wxDataViewCtrl (and others)

Post by ollydbg23 »

doublemax wrote: Wed Jun 06, 2018 5:34 pm Here is the source for my SVG_panel i used for testing nanosvg. Maybe it helps.
Thanks!

It looks like wxWigets are now using nanosvg.


Just FYI: wxWidgets does now include nanosvg as SVG renderer · Issue #201 · memononen/nanosvg
ollydbg23
Super wx Problem Solver
Super wx Problem Solver
Posts: 438
Joined: Fri Dec 12, 2008 10:31 am

Re: Use SVG Icons with wxDataViewCtrl (and others)

Post by ollydbg23 »

I try to use doublemax's svg_panel.cpp/h file to show a svg file.

While I see that nanosvg can not support showing the text field. Luckily, I found someone has a pull request to the nanosvg, and the parser can extract the text, and I can now draw the text by the dc.DrawText function over the rasterized svg image.

See discussion here: Adds basic text parsing by jamislike · Pull Request #94 · memononen/nanosvg

And see the image shot here, note that the text "abc" is drawn by the native dc.DrawText function.

show_text_by_wx_dc_DrawText.png
show_text_by_wx_dc_DrawText.png (48.38 KiB) Viewed 980 times
ollydbg23
Super wx Problem Solver
Super wx Problem Solver
Posts: 438
Joined: Fri Dec 12, 2008 10:31 am

Re: Use SVG Icons with wxDataViewCtrl (and others)

Post by ollydbg23 »

FYI:

I have create a github repo to share my work on show SVG text by the nanosvg and doublemax's svg_panel.cpp/h.

See here: asmwarrior/SvgPanel: a wxPanel which can show svg image and simple text labels
Post Reply