core-text

CoreText and strikethrough on iPhone

丶灬走出姿态 提交于 2019-12-22 10:07:26
问题 I'm currently struggling with the need to display strikethrough text in many UITableViewCell s. Something that written in HTML would looke like <strike>€99</strike> save 50% => now €49 I don't want to use a UIWebView just for a single line of text, especially that it's used in small UITableViewCell s. I know there are reusable cells and all, but I'd like to keep things the more memory-efficient way possible. So... I'm using NSAttributedString s, with the help of AliSoftware's UILabel

Core Text in Cocoa app

感情迁移 提交于 2019-12-22 09:24:13
问题 I have the following sample code which works on iPhone. It draws the text "Hello World!" on the screen using Core Text. Dropping this code into a cocoa project in an NSView produces different results. The font size is scaled much bigger and the letters are drawn on top of each other. How do I have the text draw the same in the cocoa app? - (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSaveGState(context); CFStringRef font_name =

CATextLayer wrapped sizeToFit?

六月ゝ 毕业季﹏ 提交于 2019-12-22 04:17:09
问题 If I set textLayer.wrapped = YES , how do I resize textLayer to contain the wrapped text? I.e., how do I get the new height of the textLayer ? Basically, I want something like -[UILabel sizeToFit] . 回答1: The first thing you need to do is get the size of the text. Thankfully, the NSString UIKit Additions Reference offers a method to do exactly that: - (CGSize)sizeWithFont:(UIFont *)font constrainedToSize:(CGSize)size lineBreakMode:(UILineBreakMode)lineBreakMode That will give you a CGSize that

NSLayoutManager: Calling setLocation(_:forStartOfGlyphRange:) disables kerning in the whole string?

折月煮酒 提交于 2019-12-21 23:18:13
问题 I created simple NSLayoutManager subclass that allows to set custom layout location for defined substrings: class PositionableLayoutManager: NSLayoutManager { var xOffsetsPerGlyphRange = [(NSRange, CGPoint)]() override func invalidateLayoutForCharacterRange(charRange: NSRange, actualCharacterRange actualCharRange: NSRangePointer) { super.invalidateLayoutForCharacterRange(charRange, actualCharacterRange: actualCharRange) for (range, offset) in xOffsetsPerGlyphRange { setLocation(offset,

How to get emoji path in iOS

做~自己de王妃 提交于 2019-12-21 19:54:12
问题 My purpose : Draw outline of every glyph example1: input: text= "666棒" display: Attach :In the figure above, 1 is displayView,2 is inputView. example2: input : text= "666😁棒" display : Attach: In the figure above, 1 is displayView,2 is inputView,3 is nothing rendered. Main ideas is : Use CoreText obtained every CGglyph. Get every glyph's CGPath Use CAShapeLayer display the glyph on screen. Main method: let letters = CGMutablePath() let font = CTFontCreateWithName(fontName as CFString?,

memory management for CTRunDelegateRef iPhone

空扰寡人 提交于 2019-12-21 06:37:33
问题 I focus on a project to add image support based on OmniGroup's rtf editor.I met the problem when I use CTFramesetterCreateWithAttributedString , and it receives EXC_BAD_ACCESS which is caused by a zombie object. For simplicity, I get the NSAttributedString from a rtfd file which only has a photo. I add the method to parser the image tag on iOS based on the Omni's sample. And the part to create the NSAttributedString is followed by this tutorial from raywenderlich, and looks like:

UILabel default kerning different from CATextLayer

吃可爱长大的小学妹 提交于 2019-12-20 18:43:05
问题 I have a UILabel with the string 'LA'. I also have a CATextLayer with the same characters in an NSAttributedString assigned to its string property. The kerning in the UILabel is noticeably different from the CATextLayer . Here's the code. - (void)viewDidLoad { [super viewDidLoad]; // // UILabel // UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(20, 50, 280, 100)]; label1.text = @"LA"; label1.backgroundColor = [UIColor clearColor]; label1.font = [UIFont fontWithName:@"Futura" size

Get CGPath from Text

牧云@^-^@ 提交于 2019-12-18 18:07:21
问题 Hej fellows, I'm currently trying to convert a letter and/or multiple of them to a CGPathRef for manually drawing them into a custom UIView. I tried the way over CoreText and Framesetters including this little snippet but it doesn't seem to work.... NSAttributedString *stringToDraw = [[NSAttributedString alloc] initWithString:content attributes:nil]; // now for the actual drawing CGContextRef context = UIGraphicsGetCurrentContext(); // flip the coordinate system // draw CTFramesetterRef

How do I get an NSFont object from a CGFont or CTFont object?

♀尐吖头ヾ 提交于 2019-12-18 16:32:27
问题 I am dealing with loading a TTF from Resource only. This question helped me answer part 1. But now I need a NSFont from a CGFont or CTFont. This is for a Mac only application. 回答1: How to get an NSFont from a CGFont Use CTFontCreateWithGraphicsFont . How to get an NSFont from a CTFont Do nothing. You already have one. NSFont and CTFont are toll-free bridged, so a CTFont is an NSFont and vice versa. 来源: https://stackoverflow.com/questions/4942711/how-do-i-get-an-nsfont-object-from-a-cgfont-or

Most performant way to draw text on a curve, and animate it?

久未见 提交于 2019-12-18 12:38:11
问题 I'm guessing that it's to make a string out of individual CATextLayers and then position them as required along the curve, then animate. Because that's what's I've got working now, but it loses Kerning. Here's how: Why isn't my curved text centering itself? But is Core Text more performant and able to avoid the whole "drawing into a context" nonsense that slows everything down compared to the lean, mean Core Animation way of doing things, and respect kerning? i.e. avoiding drawRect: and all