drawString into toolItems

I have a 64x64 picture representing Bengali words. Creating it as a 32x32 pict wont do, since the letter’s ornaments get marred.
In targetMacOS environment I can satisfactorily use the 64x64 either in Retina and not-Retina builds.
Or I can scale it down at 32x32, or even draw it as a string with pretty good results:

dim p as new Picture(32,32)
p.Graphics.TextFont = BengaliFont
p.Graphics.TextSize = 20
p.Graphics.Bold = true
p.Graphics.ForeColor = kClrBlu
p.Graphics.DrawString "????", 0, 16
p.Graphics.ForeColor = kClrGreenClover
p.Graphics.DrawString "??????", 6, 32
me.ToolItem2.icon = p

But I found out that the above code, in win32, with GDI enabled, leaves the ToolItem blackish, and up to now the only way to see the icon is to modify the code as:

dim p as new Picture(32,32,32)
p.Graphics.TextFont = BengaliFont
p.Graphics.TextSize = 20
p.Graphics.Bold = true
p.Graphics.ForeColor = kClrBlu
p.Graphics.DrawString "????", 0, 16
p.Graphics.ForeColor = kClrGreenClover
p.Graphics.DrawString "??????", 6, 32
p.transparent = 1
me.ToolItem2.icon = p

That is, depth 32 is added, and the pict is made tranparent.
Now the icon draws, but very unsatisfactorily; there are whitish spots along the letters, that get worst when the toolItem is selected.
And scaling down the 64x64 pict to 32x32 doesnt give good results.

Any suggestion how to proceed welcome. Thanks.

Since you mentioned a “ToolItem blackish” , I tried with a very basic window and toolbar, and to make sure to see the blackishness, I set the background of the window to white. I also placed p into a canvas backdrop to compare.

I did not have access to your special font so I kept System, and inferred the colors as blue and green.

No trace of grey.

[code] App.UseGDIPlus = True
dim p as new Picture(32,32)
'p.Graphics.TextFont = BengaliFont
p.Graphics.TextSize = 20
p.Graphics.Bold = true
p.Graphics.ForeColor = &c00008000 'kClrBlu
p.Graphics.DrawString “???”, 0, 16
p.Graphics.ForeColor =&c00800000 ’ kClrGreenClover
p.Graphics.DrawString “???”, 6, 32
'me.ToolItem2.icon = p
Canvas1.Backdrop = p

SaveButton = New ToolButton

SaveButton.Caption=“Save” //Caption appears below the Icon
SaveButton.Name=“Save”
SaveButton.icon= p
Toolbar11.append SaveButton[/code]

Could it be the BengaliFont ?

Yes, that is Bangla. So I tried your code and it works OK. The only difference that I can see just now is that you create the button in code, while I set the icon of an already existing button (without any icon).
That could be the reason, since when I tried to set an icon to toolItem that already had an icon, win32 complained.
As for the blackish toolitem, I meant that the toolitem showed a grey rectangle as if the icon had been set.
I’ll try creating the buttons of the toolbar in code, pretty sure now that it should work.
Thanks.

I added a toolItem to the toolBar and made the necessary modification to your code, and the test app works all right.
So I have to discover what’s wrong with the real app that actually uses the same code.

I found the reason why the button wouldnt draw the string: the code is OK, the problem is the custom Bangla font I use, which is not installed but it is loaded dynamically in the open event of app. I put the above code in a pushbutton, but the string wouldnt draw; it only draws correctly when I change the font to “Vrinda” (which comes with Windows).
The thing is strange, since the app all over uses my custom font to draw in canvases, in textareas, in button.captions etc.
Or it could be that the custom font (which I built on a Mac) is not completely suitable for Windows. Unfortunatelly I dont dare install the font on the windows PC I’m using for tests, because it is not mine to use.

[quote=204156:@Carlo Rubini]I found the reason why the button wouldnt draw the string: the code is OK, the problem is the custom Bangla font I use, which is not installed but it is loaded dynamically in the open event of app. I put the above code in a pushbutton, but the string wouldnt draw; it only draws correctly when I change the font to “Vrinda” (which comes with Windows).
The thing is strange, since the app all over uses my custom font to draw in canvases, in textareas, in button.captions etc.
Or it could be that the custom font (which I built on a Mac) is not completely suitable for Windows. Unfortunatelly I dont dare install the font on the windows PC I’m using for tests, because it is not mine to use.[/quote]

I did suspect the font, as this is the only parameter I did not have. There are apparently several Bangla fonts for download on the Internet, so I could not locate that particular one to have a look with my tools. Incompatibility is a possibility if the font is not very recent.

That said, it does seem strange that the font works in canvas and would not work in a pretty simple code.

The font is not available on the Internet; also because sometime I still correct some glyphs. But I would be happy if you could have a look at it and possibly detect the cause of the misbehavior:
https://www.dropbox.com/s/c4lr1kbrl1tozdb/AshramFont.zip?dl=0
The .zipped package contains the font compiled as .ttc and the four source-files (plus a screen-shot of how the intended picture should show). As I said, the font was created and compiled using FontForge. It looks OK on the Mac, while on Windows it is too thin therefore I always use it as Bold.
BTW: I know that .ttc is not the preferred way for Windows, yet I didnt experience any apparent problem temporarily loading it from the app.
Thanks.

OK. I just looked into the Ashram font. No major issue. The fonts miss a few unicode characters, but that is normal since the goal is Asian characters, not Roman.

Msdn https://msdn.microsoft.com/en-us/library/windows/desktop/dd183326(v=vs.85).aspx does mention ttc as one of the supported formats, so that is not that either.

Unless, I would try to just generate Ashram Bold as TTF, and try with it. One never knows.

Alternatively, and if the typography is acceptable, I would simply use a platform conditional execution and employ Vrinda for the TollButtond on Windows to be on the safe side.

Both Vrinda, as the Windows-shipped bangla font, and the two Bangla MN fonts provided by Apple look… horrible. It is as if Windows and Apple shipped as only Roman font a comic font. And that is the reason I temporarily load my own font.
Just for the sake of knowing what happens, could you spend a few minutes more and see if installing Ashram the problem gets solved? As I said, the PC I’m using for my test is not actually mine, and last year after installing Ashram I was not able to disinstall it, leaving the owner not so happy.
By the way, I solved the original issue taking a screen shot of the Mac button, and after erasing the backColor, the resulting picture was good enough to be used for the toolbar; something I could not achieve scaling down the original picture. But of course, never as clean as directly drawing the strings.
Thank you for your suggestions.

There are always catches. To Windows 10, there is a family of fonts which manifest as one font name, and styles.

With DrawString, you cannot set the style. So the only font you have access to is in fact Ashram. I installed Ashram.ttc which works fine in a TextField or in a label with styles, but when I try the code with “Ashram Bold”, all I get is a dark square.

I was able to get a proper display by generating Ashram Bold as a TTF file, which I installed alone in the system. Then the code with

p.Graphics.TextFont = "Ashram"

works just fine. You probably need to have the first line a little below as the first character is cut on top, but it displays just fine. I agree, it is much better graphically.

So to sum it up, use only Ashram bold as a TTF file and you will be OK.

You do not need to install it forever. See Windows Functionality Suite for TemporarilyInstallFontWFS, or
FontActivateMBS from MonkeyBreadSoftware.net (I use the later in one of my programs). It lets you install a font only for your app while it runs, and the font is not placed in the Fonts folder.

Michel, thank you very much for your testing and for the suggestions about installing a TTF file…
Yes, I already temporarily install Ashram using TemporarilyInstallFontWFS.