NISUS Archives

April 2017

NISUS@LISTSERV.DARTMOUTH.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Reply To:
Date:
Sun, 23 Apr 2017 23:13:21 +0900
Content-Type:
text/plain
Parts/Attachments:
text/plain (91 lines)
Hello Nobumi,

> On 2017/04/23, at 05:25, Nobumi Iyanaga <[log in to unmask]> wrote:

>> On Apr 22, 2017, at 5:58 PM, Kino <[log in to unmask]> wrote:

>> However, as of NWP 2.1.7 running on OS X 10.11.6, transliterateInRange seems to be buggy. For text in footnotes, it changes Japanese fonts (Hiragino Mincho ProN, YuMincho) to Andale Mono so that the transliterated strings are displayed using the fall back font (Hiragino KakuGothic?). What is strange is that Andale Mono is not used in the test file nor in the macro file. I will report this bug to Nisus soft.
> 
> Yes, in fact, with your another reply, I tried to run the macro -- and had similar problems in the footnotes of the document on which I am working. That not only changed the fonts of Japanese text, but also changed italic to non-italic, or red color to black color, in a very random way. This is a major bug... (I am running OS 10.10.5).

Oup! my test file turned out to contain text in Andale Mono font. Or rather, Andale Mono is used everywhere other than Japanese text. At that time, I did check for Document fonts... Then, the bug seems to remove all character attributes from footnote text visited by transliterateInRange.

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
--

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.

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>


Kino

ATOM RSS1 RSS2