2011年5月16日

こんにちわ、でいいのじゃ

「こんにちわ」という表記は“間違い”とまでは言えぬのではありませぬか。

1986年内閣告示の「現代仮名遣い」には、「こんにちは」が助詞「は」の表記例としてあげられていますが、46年の「現代かなづかい」は「こんにちは」の例をあげておりませぬ。

それどころか、86年に文部省が都道府県教育委員長などに通知した「学校教育における『現代仮名遣い』の取扱いについて」では、助詞「は」「へ」について、「現代かなづかい」では“「わ」「え」と書くことも許容すると解釈されてい”たことを(参考)にあげております。同通知全文はこちら

つまり、「現代仮名遣い」告示以前には、「コンニチワ」を一語ととらえる(「は」を助詞ととらえない)ならば、「現代かなづかい」の細則第四「ワに発音されるはは、わと書く」にしたがって「こんにちわ」と表記することもできたわけです。
戦後すぐに読み書きを習った少し年配の方が「こんにちわ」と書かれるのは自然なことかもしれませぬ。

もっとも、規定云々の前提として、「現代仮名遣い」は「個々人の表記にまで及ぼそうとするものではない」と適用範囲を限定しています(「常用漢字」も同様です)から、twitterやblogのように個人的な書き物について、“「こんにちわ」と書くのは間違いだ”と言うのは行き過ぎだと思うのであります。

2011年5月14日

EPUB ZIP コンテナの作り方

EPUBのファイル(コンテナ)は「.epub」という拡張子がついていますが、ファイルの構造としてはZIPアーカイブです。ですから、拡張子を「.zip」に書き換えれば、MacでもWindowsでも解凍(展開)して、本文などを普段使い慣れているテキストエディタで編集できます。

しかし、編集後、ZIPで圧縮(アーカイブ)して、拡張子を「.epub」に戻せばいいかというと、そうではないのです。mimetypeファイルの扱いが少し特別なのです。
  • 要件1: ZIPコンテナの先頭に置く
  • 要件2: 圧縮も暗号化もしない
  • 要件3:  ヘッダにはextra fieldをつけない
ことが求められているのです。

要件1を満たすには
→ 最初にmimetypeファイルを単独でZIPアーカイブし、次に残りのディレクトリ・ファイルをそのZIPコンテナに追加すればOK。なんか、簡単^^

要件2を満たすには
→ zipコマンドに「-0」(ゼロです。圧縮率0という意味)をつければOK。

要件3を満たすには
→ zipコマンドに「-X」(大文字です)をつければOK。

たとえば、「De_Suse」というフォルダにmimetypeもふくめ必要なデータを入れておいて、
$ cd De_Suse
$ zip -0 -X ../De_Suse.epub mimetype
$ zip -r ../De_Suse.epub * -x mimetype
$ cd ..

これで「De_Suse.epub」というEPUBファイルができます。なお、2行目の「-X」は大文字、3行目の「-x」(引数ファイルを除外するという意味のオプション)は小文字です。


なお、mimetypeの扱いについての詳細は「EPUB Open Container Format (OCF)」に規定されています。

EPUB 2.0.1
http://idpf.org/epub/20/spec/OCF_2.0.1_draft.doc
「4 ZIP Container」節の末尾
The first file in the ZIP Container MUST be a file by the ASCII name of ‘mimetype’ which holds the MIME type for the ZIP Container (i.e., “application/epub+zip” as an ASCII string; no padding, white-space or case change). The file MUST be neither compressed nor encrypted and there MUST NOT be an extra field in its ZIP header. If this is done, then the ZIP Container offers convenient “magic number” support as described in RFC 2048 and the following will hold true:
The bytes “PK” will be at the beginning of the file
The bytes “mimetype” will be at position 30
The actual MIME type (i.e., the ASCII string “application/epub+zip”) will begin at position 38

EPUB 3
http://idpf.org/epub/30/spec/epub30-ocf.htm
3.3 OCF ZIP Container Media Type Identification
OCF ZIP Containers must include a mimetype file as the first file in the Container, and the contents of this file must be the MIME type string application/epub+zip.
The contents of the mimetype file must not contain any leading padding or whitespace, must not begin with the Unicode signature (or Byte Order Mark), and the case of the MIME type string must be exactly as presented above. The mimetype file additionally must be neither compressed nor encrypted, and there must not be an extra field in its ZIP header.

ほんとうに3要件を満たしているかは、hexdumpしてみれば分かります。

moria:Desktop tac$ hexdump -C De_Suse.epub |head

00000000  50 4b 03 04 0a 00 00 00  00 00 52 bb ac 3e 6f 61  |PK........R..>oa|
00000010  ab 2c 14 00 00 00 14 00  00 00 08 00 00 00 6d 69  |.,............mi|
00000020  6d 65 74 79 70 65 61 70  70 6c 69 63 61 74 69 6f  |metypeapplicatio|
00000030  6e 2f 65 70 75 62 2b 7a  69 70 50 4b 03 04 0a 00  |n/epub+zipPK....|
00000040  00 00 00 00 7d bb ac 3e  00 00 00 00 00 00 00 00  |....}..>........|
00000050  00 00 00 00 09 00 00 00  4d 45 54 41 2d 49 4e 46  |........META-INF|
00000060  2f 50 4b 03 04 14 00 00  00 08 00 52 bb ac 3e c5  |/PK........R..>.|
00000070  06 1a 6f a3 00 00 00 f2  00 00 00 16 00 00 00 4d  |..o............M|
00000080  45 54 41 2d 49 4e 46 2f  63 6f 6e 74 61 69 6e 65  |ETA-INF/containe|
00000090  72 2e 78 6d 6c 55 8e c1  0e c2 20 10 44 ef fd 0a  |r.xmlU.... .D...|


いったん、unzipしたものをMacの普通の“圧縮”でZIPして、拡張子を付け替えたもの(De_Suseフォルダの中身だけをZIPしたもの)だと、

moria:Desktop tac$ hexdump -C De_Suse_MacZIP.epub |head
00000000  50 4b 03 04 0a 00 00 00  00 00 7d bb ac 3e 00 00  |PK........}..>..|
00000010  00 00 00 00 00 00 00 00  00 00 09 00 10 00 4d 45  |..............ME|
00000020  54 41 2d 49 4e 46 2f 55  58 0c 00 cd ef cb 4d 6e  |TA-INF/UX.....Mn|
00000030  ee cb 4d f6 01 f6 01 50  4b 03 04 14 00 08 00 08  |..M....PK.......|
00000040  00 52 bb ac 3e 00 00 00  00 00 00 00 00 00 00 00  |.R..>...........|
00000050  00 16 00 10 00 4d 45 54  41 2d 49 4e 46 2f 63 6f  |.....META-INF/co|
00000060  6e 74 61 69 6e 65 72 2e  78 6d 6c 55 58 0c 00 5e  |ntainer.xmlUX..^|
00000070  05 cc 4d 1c ee cb 4d f6  01 f6 01 55 8e c1 0e c2  |..M...M....U....|
00000080  20 10 44 ef fd 0a c2 d5  b4 e8 95 40 4d 4c 3c 6b  | .D........@ML<k|
00000090  e2 17 ac 74 ab 44 60 09  50 a3 7f 2f d6 a4 b1 7b  |...t.D`.P../...{|


ところが、場合によっては、Macの右クリックによる“圧縮”でつくったZIPファイルの拡張子を「.epub」に書き換えたものでも、Adobe Digital EditionsやSigilはEPUBとして読み出せますし、それをkindlegenで変換したMOBIファイルもKindleで普通に表示できます。
これは上のOCFによる3要件を一つも満たしていないのですが、なぜか大丈夫なのです。