[自炊用]画像からepubを作成します(右→左開き、calibreでの閲覧対応)
AppleScript サンプルコード
行番号 | ソース |
---|---|
001 | #! /usr/bin/env osascript |
002 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
003 | # |
004 | (* |
005 | 自炊用 |
006 | 画像ファイル=各ページ で |
007 | EPUBのコンテンツを生成します |
008 | 前提条件 |
009 | 全部同じ画像サイズであること |
010 | V2 |
011 | ibookでの閲覧に最適化しました |
012 | V3 |
013 | calibreでのエラーに対応しました |
014 | 警告はありますが、閲覧可能です |
015 | |
016 | *) |
017 | #com.cocolog-nifty.quicktimer.icefloe |
018 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
019 | use AppleScript version "2.8" |
020 | use framework "Foundation" |
021 | use framework "AppKit" |
022 | use scripting additions |
023 | property refMe : a reference to current application |
024 | |
025 | |
026 | ############################# |
027 | ### 設定項目 |
028 | ############################# |
029 | |
030 | ###一般的には著者 または 作成者 |
031 | set strAuthor to ("com.cocolog-nifty.quicktimer") as text |
032 | |
033 | ###表紙のラベル (この設定は表紙なしなので設定しなくてもOK) |
034 | set strLabelTitle to ("表紙") as text |
035 | |
036 | ###表紙ページを付与するか trueで表紙ページあり falseで表紙ページなし |
037 | set boolCoverPage to true as boolean |
038 | |
039 | ### 左開き? ltr (left-to-right) 右開き? rtl (right-to-left) |
040 | # set strPageProgression to ("ltr") as text |
041 | set strPageProgression to ("rtl") as text |
042 | |
043 | ###見開き調整 trueで表紙をコンテンツから抜いて1ページずらします |
044 | ##見開きページがズレる場合に true を入れてください |
045 | set boolProgression to false as boolean |
046 | |
047 | |
048 | ############################# |
049 | ### ここから本処理 |
050 | (* |
051 | 大まかな手順 |
052 | 【1】ROOT フォルダ:META-INF OPS ファイル:mimetype |
053 | 【1−2】mimetype |
054 | |
055 | 【2】META-INF ファイル: container.xml com.apple.ibooks.display-options.xml |
056 | 【2−1】container.xml |
057 | 【2−2】com.apple.ibooks.display-options.xml |
058 | |
059 | 【3】OPS |
060 | 【3−1】css book.css |
061 | 【3−2】js book.js |
062 | 【3−3】images |
063 | 【3−4】toc.ncx |
064 | 【3−5】content.opf |
065 | 【3−6】toc.xhtml |
066 | 【3−7】page-XXXX.xhtml |
067 | 【3−8】cover.xhtml |
068 | *) |
069 | ###### |
070 | ##設定項目(詳細) |
071 | ##XMLファイル名の接頭語 |
072 | set strBaseFileName to ("page-") as text |
073 | ##コピー後のファイル名の接頭名 コピー後のファイル名を固定にする事で後処理を少し簡素化 |
074 | set strBaseImageFileName to ("Image_") as text |
075 | |
076 | |
077 | ############################# |
078 | ###ドキュメントのUUID |
079 | set ocidUUID to refMe's NSUUID's alloc()'s init() |
080 | set strUUID to ocidUUID's UUIDString as text |
081 | |
082 | ############################# |
083 | ###ダイアログ |
084 | tell current application |
085 | set strName to name as text |
086 | end tell |
087 | ####スクリプトメニューから実行したら |
088 | if strName is "osascript" then |
089 | tell application "Finder" to activate |
090 | else |
091 | tell current application to activate |
092 | end if |
093 | ############ デフォルトロケーション |
094 | set appFileManager to refMe's NSFileManager's defaultManager() |
095 | set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask)) |
096 | set ocidDesktopDirPathURL to ocidURLsArray's firstObject() |
097 | set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias |
098 | ############UTIリスト |
099 | set listUTI to {"public.image"} |
100 | set strMes to ("画像ファイルを選んでください") as text |
101 | set strPrompt to ("画像ファイルを選んでください") as text |
102 | try |
103 | ### ファイル選択 |
104 | set listAliasFilePath to (choose file strMes with prompt strPrompt default location aliasDefaultLocation of type listUTI with invisibles, multiple selections allowed and showing package contents) as list |
105 | on error |
106 | log "エラーしました" |
107 | return "エラーしました" |
108 | end try |
109 | if listAliasFilePath is {} then |
110 | return "選んでください" |
111 | end if |
112 | |
113 | set aliasFirstFilePath to (item 1 of listAliasFilePath) as alias |
114 | tell application "Finder" |
115 | set aliasContainerDirPath to (container of aliasFirstFilePath) as alias |
116 | set strDocumentTitle to (name of folder aliasContainerDirPath) as text |
117 | end tell |
118 | |
119 | |
120 | ##パス 保存先パス |
121 | set appFileManager to refMe's NSFileManager's defaultManager() |
122 | set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask)) |
123 | ###デスクトップ |
124 | set ocidDesktopDirPathURL to ocidURLsArray's firstObject() |
125 | ###設定項目の名称がフォルダ名 |
126 | set strSetValue to ("MakeEpub/" & strDocumentTitle & "/") as text |
127 | set ocidEpubDirPathURL to ocidDesktopDirPathURL's URLByAppendingPathComponent:(strSetValue) |
128 | set ocidEpubDirPath to ocidEpubDirPathURL's |path|() |
129 | #圧縮用 |
130 | set ocidPushdDirPathURL to ocidEpubDirPathURL's URLByDeletingLastPathComponent() |
131 | set ocidPushdDirPath to ocidPushdDirPathURL's |path|() |
132 | #### |
133 | set strSetValue to ("MakeEpub/" & strDocumentTitle & ".epub") as text |
134 | set ocidEpubFilePathURL to ocidDesktopDirPathURL's URLByAppendingPathComponent:(strSetValue) |
135 | set ocidEpubFilePath to ocidEpubDirPathURL's |path|() |
136 | ############################## |
137 | ## 選択画像リストをファイル名順に並び替える |
138 | |
139 | set ocidImageFilePathArrayM to refMe's NSMutableArray's alloc()'s initWithCapacity:(0) |
140 | repeat with itemArray in listAliasFilePath |
141 | set aliasFilePath to itemArray as alias |
142 | set strFilePath to (POSIX path of aliasFilePath) as text |
143 | set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePath)) |
144 | set ocidFilePath to ocidFilePathStr's stringByStandardizingPath() |
145 | set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false) |
146 | (ocidImageFilePathArrayM's addObject:(ocidFilePathURL)) |
147 | end repeat |
148 | |
149 | set ocidSortDescriptor to (refMe's NSSortDescriptor's sortDescriptorWithKey:"absoluteString" ascending:(true) selector:"localizedStandardCompare:") |
150 | set ocidDescriptorArray to refMe's NSArray's arrayWithObject:(ocidSortDescriptor) |
151 | set ocidSortedArrayM to ocidImageFilePathArrayM's sortedArrayUsingDescriptors:(ocidDescriptorArray) |
152 | |
153 | ############################## |
154 | ##必要なフォルダを作る |
155 | set appFileManager to refMe's NSFileManager's defaultManager() |
156 | set ocidAttrDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0) |
157 | ##アクセス権755この値は後でも使う |
158 | (ocidAttrDict's setValue:(493) forKey:(refMe's NSFilePosixPermissions)) |
159 | ##フォルダのパスのリスト |
160 | set listDirName to {"OPS", "OPS/css", "OPS/images", "OPS/js", "META-INF"} as list |
161 | ##stringsByAppendingPathsでARRAYにする |
162 | set ocidSubPathArray to ocidEpubDirPath's stringsByAppendingPaths:(listDirName) |
163 | ##ARRAYの分だけ |
164 | repeat with itemSubPathArray in ocidSubPathArray |
165 | ##フォルダを作る |
166 | set listBoolMakeDir to (appFileManager's createDirectoryAtPath:(itemSubPathArray) withIntermediateDirectories:true attributes:(ocidAttrDict) |error| :(reference)) |
167 | end repeat |
168 | ################################################################################# |
169 | ### 【1】ROOT フォルダ:META-INF OPS ファイル:mimetype |
170 | set ocidEpubDirPathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidEpubDirPath) isDirectory:true) |
171 | ### 【1−2】mimetype |
172 | ##保存先パス |
173 | set ocidMimetypeFilePathURL to ocidEpubDirPathURL's URLByAppendingPathComponent:("mimetype") isDirectory:false |
174 | ##内容 |
175 | set strMimetype to ("application/epub+zip") as text |
176 | set ocidMimetype to refMe's NSString's stringWithString:(strMimetype) |
177 | ##ファイルに保存して |
178 | set listDone to ocidMimetype's writeToURL:(ocidMimetypeFilePathURL) atomically:true encoding:(refMe's NSUTF8StringEncoding) |error| :(reference) |
179 | ##アクセス権755を指定する |
180 | set listDone to appFileManager's setAttributes:(ocidAttrDict) ofItemAtPath:(ocidMimetypeFilePathURL's |path|) |error| :(reference) |
181 | ################################################################################# |
182 | ### 【3】OPS |
183 | set ocidOPSDirPathURL to ocidEpubDirPathURL's URLByAppendingPathComponent:("OPS") isDirectory:true |
184 | ######◆ 【3−1】css book.css |
185 | ##フォルダのパス |
186 | set ocidCssDirPathURL to ocidOPSDirPathURL's URLByAppendingPathComponent:("css") isDirectory:true |
187 | ###ファイルのパス |
188 | set ocidCssFilePathURL to ocidCssDirPathURL's URLByAppendingPathComponent:("book.css") isDirectory:false |
189 | ##ファイルの中身 |
190 | set strCssContents to ("hrml{margin: 0;padding: 0;border: 0;display: flex;justify-content: center;align-items: center;}body {margin: 0;padding: 0;border: 0;display: flex;justify-content: center;align-items: center;}div {display: flex;justify-content: center;align-items: center;height: 100%;}img {height: 100vh;width: auto;}") as text |
191 | set ocidCssContents to refMe's NSString's stringWithString:(strCssContents) |
192 | ##保存 |
193 | set listDone to ocidCssContents's writeToURL:(ocidCssFilePathURL) atomically:true encoding:(refMe's NSUTF8StringEncoding) |error| :(reference) |
194 | ##アクセス権 |
195 | set listDone to appFileManager's setAttributes:(ocidAttrDict) ofItemAtPath:(ocidCssFilePathURL's |path|) |error| :(reference) |
196 | ######◆ 【3−2】js book.js |
197 | ##フォルダのパス |
198 | #set ocidJsDirPathURL to ocidOPSDirPathURL's URLByAppendingPathComponent:("js") isDirectory:true |
199 | ###ファイルのパス |
200 | #set ocidJsFilePathURL to ocidJsDirPathURL's URLByAppendingPathComponent:("book.js") isDirectory:false |
201 | ##ファイルの中身 |
202 | #set strJsContents to ("function Body_onLoad() {};") as text |
203 | #set strJsContents to doGetJs() as text |
204 | #set ocidJsContents to refMe's NSString's stringWithString:(strJsContents) |
205 | ##保存 |
206 | #set listDone to ocidJsContents's writeToURL:(ocidJsFilePathURL) atomically:true encoding:(refMe's NSUTF8StringEncoding) |error| :(reference) |
207 | ##アクセス権 |
208 | #set listDone to appFileManager's setAttributes:(ocidAttrDict) ofItemAtPath:(ocidJsFilePathURL's |path|) |error| :(reference) |
209 | ######◆ 【3−3】images イメージファイルをコピーします |
210 | set ocidImagesDirPathURL to ocidOPSDirPathURL's URLByAppendingPathComponent:("images") isDirectory:true |
211 | |
212 | set numCntPage to 1 as integer |
213 | set numCntAllImage to (count of listAliasFilePath) as integer |
214 | set listImageFileName to {} as list |
215 | ##画像ファイルの数だけ繰り返し |
216 | repeat with itemArray in ocidSortedArrayM |
217 | ##パス |
218 | # set aliasFilePath to itemAliasFilePath as alias |
219 | # set strFilePath to (POSIX path of aliasFilePath) as text |
220 | # set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePath)) |
221 | # set ocidFilePath to ocidFilePathStr's stringByStandardizingPath() |
222 | # set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false) |
223 | set ocidFilePathURL to itemArray |
224 | ##拡張子 |
225 | set ocidExtensionName to ocidFilePathURL's pathExtension() |
226 | ###コピー後の画像ファイルは連番処理 四桁のゼロパディング |
227 | set strZeroSup to "0000" as text |
228 | set strSeroSup to (strZeroSup & (numCntPage as text)) as text |
229 | set strSeroSup to (text -4 through -1 of strSeroSup) as text |
230 | set strFileName to (strBaseImageFileName & strSeroSup) as text |
231 | ##コピー先URL |
232 | set ocidBaseFilePathURL to (ocidImagesDirPathURL's URLByAppendingPathComponent:(strFileName)) |
233 | set ocidSaveFilePathURL to (ocidBaseFilePathURL's URLByAppendingPathExtension:(ocidExtensionName)) |
234 | ##ファイル名のリストを作っておく |
235 | set ocidImageFileName to ocidSaveFilePathURL's lastPathComponent() |
236 | set strImageFileName to ocidImageFileName as text |
237 | set end of listImageFileName to strImageFileName |
238 | ###コピー |
239 | set appFileManager to refMe's NSFileManager's defaultManager() |
240 | set listDone to (appFileManager's copyItemAtURL:(ocidFilePathURL) toURL:(ocidSaveFilePathURL) |error| :(reference)) |
241 | ##カウントアップ |
242 | set numCntPage to numCntPage + 1 as integer |
243 | end repeat |
244 | |
245 | |
246 | ################################# |
247 | ###◆ 【3−7】page-XXXX.xhtml |
248 | ##配置オブジェクトが画像1つ限定なのでシンプルな構造 |
249 | ##【3−7−A】 root エレメント 【3−7−B】 head エレメント 【3−7−C】 body エレメント |
250 | ##カウンター |
251 | set numCntPage to 1 as integer |
252 | ##総画像ファイルする右=ページ数 |
253 | set numCntAllImage to (count of ocidSortedArrayM) as integer |
254 | ##画像の数だけ繰り返し |
255 | repeat numCntAllImage times |
256 | ###ファイルは連番処理 四桁のゼロパディング |
257 | set strZeroSup to "0000" as text |
258 | set strSeroSup to (strZeroSup & (numCntPage as text)) as text |
259 | set strSeroSup to (text -4 through -1 of strSeroSup) as text |
260 | set strFileName to (strBaseFileName & strSeroSup & ".xhtml") as text |
261 | ##XHTMLのパス |
262 | set ocidXHTMLFilePathURL to ocidOPSDirPathURL's URLByAppendingPathComponent:(strFileName) isDirectory:false |
263 | ##配置画像 |
264 | ##不具合の元かもしれないが拡張子判定する方法が見つからなかった |
265 | set strImageName to (item numCntPage of listImageFileName) |
266 | set ocidImagesFilePathURL to ocidImagesDirPathURL's URLByAppendingPathComponent:(strImageName) isDirectory:false |
267 | set ocidReadImage to (refMe's NSImage's alloc()'s initWithContentsOfURL:(ocidFilePathURL)) |
268 | ##BitMapRepに変換 |
269 | set ocidReadImageRepArray to ocidReadImage's representations() |
270 | set ocidReadImageRep to (ocidReadImageRepArray's objectAtIndex:0) |
271 | ##ピクセルサイズ取得 |
272 | set strPixelsWidth to (ocidReadImageRep's pixelsWide()) as text |
273 | set strPixelsHeight to (ocidReadImageRep's pixelsHigh()) as text |
274 | ######## |
275 | ##◆【3−7−A】 root エレメント |
276 | set ocidRootElement to refMe's NSXMLElement's alloc()'s initWithName:"html" |
277 | ocidRootElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("xml:lang") stringValue:("ja")) |
278 | ocidRootElement's addNamespace:(refMe's NSXMLNode's namespaceWithName:("") stringValue:("http://www.w3.org/1999/xhtml")) |
279 | ######## |
280 | ##◆【3−7−B】 head エレメント |
281 | set ocidHeadElement to refMe's NSXMLElement's alloc()'s initWithName:("head") |
282 | #CSS |
283 | set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("link") |
284 | ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("rel") stringValue:("stylesheet")) |
285 | ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("href") stringValue:("css/book.css")) |
286 | ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("type") stringValue:("text/css")) |
287 | ocidHeadElement's addChild:(ocidMetaElement) |
288 | #JS |
289 | # set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("script") |
290 | # ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("src") stringValue:("js/book.js")) |
291 | # ocidHeadElement's addChild:(ocidMetaElement) |
292 | #文字コード |
293 | set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("meta") |
294 | ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("charset") stringValue:("UTF-8")) |
295 | ocidHeadElement's addChild:(ocidMetaElement) |
296 | #タイトル |
297 | set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("title") |
298 | set strPageTitle to ("Page : " & strSeroSup) as text |
299 | ocidMetaElement's setStringValue:(strPageTitle) |
300 | ocidHeadElement's addChild:(ocidMetaElement) |
301 | #EPUBドキュメントのUUID |
302 | set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("meta") |
303 | ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("name") stringValue:("EPB-UUID")) |
304 | ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("content") stringValue:(strUUID)) |
305 | ocidHeadElement's addChild:(ocidMetaElement) |
306 | #ビューポイント ここで画像のサイズ指定=全画面 |
307 | set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("meta") |
308 | ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("name") stringValue:("viewport")) |
309 | ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("content") stringValue:("width=" & strPixelsWidth & ",height=" & strPixelsHeight & ", initial-scale=1.0")) |
310 | # ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("content") stringValue:("width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no")) |
311 | ocidHeadElement's addChild:(ocidMetaElement) |
312 | ######## |
313 | ##◆【3−7−C】 body エレメント |
314 | set ocidBodyElement to refMe's NSXMLElement's alloc()'s initWithName:("body") |
315 | # ocidBodyElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("onload") stringValue:("Body_onLoad()")) |
316 | #開き方向指定 |
317 | ocidBodyElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("dir") stringValue:(strPageProgression)) |
318 | #一番外側のDIV要素 |
319 | set ocidOutDiivElement to refMe's NSXMLElement's alloc()'s initWithName:("div") |
320 | #ocidOutDiivElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("style") #stringValue:("position:absolute;left:0;top:0;width: " & strPixelsWidth & "px;height:" & strPixelsHeight & "px;")) |
321 | #imgタグ |
322 | set ocidImgElement to refMe's NSXMLElement's alloc()'s initWithName:("img") |
323 | set strPath to ("images/" & strImageName) as text |
324 | ocidImgElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("src") stringValue:(strPath)) |
325 | ocidImgElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("alt") stringValue:(strFileName)) |
326 | # ocidImgElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("style") stringValue:("object-fit: cover;width: " & strPixelsWidth & "px;height:" & strPixelsHeight & "px;")) |
327 | #imgタグをDIVにセット |
328 | ocidOutDiivElement's addChild:(ocidImgElement) |
329 | #DIVをbodyにセット |
330 | ocidBodyElement's addChild:(ocidOutDiivElement) |
331 | ######## |
332 | ##【3−7−B】のheadエレメントをAのROOTにセット |
333 | ocidRootElement's addChild:(ocidHeadElement) |
334 | ##【3−7−C】 bodyエレメントをAのROOTにセット |
335 | ocidRootElement's addChild:(ocidBodyElement) |
336 | ## ↑からのROOTエレメントをセットしてXMLとする |
337 | set ocidOutPutXML to refMe's NSXMLDocument's alloc()'s initWithRootElement:(ocidRootElement) |
338 | ocidOutPutXML's setVersion:"1.0" |
339 | ocidOutPutXML's setCharacterEncoding:"UTF-8" |
340 | #XMLをテキストにして |
341 | set ocidSaveStrings to ocidOutPutXML's XMLString() |
342 | ###改行コードを指定して |
343 | ocidSaveStrings's appendString:"\n" |
344 | ##保存 |
345 | set listWritetoUrlArray to ocidSaveStrings's writeToURL:(ocidXHTMLFilePathURL) atomically:true encoding:(refMe's NSUTF8StringEncoding) |error| :(reference) |
346 | ## |
347 | set numCntPage to numCntPage + 1 as integer |
348 | end repeat |
349 | |
350 | ################################# |
351 | ###◆【3−8】cover.xhtml いわゆる表紙ページ |
352 | # cover-page と cover-imageがあるがここではcover-pageを生成する |
353 | #保存パス |
354 | set ocidXHTMLFilePathURL to ocidOPSDirPathURL's URLByAppendingPathComponent:("cover.xhtml") isDirectory:false |
355 | # 表紙イメージ=1ページ目の画像 |
356 | set aliasCoverImageFilePath to (item 1 of listAliasFilePath) as alias |
357 | set strCoverImageFilePath to (POSIX path of aliasCoverImageFilePath) as text |
358 | set ocidCoverImageFilePathStr to refMe's NSString's stringWithString:(strCoverImageFilePath) |
359 | set ocidCoverImageFilePath to ocidCoverImageFilePathStr's stringByStandardizingPath() |
360 | set ocidCoverImageFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidCoverImageFilePath) isDirectory:false) |
361 | set strExtensionName to (ocidCoverImageFilePathURL's pathExtension()) as text |
362 | ### |
363 | set ocidReadImage to (refMe's NSImage's alloc()'s initWithContentsOfURL:(ocidCoverImageFilePathURL)) |
364 | ##BitMapRepに変換 |
365 | set ocidReadImageRepArray to ocidReadImage's representations() |
366 | set ocidReadImageRep to (ocidReadImageRepArray's objectAtIndex:0) |
367 | ##ピクセルサイズ取得 |
368 | set strPixelsWidth to (ocidReadImageRep's pixelsWide()) as text |
369 | set strPixelsHeight to (ocidReadImageRep's pixelsHigh()) as text |
370 | #######【3−8-A】ルートエレメント XHTMLのルートエレメント |
371 | set ocidRootElement to refMe's NSXMLElement's alloc()'s initWithName:"html" |
372 | #ネームスペースの追加 |
373 | ocidRootElement's addNamespace:(refMe's NSXMLNode's namespaceWithName:("") stringValue:("http://www.w3.org/1999/xhtml")) |
374 | ocidRootElement's addNamespace:(refMe's NSXMLNode's namespaceWithName:("epub") stringValue:("http://www.idpf.org/2007/ops")) |
375 | #アトリビュートの追加 |
376 | ocidRootElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("xml:lang") stringValue:("ja")) |
377 | ocidRootElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("epub:prefix") stringValue:("ibooks: http://vocabulary.itunes.apple.com/rdf/ibooks/vocabulary-extensions-1.0/")) |
378 | #####【3−6-B】 headエレメント |
379 | set ocidHeadElement to refMe's NSXMLElement's alloc()'s initWithName:("head") |
380 | #タイトル |
381 | set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("title") |
382 | ocidMetaElement's setStringValue:("表紙:Cover Page") |
383 | ocidHeadElement's addChild:(ocidMetaElement) |
384 | #スタイルシートへのリンク |
385 | set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("link") |
386 | ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("rel") stringValue:("stylesheet")) |
387 | ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("href") stringValue:("css/book.css")) |
388 | ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("type") stringValue:("text/css")) |
389 | ocidHeadElement's addChild:(ocidMetaElement) |
390 | #Jsへのリンク |
391 | #set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("script") |
392 | #ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("src") stringValue:("js/book.js")) |
393 | #ocidHeadElement's addChild:(ocidMetaElement) |
394 | #文字コード宣言 |
395 | set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("meta") |
396 | ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("charset") stringValue:("UTF-8")) |
397 | ocidHeadElement's addChild:(ocidMetaElement) |
398 | #UUID設定 |
399 | set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("meta") |
400 | ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("name") stringValue:("EPB-UUID")) |
401 | ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("content") stringValue:(strUUID)) |
402 | ocidHeadElement's addChild:(ocidMetaElement) |
403 | #ビューポイント |
404 | set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("meta") |
405 | ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("name") stringValue:("viewport")) |
406 | #ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("content") stringValue:("width=" & strPixelsWidth & ",height=" & strPixelsHeight & ", initial-scale=1.0")) |
407 | ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("content") stringValue:("width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no")) |
408 | ocidHeadElement's addChild:(ocidMetaElement) |
409 | ######【3−8-C】ボディエレメント |
410 | set ocidBodyElement to refMe's NSXMLElement's alloc()'s initWithName:("body") |
411 | #ocidBodyElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("onload") stringValue:("Body_onLoad()")) |
412 | #開き方向 |
413 | ocidBodyElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("dir") stringValue:(strPageProgression)) |
414 | # |
415 | set ocidOutDiivElement to refMe's NSXMLElement's alloc()'s initWithName:("div") |
416 | #ocidOutDiivElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("style") stringValue:("position:absolute;left:0;top:0;width: " & strPixelsWidth & "px;height:" & strPixelsHeight & "px;")) |
417 | ## |
418 | set ocidImgElement to refMe's NSXMLElement's alloc()'s initWithName:("img") |
419 | set strImageName to (strBaseImageFileName & "0001." & strExtensionName) as text |
420 | set strPath to ("images/" & strImageName) as text |
421 | ocidImgElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("src") stringValue:(strPath)) |
422 | ocidImgElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("alt") stringValue:(strFileName)) |
423 | #ocidImgElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("style") stringValue:("object-fit: cover;width: " & strPixelsWidth & "px;height:" & strPixelsHeight & "px;")) |
424 | ocidOutDiivElement's addChild:(ocidImgElement) |
425 | ocidBodyElement's addChild:(ocidOutDiivElement) |
426 | #### |
427 | #【3−8-B】 head を【3−8-A】 ルートエレメントに追加 |
428 | ocidRootElement's addChild:(ocidHeadElement) |
429 | #【3−8-C】 body を【3−8-A】ルートエレメントに追加 |
430 | ocidRootElement's addChild:(ocidBodyElement) |
431 | ## ↑からのROOTエレメントをセットしてXMLとする |
432 | set ocidOutPutXML to refMe's NSXMLDocument's alloc()'s initWithRootElement:(ocidRootElement) |
433 | ocidOutPutXML's setVersion:"1.0" |
434 | ocidOutPutXML's setCharacterEncoding:"UTF-8" |
435 | ###テキストにして |
436 | set ocidSaveStrings to ocidOutPutXML's XMLString() |
437 | ###改行コードを指定して |
438 | ocidSaveStrings's appendString:"\n" |
439 | ##保存 |
440 | set listDone to ocidSaveStrings's writeToURL:(ocidXHTMLFilePathURL) atomically:true encoding:(refMe's NSUTF8StringEncoding) |error| :(reference) |
441 | ################################# |
442 | ###◆ 【3−6】toc.xhtml いわゆる目次 |
443 | #【3−6-B】 head 【3−6-C】 body |
444 | #保存パス |
445 | set ocidXHTMLFilePathURL to ocidOPSDirPathURL's URLByAppendingPathComponent:("toc.xhtml") isDirectory:false |
446 | set ocidNavPathURL to ocidEpubDirPathURL's URLByAppendingPathComponent:("nav.xhtml") isDirectory:false |
447 | |
448 | #【3−6-A】ルートエレメント XHTMLのルートエレメント |
449 | set ocidRootElement to refMe's NSXMLElement's alloc()'s initWithName:"html" |
450 | #ネームスペースの追加 |
451 | ocidRootElement's addNamespace:(refMe's NSXMLNode's namespaceWithName:("") stringValue:("http://www.w3.org/1999/xhtml")) |
452 | ocidRootElement's addNamespace:(refMe's NSXMLNode's namespaceWithName:("epub") stringValue:("http://www.idpf.org/2007/ops")) |
453 | #アトリビュートの追加 |
454 | ocidRootElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("xml:lang") stringValue:("ja")) |
455 | ocidRootElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("epub:prefix") stringValue:("ibooks: http://vocabulary.itunes.apple.com/rdf/ibooks/vocabulary-extensions-1.0/")) |
456 | #####【3−6-B】 headエレメント |
457 | set ocidHeadElement to refMe's NSXMLElement's alloc()'s initWithName:("head") |
458 | #タイトル |
459 | set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("title") |
460 | ocidMetaElement's setStringValue:("目次:Table of Contents") |
461 | ocidHeadElement's addChild:(ocidMetaElement) |
462 | #スタイルシートへのリンク |
463 | set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("link") |
464 | ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("rel") stringValue:("stylesheet")) |
465 | ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("href") stringValue:("css/book.css")) |
466 | ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("type") stringValue:("text/css")) |
467 | ocidHeadElement's addChild:(ocidMetaElement) |
468 | #文字コード宣言 |
469 | set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("meta") |
470 | ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("charset") stringValue:("UTF-8")) |
471 | ocidHeadElement's addChild:(ocidMetaElement) |
472 | #UUID設定 |
473 | set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("meta") |
474 | ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("name") stringValue:("EPB-UUID")) |
475 | ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("content") stringValue:(strUUID)) |
476 | ocidHeadElement's addChild:(ocidMetaElement) |
477 | #ビューポイント |
478 | set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("meta") |
479 | ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("name") stringValue:("viewport")) |
480 | #ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("content") stringValue:("width=" & strPixelsWidth & ",height=" & strPixelsHeight & ", initial-scale=1.0")) |
481 | ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("content") stringValue:("width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no")) |
482 | ocidHeadElement's addChild:(ocidMetaElement) |
483 | ####【3−6-C】 body |
484 | set ocidBodyElement to refMe's NSXMLElement's alloc()'s initWithName:("body") |
485 | #bodyエレメントに開き方向のアトリビュート |
486 | ocidBodyElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("dir") stringValue:(strPageProgression)) |
487 | #タイトルをH1で入れて |
488 | set ocidBodyItem to refMe's NSXMLElement's alloc()'s initWithName:("h1") |
489 | ocidBodyItem's setStringValue:(strDocumentTitle) |
490 | ocidBodyElement's addChild:(ocidBodyItem) |
491 | #区切り線 |
492 | set ocidBodyItem to refMe's NSXMLElement's alloc()'s initWithName:("hr") |
493 | ocidBodyElement's addChild:(ocidBodyItem) |
494 | #メインの要素 |
495 | set ocidBodyItem to refMe's NSXMLElement's alloc()'s initWithName:("div") |
496 | ocidBodyItem's addAttribute:(refMe's NSXMLNode's attributeWithName:("class") stringValue:("nav-body")) |
497 | ocidBodyElement's addChild:(ocidBodyItem) |
498 | #ナビ |
499 | set ocidNavItem to refMe's NSXMLElement's alloc()'s initWithName:("nav") |
500 | ocidNavItem's addAttribute:(refMe's NSXMLNode's attributeWithName:("epub:type") stringValue:("toc")) |
501 | ocidNavItem's addAttribute:(refMe's NSXMLNode's attributeWithName:("id") stringValue:("toc")) |
502 | #リスト |
503 | set ocidNavOL to refMe's NSXMLElement's alloc()'s initWithName:("ol") |
504 | #番号初期化 |
505 | set numCntPage to 1 as integer |
506 | #総ページ数の数だけ繰り返し |
507 | repeat numCntAllImage times |
508 | ###画像ファイルは連番処理 四桁のゼロパディング |
509 | set strZeroSup to "0000" as text |
510 | set strSeroSup to (strZeroSup & (numCntPage as text)) as text |
511 | set strSeroSup to (text -4 through -1 of strSeroSup) as text |
512 | set strLinkFileName to (strBaseFileName & strSeroSup) as text |
513 | set strFileName to (strBaseFileName & strSeroSup & ".xhtml") as text |
514 | #### |
515 | set ocidNavLI to refMe's NSXMLElement's alloc()'s initWithName:("li") |
516 | set ocidNavA to refMe's NSXMLElement's alloc()'s initWithName:("a") |
517 | ocidNavA's addAttribute:(refMe's NSXMLNode's attributeWithName:("href") stringValue:(strFileName)) |
518 | ocidNavA's setStringValue:(strLinkFileName) |
519 | ocidNavLI's addChild:(ocidNavA) |
520 | ocidNavOL's addChild:(ocidNavLI) |
521 | set numCntPage to numCntPage + 1 as integer |
522 | end repeat |
523 | ##リストに表紙ページを追加 |
524 | set ocidNavLI to refMe's NSXMLElement's alloc()'s initWithName:("li") |
525 | set ocidNavA to refMe's NSXMLElement's alloc()'s initWithName:("a") |
526 | ocidNavA's addAttribute:(refMe's NSXMLNode's attributeWithName:("href") stringValue:("cover.xhtml")) |
527 | ocidNavA's addAttribute:(refMe's NSXMLNode's attributeWithName:("epub:type") stringValue:("ibooks:reader-start-page")) |
528 | ocidNavA's setStringValue:("Cover Page") |
529 | ocidNavLI's addChild:(ocidNavA) |
530 | ocidNavOL's addChild:(ocidNavLI) |
531 | #リストに目次を追加 |
532 | set ocidNavLI to refMe's NSXMLElement's alloc()'s initWithName:("li") |
533 | set ocidNavA to refMe's NSXMLElement's alloc()'s initWithName:("a") |
534 | ocidNavA's addAttribute:(refMe's NSXMLNode's attributeWithName:("href") stringValue:("toc.xhtml")) |
535 | ocidNavA's addAttribute:(refMe's NSXMLNode's attributeWithName:("epub:type") stringValue:("toc")) |
536 | ocidNavA's setStringValue:("Table of Contents") |
537 | ocidNavLI's addChild:(ocidNavA) |
538 | ocidNavOL's addChild:(ocidNavLI) |
539 | #出来上がったリストをbodyに追加 |
540 | ocidNavItem's addChild:(ocidNavOL) |
541 | ocidBodyItem's addChild:(ocidNavItem) |
542 | #### |
543 | #【3−6-B】 head を【3−6-A】 ルートエレメントに追加 |
544 | ocidRootElement's addChild:(ocidHeadElement) |
545 | #【3−6-C】 body を【3−6-A】ルートエレメントに追加 |
546 | ocidRootElement's addChild:(ocidBodyElement) |
547 | ## ↑からのROOTエレメントをセットしてXMLとする |
548 | set ocidOutPutXML to refMe's NSXMLDocument's alloc()'s initWithRootElement:(ocidRootElement) |
549 | ocidOutPutXML's setVersion:"1.0" |
550 | ocidOutPutXML's setCharacterEncoding:"UTF-8" |
551 | ###テキストにして |
552 | set ocidSaveStrings to ocidOutPutXML's XMLString() |
553 | ###改行コードを指定して |
554 | ocidSaveStrings's appendString:"\n" |
555 | ##保存 |
556 | set listDone to ocidSaveStrings's writeToURL:(ocidXHTMLFilePathURL) atomically:true encoding:(refMe's NSUTF8StringEncoding) |error| :(reference) |
557 | set listDone to ocidSaveStrings's writeToURL:(ocidNavPathURL) atomically:true encoding:(refMe's NSUTF8StringEncoding) |error| :(reference) |
558 | |
559 | |
560 | |
561 | ############################################# |
562 | ###◆【3−5】content.opf |
563 | ##【B】メタ情報のheadからなる 【C】各種コンテンツへのパス manifest と 【D】コンテンツの配置 spine 【E】ガイドguide |
564 | ##Pageの場合 |
565 | ## set ocidOptFilePathURL to ocidOPSDirPathURL's URLByAppendingPathComponent:("epb.opf") isDirectory:false |
566 | ##一般的な命名 |
567 | set ocidOptFilePathURL to ocidOPSDirPathURL's URLByAppendingPathComponent:("content.opf") isDirectory:false |
568 | ##【A】ルートエレメント |
569 | set ocidRootElement to refMe's NSXMLElement's alloc()'s initWithName:"package" |
570 | #アトリビュートを追加 |
571 | ocidRootElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("version") stringValue:("3.0")) |
572 | ocidRootElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("unique-identifier") stringValue:("BookId")) |
573 | ocidRootElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("prefix") stringValue:("ibooks: http://vocabulary.itunes.apple.com/rdf/ibooks/vocabulary-extensions-1.0/ rendition: http://www.idpf.org/vocab/rendition/#")) |
574 | #ネームスペースを追加 |
575 | ocidRootElement's addNamespace:(refMe's NSXMLNode's namespaceWithName:("") stringValue:("http://www.idpf.org/2007/opf")) |
576 | ocidRootElement's addNamespace:(refMe's NSXMLNode's namespaceWithName:("ibooks") stringValue:("http://vocabulary.itunes.apple.com/rdf/ibooks/vocabulary-extensions-1.0/")) |
577 | ################## |
578 | #【B】メタ情報のhead |
579 | set ocidMetaDataElement to refMe's NSXMLElement's alloc()'s initWithName:("metadata") |
580 | ocidMetaDataElement's addNamespace:(refMe's NSXMLNode's namespaceWithName:("dc") stringValue:("http://purl.org/dc/elements/1.1/")) |
581 | ocidMetaDataElement's addNamespace:(refMe's NSXMLNode's namespaceWithName:("opf") stringValue:("http://www.idpf.org/2007/opf")) |
582 | #◆【B-1】タイトル |
583 | set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("dc:title") |
584 | ocidMetaElement's setStringValue:(strDocumentTitle) |
585 | ocidMetaDataElement's addChild:(ocidMetaElement) |
586 | #◆【B-2】作成者 著者 |
587 | set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("dc:creator") |
588 | ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("id") stringValue:("creator")) |
589 | ocidMetaElement's setStringValue:(strAuthor) |
590 | ocidMetaDataElement's addChild:(ocidMetaElement) |
591 | #◆【B-3】UUID |
592 | set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("dc:identifier") |
593 | ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("id") stringValue:("BookId")) |
594 | ocidMetaElement's setStringValue:(strUUID) |
595 | ocidMetaDataElement's addChild:(ocidMetaElement) |
596 | #◆【B-4】言語 |
597 | set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("dc:language") |
598 | ocidMetaElement's setStringValue:("ja") |
599 | ocidMetaDataElement's addChild:(ocidMetaElement) |
600 | #◆【B-5】作成日 |
601 | set strSetDate to doGetDateNo("yyyy-MM-dd") as text |
602 | set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("dc:date") |
603 | ocidMetaElement's setStringValue:(strSetDate) |
604 | ocidMetaDataElement's addChild:(ocidMetaElement) |
605 | #◆【B-6】修正日 |
606 | set strSetDate to doGetDateNo("yyyy-MM-dd'T'HH:mm:ss'Z'") as text |
607 | set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("dc:modified") |
608 | ocidMetaElement's setStringValue:(strSetDate) |
609 | ocidMetaDataElement's addChild:(ocidMetaElement) |
610 | #◆【B-7】コンテンツのプロパティ レイアウト |
611 | set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("meta") |
612 | ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("property") stringValue:("rendition:layout")) |
613 | ##リフロータイプのレイアウト 柔軟な表示形式 文字中心なものに最適 |
614 | # ocidMetaElement's setStringValue:("reflowable") |
615 | ##固定型のレイアウト 画面サイズに依存しない表示 画面のレイアウトを優先したい場合 |
616 | # ocidMetaElement's setStringValue:("fixed") |
617 | ##事前にページ化されたレイアウト ページベースの表示形式 画像コンテンツに最適 |
618 | ocidMetaElement's setStringValue:("pre-paginated") |
619 | ocidMetaDataElement's addChild:(ocidMetaElement) |
620 | #◆【B-8】コンテンツのプロパティ スプレッド 開き方 |
621 | set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("meta") |
622 | ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("property") stringValue:("rendition:spread")) |
623 | ##デバイスの向きに依存しない |
624 | ocidMetaElement's setStringValue:("both") |
625 | ##横 |
626 | #ocidMetaElement's setStringValue:("landscape") |
627 | ##縦 非推奨 |
628 | #ocidMetaElement's setStringValue:("portrait") |
629 | ##単ページ |
630 | ##ocidMetaElement's setStringValue:("none") |
631 | ##自動 |
632 | ##ocidMetaElement's setStringValue:("auto") |
633 | ocidMetaDataElement's addChild:(ocidMetaElement) |
634 | #◆【B-9】向き |
635 | set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("meta") |
636 | ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("property") stringValue:("rendition:orientation")) |
637 | #自動 |
638 | ocidMetaElement's setStringValue:("auto") |
639 | ##横 |
640 | #ocidMetaElement's setStringValue:("landscape") |
641 | ##縦 |
642 | #ocidMetaElement's setStringValue:("portrait") |
643 | ocidMetaDataElement's addChild:(ocidMetaElement) |
644 | ##表紙の有無での分岐 |
645 | if boolCoverPage is true then |
646 | set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("meta") |
647 | ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("name") stringValue:("cover")) |
648 | ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("content") stringValue:("cover-image")) |
649 | ocidMetaDataElement's addChild:(ocidMetaElement) |
650 | end if |
651 | |
652 | ################## |
653 | ### 【C】各種コンテンツへのパス manifest |
654 | ##manifestのROOTエレメント |
655 | set ocidManifestElement to refMe's NSXMLElement's alloc()'s initWithName:("manifest") |
656 | #CSS追加 |
657 | set ocidItemElement to refMe's NSXMLElement's alloc()'s initWithName:("item") |
658 | ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("id") stringValue:("stylesheet")) |
659 | ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("href") stringValue:("css/book.css")) |
660 | ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("media-type") stringValue:("text/css")) |
661 | ocidManifestElement's addChild:(ocidItemElement) |
662 | #JS追加 |
663 | #set ocidItemElement to refMe's NSXMLElement's alloc()'s initWithName:("item") |
664 | #ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("id") stringValue:("javascript")) |
665 | #ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("href") stringValue:("js/book.js")) |
666 | #ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("media-type") stringValue:("text/javascript")) |
667 | #ocidManifestElement's addChild:(ocidItemElement) |
668 | #NCX追加 |
669 | set ocidItemElement to refMe's NSXMLElement's alloc()'s initWithName:("item") |
670 | ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("id") stringValue:("ncx")) |
671 | ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("href") stringValue:("toc.ncx")) |
672 | ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("media-type") stringValue:("application/xhtml+xml")) |
673 | ocidManifestElement's addChild:(ocidItemElement) |
674 | #目次追加 |
675 | set ocidItemElement to refMe's NSXMLElement's alloc()'s initWithName:("item") |
676 | ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("id") stringValue:("toc")) |
677 | ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("href") stringValue:("toc.xhtml")) |
678 | ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("media-type") stringValue:("application/xhtml+xml")) |
679 | ocidManifestElement's addChild:(ocidItemElement) |
680 | ##表紙 表示画像 |
681 | if boolCoverPage is true then |
682 | ##表紙ページ設定 |
683 | set ocidItemElement to refMe's NSXMLElement's alloc()'s initWithName:("item") |
684 | ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("id") stringValue:("cover")) |
685 | ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("href") stringValue:("cover.xhtml")) |
686 | ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("media-type") stringValue:("application/xhtml+xml")) |
687 | ocidManifestElement's addChild:(ocidItemElement) |
688 | ##表紙画像 |
689 | set ocidExtensionName to ocidCoverImageFilePathURL's pathExtension() |
690 | ####拡張子からUTI取得 |
691 | set ocidUTType to (refMe's UTType's typeWithFilenameExtension:(ocidExtensionName)) |
692 | set ocidFileMimeType to ocidUTType's preferredMIMEType() |
693 | ##MimeTypeを取得してから |
694 | set strFileMimeType to ocidFileMimeType as text |
695 | #設定 |
696 | set strCoverImageFileName to (strBaseImageFileName & "0001." & (ocidExtensionName as text)) as text |
697 | set strHref to ("images/" & strCoverImageFileName) as text |
698 | set ocidItemElement to refMe's NSXMLElement's alloc()'s initWithName:("item") |
699 | ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("id") stringValue:("cover-image")) |
700 | ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("href") stringValue:(strHref)) |
701 | ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("media-type") stringValue:(strFileMimeType)) |
702 | ocidManifestElement's addChild:(ocidItemElement) |
703 | end if |
704 | |
705 | |
706 | set numCntPage to 1 as integer |
707 | repeat with itemAliasFilePath in listAliasFilePath |
708 | set aliasFilePath to itemAliasFilePath as alias |
709 | set strFilePath to (POSIX path of aliasFilePath) as text |
710 | set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePath)) |
711 | set ocidFilePath to ocidFilePathStr's stringByStandardizingPath() |
712 | set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false) |
713 | set ocidExtensionName to ocidFilePathURL's pathExtension() |
714 | ####拡張子からUTI取得 |
715 | set ocidUTType to (refMe's UTType's typeWithFilenameExtension:(ocidExtensionName)) |
716 | set ocidFileMimeType to ocidUTType's preferredMIMEType() |
717 | set strFileMimeType to ocidFileMimeType as text |
718 | ###画像ファイルは連番処理 四桁のゼロパディング |
719 | set strZeroSup to "0000" as text |
720 | set strSeroSup to (strZeroSup & (numCntPage as text)) as text |
721 | set strSeroSup to (text -4 through -1 of strSeroSup) as text |
722 | #IDを定義 |
723 | set strBaseImageFileName to ("dataItem") as text |
724 | set strFileName to (strBaseImageFileName & strSeroSup) as text |
725 | ##メディア要素(イメージファイル) |
726 | #itemエレメント |
727 | set ocidItemElement to (refMe's NSXMLElement's alloc()'s initWithName:("item")) |
728 | (ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("id") stringValue:(strFileName))) |
729 | #パス |
730 | set strSetValue to ("images/Image_" & strSeroSup & "." & (ocidExtensionName as text)) as text |
731 | (ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("href") stringValue:(strSetValue))) |
732 | (ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("media-type") stringValue:(strFileMimeType))) |
733 | (ocidManifestElement's addChild:(ocidItemElement)) |
734 | ##ページ要素(XHTMLファイル) |
735 | set strBaseFileName to ("page-") as text |
736 | set strFileName to (strBaseFileName & strSeroSup) as text |
737 | #itemエレメント |
738 | set ocidItemElement to (refMe's NSXMLElement's alloc()'s initWithName:("item")) |
739 | (ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("id") stringValue:(strFileName))) |
740 | #パス |
741 | set strSetValue to (strBaseFileName & strSeroSup & ".xhtml") as text |
742 | (ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("href") stringValue:(strSetValue))) |
743 | (ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("media-type") stringValue:("application/xhtml+xml"))) |
744 | (ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("properties") stringValue:("scripted"))) |
745 | (ocidManifestElement's addChild:(ocidItemElement)) |
746 | ##カウントアップ |
747 | set numCntPage to numCntPage + 1 as integer |
748 | end repeat |
749 | |
750 | ##表紙ページ設定 |
751 | set ocidItemElement to refMe's NSXMLElement's alloc()'s initWithName:("item") |
752 | ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("id") stringValue:("nav")) |
753 | ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("href") stringValue:("../nav.xhtml")) |
754 | ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("media-type") stringValue:("application/xhtml+xml")) |
755 | (ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("properties") stringValue:("nav"))) |
756 | ocidManifestElement's addChild:(ocidItemElement) |
757 | |
758 | |
759 | |
760 | ######################## |
761 | #【D】コンテンツの配置 spine |
762 | set ocidSpineElement to refMe's NSXMLElement's alloc()'s initWithName:("spine") |
763 | ##アトリビュート |
764 | ocidSpineElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("toc") stringValue:("ncx")) |
765 | ##開き方向指定 |
766 | ocidSpineElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("page-progression-direction") stringValue:(strPageProgression)) |
767 | ##【D-1】表紙ページの有無 |
768 | if boolCoverPage is true then |
769 | #表紙ページ ID: cover-page |
770 | set ocidItemRef to refMe's NSXMLElement's alloc()'s initWithName:("itemref") |
771 | ocidItemRef's addAttribute:(refMe's NSXMLNode's attributeWithName:("idref") stringValue:("cover")) |
772 | ocidItemRef's addAttribute:(refMe's NSXMLNode's attributeWithName:("linear") stringValue:("yes")) |
773 | ocidSpineElement's addChild:(ocidItemRef) |
774 | (* |
775 | #表紙画像 ID: cover-image |
776 | set ocidItemRef to refMe's NSXMLElement's alloc()'s initWithName:("itemref") |
777 | ocidItemRef's addAttribute:(refMe's NSXMLNode's attributeWithName:("idref") stringValue:("cover-image")) |
778 | ocidItemRef's addAttribute:(refMe's NSXMLNode's attributeWithName:("linear") stringValue:("yes")) |
779 | ocidSpineElement's addChild:(ocidItemRef) |
780 | #表紙ページ ID: cover-page |
781 | set ocidItemRef to refMe's NSXMLElement's alloc()'s initWithName:("itemref") |
782 | ocidItemRef's addAttribute:(refMe's NSXMLNode's attributeWithName:("idref") stringValue:("cover-page")) |
783 | ocidItemRef's addAttribute:(refMe's NSXMLNode's attributeWithName:("linear") stringValue:("yes")) |
784 | ocidSpineElement's addChild:(ocidItemRef) |
785 | *) |
786 | ##【D-2】目次ページ |
787 | set ocidItemRef to refMe's NSXMLElement's alloc()'s initWithName:("itemref") |
788 | ocidItemRef's addAttribute:(refMe's NSXMLNode's attributeWithName:("idref") stringValue:("toc")) |
789 | ocidItemRef's addAttribute:(refMe's NSXMLNode's attributeWithName:("linear") stringValue:("yes")) |
790 | ocidSpineElement's addChild:(ocidItemRef) |
791 | end if |
792 | |
793 | #カウンタ初期化 |
794 | set numCntPage to 1 as integer |
795 | #事前に取得している総ページ数回繰り返す |
796 | repeat numCntAllImage times |
797 | ###画像ファイルは連番処理 四桁のゼロパディング |
798 | set strZeroSup to "0000" as text |
799 | set strSeroSup to (strZeroSup & (numCntPage as text)) as text |
800 | set strSeroSup to (text -4 through -1 of strSeroSup) as text |
801 | set strSetFileID to (strBaseFileName & strSeroSup) as text |
802 | ##ファイル名をitemrefとして登録 |
803 | set ocidItemRef to refMe's NSXMLElement's alloc()'s initWithName:("itemref") |
804 | ocidItemRef's addAttribute:(refMe's NSXMLNode's attributeWithName:("idref") stringValue:(strSetFileID)) |
805 | ocidItemRef's addAttribute:(refMe's NSXMLNode's attributeWithName:("linear") stringValue:("yes")) |
806 | if boolProgression is true then |
807 | if numCntPage = 1 then |
808 | log "spineから1ページ目を抜きます" |
809 | else |
810 | ##ページ要素itemrefをspineの子要素に追加 |
811 | ocidSpineElement's addChild:(ocidItemRef) |
812 | end if |
813 | else |
814 | ##ページ要素itemrefをspineの子要素に追加 |
815 | ocidSpineElement's addChild:(ocidItemRef) |
816 | end if |
817 | set numCntPage to numCntPage + 1 as integer |
818 | end repeat |
819 | ################## |
820 | #【E】ガイドguide |
821 | (* referenceのtypeの要素 |
822 | toc(Table of Contents): 目次へのリンク。 |
823 | cover: 書籍の表紙ページへのリンク。 |
824 | title-page: 書籍のタイトルページへのリンク。 |
825 | colophon: 制作者や印刷情報を含むページへのリンク。 |
826 | acknowledgements: 著者への謝辞が含まれるページへのリンク。 |
827 | dedication: 書籍の献辞が含まれるページへのリンク。 |
828 | *) |
829 | set ocidGuideElement to refMe's NSXMLElement's alloc()'s initWithName:("guide") |
830 | #【E-1】目次追加 |
831 | set ocidReferenceElement to (refMe's NSXMLElement's alloc()'s initWithName:("reference")) |
832 | ocidReferenceElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("type") stringValue:("toc")) |
833 | ocidReferenceElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("href") stringValue:("toc.xhtml")) |
834 | ocidReferenceElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("title") stringValue:("目次")) |
835 | ocidGuideElement's addChild:(ocidReferenceElement) |
836 | ##【E-2】表紙ページの有無 設定依存 |
837 | if boolCoverPage is true then |
838 | set ocidReferenceElement to (refMe's NSXMLElement's alloc()'s initWithName:("reference")) |
839 | ocidReferenceElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("type") stringValue:("cover")) |
840 | ocidReferenceElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("href") stringValue:("cover.xhtml")) |
841 | ocidReferenceElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("title") stringValue:("表紙")) |
842 | ocidGuideElement's addChild:(ocidReferenceElement) |
843 | ##1ページ目指定 |
844 | set strStartFileName to (strBaseFileName & "0001.xhtml") as text |
845 | set ocidReferenceElement to (refMe's NSXMLElement's alloc()'s initWithName:("reference")) |
846 | ocidReferenceElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("type") stringValue:("other.reader-start-page")) |
847 | ocidReferenceElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("href") stringValue:(strStartFileName)) |
848 | ocidReferenceElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("title") stringValue:("最初のページ")) |
849 | ocidGuideElement's addChild:(ocidReferenceElement) |
850 | ##1ページ目指定 |
851 | set ocidReferenceElement to (refMe's NSXMLElement's alloc()'s initWithName:("reference")) |
852 | ocidReferenceElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("type") stringValue:("text")) |
853 | ocidReferenceElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("href") stringValue:(strStartFileName)) |
854 | ocidReferenceElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("title") stringValue:("最初のコンテンツ")) |
855 | ocidGuideElement's addChild:(ocidReferenceElement) |
856 | end if |
857 | |
858 | ################## |
859 | #↑からの各子要素をセット |
860 | ## 【B】メタ部を【A】のROOTエレメントに追加 |
861 | ocidRootElement's addChild:(ocidMetaDataElement) |
862 | ## 【C】manifest部を【A】のROOTエレメントに追加 |
863 | ocidRootElement's addChild:(ocidManifestElement) |
864 | ## 【D】spine部を【A】のROOTエレメントに追加 |
865 | ocidRootElement's addChild:(ocidSpineElement) |
866 | ## 【E】ガイド部を【A】のROOTエレメントに追加 |
867 | ocidRootElement's addChild:(ocidGuideElement) |
868 | ## 【A】をROOTエレメントをセットしてXMLとする |
869 | set ocidOutPutXML to refMe's NSXMLDocument's alloc()'s initWithRootElement:(ocidRootElement) |
870 | ocidOutPutXML's setVersion:"1.0" |
871 | ocidOutPutXML's setCharacterEncoding:"UTF-8" |
872 | ### 【A】をテキストにして |
873 | set ocidSaveStrings to ocidOutPutXML's XMLString() |
874 | ###改行コードを指定して |
875 | ocidSaveStrings's appendString:"\n" |
876 | ##保存 |
877 | set listWritetoUrlArray to ocidSaveStrings's writeToURL:(ocidOptFilePathURL) atomically:true encoding:(refMe's NSUTF8StringEncoding) |error| :(reference) |
878 | #################################### |
879 | ###◆ 【3−4】toc.ncx 主に閲覧者が必要な情報や |
880 | ##ページや項目の順番等を指定する |
881 | ##マルチメディア系やアクセシビリティ要素もここで指定する |
882 | ###ファイルパス |
883 | ##Pageの場合 |
884 | ## set ocidNcxFilePathURL to ocidOPSDirPathURL's URLByAppendingPathComponent:("epb.ncx") isDirectory:false |
885 | ##一般的な命名 |
886 | set ocidNcxFilePathURL to ocidOPSDirPathURL's URLByAppendingPathComponent:("toc.ncx") isDirectory:false |
887 | ######【A】ROOTのエレメント 4つの子要素がある |
888 | set ocidRootElement to refMe's NSXMLElement's alloc()'s initWithName:"ncx" |
889 | ocidRootElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("version") stringValue:("2005-1")) |
890 | ocidRootElement's addNamespace:(refMe's NSXMLNode's namespaceWithName:("") stringValue:("http://www.daisy.org/z3986/2005/ncx/")) |
891 | ######【B】head メタ情報部分 |
892 | set ocidHeadElement to refMe's NSXMLElement's alloc()'s initWithName:("head") |
893 | ##【B-1】uid |
894 | ###エレメント名meta |
895 | set ocidMetaElement to refMe's NSXMLElement's elementWithName:("meta") |
896 | ##アトリビュートを設定して |
897 | ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("name") stringValue:("dtb:uid")) |
898 | ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("content") stringValue:(strUUID)) |
899 | ##親要素の【B】head に追加する |
900 | ocidHeadElement's addChild:(ocidMetaElement) |
901 | ##◆【B-2】depth |
902 | ###エレメント名meta |
903 | set ocidMetaElement to refMe's NSXMLElement's elementWithName:("meta") |
904 | ##アトリビュートを設定して |
905 | ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("name") stringValue:("dtb:depth")) |
906 | ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("content") stringValue:("1")) |
907 | ##親要素の【B】head に追加する |
908 | ocidHeadElement's addChild:(ocidMetaElement) |
909 | ##◆【B-3】totalPageCount |
910 | set strCntAllImage to numCntAllImage as text |
911 | ###エレメント名meta |
912 | set ocidMetaElement to refMe's NSXMLElement's elementWithName:("meta") |
913 | ##アトリビュートを設定して |
914 | ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("name") stringValue:("dtb:totalPageCount")) |
915 | ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("content") stringValue:(strCntAllImage)) |
916 | ##親要素の【B】head に追加する |
917 | ocidHeadElement's addChild:(ocidMetaElement) |
918 | ##◆【B-4】maxPageNumber |
919 | ###エレメント名meta |
920 | set ocidMetaElement to refMe's NSXMLElement's elementWithName:("meta") |
921 | ##アトリビュートを設定して |
922 | ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("name") stringValue:("dtb:maxPageNumber")) |
923 | ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("content") stringValue:(strCntAllImage)) |
924 | ##親要素の【B】head に追加する |
925 | ocidHeadElement's addChild:(ocidMetaElement) |
926 | ##◆【B-5】作成日 |
927 | set strSetDate to doGetDateNo("yyyy-MM-dd") as text |
928 | ###エレメント名meta |
929 | set ocidMetaElement to refMe's NSXMLElement's elementWithName:("meta") |
930 | ##アトリビュートを設定して |
931 | ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("name") stringValue:("dc:date")) |
932 | ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("content") stringValue:(strSetDate)) |
933 | ##親要素の【B】head に追加する |
934 | ocidHeadElement's addChild:(ocidMetaElement) |
935 | ##◆【B-6】修正日 |
936 | set strSetDate to doGetDateNo("yyyy-MM-dd'T'HH:mm:ss'Z'") as text |
937 | ###エレメント名meta |
938 | set ocidMetaElement to refMe's NSXMLElement's elementWithName:("meta") |
939 | ##アトリビュートを設定して |
940 | ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("name") stringValue:("dc:modified")) |
941 | ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("content") stringValue:(strSetDate)) |
942 | ##親要素の【B】head に追加する |
943 | ocidHeadElement's addChild:(ocidMetaElement) |
944 | ######【C】docTitle タイトル |
945 | ##エレメント名docTitle |
946 | set ocidTitleElement to refMe's NSXMLElement's alloc()'s initWithName:("docTitle") |
947 | ##子要素のtext |
948 | set ocidTextElement to refMe's NSXMLElement's elementWithName:("text") |
949 | ##子要素textにドキュメント名を値として設定して |
950 | ocidTextElement's setStringValue:(strDocumentTitle) |
951 | ##CのdocTitleエレメントに子要素として追加する |
952 | ocidTitleElement's addChild:(ocidTextElement) |
953 | ######【D】docAuthor 作者 著者 |
954 | ##エレメント名 docAuthor |
955 | set ocidAuthorElement to refMe's NSXMLElement's alloc()'s initWithName:("docAuthor") |
956 | ##子要素のtext |
957 | set ocidTextElement to refMe's NSXMLElement's elementWithName:("text") |
958 | ##子要素textに作者情報を値として設定して |
959 | ocidTextElement's setStringValue:(strAuthor) |
960 | ##DのdocAuthorエレメントに子要素として追加する |
961 | ocidAuthorElement's addChild:(ocidTextElement) |
962 | ######【E】navMap navMapは閲覧時の順番を指定するので表紙イメージの設定とは異なる |
963 | set ocidMapElement to refMe's NSXMLElement's alloc()'s initWithName:("navMap") |
964 | #navMapの子要素navPoint |
965 | set ocidNavPointElement to refMe's NSXMLElement's elementWithName:("navPoint") |
966 | ##navPointのアトリビュート カバー表紙を最初のページとして読み順指定する |
967 | ocidNavPointElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("id") stringValue:("navpoint-1")) |
968 | ocidNavPointElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("playOrder") stringValue:("1")) |
969 | ##【E-1】 navLabel ↑このnavPointの意図するラベル名 |
970 | set ocidNavLabelElement to refMe's NSXMLElement's elementWithName:("navLabel") |
971 | set ocidTextElement to refMe's NSXMLElement's elementWithName:("text") |
972 | ocidTextElement's setStringValue:(strLabelTitle) |
973 | ##ラベルテキストをnavLabelに子要素として追加 |
974 | ocidNavLabelElement's addChild:(ocidTextElement) |
975 | ##↑追加したラベルをnavPointに子要素として追加 |
976 | ocidNavPointElement's addChild:(ocidNavLabelElement) |
977 | ##【E-2】contentはnavPointとして指定するファイルのリソースパス |
978 | set ocidNavContentElement to refMe's NSXMLElement's elementWithName:("content") |
979 | ###表紙設定ありの場合は |
980 | if boolCoverPage is true then |
981 | ##アトリビュートでパス指定する =表紙ページ |
982 | ocidNavContentElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("src") stringValue:("cover.xhtml")) |
983 | else |
984 | ##見開き調整ありの場合は |
985 | if boolProgression is true then |
986 | set strStartFileName to (strBaseFileName & "0002.xhtml") as text |
987 | ocidNavContentElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("src") stringValue:(strStartFileName)) |
988 | else |
989 | set strStartFileName to (strBaseFileName & "0001.xhtml") as text |
990 | ocidNavContentElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("src") stringValue:(strStartFileName)) |
991 | end if |
992 | end if |
993 | ##contentをnavPointに子要素として追加 |
994 | ocidNavPointElement's addChild:(ocidNavContentElement) |
995 | ##複数のnavPointを指定する場合はこの下に追加していく |
996 | ###navPointをnavMapに子要素として追加 |
997 | ocidMapElement's addChild:(ocidNavPointElement) |
998 | ## ↑からの子要素をセット |
999 | ##【A】に【B】を追加 |
000 | ocidRootElement's addChild:(ocidHeadElement) |
001 | ##【A】に【C】を追加 |
002 | ocidRootElement's addChild:(ocidTitleElement) |
003 | ##【A】に【D】を追加 |
004 | ocidRootElement's addChild:(ocidAuthorElement) |
005 | ##【A】に【E】を追加 |
006 | ocidRootElement's addChild:(ocidMapElement) |
007 | ## ↑からのROOTエレメントをセットしてXMLとする |
008 | set ocidOutPutXML to refMe's NSXMLDocument's alloc()'s initWithRootElement:(ocidRootElement) |
009 | ocidOutPutXML's setVersion:"1.0" |
010 | ocidOutPutXML's setCharacterEncoding:"UTF-8" |
011 | ###XML形式のテキストに出力 |
012 | set ocidSaveStrings to ocidOutPutXML's XMLString() |
013 | ###改行コードを指定して |
014 | ocidSaveStrings's appendString:"\n" |
015 | ##保存 これでCNXファイルの出来上がり |
016 | set listWritetoUrlArray to ocidSaveStrings's writeToURL:(ocidNcxFilePathURL) atomically:true encoding:(refMe's NSUTF8StringEncoding) |error| :(reference) |
017 | |
018 | ################################################################# |
019 | ### 【2】META-INF ファイル: container.xml com.apple.ibooks.display-options.xml |
020 | set ocidMetaDirPathURL to ocidEpubDirPathURL's URLByAppendingPathComponent:("META-INF") isDirectory:true |
021 | ################## |
022 | ###◆【2−1】container.xml |
023 | ###ファイルのパス |
024 | set ocidContainerFilePathURL to ocidMetaDirPathURL's URLByAppendingPathComponent:("container.xml") isDirectory:false |
025 | ###【A】ROOT エレメント |
026 | set ocidRootElement to refMe's NSXMLElement's alloc()'s initWithName:"container" |
027 | ##【A】にアトリビュートを追加 |
028 | ocidRootElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("version") stringValue:("1.0")) |
029 | ##【A】にネームスペースを追加 |
030 | ocidRootElement's addNamespace:(refMe's NSXMLNode's namespaceWithName:("") stringValue:("urn:oasis:names:tc:opendocument:xmlns:container")) |
031 | ###【B】子要素 rootfiles エレメント |
032 | set ocidRootFilesElement to refMe's NSXMLElement's alloc()'s initWithName:"rootfiles" |
033 | ###【C】Bの子要素 rootfileノード |
034 | set ocidRootFilesNode to refMe's NSXMLElement's alloc()'s initWithName:"rootfile" |
035 | ##【C】にアトリビュートを追加 |
036 | ocidRootFilesNode's addAttribute:(refMe's NSXMLNode's attributeWithName:("full-path") stringValue:("OPS/content.opf")) |
037 | ocidRootFilesNode's addAttribute:(refMe's NSXMLNode's attributeWithName:("media-type") stringValue:("application/oebps-package+xml")) |
038 | ## ↑からの子要素をセット(【B】に【C】を追加) |
039 | ocidRootFilesElement's addChild:(ocidRootFilesNode) |
040 | ## ↑からの子要素をセット(【A】に【B】を追加) |
041 | ocidRootElement's addChild:(ocidRootFilesElement) |
042 | ## ↑からのROOTエレメントをセットしてXMLとする 【A】をXMLドキュメントに |
043 | set ocidOutPutXML to refMe's NSXMLDocument's alloc()'s initWithRootElement:(ocidRootElement) |
044 | ocidOutPutXML's setVersion:"1.0" |
045 | ocidOutPutXML's setCharacterEncoding:"UTF-8" |
046 | ###XML形式のテキストに出力 |
047 | set ocidSaveStrings to ocidOutPutXML's XMLString() |
048 | ###改行コードを指定して |
049 | ocidSaveStrings's appendString:"\n" |
050 | ##保存 |
051 | set listDone to ocidSaveStrings's writeToURL:(ocidContainerFilePathURL) atomically:true encoding:(refMe's NSUTF8StringEncoding) |error| :(reference) |
052 | |
053 | ################## |
054 | ###◆ 【2−2】com.apple.ibooks.display-options.xml |
055 | ##ファイルパス |
056 | set ocidContainerFilePathURL to ocidMetaDirPathURL's URLByAppendingPathComponent:("com.apple.ibooks.display-options.xml") isDirectory:false |
057 | ###【A】ROOT エレメント |
058 | set ocidRootElement to refMe's NSXMLElement's alloc()'s initWithName:"display_options" |
059 | ###【B】子要素 platform エレメント |
060 | set ocidPlatformElement to refMe's NSXMLElement's alloc()'s initWithName:("platform") |
061 | ###【B】にアトリビュートを追加 |
062 | ocidPlatformElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("name") stringValue:("*")) |
063 | ###【C】Bの子要素としてのoption エレメント |
064 | set ocidOptionElement to refMe's NSXMLElement's elementWithName:("option") |
065 | ###【C】にアトリビュートを追加 |
066 | ocidOptionElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("name") stringValue:("specified-fonts")) |
067 | ###【C】にテキストの値を設定 |
068 | ocidOptionElement's setStringValue:("false") |
069 | ## 子要素をセット 【C】を【B】に追加 |
070 | ocidPlatformElement's addChild:(ocidOptionElement) |
071 | ## ↑からの子要素をセット 【B】を【A】に追加 |
072 | ocidRootElement's addChild:(ocidPlatformElement) |
073 | ## ↑からのROOTエレメントをセットしてXMLとする 【A】をXMLドキュメントにする |
074 | set ocidOutPutXML to refMe's NSXMLDocument's alloc()'s initWithRootElement:(ocidRootElement) |
075 | ocidOutPutXML's setVersion:"1.0" |
076 | ocidOutPutXML's setCharacterEncoding:"UTF-8" |
077 | ###XML形式のテキストに出力 |
078 | set ocidSaveStrings to ocidOutPutXML's XMLString() |
079 | ###改行コードを指定して |
080 | ocidSaveStrings's appendString:"\n" |
081 | ##保存 |
082 | set listDone to ocidSaveStrings's writeToURL:(ocidContainerFilePathURL) atomically:true encoding:(refMe's NSUTF8StringEncoding) |error| :(reference) |
083 | |
084 | |
085 | delay 2 |
086 | |
087 | ############################## |
088 | ### 圧縮 |
089 | ############################## |
090 | |
091 | set strEpubDirPath to ocidEpubDirPath as text |
092 | set strEpubFilePath to ocidEpubFilePath as text |
093 | set strPushdDirPath to ocidPushdDirPath as text |
094 | ### |
095 | set strCommandText to ("pushd \"" & strPushdDirPath & "\"") as text |
096 | log strCommandText |
097 | do shell script strCommandText |
098 | |
099 | set strCommandText to ("pushd \"" & strEpubDirPath & "/\" && '/usr/bin/zip' -rX \"../" & strDocumentTitle & ".epub\" mimetype META-INF/ OPS/ nav.xhtml") as text |
100 | log strCommandText |
101 | do shell script strCommandText |
102 | |
103 | |
104 | set aliasSaveDirPath to (ocidPushdDirPathURL's absoluteURL()) as alias |
105 | |
106 | tell application "Finder" |
107 | open location aliasSaveDirPath |
108 | end tell |
109 | |
110 | return |
111 | |
112 | |
113 | ############################## |
114 | ### 今の日付日間 テキスト |
115 | ############################## |
116 | to doGetDateNo(argDateFormat) |
117 | ####日付情報の取得 |
118 | set ocidDate to current application's NSDate's |date|() |
119 | ###日付のフォーマットを定義 |
120 | set ocidNSDateFormatter to current application's NSDateFormatter's alloc()'s init() |
121 | ocidNSDateFormatter's setLocale:(current application's NSLocale's localeWithLocaleIdentifier:"ja_JP_POSIX") |
122 | set ocidTimeZone to refMe's NSTimeZone's alloc()'s initWithName:"Asia/Tokyo" |
123 | ocidNSDateFormatter's setTimeZone:(ocidTimeZone) |
124 | ocidNSDateFormatter's setDateFormat:(argDateFormat) |
125 | set ocidDateAndTime to ocidNSDateFormatter's stringFromDate:ocidDate |
126 | set strDateAndTime to ocidDateAndTime as text |
127 | return strDateAndTime |
128 | end doGetDateNo |
129 | |
130 | |
131 | |
132 | to doGetJs() |
133 | set strKoboJS to ("function Body_onLoad() {};var gPosition = 0;var gProgress = 0;var gCurrentPage = 0;var gPageCount = 0;var gClientHeight = null;const kMaxFont = 0;function getPosition() {return gPosition;}function getProgress() {return gProgress;}function getPageCount() {return gPageCount;}function getCurrentPage() {return gCurrentPage;}function setupBookColumns() {var body = document.getElementsByTagName('body')[0].style;body.marginLeft = 0;body.marginRight = 0;body.marginTop = 0;body.marginBottom = 0;var bc = document.getElementById('book-columns').style;bc.width = (window.innerWidth * 2) + 'px !important';bc.height = (window.innerHeight - kMaxFont) + 'px !important';bc.marginTop = '0px !important';bc.webkitColumnWidth = window.innerWidth + 'px !important';bc.webkitColumnGap = '0px';bc.overflow = 'visible';gCurrentPage = 1;gProgress = gPosition = 0;var bi = document.getElementById('book-inner').style;bi.marginLeft = '0px';bi.marginRight = '0px';bi.padding = '0';gPageCount = document.body.scrollWidth / window.innerWidth;if (gClientHeight < (window.innerHeight - kMaxFont)) {gPageCount = 1;}}function paginate() {lue to the height of the window and then decide wether to force the page count to one.if(gClientHeight == undefined) {gClientHeight = document.getElementById('book-columns').clientHeight;}setupBookColumns();}function paginateAndMaintainProgress() {var savedProgress = gProgress;setupBookColumns();goProgress(savedProgress);}function updateProgress() {gProgress = (gCurrentPage - 1.0) / gPageCount;}function goBack() {if (gCurrentPage > 1) {gCurrentPage--;gPosition -= window.innerWidth;window.scrollTo(gPosition, 0);updateProgress();}}function goForward() {if (gCurrentPage < gPageCount) {gCurrentPage++;gPosition += window.innerWidth;window.scrollTo(gPosition, 0);updateProgress();}}function goPage(pageNumber) {if (pageNumber > 0 && pageNumber <= gPageCount) {gCurrentPage = pageNumber;gPosition = (gCurrentPage - 1) * window.innerWidth;window.scrollTo(gPosition, 0);updateProgress();}}function goProgress(progress) {progress += 0.0001;var progressPerPage = 1.0 / gPageCount;var newPage = 0;for (var page = 0; page < gPageCount; page++) {var low = page * progressPerPage;var high = low + progressPerPage;if (progress >= low && progress < high) {newPage = page;break;}}gCurrentPage = newPage + 1;gPosition = (gCurrentPage - 1) * window.innerWidth;window.scrollTo(gPosition, 0);updateProgress();}function setFontFamily(newFont) {document.body.style.fontFamily = newFont + \" !important\";paginateAndMaintainProgress();}function setFontSize(toSize) {document.getElementById('book-inner').style.fontSize = toSize + \"em !important\";paginateAndMaintainProgress();}function setLineHeight(toHeight) {document.getElementById('book-inner').style.lineHeight = toHeight + \"em !important\";paginateAndMaintainProgress();}function enableNightReading() {document.body.style.backgroundColor = \"#000000\";var theDiv = document.getElementById('book-inner');theDiv.style.color = \"#ffffff\";var anchorTags;anchorTags = theDiv.getElementsByTagName('a');for (var i = 0; i < anchorTags.length; i++) {anchorTags[i].style.color = \"#ffffff\";}}") as text |
134 | return strKoboJS |
135 | end doGetJs |
AppleScriptで生成しました |
| 固定リンク