Hello Yusuke,
> On Apr 23, 2017, at 11:13 PM, Kino <[log in to unmask]> wrote:
>
> ...
>
> And here is a macro which is not affected by the bug (i.e. it does not use transliterateInRange).
> <http://www2.odn.ne.jp/alt-quinon/files/NWPro/convert/MakeKanjiTraditional_20170423_nwm.zip>
>
> --
> ### Make Kanji Traditional ###
>
> # Replace Simplified Japanese kanji characters (Shin-ji) with Traditional forms.
> # The macro works on selection(s). With no selection (just a caret), the macro will make a copy of the document and process it entirely.
> # Ambiguous letters will be converted to a set. For example, 余 will be [余餘].
>
> $doc = Document.active
> if $doc == @undefined # if there is no open document...
> exit
> end
>
> Require Pro Version '2.1'
> # Use @S (String Literal) to make keys and values of $kanjiConv plain text
> $kanjiConv = Hash.new
> $kanjiConv{@S'万'} = @S'萬' # trad
> $kanjiConv{@S'与'} = @S'與' # trad
> $kanjiConv{@S'亀'} = @S'龜' # pr
> $kanjiConv{@S'予'} = @S'[予豫]' # 予 => [予豫] trad*
>
> # about 500 definitions omitted here
>
> $shinKanjis = $kanjiConv.keys.join ''
> $shinKanjis = @S'[' & $shinKanjis & @S']'
> /* Join all keys of $shinKanjis and put them between [ and ] without "+" so that the macro transliterates kanji letters one by one, not as a sequence of multiple characters. */
>
> $sels = $doc.textSelections
> if $sels[0].length > 0
> foreach $sel in reversed $sels
> # Process from end to top for some values of $kanjiConv consist of multiple characters
> $copiedText = $sel.subtext.copy
> # Make a copy of seleted text so that we can do something like
> # Replace in Selection.
> $charSels = $copiedText.findAll $shinKanjis, 'E-i'
> if $charSels.count
> foreach $charsel in reversed $charSels
> $char = $charsel.text.substringInRange($charsel.range)
> $copiedText.replaceInRange($charsel.range, $kanjiConv{$char})
> end
> $sel.text.replaceInRange($sel.range, $copiedText)
> end
> end
> else
> $doc = $doc.copy
> # Bug: with @false added, text in footnotes will be ignored.
> $doc.markAsDiscardable
> $charSels = $doc.text.findAll $shinKanjis, 'E-i'
> if $charSels.count
> foreach $charsel in reversed $charSels
> $char = $charsel.text.substringInRange($charsel.range)
> $charsel.text.replaceInRange $charsel.range, $kanjiConv{$char}
> end
> end
> end
>
> ### end of macro
> --
Wow, this is great! Thus, it is possible to avoid using "transliterateInRange" to transliterate all the characters of a certain kind. And this is even better than "transliterateInRange" since it is possible to replace one target character with two or more characters...!
>
> When uploading the macro, I *discovered* an old macro for a similar purpose, uploaded there seven years ago. Seems to work though affected by the transliterateInRange bug. It works for selection(s) only. However, it covers non-Unicode glyph variants, e.g. 道󠄁 with two points sinnyo. If you are interested in it, please try it. Before running it, open the macro file and change "$demo = true" to "$demo = false". With "$demo = true", it produces a conversion table.
> <http://www2.odn.ne.jp/alt-quinon/files/NWPro/convert/TradKanjiForm_nwm.zip>
>
> To support glyph variants, the macro above manipulates rtf code. A weakness of that method is that glyph variants are displayed only in OS X apps using Apple's text engine.
This seems to be a really great macro! The "weakness" that you mention is not really a weakness, as far as the files are used within NWP...
>
> Please note that, in both of the two macros, the conversion table may contain bugs. I have not tested them throughly and what I know about traditional kanji forms is very limited.
>
>
> Another topic. A little while ago, I came to know Ideographic Variation Sequences system which uses special Unicode characters to specify a variant and which is supported by TextEdit, Mail.app, etc. in OS X 10.11.6 at least. Unfortunately, NWP does not support it yet (I will send a feature request to Nisus Soft), but, with XeLaTeX, for example, I think it is the surest way to use glyph variants.
> <http://www.unicode.org/ivd/#versions>
> <http://www.unicode.org/reports/tr37/>
>
> From <http://www.unicode.org/ivd/data/2016-08-15/IVD_Sequences.txt>, I made a table of variation sequences.
> <http://www2.odn.ne.jp/alt-quinon/files/varia/IDV_Sequences_AdobeJapan1.zip>
>
This is also an incredibly well-done file. This will be certainly a very important work!
Thank you so much!
Best regard,
Nobumi Iyanaga
Tokyo,
Japan
|