Page 1 of 1

Small issue displaying a symbol

Posted: Fri Feb 03, 2017 12:17 am
by marcoagpinto
I am using Arial font.

I am trying to use the symbol: Trophy
which an ASCII says it chr(55356)

The debugger says that chr(55356) corresponds to the symbol but, when I try to display the chr or the symbol directly, it results in a corrupted symbol.

It there a way of fixing it?

Thanks!

Re: Small issue displaying a symbol

Posted: Fri Feb 03, 2017 1:37 am
by RASHAD
It is available in Segoe UI Symbol

1- Open WordPad
2- Press Alt and keep it down
3- Type using keypad 0127942
4- Release Alt key
5- Copy the symbol and paste it in your PB code

Re: Small issue displaying a symbol

Posted: Fri Feb 03, 2017 1:47 am
by marcoagpinto
RASHAD wrote:It is available in Segoe UI Symbol

1- Open WordPad
2- Press Alt and keep it down
3- Type using keypad 0127942
4- Release Alt key
5- Copy the symbol and paste it in your PB code
It didn't work.

I am using the Arial font and I pasted the symbol into the editor and it appears correct there, but when I run the program I get a corrupted chr.

What is strange is that I tried pasting it in MS Office and LibreOffice with the Arial font and there it appears okay.

Re: Small issue displaying a symbol

Posted: Fri Feb 03, 2017 2:01 am
by RASHAD
Compile in Unicode mode
Try to fix your code
Using HTML

Code: Select all

CompilerIf #PB_Compiler_Unicode = 0
  MessageRequester("Error","Compile with Unicode enabled!") : End
CompilerEndIf
  
  #XmlEncoding = #PB_UTF8
  #Dialog = 0
  #Xml = 0
  
  LoadFont(1, "Segoe UI Symbol", 24)
 
  XML$ = "<window id='#PB_Any' name='test' text='Gridbox' minwidth='auto' minheight='auto' flags='#PB_Window_ScreenCentered | #PB_Window_SystemMenu | #PB_Window_SizeGadget'>" +
          "          <text name='text1' text='I won the &#127942;' width='200' height='100'/>" +
          "  </window>"

  If CatchXML(#Xml, @XML$, StringByteLength(XML$), 0, #XmlEncoding) And XMLStatus(#Xml) = #PB_XML_Success
   
    If CreateDialog(#Dialog) And OpenXMLDialog(#Dialog, #Xml, "test")
     SetGadgetFont(DialogGadget(#Dialog, "text1"), FontID(1))

      Repeat
        Event = WaitWindowEvent()
      Until Event = #PB_Event_CloseWindow
     
    Else
      Debug "Dialog error: " + DialogError(#Dialog)
    EndIf
  Else
    Debug "XML error: " + XMLError(#Xml) + " (Line: " + XMLErrorLine(#Xml) + ")"
  EndIf


Re: Small issue displaying a symbol

Posted: Fri Feb 03, 2017 2:52 am
by Demivec
Here's a code with a helpful procedure from link: http://www.purebasic.fr/english/viewtopic.php?f=12&t=64947

Code: Select all

;just a safety check for 'old' compilers ;)
CompilerIf #PB_Compiler_Unicode = 0
  CompilerError "Requires compiling as unicode."
CompilerEndIf

Procedure.s _Chr(v.i) ;return a proper surrogate pair for unicode values outside the BMP (Basic Multilingual Plane)
  Protected high, low
  If v < $10000
    ProcedureReturn Chr(v)
  Else
    ;calculate surrogate pair of unicode codepoints to represent value in UTF-16
    v - $10000
    high = v / $400 + $D800 ;high/lead surrogate value
    low = v % $400 + $DC00 ;low/tail surrogate value
    ProcedureReturn Chr(high) + Chr(low)
  EndIf
EndProcedure

OpenWindow(0, 0, 0, 160, 160, "Unicode Fun", #PB_Window_SystemMenu)

;Unicode codepoints greater than $FFFF require a pair of codepoints known
;as surrogates to encode them in UTF-16 (for a total of 4 bytes instead of 2)
trophyChar = $1F3C6 ;set the proper codepoint
StringGadget(0, 0, 0, 160, 160, _Chr(trophyChar))
If LoadFont(0, "Arial", 120)
  SetGadgetFont(0, FontID(0))
EndIf

Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
@Edit: removed extraneous code example

Re: Small issue displaying a symbol

Posted: Fri Feb 03, 2017 2:57 am
by Keya
what gadget are you trying to display it in? when looking at it as html it looks like a colored image, not the typical monocolor character so im wondering if it's even possible using the regular text gadget? Rashad's Segue font instructions didnt work on my XP, neither Demivec's (which shows a square, the same as in notepad and wordpad), although Firefox shows it ok

Re: Small issue displaying a symbol

Posted: Fri Feb 03, 2017 3:03 am
by marcoagpinto
Guys,

I decided to place the chr in an image (creating a 16x16 PNG).

Now it is solved and it works as planned.

Thanks for your time!