Created
November 22, 2018 13:43
-
-
Save drott/5ce9cbe1508e1a9bb153dfc1e1a44b1c to your computer and use it in GitHub Desktop.
Variable Color Font Rendering Issue Reproduction
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Variable Color Font Rendering Issue Reproduction | |
// ViewController.swift | |
// | |
import Cocoa | |
class ViewController: NSViewController { | |
final class Line: NSView { | |
override func draw(_ dirtyRect: NSRect) { | |
let data = NSData(contentsOfFile: "/Users/drott/Downloads/RocherColorGX-subset.ttf")! | |
let providerRef = CGDataProvider.init(data:data)! | |
let cg_font = CGFont.init(providerRef) | |
var variations_dict = cg_font.variations as! [String:CFNumber] | |
let bezel_value = 60.0 as CFNumber | |
variations_dict["Bevel"] = bezel_value | |
let cg_font_variations = cg_font.copy(withVariations:variations_dict as! CFMutableDictionary)! | |
let font = CTFontCreateWithGraphicsFont(cg_font_variations, 128, nil, nil) | |
let textRect: NSRect = NSMakeRect(0, 0, 1200, 200) | |
let textFontAttributes = [ | |
NSFontAttributeName: font as NSFont | |
] | |
let myText = "eé" as NSString | |
myText.draw(in: textRect, withAttributes: textFontAttributes) | |
} | |
} | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
let frame = CGRect(x: 0, y: 0, width: 1200, height: 200) | |
let line = Line(frame: frame) | |
view.addSubview(line) | |
// Do any additional setup after loading the view. | |
} | |
override var representedObject: Any? { | |
didSet { | |
// Update the view, if already loaded. | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment