How to handle carriage returns when modifying an annotation?
jeremypmeyers
I created the following code that prompts the user for which chart they want to modify. It changes some of the graph settings, but I also want to modify the annotations to make everything 16-point font. I've extracted the text of each annotation, done a clumsy but effective search-and-replace of all font size declarations, and prepended a 16-point font declaration so all annotation text should be displayed in 16-point font. I've managed to get this to work so that \s(wavename) declarations still display wave markers in the annotation, and font changes \F still work as originally entered, but the carriage returns from the original annotation don't come out right after the modification.
After running this code, each annotation shows an odd triangular character where the line breaks were, and the editable text in the annotation window shows \r. I've also tried with the sprintf command to generate the string for the textbox/C/N command, and that doesn't work either. Is there a way that I can make this work?
function PrepGraphForPresentation()
string wl=winlist("*",";","WIN:1") //Gets a list of all existing graph windows
print wl
string wn
string wtl=""
variable wi=0
do
wn=StringFromList(wi,wl)
if (strlen(wn)==0)
break
endif
GetWindow $wn wtitle
wtl += ReplaceString(";", s_value, "") +";" //Creates a list of existing windows titles
wi+=1
while(1)
variable wselect
prompt wselect, "Which graph do you want to apply style to?", popup, wtl
doprompt "Graph selection", wselect //Prompts the user to select which chart to change styles on
string chartname=Stringfromlist((wselect-1),wl)
Modifygraph/Z /W=$chartname standoff=0,fsize=18,freePos=0 //Eliminates standoffs, sets axis font size to 18
string al=annotationlist(chartname) //Creates a list of all annotations in the chart
variable ai=0
do //Do-loop to change all annotations in the chart
string an=stringfromlist(ai,al)
if (strlen(an)==0)
break
endif
string astring= annotationinfo(chartname,an)
string tstring= StringByKey("TEXT", astring ) //Captures the existing annotation text
variable start=0
do
variable fontsizestart=strsearch(tstring,"\Z",start) //Looks for places in the text where font size is declared
if (fontsizestart<0)
break
endif
tstring=ReplaceString(tstring[fontsizestart+2], tstring, "1",1,1) //there's got to be a more elegant way to replace the two digits of
tstring=ReplaceString(tstring[fontsizestart+3], tstring, "6",1,1) //an existing font size with "16" but this is what I came up with.
start=fontsizestart+3
while(1)
tstring = ReplaceString("\\\\", tstring, "\\") //this gets most \ output formatted correctly so they're read
//as control characters and not as the actual '\' character
tstring = "\\Z16"+tstring //If font size is default, explicitly changes font size to 16 point.
textbox/C/N=$an tstring
ai+=1
while(1)
end
<\igor>
string wl=winlist("*",";","WIN:1") //Gets a list of all existing graph windows
print wl
string wn
string wtl=""
variable wi=0
do
wn=StringFromList(wi,wl)
if (strlen(wn)==0)
break
endif
GetWindow $wn wtitle
wtl += ReplaceString(";", s_value, "") +";" //Creates a list of existing windows titles
wi+=1
while(1)
variable wselect
prompt wselect, "Which graph do you want to apply style to?", popup, wtl
doprompt "Graph selection", wselect //Prompts the user to select which chart to change styles on
string chartname=Stringfromlist((wselect-1),wl)
Modifygraph/Z /W=$chartname standoff=0,fsize=18,freePos=0 //Eliminates standoffs, sets axis font size to 18
string al=annotationlist(chartname) //Creates a list of all annotations in the chart
variable ai=0
do //Do-loop to change all annotations in the chart
string an=stringfromlist(ai,al)
if (strlen(an)==0)
break
endif
string astring= annotationinfo(chartname,an)
string tstring= StringByKey("TEXT", astring ) //Captures the existing annotation text
variable start=0
do
variable fontsizestart=strsearch(tstring,"\Z",start) //Looks for places in the text where font size is declared
if (fontsizestart<0)
break
endif
tstring=ReplaceString(tstring[fontsizestart+2], tstring, "1",1,1) //there's got to be a more elegant way to replace the two digits of
tstring=ReplaceString(tstring[fontsizestart+3], tstring, "6",1,1) //an existing font size with "16" but this is what I came up with.
start=fontsizestart+3
while(1)
tstring = ReplaceString("\\\\", tstring, "\\") //this gets most \ output formatted correctly so they're read
//as control characters and not as the actual '\' character
tstring = "\\Z16"+tstring //If font size is default, explicitly changes font size to 16 point.
textbox/C/N=$an tstring
ai+=1
while(1)
end
<\igor>
October 11, 2015 at 06:25 am - Permalink