Scintilla Text Alignment

Just starting out? Need help? Post your questions and find answers here.
mocitymm
User
User
Posts: 37
Joined: Wed Feb 08, 2017 6:56 pm

Scintilla Text Alignment

Post by mocitymm »

I can't seem to find the appropriate 'ScintillaSendMessage' to handle text alignment from a 'ReadFile()' to a Scintilla gadget. The text file is displayed in full but, the text alignment is off.

I can display/use '#SCI_SETVIEWWS' and see the dots (space), they match from Notepad/Notepad++ and Vim. I don't believe that it is an issue of font, I've matched that using '#SCI_STYLESETFONT' with what Notepad/Notepad++ and Vim are using to display the text file.

Example text:

INFO 2020-02-05 08:03:30.061 5066 140147193812736 PolicyManager > Set policy refresh task to start at 2020-02-05 08:05:30 with interval of 5 minutes, deviation 0 minutes.
WARN 2020-02-05 08:03:30.067 5066 140147193812736 ClientSchedulerPlugin > RefreshTask: Failed to delete the old task 'CS01': 2147484148, Unknown error

I would like to align the 'INFO' and 'WARN' (column if you will, which is 6 spaces to 5066, 2 spaces to 140147193812736), etc...

Using Consolas Regular on Windows and Monospace on Linux, same issue on both, PB 5.72 x64.

Hopefully, I've explained it well enough to be deciphered as to what I want to accomplish.

Regards,

-M
User avatar
Tenaja
Addict
Addict
Posts: 1959
Joined: Tue Nov 09, 2010 10:15 pm

Re: Scintilla Text Alignment

Post by Tenaja »

Check two things, tab size, and font size & font selection. Both of those can have an impact.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: Scintilla Text Alignment

Post by RASHAD »

Is that what you want ?
I think you have a problem with initializing the font and size
We can use ScintillaSendMessage() to find and replace
But no need

Code: Select all

Global Result2$
 
Procedure InsertSpaces(text$,inert1$,insert2$) 
  Position = FindString(Text$, inert1$)
  Result$ = InsertString(text$, Space(6), Position)
  Position = FindString(Result$, "140147193812736")
  Result2$ = InsertString(Result$, Space(2), Position)
EndProcedure
 
If OpenWindow(0, 0, 0, 800, 600, "ScintillaGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
 
  If InitScintilla()
    ScintillaGadget(0, 10, 10, 780, 580, 0)
         
    ; Output set to red color
    ScintillaSendMessage(0, #SCI_STYLESETFORE, 0, $0000FF)
    *font = UTF8("Consolas")
    ScintillaSendMessage(0, #SCI_STYLESETFONT, 32, *font)
    FreeMemory(*font)
    ScintillaSendMessage(0, #SCI_STYLESETSIZE, 32, 14)
    InsertSpaces("INFO 2020-02-05 08:03:30.061 5066 140147193812736 PolicyManager > Set policy refresh","5066","140147193812736")
    *Text=UTF8(Result2$)
    ScintillaSendMessage(0, #SCI_SETTEXT, 0, *Text)
    FreeMemory(*Text) ; The buffer made by UTF8() has to be freed, to avoid memory leak     

  EndIf
 
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Edit :Bug fixed
Egypt my love
User avatar
kenmo
Addict
Addict
Posts: 2033
Joined: Tue Dec 23, 2003 3:54 am

Re: Scintilla Text Alignment

Post by kenmo »

Tenaja wrote:Check two things, tab size, and font size & font selection. Both of those can have an impact.
That was my first thought too, the tab size.
If the font and the text really match Notepad++ exactly, then all I can think is tabs being displayed at different widths.

SCI_SETTABWIDTH(int tabWidth)
https://www.scintilla.org/ScintillaDoc. ... ETTABWIDTH
User avatar
Borstensohn
User
User
Posts: 13
Joined: Sun Jun 05, 2005 9:45 pm

Re: Scintilla Text Alignment

Post by Borstensohn »

I tried the whole day to initialize a font, without any success, and lucky me found the answer in this thread:

Code: Select all

*font = UTF8("Consolas")
ScintillaSendMessage(0, #SCI_STYLESETFONT, 32, *font)
FreeMemory(*font)
That did the trick. I had not known about the UTF8 thing.
So, thank you so much for posting the code!
ON ERROR GOTO BED
Post Reply