Page 1 of 1

[SOLVED] ScintillaGadget - Changing font

Posted: Mon Nov 04, 2013 10:18 pm
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

Re: ScintillaGadget - Changing font

Posted: Tue Nov 05, 2013 12:27 am
by Fred
Are you sure you have not enabled the 'unicode' mode ? Scintilla expect ascii/utf8 strings

Re: ScintillaGadget - Changing font

Posted: Tue Nov 05, 2013 3:24 pm
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?

Re: ScintillaGadget - Changing font

Posted: Tue Nov 05, 2013 3:35 pm
by Fred
No, as the following string is sent in unicode (UTF16) format, which is not understood by scintilla

Code: Select all

@"Monospace"

Re: ScintillaGadget - Changing font

Posted: Tue Nov 05, 2013 3:43 pm
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)

Re: ScintillaGadget - Changing font

Posted: Tue Nov 05, 2013 3:44 pm
by Perkin
Thanks Fred.

Re: ScintillaGadget - Changing font

Posted: Thu Apr 14, 2022 4:04 am
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.

Re: [SOLVED] ScintillaGadget - Changing font

Posted: Thu Apr 14, 2022 11:59 am
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