Archive for the 'NSShadow' Category

2017/05/27 書式つきテキストを組み立てて、クリップボードに設定(影をつける)



– Created 2017-05-26 by Takaaki Naganoya
– 2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "AppKit"

set anAttrStr to makeRTFfromParameters("ぴよまるソフトウェア", 2.0, 36) of me

set attrList to {anAttrStr}
restoreClipboard(attrList) of me –set the clipboard to rtf_data

on makeRTFfromParameters(aStr as string, outlineNum as real, aFontSize as real)
set aVal1 to current application’s NSFont’s fontWithName:"HiraKakuStdN-W8" |size|:aFontSize
set aKey1 to (current application’s NSFontAttributeName)
set aVal2 to current application’s NSColor’s blackColor()
set aKey2 to (current application’s NSForegroundColorAttributeName)
set aVal3 to -2.0
set akey3 to (current application’s NSKernAttributeName)
set aVal4 to 0
set akey4 to (current application’s NSUnderlineStyleAttributeName)
set aVal5 to 2 –全てのリガチャを有効にする
set akey5 to (current application’s NSLigatureAttributeName)
set aVal6 to outlineNum
set akey6 to (current application’s NSStrokeWidthAttributeName)
set aVal7 to current application’s NSShadow’s alloc()’s init()
aVal7’s setShadowOffset:(current application’s CGSizeMake(1.0, 1.0)) –影のサイズ
aVal7’s setShadowColor:(current application’s NSColor’s blackColor()) –影の色
aVal7’s setShadowBlurRadius:2.0 –ぼかしの半径
set akey7 to (current application’s NSShadowAttributeName)
set keyList to {aKey1, aKey2, akey3, akey4, akey5, akey6, akey7}
set valList to {aVal1, aVal2, aVal3, aVal4, aVal5, aVal6, aVal7}
set attrsDictionary to current application’s NSMutableDictionary’s dictionaryWithObjects:valList forKeys:keyList
set attrStr to current application’s NSMutableAttributedString’s alloc()’s initWithString:aStr attributes:attrsDictionary
return attrStr
end makeRTFfromParameters

–From Shane Stanley’s Book "Everyday AppleScriptObjC"
on restoreClipboard(theArray as list)
  set thePasteboard to current application’s NSPasteboard’s generalPasteboard()
thePasteboard’s clearContents()
thePasteboard’s writeObjects:theArray
end restoreClipboard

★Click Here to Open This Script