Small issue displaying a symbol

Just starting out? Need help? Post your questions and find answers here.
User avatar
marcoagpinto
Addict
Addict
Posts: 1076
Joined: Sun Mar 10, 2013 3:01 pm
Location: Portugal
Contact:

Small issue displaying a symbol

Post 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!
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 5011
Joined: Sun Apr 12, 2009 6:27 am

Re: Small issue displaying a symbol

Post 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
Egypt my love
User avatar
marcoagpinto
Addict
Addict
Posts: 1076
Joined: Sun Mar 10, 2013 3:01 pm
Location: Portugal
Contact:

Re: Small issue displaying a symbol

Post 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.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 5011
Joined: Sun Apr 12, 2009 6:27 am

Re: Small issue displaying a symbol

Post 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

Egypt my love
User avatar
Demivec
Addict
Addict
Posts: 4282
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Small issue displaying a symbol

Post 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
Last edited by Demivec on Sat Feb 04, 2017 6:21 am, edited 4 times in total.
User avatar
Keya
Addict
Addict
Posts: 1890
Joined: Thu Jun 04, 2015 7:10 am

Re: Small issue displaying a symbol

Post 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
User avatar
marcoagpinto
Addict
Addict
Posts: 1076
Joined: Sun Mar 10, 2013 3:01 pm
Location: Portugal
Contact:

Re: Small issue displaying a symbol

Post 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!
Post Reply