画像とテキストを貼り付けるユーティリティに取り組んでいます。これまでのところ、これを行うための最良の方法はNSPasteboard
、画像とテキストを使用して RTFD データ ストリームにカプセル化することでした。私が抱えている問題は、コピーしたコードをドキュメントに貼り付けるたびに、フォント属性がない (確認済み) にもかかわらず、フォントが「Helvetica サイズ 12」に変更されることです。フォントを変更せずにテキストと画像を強制的に貼り付けることはできますか?
void copyData() {
let pboard = NSPasteboard.generalPasteboard()
pboard.clearContents()
let str = NSMutableAttributedString()
for im in images {
let a = NSTextAttachment()
a.image = im
let s = NSAttributedString(attachment: a)
str.appendAttributedString(s)
}
//now I have an rtf with a whole bunch of images
let range = NSMakeRange(0, str.length)
if let d = str.RTFDFromRange(range, documentAttributes: [NSDocumentTypeDocumentAttribute: NSPlainTextDocumentType]) {
pboard.setData(d, forType: NSPasteboardTypeRTFD)
}
pboard.writeObjects(images)
}