Page 1 of 1

Scintilla Text Alignment

Posted: Tue Apr 14, 2020 12:24 pm
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

Re: Scintilla Text Alignment

Posted: Tue Apr 14, 2020 1:33 pm
by Tenaja
Check two things, tab size, and font size & font selection. Both of those can have an impact.

Re: Scintilla Text Alignment

Posted: Tue Apr 14, 2020 1:51 pm
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

Re: Scintilla Text Alignment

Posted: Tue Apr 14, 2020 4:28 pm
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

Re: Scintilla Text Alignment

Posted: Wed Dec 29, 2021 10:20 pm
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!