Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 11:17 01 Aug 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : SciLexer/Scintilla

Author Message
Malibu
Senior Member

Joined: 07/07/2018
Location: Australia
Posts: 260
Posted: 05:18am 10 Sep 2018
Copy link to clipboard 
Print this post

Ok, so it's not really a MM question, but I'm sure there's plenty out there with more experience (ie: Smarter than me!) that might have an idea where I'm going wrong...

I'm fiddling around with a code edit package (just as a future idea) in VB6 using API calls with SciLexer/Scintilla. I can't for the life of me get the font to change in the edit window.
Here's the code (remember, it's VB6)

Private Sub Form_Load()
Dim Font As String
Dim Lex As Variant
Lex = App.Path & "\SciLexer.DLL"
LoadLibrary (Lex)
sci = CreateWindowEx(WS_EX_CLIENTEDGE, "Scintilla", _
"TEST", WS_CHILD Or WS_VISIBLE, 0, 0, 200, 200, _
Form1.hWnd, 0, App.hInstance, 0)
Font = "Monotype Corsiva" + Chr$(0)
SendMessage sci, SCI_SETMARGINTYPEN, 1, 1
SendMessage sci, SCI_MARGINSETSTYLE, 1, 1
SendMessage sci, SCI_SETMARGINTYPEN, 1, 1
SendMessage sci, SCI_SETMARGINWIDTHN, 1, 55
For i = 0 To 50
SendMessage sci, SCI_STYLESETFONT, i, StrPtr(Font)
SendMessage sci, SCI_STYLESETSIZE, i, 18
SendMessage sci, SCI_STYLESETFORE, i, vbBlack
SendMessage sci, SCI_STYLESETBOLD, i, False
SendMessage sci, SCI_STYLESETITALIC, i, False
'-----------------------------
SendMessage sci, SCI_STYLESETFONT, i, StrPtr(Font)
'-----------------------------
Next i
SendMessageString sci, SCI_ADDTEXT, 13, "Hello World" & vbCrLf
End Sub

The problem part is between the "-------------" comments and no matter what font I select, it always seems to use the default font (which I believe is Verdana)
Everything else is great (bold, italic, size, etc), just the font style...

I'm a bit stumped ATM... Has anyone had any experience with this that might pick my stumbling block?Edited by Malibu 2018-09-11
John
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2944
Posted: 05:48am 10 Sep 2018
Copy link to clipboard 
Print this post

Just checking - CHR$(0) is the Null Character. Is that what is required at the end of string when setting Font = "...."?

Sorry I can't help otherwise as no experience with Scintilla (and VB6 was last used about 10years ago so have forgotten all the 'detail')
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 05:58am 10 Sep 2018
Copy link to clipboard 
Print this post

It looks OK to me (but I don't speak VB)

In Purebasic the procedure I use is
  Quote  If fontName$
;Convert the fontName$ to Ascii.
asciiBuffer = AllocateMemory(Len(fontName$) + 1)
If asciiBuffer
PokeS(asciiBuffer, fontName$, -1, #PB_Ascii)
ScintillaSendMessage(id, #SCI_STYLESETFONT, styleIndex, asciiBuffer)
FreeMemory(asciiBuffer)
EndIf
EndIf


I normally use the default font so not a lot of experience changing fonts.

VK7JH
MMedit
 
Malibu
Senior Member

Joined: 07/07/2018
Location: Australia
Posts: 260
Posted: 06:01am 10 Sep 2018
Copy link to clipboard 
Print this post

  Quote  and VB6 was last used about 10years ago so have forgotten all the 'detail'

Yup, you and me both WW!
It's amazing how much 'we' can forget when something's not used for a while! (although, I can still remember words to all my favorite songs from the '70s )

Here's a snip of the documentation -

  Quote  SCI_STYLESETFONT(int style, const char *fontName)
The fontName is a zero terminated string holding the name of a font. Under Windows, only the first 32 characters of the name are used, the name is decoded as UTF-8, and the name is not case sensitive. For internal caching, Scintilla tracks fonts by name and does care about the casing of font names, so please be consistent.


I read that as 'a zero terminated' string equates to a null char. I could be wrong though and I've tried it with and without it.
UTF-8 encoding is still something I'm trying to get my head around as well.
John
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2944
Posted: 06:04am 10 Sep 2018
Copy link to clipboard 
Print this post

Could 'zero terminated' actually mean '0' ?

Maybe try CHR$(48)
 
Malibu
Senior Member

Joined: 07/07/2018
Location: Australia
Posts: 260
Posted: 06:17am 10 Sep 2018
Copy link to clipboard 
Print this post

  Quote  ScintillaSendMessage(id, #SCI_STYLESETFONT, styleIndex, asciiBuffer)

Jim, a quick mental conversion says that what you have and what I have are pretty much the same (I don't speak PureBasic, but the lines look pretty close to each other)

  Quote  Could 'zero terminated' actually mean '0' ?
Maybe try CHR$(48)

Tried that about 2 days ago because I had the same thoughts (no avail on that either, but a good thought!)

I even tried this in case adding the Null to the string variable was messing the string up...

'-----------------------------
SendMessage sci, SCI_STYLESETFONT, i, StrPtr(Font + Chr$(0))
'-----------------------------

... but no luck on that one as well.
John
 
ajkw
Senior Member

Joined: 29/06/2011
Location: Australia
Posts: 290
Posted: 06:56am 10 Sep 2018
Copy link to clipboard 
Print this post

Quick thought, does it want the font file name not its common name?
 
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 986
Posted: 07:32am 10 Sep 2018
Copy link to clipboard 
Print this post

Malibu, I had a similar problem with VB only a couple of weeks ago, I was using the MSGraph utility and I could not change fonts during run time but I was able to change them using the properties applet that is attached to MSGraph.

Hope that makes sense.
OA47
 
Malibu
Senior Member

Joined: 07/07/2018
Location: Australia
Posts: 260
Posted: 10:57pm 10 Sep 2018
Copy link to clipboard 
Print this post

Thanks everyone!
Looking with fresh eyes this morning and trying out a few more things, I found the solution...
Here's the two lines that do all the work -


Font = StrConv("Century Gothic", vbFromUnicode)
&
SendMessage sci, SCI_STYLESETFONT, i, StrPtr(Font)


The first line takes the UniCode string (which is what VB uses) and converts it to the default code page - which as this works, I would presume is UTF-8
The second line sends it out to SciLexer correctly formatted.
Interestingly, it makes no difference having a NULL char on the end or not, so I don't know what that was all about!

Anyway, all good in the end, so thanks to everyone's thoughts
John
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 11:51pm 10 Sep 2018
Copy link to clipboard 
Print this post

Good to see it working at last.

That is similar to my "PokeS(asciiBuffer, fontName$, -1, #PB_Ascii)" which converts the font name string to ASCII.

Scintilla can handle UTF-8 but I am old-fashioned enough to stick with ASCII.
I have a lot of trouble getting my head around the various string coding options.

The zero terminator is probably present in your string anyway, just like C strings. the extra zero byte would be ignored.

Jim
VK7JH
MMedit
 
Malibu
Senior Member

Joined: 07/07/2018
Location: Australia
Posts: 260
Posted: 01:58am 11 Sep 2018
Copy link to clipboard 
Print this post

G'day Jim,
It's always a satisfying moment when you hit the 'run' command, and it all works as it should!

As you say, your code and mine (ignoring the syntax differences) are pretty much the same - I actually used PowerBasic examples for my guides. Again, a little different, but close enough to figure out the basics.

The way I read the documentation is that Scintilla decodes the ascii string sent to it into UTF-8, but as it turned out I need to send in UTF-8. I'm the same as you, I prefer a simple ascii string and when it gets down to conversions between ascii, UTF-8, UTF-16, UniCode and all the other formats (not to mention Dec, Hex, Oct and Chars) things get a little mesmerising!
Next on the list is KeyWords!
John
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 02:22am 11 Sep 2018
Copy link to clipboard 
Print this post

Settings the keywords is the same as setting the font.
I have my keywords list as a lowercase, space separated list and use SETKEYWORDS to update Scintilla.

Scintilla is a great tool but there is much to learn to use it to the max.

I rely on work that others have done.

Jim


VK7JH
MMedit
 
Malibu
Senior Member

Joined: 07/07/2018
Location: Australia
Posts: 260
Posted: 06:34am 11 Sep 2018
Copy link to clipboard 
Print this post

  Quote  Settings the keywords is the same as setting the font.
I have my keywords list as a lowercase, space separated list and use SETKEYWORDS to update Scintilla.

aaahhh, you make it sound easy!

  Quote  Scintilla is a great tool but there is much to learn to use it to the max.

For a good example of using it to the max, check out "Programmers Notepad"
John
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025