001 | #!/usr/bin/env osascript |
---|
002 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
---|
003 | # |
---|
004 | #com.cocolog-nifty.quicktimer.icefloe |
---|
005 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
---|
006 | use AppleScript version "2.8" |
---|
007 | use framework "Foundation" |
---|
008 | use framework "UniformTypeIdentifiers" |
---|
009 | use framework "AppKit" |
---|
010 | #use framework "Carbon" |
---|
011 | use scripting additions |
---|
012 | property refMe : a reference to current application |
---|
013 | |
---|
014 | ############################# |
---|
015 | #【1】設定項目 |
---|
016 | #Dataフォルダ内にあるファイルから1つ |
---|
017 | set strRandomColorFileNameRGB to ("TOKYO SEEDS.tsv") as text |
---|
018 | #ロゴ画像データ imagesフォルダ内に入れてください |
---|
019 | set strLogoFileName to ("logo-140x140@72.png") as text |
---|
020 | #解像度変更するか? true=144ppi false=72ppi |
---|
021 | set booldHightResolution to false as boolean |
---|
022 | |
---|
023 | ############################# |
---|
024 | #【2】PANTONE カラーデータを読み込む |
---|
025 | set aliasPathToMe to (path to me) as alias |
---|
026 | set strPathToMe to (POSIX path of aliasPathToMe) as text |
---|
027 | set ocidPathToMeStr to refMe's NSString's stringWithString:(strPathToMe) |
---|
028 | set ocidPathToMe to ocidPathToMeStr's stringByStandardizingPath() |
---|
029 | set ocidPathToMeURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidPathToMe) isDirectory:false) |
---|
030 | set ocidContainerDirPathURL to ocidPathToMeURL's URLByDeletingLastPathComponent() |
---|
031 | set strSetPath to ("Data/" & strRandomColorFileNameRGB) as text |
---|
032 | set ocidColorFilePathURL to ocidContainerDirPathURL's URLByAppendingPathComponent:(strSetPath) isDirectory:(false) |
---|
033 | set listResponse to refMe's NSString's alloc()'s initWithContentsOfURL:(ocidColorFilePathURL) encoding:(refMe's NSUTF8StringEncoding) |error| :(reference) |
---|
034 | if (item 2 of listResponse) = (missing value) then |
---|
035 | set ocidReadStrings to (item 1 of listResponse) |
---|
036 | else if (item 2 of listResponse) ≠ (missing value) then |
---|
037 | set strErrorNO to (item 2 of listResponse)'s code() as text |
---|
038 | set strErrorMes to (item 2 of listResponse)'s localizedDescription() as text |
---|
039 | refMe's NSLog("■:" & strErrorNO & strErrorMes) |
---|
040 | return "エラーしました" & strErrorNO & strErrorMes |
---|
041 | end if |
---|
042 | #改行をUNIXに強制 |
---|
043 | set ocidReadStringsTMP to (ocidReadStrings's stringByReplacingOccurrencesOfString:("\n\r") withString:("\n")) |
---|
044 | set ocidReadStringsTMP to (ocidReadStringsTMP's stringByReplacingOccurrencesOfString:("\r") withString:("\n")) |
---|
045 | set ocidReadStrings to (ocidReadStringsTMP's stringByReplacingOccurrencesOfString:("\n\n") withString:("\n")) |
---|
046 | #文末最後が改行の場合は最後の改行を削除する |
---|
047 | set boolLastReturn to (ocidReadStrings's hasSuffix:("\n")) as boolean |
---|
048 | if boolLastReturn is true then |
---|
049 | set numStringLength to ocidReadStrings's |length|() as integer |
---|
050 | set ocidReadStringM to ocidReadStrings's substringToIndex:(numStringLength - 1) |
---|
051 | else |
---|
052 | set ocidReadStringM to ocidReadStrings |
---|
053 | end if |
---|
054 | #改行区切りでArrayにする |
---|
055 | set ocidColorItemArray to ocidReadStringM's componentsSeparatedByString:("\n") |
---|
056 | #リストの数を数えて |
---|
057 | set numCntArray to (ocidColorItemArray's |count|()) as integer |
---|
058 | #どの色にするか? ランダムの値にする |
---|
059 | set numRandomNO to random number from 0 to (numCntArray - 1) |
---|
060 | #ランダムの値で行データ=リストを取得する |
---|
061 | set ocidLineString to ocidColorItemArray's objectAtIndex:(numRandomNO) |
---|
062 | #タブで各値を格納 |
---|
063 | set ocidColorCodeArray to ocidLineString's componentsSeparatedByString:("\t") |
---|
064 | #8BIT カラーの値を 整数に変換 |
---|
065 | set str8bitR to (item 2 of ocidColorCodeArray) as text |
---|
066 | set str8bitG to (item 3 of ocidColorCodeArray) as text |
---|
067 | set str8bitB to (item 4 of ocidColorCodeArray) as text |
---|
068 | set ocid8bitR to refMe's NSDecimalNumber's alloc()'s initWithString:(str8bitR) |
---|
069 | set ocid8bitG to refMe's NSDecimalNumber's alloc()'s initWithString:(str8bitG) |
---|
070 | set ocid8bitB to refMe's NSDecimalNumber's alloc()'s initWithString:(str8bitB) |
---|
071 | set ocid8bit to refMe's NSDecimalNumber's alloc()'s initWithString:("255") |
---|
072 | set ocidFloatR to (ocid8bitR's decimalNumberByDividingBy:(ocid8bit)) |
---|
073 | set ocidFloatG to (ocid8bitG's decimalNumberByDividingBy:(ocid8bit)) |
---|
074 | set ocidFloatB to (ocid8bitB's decimalNumberByDividingBy:(ocid8bit)) |
---|
075 | set numFloatR to ocidFloatR's floatValue() as number |
---|
076 | set numFloatG to ocidFloatG's floatValue() as number |
---|
077 | set numFloatB to ocidFloatB's floatValue() as number |
---|
078 | set numFloatA to (1) as number |
---|
079 | #カラーを定義 |
---|
080 | set ocidBackgroundColor to (refMe's NSColor's colorWithSRGBRed:(numFloatR) green:(numFloatG) blue:(numFloatB) alpha:(numFloatA)) |
---|
081 | #色の名前を取得して描画用にStringにしておく |
---|
082 | set strColorName to (item 1 of ocidColorCodeArray) as text |
---|
083 | set ocidText to (refMe's NSString's stringWithString:(strColorName)) |
---|
084 | ######################## |
---|
085 | #【3】合成画像 |
---|
086 | #デフォルトパス |
---|
087 | set appFileManager to refMe's NSFileManager's defaultManager() |
---|
088 | set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSPicturesDirectory) inDomains:(refMe's NSUserDomainMask)) |
---|
089 | set ocidPicturesDirPathURL to ocidURLsArray's firstObject() |
---|
090 | set ocidSetImageDirPathURL to ocidPicturesDirPathURL's URLByAppendingPathComponent:("ScreenCapture/AutomatorExport") isDirectory:(true) |
---|
091 | set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0 |
---|
092 | ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions) |
---|
093 | set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidSetImageDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error| :(reference) |
---|
094 | #ダイアログ |
---|
095 | set strName to (name of current application) as text |
---|
096 | if strName is "osascript" then |
---|
097 | tell application "Finder" to activate |
---|
098 | else |
---|
099 | tell current application to activate |
---|
100 | end if |
---|
101 | #自分用 |
---|
102 | set ocidURLsArray to appFileManager's URLsForDirectory:(refMe's NSPicturesDirectory) inDomains:(refMe's NSUserDomainMask) |
---|
103 | set ocidPicturesDirPathURL to ocidURLsArray's firstObject() |
---|
104 | set ocidAutomatorExportDirPathURL to ocidPicturesDirPathURL's URLByAppendingPathComponent:("ScreenCapture/AutomatorExport") isDirectory:(false) |
---|
105 | set aliasDefaultLocation to (ocidAutomatorExportDirPathURL's absoluteURL()) as alias |
---|
106 | (* 一般用 |
---|
107 | set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask)) |
---|
108 | set ocidDesktopDirPathURL to ocidURLsArray's firstObject() |
---|
109 | set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias |
---|
110 | *) |
---|
111 | set listUTI to {"public.image"} |
---|
112 | set strMes to ("画像ファイルを選んでください") as text |
---|
113 | set strPrompt to ("画像ファイルを選んでください") as text |
---|
114 | try |
---|
115 | set aliasFilePath to (choose file strMes with prompt strPrompt default location (aliasDefaultLocation) of type listUTI with invisibles and showing package contents without multiple selections allowed) as alias |
---|
116 | on error |
---|
117 | log "エラーしました" |
---|
118 | return "エラーしました" |
---|
119 | end try |
---|
120 | #セットする画像のパス |
---|
121 | set strSetImageFilePath to (POSIX path of aliasFilePath) as text |
---|
122 | set ocidSetImageFilePathStr to refMe's NSString's stringWithString:(strSetImageFilePath) |
---|
123 | set ocidSetImageFilePath to ocidSetImageFilePathStr's stringByStandardizingPath() |
---|
124 | set ocidSetImageFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidSetImageFilePath) isDirectory:false) |
---|
125 | |
---|
126 | ######################## |
---|
127 | #【4】画像読み込み |
---|
128 | set ocidOption to (refMe's NSDataReadingMappedIfSafe) |
---|
129 | set listResponse to refMe's NSData's alloc()'s initWithContentsOfURL:(ocidSetImageFilePathURL) options:(ocidOption) |error| :(reference) |
---|
130 | set ocidSetImageData to (item 1 of listResponse) |
---|
131 | #NSImage's |
---|
132 | set ocidSetImage to refMe's NSImage's alloc()'s initWithData:(ocidSetImageData) |
---|
133 | set ocidSetImageRepArray to ocidSetImage's representations() |
---|
134 | set ocidSetImageRep to ocidSetImageRepArray's firstObject() |
---|
135 | set numSetImagePixelsWidth to ocidSetImageRep's pixelsWide() |
---|
136 | set numSetImagePixelsHeight to ocidSetImageRep's pixelsHigh() |
---|
137 | |
---|
138 | #サイズ計算 幅 縦 最大1060で縦横比を保持する |
---|
139 | if numSetImagePixelsWidth > numSetImagePixelsHeight then |
---|
140 | set numRatio to (numSetImagePixelsHeight / numSetImagePixelsWidth) as number |
---|
141 | set numDiffW to (1060 - numSetImagePixelsWidth) |
---|
142 | set numSetW to (numSetImagePixelsWidth + numDiffW) as integer |
---|
143 | set numSetH to (numSetW * numRatio) as integer |
---|
144 | set numDiffH to (820 - numSetH) as integer |
---|
145 | else if numSetImagePixelsWidth ≤ numSetImagePixelsHeight then |
---|
146 | set numRatio to (numSetImagePixelsWidth / numSetImagePixelsHeight) as number |
---|
147 | set numDiffH to (820 - numSetImagePixelsHeight) as number |
---|
148 | set numSetH to (numSetImagePixelsHeight + numDiffH) as integer |
---|
149 | set numSetW to (numSetH * numRatio) as integer |
---|
150 | set numDiffW to (1060 - numSetW) as integer |
---|
151 | end if |
---|
152 | #最終的なDRAWRECTを計算 |
---|
153 | set numPasteX to (1060 - numSetW) / 2 + 10 as integer |
---|
154 | set numPasteY to ((1060 - numSetH) / 2) + 130 as integer |
---|
155 | set ocidSetImageDrawRect to refMe's NSRect's NSMakeRect(numPasteX, numPasteY, numSetW, numSetH) |
---|
156 | set ocidSetImageFromRect to refMe's NSRect's NSMakeRect(0, 0, numSetImagePixelsWidth, numSetImagePixelsHeight) |
---|
157 | log ocidSetImageFromRect |
---|
158 | log ocidSetImageDrawRect |
---|
159 | |
---|
160 | ######################## |
---|
161 | #【5】画像保存先 |
---|
162 | set ocidSaveDirPathURL to ocidPicturesDirPathURL's URLByAppendingPathComponent:("ScreenCapture/PostImage") isDirectory:(true) |
---|
163 | set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error| :(reference) |
---|
164 | ######################## |
---|
165 | #【6】ロゴマーク読み込み |
---|
166 | set strSetValue to ("images/" & strLogoFileName) as text |
---|
167 | set ocidLogoFilePathURL to ocidContainerDirPathURL's URLByAppendingPathComponent:(strSetValue) isDirectory:(false) |
---|
168 | #ロゴマーク読み込みNSData's |
---|
169 | set ocidOption to (refMe's NSDataReadingMappedIfSafe) |
---|
170 | set listResponse to refMe's NSData's alloc()'s initWithContentsOfURL:(ocidLogoFilePathURL) options:(ocidOption) |error| :(reference) |
---|
171 | set ocidLogoData to (item 1 of listResponse) |
---|
172 | #NSImage's |
---|
173 | set ocidLogoImage to refMe's NSImage's alloc()'s initWithData:(ocidLogoData) |
---|
174 | set ocidLogoImageRepArray to ocidLogoImage's representations() |
---|
175 | set ocidLogoImageRep to ocidLogoImageRepArray's firstObject() |
---|
176 | #ロゴマークのペースト位置のRECT |
---|
177 | set ocidLogoDrawRect to refMe's NSRect's NSMakeRect(920, 10, 140, 140) |
---|
178 | set ocidLogoFromRect to refMe's NSRect's NSMakeRect(0, 0, 140, 140) |
---|
179 | |
---|
180 | ######################## |
---|
181 | #【7】画像生成開始 |
---|
182 | set listResponse to {1080, 1080} as list |
---|
183 | set numW to (item 1 of listResponse) as integer |
---|
184 | set numH to (item 2 of listResponse) as integer |
---|
185 | set strDateTime to doGetNextDateNo({"yyyyMMddhhmm", 1}) |
---|
186 | set strFileName to (strDateTime & "-" & numW & "x" & numH & "@144") as text |
---|
187 | set ocidSaveBasePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(strFileName) isDirectory:(false) |
---|
188 | set ocidSaveFilePathURL to ocidSaveBasePathURL's URLByAppendingPathExtension:("png") |
---|
189 | #カラーICC |
---|
190 | set strIccFilePath to ("/System/Library/ColorSync/Profiles/sRGB Profile.icc") as text |
---|
191 | set ocidIccFilePathStr to refMe's NSString's stringWithString:(strIccFilePath) |
---|
192 | set ocidIccFilePath to ocidIccFilePathStr's stringByStandardizingPath |
---|
193 | set ocidIccFilePathURL to refMe's NSURL's alloc()'s initFileURLWithPath:(ocidIccFilePath) isDirectory:(false) |
---|
194 | set ocidProfileData to refMe's NSData's alloc()'s initWithContentsOfURL:(ocidIccFilePathURL) |
---|
195 | #セットするRECT |
---|
196 | set ocidDrawRect to refMe's NSRect's NSMakeRect(0, 0, numW, numH) |
---|
197 | # RGB系のカラースペース |
---|
198 | set ocidColorSpaceName to (refMe's NSCalibratedRGBColorSpace) |
---|
199 | # アルファあり |
---|
200 | set ocidBitmapFormat to (refMe's NSAlphaFirstBitmapFormat) |
---|
201 | #アートボード |
---|
202 | set ocidArtBoardRep to (refMe's NSBitmapImageRep's alloc()'s initWithBitmapDataPlanes:(missing value) pixelsWide:(numW) pixelsHigh:(numH) bitsPerSample:(8) samplesPerPixel:(4) hasAlpha:(true) isPlanar:(false) colorSpaceName:(ocidColorSpaceName) bitmapFormat:(ocidBitmapFormat) bytesPerRow:(0) bitsPerPixel:(32)) |
---|
203 | |
---|
204 | ######################## |
---|
205 | #【8】最下層アートボード |
---|
206 | set ocidArtBoardColor to (refMe's NSColor's colorWithSRGBRed:(numFloatR) green:(numFloatG) blue:(numFloatB) alpha:(numFloatA)) |
---|
207 | ####【NSGraphicsContext's】 |
---|
208 | refMe's NSGraphicsContext's saveGraphicsState() |
---|
209 | #Context 選択した画像を読み込んで |
---|
210 | set ocidSetImageContext to (refMe's NSGraphicsContext's graphicsContextWithBitmapImageRep:(ocidArtBoardRep)) |
---|
211 | (ocidSetImageContext's setShouldAntialias:(true)) |
---|
212 | (ocidSetImageContext's setImageInterpolation:(refMe's NSImageInterpolationHigh)) |
---|
213 | (ocidSetImageContext's setColorRenderingIntent:(refMe's NSColorRenderingIntentRelativeColorimetric)) |
---|
214 | #生成された画像でNSGraphicsContext初期化 |
---|
215 | (refMe's NSGraphicsContext's setCurrentContext:(ocidSetImageContext)) |
---|
216 | #外側の角丸のマスク |
---|
217 | set ocidMaskRect to refMe's NSRect's NSMakeRect(0, 0, numW, numH) |
---|
218 | set ocidMaskPath to refMe's NSBezierPath's bezierPathWithRoundedRect:(ocidDrawRect) xRadius:(40) yRadius:(40) |
---|
219 | ocidMaskPath's addClip() |
---|
220 | #RGB値で背景色をセットして |
---|
221 | ocidArtBoardColor's |set|() |
---|
222 | #指定した色で背景を塗る |
---|
223 | refMe's NSRectFill(ocidDrawRect) |
---|
224 | #画像をNSCompositingOperationSourceOver |
---|
225 | #(ocidSetImageRep's drawInRect:(ocidSetImageDrawRect) fromRect:(ocidSetImageFromRect) operation:(refMe's NSCompositingOperationSourceOver) fraction:(1.0) respectFlipped:(false) hints:(missing value)) |
---|
226 | #外側の角丸のマスク |
---|
227 | set ocidMaskRect to refMe's NSRect's NSMakeRect(0, 0, numW, numH) |
---|
228 | set ocidMaskPath to refMe's NSBezierPath's bezierPathWithRoundedRect:(ocidDrawRect) xRadius:(40) yRadius:(40) |
---|
229 | ocidMaskPath's addClip() |
---|
230 | (ocidSetImageRep's drawInRect:(ocidSetImageDrawRect) fromRect:(refMe's NSZeroRect) operation:(refMe's NSCompositingOperationSourceOver) fraction:(1.0) respectFlipped:(false) hints:(missing value)) |
---|
231 | #処理終了 |
---|
232 | refMe's NSGraphicsContext's restoreGraphicsState() |
---|
233 | ####【NSGraphicsContext's】 |
---|
234 | |
---|
235 | ######################## |
---|
236 | #【9】画像の上に来るフレーム |
---|
237 | #色指定 |
---|
238 | set ocidBaseBoardColor to (refMe's NSColor's colorWithSRGBRed:(numFloatR) green:(numFloatG) blue:(numFloatB) alpha:(numFloatA)) |
---|
239 | #サイズ |
---|
240 | set baseSiezeWPx to 1080 as integer |
---|
241 | set baseSiezeHPx to 1080 as integer |
---|
242 | #ドロップシャドウ初期化 |
---|
243 | set ocidSetShadow to refMe's NSShadow's alloc()'s init() |
---|
244 | set ocidOffSetSize to refMe's NSSize's NSMakeSize(0, 0) |
---|
245 | ocidSetShadow's setShadowOffset:(ocidOffSetSize) |
---|
246 | ocidSetShadow's setShadowBlurRadius:(20) |
---|
247 | set ocidShadowColor to refMe's NSColor's colorWithCalibratedWhite:(0) alpha:(0.5) |
---|
248 | ocidSetShadow's setShadowColor:(ocidShadowColor) |
---|
249 | #アートボード |
---|
250 | set ocidBaseBoardRep to (refMe's NSBitmapImageRep's alloc()'s initWithBitmapDataPlanes:(missing value) pixelsWide:(numW) pixelsHigh:(numH) bitsPerSample:(8) samplesPerPixel:(4) hasAlpha:(true) isPlanar:(false) colorSpaceName:(ocidColorSpaceName) bitmapFormat:(ocidBitmapFormat) bytesPerRow:(0) bitsPerPixel:(32)) |
---|
251 | ####【NSGraphicsContext's】 |
---|
252 | refMe's NSGraphicsContext's saveGraphicsState() |
---|
253 | #Context 選択した画像を読み込んで |
---|
254 | set ocidSetImageContext to (refMe's NSGraphicsContext's graphicsContextWithBitmapImageRep:(ocidBaseBoardRep)) |
---|
255 | (ocidSetImageContext's setShouldAntialias:(true)) |
---|
256 | (ocidSetImageContext's setImageInterpolation:(refMe's NSImageInterpolationHigh)) |
---|
257 | (ocidSetImageContext's setColorRenderingIntent:(refMe's NSColorRenderingIntentRelativeColorimetric)) |
---|
258 | #生成された画像でNSGraphicsContext初期化 |
---|
259 | (refMe's NSGraphicsContext's setCurrentContext:(ocidSetImageContext)) |
---|
260 | #外側の角丸のマスク |
---|
261 | set ocidMaskRectOut to refMe's NSRect's NSMakeRect(0, 0, numW, numH) |
---|
262 | set ocidMaskOutPath to refMe's NSBezierPath's bezierPathWithRoundedRect:(ocidMaskRectOut) xRadius:(40) yRadius:(40) |
---|
263 | #ocidMaskPath's addClip() |
---|
264 | #インマスク |
---|
265 | set ocidMaskRectIn to refMe's NSRect's NSMakeRect(20, 260, 1040, 800) |
---|
266 | set ocidMaskInPath to refMe's NSBezierPath's bezierPathWithRoundedRect:(ocidMaskRectIn) xRadius:(40) yRadius:(40) |
---|
267 | ocidMaskOutPath's appendBezierPath:(ocidMaskInPath) |
---|
268 | ocidMaskOutPath's setWindingRule:(refMe's NSEvenOddWindingRule) |
---|
269 | ocidMaskOutPath's addClip() |
---|
270 | #RGB値で背景色をセットして |
---|
271 | ocidBaseBoardColor's |set|() |
---|
272 | #指定した色で背景を塗る |
---|
273 | refMe's NSRectFill(ocidDrawRect) |
---|
274 | #外側の角丸のマスク |
---|
275 | set ocidMaskRect to refMe's NSRect's NSMakeRect(0, 0, numW, numH) |
---|
276 | set ocidMaskPath to refMe's NSBezierPath's bezierPathWithRoundedRect:(ocidDrawRect) xRadius:(40) yRadius:(40) |
---|
277 | ocidMaskPath's addClip() |
---|
278 | #ロゴマークをNSCompositingOperationSourceOver |
---|
279 | (ocidLogoImageRep's drawInRect:(ocidLogoDrawRect) fromRect:(ocidLogoFromRect) operation:(refMe's NSCompositingOperationSourceOver) fraction:(1.0) respectFlipped:(false) hints:(missing value)) |
---|
280 | #処理終了 |
---|
281 | refMe's NSGraphicsContext's restoreGraphicsState() |
---|
282 | ####【NSGraphicsContext's】 |
---|
283 | |
---|
284 | ######################## |
---|
285 | #【10】アートボードにフレームをペースト |
---|
286 | set ocidDrawRect to refMe's NSRect's NSMakeRect(0, 0, 1080, 1080) |
---|
287 | set ocidFromRect to refMe's NSRect's NSMakeRect(0, 0, 1080, 1080) |
---|
288 | ####【NSGraphicsContext's】 |
---|
289 | refMe's NSGraphicsContext's saveGraphicsState() |
---|
290 | #Context 選択した画像を読み込んで |
---|
291 | set ocidSetImageContext to (refMe's NSGraphicsContext's graphicsContextWithBitmapImageRep:(ocidArtBoardRep)) |
---|
292 | (ocidSetImageContext's setShouldAntialias:(true)) |
---|
293 | (ocidSetImageContext's setImageInterpolation:(refMe's NSImageInterpolationHigh)) |
---|
294 | (ocidSetImageContext's setColorRenderingIntent:(refMe's NSColorRenderingIntentRelativeColorimetric)) |
---|
295 | #生成された画像でNSGraphicsContext初期化 |
---|
296 | (refMe's NSGraphicsContext's setCurrentContext:(ocidSetImageContext)) |
---|
297 | #シャドウをセットして |
---|
298 | ocidSetShadow's |set|() |
---|
299 | #外側の角丸のマスク |
---|
300 | set ocidMaskRect to refMe's NSRect's NSMakeRect(0, 0, numW, numH) |
---|
301 | set ocidMaskPath to refMe's NSBezierPath's bezierPathWithRoundedRect:(ocidDrawRect) xRadius:(40) yRadius:(40) |
---|
302 | ocidMaskPath's addClip() |
---|
303 | #背景画像の上NSCompositeSourceOver |
---|
304 | set appOperation to (refMe's NSCompositeSourceOver) |
---|
305 | ocidBaseBoardRep's drawInRect:(ocidDrawRect) fromRect:(ocidFromRect) operation:(appOperation) fraction:1.0 respectFlipped:true hints:(missing value) |
---|
306 | #処理終了 |
---|
307 | refMe's NSGraphicsContext's restoreGraphicsState() |
---|
308 | ####【NSGraphicsContext's】 |
---|
309 | |
---|
310 | ######################## |
---|
311 | #【11】カラーバー4色 |
---|
312 | set ocidWhiteColor to (refMe's NSColor's colorWithSRGBRed:(1) green:(1) blue:(1) alpha:(1)) |
---|
313 | set numFirstDiv to 1.1 as number |
---|
314 | set numSecondDiv to 1.15 as number |
---|
315 | set numThirdDiv to 1.2 as number |
---|
316 | set numFourthDiv to 1.25 as number |
---|
317 | set ocidWhiteColor8 to (refMe's NSColor's colorWithSRGBRed:(numFloatR * numFirstDiv) green:(numFloatG * numFirstDiv) blue:(numFloatB * numFirstDiv) alpha:(numFloatA)) |
---|
318 | set ocidWhiteColor6 to (refMe's NSColor's colorWithSRGBRed:(numFloatR * numSecondDiv) green:(numFloatG * numSecondDiv) blue:(numFloatB * numSecondDiv) alpha:(numFloatA)) |
---|
319 | set ocidWhiteColor4 to (refMe's NSColor's colorWithSRGBRed:(numFloatR * numThirdDiv) green:(numFloatG * numThirdDiv) blue:(numFloatB * numThirdDiv) alpha:(numFloatA)) |
---|
320 | set ocidWhiteColor2 to (refMe's NSColor's colorWithSRGBRed:(numFloatR * numFourthDiv) green:(numFloatG * numFourthDiv) blue:(numFloatB * numFourthDiv) alpha:(numFloatA)) |
---|
321 | set listWhiteColor to {ocidWhiteColor8, ocidWhiteColor6, ocidWhiteColor4, ocidWhiteColor2} as list |
---|
322 | #描画位置のRECT |
---|
323 | set ocidWhiteColor8Rect to refMe's NSRect's NSMakeRect(20, 160, 250, 90) |
---|
324 | set ocidWhiteColor6Rect to refMe's NSRect's NSMakeRect(282, 160, 250, 90) |
---|
325 | set ocidWhiteColor4Rect to refMe's NSRect's NSMakeRect(544, 160, 250, 90) |
---|
326 | set ocidWhiteColor2Rect to refMe's NSRect's NSMakeRect(807, 160, 250, 90) |
---|
327 | set listWhiteColorRect to {ocidWhiteColor8Rect, ocidWhiteColor6Rect, ocidWhiteColor4Rect, ocidWhiteColor2Rect} as list |
---|
328 | #カラーバー用画像を4つ |
---|
329 | repeat with itemNO from 1 to 4 by 1 |
---|
330 | set itemWColor to (item itemNO of listWhiteColor) |
---|
331 | set itemWColorRect to (item itemNO of listWhiteColorRect) |
---|
332 | set ocidColorBarRep to (refMe's NSBitmapImageRep's alloc()'s initWithBitmapDataPlanes:(missing value) pixelsWide:(240) pixelsHigh:(90) bitsPerSample:(8) samplesPerPixel:(4) hasAlpha:(true) isPlanar:(false) colorSpaceName:(ocidColorSpaceName) bitmapFormat:(ocidBitmapFormat) bytesPerRow:(0) bitsPerPixel:(32)) |
---|
333 | ####【NSGraphicsContext's】 |
---|
334 | refMe's NSGraphicsContext's saveGraphicsState() |
---|
335 | #Context 選択した画像を読み込んで |
---|
336 | set ocidSetImageContext to (refMe's NSGraphicsContext's graphicsContextWithBitmapImageRep:(ocidArtBoardRep)) |
---|
337 | (ocidSetImageContext's setShouldAntialias:(true)) |
---|
338 | (ocidSetImageContext's setImageInterpolation:(refMe's NSImageInterpolationHigh)) |
---|
339 | (* setColorRenderingIntent |
---|
340 | 標準 |
---|
341 | NSColorRenderingIntentDefault |
---|
342 | 絶対的な色彩を保持 (色の再現重視 印刷向き) |
---|
343 | NSColorRenderingIntentAbsoluteColorimetric |
---|
344 | 相対的な色彩を保持 (全体的なバランス重視 モニター向き) |
---|
345 | NSColorRenderingIntentRelativeColorimetric |
---|
346 | 知覚的な色再現 (写真向き 色数が多い場合) |
---|
347 | NSColorRenderingIntentPerceptual |
---|
348 | 彩度を優先 (グラフィック向き 色数が少ない場合) |
---|
349 | NSColorRenderingIntentSaturation |
---|
350 | *) |
---|
351 | (ocidSetImageContext's setColorRenderingIntent:(refMe's NSColorRenderingIntentSaturation)) |
---|
352 | (ocidSetImageContext's setCompositingOperation:(refMe's NSCompositingOperationMultiply)) |
---|
353 | #生成された画像でNSGraphicsContext初期化 |
---|
354 | (refMe's NSGraphicsContext's setCurrentContext:(ocidSetImageContext)) |
---|
355 | #外側の角丸のマスク |
---|
356 | set ocidMaskOutPath to (refMe's NSBezierPath's bezierPathWithRoundedRect:(itemWColorRect) xRadius:(20) yRadius:(20)) |
---|
357 | ocidMaskOutPath's addClip() |
---|
358 | #RGB値で背景色をセットして |
---|
359 | # ocidWhiteColor's setFill() |
---|
360 | #指定した色で背景を塗る |
---|
361 | # refMe's NSRectFill(itemWColorRect) |
---|
362 | |
---|
363 | itemWColor's setFill() |
---|
364 | #指定した色で背景を塗る |
---|
365 | refMe's NSRectFill(itemWColorRect) |
---|
366 | #処理終了 |
---|
367 | refMe's NSGraphicsContext's restoreGraphicsState() |
---|
368 | ####【NSGraphicsContext's】 |
---|
369 | end repeat |
---|
370 | |
---|
371 | ######################## |
---|
372 | #【12】文字入れ |
---|
373 | ###フォント初期化 |
---|
374 | set appFontManager to refMe's NSFontManager |
---|
375 | set appSharedMaanager to appFontManager's sharedFontManager() |
---|
376 | set ocidTextAttr to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0) |
---|
377 | set ocidStyle to refMe's NSParagraphStyle's defaultParagraphStyle() |
---|
378 | (ocidTextAttr's setObject:(ocidStyle) forKey:(refMe's NSParagraphStyleAttributeName)) |
---|
379 | #テキストカラー黒 |
---|
380 | set ocidTextColor to (refMe's NSColor's colorWithSRGBRed:(0) green:(0) blue:(0) alpha:(1.0)) |
---|
381 | (ocidTextAttr's setObject:(ocidTextColor) forKey:(refMe's NSForegroundColorAttributeName)) |
---|
382 | ####【NSGraphicsContext's】 |
---|
383 | refMe's NSGraphicsContext's saveGraphicsState() |
---|
384 | set ocidContext to (refMe's NSGraphicsContext's graphicsContextWithBitmapImageRep:(ocidArtBoardRep)) |
---|
385 | ###ArtBoardでNSGraphicsContext初期化 |
---|
386 | (refMe's NSGraphicsContext's setCurrentContext:(ocidContext)) |
---|
387 | #フォント指定 |
---|
388 | set ocidFont to (refMe's NSFont's fontWithName:("Helvetica-Bold") |size|:(52)) |
---|
389 | (ocidTextAttr's setObject:(ocidFont) forKey:(refMe's NSFontAttributeName)) |
---|
390 | (ocidTextAttr's setObject:(-1.8) forKey:(refMe's NSKernAttributeName)) |
---|
391 | set ocidTextOrigin to refMe's NSMakePoint((30), (20)) |
---|
392 | #テキストを描画 |
---|
393 | (ocidText's drawAtPoint:(ocidTextOrigin) withAttributes:(ocidTextAttr)) |
---|
394 | #画像作成終了 |
---|
395 | refMe's NSGraphicsContext's restoreGraphicsState() |
---|
396 | ####【NSGraphicsContext's】 |
---|
397 | |
---|
398 | ######################## |
---|
399 | #【13】解像度変更 |
---|
400 | if booldHightResolution is false then |
---|
401 | set ocidSetSize to refMe's NSSize's NSMakeSize(numW, numH) |
---|
402 | ocidArtBoardRep's setSize:(ocidSetSize) |
---|
403 | else if booldHightResolution is true then |
---|
404 | set numPPI to 144 as integer |
---|
405 | set numWpt to ((numW / numPPI) * 72) as integer |
---|
406 | set numHpt to ((numH / numPPI) * 72) as integer |
---|
407 | set ocidSetSize to refMe's NSSize's NSMakeSize(numWpt, numHpt) |
---|
408 | ocidArtBoardRep's setSize:(ocidSetSize) |
---|
409 | end if |
---|
410 | |
---|
411 | ######################## |
---|
412 | #【14】保存 |
---|
413 | set ocidProperty to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0) |
---|
414 | (ocidProperty's setObject:(refMe's NSNumber's numberWithBool:false) forKey:(refMe's NSImageInterlaced)) |
---|
415 | (ocidProperty's setObject:(refMe's NSNumber's numberWithDouble:(1 / 2.2)) forKey:(refMe's NSImageGamma)) |
---|
416 | (ocidProperty's setObject:(ocidProfileData) forKey:(refMe's NSImageColorSyncProfileData)) |
---|
417 | |
---|
418 | #保存データに変換 |
---|
419 | set ocidNSInlineData to (ocidArtBoardRep's representationUsingType:(refMe's NSBitmapImageFileTypePNG) |properties|:(ocidProperty)) |
---|
420 | #保存 |
---|
421 | set boolDone to (ocidNSInlineData's writeToURL:(ocidSaveFilePathURL) options:(refMe's NSDataWritingAtomic) |error| :(reference)) |
---|
422 | |
---|
423 | |
---|
424 | ######################## |
---|
425 | #【15】保存先を開く |
---|
426 | set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace() |
---|
427 | set boolDone to appSharedWorkspace's openURL:(ocidSaveDirPathURL) |
---|
428 | log boolDone |
---|
429 | |
---|
430 | |
---|
431 | ################################ |
---|
432 | # 明日の日付 doGetDateNo(argDateFormat,argCalendarNO) |
---|
433 | # argCalendarNO 1 NSCalendarIdentifierGregorian 西暦 |
---|
434 | # argCalendarNO 2 NSCalendarIdentifierJapanese 和暦 |
---|
435 | ################################ |
---|
436 | to doGetNextDateNo({argDateFormat, argCalendarNO}) |
---|
437 | ##渡された値をテキストで確定させて |
---|
438 | set strDateFormat to argDateFormat as text |
---|
439 | set intCalendarNO to argCalendarNO as integer |
---|
440 | ###日付情報の取得 |
---|
441 | set ocidDate to current application's NSDate's |date|() |
---|
442 | set ocidIntervalt to current application's NSDate's dateWithTimeIntervalSinceNow:(86400) |
---|
443 | ###日付のフォーマットを定義(日本語) |
---|
444 | set ocidFormatterJP to current application's NSDateFormatter's alloc()'s init() |
---|
445 | ###和暦 西暦 カレンダー分岐 |
---|
446 | if intCalendarNO = 1 then |
---|
447 | set ocidCalendarID to (current application's NSCalendarIdentifierGregorian) |
---|
448 | else if intCalendarNO = 2 then |
---|
449 | set ocidCalendarID to (current application's NSCalendarIdentifierJapanese) |
---|
450 | else |
---|
451 | set ocidCalendarID to (current application's NSCalendarIdentifierISO8601) |
---|
452 | end if |
---|
453 | set ocidCalendarJP to current application's NSCalendar's alloc()'s initWithCalendarIdentifier:(ocidCalendarID) |
---|
454 | set ocidTimezoneJP to current application's NSTimeZone's alloc()'s initWithName:("Asia/Tokyo") |
---|
455 | set ocidLocaleJP to current application's NSLocale's alloc()'s initWithLocaleIdentifier:("ja_JP_POSIX") |
---|
456 | ###設定 |
---|
457 | ocidFormatterJP's setTimeZone:(ocidTimezoneJP) |
---|
458 | ocidFormatterJP's setLocale:(ocidLocaleJP) |
---|
459 | ocidFormatterJP's setCalendar:(ocidCalendarJP) |
---|
460 | # ocidFormatterJP's setDateStyle:(current application's NSDateFormatterNoStyle) |
---|
461 | # ocidFormatterJP's setDateStyle:(current application's NSDateFormatterShortStyle) |
---|
462 | # ocidFormatterJP's setDateStyle:(current application's NSDateFormatterMediumStyle) |
---|
463 | # ocidFormatterJP's setDateStyle:(current application's NSDateFormatterLongStyle) |
---|
464 | ocidFormatterJP's setDateStyle:(current application's NSDateFormatterFullStyle) |
---|
465 | ###渡された値でフォーマット定義 |
---|
466 | ocidFormatterJP's setDateFormat:(strDateFormat) |
---|
467 | ###フォーマット適応 |
---|
468 | set ocidDateAndTime to ocidFormatterJP's stringFromDate:(ocidIntervalt) |
---|
469 | ###テキストで戻す |
---|
470 | set strDateAndTime to ocidDateAndTime as text |
---|
471 | return strDateAndTime |
---|
472 | end doGetNextDateNo |
---|
473 | |
---|
474 | |
---|
475 | return "正常終了" |
---|
476 | |
---|