Hello Kino,
Thank you very much for your reply.
On Jun 3, 2010, at 11:15 PM, Kino wrote:
> On Jun 3, 2010, at 11:58 AM, Nobumi Iyanaga wrote:
>
>> On Jun 1, 2010, at 8:00 PM, Kino wrote:
>>
>>> Surely there would be other ways to do so but my usual procedure is
>>>
>>> $variable = Cast to String 'something' # unnecessary if
>>> 'something' is already plain text
>>> Push Target Text $variable
>>> Set Font Name 'Hiragino Mincho Pro'
>>> Pop Target Text
>>
>> Ah, I didn't know these commands. I read the explanation in Nisus
>> Macro Reference, but I don't understand well what is the point.
>> Could you give me a more detailed explanation on these commands...?
>
> But what details? All I know is that it allows you to apply some
> attributes on a variable (text object). Isn't it handy?
Ah, that was the "details" that I was looking for. Yes, it is
certainly very useful.
>>
>> Another thing (unrelated to this subject) that I found in writing
>> this macro is that the command "$text.find xxx"... is VERY VERY
>> slow. I could replace them with "$text.rangeOfString xxx" -- but
>> this should really be improved, like perl's "$text =~ /xxx/"...
>> command.
>
> Really? How did you test it? For me, find command seems to be 2 or
> 3 times slower but is it fair to call it "VERY VERY slow" for that?
> It is much more featured and it would not be a good idea to use it
> when rangeOfString is sufficient. I don't know what perl's
> equivalent of rangeOfString is but, as to s///, sed is much faster
> than perl and perl's tr/// is much faster than its s///. However, I
> don't think you will blame perl for that.
Below are two results of code profiling (I am sorry, they are
long..., and certainly VERY VERY clumsy...). Perhaps I used
"$text.find ..." in a wrong way? Anyway, the comparison seems evident...
And thank you VERY MUCH for your very useful macro "Styles2LaTeX".
This is the kind of things I wanted for a long time.
Best regard,
Nobumi Iyanaga
Tokyo,
Japan
-------
Profiling result using "$text.find...":
Total macro elapsed time: 19.4 seconds
Total profiled execution time: 8.2 seconds
The following lists the percent of profiled time spent on each line:
Debug.setCodeProfilingEnabled true
$doc = Document.active
if $doc == undefined
exit
end
$sels = Array.new
$ranges = Array.new
# $selects = Array.new
0.2 foreach $text in $doc.allTexts
if $text.length
$i = 0
0.2 while $i < $text.length
0.8 $attr = $text.displayAttributesAtIndex $i
0.8 $fname = $attr.fontName
0.8 $range = $text.rangeOfDisplayAttributesAtIndex $i
95.9 if $fname.find '^Mojikyo', 'E'
# if $fname.rangeOfString 'Mojikyo'
0.4 $theChar = $text.subtextInRange $range
if $theChar.length > 1
$charList = $theChar.split ('')
foreach $a_char in $charList
if $a_char == "\n"
$the_location = $range.location + 1
$range = Range.new ($the_location, 1)
else
$sels.appendValue $a_char, $fname
$a_range = Range.new ($range.location, 1)
$ranges.appendValue $a_range
$the_location = $range.location + 1
$range = Range.new ($the_location, 1)
end
end
elsif $theChar != "\n"
0.2 $sels.appendValue $theChar, $fname
$ranges.appendValue $range
end
end
0.6 $i = $range.bound
end
end
end
Debug.log $sels
# Debug.log $ranges
exit
-----
Profiling result using "$text.rangeOfString ...":
Total macro elapsed time: 3.4 seconds
Total profiled execution time: 0.3 seconds
The following lists the percent of profiled time spent on each line:
Debug.setCodeProfilingEnabled true
$doc = Document.active
if $doc == undefined
exit
end
$sels = Array.new
$ranges = Array.new
# $selects = Array.new
foreach $text in $doc.allTexts
5.6 if $text.length
$i = 0
11.1 while $i < $text.length
16.7 $attr = $text.displayAttributesAtIndex $i
27.8 $fname = $attr.fontName
16.7 $range = $text.rangeOfDisplayAttributesAtIndex $i
# if $fname.find '^Mojikyo', 'E'
5.6 if $fname.rangeOfString 'Mojikyo'
5.6 $theChar = $text.subtextInRange $range
if $theChar.length > 1
$charList = $theChar.split ('')
foreach $a_char in $charList
if $a_char == "\n"
$the_location = $range.location + 1
$range = Range.new ($the_location, 1)
else
$sels.appendValue $a_char, $fname
$a_range = Range.new ($range.location, 1)
$ranges.appendValue $a_range
$the_location = $range.location + 1
$range = Range.new ($the_location, 1)
end
end
elsif $theChar != "\n"
$sels.appendValue $theChar, $fname
$ranges.appendValue $range
end
end
5.6 $i = $range.bound
end
end
end
5.6 Debug.log $sels
# Debug.log $ranges
exit
# Prompt $sels
# Prompt $ranges
|