Page 1 of 1

Problem printing some unicode characters to canvas gadget

Posted: Sun Apr 20, 2025 6:14 am
by TassyJim
PB6.20 and PB6.21 beta6
I have a strange problem printing some Unicode characters to a canvas gadget.
The characters I have found so far are
Chr($2370)+Chr($23fb)+Chr($23f5)+Chr($2315)+Chr($29f2)
They render as a hollow box unless I include a "magic" character in the string.

One of the magic characters is Chr($23fa)

Code: Select all

testtxt.s = "*"+Chr($23fb)+Chr($23fa)+Chr($23fb)+Chr($23fb)+"*"
testtxt2.s = "*"+Chr($23fb)+Chr($23fb)+Chr($23fb)+Chr($23fb)+"*"
problemch.s= Chr($2370)+Chr($23fb)+Chr($23f5)+Chr($2315)+Chr($29f2)

If OpenWindow(0, 0, 0, 420, 180, "CanvasGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  CanvasGadget(0, 10, 10, 400, 100)
  TextGadget(2,0,120,250,40,testtxt+"  "+testtxt2+"  "+problemch)
  LoadFont(1,"Courier New",14)
  If StartDrawing(CanvasOutput(0))
    DrawingFont(FontID(1))
    
    DrawText(10,50,testtxt)
    DrawText(150,50,testtxt2)
    DrawText(300,50,problemch+Chr($23fa))
    DrawText(300,10,problemch)
    StopDrawing()
  EndIf
  
  Repeat
    Event = WaitWindowEvent()
    
  Until Event = #PB_Event_CloseWindow
EndIf
Changing font doesn't seem to make any difference.
No problems printing to a TextGadget.

Jim

Re: Problem printing some unicode characters to canvas gadget

Posted: Sun Apr 20, 2025 8:31 am
by STARGÅTE
Image
Confirmed.

However, if I use e.g. Segoe UI, DrawText renders the characters also without the magic character, but the size is different:
Image

Re: Problem printing some unicode characters to canvas gadget

Posted: Sun Apr 20, 2025 9:08 am
by TassyJim
I notice that your TextGadget text is not correct either.
You don't seem to have Chr($23fb) available. (looks like a power switch)

I just tested Vector text and it DOES print the characters correctly.

Jim

Re: Problem printing some unicode characters to canvas gadget

Posted: Sun Apr 20, 2025 9:57 am
by Fred
Just for info, was it working in previous PB version (6.1x) ?

Re: Problem printing some unicode characters to canvas gadget

Posted: Sun Apr 20, 2025 10:20 am
by STARGÅTE
Fred wrote: Sun Apr 20, 2025 9:57 am Just for info, was it working in previous PB version (6.1x) ?
No. I think it is a problem with character replacement, when a character is not present in the used font.

Re: Problem printing some unicode characters to canvas gadget

Posted: Sun Apr 20, 2025 10:54 am
by TassyJim
Fred,
V6.10 has the same issue.
I don't have any earlier version installed.
Characters are displayed correctly in a TextGadget but not on the canvas.
Vector graphics display correctly so the characters are present in the font.

Re: Problem printing some unicode characters to canvas gadget

Posted: Sun Apr 20, 2025 12:14 pm
by Fred
We just use TextOut_() to draw the font so I guess the problem lies here

Re: Problem printing some unicode characters to canvas gadget

Posted: Sun Apr 20, 2025 1:47 pm
by User_Russian
Maybe function DrawText() won't have this problem.

Re: [Done] Problem printing some unicode characters to canvas gadget

Posted: Wed Apr 30, 2025 5:11 pm
by Fred
Fixed.

Re: [Done] Problem printing some unicode characters to canvas gadget

Posted: Fri May 09, 2025 10:57 am
by Fred
Reverted the fix as it creates slowness. I will probably introduce a new flag to have a fast vs precise drawtext in 6.30.

Re: Problem printing some unicode characters to canvas gadget

Posted: Sat May 10, 2025 12:16 am
by TassyJim
Thanks for trying Fred.
I can work around it for now.

Edit
The fix I implemented is

Code: Select all

 Procedure DrawTextEx(hDc,x, y, Text.s, FrontColor, BackColor)
 Protected chRect.RECT
  chRect\left = x
  chRect\top = y
  chRect\right = x +  VT\CharPixelW
  chrect\bottom = y +  VT\CharPixelH

  SetTextColor_(hdc, frontColor)
  SetBkColor_(hdc, backColor)

  DrawText_(hDC, Text, Len(Text), @chRect.Rect, #DT_SINGLELINE )
 
EndProcedure
Thanks to mk-soft in the drawText() is very slow thread.