nisus.com
https://www.nisus.com/forum/

Type Text vs Type Attributed Text
https://www.nisus.com/forum/viewtopic.php?f=17&t=6570
Page 1 of 1

Author:  credneb [ 2017-01-13 18:56:11 ]
Post subject:  Type Text vs Type Attributed Text

Greetings.

The macro reference states:
Type Text text
Replaces the currently selected text with the text provided. The inserted text uses the attributes that were applied to the selected text.

Type Attributed Text text
....The inserted text will have the attributes that are applied to the argument in the macro itself.

However, using the Type Text statement in the following macro (abbreviated, which converts 2-byte Japanese characters to 1-byte equivalents), all attributes are removed from the text -- so red text goes black and superscript/subscript attributes are stripped.

Using the Type Attributed Text statement retains the attributes in the original text. But, there are no attributes "applied to the argument in the macro itself."

If the documentation isn't wrong, why isn't Type Text the correct command?

[code]$sel = $doc.selectedSubtext
$len = $sel.length
If $len < 1
Prompt "Select some text first."
Exit
End

$map = Hash.new
$map{'A'} = 'A'
$map{'B'} = 'B'
$map{'C'} = 'C'
$map{'0'} = '0'
$map{'1'} = '1'
$map{'2'} = '2'
$map{'3'} = '3'
$map{'4'} = '4'

$range = Range.new(0, $len)
$sel.transliterateInRange($range, $map)
Type Attributed Text $sel[/code]

Cliff

Author:  phspaelti [ 2017-01-14 04:36:58 ]
Post subject:  Re: Type Text vs Type Attributed Text

Hello Cliff,
I don't know that the "documentation isn't wrong". But what you are seeing is the difference between using a variable and a literal. If you use Type Attributed Text with a literal, it will apply the attributes that are applied to the literal in the macro. However if you are using a variable the command applies the attributes that are applied to the text held in the variable.

And as a side note: You are aware that you could just transliterate the selection in place, without needing to copy it into a variable and then typing the variable back into the document? The command would look like this:
Code:
$sel = $doc.textSelection
$sel.text.transliterateInRange($sel.range, $map)


This approach will, as a matter of course, keep the attributes in the document. It won't keep the selection. If you want the selection to get specific attributes, you could re-select it, and then apply the wanted attributes with menu commands. For example
Code:
$sel = $doc.textSelection
$sel.text.transliterateInRange($sel.range, $map)
$doc.setSelection $sel
Size:14
Text Color:Red
Bold

Author:  credneb [ 2017-01-14 23:04:33 ]
Post subject:  Re: Type Text vs Type Attributed Text

Hello, Philip.

Thank you for your help.

I was not aware that

$sel.text.transliterateInRange($sel.range, $map)

was valid, and have changed my macro. In the process, (prompted by .textSelection) I learned I was using a deprecated command.

And I have been re-reading the lang ref in the process about literals and interpolated variables.

Thanks again.

Page 1 of 1 All times are UTC - 8 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/