0
아래의 클래스 & func을 사용하여 보이지 않는 문자를 표시하려고하는데 잘 동작합니다.Swift의 drawGlyphsForGlyphRange (보이지 않는 문자 표시). replaceGlyphAtIndex가 더 이상 사용되지 않습니다
그러나 replaceGlyphAtIndex는 OS X 10.11에서 더 이상 사용되지 않습니다 우리는() setGlyhs를 사용할 필요가
setGlyphs(<#T##glyphs: UnsafePointer<CGGlyph>##UnsafePointer<CGGlyph>#>, properties: <#T##UnsafePointer<NSGlyphProperty>#>, characterIndexes: <#T##UnsafePointer<Int>#>, font: <#T##NSFont#>, forGlyphRange: <#T##NSRange#>)
하지만 setGlyphs에 replaceGlyphAtIndex을 변환하는 방법에 어려움을 겪고 있어요. 아래에서 GlyphAtIndex를 setGlyphs()로 바꾸는 방법을 제안 해 줄 수 있습니까?
아래에서 시도했지만 충돌이 발생했습니다.
let data = String(g).dataUsingEncoding(NSUTF8StringEncoding)
let cgG = UnsafePointer<CGGlyph>(data!.bytes)
self.setGlyphs(cgG, properties: nil, characterIndexes: UnsafePointer<Int>(bitPattern: characterIndex), font: font as! NSFont, forGlyphRange: NSMakeRange(glyphIndex, 1))
위의 코드 줄에서 잘못된 점을 알 수 있습니까?
class MyLayoutManager: NSLayoutManager {
override func drawGlyphsForGlyphRange(glyphsToShow: NSRange, atPoint origin: NSPoint) {
if let storage = self.textStorage {
let s = storage.string
let startIndex = s.startIndex
for glyphIndex in glyphsToShow.location ..< glyphsToShow.location + glyphsToShow.length {
let characterIndex = self.characterIndexForGlyphAtIndex(glyphIndex)
let ch = s[startIndex.advancedBy(characterIndex)]
switch ch {
case " ": //Blank Space
let attrs = storage.attributesAtIndex(characterIndex, effectiveRange: nil)
if let font = attrs[NSFontAttributeName] {
let g = font.glyphWithName("period")//("periodcentered")
self.replaceGlyphAtIndex(glyphIndex, withGlyph: g)
// let data = String(g).dataUsingEncoding(NSUTF8StringEncoding)
// let cgG = UnsafePointer<CGGlyph>(data!.bytes)
//
// self.setGlyphs(cgG, properties: nil, characterIndexes: UnsafePointer<Int>(bitPattern: characterIndex), font: font as! NSFont, forGlyphRange: NSMakeRange(glyphIndex, 1))
}
case "\n": //New Line
let attrs = storage.attributesAtIndex(characterIndex, effectiveRange: nil)
if let font = attrs[NSFontAttributeName] {
let g = font.glyphWithName("logicalnot")
self.replaceGlyphAtIndex(glyphIndex, withGlyph: g)
}
case newLineUniCodeStr:
let attrs = storage.attributesAtIndex(characterIndex, effectiveRange: nil)
if let font = attrs[NSFontAttributeName] {
let g = font.glyphWithName("logicalnot")
self.replaceGlyphAtIndex(glyphIndex, withGlyph: g)
}
default:
break
}
}
}
super.drawGlyphsForGlyphRange(glyphsToShow, atPoint: origin)
}
}
불행하게도,이 방법은 너무 느립니다 (그것은 다른 사람에게 도움이 될 수 있으므로 아래에있는 내 코드를 게시) 및 @VitaliyVashchenko가 네, 최근에 그 눈치 않았다 멀티 페이지 레이아웃 –
작동하지 않습니다. 더 좋은 아이디어는 알고 있습니까? 그래서 그는 저와 다른 사람들에게 도움이 될 것입니다. –
네, 매우 효율적입니다. 솔루션을 찾았을 때 내 질문 주제에 코드를 게시했습니다. http://stackoverflow.com/questions/39545718/nslayoutmanager-hides-new-line-characters-no-matter-what-i-do –