[SOLVED] ScintillaGadget - Changing font

Just starting out? Need help? Post your questions and find answers here.
Perkin
Enthusiast
Enthusiast
Posts: 504
Joined: Thu Jul 03, 2008 10:13 pm
Location: Kent, UK

[SOLVED] ScintillaGadget - Changing font

Post by Perkin »

SOLVED
Has the ScintillaGadget changed the way the font should be changed?
Edit: PB5.20LTS
This no longer works - even crossplatform ( WinXP, Linux Mint 15, Mac OS X 10.9 )
The size is changed, but the fontface isn't
Cany anyone tell me why and how to fix it?

save as ScintillaFontTest.pb

Code: Select all

Procedure SCINT_LoadFile(ID, FileName.s)
	Protected FF, length, *mem
	
	FF = ReadFile(#PB_Any, FileName)
	If FF
		length = Lof(FF)
		If length
			*mem = AllocateMemory(length+4)
			If *mem
				ReadStringFormat(FF)
				ReadData(FF, *mem, length);-Loc(FF))
				ScintillaSendMessage(ID, #SCI_SETTEXT, length, *mem)
				FreeMemory(*mem)
				CloseFile(FF)
				ProcedureReturn #True
			EndIf
		EndIf
		CloseFile(FF)
	EndIf
EndProcedure

flgs=#PB_Window_ScreenCentered|#PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_MaximizeGadget|#PB_Window_MinimizeGadget
OpenWindow(0,0,0,620,820,"ScintillaFontTest",flgs)
ScintillaGadget(0,0,0,600,800,0)
ScintillaSendMessage(0, #SCI_SETCODEPAGE, #SC_CP_UTF8)
ScintillaSendMessage(0,#SCI_STYLESETFONT,#STYLE_DEFAULT,@"Monospace")
ScintillaSendMessage(0,#SCI_STYLESETSIZE,#STYLE_DEFAULT,16)

textile_file.s="ScintillaFontTest.pb"
SCINT_LoadFile(0,textile_file)

Repeat
  Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
Last edited by Perkin on Tue Nov 05, 2013 7:41 pm, edited 1 time in total.
%101010 = $2A = 42
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: ScintillaGadget - Changing font

Post by Fred »

Are you sure you have not enabled the 'unicode' mode ? Scintilla expect ascii/utf8 strings
Perkin
Enthusiast
Enthusiast
Posts: 504
Joined: Thu Jul 03, 2008 10:13 pm
Location: Kent, UK

Re: ScintillaGadget - Changing font

Post by Perkin »

D'Oh! :oops:

Yep, works with Unicode off.
I'm pretty sure I used to compile with unicode on though.
Looked through my old code to check, and I was compiling with Unicode on.

Shouldn't the 'ScintillaSendMessage(0, #SCI_SETCODEPAGE, #SC_CP_UTF8)' have counertacted/nullified that?
%101010 = $2A = 42
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: ScintillaGadget - Changing font

Post by Fred »

No, as the following string is sent in unicode (UTF16) format, which is not understood by scintilla

Code: Select all

@"Monospace"
Perkin
Enthusiast
Enthusiast
Posts: 504
Joined: Thu Jul 03, 2008 10:13 pm
Location: Kent, UK

Re: ScintillaGadget - Changing font

Post by Perkin »

Yep, got it. (It's been a while since I needed to go through the code)

As a quick fix - I've added.

Code: Select all

Global *ASCII_string
Procedure SetASCII_string(unicode.s)
  If *ASCII_string
    FreeMemory(*ASCII_string)
  EndIf
  *ASCII_string = AllocateMemory(Len(unicode) + 1)
  If *ASCII_string
    PokeS(*ASCII_string, unicode, -1, #PB_Ascii)
  EndIf
EndProcedure
And altered

Code: Select all

SetASCII_string("Monospace")
ScintillaSendMessage(0,#SCI_STYLESETFONT,#STYLE_DEFAULT,*ASCII_string)
%101010 = $2A = 42
Perkin
Enthusiast
Enthusiast
Posts: 504
Joined: Thu Jul 03, 2008 10:13 pm
Location: Kent, UK

Re: ScintillaGadget - Changing font

Post by Perkin »

Thanks Fred.
%101010 = $2A = 42
phaselock.studio
User
User
Posts: 12
Joined: Wed Apr 13, 2022 10:08 pm
Location: Low Orbit

Re: ScintillaGadget - Changing font

Post by phaselock.studio »

Perkin wrote: Tue Nov 05, 2013 3:43 pm Yep, got it. (It's been a while since I needed to go through the code)

As a quick fix - I've added.

Code: Select all

Global *ASCII_string
Procedure SetASCII_string(unicode.s)
  If *ASCII_string
    FreeMemory(*ASCII_string)
  EndIf
  *ASCII_string = AllocateMemory(Len(unicode) + 1)
  If *ASCII_string
    PokeS(*ASCII_string, unicode, -1, #PB_Ascii)
  EndIf
EndProcedure
And altered

Code: Select all

SetASCII_string("Monospace")
ScintillaSendMessage(0,#SCI_STYLESETFONT,#STYLE_DEFAULT,*ASCII_string)
Just ran into this same problem and looks like it can now be addressed by using the Ascii() function. I'm on a mac and just used Ascii("Monospace") and that fixed the problem for me.
User avatar
mk-soft
Always Here
Always Here
Posts: 6207
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: [SOLVED] ScintillaGadget - Changing font

Post by mk-soft »

There are ready function for Ascii and UTF8

Code: Select all

If OpenWindow(0, 0, 0, 600, 400, "ScintillaGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  
  If InitScintilla()
    dx = WindowWidth(0)
    dy = WindowHeight(0)
    ScintillaGadget(0, 0, 0, dx, dy, 0)
    
    ;*font = Ascii("Monospace")
    *font = UTF8("Monospace")
    ScintillaSendMessage(0, #SCI_STYLESETFONT, #STYLE_DEFAULT, *font)
    FreeMemory(*font)
    ScintillaSendMessage(0, #SCI_STYLESETSIZE, #STYLE_DEFAULT, 16)
    
    ; Anfänglichen Text des ScintillaGadgets festlegen
    *Text = UTF8("This is a simple ScintillaGadget with text...")
    ScintillaSendMessage(0, #SCI_SETTEXT, 0, *Text)
    FreeMemory(*Text)  ; Der von UTF8() erstellte Puffer muss freigegeben werden, um ein Speicherleck zu vermeiden
    
    ; Hinzufügen einer zweiten Zeile mit einem vorherigen Zeilenumbruch
    Text$ = Chr(10) + "Second line"
    *Text = UTF8(Text$)
    ScintillaSendMessage(0, #SCI_APPENDTEXT, Len(Text$), *Text)
    FreeMemory(*Text)
  EndIf
  
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Post Reply