Date: 02-16-2022
Return to Index
created by gbSnippets
Function WordWrap2() As Long
Local index, LinePixelsWidth, SpaceWidth As Long
Local pOld, pSpace As Byte Ptr, pLetter As Long Ptr
SpaceWidth = LetterWidth(32)
pOld = StrPtr(OldBuffer$) 'pointer to Buffer
pLetter = VarPtr(LetterWidth(0)) 'pointer to LetterWidth() array
For index = 1 To Len(OldBuffer$)
Select Case As Long @pOld[index] 'Byte pointer
Case > 32 'All characters avove SPC
LinePixelsWidth = LinePixelsWidth + @pLetter[@pOld] 'width of line increases by one character
' If LinePixelsWidth > MaxWidth And pSpace Then
If pSpace And LinePixelsWidth > MaxWidth Then
@pSpace = 13 'Change last SPC to a CR
pSpace = 0 'Reset pSpace as a TRUE/FALSE flag for the "IF pSpace"
LinePixelsWidth = 0 'Start a new line, so width is zero
End If
Case 32 : pSpace = pOld+index 'Record the position in case a CR is needed in the next word
LinePixelsWidth += SpaceWidth 'Add width of a SPC
Case 13 : @pOld[index] = 32 'Convert to a SPC to get: "string" & $SPC & $CR & "string"
Case 10 : @pOld[index] = 13 'Convert to a CR to get: "string" & $SPC & $CR & "string"
Case Else : LinePixelsWidth += SpaceWidth 'Should not append, char < 32 and not SPC-CR-LF
End Select
Next
End Function
http://www.garybeene.com/sw/gbsnippets.htm