Help understanding styleruns

I’m trying to get a handle on styleruns and find it a bit confusing when looking at the code in the Language Reference. I was able to use their example to output the styled text in the textarea to an RTF file. My application will be a bit different, however. The user will set text entries in a textarea where they can select some words (via SelStart and SelLength) and apply a style to them via a style pulldown menu (plain, bold, italic, underline). The text will be saved to a listbox via button or keypress. After they are all done making entries I need to take the text from each listbox entry and apply any style markup such as for italic to individual words in each listbox entry to the exported text file. I just don’t understand how I can store that style information for each separate listbox entry.

Use CellTag to store the formatting information.

thanks. so i can use celltag to allow me to store a variant in a listbox cell.
listBox1.cellTag(0,0) = TextArea1.StyledText
seems simple enough, but how would i call that cell back and put italic tags around the italic text?
let’s say in the string “The dog has always been lazy.” how would I add the tags around the word lazy in a text file? I would imagine it would be finding the range of the italic text?

Look at /Applications/Xojo 2016 Release 3/Example Projects/Text/StyledText.xojo_binary_project

It shows you how to set styles.

ok thanks!

unfortunately that example does not actually help me with what I need to do. once the text is saved via CellTag, I cannot understand how to read that info back in and apply italic tags around the italic text. It simply writes it out to an RTF file.

are you attempting to do something more complicated than


which makes “Y” characters starting at location “X” all italic (there are also color, bold, underline)???

There is no example, as far as I know, that shows how to convert HTML tags to styled text directly. You will have to figure out how to do it. I pointed to the example because it shows clearly how to apply different styles to different portions of text :

[code] // Load Chapter 3 of the book, “A Princess of Mars” by Edgar Rice Burroughs

Dim text As String

text = kPrincessOfMars

StyledTextArea.StyledText.Text = text

// Chapter Title
StyledTextArea.StyledText.Font( 0, 11) = “Arial”
StyledTextArea.StyledText.Size( 0, 11) = 24
StyledTextArea.StyledText.Bold( 0, 11 ) = True
StyledTextArea.StyledText.TextColor(0, 11) = &c0000ff

StyledTextArea.StyledText.Bold(13, 17) = True

StyledTextArea.StyledText.Font(31, text.Len-31) = “Times New Roman”
StyledTextArea.StyledText.Size( 31, text.Len-31) = 16

// Italicize Mars in the text
Dim position As Integer = 31
position = text.InStr(position, “Mars”) // Start after title
If position > 0 Then
StyledTextArea.StyledText.Italic(position-1, 4) = True
position = position + 4
End If
Loop Until position <= 0

It is very similar to what Dave posted.

For tags such as , and so on, I would simply use Instr to find the first occurrence of a tag, then another instr() to find , and then I will have the extent of the italic. Something like :

[code] dim lastStart as Integer = 1
lastStart = instr(lastStart, TextArea1.Text, “”) + 2
TextArea1.Selstart = lastStart
TextArea1.SelLength = instr(lastStart, TextArea1.Text, “
”)-1 - lastStart
TextArea1.SelItalic = True
Loop until (instr(lastStart, TextArea1.Text, “”) = 0)


You could also use split with the tags to convert the text in an array of styles, and rebuild the styled text from it. That would remove them at the same time.

It happens so I need to print the styled content of an IOSHTMLViewer, and there is strictly nothing whatsoever in the Xojo iOS framework to print (styled or not). So I will have to figure how to interpret HTML tags in a similar way to create a picture showing the styled text. Meaning, I may yet explore beyond what I describe above.

no, i need to go the other way. if the user sets some text in the textarea, I need to save that text and any style information such as italics that were set on let’s say 3 words in the middle of that sentence. I am saving them into a listbox. Then I need to call that information back when the user exports and add tags (or possibly something else depending on the export option chosen) to the text that was originally set to italics in the textarea. I will not be outputting formatted text such as RTF in most cases. The example just does not show how I can do that.

Place the text exactly as it comes from the styledtext control in CellTag. Strip out the styles from the text and place the readable text in the CellText. That way the user can see the text (unstyled) in the listbox and the ‘real’ text is hidden in the CellTag. When you save the data from the listbox use the CellTag variable to get the styled text.

Let me try to understand. Each cell contains a stylerun, right ?

Seems to me relatively easy to throw in the cell tag, and add this plus to the textual data in the cell. Way easier than the reverse.

Problem with adding the tags prior to exporting is that some exports require a character count (32 characters per line) and that would be adding unneeded characters to the character count. I would not want the final product to be displaying tags. Note that this character count doesn’t apply to formats that use the tags, but some will require a special code when dealing with styled text. For instance, instead of I would be adding 91ae on export prior to italic text and then 9120 prior to the rest of the text if it’s plain text. So it’s kinda not a one-size-fits-all thing. I need to change the tags as needed for each separate export.

Does your cell tags contain a STYLERUN? or does it contain HTML?
If it is a style run, then set or reset the BOLD and/or ITALIC property (there are no “tags”)
if it is HTML then you deal with tags

There an idiom that says “What is clearly thought out is clearly expressed”. You start by a post saying that you need to output styled text :

That is exactly what I suggested.

Now you pull a new rabbit out of your hat with new codes, and say it is no good.

Get your specs straighten out, and we can start speaking again. In the meantime, nothing can be done on a moving target.

Good luck.

sorry. not sure i could have been any clearer. it’s not a moving target at all. I stated that I needed to apply style markup (not a stylerun) to some text that the user has designated to be italic in the textarea. So they typed some text, then highlighted some of it and changed it to italic in the textarea, then hit the save button for that entry. the s/w would then save that styled text into a listbox. when they got all done making entries, they would export and depending on the export (not styled RTF as the example in language reference showed) the s/w will apply some code to the italic text either via or whatever was appropriate for that export format. not sure how i could have stated it much better in my original post, but maybe this helps? i appreciate the help as I just cannot figure this out from the supplied stylerun examples.

I think the confusion is you are mixing technology in your descriptions. StyleRuns DO NOT use tags,
a Style run is a segment of text that has a unique combination of color, bold, italic and/or underline
in a Textarea if any one of those attributes change, a NEW stylerun is created…
So if you had 5 words, and every other word was Italic, you would have 5 styleruns… If all the words were italic you would have ONE.

This is unlike markup (such as HTML), where you have a single string with special character sequences to denote changes.

So …

[quote]Get your specs straighten out, and we can start speaking again. In the meantime, nothing can be done on a moving target.

If what you want is export in a tag system, it should be pretty simple, and I frankly do not see the need for a listbox in the middle.

Where you lost me is this :

I would assume that you are clever enough to add the tags upon saving.

That is up to you. Display and data better be separate. You don’t store data in the control, you store it separately. Actually as far as I understand, it could very well stay in the TextArea.

If this is an export format for instance for a printer, then keep it an export format, and save the original text as RTF.

Now, I should not be the one struggling to understand what you want to do.

If you made the effort to present the process in a dotted list, maybe that would become clearer. For the moment, it is absolutely not.

I do understand what styleruns do and kind of how they work. I did some experiments with the other stylerun code in language ref under Range. it only shows where there are different styleruns, however, but not which are which.

I’m already using a listbox in my s/w and i do not want to change that, as it’s integral to how it works. I will not be exporting for a printer for any reason. the exports will be video related. right now a user can mark up a whole entry as being italic, but not several words within it. I keep the info in an array as to whether or not that entry has italic set for it. then when they export i can apply the italic code to the file it creates, depending on what’s needed. I simply need more granular control over marking up individual words within each entry.

Sorry i cannot be more clear on how this works. Perhaps this video showing how the s/w works would give you an idea.

Each stylerun has properties pertaining to font, style, font size. And you even have Text to see what’s in there. It far more than where there are.