SVG with text

163 views
Skip to first unread message

Igor Korot

unread,
Nov 17, 2022, 1:05:16 AM11/17/22
to wx-dev
Hi,
Will there be an SVG library that supports text rendering?

nanoSVG does not support it and it is a nice feature to have.

Thank you.

asm warrior

unread,
Nov 17, 2022, 8:51:20 AM11/17/22
to wx-dev
Some months ago, I have modified nanoSVG to let it extract text elements, and later I draw it by wxWidgets' DrawText function.

You can find the code here: asmwarrior/SvgPanel: a wxPanel which can show svg image and simple text labels — https://github.com/asmwarrior/SvgPanel

Hopefully it helps.
Note that parsing the text field of the svg file is very difficult.

Asmwarrior

Igor Korot

unread,
Nov 19, 2022, 12:48:32 AM11/19/22
to wx-...@googlegroups.com
Hi,

On Thu, Nov 17, 2022 at 7:51 AM asm warrior <asmwa...@gmail.com> wrote:
>
> Some months ago, I have modified nanoSVG to let it extract text elements, and later I draw it by wxWidgets' DrawText function.
>
> You can find the code here: asmwarrior/SvgPanel: a wxPanel which can show svg image and simple text labels — https://github.com/asmwarrior/SvgPanel

Yes, I saw that.
However as I said I need it in the bitmap for the toolbar button.
How hard would it be to do that?

Thank you.

>
> Hopefully it helps.
> Note that parsing the text field of the svg file is very difficult.
>
> Asmwarrior
>
> On Thursday, November 17, 2022 at 2:05:16 PM UTC+8 Igor Korot wrote:
>>
>> Hi,
>> Will there be an SVG library that supports text rendering?
>>
>> nanoSVG does not support it and it is a nice feature to have.
>>
>> Thank you.
>
> --
> You received this message because you are subscribed to the Google Groups "wx-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to wx-dev+un...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/wx-dev/19bcef98-325c-41ed-9703-0be8b058fab0n%40googlegroups.com.

asm warrior

unread,
Nov 19, 2022, 7:46:41 AM11/19/22
to wx-dev
On Saturday, November 19, 2022 at 1:48:32 PM UTC+8 Igor Korot wrote:
Hi,

On Thu, Nov 17, 2022 at 7:51 AM asm warrior <asmwa...@gmail.com> wrote:
>
> Some months ago, I have modified nanoSVG to let it extract text elements, and later I draw it by wxWidgets' DrawText function.
>
> You can find the code here: asmwarrior/SvgPanel: a wxPanel which can show svg image and simple text labels — https://github.com/asmwarrior/SvgPanel

Yes, I saw that.
However as I said I need it in the bitmap for the toolbar button.
How hard would it be to do that?

Thank you.



This source file was originally created by doublemax in the wxWidgets forum, my change is just draw the text in the DC, for you requirement, I think you should draw it on the wxBitmap.

I think it could not be that hard to do it.

BTW, it looks like under Windows, wxWidgets does not have AntiAliased(true) feature for the font. So, text in your rendered bitmap may be blur if you don't enable font antialiase.
You have to enable it by yourself by the native font descriptions, see here as a reference:

Re: font rendering issue when using C::B under windows remote desktop — https://forums.codeblocks.org/index.php/topic,25146.msg171498.html#msg171498

Mostly, you should do like the code snippet below:

+
+    // enable the smooth font by default
+    // font rendering issue when using C::B under windows remote desktop
+    // https://forums.codeblocks.org/index.php/topic,25146.msg171484.html#msg171484
+
+    wxString nativeDesc = font.GetNativeFontInfoDesc();
+    int index = 0;
+    for (size_t pos = 0, start = 0; pos <= nativeDesc.length(); )
+    {
+        pos = nativeDesc.find(";", start);
+        index++;
+        if (index == 14)
+        {
+            // enable the cleartype option of the font
+            nativeDesc.replace(start, pos - start, "5");
+            bool result = font.SetNativeFontInfo(nativeDesc);
+            break;
+        }
+        start = pos+1;
+    }

Asmwarrior
 

asm warrior

unread,
Nov 28, 2022, 3:17:52 AM11/28/22
to wx-dev
Hi, Igor Korot.

I think this font rendering problem can be fully resolved. If you look at the discussion in wxWidgets.org's forum(see the link below), the forum admin "doublemax" gave me very nice solution and code to solve your original question. We have discussed this problem those days, and finally got the solution. Hope that can help you and others.

draw text with transparent background on wxBitmap — https://forums.wxwidgets.org/viewtopic.php?f=1&t=49865

Asmwarrior
Reply all
Reply to author
Forward
0 new messages