New topic: 

Syled Text confusion

<http://forums.realsoftware.com/viewtopic.php?t=47470>

         Page 1 of 1
   [ 1 post ]                 Previous topic | Next topic          Author  
Message        bobjtls          Post subject: Syled Text confusionPosted: Mon 
Apr 01, 2013 8:15 pm                         
Joined: Wed Nov 08, 2006 6:25 pm
Posts: 33
Location: Sydney, Australia                I am confused about handling styled 
text ina  text area. My project needs to convert a text area to an RTF file. I 
can style the text in the text area, say setting text colour of selected text 
to blue. But then, a subsequent operation, including some text replacements, 
loses the style information.

Does someone have a primer on how to do styled text? Or maybe an example? I 
find the reference manual totally confusing.

This is the basic loop. In the select...end select loop, I process tags and 
need to do the styling. For example, if the text contains [spelling freed] then 
the output should be freed* colored red
 
//proceses the right hand box converting the square bracket notation into 
styled text
dim i, j, numTags, tagStart, tagEnd as integer
dim currentTag, currentTagType, styledText,s as string

//handle [event tags, [event xx] -> [xx]
TextFileContents.text = replaceAll(TextFileContents.text,"[event ","[")

// handle interjections
while InStr(TextFileContents.text,App.CRLF + "[interjection") > 0
  TextFileContents.text = replaceAll(TextFileContents.Text,App.CRLF + 
"[interjection","[interjection")
wend
TextFileContents.text = replaceAll(TextFileContents.Text,"[interjection "," [")

//make unsure tags inline
while InStr(TextFileContents.text,App.CRLF + "[unsure") > 1
  TextFileContents.text = replaceAll(TextFileContents.Text,App.CRLF + 
"[unsure","[unsure")
wend

//make spelling tags inline
while InStr(TextFileContents.text,App.CRLF + "[spelling") > 1
  TextFileContents.text = replaceAll(TextFileContents.Text,App.CRLF + 
"[spelling","[spelling")
wend

// process styling
if DebugnumTags = 0 then
  numTags = CountFields(TextFileContents.StyledText.text,"[")
else
  numtags = DebugnumTags //if option ket was down when button pressed
end if


tagStart = 0
for i = 1 to numtags
  ShowProgressBar(true,i,numTags)
  tagStart = InStr(tagStart + 1,TextFileContents.text,"[")
  tagEnd = tagStart
  while mid(TextFileContents.text,tagEnd,1) <> "]"
  tagEnd = tagEnd + 1
  wend
  //select tag
  TextFileContents.SelStart = tagStart
  TextFileContents.SelLength = tagEnd - tagStart + 1
  //
  currenttag = TextFileContents.SelText
  currentTagType = NthField(currentTag, App.Space,1)
  select case currentTagType
  case "indecipherable]"
  case "spelling"
  s = Trim(replace(currentTag,"spelling "," "))
  s = replace(s,"]","*")
  TextFileContents.text = replace(TextFileContents.text,"[" + 
currentTag,App.Space + s)
  //need to add color=red
  case "unsure"
  s = Trim(replace(currentTag,"unsure "," "))
  s = replace(s,"]","*")
  TextFileContents.text = replace(TextFileContents.text,"[" + 
currentTag,App.Space + s)
  //need to add color=red
  case "title"
  case "speaker"
  s = Trim(replace(currentTag,"speaker ",""))
  s = replace(s,"]:",":")
  TextFileContents.text = replace(TextFileContents.text,"[" + 
currentTag,App.Space + s)
  //need to set style to bold
  end select
next
ShowProgressBar(false,i,numTags)

//miscellaneous tidying up
while InStr(TextFileContents.text,App.CRLF + App.Space) > 0
  TextFileContents.text = replaceAll(TextFileContents.text,App.CRLF + 
App.Space,App.CRLF)
wend

while InStr(TextFileContents.text,App.space + App.Space) > 0
  TextFileContents.text = replaceAll(TextFileContents.text,App.space + 
App.Space,App.CRLF)
wend
      
_________________
bobj 
----------------------------------- 
Dr Bob Jansen 
Turtle Lane Studios Pty Ltd 
PO Box 26, Erskineville NSW 2043, Australia 
Ph: +61-414 297 448 
Skype: bobjtls 
http://www.turtlelane.com.au  
                             Top             Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 1 post ]      
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

[email protected]

Reply via email to