TextHighlighter: Fix Paint() method, and add an optional argument that defines the position of the first character of the highlighted text to paint.

[GB.EVAL.HIGHLIGHT]
* BUG: TextHighlighter: Paint() correctly takes into account the new highlighter theme design.
* NEW: TextHighlighter: Paint() method takes an optional argument that defines the position of the first character of the highlighted text to paint.
This commit is contained in:
gambas 2021-12-15 15:54:39 +01:00
parent 1feb4d4ff1
commit 3d3f7cd4d4
2 changed files with 23 additions and 9 deletions

View file

@ -46,10 +46,12 @@ End
Public Sub Main()
' Dim hHighlighter As TextHighlighter
'
' hHighlighter = TextHighlighter["webpage"]
'
' Print hHighlighter.ToHTML(File.Load("~/gambas/git/master/app/src/gambas-wiki/.src/Wiki.webpage"))
Dim hHighlighter As TextHighlighter
Dim hTheme As TextHighlighterTheme
hHighlighter = TextHighlighter["gambas"]
hTheme = New TextHighlighterTheme
'hTheme.Invert()
Print hHighlighter.ToANSI(File.Load("UnitTest/TestProgram"), hTheme)
End

View file

@ -823,7 +823,7 @@ Static Private Sub GetStyles(hTheme As Variant) As TextHighlighterStyle[]
End
Public Sub Paint(Text As String, X As Float, Y As Float, Optional Theme As Variant)
Public Sub Paint(Text As String, X As Float, Y As Float, Optional Theme As Variant, Optional Pos As Integer)
Dim sLine As String
Dim aHighlight As Byte[]
@ -846,6 +846,8 @@ Public Sub Paint(Text As String, X As Float, Y As Float, Optional Theme As Varia
aStyles = GetStyles(Theme)
Pos = Max(Pos, 1)
fCharWidth = Paint._EstimateFixedFontCharWidth(Paint.Font)
LH = Paint.Font.Height + 1
BW = 1 + LH \ 6
@ -878,16 +880,26 @@ Public Sub Paint(Text As String, X As Float, Y As Float, Optional Theme As Varia
For I = 0 To aHighlight.Max Step 2
iState = aHighlight[I] And 31
iState = aHighlight[I] And 63
Try hStyle = aStyles[iState]
If Error Then hStyle = aStyles[0]
bAlt = aHighlight[I] >= 128
iLen = aHighlight[I + 1]
If (P + iLen) < Pos Then
P += iLen
Continue
Else
If Pos > P Then
iLen -= Pos - P
P = Pos
Endif
Endif
If fCharWidth Then
X = X0 + fCharWidth * (P - 1)
X = X0 + fCharWidth * (P - Pos)
Else
X = X0 + Paint.Font.TextWidth(String.Left(sLine, P - 1))
X = X0 + Paint.Font.TextWidth(String.Mid(sLine, Pos, P - Pos))
Endif
sText = String.Mid$(sLine, P, iLen)