Future of StyledTextPrinter?

I just tried the one from your May 22 posting and don’t see any difference from the original one. Are you sure you didn’t accidentally repost the old one?

I’ve just downloaded it using the Dropbox link and it is definitely the right version (the ReadMe notes states version 1.1).

It also contains the lines of code that sets the 3rd paragraph to green as I used that to diagnose the original problem.

Yes, I see that it is version 1.1. However, there is still an issue with the runs. The code in the Open event should set just the third paragraph to green but there are also parts of paragraph 1 getting set to green.

I really do appreciate your doing this class.

The parts you have circled aren’t green on my Mac using the updated version. I guess it could be a MS-Windows only issue or maybe something different in newer versions of Xojo. I’d have to run some more tests.

Actually, it happens on the Mac too.

Add

Sub TextChange() Handles TextChange  
  Self.Invalidate
End Sub

to TextArea1 so that it updates any changes to the text, then in the first paragraph keep entering SPACES before the “line.” until “line.” approaches the right end - and you’ll see “line.” turning green.

This does not happen if you add other characters.

1 Like

New version which processes style runs better than previous versions. The test project has been improved and now allows you to manipulate some style information on the test text area.

2 Likes

I haven’t given it a decent test yet but it looks good so far. Thanks.

BTW, nice job on the test app.

You should use Invalidate instead of Refresh. Refresh forces the control to update immediately (which can lead to flicker), invalidate updates it the next time a paint cycle comes around (which is every 1/60th of a second on a 60 Hz monitor).

Refresh is useful in tight loops but otherwise stay away from it.

Yeh, I know the difference between invalidate & Refresh. Unfortunately, invalidate was making the updates laggy.

I had tried it before posting and there was no lag, but that could be because I’m on a Mac and Macs double buffer. The experience on Windows could be different.

macOS showed no lag for me as well.

Using the test app you supplied, and changing the .Refresh instances to .Invalidate, I didn’t see any significant lag on Windows either.

I was using a quite old version of Xojo (before Direct2D) so it could be something that only affects older versions.

Hello, other 2 years StyledTextPrinter still doesn’t work. I tried the last example with the link to the drop box but running it on the latest Xojo version 2023 v1.1 it’s hanging. I have an old code that was running fine on Windows and now it’s broken for bug that’s here fore more than 5 years and no answers from the developers… Everything I can get is at very low resolution.

what is hanging ? the dropbox example compiles and runs fine here…
macos 13.3 and xojo 2023r11

I think the Windows side is broken.

See StyledTextPrinter issues

1 Like

I know this is an old post but my reply may just help someone. I was also having issues with the StyledTextPrinter (for windows). The following solution works for me. It’s close enough to WYSIWYG for me and allows me to independently set the text size. Disclaimer: note I am a beginner programmer just bumbling my way through. So take this solution for what it’s worth.

Here is my code:
(Basically I loop through each StyleRun in the TextArea1 (this allows me to determine formatting settings) and then I split the text of each StyleRun into an array of strings. Then I draw each string using the formatting from the StyleRun).

Var xTempString As String
Var xLine As String
Var xLines() As String
Var xTopMargin As Integer = 60 

Var xPS As New PrinterSetup
Var xG As Graphics
xG = xPS.ShowPrinterDialog

If xG <> Nil Then
  
  For i As Integer = 0 To TextArea1.StyledText.StyleRunCount - 1 // Loop through each style run
    Var xRun As StyleRun = TextArea1.StyledText.StyleRun(i)
    xTempString = xRun.Text
    xLines = xTempString.Split(Chr(13)) // Create an array of sentences (strings)
    Var xCount As Integer = 0
    For Each xLine In xLines
      
      xG.DrawingColor = xRun.TextColor
      xG.FontName = xRun.FontName
      xG.FontSize = xRun.FontSize - 6 // by subtracting 6 I can reduce the printed font size
      xG.Bold = xRun.Bold
      xG.Underline = xRun.Underline
      xG.DrawText(xLine.ToText, 50, xTopMargin)
      
      xTopMargin = xTopMargin + xRun.FontSize - 6
      If xTopMargin > 750 Then // change this number for the bottom margin
        xG.NextPage
        xTopMargin = 60 // change this number for the top margin size
      End If
    Next xLine
  Next
End If

3 Likes