uikit - How to cast a UIFont object to CTFont in Swift -


i'm trying port code swift uses uifont , ctfont, , (successfully, in objective-c) uses simple bridged casts 1 other , vice versa.

for example, consider code (in uifontdescriptor category):

uifont *font = [uifont fontwithdescriptor:self size:0.0]; nsarray *features = cfbridgingrelease(ctfontcopyfeatures((__bridge ctfontref)font)); 

i haven't yet been able figure out how express in swift in way compile. following @ least doesn't:

let font = uifont(descriptor:self, size: 0.0) let features = ctfontcopyfeatures(font ctfont) 

error: 'uifont' not convertible 'ctfont'

try this. can't coerce values 1 type another. if create ctfont descriptor , size though, seems give valid array if don't include matrix transformations (the nil parameter)

let font = ctfontcreatewithfontdescriptor(descriptor, 0.0, nil) let features: nsarray = ctfontcopyfeatures(font) 

as creating ctfontdescriptor, i'd use ctfontdescriptorcreatewithnameandsize or ctfontdescriptorcreatewithattributes depending on you're given. latter takes simple nsdictionary, , former uses font name , size.

to go existing font (call originalfont) following descriptor:

let font = ctfontcreatewithname(originalfont.fontname cfstringref,      originalfont.pointsize cgfloat, nil) 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -