XML SVG

[pymupdf]SVG to PDF(個別フォントをロードしないので文字のあるSVG向きではない)



ダウンロード - svg2pdfv2.zip




サンプルコード

サンプルソース(参考)
行番号ソース
001#!/usr/bin/env python3
002# coding: utf-8
003import sys
004import os
005import pymupdf
006
007# 本番用のパスの受け取り
008arg_file_path = sys.argv
009path_pdf_file = str(arg_file_path[1])
010# テスト用のパス
011# path_desktop_dir = os.path.join(os.path.expanduser("~"), "Desktop")
012# path_pdf_file = os.path.join(path_desktop_dir, "demo.svg")
013
014# パスからベースファイル名とコンテナを取得
015path_container_dir = os.path.dirname(path_pdf_file)
016path_file_name = os.path.basename(path_pdf_file)
017path_base_file_name = os.path.splitext(path_file_name)[0]
018
019# 保存先パス
020path_save_file = path_container_dir + "/" + path_base_file_name + ".svg.pdf"
021
022# SVG読み込み
023import_graphic = pymupdf.open(path_pdf_file, filetype="svg")
024rect_graphic = import_graphic[0].rect
025#SVGをPDFに変換
026raw_pdf_graphic = import_graphic.convert_to_pdf()
027#SVGを閉じる
028import_graphic.close()
029#変換済みのデータでPDFを新規作成
030pdf_document = pymupdf.open("pdf", raw_pdf_graphic)
031pdf_page = pdf_document[0]
032pdf_page.set_cropbox(rect_graphic)
033pdf_page.set_bleedbox(rect_graphic)
034pdf_page.set_trimbox(rect_graphic)
035pdf_page.set_mediabox(rect_graphic)
036#保存
037pdf_document.save(path_save_file)
038#終了
039pdf_document.close()
040sys.exit(0)
AppleScriptで生成しました

|

[Keynote]Keynoteを使ってSVGを画像にする(仮)



ダウンロード - svg2png4key.zip




AppleScript サンプルコード

【スクリプトエディタで開く】 |

AppleScript サンプルソース(参考)
行番号ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#
004# 途中だけと機能としては利用できる(詰めを考え中)
005#
006#com.cocolog-nifty.quicktimer.icefloe
007----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
008use AppleScript version "2.8"
009use framework "Foundation"
010use framework "UniformTypeIdentifiers"
011use framework "AppKit"
012use scripting additions
013property refMe : a reference to current application
014set appFileManager to refMe's NSFileManager's defaultManager()
015
016
017##設定項目
018#set strThemeFileName to ("200x200背景白.key") as text
019set strThemeFileName to ("200x200背景透過.key") as text
020
021##設定項目
022#SVGで指定してあるサイズの何倍のサイズを生成するか?
023# 1でSVGの指定サイズPX
024set numExpand to 2 as integer
025
026##設定項目
027#解像度 72ppi= false か 144ppi= trueか
028set boolRetina to true as boolean
029
030#############################
031#書き出し先
032set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSPicturesDirectory) inDomains:(refMe's NSUserDomainMask))
033set ocidPicturesDirPathURL to ocidURLsArray's firstObject()
034set ocidSaveDirPathURL to ocidPicturesDirPathURL's URLByAppendingPathComponent:("SVG書き出し") isDirectory:(true)
035#書き出しフォルダ作成
036set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
037ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions)
038set listDone to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error| :(reference)
039set aliasSaveFilePath to (ocidSaveDirPathURL's absoluteURL()) as «class furl»
040
041
042############
043#Keynote テンプレート パス
044set aliasPathToMe to (path to me) as alias
045set strPathToMe to (POSIX path of aliasPathToMe) as text
046set ocidPathToMeStr to refMe's NSString's stringWithString:(strPathToMe)
047set ocidPathToMe to ocidPathToMeStr's stringByStandardizingPath()
048set ocidPathToMeURL to refMe's NSURL's alloc()'s initFileURLWithPath:(ocidPathToMe) isDirectory:(false)
049set ocidPathToMeContainerDirPathURL to ocidPathToMeURL's URLByDeletingLastPathComponent()
050set strThemePath to ("theme/" & strThemeFileName) as text
051set ocidThemeFilePathURL to ocidPathToMeContainerDirPathURL's URLByAppendingPathComponent:(strThemePath) isDirectory:(false)
052set aliasThemeFilePath to (ocidThemeFilePathURL's absoluteURL()) as alias
053
054############
055#Keynote起動
056tell application "Keynote"
057  activate
058end tell
059
060#############################
061#ダイアログ
062set strName to (name of current application) as text
063if strName is "osascript" then
064  tell application "Finder" to activate
065else
066  tell current application to activate
067end if
068set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
069set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
070set aliasDesktopDirPath to (ocidDesktopDirPathURL's absoluteURL()) as alias
071set listUTI to {"public.svg-image"}
072set strMes to ("SVGファイルを選んでください") as text
073set strPrompt to ("SVGファイルを選んでください") as text
074try
075  set aliasFilePath to (choose file strMes with prompt strPrompt default location (aliasDesktopDirPath) of type listUTI with invisibles and showing package contents without multiple selections allowed) as alias
076on error
077  log "エラーしました"
078  return "エラーしました"
079end try
080
081
082#############################
083#パス
084set strFilePath to (POSIX path of aliasFilePath) as text
085set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)
086set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
087set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)
088set strExtensionName to ocidFilePathURL's pathExtension() as text
089set ocidBaseFilePathURL to ocidFilePathURL's URLByDeletingPathExtension()
090set ocidBaseFileName to ocidBaseFilePathURL's lastPathComponent()
091
092#拡張子がSVGZの場合
093if strExtensionName is "svgz" then
094  return "svgzには非対応です"
095  #set strFilePath to ocidFilePathURL's |path| as text
096  # set strFilePath to doExtractSvgz(strFilePath)
097  if strFilePath is false then
098    #   return "解凍に失敗しました"
099  end if
100  set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)
101  set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
102  set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)
103  set strExtensionName to ocidFilePathURL's pathExtension() as text
104end if
105#SVGのエイリアス
106set aliasImageFilePath to (ocidFilePathURL's absoluteURL()) as alias
107
108#############################
109#NSDATAに読み込み
110set ocidOption to (refMe's NSDataReadingMappedIfSafe)
111set listResponse to refMe's NSData's alloc()'s initWithContentsOfURL:(ocidFilePathURL) options:(ocidOption) |error| :(reference)
112set ocidReadData to (item 1 of listResponse)
113#NSXML
114set ocidOption to (refMe's NSXMLNodePreserveAll) + (refMe's NSXMLDocumentTidyXML)
115set listResponse to refMe's NSXMLDocument's alloc()'s initWithData:(ocidReadData) options:(ocidOption) |error| :(reference)
116set ocidXMLDoc to (item 1 of listResponse)
117set ocidRootElement to ocidXMLDoc's rootElement
118
119###########################
120# SVGのサイズ取得
121###########################
122#viewBoxのサイズの取得
123set ocidViewBox to (ocidRootElement's attributeForName:("viewBox"))
124set ocidViewBoxStr to ocidViewBox's stringValue()
125set ocidViewBoxArray to (ocidViewBoxStr's componentsSeparatedByString:(" "))
126set ocidViewBoxX to (ocidViewBoxArray's objectAtIndex:(0))
127set ocidViewBoxY to (ocidViewBoxArray's objectAtIndex:(1))
128set ocidViewBoxW to (ocidViewBoxArray's objectAtIndex:(2))
129set ocidViewBoxH to (ocidViewBoxArray's objectAtIndex:(3))
130#アトリビュートのRECT
131set ocidRectX to (ocidRootElement's attributeForName:("x"))
132set ocidRectY to (ocidRootElement's attributeForName:("y"))
133set ocidRectW to (ocidRootElement's attributeForName:("width"))
134set ocidRectH to (ocidRootElement's attributeForName:("height"))
135
136#採用するサイズの判定
137if ocidRectW = (missing value) then
138  # viewBoxのPXサイズをそのままサイズとする
139  set strPxW to ocidViewBoxW as text
140  set strPxH to ocidViewBoxH as text
141  set numPxW to strPxW as integer
142  set numPxH to strPxH as integer
143else
144  #width height指定がある場合
145  # set strRectX to ocidRectX's stringValue()
146  # set strRectY to ocidRectY's stringValue()
147  set ocidRectW to ocidRectW's stringValue()
148  set ocidRectH to ocidRectH's stringValue()
149  
150  #単位文字チェック
151  set boolPercent to (ocidRectW's containsString:("%")) as boolean
152  set boolPT to (ocidRectW's containsString:("pt")) as boolean
153  set boolPx to (ocidRectW's containsString:("px")) as boolean
154  set boolPEm to (ocidRectW's containsString:("em")) as boolean
155  
156  #英数文字以外の値=単位文字を削除
157  #数値のキャラクタセット
158  set ocidCharSet to refMe's NSCharacterSet's decimalDigitCharacterSet
159  #逆セット=数値以外
160  set ocidCharSetInv to ocidCharSet's invertedSet()
161  #数値以外を置換
162  set ocidRectW to (ocidRectW's componentsSeparatedByCharactersInSet:(ocidCharSetInv))'s componentsJoinedByString:("")
163  set ocidRectH to (ocidRectH's componentsSeparatedByCharactersInSet:(ocidCharSetInv))'s componentsJoinedByString:("")
164  #%指定されている場合は
165  if boolPercent is true then
166    log "サイズ指定が%です"
167    set strPxW to ocidViewBoxW as text
168    set strPxH to ocidViewBoxH as text
169    set strRectW to ocidRectW as text
170    set strRectH to ocidRectH as text
171    #%を加味した値をサイズとする
172    #ピクセルサイズなので整数に丸める
173    set numPxW to (strPxW * (strRectW / 100)) as integer
174    set numPxH to (strPxH * (strRectH / 100)) as integer
175  else if boolPx is true then
176    #width heigh指定がPXサイズ指定の場合
177    #width heigh指定のpxサイズを採用する
178    set strPxW to strRectW as text
179    set strPxH to strRectH as text
180    set numPxW to strPxW as integer
181    set numPxH to strPxH as integer
182  else if boolPT is true then
183    set strPxW to ocidRectW as text
184    set strPxH to ocidRectH as text
185    set numPxW to strPxW as integer
186    set numPxH to strPxH as integer
187  else if boolPEm is true then
188    return "サイズ指定EMは対象外"
189  else
190    set strPxW to ocidViewBoxW as text
191    set strPxH to ocidViewBoxH as text
192    set numPxW to strPxW as integer
193    set numPxH to strPxH as integer
194  end if
195end if
196
197log numPxW
198log numPxH
199
200# Key noteはPXはそのままPT換算?
201#set numPtW to (strPxW / 72) as integer
202#set numPtH to (strPxH / 72) as integer
203#Key noteの最小サイズ200pt以下の調整
204if numPxW < 200 then
205  set numResolution to (numPxW / numPxH) as number
206  set numPtW to 200 as integer
207  set numPtH to 200 * numResolution as integer
208else if numPxH < 200 then
209  set numResolution to (numPxH / numPxW) as number
210  set numPtW to 200 * numResolution as integer
211  set numPtH to 200 as integer
212else
213  set numPtW to numPxW as integer
214  set numPtH to numPxH as integer
215end if
216set numSetWpx to numPtW as integer
217set numSetHpx to numPtH as integer
218
219log numSetWpx
220log numSetHpx
221
222#############################
223#最終的なサイズ
224set numSetWpx to (numSetWpx * numExpand) as integer
225set numSetHpx to (numSetHpx * numExpand) as integer
226
227############
228#本処理
229repeat 10 times
230  tell application "Keynote"
231    activate
232    set boolFrontMost to frontmost as boolean
233  end tell
234  if boolFrontMost is true then
235    exit repeat
236  else
237    delay 1
238  end if
239end repeat
240
241############
242#テンプレートオープン
243tell application "Keynote"
244  set objDocument to open file aliasThemeFilePath
245end tell
246
247############
248#開いたドキュメントサイズを画像サイズに
249tell application "Keynote"
250  tell front document
251    set width to numSetWpx
252    set height to numSetHpx
253  end tell
254end tell
255delay 1
256#画像のオフセット値0
257set numLeftOffSetPx to 0 as integer
258set numTopOffsetPx to 0 as integer
259set listOffsetPos to {numLeftOffSetPx, numTopOffsetPx} as list
260
261############
262#サイズ指定でSVGを読み込む
263tell application "Keynote"
264  tell objDocument
265    tell current slide
266      #画像読み込み
267      set objSetImage to make new image with properties {file:aliasImageFilePath, width:numSetWpx, height:numSetHpx, position:listOffsetPos}
268    end tell
269  end tell
270end tell
271
272############
273#画像を書き出すフォルダを作成する
274set ocidTempDirURL to appFileManager's temporaryDirectory()
275set ocidTempDirPathURL to ocidTempDirURL's URLByAppendingPathComponent:(ocidBaseFileName) isDirectory:true
276set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
277ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions)
278set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidTempDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error| :(reference)
279set aliasSaveDirPath to (ocidTempDirPathURL's absoluteURL()) as «class furl»
280
281####################
282#書き出し
283tell application "Keynote"
284  set saveDoc to front document
285  export front document to file aliasSaveDirPath as slide images with properties {image format:PNG, export style:IndividualSlides}
286end tell
287
288####################
289#白紙に戻す
290tell application "Keynote"
291  tell objDocument
292    #次のページスライドを開く
293    try
294      set thisSlide to make new slide with properties {base layout:slide layout "Blank"}
295    on error
296      set thisSlide to make new slide with properties {base layout:slide layout "空白"}
297    end try
298  end tell
299end tell
300
301####################
302#最初のスライドは削除
303tell application "Keynote"
304  tell objDocument
305    tell first slide
306      delete
307    end tell
308  end tell
309end tell
310
311####################
312#元にサイズ戻して閉じる
313tell application "Keynote"
314  tell objDocument
315    set width to 200
316    set height to 200
317    close saving yes
318  end tell
319end tell
320
321####################
322#ファイル名 書き出されるファイル
323set strTmpFileName to ((ocidBaseFileName as text) & ".001.png") as text
324set ocidTempFilePathURL to ocidTempDirPathURL's URLByAppendingPathComponent:(strTmpFileName) isDirectory:false
325set strTempFilePath to ocidTempFilePathURL's |path|() as text
326
327####################
328#解像度による分岐
329if boolRetina is true then
330  #解像度上げるサブルーチンに渡す
331  set ocidTempFilePathURL to doMakeRetinaImagePNG(strTempFilePath)
332  #戻り値NSURLが移動元
333  set ocidFileName to ocidTempFilePathURL's lastPathComponent()
334  set ocidSaveFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(ocidFileName) isDirectory:false
335else
336  ###リネームして移動するファイル
337  set strDistFileName to ((ocidBaseFileName as text) & "_" & numSetWpx & "x" & numSetHpx & ".png") as text
338  set ocidSaveFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(strDistFileName) isDirectory:false
339end if
340##リネームしながら移動もする
341set appFileManager to refMe's NSFileManager's defaultManager()
342set listDone to (appFileManager's moveItemAtURL:(ocidTempFilePathURL) toURL:(ocidSaveFilePathURL) |error| :(reference))
343####################
344###保存先を開く
345set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
346set boolDone to appSharedWorkspace's openURL:(ocidSaveDirPathURL)
347if boolDone is false then
348  tell application "Finder"
349    open folder aliasSaveFilePath
350  end tell
351end if
352
353################################
354##PXサイズはそのままPTサイズを半分にして
355##144ppiにして上書き保存
356##@2タイプのファイル名にリネームして
357##新しいファイルURLを戻します
358##エラーの場合はFALSEを戻します
359################################
360to doMakeRetinaImagePNG(argFilePath)
361  set strFilePath to argFilePath as text
362  set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)
363  set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
364  set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)
365  set ocidContainerDirPathURL to ocidFilePathURL's URLByDeletingLastPathComponent()
366  set ocidFileName to ocidFilePathURL's lastPathComponent()
367  
368  set ocidFileNameArray to ocidFileName's componentsSeparatedByString:("_")
369  #ファイル名分岐(通常のファイル名対応)
370  set numCntArray to ocidFileNameArray's |count|()
371  if numCntArray = 1 then
372    set ocidBaseFileName to ocidFileName's stringByDeletingPathExtension()
373    set ocidBaseFileName to (ocidBaseFileName's stringByReplacingOccurrencesOfString:(".001") withString:(""))
374    set ocidBaseFileName to ocidBaseFileName's stringByAppendingString:("_")
375  else
376    #よくあるICON系のファイル名にはこれでOK
377    set ocidBaseFileName to ocidFileNameArray's lastObject()
378    set ocidBaseFileName to (ocidFileName's stringByReplacingOccurrencesOfString:(ocidBaseFileName) withString:(""))
379  end if
380  #NSIMAGE
381  set ocidReadImage to refMe's NSImage's alloc()'s initWithContentsOfURL:(ocidFilePathURL)
382  set ocidImageSize to ocidReadImage's |size|()
383  set numPtW to ocidImageSize's width()
384  set numPtH to ocidImageSize's height()
385  #NSIMAGEREP
386  set ocidImageRepArray to ocidReadImage's representations()
387  set ocidImageRep to ocidImageRepArray's firstObject()
388  set numPxW to ocidImageRep's pixelsWide()
389  set numPxH to ocidImageRep's pixelsHigh()
390  #pxサイズの1/2のptサイズ
391  set numSetPtSizeW to (numPxW / 2) as integer
392  set numSetPtSizeH to (numPxH / 2) as integer
393  set ocidSetSize to refMe's NSSize's NSMakeSize(numSetPtSizeW, numSetPtSizeH)
394  #NSIMAGEサイズをセット
395  ocidImageRep's setSize:(ocidSetSize)
396  #NSDATAのPNGにして
397  set ocidImageType to (refMe's NSBitmapImageFileTypePNG)
398  set ocidProperty to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
399  (ocidProperty's setObject:(refMe's NSNumber's numberWithBool:false) forKey:(refMe's NSImageInterlaced))
400  (ocidProperty's setObject:(refMe's NSNumber's numberWithDouble:(1 / 2.2)) forKey:(refMe's NSImageGamma))
401  set ocidSaveImageData to ocidImageRep's representationUsingType:(ocidImageType) |properties|:(ocidProperty)
402  ##NSDataで上書き保存
403  set ocidOption to (refMe's NSDataWritingAtomic)
404  set listDone to ocidSaveImageData's writeToURL:(ocidFilePathURL) options:(ocidOption) |error| :(reference)
405  if (item 1 of listDone) is true then
406    log "保存OK"
407    #新しいファイルパス
408    set strNewFileName to ((ocidBaseFileName as text) & numSetPtSizeW & "x" & numSetPtSizeH & "@2x.png") as text
409    set ocidNewFilePathURL to ocidContainerDirPathURL's URLByAppendingPathComponent:(strNewFileName) isDirectory:(false)
410    #移動=リネーム
411    set appFileManager to refMe's NSFileManager's defaultManager()
412    set listRenameDone to (appFileManager's moveItemAtURL:(ocidFilePathURL) toURL:(ocidNewFilePathURL) |error| :(reference))
413    if (item 1 of listRenameDone) is true then
414      log "リネームOK"
415      return ocidNewFilePathURL
416    else if (item 1 of listRenameDone) is false then
417      log "リネーム失敗"
418      return false
419    end if
420  else if (item 1 of listDone) is false then
421    log "保存失敗"
422    return false
423  end if
424  log "処理失敗"
425  return false
426end doMakeRetinaImagePNG
427
428
429################################
430##SVGZの解凍用だが使わなかった
431################################
432
433to doExtractSvgz(argFilePath)
434  #解凍先テンポラリ
435  set appFileManager to refMe's NSFileManager's defaultManager()
436  set ocidTempDirURL to appFileManager's temporaryDirectory()
437  set ocidUUID to refMe's NSUUID's alloc()'s init()
438  set ocidUUIDString to ocidUUID's UUIDString
439  set ocidSaveDirPathURL to (ocidTempDirURL's URLByAppendingPathComponent:(ocidUUIDString) isDirectory:true)
440  set appFileManager to refMe's NSFileManager's defaultManager()
441  set ocidAttrDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
442  (ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions))
443  set listBoolMakeDir to (appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error| :(reference))
444  #
445  set strOrgFilePath to argFilePath as text
446  set ocidOrgFilePathStr to refMe's NSString's stringWithString:(strOrgFilePath)
447  set ocidOrgFilePath to ocidOrgFilePathStr's stringByStandardizingPath()
448  set ocidOrgBaseFilePath to ocidOrgFilePath's stringByDeletingPathExtension()
449  set ocidOrgFileName to ocidOrgBaseFilePath's lastPathComponent()
450  #
451  set ocidDistFilePath to ocidOrgBaseFilePath's stringByAppendingPathExtension:("svg")
452  set ocidDistFilePathURL to refMe's NSURL's alloc()'s initFileURLWithPath:(ocidDistFilePath) isDirectory:(false)
453  set strDistFilePath to ocidDistFilePathURL's |path| as text
454  #
455  set ocidSaveBaseFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(ocidOrgFileName) isDirectory:(false)
456  set ocidSaveFilePathURL to ocidSaveBaseFilePathURL's URLByAppendingPathExtension:("svg")
457  set strSaveFilePath to ocidSaveFilePathURL's |path| as text
458  #
459  set strCommandText to ("/usr/bin/gunzip -c \"" & strOrgFilePath & "\" > \"" & strSaveFilePath & "\"") as text
460  set strExec to ("/bin/zsh -c '" & strCommandText & "'") as text
461  try
462    do shell script strExec
463  on error
464    return false
465  end try
466  return strDistFilePath
467  
468end doExtractSvgz
AppleScriptで生成しました

|

SVG←→SVGZ


【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use scripting additions

property refMe : a reference to current application

on run
  
  set aliasIconPass to (POSIX file "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/MultipleItemsIcon.icns") as alias
  set strDialogText to "ドロップしても利用できます"
  set strTitleText to "画像ファイルを選んでください"
  set listButton to {"ファイルを選びます", "キャンセル"} as list
display dialog strDialogText buttons listButton default button 1 cancel button 2 with title strTitleText with icon aliasIconPass giving up after 1 with hidden answer
  
  set aliasDefaultLocation to (path to desktop folder from user domain) as alias
  set listChooseFileUTI to {"public.svg-image"}
  set strPromptText to "イメージファイルを選んでください" as text
  set strPromptMes to "イメージファイルを選んでください" as text
  set listAliasFilePath to (choose file strPromptMes with prompt strPromptText default location (aliasDefaultLocation) of type listChooseFileUTI with showing package contents, invisibles and multiple selections allowed) as list
  
  -->値をOpenに渡たす
open listAliasFilePath
end run


on open listAliasFilePath
  ##対象の拡張子のURLだけ格納するARRAY
  set ocidFilePathURLArrayM to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
  ##開いたエイリアスの数だけ々
  repeat with itemAliasFilePath in listAliasFilePath
    #パス処理
    set strFilePath to (POSIX path of itemAliasFilePath) as text
    set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePath))
    set ocidFilePath to ocidFilePathStr's stringByStandardizingPath
    set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath))
    #拡張子を小文字で取得して
    set ocidExtensionName to ocidFilePathURL's pathExtension()
    set strExtensionName to ocidExtensionName's lowercaseString() as text
    #対象の拡張子のURLだけARRAYに格納していく
    if strExtensionName is "svg" then
(ocidFilePathURLArrayM's addObject:(ocidFilePathURL))
    else if strExtensionName is "svgz" then
(ocidFilePathURLArrayM's addObject:(ocidFilePathURL))
    end if
  end repeat
  ##########################
  ##対象の拡張子のURLファイルの数だけ繰り返し
  repeat with itemArray in ocidFilePathURLArrayM
    #Arrayの中身はURLなので
    set ocidFilePathURL to itemArray
    #ファイル名
    set ocidFileName to ocidFilePathURL's lastPathComponent()
    #拡張子を小文字で取得
    set ocidExtensionName to ocidFilePathURL's pathExtension()
    set strExtensionName to ocidExtensionName's lowercaseString() as text
    #SVGZを解凍する
    if strExtensionName is "svgz" then
      #解凍先ディレクトリ 起動時に削除する項目
      set appFileManager to refMe's NSFileManager's defaultManager()
      set ocidTempDirURL to appFileManager's temporaryDirectory()
      set ocidUUID to refMe's NSUUID's alloc()'s init()
      set ocidUUIDString to ocidUUID's UUIDString
      set ocidSaveDirPathURL to (ocidTempDirURL's URLByAppendingPathComponent:(ocidUUIDString) isDirectory:true)
      set appFileManager to refMe's NSFileManager's defaultManager()
      set ocidAttrDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
      # 777-->511 755-->493 700-->448 766-->502
(ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions))
      set listBoolMakeDir to (appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference))
      #解凍先のファイルパス
      set ocidTmpFilePathURL to (ocidSaveDirPathURL's URLByAppendingPathComponent:(ocidFileName) isDirectory:false)
      #コマンド用にパステキストに
      set strFilePath to ocidFilePathURL's |path| as text
      set strTmpeFilePath to ocidTmpFilePathURL's |path| as text
      #
      set strCommandText to ("/usr/bin/gunzip -c \"" & strFilePath & "\" > \"" & strTmpeFilePath & "\"") as text
do shell script strCommandText
      set ocidFilePathURL to ocidTmpFilePathURL
    end if
    ####################################
    ##サイズ取得
    #ファイルを読み込み
    set listReadData to (refMe's NSXMLDocument's alloc()'s initWithContentsOfURL:(ocidFilePathURL) options:(refMe's NSXMLNodeOptionsNone) |error|:(reference))
    set ocidXmlDoc to (item 1 of listReadData)
    #ROOTエレメントを取得して
    set ocidRootElement to ocidXmlDoc's rootElement
    #viewBoxを取得
    set ocidViewBox to (ocidRootElement's attributeForName:("viewBox"))
    #テキストにして
    set ocidViewBoxStr to ocidViewBox's stringValue()
    #スペースを区切り文字でリストにして
    set ocidViewBoxArray to (ocidViewBoxStr's componentsSeparatedByString:(" "))
    #3番目と4番目が横縦ピクセルサイズ
    set ocidPixelWidth to (ocidViewBoxArray's objectAtIndex:(2))
    set ocidPixelHeight to (ocidViewBoxArray's objectAtIndex:(3))
    set numPixelWidth to ocidPixelWidth as integer
    set numPixelHeight to ocidPixelHeight as integer
    ##戻り値
    set strResponseText to ("W: " & numPixelWidth & "\nH: " & numPixelHeight & "\n<img src=\"パス\" width=\"" & numPixelWidth & "\" height=\"" & numPixelHeight & "\" alt=\"" & (ocidFileName as text) & "\">\n\nmax-width: " & numPixelWidth & "px;\nmax-height: " & numPixelHeight & "px;\n") as text
    
    #####ダイアログを前面に
    tell current application
      set strName to name as text
    end tell
    ####スクリプトメニューから実行したら
    if strName is "osascript" then
      tell application "Finder" to activate
    else
      tell current application to activate
    end if
    set aliasIconPath to POSIX file "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertNoteIcon.icns"
    ###ダイアログ
    set recordResult to (display dialog "SVGサイズ戻り値です" with title "戻り値です" default answer strResponseText buttons {"クリップボードにコピー", "キャンセル", "OK"} default button "OK" cancel button "キャンセル" giving up after 20 with icon aliasIconPath without hidden answer)
    ###クリップボードコピー
    if button returned of recordResult is "クリップボードにコピー" then
      set strText to text returned of recordResult as text
      ####ペーストボード宣言
      set appPasteboard to refMe's NSPasteboard's generalPasteboard()
      set ocidText to (refMe's NSString's stringWithString:(strText))
appPasteboard's clearContents()
(appPasteboard's setString:(ocidText) forType:(refMe's NSPasteboardTypeString))
    end if
    
    
  end repeat
end open


|

SVGの縦横サイズの取得(SVGZ対応)


【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use scripting additions

property refMe : a reference to current application

on run
  
  set aliasIconPass to (POSIX file "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/MultipleItemsIcon.icns") as alias
  set strDialogText to "ドロップしても利用できます"
  set strTitleText to "画像ファイルを選んでください"
  set listButton to {"ファイルを選びます", "キャンセル"} as list
display dialog strDialogText buttons listButton default button 1 cancel button 2 with title strTitleText with icon aliasIconPass giving up after 1 with hidden answer
  
  set aliasDefaultLocation to (path to desktop folder from user domain) as alias
  set listChooseFileUTI to {"public.svg-image"}
  set strPromptText to "イメージファイルを選んでください" as text
  set strPromptMes to "イメージファイルを選んでください" as text
  set listAliasFilePath to (choose file strPromptMes with prompt strPromptText default location (aliasDefaultLocation) of type listChooseFileUTI with showing package contents, invisibles and multiple selections allowed) as list
  
  -->値をOpenに渡たす
open listAliasFilePath
end run


on open listAliasFilePath
  ##対象の拡張子のURLだけ格納するARRAY
  set ocidFilePathURLArrayM to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
  ##開いたエイリアスの数だけ々
  repeat with itemAliasFilePath in listAliasFilePath
    #パス処理
    set strFilePath to (POSIX path of itemAliasFilePath) as text
    set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePath))
    set ocidFilePath to ocidFilePathStr's stringByStandardizingPath
    set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath))
    #拡張子を小文字で取得して
    set ocidExtensionName to ocidFilePathURL's pathExtension()
    set strExtensionName to ocidExtensionName's lowercaseString() as text
    #対象の拡張子のURLだけARRAYに格納していく
    if strExtensionName is "svg" then
(ocidFilePathURLArrayM's addObject:(ocidFilePathURL))
    else if strExtensionName is "svgz" then
(ocidFilePathURLArrayM's addObject:(ocidFilePathURL))
    end if
  end repeat
  ##########################
  ##対象の拡張子のURLファイルの数だけ繰り返し
  repeat with itemArray in ocidFilePathURLArrayM
    #Arrayの中身はURLなので
    set ocidFilePathURL to itemArray
    #ファイル名
    set ocidFileName to ocidFilePathURL's lastPathComponent()
    #拡張子を小文字で取得
    set ocidExtensionName to ocidFilePathURL's pathExtension()
    set strExtensionName to ocidExtensionName's lowercaseString() as text
    #SVGZを解凍する
    if strExtensionName is "svgz" then
      #解凍先ディレクトリ 起動時に削除する項目
      set appFileManager to refMe's NSFileManager's defaultManager()
      set ocidTempDirURL to appFileManager's temporaryDirectory()
      set ocidUUID to refMe's NSUUID's alloc()'s init()
      set ocidUUIDString to ocidUUID's UUIDString
      set ocidSaveDirPathURL to (ocidTempDirURL's URLByAppendingPathComponent:(ocidUUIDString) isDirectory:true)
      set appFileManager to refMe's NSFileManager's defaultManager()
      set ocidAttrDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
      # 777-->511 755-->493 700-->448 766-->502
(ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions))
      set listBoolMakeDir to (appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference))
      #解凍先のファイルパス
      set ocidTmpFilePathURL to (ocidSaveDirPathURL's URLByAppendingPathComponent:(ocidFileName) isDirectory:false)
      #コマンド用にパステキストに
      set strFilePath to ocidFilePathURL's |path| as text
      set strTmpeFilePath to ocidTmpFilePathURL's |path| as text
      #
      set strCommandText to ("/usr/bin/gunzip -c \"" & strFilePath & "\" > \"" & strTmpeFilePath & "\"") as text
do shell script strCommandText
      set ocidFilePathURL to ocidTmpFilePathURL
    end if
    ####################################
    ##サイズ取得
    #ファイルを読み込み
    set listReadData to (refMe's NSXMLDocument's alloc()'s initWithContentsOfURL:(ocidFilePathURL) options:(refMe's NSXMLNodeOptionsNone) |error|:(reference))
    set ocidXmlDoc to (item 1 of listReadData)
    #ROOTエレメントを取得して
    set ocidRootElement to ocidXmlDoc's rootElement
    #viewBoxを取得
    set ocidViewBox to (ocidRootElement's attributeForName:("viewBox"))
    #テキストにして
    set ocidViewBoxStr to ocidViewBox's stringValue()
    #スペースを区切り文字でリストにして
    set ocidViewBoxArray to (ocidViewBoxStr's componentsSeparatedByString:(" "))
    #3番目と4番目が横縦ピクセルサイズ
    set ocidPixelWidth to (ocidViewBoxArray's objectAtIndex:(2))
    set ocidPixelHeight to (ocidViewBoxArray's objectAtIndex:(3))
    set numPixelWidth to ocidPixelWidth as integer
    set numPixelHeight to ocidPixelHeight as integer
    ##戻り値
    set strResponseText to ("W: " & numPixelWidth & "\nH: " & numPixelHeight & "\n<img src=\"パス\" width=\"" & numPixelWidth & "\" height=\"" & numPixelHeight & "\" alt=\"" & (ocidFileName as text) & "\">\n\nmax-width: " & numPixelWidth & "px;\nmax-height: " & numPixelHeight & "px;\n") as text
    
    #####ダイアログを前面に
    tell current application
      set strName to name as text
    end tell
    ####スクリプトメニューから実行したら
    if strName is "osascript" then
      tell application "Finder" to activate
    else
      tell current application to activate
    end if
    set aliasIconPath to POSIX file "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertNoteIcon.icns"
    ###ダイアログ
    set recordResult to (display dialog "SVGサイズ戻り値です" with title "戻り値です" default answer strResponseText buttons {"クリップボードにコピー", "キャンセル", "OK"} default button "OK" cancel button "キャンセル" giving up after 20 with icon aliasIconPath without hidden answer)
    ###クリップボードコピー
    if button returned of recordResult is "クリップボードにコピー" then
      set strText to text returned of recordResult as text
      ####ペーストボード宣言
      set appPasteboard to refMe's NSPasteboard's generalPasteboard()
      set ocidText to (refMe's NSString's stringWithString:(strText))
appPasteboard's clearContents()
(appPasteboard's setString:(ocidText) forType:(refMe's NSPasteboardTypeString))
    end if
    
    
  end repeat
end open


|

SVGイメージのEpubフォルダを生成する


【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
(*
自炊用
画像ファイル=各ページ で
EPUBのコンテンツを生成します
出来上がったフォルダを
[ドロップレット]EPUB用zip圧縮(半角スペース対応)
https://quicktimer.cocolog-nifty.com/icefloe/2023/11/post-c6729c.html
圧縮してEPUBの出来上がりになります
*)
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use scripting additions
property refMe : a reference to current application


#############################
### 設定項目
###タイトル
set strDocumentTitle to ("ドキュメントのタイトル") as text

###一般的には著者 または 作成者
set strAuthor to ("com.cocolog-nifty.quicktimer") as text

###表紙のラベル (この設定は表紙なしなので設定しなくてもOK)
set strLabelTitle to ("表紙") as text

###表紙ページを付与するか trueで表紙ページあり falseで表紙ページなし
set boolCoverPage to true as boolean

### 左開き? ltr (left-to-right) 右開き? rtl (right-to-left)
# set strPageProgression to ("ltr") as text
set strPageProgression to ("rtl") as text

###見開き調整 trueで表紙をコンテンツから抜いて1ページずらします
##見開きページがズレる場合に true を入れてください
set boolProgression to false as boolean


#############################
### ここから本処理
(*
大まかな手順
【1】ROOT フォルダ:META-INF OPS ファイル:mimetype
【1−2】mimetype

【2】META-INF ファイル: container.xml com.apple.ibooks.display-options.xml
【2−1】container.xml
【2−2】com.apple.ibooks.display-options.xml

【3】OPS
【3−1】css book.css
【3−2】js book.js
【3−3】images
【3−4】toc.ncx
【3−5】content.opf
【3−6】toc.xhtml
【3−7】page-XXXX.xhtml
【3−8】cover.xhtml
*)
######
##設定項目(詳細)
##XMLファイル名の接頭語
set strBaseFileName to ("page-") as text
##コピー後のファイル名の接頭名 コピー後のファイル名を固定にする事で後処理を少し簡素化
set strBaseImageFileName to ("Image_") as text


#############################
###ドキュメントのUUID
set ocidUUID to refMe's NSUUID's alloc()'s init()
set strUUID to ocidUUID's UUIDString as text

#############################
###ダイアログ
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
############ デフォルトロケーション
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias
############UTIリスト
set listUTI to {"public.svg-image"}
set strMes to ("画像ファイルを選んでください") as text
set strPrompt to ("画像ファイルを選んでください") as text
try
  ### ファイル選択
  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
on error
log "エラーしました"
return "エラーしました"
end try
if listAliasFilePath is {} then
return "選んでください"
end if

##パス 保存先パス
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
###デスクトップ
set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
###設定項目の名称がフォルダ名
set ocidEpubDirPathURL to ocidDesktopDirPathURL's URLByAppendingPathComponent:(strDocumentTitle)
set ocidEpubDirPath to ocidEpubDirPathURL's |path|()
##############################
##必要なフォルダを作る
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidAttrDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
##アクセス権755この値は後でも使う
(ocidAttrDict's setValue:(493) forKey:(refMe's NSFilePosixPermissions))
##フォルダのパスのリスト
set listDirName to {"OPS", "OPS/css", "OPS/images", "OPS/js", "META-INF"} as list
##stringsByAppendingPathsでARRAYにする
set ocidSubPathArray to ocidEpubDirPath's stringsByAppendingPaths:(listDirName)
##ARRAYの分だけ
repeat with itemSubPathArray in ocidSubPathArray
  ##フォルダを作る
  set listBoolMakeDir to (appFileManager's createDirectoryAtPath:(itemSubPathArray) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference))
end repeat
#################################################################################
### 【1】ROOT フォルダ:META-INF OPS ファイル:mimetype
set ocidEpubDirPathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidEpubDirPath) isDirectory:true)
### 【1−2】mimetype
##保存先パス
set ocidMimetypeFilePathURL to ocidEpubDirPathURL's URLByAppendingPathComponent:("mimetype") isDirectory:false
##内容
set strMimetype to ("application/epub+zip") as text
set ocidMimetype to refMe's NSString's stringWithString:(strMimetype)
##ファイルに保存して
set listDone to ocidMimetype's writeToURL:(ocidMimetypeFilePathURL) atomically:true encoding:(refMe's NSUTF8StringEncoding) |error|:(reference)
##アクセス権755を指定する
set listDone to appFileManager's setAttributes:(ocidAttrDict) ofItemAtPath:(ocidMimetypeFilePathURL's |path|) |error|:(reference)
#################################################################################
### 【3】OPS
set ocidOPSDirPathURL to ocidEpubDirPathURL's URLByAppendingPathComponent:("OPS") isDirectory:true
######◆ 【3−1】css book.css
##フォルダのパス
set ocidCssDirPathURL to ocidOPSDirPathURL's URLByAppendingPathComponent:("css") isDirectory:true
###ファイルのパス
set ocidCssFilePathURL to ocidCssDirPathURL's URLByAppendingPathComponent:("book.css") isDirectory:false
##ファイルの中身
set strCssContents to ("body { margin: 0; padding: 0; border: 0;}") as text
set ocidCssContents to refMe's NSString's stringWithString:(strCssContents)
##保存
set listDone to ocidCssContents's writeToURL:(ocidCssFilePathURL) atomically:true encoding:(refMe's NSUTF8StringEncoding) |error|:(reference)
##アクセス権
set listDone to appFileManager's setAttributes:(ocidAttrDict) ofItemAtPath:(ocidCssFilePathURL's |path|) |error|:(reference)
######◆ 【3−2】js book.js
##フォルダのパス
set ocidJsDirPathURL to ocidOPSDirPathURL's URLByAppendingPathComponent:("js") isDirectory:true
###ファイルのパス
set ocidJsFilePathURL to ocidJsDirPathURL's URLByAppendingPathComponent:("book.js") isDirectory:false
##ファイルの中身
set strJsContents to ("function Body_onLoad() {}") as text
set ocidJsContents to refMe's NSString's stringWithString:(strJsContents)
##保存
set listDone to ocidJsContents's writeToURL:(ocidJsFilePathURL) atomically:true encoding:(refMe's NSUTF8StringEncoding) |error|:(reference)
##アクセス権
set listDone to appFileManager's setAttributes:(ocidAttrDict) ofItemAtPath:(ocidJsFilePathURL's |path|) |error|:(reference)
######◆ 【3−3】images イメージファイルをコピーします
set ocidImagesDirPathURL to ocidOPSDirPathURL's URLByAppendingPathComponent:("images") isDirectory:true

set numCntPage to 1 as integer
set numCntAllImage to (count of listAliasFilePath) as integer
set listImageFileName to {} as list
##画像ファイルの数だけ繰り返し
repeat with itemAliasFilePath in listAliasFilePath
  ##パス
  set aliasFilePath to itemAliasFilePath as alias
  set strFilePath to (POSIX path of aliasFilePath) as text
  set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePath))
  set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
  set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)
  ##拡張子
  set ocidExtensionName to ocidFilePathURL's pathExtension()
  ###コピー後の画像ファイルは連番処理 四桁のゼロパディング
  set strZeroSup to "0000" as text
  set strSeroSup to (strZeroSup & (numCntPage as text)) as text
  set strSeroSup to (text -4 through -1 of strSeroSup) as text
  set strFileName to (strBaseImageFileName & strSeroSup) as text
  ##コピー先URL
  set ocidBaseFilePathURL to (ocidImagesDirPathURL's URLByAppendingPathComponent:(strFileName))
  set ocidSaveFilePathURL to (ocidBaseFilePathURL's URLByAppendingPathExtension:(ocidExtensionName))
  ##ファイル名のリストを作っておく
  set ocidImageFileName to ocidSaveFilePathURL's lastPathComponent()
  set strImageFileName to ocidImageFileName as text
  set end of listImageFileName to strImageFileName
  ###コピー
  set appFileManager to refMe's NSFileManager's defaultManager()
  set listDone to (appFileManager's copyItemAtURL:(ocidFilePathURL) toURL:(ocidSaveFilePathURL) |error|:(reference))
  ##カウントアップ
  set numCntPage to numCntPage + 1 as integer
end repeat


#################################
###◆ 【3−7】page-XXXX.xhtml
##配置オブジェクトが画像1つ限定なのでシンプルな構造
##【3−7−A】 root エレメント 【3−7−B】 head エレメント 【3−7−C】 body エレメント
##カウンター
set numCntPage to 1 as integer
##総画像ファイルする右=ページ数
set numCntAllImage to (count of listAliasFilePath) as integer
##画像の数だけ繰り返し
repeat numCntAllImage times
  ###ファイルは連番処理 四桁のゼロパディング
  set strZeroSup to "0000" as text
  set strSeroSup to (strZeroSup & (numCntPage as text)) as text
  set strSeroSup to (text -4 through -1 of strSeroSup) as text
  set strFileName to (strBaseFileName & strSeroSup & ".xhtml") as text
  ##XHTMLのパス
  set ocidXHTMLFilePathURL to ocidOPSDirPathURL's URLByAppendingPathComponent:(strFileName) isDirectory:false
  ##配置画像
  ##不具合の元かもしれないが拡張子判定する方法が見つからなかった
  set strImageName to (item numCntPage of listImageFileName)
  set ocidImagesFilePathURL to ocidImagesDirPathURL's URLByAppendingPathComponent:(strImageName) isDirectory:false
  #ファイルを読み込み
  set listReadData to (refMe's NSXMLDocument's alloc()'s initWithContentsOfURL:(ocidFilePathURL) options:(refMe's NSXMLNodeOptionsNone) |error|:(reference))
  set ocidXmlDoc to (item 1 of listReadData)
  #ROOTエレメントを取得して
  set ocidRootElement to ocidXmlDoc's rootElement
  #viewBoxを取得
  set ocidViewBox to (ocidRootElement's attributeForName:("viewBox"))
  #テキストにして
  set ocidViewBoxStr to ocidViewBox's stringValue()
  #スペースを区切り文字でリストにして
  set ocidViewBoxArray to (ocidViewBoxStr's componentsSeparatedByString:(" "))
  #3番目と4番目が横縦ピクセルサイズ
  set strPixelsWidth to (ocidViewBoxArray's objectAtIndex:(2)) as text
  set strPixelsHeight to (ocidViewBoxArray's objectAtIndex:(3)) as text
  
  ########
  ##◆【3−7−A】 root エレメント
  set ocidRootElement to refMe's NSXMLElement's alloc()'s initWithName:"html"
ocidRootElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("xml:lang") stringValue:("ja"))
ocidRootElement's addNamespace:(refMe's NSXMLNode's namespaceWithName:("") stringValue:("http://www.w3.org/1999/xhtml"))
  ########
  ##◆【3−7−B】 head エレメント
  set ocidHeadElement to refMe's NSXMLElement's alloc()'s initWithName:("head")
  #CSS
  set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("link")
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("rel") stringValue:("stylesheet"))
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("href") stringValue:("css/book.css"))
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("type") stringValue:("text/css"))
ocidHeadElement's addChild:(ocidMetaElement)
  #JS
  set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("script")
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("src") stringValue:("js/book.js"))
ocidHeadElement's addChild:(ocidMetaElement)
  #文字コード
  set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("meta")
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("charset") stringValue:("UTF-8"))
ocidHeadElement's addChild:(ocidMetaElement)
  #タイトル
  set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("title")
  set strPageTitle to ("Page : " & strSeroSup) as text
ocidMetaElement's setStringValue:(strPageTitle)
ocidHeadElement's addChild:(ocidMetaElement)
  #EPUBドキュメントのUUID
  set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("meta")
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("name") stringValue:("EPB-UUID"))
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("content") stringValue:(strUUID))
ocidHeadElement's addChild:(ocidMetaElement)
  #ビューポイント ここで画像のサイズ指定=全画面
  set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("meta")
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("name") stringValue:("viewport"))
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("content") stringValue:("width=" & strPixelsWidth & ",height=" & strPixelsHeight & ", initial-scale=1.0"))
ocidHeadElement's addChild:(ocidMetaElement)
  ########
  ##◆【3−7−C】 body エレメント
  set ocidBodyElement to refMe's NSXMLElement's alloc()'s initWithName:("body")
ocidBodyElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("onload") stringValue:("Body_onLoad()"))
  #開き方向指定
ocidBodyElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("dir") stringValue:(strPageProgression))
  #一番外側のDIV要素
  set ocidOutDiivElement to refMe's NSXMLElement's alloc()'s initWithName:("div")
ocidOutDiivElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("style") stringValue:("position:absolute;left:0;top:0;width: " & strPixelsWidth & "px;height:" & strPixelsHeight & "px;"))
  #imgタグ
  set ocidImgElement to refMe's NSXMLElement's alloc()'s initWithName:("img")
  set strPath to ("images/" & strImageName) as text
ocidImgElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("src") stringValue:(strPath))
ocidImgElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("alt") stringValue:(strFileName))
ocidImgElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("style") stringValue:("object-fit: cover;width: " & strPixelsWidth & "px;height:" & strPixelsHeight & "px;"))
  #imgタグをDIVにセット
ocidOutDiivElement's addChild:(ocidImgElement)
  #DIVをbodyにセット
ocidBodyElement's addChild:(ocidOutDiivElement)
  ########
  ##【3−7−B】のheadエレメントをAのROOTにセット
ocidRootElement's addChild:(ocidHeadElement)
  ##【3−7−C】 bodyエレメントをAのROOTにセット
ocidRootElement's addChild:(ocidBodyElement)
  ## ↑からのROOTエレメントをセットしてXMLとする
  set ocidOutPutXML to refMe's NSXMLDocument's alloc()'s initWithRootElement:(ocidRootElement)
ocidOutPutXML's setVersion:"1.0"
ocidOutPutXML's setCharacterEncoding:"UTF-8"
  #XMLをテキストにして
  set ocidSaveStrings to ocidOutPutXML's XMLString()
  ###改行コードを指定して
ocidSaveStrings's appendString:"\n"
  ##保存
  set listWritetoUrlArray to ocidSaveStrings's writeToURL:(ocidXHTMLFilePathURL) atomically:true encoding:(refMe's NSUTF8StringEncoding) |error|:(reference)
  ##
  set numCntPage to numCntPage + 1 as integer
end repeat

#################################
###◆【3−8】cover.xhtml いわゆる表紙ページ
# cover-page と cover-imageがあるがここではcover-pageを生成する
#保存パス
set ocidXHTMLFilePathURL to ocidOPSDirPathURL's URLByAppendingPathComponent:("cover.xhtml") isDirectory:false
# 表紙イメージ=1ページ目の画像
set aliasCoverImageFilePath to (item 1 of listAliasFilePath) as alias
set strCoverImageFilePath to (POSIX path of aliasCoverImageFilePath) as text
set ocidCoverImageFilePathStr to refMe's NSString's stringWithString:(strCoverImageFilePath)
set ocidCoverImageFilePath to ocidCoverImageFilePathStr's stringByStandardizingPath()
set ocidCoverImageFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidCoverImageFilePath) isDirectory:false)
set strExtensionName to (ocidCoverImageFilePathURL's pathExtension()) as text
#ファイルを読み込み
set listReadData to (refMe's NSXMLDocument's alloc()'s initWithContentsOfURL:(ocidCoverImageFilePathURL) options:(refMe's NSXMLNodeOptionsNone) |error|:(reference))
set ocidXmlDoc to (item 1 of listReadData)
#ROOTエレメントを取得して
set ocidRootElement to ocidXmlDoc's rootElement
#viewBoxを取得
set ocidViewBox to (ocidRootElement's attributeForName:("viewBox"))
#テキストにして
set ocidViewBoxStr to ocidViewBox's stringValue()
#スペースを区切り文字でリストにして
set ocidViewBoxArray to (ocidViewBoxStr's componentsSeparatedByString:(" "))
#3番目と4番目が横縦ピクセルサイズ
set strPixelsWidth to (ocidViewBoxArray's objectAtIndex:(2)) as text
set strPixelsHeight to (ocidViewBoxArray's objectAtIndex:(3)) as text


#######【3−8-A】ルートエレメント XHTMLのルートエレメント
set ocidRootElement to refMe's NSXMLElement's alloc()'s initWithName:"html"
#ネームスペースの追加
ocidRootElement's addNamespace:(refMe's NSXMLNode's namespaceWithName:("") stringValue:("http://www.w3.org/1999/xhtml"))
ocidRootElement's addNamespace:(refMe's NSXMLNode's namespaceWithName:("epub") stringValue:("http://www.idpf.org/2007/ops"))
#アトリビュートの追加
ocidRootElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("xml:lang") stringValue:("ja"))
ocidRootElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("epub:prefix") stringValue:("ibooks: http://vocabulary.itunes.apple.com/rdf/ibooks/vocabulary-extensions-1.0/"))
#####【3−6-B】 headエレメント
set ocidHeadElement to refMe's NSXMLElement's alloc()'s initWithName:("head")
#タイトル
set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("title")
ocidMetaElement's setStringValue:("表紙:Cover Page")
ocidHeadElement's addChild:(ocidMetaElement)
#スタイルシートへのリンク
set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("link")
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("rel") stringValue:("stylesheet"))
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("href") stringValue:("css/book.css"))
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("type") stringValue:("text/css"))
ocidHeadElement's addChild:(ocidMetaElement)
#Jsへのリンク
set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("script")
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("src") stringValue:("js/book.js"))
ocidHeadElement's addChild:(ocidMetaElement)
#文字コード宣言
set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("meta")
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("charset") stringValue:("UTF-8"))
ocidHeadElement's addChild:(ocidMetaElement)
#UUID設定
set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("meta")
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("name") stringValue:("EPB-UUID"))
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("content") stringValue:(strUUID))
ocidHeadElement's addChild:(ocidMetaElement)
#ビューポイント
set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("meta")
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("name") stringValue:("viewport"))
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("content") stringValue:("width=" & strPixelsWidth & ",height=" & strPixelsHeight & ", initial-scale=1.0"))
ocidHeadElement's addChild:(ocidMetaElement)
######【3−8-C】ボディエレメント
set ocidBodyElement to refMe's NSXMLElement's alloc()'s initWithName:("body")
ocidBodyElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("onload") stringValue:("Body_onLoad()"))
#開き方向
ocidBodyElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("dir") stringValue:(strPageProgression))
#
set ocidOutDiivElement to refMe's NSXMLElement's alloc()'s initWithName:("div")
ocidOutDiivElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("style") stringValue:("position:absolute;left:0;top:0;width: " & strPixelsWidth & "px;height:" & strPixelsHeight & "px;"))
##
set ocidImgElement to refMe's NSXMLElement's alloc()'s initWithName:("img")
set strImageName to (strBaseImageFileName & "0001." & strExtensionName) as text
set strPath to ("images/" & strImageName) as text
ocidImgElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("src") stringValue:(strPath))
ocidImgElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("alt") stringValue:(strFileName))
ocidImgElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("style") stringValue:("object-fit: cover;width: " & strPixelsWidth & "px;height:" & strPixelsHeight & "px;"))
ocidOutDiivElement's addChild:(ocidImgElement)
ocidBodyElement's addChild:(ocidOutDiivElement)
####
#【3−8-B】 head を【3−8-A】 ルートエレメントに追加
ocidRootElement's addChild:(ocidHeadElement)
#【3−8-C】 body を【3−8-A】ルートエレメントに追加
ocidRootElement's addChild:(ocidBodyElement)
## ↑からのROOTエレメントをセットしてXMLとする
set ocidOutPutXML to refMe's NSXMLDocument's alloc()'s initWithRootElement:(ocidRootElement)
ocidOutPutXML's setVersion:"1.0"
ocidOutPutXML's setCharacterEncoding:"UTF-8"
###テキストにして
set ocidSaveStrings to ocidOutPutXML's XMLString()
###改行コードを指定して
ocidSaveStrings's appendString:"\n"
##保存
set listDone to ocidSaveStrings's writeToURL:(ocidXHTMLFilePathURL) atomically:true encoding:(refMe's NSUTF8StringEncoding) |error|:(reference)
#################################
###◆ 【3−6】toc.xhtml いわゆる目次
#【3−6-B】 head 【3−6-C】 body
#保存パス
set ocidXHTMLFilePathURL to ocidOPSDirPathURL's URLByAppendingPathComponent:("toc.xhtml") isDirectory:false
#【3−6-A】ルートエレメント XHTMLのルートエレメント
set ocidRootElement to refMe's NSXMLElement's alloc()'s initWithName:"html"
#ネームスペースの追加
ocidRootElement's addNamespace:(refMe's NSXMLNode's namespaceWithName:("") stringValue:("http://www.w3.org/1999/xhtml"))
ocidRootElement's addNamespace:(refMe's NSXMLNode's namespaceWithName:("epub") stringValue:("http://www.idpf.org/2007/ops"))
#アトリビュートの追加
ocidRootElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("xml:lang") stringValue:("ja"))
ocidRootElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("epub:prefix") stringValue:("ibooks: http://vocabulary.itunes.apple.com/rdf/ibooks/vocabulary-extensions-1.0/"))
#####【3−6-B】 headエレメント
set ocidHeadElement to refMe's NSXMLElement's alloc()'s initWithName:("head")
#タイトル
set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("title")
ocidMetaElement's setStringValue:("目次:Table of Contents")
ocidHeadElement's addChild:(ocidMetaElement)
#スタイルシートへのリンク
set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("link")
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("rel") stringValue:("stylesheet"))
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("href") stringValue:("css/book.css"))
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("type") stringValue:("text/css"))
ocidHeadElement's addChild:(ocidMetaElement)
#文字コード宣言
set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("meta")
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("charset") stringValue:("UTF-8"))
ocidHeadElement's addChild:(ocidMetaElement)
#UUID設定
set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("meta")
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("name") stringValue:("EPB-UUID"))
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("content") stringValue:(strUUID))
ocidHeadElement's addChild:(ocidMetaElement)
#ビューポイント
set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("meta")
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("name") stringValue:("viewport"))
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("content") stringValue:("width=device-width, initial-scale=1.0"))
ocidHeadElement's addChild:(ocidMetaElement)
####【3−6-C】 body
set ocidBodyElement to refMe's NSXMLElement's alloc()'s initWithName:("body")
#bodyエレメントに開き方向のアトリビュート
ocidBodyElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("dir") stringValue:(strPageProgression))
#タイトルをH1で入れて
set ocidBodyItem to refMe's NSXMLElement's alloc()'s initWithName:("h1")
ocidBodyItem's setStringValue:(strDocumentTitle)
ocidBodyElement's addChild:(ocidBodyItem)
#区切り線
set ocidBodyItem to refMe's NSXMLElement's alloc()'s initWithName:("hr")
ocidBodyElement's addChild:(ocidBodyItem)
#メインの要素
set ocidBodyItem to refMe's NSXMLElement's alloc()'s initWithName:("div")
ocidBodyItem's addAttribute:(refMe's NSXMLNode's attributeWithName:("class") stringValue:("nav-body"))
ocidBodyElement's addChild:(ocidBodyItem)
#ナビ
set ocidNavItem to refMe's NSXMLElement's alloc()'s initWithName:("nav")
ocidNavItem's addAttribute:(refMe's NSXMLNode's attributeWithName:("epub:type") stringValue:("toc"))
ocidNavItem's addAttribute:(refMe's NSXMLNode's attributeWithName:("id") stringValue:("toc"))
#リスト
set ocidNavOL to refMe's NSXMLElement's alloc()'s initWithName:("ol")
#番号初期化
set numCntPage to 1 as integer
#総ページ数の数だけ繰り返し
repeat numCntAllImage times
  ###画像ファイルは連番処理 四桁のゼロパディング
  set strZeroSup to "0000" as text
  set strSeroSup to (strZeroSup & (numCntPage as text)) as text
  set strSeroSup to (text -4 through -1 of strSeroSup) as text
  set strLinkFileName to (strBaseFileName & strSeroSup) as text
  set strFileName to (strBaseFileName & strSeroSup & ".xhtml") as text
  ####
  set ocidNavLI to refMe's NSXMLElement's alloc()'s initWithName:("li")
  set ocidNavA to refMe's NSXMLElement's alloc()'s initWithName:("a")
ocidNavA's addAttribute:(refMe's NSXMLNode's attributeWithName:("href") stringValue:(strFileName))
ocidNavA's setStringValue:(strLinkFileName)
ocidNavLI's addChild:(ocidNavA)
ocidNavOL's addChild:(ocidNavLI)
  set numCntPage to numCntPage + 1 as integer
end repeat
##リストに表紙ページを追加
set ocidNavLI to refMe's NSXMLElement's alloc()'s initWithName:("li")
set ocidNavA to refMe's NSXMLElement's alloc()'s initWithName:("a")
ocidNavA's addAttribute:(refMe's NSXMLNode's attributeWithName:("href") stringValue:("cover.xhtml"))
ocidNavA's addAttribute:(refMe's NSXMLNode's attributeWithName:("epub:type") stringValue:("ibooks:reader-start-page"))
ocidNavA's setStringValue:("Cover Page")
ocidNavLI's addChild:(ocidNavA)
ocidNavOL's addChild:(ocidNavLI)
#リストに目次を追加
set ocidNavLI to refMe's NSXMLElement's alloc()'s initWithName:("li")
set ocidNavA to refMe's NSXMLElement's alloc()'s initWithName:("a")
ocidNavA's addAttribute:(refMe's NSXMLNode's attributeWithName:("href") stringValue:("toc.xhtml"))
ocidNavA's addAttribute:(refMe's NSXMLNode's attributeWithName:("epub:type") stringValue:("toc"))
ocidNavA's setStringValue:("Table of Contents")
ocidNavLI's addChild:(ocidNavA)
ocidNavOL's addChild:(ocidNavLI)
#出来上がったリストをbodyに追加
ocidNavItem's addChild:(ocidNavOL)
ocidBodyItem's addChild:(ocidNavItem)
####
#【3−6-B】 head を【3−6-A】 ルートエレメントに追加
ocidRootElement's addChild:(ocidHeadElement)
#【3−6-C】 body を【3−6-A】ルートエレメントに追加
ocidRootElement's addChild:(ocidBodyElement)
## ↑からのROOTエレメントをセットしてXMLとする
set ocidOutPutXML to refMe's NSXMLDocument's alloc()'s initWithRootElement:(ocidRootElement)
ocidOutPutXML's setVersion:"1.0"
ocidOutPutXML's setCharacterEncoding:"UTF-8"
###テキストにして
set ocidSaveStrings to ocidOutPutXML's XMLString()
###改行コードを指定して
ocidSaveStrings's appendString:"\n"
##保存
set listDone to ocidSaveStrings's writeToURL:(ocidXHTMLFilePathURL) atomically:true encoding:(refMe's NSUTF8StringEncoding) |error|:(reference)

#############################################
###◆【3−5】content.opf
##【B】メタ情報のheadからなる 【C】各種コンテンツへのパス manifest と 【D】コンテンツの配置 spine  【E】ガイドguide
##Pageの場合
## set ocidOptFilePathURL to ocidOPSDirPathURL's URLByAppendingPathComponent:("epb.opf") isDirectory:false
##一般的な命名
set ocidOptFilePathURL to ocidOPSDirPathURL's URLByAppendingPathComponent:("content.opf") isDirectory:false
##【A】ルートエレメント
set ocidRootElement to refMe's NSXMLElement's alloc()'s initWithName:"package"
#アトリビュートを追加
ocidRootElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("version") stringValue:("3.0"))
ocidRootElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("unique-identifier") stringValue:("BookId"))
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/#"))
#ネームスペースを追加
ocidRootElement's addNamespace:(refMe's NSXMLNode's namespaceWithName:("") stringValue:("http://www.idpf.org/2007/opf"))
ocidRootElement's addNamespace:(refMe's NSXMLNode's namespaceWithName:("ibooks") stringValue:("http://vocabulary.itunes.apple.com/rdf/ibooks/vocabulary-extensions-1.0/"))
##################
#【B】メタ情報のhead
set ocidMetaDataElement to refMe's NSXMLElement's alloc()'s initWithName:("metadata")
ocidMetaDataElement's addNamespace:(refMe's NSXMLNode's namespaceWithName:("dc") stringValue:("http://purl.org/dc/elements/1.1/"))
ocidMetaDataElement's addNamespace:(refMe's NSXMLNode's namespaceWithName:("opf") stringValue:("http://www.idpf.org/2007/opf"))
#◆【B-1】タイトル
set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("dc:title")
ocidMetaElement's setStringValue:(strDocumentTitle)
ocidMetaDataElement's addChild:(ocidMetaElement)
#◆【B-2】作成者 著者
set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("dc:creator")
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("id") stringValue:("creator"))
ocidMetaElement's setStringValue:(strAuthor)
ocidMetaDataElement's addChild:(ocidMetaElement)
#◆【B-3】UUID
set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("dc:identifier")
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("id") stringValue:("BookId"))
ocidMetaElement's setStringValue:(strUUID)
ocidMetaDataElement's addChild:(ocidMetaElement)
#◆【B-4】言語
set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("dc:language")
ocidMetaElement's setStringValue:("ja")
ocidMetaDataElement's addChild:(ocidMetaElement)
#◆【B-5】作成日
set strSetDate to doGetDateNo("yyyy-MM-dd") as text
set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("dc:date")
ocidMetaElement's setStringValue:(strSetDate)
ocidMetaDataElement's addChild:(ocidMetaElement)
#◆【B-6】修正日
set strSetDate to doGetDateNo("yyyy-MM-dd'T'HH:mm:ss'Z'") as text
set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("dc:modified")
ocidMetaElement's setStringValue:(strSetDate)
ocidMetaDataElement's addChild:(ocidMetaElement)
#◆【B-7】コンテンツのプロパティ レイアウト
set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("meta")
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("property") stringValue:("rendition:layout"))
##リフロータイプのレイアウト 柔軟な表示形式 文字中心なものに最適
# ocidMetaElement's setStringValue:("reflowable")
##固定型のレイアウト 画面サイズに依存しない表示 画面のレイアウトを優先したい場合
# ocidMetaElement's setStringValue:("fixed")
##事前にページ化されたレイアウト ページベースの表示形式 画像コンテンツに最適
ocidMetaElement's setStringValue:("pre-paginated")
ocidMetaDataElement's addChild:(ocidMetaElement)
#◆【B-8】コンテンツのプロパティ スプレッド 開き方
set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("meta")
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("property") stringValue:("rendition:spread"))
##デバイスの向きに依存しない
ocidMetaElement's setStringValue:("both")
##横
#ocidMetaElement's setStringValue:("landscape")
##縦 非推奨
#ocidMetaElement's setStringValue:("portrait")
##単ページ
##ocidMetaElement's setStringValue:("none")
##自動
##ocidMetaElement's setStringValue:("auto")
ocidMetaDataElement's addChild:(ocidMetaElement)
#◆【B-9】向き
set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("meta")
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("property") stringValue:("rendition:orientation"))
#自動
ocidMetaElement's setStringValue:("auto")
##横
#ocidMetaElement's setStringValue:("landscape")
##縦
#ocidMetaElement's setStringValue:("portrait")
ocidMetaDataElement's addChild:(ocidMetaElement)
##表紙の有無での分岐
if boolCoverPage is true then
  set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("meta")
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("name") stringValue:("cover"))
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("content") stringValue:("cover-image"))
ocidMetaDataElement's addChild:(ocidMetaElement)
end if

##################
### 【C】各種コンテンツへのパス manifest
##manifestのROOTエレメント
set ocidManifestElement to refMe's NSXMLElement's alloc()'s initWithName:("manifest")
#CSS追加
set ocidItemElement to refMe's NSXMLElement's alloc()'s initWithName:("item")
ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("id") stringValue:("stylesheet"))
ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("href") stringValue:("css/book.css"))
ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("media-type") stringValue:("text/css"))
ocidManifestElement's addChild:(ocidItemElement)
#JS追加
set ocidItemElement to refMe's NSXMLElement's alloc()'s initWithName:("item")
ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("id") stringValue:("javascript"))
ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("href") stringValue:("js/book.js"))
ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("media-type") stringValue:("text/javascript"))
ocidManifestElement's addChild:(ocidItemElement)
#NCX追加
set ocidItemElement to refMe's NSXMLElement's alloc()'s initWithName:("item")
ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("id") stringValue:("ncx"))
ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("href") stringValue:("toc.ncx"))
ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("media-type") stringValue:("application/x-dtbncx+xml"))
ocidManifestElement's addChild:(ocidItemElement)
#目次追加
set ocidItemElement to refMe's NSXMLElement's alloc()'s initWithName:("item")
ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("id") stringValue:("toc"))
ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("href") stringValue:("toc.xhtml"))
ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("media-type") stringValue:("application/x-dtbncx+xml"))
ocidManifestElement's addChild:(ocidItemElement)
##表紙 表示画像
if boolCoverPage is true then
  ##表紙ページ設定
  set ocidItemElement to refMe's NSXMLElement's alloc()'s initWithName:("item")
ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("id") stringValue:("cover"))
ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("href") stringValue:("cover.xhtml"))
ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("media-type") stringValue:("application/x-dtbncx+xml"))
ocidManifestElement's addChild:(ocidItemElement)
  ##表紙画像
  set ocidExtensionName to ocidCoverImageFilePathURL's pathExtension()
  ####拡張子からUTI取得
  set ocidUTType to (refMe's UTType's typeWithFilenameExtension:(ocidExtensionName))
  set ocidFileMimeType to ocidUTType's preferredMIMEType()
  ##MimeTypeを取得してから
  set strFileMimeType to ocidFileMimeType as text
  #設定
  set strCoverImageFileName to (strBaseImageFileName & "0001." & (ocidExtensionName as text)) as text
  set strHref to ("images/" & strCoverImageFileName) as text
  set ocidItemElement to refMe's NSXMLElement's alloc()'s initWithName:("item")
ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("id") stringValue:("cover-image"))
ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("href") stringValue:(strHref))
ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("media-type") stringValue:(strFileMimeType))
ocidManifestElement's addChild:(ocidItemElement)
end if


set numCntPage to 1 as integer
repeat with itemAliasFilePath in listAliasFilePath
  set aliasFilePath to itemAliasFilePath as alias
  set strFilePath to (POSIX path of aliasFilePath) as text
  set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePath))
  set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
  set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)
  set ocidExtensionName to ocidFilePathURL's pathExtension()
  ####拡張子からUTI取得
  set ocidUTType to (refMe's UTType's typeWithFilenameExtension:(ocidExtensionName))
  set ocidFileMimeType to ocidUTType's preferredMIMEType()
  set strFileMimeType to ocidFileMimeType as text
  ###画像ファイルは連番処理 四桁のゼロパディング
  set strZeroSup to "0000" as text
  set strSeroSup to (strZeroSup & (numCntPage as text)) as text
  set strSeroSup to (text -4 through -1 of strSeroSup) as text
  #IDを定義
  set strBaseImageFileName to ("dataItem") as text
  set strFileName to (strBaseImageFileName & strSeroSup) as text
  ##メディア要素(イメージファイル)
  #itemエレメント
  set ocidItemElement to (refMe's NSXMLElement's alloc()'s initWithName:("item"))
(ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("id") stringValue:(strFileName)))
  #パス
  set strSetValue to ("images/Image_" & strSeroSup & "." & (ocidExtensionName as text)) as text
(ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("href") stringValue:(strSetValue)))
(ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("media-type") stringValue:(strFileMimeType)))
(ocidManifestElement's addChild:(ocidItemElement))
  ##ページ要素(XHTMLファイル)
  set strBaseFileName to ("page-") as text
  set strFileName to (strBaseFileName & strSeroSup) as text
  #itemエレメント
  set ocidItemElement to (refMe's NSXMLElement's alloc()'s initWithName:("item"))
(ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("id") stringValue:(strFileName)))
  #パス
  set strSetValue to (strBaseFileName & strSeroSup & ".xhtml") as text
(ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("href") stringValue:(strSetValue)))
(ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("media-type") stringValue:("application/xhtml+xml")))
(ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("properties") stringValue:("scripted")))
(ocidManifestElement's addChild:(ocidItemElement))
  ##カウントアップ
  set numCntPage to numCntPage + 1 as integer
end repeat

########################
#【D】コンテンツの配置 spine
set ocidSpineElement to refMe's NSXMLElement's alloc()'s initWithName:("spine")
##アトリビュート
ocidSpineElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("toc") stringValue:("ncx"))
##開き方向指定
ocidSpineElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("page-progression-direction") stringValue:(strPageProgression))
##【D-1】表紙ページの有無
if boolCoverPage is true then
  #表紙ページ ID: cover-page
  set ocidItemRef to refMe's NSXMLElement's alloc()'s initWithName:("itemref")
ocidItemRef's addAttribute:(refMe's NSXMLNode's attributeWithName:("idref") stringValue:("cover"))
ocidItemRef's addAttribute:(refMe's NSXMLNode's attributeWithName:("linear") stringValue:("yes"))
ocidSpineElement's addChild:(ocidItemRef)
  (*
#表紙画像 ID: cover-image
set ocidItemRef to refMe's NSXMLElement's alloc()'s initWithName:("itemref")
ocidItemRef's addAttribute:(refMe's NSXMLNode's attributeWithName:("idref") stringValue:("cover-image"))
ocidItemRef's addAttribute:(refMe's NSXMLNode's attributeWithName:("linear") stringValue:("yes"))
ocidSpineElement's addChild:(ocidItemRef)
#表紙ページ ID: cover-page
set ocidItemRef to refMe's NSXMLElement's alloc()'s initWithName:("itemref")
ocidItemRef's addAttribute:(refMe's NSXMLNode's attributeWithName:("idref") stringValue:("cover-page"))
ocidItemRef's addAttribute:(refMe's NSXMLNode's attributeWithName:("linear") stringValue:("yes"))
ocidSpineElement's addChild:(ocidItemRef)
*)
  ##【D-2】目次ページ
  set ocidItemRef to refMe's NSXMLElement's alloc()'s initWithName:("itemref")
ocidItemRef's addAttribute:(refMe's NSXMLNode's attributeWithName:("idref") stringValue:("toc"))
ocidItemRef's addAttribute:(refMe's NSXMLNode's attributeWithName:("linear") stringValue:("yes"))
ocidSpineElement's addChild:(ocidItemRef)
end if

#カウンタ初期化
set numCntPage to 1 as integer
#事前に取得している総ページ数回繰り返す
repeat numCntAllImage times
  ###画像ファイルは連番処理 四桁のゼロパディング
  set strZeroSup to "0000" as text
  set strSeroSup to (strZeroSup & (numCntPage as text)) as text
  set strSeroSup to (text -4 through -1 of strSeroSup) as text
  set strSetFileID to (strBaseFileName & strSeroSup) as text
  ##ファイル名をitemrefとして登録
  set ocidItemRef to refMe's NSXMLElement's alloc()'s initWithName:("itemref")
ocidItemRef's addAttribute:(refMe's NSXMLNode's attributeWithName:("idref") stringValue:(strSetFileID))
ocidItemRef's addAttribute:(refMe's NSXMLNode's attributeWithName:("linear") stringValue:("yes"))
  if boolProgression is true then
    if numCntPage = 1 then
log "spineから1ページ目を抜きます"
    else
      ##ページ要素itemrefをspineの子要素に追加
ocidSpineElement's addChild:(ocidItemRef)
    end if
  else
    ##ページ要素itemrefをspineの子要素に追加
ocidSpineElement's addChild:(ocidItemRef)
  end if
  set numCntPage to numCntPage + 1 as integer
end repeat
##################
#【E】ガイドguide
(* referenceのtypeの要素
toc(Table of Contents): 目次へのリンク。
cover: 書籍の表紙ページへのリンク。
title-page: 書籍のタイトルページへのリンク。
colophon: 制作者や印刷情報を含むページへのリンク。
acknowledgements: 著者への謝辞が含まれるページへのリンク。
dedication: 書籍の献辞が含まれるページへのリンク。
*)
set ocidGuideElement to refMe's NSXMLElement's alloc()'s initWithName:("guide")
#【E-1】目次追加
set ocidReferenceElement to (refMe's NSXMLElement's alloc()'s initWithName:("reference"))
ocidReferenceElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("type") stringValue:("toc"))
ocidReferenceElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("href") stringValue:("toc.xhtml"))
ocidReferenceElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("title") stringValue:("目次"))
ocidGuideElement's addChild:(ocidReferenceElement)
##【E-2】表紙ページの有無 設定依存
if boolCoverPage is true then
  set ocidReferenceElement to (refMe's NSXMLElement's alloc()'s initWithName:("reference"))
ocidReferenceElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("type") stringValue:("cover"))
ocidReferenceElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("href") stringValue:("cover.xhtml"))
ocidReferenceElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("title") stringValue:("表紙"))
ocidGuideElement's addChild:(ocidReferenceElement)
  ##1ページ目指定
  set strStartFileName to (strBaseFileName & "0001.xhtml") as text
  set ocidReferenceElement to (refMe's NSXMLElement's alloc()'s initWithName:("reference"))
ocidReferenceElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("type") stringValue:("other.reader-start-page"))
ocidReferenceElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("href") stringValue:(strStartFileName))
ocidReferenceElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("title") stringValue:("最初のページ"))
ocidGuideElement's addChild:(ocidReferenceElement)
  ##1ページ目指定
  set ocidReferenceElement to (refMe's NSXMLElement's alloc()'s initWithName:("reference"))
ocidReferenceElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("type") stringValue:("text"))
ocidReferenceElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("href") stringValue:(strStartFileName))
ocidReferenceElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("title") stringValue:("最初のコンテンツ"))
ocidGuideElement's addChild:(ocidReferenceElement)
end if

##################
#↑からの各子要素をセット
## 【B】メタ部を【A】のROOTエレメントに追加
ocidRootElement's addChild:(ocidMetaDataElement)
## 【C】manifest部を【A】のROOTエレメントに追加
ocidRootElement's addChild:(ocidManifestElement)
## 【D】spine部を【A】のROOTエレメントに追加
ocidRootElement's addChild:(ocidSpineElement)
## 【E】ガイド部を【A】のROOTエレメントに追加
ocidRootElement's addChild:(ocidGuideElement)
## 【A】をROOTエレメントをセットしてXMLとする
set ocidOutPutXML to refMe's NSXMLDocument's alloc()'s initWithRootElement:(ocidRootElement)
ocidOutPutXML's setVersion:"1.0"
ocidOutPutXML's setCharacterEncoding:"UTF-8"
### 【A】をテキストにして
set ocidSaveStrings to ocidOutPutXML's XMLString()
###改行コードを指定して
ocidSaveStrings's appendString:"\n"
##保存
set listWritetoUrlArray to ocidSaveStrings's writeToURL:(ocidOptFilePathURL) atomically:true encoding:(refMe's NSUTF8StringEncoding) |error|:(reference)
####################################
###◆ 【3−4】toc.ncx 主に閲覧者が必要な情報や
##ページや項目の順番等を指定する
##マルチメディア系やアクセシビリティ要素もここで指定する
###ファイルパス
##Pageの場合
## set ocidNcxFilePathURL to ocidOPSDirPathURL's URLByAppendingPathComponent:("epb.ncx") isDirectory:false
##一般的な命名
set ocidNcxFilePathURL to ocidOPSDirPathURL's URLByAppendingPathComponent:("toc.ncx") isDirectory:false
######【A】ROOTのエレメント 4つの子要素がある
set ocidRootElement to refMe's NSXMLElement's alloc()'s initWithName:"ncx"
ocidRootElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("version") stringValue:("2005-1"))
ocidRootElement's addNamespace:(refMe's NSXMLNode's namespaceWithName:("") stringValue:("http://www.daisy.org/z3986/2005/ncx/"))
######【B】head メタ情報部分
set ocidHeadElement to refMe's NSXMLElement's alloc()'s initWithName:("head")
##【B-1】uid
###エレメント名meta
set ocidMetaElement to refMe's NSXMLElement's elementWithName:("meta")
##アトリビュートを設定して
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("name") stringValue:("dtb:uid"))
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("content") stringValue:(strUUID))
##親要素の【B】head に追加する
ocidHeadElement's addChild:(ocidMetaElement)
##◆【B-2】depth
###エレメント名meta
set ocidMetaElement to refMe's NSXMLElement's elementWithName:("meta")
##アトリビュートを設定して
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("name") stringValue:("dtb:depth"))
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("content") stringValue:("1"))
##親要素の【B】head に追加する
ocidHeadElement's addChild:(ocidMetaElement)
##◆【B-3】totalPageCount
set strCntAllImage to numCntAllImage as text
###エレメント名meta
set ocidMetaElement to refMe's NSXMLElement's elementWithName:("meta")
##アトリビュートを設定して
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("name") stringValue:("dtb:totalPageCount"))
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("content") stringValue:(strCntAllImage))
##親要素の【B】head に追加する
ocidHeadElement's addChild:(ocidMetaElement)
##◆【B-4】maxPageNumber
###エレメント名meta
set ocidMetaElement to refMe's NSXMLElement's elementWithName:("meta")
##アトリビュートを設定して
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("name") stringValue:("dtb:maxPageNumber"))
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("content") stringValue:(strCntAllImage))
##親要素の【B】head に追加する
ocidHeadElement's addChild:(ocidMetaElement)
##◆【B-5】作成日
set strSetDate to doGetDateNo("yyyy-MM-dd") as text
###エレメント名meta
set ocidMetaElement to refMe's NSXMLElement's elementWithName:("meta")
##アトリビュートを設定して
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("name") stringValue:("dc:date"))
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("content") stringValue:(strSetDate))
##親要素の【B】head に追加する
ocidHeadElement's addChild:(ocidMetaElement)
##◆【B-6】修正日
set strSetDate to doGetDateNo("yyyy-MM-dd'T'HH:mm:ss'Z'") as text
###エレメント名meta
set ocidMetaElement to refMe's NSXMLElement's elementWithName:("meta")
##アトリビュートを設定して
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("name") stringValue:("dc:modified"))
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("content") stringValue:(strSetDate))
##親要素の【B】head に追加する
ocidHeadElement's addChild:(ocidMetaElement)
######【C】docTitle タイトル
##エレメント名docTitle
set ocidTitleElement to refMe's NSXMLElement's alloc()'s initWithName:("docTitle")
##子要素のtext
set ocidTextElement to refMe's NSXMLElement's elementWithName:("text")
##子要素textにドキュメント名を値として設定して
ocidTextElement's setStringValue:(strDocumentTitle)
##CのdocTitleエレメントに子要素として追加する
ocidTitleElement's addChild:(ocidTextElement)
######【D】docAuthor 作者 著者
##エレメント名 docAuthor
set ocidAuthorElement to refMe's NSXMLElement's alloc()'s initWithName:("docAuthor")
##子要素のtext
set ocidTextElement to refMe's NSXMLElement's elementWithName:("text")
##子要素textに作者情報を値として設定して
ocidTextElement's setStringValue:(strAuthor)
##DのdocAuthorエレメントに子要素として追加する
ocidAuthorElement's addChild:(ocidTextElement)
######【E】navMap navMapは閲覧時の順番を指定するので表紙イメージの設定とは異なる
set ocidMapElement to refMe's NSXMLElement's alloc()'s initWithName:("navMap")
#navMapの子要素navPoint
set ocidNavPointElement to refMe's NSXMLElement's elementWithName:("navPoint")
##navPointのアトリビュート カバー表紙を最初のページとして読み順指定する
ocidNavPointElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("id") stringValue:("navpoint-1"))
ocidNavPointElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("playOrder") stringValue:("1"))
##【E-1】 navLabel ↑このnavPointの意図するラベル名
set ocidNavLabelElement to refMe's NSXMLElement's elementWithName:("navLabel")
set ocidTextElement to refMe's NSXMLElement's elementWithName:("text")
ocidTextElement's setStringValue:(strLabelTitle)
##ラベルテキストをnavLabelに子要素として追加
ocidNavLabelElement's addChild:(ocidTextElement)
##↑追加したラベルをnavPointに子要素として追加
ocidNavPointElement's addChild:(ocidNavLabelElement)
##【E-2】contentはnavPointとして指定するファイルのリソースパス
set ocidNavContentElement to refMe's NSXMLElement's elementWithName:("content")
###表紙設定ありの場合は
if boolCoverPage is true then
  ##アトリビュートでパス指定する =表紙ページ
ocidNavContentElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("src") stringValue:("cover.xhtml"))
else
  ##見開き調整ありの場合は
  if boolProgression is true then
    set strStartFileName to (strBaseFileName & "0002.xhtml") as text
ocidNavContentElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("src") stringValue:(strStartFileName))
  else
    set strStartFileName to (strBaseFileName & "0001.xhtml") as text
ocidNavContentElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("src") stringValue:(strStartFileName))
  end if
end if
##contentをnavPointに子要素として追加
ocidNavPointElement's addChild:(ocidNavContentElement)
##複数のnavPointを指定する場合はこの下に追加していく
###navPointをnavMapに子要素として追加
ocidMapElement's addChild:(ocidNavPointElement)
## ↑からの子要素をセット
##【A】に【B】を追加
ocidRootElement's addChild:(ocidHeadElement)
##【A】に【C】を追加
ocidRootElement's addChild:(ocidTitleElement)
##【A】に【D】を追加
ocidRootElement's addChild:(ocidAuthorElement)
##【A】に【E】を追加
ocidRootElement's addChild:(ocidMapElement)
## ↑からのROOTエレメントをセットしてXMLとする
set ocidOutPutXML to refMe's NSXMLDocument's alloc()'s initWithRootElement:(ocidRootElement)
ocidOutPutXML's setVersion:"1.0"
ocidOutPutXML's setCharacterEncoding:"UTF-8"
###XML形式のテキストに出力
set ocidSaveStrings to ocidOutPutXML's XMLString()
###改行コードを指定して
ocidSaveStrings's appendString:"\n"
##保存 これでCNXファイルの出来上がり
set listWritetoUrlArray to ocidSaveStrings's writeToURL:(ocidNcxFilePathURL) atomically:true encoding:(refMe's NSUTF8StringEncoding) |error|:(reference)

#################################################################
### 【2】META-INF ファイル: container.xml com.apple.ibooks.display-options.xml
set ocidMetaDirPathURL to ocidEpubDirPathURL's URLByAppendingPathComponent:("META-INF") isDirectory:true
##################
###◆【2−1】container.xml
###ファイルのパス
set ocidContainerFilePathURL to ocidMetaDirPathURL's URLByAppendingPathComponent:("container.xml") isDirectory:false
###【A】ROOT エレメント
set ocidRootElement to refMe's NSXMLElement's alloc()'s initWithName:"container"
##【A】にアトリビュートを追加
ocidRootElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("version") stringValue:("1.0"))
##【A】にネームスペースを追加
ocidRootElement's addNamespace:(refMe's NSXMLNode's namespaceWithName:("") stringValue:("urn:oasis:names:tc:opendocument:xmlns:container"))
###【B】子要素 rootfiles エレメント
set ocidRootFilesElement to refMe's NSXMLElement's alloc()'s initWithName:"rootfiles"
###【C】Bの子要素 rootfileノード
set ocidRootFilesNode to refMe's NSXMLElement's alloc()'s initWithName:"rootfile"
##【C】にアトリビュートを追加
ocidRootFilesNode's addAttribute:(refMe's NSXMLNode's attributeWithName:("full-path") stringValue:("OPS/content.opf"))
ocidRootFilesNode's addAttribute:(refMe's NSXMLNode's attributeWithName:("media-type") stringValue:("application/oebps-package+xml"))
## ↑からの子要素をセット(【B】に【C】を追加)
ocidRootFilesElement's addChild:(ocidRootFilesNode)
## ↑からの子要素をセット(【A】に【B】を追加)
ocidRootElement's addChild:(ocidRootFilesElement)
## ↑からのROOTエレメントをセットしてXMLとする  【A】をXMLドキュメントに
set ocidOutPutXML to refMe's NSXMLDocument's alloc()'s initWithRootElement:(ocidRootElement)
ocidOutPutXML's setVersion:"1.0"
ocidOutPutXML's setCharacterEncoding:"UTF-8"
###XML形式のテキストに出力
set ocidSaveStrings to ocidOutPutXML's XMLString()
###改行コードを指定して
ocidSaveStrings's appendString:"\n"
##保存
set listDone to ocidSaveStrings's writeToURL:(ocidContainerFilePathURL) atomically:true encoding:(refMe's NSUTF8StringEncoding) |error|:(reference)

##################
###◆ 【2−2】com.apple.ibooks.display-options.xml
##ファイルパス
set ocidContainerFilePathURL to ocidMetaDirPathURL's URLByAppendingPathComponent:("com.apple.ibooks.display-options.xml") isDirectory:false
###【A】ROOT エレメント
set ocidRootElement to refMe's NSXMLElement's alloc()'s initWithName:"display_options"
###【B】子要素 platform エレメント
set ocidPlatformElement to refMe's NSXMLElement's alloc()'s initWithName:("platform")
###【B】にアトリビュートを追加
ocidPlatformElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("name") stringValue:("*"))
###【C】Bの子要素としてのoption エレメント
set ocidOptionElement to refMe's NSXMLElement's elementWithName:("option")
###【C】にアトリビュートを追加
ocidOptionElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("name") stringValue:("specified-fonts"))
###【C】にテキストの値を設定
ocidOptionElement's setStringValue:("false")
## 子要素をセット 【C】を【B】に追加
ocidPlatformElement's addChild:(ocidOptionElement)
## ↑からの子要素をセット 【B】を【A】に追加
ocidRootElement's addChild:(ocidPlatformElement)
## ↑からのROOTエレメントをセットしてXMLとする 【A】をXMLドキュメントにする
set ocidOutPutXML to refMe's NSXMLDocument's alloc()'s initWithRootElement:(ocidRootElement)
ocidOutPutXML's setVersion:"1.0"
ocidOutPutXML's setCharacterEncoding:"UTF-8"
###XML形式のテキストに出力
set ocidSaveStrings to ocidOutPutXML's XMLString()
###改行コードを指定して
ocidSaveStrings's appendString:"\n"
##保存
set listDone to ocidSaveStrings's writeToURL:(ocidContainerFilePathURL) atomically:true encoding:(refMe's NSUTF8StringEncoding) |error|:(reference)


return


##############################
### 今の日付日間 テキスト
##############################
to doGetDateNo(argDateFormat)
  ####日付情報の取得
  set ocidDate to current application's NSDate's |date|()
  ###日付のフォーマットを定義
  set ocidNSDateFormatter to current application's NSDateFormatter's alloc()'s init()
ocidNSDateFormatter's setLocale:(current application's NSLocale's localeWithLocaleIdentifier:"ja_JP_POSIX")
  set ocidTimeZone to refMe's NSTimeZone's alloc()'s initWithName:"Asia/Tokyo"
ocidNSDateFormatter's setTimeZone:(ocidTimeZone)
ocidNSDateFormatter's setDateFormat:(argDateFormat)
  set ocidDateAndTime to ocidNSDateFormatter's stringFromDate:ocidDate
  set strDateAndTime to ocidDateAndTime as text
return strDateAndTime
end doGetDateNo


|

SVG画像のサイズを求める


【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use scripting additions

property refMe : a reference to current application

on run
  
  set aliasIconPass to (POSIX file "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/MultipleItemsIcon.icns") as alias
  set strDialogText to "ドロップしても利用できます"
  set strTitleText to "画像ファイルを選んでください"
  set listButton to {"ファイルを選びます", "キャンセル"} as list
display dialog strDialogText buttons listButton default button 1 cancel button 2 with title strTitleText with icon aliasIconPass giving up after 1 with hidden answer
  
  set aliasDefaultLocation to (path to desktop folder from user domain) as alias
  set listChooseFileUTI to {"public.svg-image"}
  set strPromptText to "イメージファイルを選んでください" as text
  set strPromptMes to "イメージファイルを選んでください" as text
  set listAliasFilePath to (choose file strPromptMes with prompt strPromptText default location (aliasDefaultLocation) of type listChooseFileUTI with showing package contents, invisibles and multiple selections allowed) as list
  
  -->値をOpenに渡たす
open listAliasFilePath
end run


on open listAliasFilePath
  
  ##########################
  ####ファイルの数だけ繰り返し
  repeat with itemAliasFilePath in listAliasFilePath
    ####まずはUNIXパスにして
    set strFilePath to (POSIX path of itemAliasFilePath) as text
    set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePath))
    set ocidFilePath to ocidFilePathStr's stringByStandardizingPath
    set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath))
    ####################################
    ##サイズ取得
    #ファイルを読み込み
    set listReadData to (refMe's NSXMLDocument's alloc()'s initWithContentsOfURL:(ocidFilePathURL) options:(refMe's NSXMLNodeOptionsNone) |error|:(reference))
    set ocidXmlDoc to (item 1 of listReadData)
    #ROOTエレメントを取得して
    set ocidRootElement to ocidXmlDoc's rootElement
    #viewBoxを取得
    set ocidViewBox to (ocidRootElement's attributeForName:("viewBox"))
    #テキストにして
    set ocidViewBoxStr to ocidViewBox's stringValue()
    #スペースを区切り文字でリストにして
    set ocidViewBoxArray to (ocidViewBoxStr's componentsSeparatedByString:(" "))
    #3番目と4番目が横縦ピクセルサイズ
    set ocidPixelWidth to (ocidViewBoxArray's objectAtIndex:(2))
    set ocidPixelHeight to (ocidViewBoxArray's objectAtIndex:(3))
log ocidPixelWidth as integer
log ocidPixelHeight as integer
  end repeat
end open


|

TSV2AdobeXML タブ区切りテキストからAdobe Illustratorの変数印字用の『変数ライブラリ』を生成する(1ページに複数面付け版)

TSV2AdobeXML タブ区切りテキストからAdobe Illustratorの変数印字用の『変数ライブラリ』を生成する
https://quicktimer.cocolog-nifty.com/icefloe/2024/03/post-bba3c3.html

複数項目を1ページ内に面付けする用

ダウンロード - tsv2adobexml4entries.zip



【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
(*
com.cocolog-nifty.quicktimer.icefloe
TSVタブ区切りテキストから
Adobe Illustrator用の変数用のXMLを生成します

設定項目で1ページに面付けする数を設定してください
デフォルトは10です
-->1ページに10件分のデータを割り付けます

【制限事項】その1
TSVの1行目の項目がデータセット名になります
表の1行目が項目名称になるようなTSVで利用してください
【制限事項】その2
可変テキストのみ設定可能です
他の要素の付与はご相談ください
*)
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use scripting additions
property refMe : a reference to current application
property refNSNotFound : a reference to 9.22337203685477E+18 + 5807
set appFileManager to refMe's NSFileManager's defaultManager()

#################################
### 【1】設定項目
#################################
#1ページの面付け数
set numPageEntries to 10 as integer

#################################
### 【1】入力ファイル
#################################
#ダイアログ
tell current application
  set strName to name as text
end tell
#スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
#デフォルトロケーション
tell application "Finder"
  set aliasPathToMe to (path to me) as alias
  set aliasContainerDir to (container of aliasPathToMe) as alias
end tell
#
set listUTI to {"public.tab-separated-values-text"}
set strMes to ("ファイルを選んでください") as text
set strPrompt to ("ファイルを選んでください") as text
try
  ### ファイル選択時
  set aliasFilePath to (choose file strMes with prompt strPrompt default location aliasContainerDir of type listUTI with invisibles and showing package contents without multiple selections allowed) as alias
on error
log "エラーしました"
return "エラーしました"
end try
if aliasFilePath is (missing value) then
return "選んでください"
end if
#ファイルパス
set strFilePath to (POSIX path of aliasFilePath) as text
set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePath))
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)
#################################
### 【2】保存先
#################################
set ocidContainerDirPathURL to ocidFilePathURL's URLByDeletingLastPathComponent()
set aliasContainerDirPath to (ocidContainerDirPathURL's absoluteURL()) as alias
set strMes to "フォルダを選んでください" as text
set strPrompt to "保存先フォルダを選択してください\n同名ファイルがある場合\n『上書き』になります" as text
try
  ###ダイアログを前面に出す
  set strName to (name of current application) as text
  if strName is "osascript" then
    tell application "Finder" to activate
  else
    tell current application to activate
  end if
  #
  set aliasResponse to (choose folder strMes with prompt strPrompt default location aliasContainerDirPath with invisibles and showing package contents without multiple selections allowed) as alias
on error
log "エラーしました"
return "エラーしました"
end try
#戻り値エイリアスをURLに
set strSaveDirPath to (POSIX path of aliasResponse) as text
set ocidSaveDirPathStr to (refMe's NSString's stringWithString:(strSaveDirPath))
set ocidSaveDirPath to ocidSaveDirPathStr's stringByStandardizingPath()
set ocidSaveDirPathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidSaveDirPath) isDirectory:true)
##出力用ファイルパス
set ocidSaveFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:("variables.xml")
#################################
### 【3】本処理
#################################
#ファイル読み込み
set listResponse to (refMe's NSString's alloc()'s initWithContentsOfURL:(ocidFilePathURL) usedEncoding:(refMe's NSUTF8StringEncoding) |error|:(reference))
set ocidReadString to (item 1 of listResponse)
if ocidReadString = (missing value) then
return "文字コードを判定出来ませんでした : " & strFileName
end if

#改行コードをUNIXに強制
set ocidCRChar to refMe's NSString's stringWithString:("\r")
set ocidLFChar to refMe's NSString's stringWithString:("\n")
set ocidCRLFChar to refMe's NSString's stringWithString:("\r\n")
set ocidReadStringsA to ocidReadString's stringByReplacingOccurrencesOfString:(ocidCRLFChar) withString:(ocidLFChar)
set ocidReadStrings to ocidReadStringsA's stringByReplacingOccurrencesOfString:(ocidCRChar) withString:(ocidLFChar)

#改行毎でリストにする
set ocidCharSet to (refMe's NSCharacterSet's newlineCharacterSet)
set ocidLineArray to (ocidReadStrings's componentsSeparatedByCharactersInSet:(ocidCharSet))

#出力用のリスト
set ocidEditLineArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)

#読み取ったデータに項目連番を入れておく
set numCntLineNo to 0 as integer
repeat with itemLineArray in ocidLineArray
  set ocidEditLineText to (refMe's NSMutableString's alloc()'s initWithCapacity:(0))
  if numCntLineNo = 0 then
    set strAppendText to ("rowno\t") as text
(ocidEditLineText's appendString:(strAppendText))
(ocidEditLineText's appendString:(itemLineArray))
  else
    if (itemLineArray as text) is "" then
      exit repeat
    end if
    #タブ区切りで挿入
    set strAppendText to (numCntLineNo & "\t") as text
(ocidEditLineText's appendString:(strAppendText))
(ocidEditLineText's appendString:(itemLineArray))
  end if
(ocidEditLineArray's addObject:(ocidEditLineText))
  #カウントアップ
  set numCntLineNo to (numCntLineNo + 1) as integer
end repeat

#最初の1行目だけ別で取得しておく
set ocidFirstObjectString to ocidEditLineArray's firstObject()
set ocidFirstRowArray to ocidFirstObjectString's componentsSeparatedByString:("\t")

################################
###XML初期化
set ocidXMLDoc to refMe's NSXMLDocument's alloc()'s init()
ocidXMLDoc's setVersion:("1.0")
ocidXMLDoc's setCharacterEncoding:("utf-8")
ocidXMLDoc's setDocumentContentKind:(refMe's NSXMLDocumentXMLKind)
###DTD生成
set ocidDTD to refMe's NSXMLDTD's alloc()'s init()
ocidDTD's setName:("svg")
ocidDTD's setPublicID:("-//W3C//DTD SVG 20001102//EN")
ocidDTD's setSystemID:("http://www.w3.org/TR/2000/CR-SVG-20001102/DTD/svg-20001102.dtd")
#Entitry付与
set strEntitry to ("<!ENTITY ns_graphs \"http://ns.adobe.com/Graphs/1.0/\">") as text
set ocidEntitry to refMe's NSString's stringWithString:(strEntitry)
set ocidEntityNode to refMe's NSXMLDTDNode's alloc()'s initWithXMLString:(ocidEntitry)
ocidEntityNode's setDTDKind:(refMe's NSXMLAttributeEntityKind)
ocidDTD's addChild:(ocidEntityNode)
#Entitry付与
set strEntitry to ("<!ENTITY ns_vars \"http://ns.adobe.com/Variables/1.0/\">") as text
set ocidEntitry to refMe's NSString's stringWithString:(strEntitry)
set ocidEntityNode to refMe's NSXMLDTDNode's alloc()'s initWithXMLString:(ocidEntitry)
ocidEntityNode's setDTDKind:(refMe's NSXMLAttributeEntityKind)
ocidDTD's addChild:(ocidEntityNode)
#Entitry付与
set strEntitry to ("<!ENTITY ns_imrep \"http://ns.adobe.com/ImageReplacement/1.0/\">") as text
set ocidEntitry to refMe's NSString's stringWithString:(strEntitry)
set ocidEntityNode to refMe's NSXMLDTDNode's alloc()'s initWithXMLString:(ocidEntitry)
ocidEntityNode's setDTDKind:(refMe's NSXMLAttributeEntityKind)
ocidDTD's addChild:(ocidEntityNode)
#Entitry付与
set strEntitry to ("<!ENTITY ns_custom \"http://ns.adobe.com/GenericCustomNamespace/1.0/\">") as text
set ocidEntitry to refMe's NSString's stringWithString:(strEntitry)
set ocidEntityNode to refMe's NSXMLDTDNode's alloc()'s initWithXMLString:(ocidEntitry)
ocidEntityNode's setDTDKind:(refMe's NSXMLAttributeEntityKind)
ocidDTD's addChild:(ocidEntityNode)
#Entitry付与
set strEntitry to ("<!ENTITY ns_flows \"http://ns.adobe.com/Flows/1.0/\">") as text
set ocidEntitry to refMe's NSString's stringWithString:(strEntitry)
set ocidEntityNode to refMe's NSXMLDTDNode's alloc()'s initWithXMLString:(ocidEntitry)
ocidEntityNode's setDTDKind:(refMe's NSXMLAttributeEntityKind)
ocidDTD's addChild:(ocidEntityNode)
#Entitry付与
set strEntitry to ("<!ENTITY ns_extend \"http://ns.adobe.com/Extensibility/1.0/\">") as text
set ocidEntitry to refMe's NSString's stringWithString:(strEntitry)
set ocidEntityNode to refMe's NSXMLDTDNode's alloc()'s initWithXMLString:(ocidEntitry)
ocidEntityNode's setDTDKind:(refMe's NSXMLAttributeEntityKind)
ocidDTD's addChild:(ocidEntityNode)
##DTDをXMLDOCにセット
ocidXMLDoc's setDTD:(ocidDTD)
###ROOTエレメント
set ocidRootElement to refMe's NSXMLElement's elementWithName:("svg")
#【1】variableSets
set ocidVsetsElement to refMe's NSXMLElement's elementWithName:("variableSets")
set ocidSetNameSpace to refMe's NSXMLNode's namespaceWithName:("") stringValue:("&ns_vars;")
ocidVsetsElement's addNamespace:(ocidSetNameSpace)

#【2】variableSet
set ocidVsetElement to refMe's NSXMLElement's elementWithName:("variableSet")
set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("varSetName") stringValue:("binding1"))
(ocidVsetElement's addAttribute:(ocidAddNode))
set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("locked") stringValue:("none"))
(ocidVsetElement's addAttribute:(ocidAddNode))

#【3−1】variables
set ocidVariablesElement to refMe's NSXMLElement's elementWithName:("variables")
################
#【3−2】variable
(*
可変テキスト:trait="textcontent" category="&ns_flows;"
フィアルパス:trait="fileref" category="&ns_vars;"
表示有無:trait="visibility" category="&ns_vars;"
表示有無?:trait="graphdata" category="&ns_graphs;"
*)
###########################
##ページレイアウト
###########################
repeat with itemEntries from 1 to numPageEntries by 1
  #【3−2−1】連番用の追加項目
  set ocidVariableElement to (refMe's NSXMLElement's elementWithName:("variable"))
  
  #【3−2−2】読み込みデータの項目
  repeat with itemFirstRowArray in ocidFirstRowArray
    set strFirstRowArray to itemFirstRowArray as text
    set ocidVariableElement to (refMe's NSXMLElement's elementWithName:("variable"))
    #ページのエントリー数を入れる
    set strSetVarName to ("E" & itemEntries & "-" & strFirstRowArray) as text
    set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("varName") stringValue:(strSetVarName))
(ocidVariableElement's addAttribute:(ocidAddNode))
    set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("category") stringValue:("&ns_flows;"))
(ocidVariableElement's addAttribute:(ocidAddNode))
    set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("trait") stringValue:("textcontent"))
(ocidVariableElement's addAttribute:(ocidAddNode))
    #【3−2−2】variableを【3−1】variablesにセット
(ocidVariablesElement's addChild:(ocidVariableElement))
  end repeat
end repeat

################
#【4−1】DataSets
set ocidDataSetsElement to refMe's NSXMLElement's elementWithName:("v:sampleDataSets")
set ocidSetNameSpace to refMe's NSXMLNode's namespaceWithName:("v") stringValue:("&ns_vars;")
ocidDataSetsElement's addNamespace:(ocidSetNameSpace)
set ocidSetNameSpace to refMe's NSXMLNode's namespaceWithName:("") stringValue:("&ns_custom;")
ocidDataSetsElement's addNamespace:(ocidSetNameSpace)

################
#【4−2】DataSet
#データのリスト行数 先頭行の項目名行を除くので1引く
set numCntEditArray to ((count of ocidEditLineArray) - 1) as integer
#データの行数から何ページ分のデータ=dataSetの数
set numMakePage to (round of (numCntEditArray / numPageEntries) rounding up) as integer
#取り出すデータ行番号初期化
set numCntRowNoAll to 1 as integer
#作成される予定ページ数=dataSetの数ぶん繰り返す
repeat with itemdataSet from 1 to numMakePage by 1
  #【4−2】DataSetのエレメント
  set ocidDataSetElement to (refMe's NSXMLElement's elementWithName:("v:sampleDataSet"))
  #DataSetのアトリビュートに項目番号+2列目のデータで命名する
  set strSetDataSetName to (itemdataSet & ":ページ目") as text
  #↑の内容でdataSetNameをセット
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("dataSetName") stringValue:(strSetDataSetName))
(ocidDataSetElement's addAttribute:(ocidAddNode))
  #1ページに入る行目数分くりかえし
  repeat with itemPageEntries from 1 to numPageEntries by 1
    #指定行数の行データを取得
    set ocidRowStrings to (ocidEditLineArray's objectAtIndex:(numCntRowNoAll))
    #区切り文字タブでリストにして
    set ocidRowArray to (ocidRowStrings's componentsSeparatedByString:("\t"))
    #OS用の0スタートで行の項目数
    set numCntRowItemAll to ((count of ocidRowArray) - 1) as integer
    #行項目のリストから取得するための項目数初期化
    set numCntRowItem to 0 as integer
    #項目の数だけ繰り返し
    repeat with itemFirstRowArray in ocidFirstRowArray
      #ページ内での項目数+項目名でセット
      set strSetVarName to ("E" & itemPageEntries & "-" & itemFirstRowArray) as text
      set ocidDataSetChildElement to (refMe's NSXMLElement's elementWithName:(strSetVarName))
      #対象行列データを取得
      set strSetValieRowItem to (ocidRowArray's objectAtIndex:(numCntRowItem)) as text
      #Pエレメント内にテキストとして値をセット
      set ocidPElement to (refMe's NSXMLElement's elementWithName:("p"))
(ocidPElement's setStringValue:(strSetValieRowItem))
(ocidDataSetChildElement's addChild:(ocidPElement))
(ocidDataSetElement's addChild:(ocidDataSetChildElement))
      #カウントアップ
      set numCntRowItem to (numCntRowItem + 1) as integer
    end repeat
    set numCntRowNoAll to numCntRowNoAll + 1 as integer
    #データ行項目数より行カウンターが多くなったら終わり
    if numCntRowNoAll > (numCntEditArray) then
      exit repeat
    end if
  end repeat
  #【4−2】DataSetを【4−1】DataSetsにセット
(ocidDataSetsElement's addChild:(ocidDataSetElement))
end repeat

#【3−1】variablesを【2】のvariableSetにセット
ocidVsetElement's addChild:(ocidVariablesElement)
#【4−1】DataSetsを【2】のvariableSetにセット
ocidVsetElement's addChild:(ocidDataSetsElement)
#【2】variableSetを【1】のvariableSetsにセット
ocidVsetsElement's addChild:(ocidVsetElement)
#【1】のvariableSetsをROOTにセット
ocidRootElement's addChild:(ocidVsetsElement)
#
################################
###保存
ocidXMLDoc's setRootElement:(ocidRootElement)
###NSXMLNodePrettyPrint形式でデータにして
###NSXMLNodeCompactEmptyElementにすると少しデータサイズが節約できる
set ocidXMLdata to ocidXMLDoc's XMLDataWithOptions:(refMe's NSXMLNodeExpandEmptyElement)
###データをテキストに戻して
set ocidXMLString to refMe's NSString's alloc()'s initWithData:(ocidXMLdata) encoding:(refMe's NSUTF8StringEncoding)
###改行コードをWindowsに
set ocidSaveStrings to ocidXMLString's stringByReplacingOccurrencesOfString:(ocidLFChar) withString:(ocidCRLFChar)
###保存
set listDone to (ocidSaveStrings's writeToURL:(ocidSaveFilePathURL) atomically:true encoding:(refMe's NSUTF8StringEncoding) |error|:(reference))

return




|

TSV2AdobeXML タブ区切りテキストからAdobe Illustratorの変数印字用の『変数ライブラリ』を生成する

TSV2AdobeXML タブ区切りテキストからAdobe Illustratorの変数印字用の『変数ライブラリ』を生成する(1ページに複数面付け版)
https://quicktimer.cocolog-nifty.com/icefloe/2024/03/post-143f05.html
もあります
このページのスクリプトは1ページに1項目版です

変数パネルを使った可変テキスト
1:変数パネルを出す
2:変数パネル
3:ハンバーガーから『変数ライブラリの読み込み』
4:読み込んだ状態
5:テキストオブジェクトを生成して
6:使用したい変数を選択してから『テキスト動的に設定』を実行
7:動作確認

ダウンロード - makevariables.zip


1:変数パネルを出す
1_20240306130101
2:変数パネル
2_20240306130101
3:ハンバーガーから『変数ライブラリの読み込み』
3_20240306130101
4:読み込んだ状態
4_20240306130101
5:テキストオブジェクトを生成して
5_20240306130101
6:使用したい変数を選択してから『テキスト動的に設定』を実行
6_20240306130101
7:動作確認
7_20240306130101


【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
(*
com.cocolog-nifty.quicktimer.icefloe
TSVタブ区切りテキストから
Adobe Illustrator用の変数用のXMLを生成します
【制限事項】その1
TSVの1行目の項目がデータセット名になります
表の1行目が項目名称になるようなTSVで利用してください
【制限事項】その2
可変テキストのみ設定可能です
他の要素の付与はご相談ください
*)
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use scripting additions
property refMe : a reference to current application
property refNSNotFound : a reference to 9.22337203685477E+18 + 5807
set appFileManager to refMe's NSFileManager's defaultManager()


#################################
### 【1】入力ファイル
#################################
#ダイアログ
tell current application
  set strName to name as text
end tell
#スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
#デフォルトロケーション
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
set aliasDesktopDirPath to (ocidDesktopDirPathURL's absoluteURL()) as alias
#
set listUTI to {"public.tab-separated-values-text"}
set strMes to ("ファイルを選んでください") as text
set strPrompt to ("ファイルを選んでください") as text
try
  ### ファイル選択時
  set aliasFilePath to (choose file strMes with prompt strPrompt default location aliasDesktopDirPath of type listUTI with invisibles and showing package contents without multiple selections allowed) as alias
on error
log "エラーしました"
return "エラーしました"
end try
if aliasFilePath is (missing value) then
return "選んでください"
end if
#ファイルパス
set strFilePath to (POSIX path of aliasFilePath) as text
set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePath))
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)
#################################
### 【2】保存先
#################################
set ocidContainerDirPathURL to ocidFilePathURL's URLByDeletingLastPathComponent()
set aliasContainerDirPath to (ocidContainerDirPathURL's absoluteURL()) as alias
set strMes to "フォルダを選んでください" as text
set strPrompt to "保存先フォルダを選択してください\n同名ファイルがある場合\n『上書き』になります" as text
try
  ###ダイアログを前面に出す
  set strName to (name of current application) as text
  if strName is "osascript" then
    tell application "Finder" to activate
  else
    tell current application to activate
  end if
  #
  set aliasResponse to (choose folder strMes with prompt strPrompt default location aliasContainerDirPath with invisibles and showing package contents without multiple selections allowed) as alias
on error
log "エラーしました"
return "エラーしました"
end try
#戻り値エイリアスをURLに
set strSaveDirPath to (POSIX path of aliasResponse) as text
set ocidSaveDirPathStr to (refMe's NSString's stringWithString:(strSaveDirPath))
set ocidSaveDirPath to ocidSaveDirPathStr's stringByStandardizingPath()
set ocidSaveDirPathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidSaveDirPath) isDirectory:true)
##出力用ファイルパス
set ocidSaveFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:("variables.xml")
#################################
### 【3】本処理
#################################
#ファイル読み込み
set listResponse to (refMe's NSString's alloc()'s initWithContentsOfURL:(ocidFilePathURL) usedEncoding:(refMe's NSUTF8StringEncoding) |error|:(reference))
set ocidReadString to (item 1 of listResponse)
if ocidReadString = (missing value) then
return "文字コードを判定出来ませんでした : " & strFileName
end if

#改行コードをUNIXに強制
set ocidCRChar to refMe's NSString's stringWithString:("\r")
set ocidLFChar to refMe's NSString's stringWithString:("\n")
set ocidCRLFChar to refMe's NSString's stringWithString:("\r\n")
set ocidReadStringsA to ocidReadString's stringByReplacingOccurrencesOfString:(ocidCRLFChar) withString:(ocidLFChar)
set ocidReadStrings to ocidReadStringsA's stringByReplacingOccurrencesOfString:(ocidCRChar) withString:(ocidLFChar)
#改行毎でリストにする
set ocidCharSet to (refMe's NSCharacterSet's newlineCharacterSet)
set ocidLineArray to (ocidReadStrings's componentsSeparatedByCharactersInSet:(ocidCharSet))
#出力用のリスト
set ocidEditLineArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
#読み取ったデータに項目連番を入れておく
set numCntLineNo to 0 as integer
repeat with itemLineArray in ocidLineArray
  set ocidEditLineText to (refMe's NSMutableString's alloc()'s initWithCapacity:(0))
  if numCntLineNo = 0 then
    set strAppendText to ("rowno\t") as text
(ocidEditLineText's appendString:(strAppendText))
(ocidEditLineText's appendString:(itemLineArray))
  else
    if (itemLineArray as text) is "" then
      exit repeat
    end if
    set strAppendText to (numCntLineNo & "\t") as text
(ocidEditLineText's appendString:(strAppendText))
(ocidEditLineText's appendString:(itemLineArray))
  end if
(ocidEditLineArray's addObject:(ocidEditLineText))
  #カウントアップ
  set numCntLineNo to (numCntLineNo + 1) as integer
end repeat

#最初の1行目だけ別で取得しておく
set ocidFirstObjectString to ocidEditLineArray's firstObject()
set ocidFirstRowArray to ocidFirstObjectString's componentsSeparatedByString:("\t")

################################
###XML初期化
set ocidXMLDoc to refMe's NSXMLDocument's alloc()'s init()
ocidXMLDoc's setVersion:("1.0")
ocidXMLDoc's setCharacterEncoding:("utf-8")
ocidXMLDoc's setDocumentContentKind:(refMe's NSXMLDocumentXMLKind)
###DTD生成
set ocidDTD to refMe's NSXMLDTD's alloc()'s init()
ocidDTD's setName:("svg")
ocidDTD's setPublicID:("-//W3C//DTD SVG 20001102//EN")
ocidDTD's setSystemID:("http://www.w3.org/TR/2000/CR-SVG-20001102/DTD/svg-20001102.dtd")
#Entitry付与
set strEntitry to ("<!ENTITY ns_graphs \"http://ns.adobe.com/Graphs/1.0/\">") as text
set ocidEntitry to refMe's NSString's stringWithString:(strEntitry)
set ocidEntityNode to refMe's NSXMLDTDNode's alloc()'s initWithXMLString:(ocidEntitry)
ocidEntityNode's setDTDKind:(refMe's NSXMLAttributeEntityKind)
ocidDTD's addChild:(ocidEntityNode)
#Entitry付与
set strEntitry to ("<!ENTITY ns_vars \"http://ns.adobe.com/Variables/1.0/\">") as text
set ocidEntitry to refMe's NSString's stringWithString:(strEntitry)
set ocidEntityNode to refMe's NSXMLDTDNode's alloc()'s initWithXMLString:(ocidEntitry)
ocidEntityNode's setDTDKind:(refMe's NSXMLAttributeEntityKind)
ocidDTD's addChild:(ocidEntityNode)
#Entitry付与
set strEntitry to ("<!ENTITY ns_imrep \"http://ns.adobe.com/ImageReplacement/1.0/\">") as text
set ocidEntitry to refMe's NSString's stringWithString:(strEntitry)
set ocidEntityNode to refMe's NSXMLDTDNode's alloc()'s initWithXMLString:(ocidEntitry)
ocidEntityNode's setDTDKind:(refMe's NSXMLAttributeEntityKind)
ocidDTD's addChild:(ocidEntityNode)
#Entitry付与
set strEntitry to ("<!ENTITY ns_custom \"http://ns.adobe.com/GenericCustomNamespace/1.0/\">") as text
set ocidEntitry to refMe's NSString's stringWithString:(strEntitry)
set ocidEntityNode to refMe's NSXMLDTDNode's alloc()'s initWithXMLString:(ocidEntitry)
ocidEntityNode's setDTDKind:(refMe's NSXMLAttributeEntityKind)
ocidDTD's addChild:(ocidEntityNode)
#Entitry付与
set strEntitry to ("<!ENTITY ns_flows \"http://ns.adobe.com/Flows/1.0/\">") as text
set ocidEntitry to refMe's NSString's stringWithString:(strEntitry)
set ocidEntityNode to refMe's NSXMLDTDNode's alloc()'s initWithXMLString:(ocidEntitry)
ocidEntityNode's setDTDKind:(refMe's NSXMLAttributeEntityKind)
ocidDTD's addChild:(ocidEntityNode)
#Entitry付与
set strEntitry to ("<!ENTITY ns_extend \"http://ns.adobe.com/Extensibility/1.0/\">") as text
set ocidEntitry to refMe's NSString's stringWithString:(strEntitry)
set ocidEntityNode to refMe's NSXMLDTDNode's alloc()'s initWithXMLString:(ocidEntitry)
ocidEntityNode's setDTDKind:(refMe's NSXMLAttributeEntityKind)
ocidDTD's addChild:(ocidEntityNode)
##DTDをXMLDOCにセット
ocidXMLDoc's setDTD:(ocidDTD)
###ROOTエレメント
set ocidRootElement to refMe's NSXMLElement's elementWithName:("svg")
#【1】variableSets
set ocidVsetsElement to refMe's NSXMLElement's elementWithName:("variableSets")
set ocidSetNameSpace to refMe's NSXMLNode's namespaceWithName:("") stringValue:("&ns_vars;")
ocidVsetsElement's addNamespace:(ocidSetNameSpace)

#【2】variableSet
set ocidVsetElement to refMe's NSXMLElement's elementWithName:("variableSet")
set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("varSetName") stringValue:("binding1"))
(ocidVsetElement's addAttribute:(ocidAddNode))
set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("locked") stringValue:("none"))
(ocidVsetElement's addAttribute:(ocidAddNode))

#【3−1】variables
set ocidVariablesElement to refMe's NSXMLElement's elementWithName:("variables")
################
#【3−2】variable
(*
可変テキスト:trait="textcontent" category="&ns_flows;"
フィアルパス:trait="fileref" category="&ns_vars;"
表示有無:trait="visibility" category="&ns_vars;"
表示有無?:trait="graphdata" category="&ns_graphs;"
*)
#【3−2−1】連番用の追加項目
set ocidVariableElement to (refMe's NSXMLElement's elementWithName:("variable"))

#【3−2−2】読み込みデータの項目
repeat with itemFirstRowArray in ocidFirstRowArray
  set strFirstRowArray to itemFirstRowArray as text
  set ocidVariableElement to (refMe's NSXMLElement's elementWithName:("variable"))
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("varName") stringValue:(strFirstRowArray))
(ocidVariableElement's addAttribute:(ocidAddNode))
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("category") stringValue:("&ns_flows;"))
(ocidVariableElement's addAttribute:(ocidAddNode))
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("trait") stringValue:("textcontent"))
(ocidVariableElement's addAttribute:(ocidAddNode))
  #【3−2−2】variableを【3−1】variablesにセット
(ocidVariablesElement's addChild:(ocidVariableElement))
end repeat

################
#【4−1】DataSets
set ocidDataSetsElement to refMe's NSXMLElement's elementWithName:("v:sampleDataSets")
set ocidSetNameSpace to refMe's NSXMLNode's namespaceWithName:("v") stringValue:("&ns_vars;")
ocidDataSetsElement's addNamespace:(ocidSetNameSpace)
set ocidSetNameSpace to refMe's NSXMLNode's namespaceWithName:("") stringValue:("&ns_custom;")
ocidDataSetsElement's addNamespace:(ocidSetNameSpace)
################
#【4−2】DataSet
#データのリストの数
set numCntEditArray to (count of ocidEditLineArray) as integer
#データリストの2行目から最後まで繰り返す
repeat with itemIntNo from 1 to (numCntEditArray - 1) by 1
  #【4−2】DataSetのエレメント
  set ocidDataSetElement to (refMe's NSXMLElement's elementWithName:("v:sampleDataSet"))
  #DataSetのアトリビュートに項目番号+2列目のデータで命名する
  set ocidRowStrings to (ocidEditLineArray's objectAtIndex:(itemIntNo))
  set ocidRowArray to (ocidRowStrings's componentsSeparatedByString:("\t"))
  #ここが行番号
  set strRowNo to (ocidRowArray's objectAtIndex:(0)) as text
  #ここが2列目
  set strRowName to (ocidRowArray's objectAtIndex:(1)) as text
  #データセット名にする
  set strSetName to (strRowNo & ":" & strRowName) as text
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("dataSetName") stringValue:(strSetName))
(ocidDataSetElement's addAttribute:(ocidAddNode))
  #【4−2】の子要素の生成
  set numCntFirstRowArray to (count of ocidFirstRowArray) as integer
  repeat with itemIntNo from 0 to (numCntFirstRowArray - 1) by 1
    set ocidFirstRowValue to (ocidFirstRowArray's objectAtIndex:(itemIntNo))
    set ocidDataSetChildElement to (refMe's NSXMLElement's elementWithName:(ocidFirstRowValue))
    #Pパラグラフのエレメントのテキストの値として生成する
    set strSetRowItem to (ocidRowArray's objectAtIndex:(itemIntNo))
    set ocidPElement to (refMe's NSXMLElement's elementWithName:("p"))
    #テキストの値を入れる
(ocidPElement's setStringValue:(strSetRowItem))
(ocidDataSetChildElement's addChild:(ocidPElement))
(ocidDataSetElement's addChild:(ocidDataSetChildElement))
  end repeat
(ocidDataSetsElement's addChild:(ocidDataSetElement))
end repeat

#【3−1】のvariablesを【2】のvariableSetにセット
ocidVsetElement's addChild:(ocidVariablesElement)
#【4−1】DataSetsを【2】のvariableSetにセット
ocidVsetElement's addChild:(ocidDataSetsElement)
#【2】variableSetを【1】のvariableSetsにセット
ocidVsetsElement's addChild:(ocidVsetElement)
#【1】のvariableSetsをROOTにセット
ocidRootElement's addChild:(ocidVsetsElement)
#
################################
###保存
ocidXMLDoc's setRootElement:(ocidRootElement)
###NSXMLNodePrettyPrint形式でデータにして
###NSXMLNodeCompactEmptyElementにすると少しデータサイズが節約できる
set ocidXMLdata to ocidXMLDoc's XMLDataWithOptions:(refMe's NSXMLNodeExpandEmptyElement)
###データをテキストに戻して
set ocidXMLString to refMe's NSString's alloc()'s initWithData:(ocidXMLdata) encoding:(refMe's NSUTF8StringEncoding)
###改行コードをWindowsに
set ocidSaveStrings to ocidXMLString's stringByReplacingOccurrencesOfString:(ocidLFChar) withString:(ocidCRLFChar)
###保存
set listDone to (ocidSaveStrings's writeToURL:(ocidSaveFilePathURL) atomically:true encoding:(refMe's NSUTF8StringEncoding) |error|:(reference))

return




|

[XML]XMLとしてSVGを生成する


【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "UniformTypeIdentifiers"
use framework "AppKit"
use scripting additions
property refMe : a reference to current application
set appFileManager to refMe's NSFileManager's defaultManager()


###設定
set strWidth to ("360") as text
set strHight to ("720") as text
set strText to ("美しい日本語") as text
set strFontSize to ("36") as text
#
set strTextRange to (strFontSize * (count of strText))

###【1】保存先ファイルパス
###デスクトップ
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
###保存ファイルURL
set strFileName to ("test.svg") as text
set ocidSaveFilePathURL to ocidDesktopDirPathURL's URLByAppendingPathComponent:(strFileName)

###【2】XML生成
set ocidXMLDoc to refMe's NSXMLDocument's alloc()'s init()
ocidXMLDoc's setVersion:("1.0")
ocidXMLDoc's setCharacterEncoding:("UTF-8")
ocidXMLDoc's setStandalone:("no")
(*
NSXMLDocumentXMLKind: XML形式
NSXMLDocumentXHTMLKind: XHTML形式の
NSXMLDocumentHTMLKind: HTML形式の
NSXMLDocumentTextKind: プレーンテキスト形式
*)
ocidXMLDoc's setDocumentContentKind:(refMe's NSXMLDocumentXMLKind)

###【3】DTD生成
set ocidDTD to refMe's NSXMLDTD's alloc()'s init()
ocidDTD's setName:("svg")
ocidDTD's setPublicID:("-//W3C//DTD SVG 1.1//EN")
ocidDTD's setSystemID:("http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd")
####【3-1】DTDをXMLにセットする
ocidXMLDoc's setDTD:(ocidDTD)

###【4】ROOTエレメントを生成
set ocidRootElement to refMe's NSXMLElement's elementWithName:("svg")
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("version") stringValue:("1.1")
ocidRootElement's addAttribute:(ocidAddNode)
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("xmlns") stringValue:("http://www.w3.org/2000/svg")
ocidRootElement's addAttribute:(ocidAddNode)
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("xmlns:xlink") stringValue:("http://www.w3.org/1999/xlink")
ocidRootElement's addAttribute:(ocidAddNode)
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("xml:space") stringValue:("preserve")
ocidRootElement's addAttribute:(ocidAddNode)
#背景色を指定する場合はここ
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("style") stringValue:("fill-rule:nonzero;clip-rule:evenodd;stroke-linecap:round;stroke-linejoin:round;")
ocidRootElement's addAttribute:(ocidAddNode)
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("width") stringValue:("" & strWidth & ".0px")
ocidRootElement's addAttribute:(ocidAddNode)
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("height") stringValue:("" & strHight & ".0px")
ocidRootElement's addAttribute:(ocidAddNode)
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("viewBox") stringValue:("0 0 " & strWidth & " " & strHight & "")
ocidRootElement's addAttribute:(ocidAddNode)
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("stroke-miterlimit") stringValue:("10")
ocidRootElement's addAttribute:(ocidAddNode)
###【4-1】defs ここは空で
set ocidDefsElement to refMe's NSXMLElement's elementWithName:("defs")
ocidRootElement's addChild:(ocidDefsElement)
###【4-2】path一番下のレイヤー
set ocidBackgroundElement to refMe's NSXMLElement's elementWithName:("path")
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("d") stringValue:("M0 0L" & strWidth & " 0L" & strWidth & " " & strHight & "L0 " & strHight & "L0 0Z")
ocidBackgroundElement's addAttribute:(ocidAddNode)
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("fill") stringValue:("#AAAAAA")
ocidBackgroundElement's addAttribute:(ocidAddNode)
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("fill-rule") stringValue:("nonzero")
ocidBackgroundElement's addAttribute:(ocidAddNode)
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("opacity") stringValue:("1")
ocidBackgroundElement's addAttribute:(ocidAddNode)
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("stroke") stringValue:("none")
ocidBackgroundElement's addAttribute:(ocidAddNode)
#【4-2】pathをrootエレメントにセット
ocidRootElement's addChild:(ocidBackgroundElement)
###【4-3】g
set ocidGElement to refMe's NSXMLElement's elementWithName:("g")
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("id") stringValue:("text")
ocidGElement's addAttribute:(ocidAddNode)
###【4-3-1】text
set ocidTextElement to refMe's NSXMLElement's elementWithName:("text")
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("fill") stringValue:("#000000")
ocidTextElement's addAttribute:(ocidAddNode)
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("font-family") stringValue:("mono")
ocidTextElement's addAttribute:(ocidAddNode)
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("font-size") stringValue:("" & strFontSize & "")
ocidTextElement's addAttribute:(ocidAddNode)
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("opacity") stringValue:("1")
ocidTextElement's addAttribute:(ocidAddNode)
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("stroke") stringValue:("none")
ocidTextElement's addAttribute:(ocidAddNode)
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("x") stringValue:("0")
ocidTextElement's addAttribute:(ocidAddNode)
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("y") stringValue:("0")
ocidTextElement's addAttribute:(ocidAddNode)
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("text-anchor") stringValue:("start")
ocidTextElement's addAttribute:(ocidAddNode)
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("transform") stringValue:("matrix(1 0 0 1 0 360)")
ocidTextElement's addAttribute:(ocidAddNode)
###【4-3-2】tspan
set ocidTSpanElement to refMe's NSXMLElement's elementWithName:("tspan")
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("x") stringValue:("0")
ocidTSpanElement's addAttribute:(ocidAddNode)
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("y") stringValue:("0")
ocidTSpanElement's addAttribute:(ocidAddNode)
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("textLength") stringValue:(strTextRange)
ocidTSpanElement's addAttribute:(ocidAddNode)
ocidTSpanElement's setStringValue:(strText)

#######
#【4-3-2】tspan を【4-3-1】textの子要素にセット
ocidTextElement's addChild:(ocidTSpanElement)
#【4-3-1】textを 【4-3】gの子要素にセット
ocidGElement's addChild:(ocidTextElement)
#【4-3】gをrootエレメントの子要素としてセット
ocidRootElement's addChild:(ocidGElement)
#【4-3】ROOTエレメントXMLにセットする
ocidXMLDoc's setRootElement:(ocidRootElement)
###【5】XMLデータにして(ここでテキスト形式のXMLに)
set ocidXMLdata to ocidXMLDoc's XMLDataWithOptions:(refMe's NSXMLNodePrettyPrint)
###【6】ファイルに保存
set listDone to ocidXMLdata's writeToURL:(ocidSaveFilePathURL) options:(refMe's NSDataWritingAtomic) |error|:(reference)


return


|

[SVG] adobe illustrator の編集機能 adobe_illustrator_pgfを削除する