/** * Tae Won Ha - http://taewon.de - @hataewon * See LICENSE */ import Cocoa // let cells = ["πŸ‘¨β€πŸ‘¨β€πŸ‘§β€πŸ‘§", "", "a"] // let cells = ["πŸ‘ΆπŸ½", "", "a"] // let cells = ["ΓΌ", "aΝ†", "aΜͺ"] // let cells = ["a", "b" , "c"] // let cells = ["<", "-", "-", "\u{1F600}", "", " ", "b", "c"] class MyView: NSView { required init?(coder decoder: NSCoder) { super.init(coder: decoder) self.setupUgrid() } override func draw(_: NSRect) { guard let context = NSGraphicsContext.current?.cgContext else { return } let cellSize = FontUtils.cellSize(of: fira, linespacing: 1, characterspacing: 1) /* let string = "a\u{034B}" let attrStr = NSAttributedString(string: string, attributes: [.font: fira]) let ctLine = CTLineCreateWithAttributedString(attrStr) let ctRun = (CTLineGetGlyphRuns(ctLine) as! Array)[0] let glyphCount = CTRunGetGlyphCount(ctRun) var glyphs = Array(repeating: CGGlyph(), count: glyphCount) var positions = Array(repeating: CGPoint(), count: glyphCount) var advances = Array(repeating: CGSize(), count: glyphCount) CTRunGetGlyphs(ctRun, .zero, &glyphs) CTRunGetPositions(ctRun, .zero, &positions) CTRunGetAdvances(ctRun, .zero, &advances) let attrs = CTRunGetAttributes(ctRun) as! [NSAttributedStringKey: Any] let font = attrs[NSAttributedStringKey.font] as! NSFont for i in (0..", "=", " ", "-", "-", ">", " ", "<", "=", ">"], attrIds: Array(repeating: 0, count: 10) ) self.ugrid.update( row: 1, startCol: 0, endCol: 10, clearCol: 10, clearAttr: 0, chunk: ["ἐ", "Ο„", "Ξ­", "αΌ”", "-", ">", " ", "<", "=", ">"], attrIds: Array(repeating: 0, count: 10) ) self.ugrid.update( row: 3, startCol: 0, endCol: 10, clearCol: 10, clearAttr: 0, chunk: (0..<10).compactMap { String($0) }, attrIds: Array(repeating: 0, count: 10) ) self.ugrid.update( row: 4, startCol: 0, endCol: 8, clearCol: 8, clearAttr: 0, chunk: ["ΰ€•", "ΰ€–", "ΰ€—", "ΰ€˜", "ΰ₯œ", "-", ">", "ΰ₯œ"], attrIds: Array(repeating: 0, count: 8) ) } } private let fira = NSFont(name: "FiraCode-Regular", size: 36)!