EditorGadget change font problem

Just starting out? Need help? Post your questions and find answers here.
marc_256
Addict
Addict
Posts: 835
Joined: Thu May 06, 2010 10:16 am
Location: Belgium
Contact:

EditorGadget change font problem

Post by marc_256 »

Hello everyone,

For my robot communication program,
I like to change my font set to Courier New - 8pt.

So, I see that the command [SetGadgetFont (#PB_Default, FontID (#Font_0))] exist.
and I use it as follow ...

Image

Snipper 1:

Code: Select all

;======================================================================================================================
;- FONT TEST
;-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
EnableExplicit

;============================================================================================================================
;- ENUMERATION
;-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Enumeration
	#Window_0
	#Frame_0

	#Font_0

	#Receiver_Title
	#Receiver_EditorGadget

	#Transmitter_Title
	#Transmitter_EditorGadget
	#Transmitter_TextBoxGadget
	#Transmitter_StringGadget

EndEnumeration

;-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
;- GLOBALS
;-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Global Event.i
Global GadgetID.i
Global GadgetEventType.i

Global Transmitter_Data.s
Global Transmitter_Key.s

;-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
;- LOAD FONTS
;-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
	LoadFont (#Font_0, "Courier New", 8)
	SetGadgetFont (#PB_Default, FontID (#Font_0))

;-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
;- CREATE WINDOW
;---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
	If OpenWindow (#Window_0, 10, 10, 800, 300, "BOBO one/two - Serial Communication Terminal - RS232/RS485 -", #PB_Window_TitleBar | #PB_Window_SystemMenu | #PB_Window_ScreenCentered)			; | #PB_Window_ScreenCentered 
		SetWindowColor (#Window_0, $004000)
		FrameGadget (#Frame_0, 2, 2, 796, 596, "", #PB_Frame_Single)

;- TRANSMITTER TITLE
		TextGadget (#Transmitter_TextBoxGadget, 4, 4, 792, 15, "- TRANSMITTER DATA -", #PB_Text_Center)
		SetGadgetColor (#Transmitter_TextBoxGadget, #PB_Gadget_FrontColor, $F0F0F0)
		SetGadgetColor (#Transmitter_TextBoxGadget, #PB_Gadget_BackColor, $004000)
;		SetGadgetFont (#Transmitter_TextBoxGadget, FontID (#Font_0))
;- TRANSMITTER EDITOR
		EditorGadget (#Transmitter_EditorGadget, 4, 24, 792, 140, #PB_Editor_ReadOnly | #ES_AUTOVSCROLL)
		SetGadgetColor (#Transmitter_EditorGadget, #PB_Gadget_FrontColor, $F0F0F0)
		SetGadgetColor (#Transmitter_EditorGadget, #PB_Gadget_BackColor, $004000)
;		SetGadgetFont (#Transmitter_EditorGadget, FontID (#Font_0))

		AddGadgetItem (#Transmitter_EditorGadget, -1, "╔═════════════════════════════════════════════════════════════════════════════╗")
		AddGadgetItem (#Transmitter_EditorGadget, -1, "║ BOBO one/two - 68000 MONITOR/DEBUGGER - Ver. 1.00                           ║")
		AddGadgetItem (#Transmitter_EditorGadget, -1, "╚═════════════════════════════════════════════════════════════════════════════╝")

		AddGadgetItem (#Transmitter_EditorGadget, -1, "+-----------------------------------------------------------------------------+")
		AddGadgetItem (#Transmitter_EditorGadget, -1, "| BOBO one/two - 68000 MONITOR/DEBUGGER - Ver. 1.00                           |")
		AddGadgetItem (#Transmitter_EditorGadget, -1, "+-----------------------------------------------------------------------------+")
;- TRANSMITTER STRING
		StringGadget (#Transmitter_StringGadget, 4, 175, 792, 40, "", #ES_MULTILINE)					;|#ES_AUTOVSCROLL)
		SetGadgetColor (#Transmitter_StringGadget, #PB_Gadget_FrontColor, $F0F0F0)
		SetGadgetColor (#Transmitter_StringGadget, #PB_Gadget_BackColor, $004000)
;		SetGadgetFont (#Transmitter_StringGadget, FontID (#Font_0))

		SetActiveGadget (#Transmitter_StringGadget)

;============================================================================================================================
;- DO LOOP
;-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
		Repeat
			Event = WaitWindowEvent(10)
			Select Event
				Case #PB_Event_Gadget
					GadgetID = EventGadget()
					Select GadgetID
						Case #Transmitter_StringGadget
							GadgetEventType = EventType()
							If GadgetEventType = #PB_EventType_Change
								Transmitter_Data = GetGadgetText (#Transmitter_StringGadget)
								Transmitter_Key = Right (Transmitter_Data, 1)
								If Transmitter_Key = Chr (13) Or Transmitter_Key = Chr (10)
;									SetGadgetFont (#Transmitter_EditorGadget, FontID (#Font_0))
									AddGadgetItem (#Transmitter_EditorGadget, -1, Transmitter_Data)
									ClearGadgetItems (#Transmitter_StringGadget)
									SetGadgetText (#Transmitter_StringGadget, "")
									SetActiveGadget (#Transmitter_StringGadget)
								EndIf
							EndIf
					EndSelect
			EndSelect

		Until Event = #PB_Event_CloseWindow

;-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
;- END OF PROGRAM
;-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------		CloseWindow (#Window_0)

	EndIf

;============================================================================================================================
And the result are this:

Image

Please try the snipper,
1) TITLE [TextGadget] text is OK -> CourierNew 8pt
2) Enter Text [StringGadget] text is OK -> CourierNew 8pt
3) Sended text [EditorGadget] text is NOK -> ??

4) Type "VERSION" in StringGadget and push [ENTER]
5) Then the EditorGadget Font is changed
6) Type again "VERSION" in StringGadget and push [ENTER]
7) And again EditorGadget Font is changed (See VERSION text)

Then I changed all the gadgets Fonts separately

Snipper 2:

Code: Select all

;============================================================================================================================
;- FONT TEST
;-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
EnableExplicit

;============================================================================================================================
;- ENUMERATION
;-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Enumeration
	#Window_0
	#Frame_0

	#Font_0

	#Receiver_Title
	#Receiver_EditorGadget

	#Transmitter_Title
	#Transmitter_EditorGadget
	#Transmitter_TextBoxGadget
	#Transmitter_StringGadget

EndEnumeration

;-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
;- GLOBALS
;-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Global Event.i
Global GadgetID.i
Global GadgetEventType.i

Global Transmitter_Data.s
Global Transmitter_Key.s

;-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
;- LOAD FONTS
;-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
	LoadFont (#Font_0, "Courier New", 8)
;	SetGadgetFont (#PB_Default, FontID (#Font_0))

;-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
;- CREATE WINDOW
;-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
	If OpenWindow (#Window_0, 10, 10, 800, 300, "BOBO one/two - Serial Communication Terminal - RS232/RS485 -", #PB_Window_TitleBar | #PB_Window_SystemMenu | #PB_Window_ScreenCentered)			; | #PB_Window_ScreenCentered 
		SetWindowColor (#Window_0, $004000)
		FrameGadget (#Frame_0, 2, 2, 796, 596, "", #PB_Frame_Single)

;- TRANSMITTER TITLE
		TextGadget (#Transmitter_TextBoxGadget, 4, 4, 792, 15, "- TRANSMITTER DATA -", #PB_Text_Center)
		SetGadgetColor (#Transmitter_TextBoxGadget, #PB_Gadget_FrontColor, $F0F0F0)
		SetGadgetColor (#Transmitter_TextBoxGadget, #PB_Gadget_BackColor, $004000)
		SetGadgetFont (#Transmitter_TextBoxGadget, FontID (#Font_0))
;- TRANSMITTER EDITOR
		EditorGadget (#Transmitter_EditorGadget, 4, 24, 792, 140, #PB_Editor_ReadOnly | #ES_AUTOVSCROLL)
		SetGadgetColor (#Transmitter_EditorGadget, #PB_Gadget_FrontColor, $F0F0F0)
		SetGadgetColor (#Transmitter_EditorGadget, #PB_Gadget_BackColor, $004000)
		SetGadgetFont (#Transmitter_EditorGadget, FontID (#Font_0))

		AddGadgetItem (#Transmitter_EditorGadget, -1, "╔═════════════════════════════════════════════════════════════════════════════╗")
		AddGadgetItem (#Transmitter_EditorGadget, -1, "║ BOBO one/two - 68000 MONITOR/DEBUGGER - Ver. 1.00                           ║")
		AddGadgetItem (#Transmitter_EditorGadget, -1, "╚═════════════════════════════════════════════════════════════════════════════╝")

		AddGadgetItem (#Transmitter_EditorGadget, -1, "+-----------------------------------------------------------------------------+")
		AddGadgetItem (#Transmitter_EditorGadget, -1, "| BOBO one/two - 68000 MONITOR/DEBUGGER - Ver. 1.00                           |")
		AddGadgetItem (#Transmitter_EditorGadget, -1, "+-----------------------------------------------------------------------------+")
;- TRANSMITTER STRING
		StringGadget (#Transmitter_StringGadget, 4, 175, 792, 40, "", #ES_MULTILINE)					;|#ES_AUTOVSCROLL)
		SetGadgetColor (#Transmitter_StringGadget, #PB_Gadget_FrontColor, $F0F0F0)
		SetGadgetColor (#Transmitter_StringGadget, #PB_Gadget_BackColor, $004000)
		SetGadgetFont (#Transmitter_StringGadget, FontID (#Font_0))

		SetActiveGadget (#Transmitter_StringGadget)

;============================================================================================================================
;- DO LOOP
;-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
		Repeat
			Event = WaitWindowEvent(10)
			Select Event
				Case #PB_Event_Gadget
					GadgetID = EventGadget()
					Select GadgetID
						Case #Transmitter_StringGadget
							GadgetEventType = EventType()
							If GadgetEventType = #PB_EventType_Change
								Transmitter_Data = GetGadgetText (#Transmitter_StringGadget)
								Transmitter_Key = Right (Transmitter_Data, 1)
								If Transmitter_Key = Chr (13) Or Transmitter_Key = Chr (10)
									SetGadgetFont (#Transmitter_EditorGadget, FontID (#Font_0))
									AddGadgetItem (#Transmitter_EditorGadget, -1, Transmitter_Data)
									ClearGadgetItems (#Transmitter_StringGadget)
									SetGadgetText (#Transmitter_StringGadget, "")
									SetActiveGadget (#Transmitter_StringGadget)
								EndIf
							EndIf
					EndSelect
			EndSelect

		Until Event = #PB_Event_CloseWindow

;-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
;- END OF PROGRAM
;-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------

		CloseWindow (#Window_0)

	EndIf

;============================================================================================================================
Same result ...

Image

AFTER FIRST "VERSION" TYPED

Image

AFTER SECOND "VERSION" TYPED

Image


Can someone help me, with good advice ...

Sorry, forgot to tell

PB 5.73 LTS x64
PC Windows 8.1 x64

thanks,
marc
- every professional was once an amateur - greetings from Pajottenland - Belgium -
PS: sorry for my english I speak flemish ...
Marc56us
Addict
Addict
Posts: 1600
Joined: Sat Feb 08, 2014 3:26 pm

Re: EditorGadget change font problem

Post by Marc56us »

Hi Marc,

It is the "Box Drawing" characters (en français: caractères "Filets") Range: 2500–257F that cause problems and give PB the wrong output (and 'random' errors). They are not well represented from one font to another.
You have to try other fonts, even if this one (Courrier News) has the "Box Drawing" characters or remove its.

When there is a font problem, Windows always tries to display something close. This means that there might be an ID problem somewhere else. (I tried some other solutions, without success. :| )

See page 1 of:
En: https://www.unicode.org/charts/PDF/U2500.pdf
Fr: https://www.unicode.org/charts/fr/PDF/U2500.pdf

:wink:
marc_256
Addict
Addict
Posts: 835
Joined: Thu May 06, 2010 10:16 am
Location: Belgium
Contact:

Re: EditorGadget change font problem

Post by marc_256 »

Hello Marc56us,

thanks for your answer ...
But this is the result with the same computer PC Win8.1 x64 and PB 5.61 x64...

Image

And this is the same program in PB 5.73 LTS x64

Image

So, I think this is a PB bug in PB 5.73 LTS x64

I can be wrong ??

Marc
- every professional was once an amateur - greetings from Pajottenland - Belgium -
PS: sorry for my english I speak flemish ...
BarryG
Addict
Addict
Posts: 4123
Joined: Thu Apr 18, 2019 8:17 am

Re: EditorGadget change font problem

Post by BarryG »

On my PC, SetGadgetFont (#Transmitter_EditorGadget, FontID (#Font_0)) in your Snipper 1 only works if I put it after all the AddGadgetItem (#Transmitter_EditorGadget, -1, ...) lines. That is, the EditorGadget only uses Courier when I put that line after them, and not before them.

So yes, it definitely looks like a bug to me, as SetGadgetFont() should be usable anytime after a gadget is created, without a requirement to put text in the gadget first. Or at least put this in the manual to explain that the gadget must contain text for SetGadgetFont() to take effect.
marc_256
Addict
Addict
Posts: 835
Joined: Thu May 06, 2010 10:16 am
Location: Belgium
Contact:

Re: EditorGadget change font problem

Post by marc_256 »

Hallo BarryG,

yes, that is what I'm thinking also ...

PB 5.61 x64 -> OK
PB 5.71 x64 -> OK
PB 5.72 x64 -> OK
PB 5.73 LTS x64 -> NOT OK

Thanks,
marc
- every professional was once an amateur - greetings from Pajottenland - Belgium -
PS: sorry for my english I speak flemish ...
BarryG
Addict
Addict
Posts: 4123
Joined: Thu Apr 18, 2019 8:17 am

Re: EditorGadget change font problem

Post by BarryG »

I'm using v5.73 32-bit PureBasic, though.
User avatar
ChrisR
Addict
Addict
Posts: 1466
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: EditorGadget change font problem

Post by ChrisR »

I also tested, in fact it is good in the v5.72 and earlier versions but not in v5.73. It looks like a bug to me too.

By digging a bit, randomly, the error seems to be in the Gadget library
In v5.73, by replacing Gadget (in PureLibraries) by the one of v5.72, it looks good, the texts are now aligned.

It would probably be a good idea to move the topic to the bug section. To show the bug more easily, I shortened the code

Code: Select all

Enumeration
	#Window_0
	#Font_0
	#Transmitter_EditorGadget
EndEnumeration

LoadFont (#Font_0, "Courier New", 8)

If OpenWindow (#Window_0, 10, 10, 800, 148, "Test Font Alignment", #PB_Window_TitleBar | #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

		EditorGadget  (#Transmitter_EditorGadget, 4, 4, 792, 140, #PB_Editor_ReadOnly | #ES_AUTOVSCROLL)
		SetGadgetFont (#Transmitter_EditorGadget, FontID(#Font_0))

		AddGadgetItem (#Transmitter_EditorGadget, -1, "╔═════════════════════════════════════════════════════════════════════════════╗")
		AddGadgetItem (#Transmitter_EditorGadget, -1, "║ BOBO one/two - 68000 MONITOR/DEBUGGER - Ver. 1.00                           ║")
		AddGadgetItem (#Transmitter_EditorGadget, -1, "╚═════════════════════════════════════════════════════════════════════════════╝")

		AddGadgetItem (#Transmitter_EditorGadget, -1, "+-----------------------------------------------------------------------------+")
		AddGadgetItem (#Transmitter_EditorGadget, -1, "| BOBO one/two - 68000 MONITOR/DEBUGGER - Ver. 1.00                           |")
		AddGadgetItem (#Transmitter_EditorGadget, -1, "+-----------------------------------------------------------------------------+")
		
		;SetGadgetFont (#Transmitter_EditorGadget, FontID(#Font_0))
		;SendMessage_(GadgetID(#Transmitter_EditorGadget), #WM_SETFONT, FontID(#Font_0), #True)
EndIf

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
marc_256
Addict
Addict
Posts: 835
Joined: Thu May 06, 2010 10:16 am
Location: Belgium
Contact:

Re: EditorGadget change font problem

Post by marc_256 »

Hi ChrisR,

Thanks for testing ...
I already placed a link in the BUG section

Marc
- every professional was once an amateur - greetings from Pajottenland - Belgium -
PS: sorry for my english I speak flemish ...
Post Reply