Stylize paragraph of text

I need to display a block of text, and would like to make it more readable.

Current I have it drawing into a Canvas:

[code] Sub Paint (g as graphics)

g.TextFont=“Helvetica”
g.TextSize=16
g.ForeColor=&cF2FB8D00
g.DrawString Paragraph, 0, 20, me.width 'draws TargText into itself[/code]

Happy to change it to another container, just don’t want it to look ‘editable’ (as in a TextArea).

Any thoughts to get it double spaced? Could I hack up an HTMLviewer and send it my own HTML?

You can change the font and styling of a label with the ide using the inpector panel on the right. Just change tabs at the top (one is a cog and I can’t recall the other icon from my mobile here)

That is easy and is not a hack. See http://documentation.xojo.com/index.php/HTMLViewer.LoadPage

@Tim Parnell - I’m trying to get a paragraph appear double-spaced. From what I can tell, Labels only allow Bold/Italic/Underline.

@Michel Bujardet - Thanks! I played around with it and finally hit on the correct style tag. Working code below.

Thanks everyone!

dim htmlText as string dim f as FolderItem = GetTemporaryFolderItem htmlText = "<html><head>" htmlText = htmlText + "</head><body> <span style=line-height:1.5em>" htmlText = htmlText + TargText(port(currentIndex)) + "</span></body></html>" htmlViewer1.LoadPage(htmlText,f)

The solution I posted above seems to fail intermittently.

I tried a few things, ended up with the code below in the current version.

This code is called many times within a session. If it works on first call it works every time, but 1 of every 8-10 sessions the display is blank (and continues to be after multiple calls).

Curiously, changing the font size to something smaller makes it [almost] reliably fail…

Overall I’m thinking the HTMLviewer feels like a half-baked piece of RealBasic?

Any thoughts for where to troubleshoot? Intermittent problems are the hardest!

dim htmlText as string dim f as FolderItem = GetTemporaryFolderItem htmlText = "<html><head></head><body>" htmlText = htmlText + "<span style=line-height:1.5em;font-family:Helvetica;font-size:12pt>" htmlText = htmlText + TargText(port(currentIndex)) + "</span></body></html>" TargetHTML.Invalidate TargetHTML.LoadPage(htmlText,f) TargetHTML.Visible = true BacktoMainCanvas.Visible = true

Using RealStudio 2011 Release 4.1. Lots of legacy code was reused in other parts of this project, and I’d rather not convert to Xojo (and buy a new license) for this one project…

[quote=226745:@Tamar Kornblum]The solution I posted above seems to fail intermittently.

I tried a few things, ended up with the code below in the current version.

This code is called many times within a session. If it works on first call it works every time, but 1 of every 8-10 sessions the display is blank (and continues to be after multiple calls).

Curiously, changing the font size to something smaller makes it [almost] reliably fail…

Overall I’m thinking the HTMLviewer feels like a half-baked piece of RealBasic?

Any thoughts for where to troubleshoot? Intermittent problems are the hardest!

dim htmlText as string dim f as FolderItem = GetTemporaryFolderItem htmlText = "<html><head></head><body>" htmlText = htmlText + "<span style=line-height:1.5em;font-family:Helvetica;font-size:12pt>" htmlText = htmlText + TargText(port(currentIndex)) + "</span></body></html>" TargetHTML.Invalidate TargetHTML.LoadPage(htmlText,f) TargetHTML.Visible = true BacktoMainCanvas.Visible = true

Using RealStudio 2011 Release 4.1. Lots of legacy code was reused in other parts of this project, and I’d rather not convert to Xojo (and buy a new license) for this one project…[/quote]

I doubt extremely much HTMLViewer is to blame. It is a very basic HTML code. I would rather be inclined to suspect some bug in the way TargText(port(currentIndex)) is initialized. You could verify it with a small static symbol in the HTML, for instance a comma immediately after , which will show even if the rest of the text is not there.

should this be
htmlText = htmlText + “<span style=”“line-height:1.5em;font-family:Helvetica;font-size:12pt”">"
so the styling is a quoted string

[quote=226749:@Norman Palardy]should this be
htmlText = htmlText + “<span style=”“line-height:1.5em;font-family:Helvetica;font-size:12pt”">"
so the styling is a quoted string[/quote]

Good catch. With single quotes it works as well, and is a bit easier on the eyes :

htmlText = htmlText + "<span style='line-height:1.5em;font-family:Helvetica;font-size:12pt'>"

But it should not make the text invisible even if the styling is incorrect.

you wouldn’t think so but then you never know

but that exact code I took & ran with one small change
I made the TargText a literal
htmlText = htmlText + “TargText(port(currentIndex))” + “”

and it shows here on 10.9.5 with or without inserting the missing quotes on the style

Thanks all for the input!

Issue still persists, here’s the latest:

• Updated span style as per Michel’s suggestion. Good catch, Norman!
• Tried Norman’s suggestion to run with literal. Issue did NOT occur after a number of tries. Interesting…
• Added line to catch error, with breakpoint on MsgBox line:

[code] dim htmlText as string
dim f as FolderItem = GetTemporaryFolderItem
htmlText = “”
htmlText = htmlText + “
htmlText = htmlText + TargText(port(currentIndex)) + “

if len(htmlText)<125 then 'actual length of html code is 115 characters
MsgBox "Error loading passage text.
end if

TargetHTML.Invalidate
TargetHTML.LoadPage(htmlText,f)
TargetHTML.Visible = true
BacktoMainCanvas.Visible = true [/code]
Issue occurred, but no Message Box or breakpoint! So it seems it’s loading all the content of htmlText correctly?

I think it’s something with how the htmlViewer rendering or visibility. Curiously, when I played around adding
or “-” to the end of the htmlText, sometimes the text would not wrap to it’s container, or show up a few lines vertically displaced (the first visible line was line 3 of text, and I couldn’t scroll up.

Is there any way to confirm that the rendered html is in the correct position within the htmlViewer? Or to confirm where the text wrap is? I noticed the wrap issue in the past but it occurred even less frequently than the disappearing text issue…

[quote=229379:@Tamar Kornblum]Issue still persists, here’s the latest:

[/quote]

Which issue exactly ?

If I use your code with a sample text file, spacing is conformant to the HTML, and wrapping occurs as expected. However, you still need to insert line breaks where EndOfLine appear in the text.

 htmlText = htmlText + ReplaceAll(TargText(port(currentIndex)), EndOfLine, "<br>") + "</span></body></html>"

Major issue: intermittently, htmlViewer display is completely blank. The container (blank white square) appears and disappears as expected, but NO text shows up.

This is consistent within a session. Each time I run the program, either the text displays correctly every time, or doesn’t display at all.

When I try to debug and add “-” or
, I notice intermittent formatting problems (such as text wrap). But the intended text to be displayed is one contiguous paragraph so I can avoid the EOL issues for now.

This is mostly confusing because of how intermittent it is. Sometimes I get 8, 10, or up to 15 sessions with no problems. I’m trying to catch a breakpoint when the error happens to see what’s going on, but my attempt above failed to catch it.

Would it be helpful for me to include a link to the full project? Should I create a separate forum thread? Thanks for your attention!

I will repeat my previous post. You want to check if HTML actually displays something.

You could add to your code :

system.debuglog(TargText(port(currentIndex)))

So when it does not display, you can check in the console on Mac or DebugView on PC that the text is present.

Alternatively, this in a button will display in a MsgBox the content of the HTMLViewer DOM (except ) :

Sub Action() dim js as string js = js + "var html = document.getElementsByTagName('HTML')[0].innerHTML; " js = js + "document.title = html" TargetHTML.ExecuteJavaScript(js) End Sub

Shouldn’t my if/then above catch if the HTML is blank? Even when no text appears, this condition is not triggered.

if len(htmlText)<125 then 'actual length of html code is 115 characters MsgBox "Error loading passage text." end if

I added your JS code to the Action of a new PushButton, and curiously can’t get the problem to replicate! Will keep testing, but so far so good.

When I push the button, though, nothing happens. Can you explain what the code is doing?

Spoke too soon- issue persists.

Would love to see the DOM. Where/how exactly should I use your awesome code?

Also, I tried using system.debuglog(), but seems to not work with my version/OS. I put a simple message in a button, and pushing multiple times adds the following to Console only once per session:

11/13/15 10:00:40.708 PM PassageStudy.debug[13824]: WARNING: The Gestalt selector gestaltSystemVersion is returning 10.9.5 instead of 10.10.5. Use NSProcessInfo's operatingSystemVersion property to get correct system version number. Call location: 11/13/15 10:00:40.708 PM PassageStudy.debug[13824]: 0 CarbonCore 0x9b9b6291 ___Gestalt_SystemVersion_block_invoke + 135 11/13/15 10:00:40.708 PM PassageStudy.debug[13824]: 1 libdispatch.dylib 0x9a5fc0b5 dispatch_once_f + 251 11/13/15 10:00:40.708 PM PassageStudy.debug[13824]: 2 libdispatch.dylib 0x9a5fd0d8 dispatch_once + 31 11/13/15 10:00:40.708 PM PassageStudy.debug[13824]: 3 CarbonCore 0x9b92f69d _Gestalt_SystemVersion + 1050 11/13/15 10:00:40.709 PM PassageStudy.debug[13824]: 4 CarbonCore 0x9b92e7c0 Gestalt + 150 11/13/15 10:00:40.709 PM PassageStudy.debug[13824]: 5 rbframework.dylib 0x00364e53 _Z11InitGlobalsv + 43 11/13/15 10:00:40.709 PM PassageStudy.debug[13824]: 6 rbframework.dylib 0x0033d15f RuntimeInit + 53

[quote=229549:@Tamar Kornblum]Would love to see the DOM. Where/how exactly should I use your awesome code?

Also, I tried using system.debuglog(), but seems to not work with my version/OS. I put a simple message in a button, and pushing multiple times adds the following to Console only once per session:[/quote]

Re-read my post. The code goes into the Action event of a button.

Sub Action() dim js as string js = js + "var html = document.getElementsByTagName('HTML')[0].innerHTML; " js = js + "document.title = html" TargetHTML.ExecuteJavaScript(js) End Sub

Then you get the result in the TitleChanged event of the HTMLViewer, in the newTitle string parameter.

As for System.Debuglog, what you posted has no relationship whatsoever with what you should see.

System.debuglog "Hello World"

Here is what it does in Console :

11/14/15 7:39:35.000 AM My Application.debug[1435]: Hello World

You can also see the same message in the message pane of the IDE when run, which you access by pressing the third icon at the bottom of the central pane of the IDE.

I’m not sure what button you’re referring to. Do I add an object to the HTMLviewer? If so, please include details. I’d love to try it.

To be clear, even when the text is not shown in the HTMLviewer, I’ve confirmed that the html I’m sending is complete even when text doesn’t appear. (copied htmlText variable to window property)

Regarding the console.log - what I pasted above is every line that appears with the identifier of MyApplication.debug. The first line indicates a version mismatch, and after some research I suspect that my version of RealStudio may be too old to play nicely with Console. My IDE doesn’t have a Message pane; that came in a later version.

I created a standalone app with just an HTMLviewer, and copied affected code into it. Each test seems to work perfectly. Perhaps another piece of my project is causing a conflict. Something with how the window opens, or how the control is initiated?

More clues:

  • sometimes the text appears as one line with no text wrap. This usually happens 1st run after making a minor change in the code.
  • overall, the disappearing text issue is getting more frequent. Nothing else has changed in the code except for attempts to fix this (removing extra controls, moving code out of KeyDown into a method… all superficial).

Any more ideas for where to look/troubleshoot? The only other activity I have going on during this is a visible countdown timer.

[RealStudio 2011 r4.1, Mac Yosemite 10.10.5]

You simply add a button to your window to debug.

[quote=229977:@Tamar Kornblum]Regarding the console.log - what I pasted above is every line that appears with the identifier of MyApplication.debug. The first line indicates a version mismatch, and after some research I suspect that my version of RealStudio may be too old to play nicely with Console. My IDE doesn’t have a Message pane; that came in a later version.

[/quote]

Please simply look in the Messages pane of the IDE (third icon at the bottom of the central pane).

He is not using Xojo.

[quote=229990:@Asis Patisahusiwa]He is not using Xojo.
[/quote]

Right. In RS the Message window does not seem to show System.Debuglog.

Tamar : Here is how a message looks in the Console :

11/16/15 9:07:38.854 AM My Application.debug[996]: Hello World

It shows AFTER the kind of information you posted.