I have a TextArea (TANotes) that contains styled text (RTF data). I want to print the styled text (maintaining the style, of course) but I want the printed text size to be smaller than what is currently displayed in the text area.
I found this statement in the Xojo docs:
… which sounds like what I want to do … I don’t want to change what’s displayed in the TextArea at all, just what is printed (make the text smaller in size).
Where do I start?
Thanks in advance …
BTW … this is what I’m currently doing to get the styled text to print successfully at the same text size as what’s displayed on screen in the text area … but again, I need to reduce the text size and that’s where I’m lost.
Dim styledText As StyledTextPrinter
Dim textWidth As Integer = 7.0 * prtHRES
styledText = cntNotes(oContainers(iloop)).TANotes.styledTextPrinter(g, textWidth)
Dim blockHeight As Integer = ps.PageHeight
styledText.DrawBlock(leftoffset, ycoord, blockHeight)
Well, after reading and googling for past several hours, I’ve got a feeling I have to use StyleRun to alter the text size of what goes to the Graphics object to be printed and not change the displayed text in the text area itself … which is what I need.
Anyone have any idea where I go from there?
[quote=136144:@Don Lyttle]Well, after reading and googling for past several hours, I’ve got a feeling I have to use StyleRun to alter the text size of what goes to the Graphics object to be printed and not change the displayed text in the text area itself … which is what I need.
Anyone have any idea where I go from there?[/quote]
Before going StyleRun, which is a valid approach but more complex, I would simply play on the text size within the TextArea this way :
for i as integer = 0 to len(StyledTextArea.text)
StyledTextArea.Selstart = i
StyledTextArea.SelLength = 1
StyledTextArea.SelTextSize = StyledTextArea.SelTextSize*1.5
As it stands it is fairly slow, but you can optimize by detecting the size changes and change the size for a block of text rather than each character. With this technique, you can have any text size and then print with the very same method you are already using.
If necessary, use another TextArea out of the window to manipulate text for printing not to disturb the user.
Thank you, Michel … I had thought of this option as I went through the myriad of posts I was reading, but was hoping for something I could do purely in code without “attaching” to the TextArea. It could serve as my fallback for now though. I’m going to pick up dinner and then try your first suggestion.
I just played with the Styled Text example. In this I made text printing TextArea visible, but in my idea it was simply placed out of the window area, so all the user sees is the waiting box.
I noticed that as usual the parsing of RTF is rather slow, but I think we already discussed that in another thread, there are declares to greatly speed it up.
The main issue with StyleRun is that you will have to manage everything that the TextArea does for you. LIne spacing is not terribly easy, as you can use Fontheight but it is not extremely reliable, as the font design can change the rendition.
The biggest issue is line wrap. It is fairly simple as long as font size is consistent as well as font design, but it can become quite tricky when several font sizes and different fonts populate a line.
You also have to manage pages.
The more I look at using StyleRuns, the less I liked the proposition. For one thing, I can’t predict how many styleruns would be present in each RTF block of data (it’s user entry) … I’d be indexing through them and that looks messy.
I did find this post from Dave S where he wrote the following code using StyleRun to solve what I believe to be the same issue I’m facing. I’m still having problems though getting my head around the concept of what it would take to use DrawBlock for StyledText that’s not “attached” to a TextArea. I keep seeing inferences to doing that but can’t find a single example of “how”.
THATS WHAT MY ISSUE HAD BEEN!!! :)
I had to clone the styled text into another instance First
SUB CLONE_STYLEDTEXT(master as StyledText,ByRef Clone as StyledText)
Dim i As Integer
Dim sr As StyleRun
For i=0 To master.StyleRunCount-1
dim st as styled text.
Dave is doing much more elegantly with StyledText what I was doing with SelStart and SelLength. See http://documentation.xojo.com/index.php/StyledText for an example.