core-text

Using core text on Mac book pro / HD screen different text sizes

微笑、不失礼 提交于 2019-12-08 05:57:41
问题 I've recently shifted to a MacBook Pro 15" and core text is behaving strangely. I have an app that uses core text to draw an NSattributedstring with CTFrameDraw. It works as expected on the external 1080p monitor, if I drag the window across to the MacBook Pro screen then the font is displayed very tiny like it's changed from 10 point font to 5 point when painted. Likewise if I repaint the text on the MacBook Pro then it's still small. I'd guess it's because the MacBook Pro has the high

How can I determine if a specific emoji character can be rendered by an iOS device?

本秂侑毒 提交于 2019-12-06 12:52:38
问题 With the release of iOS 9.1, we got a lot of cool new emoji like taco (🌮)! I'm working on an application where I'd like to show the new emoji characters on devices where they are supported but keep them hidden on devices where they are not. Is there a way to determine if a given emoji character (contained in an NSString) can be rendered on the device the app is running on? After quite a bit of digging on SO and experimenting I've come up with a solution which I will post as an answer below,

Simple rich text view in cocoa-touch

主宰稳场 提交于 2019-12-06 11:12:48
问题 I'm working on an iOS app in which I need to implement a basic text view with these requirements: Rich text Font emphasis (bold, italics). Inline images for hyperlink-like actions. Scrolling Getting and setting the scroll offset (for remembering the previous scroll position). Text selection Getting the selected text character range. Scrolling the view when selecting text, if needed. I believe I could achieve this with UIWebView but the problem with this is that it provides very little control

kCGTextStroke's Fill and Stroke aren't positioned correctly

让人想犯罪 __ 提交于 2019-12-06 09:23:06
So I'm using the code below to apply a stroke (and fill) to text in a UILabel , and it's coming out like the image below. The stroke is heavier on one side than the other (look at the top of the letters compared to the bottom, and the right compared to the left. The period at the end makes it very noticeable, too, looks like a googly eye). I've not got any shadowing turned on at all, so I don't think it's the shadow interfering with the stroke. What could be causing this? - (void) drawTextInRect: (CGRect) rect { CGContextRef c = UIGraphicsGetCurrentContext(); CGContextSetTextDrawingMode(c,

NSTextAttachment image not showing when drawing using CoreText

≡放荡痞女 提交于 2019-12-06 05:52:42
问题 For some reason I'm unable to get NSTextAttachment images to draw when using core text, although the same image would display fine when the NSAttributedString is added to an UILabel. On iOS this rendering will give empty spaces for the NSTextAttachments, for OS X, a placeholder [OBJECT] square image is rendered for each NSTextAttachment instead. Is there something else that needs to be done in order to render images with CoreText? The rendering code: CGFloat contextHeight =

Core Text With Asymmetric Shape on iOS

ぃ、小莉子 提交于 2019-12-06 05:48:47
问题 I want to write text in a path that can take up any shape. Right now I can draw flipped text in it: NSArray *coordinates = ...; CGMutablePathRef pathRef = [self objectPathGivenCoordinates:coordinates]; ... // Draw the shapes // Now draw the text CGContextSetTextMatrix(context, CGAffineTransformIdentity); NSAttributedString* attString = [[NSAttributedString alloc] initWithString:@"0,1,2..."]; CTFramesetterRef frameSetter = CTFramesetterCreateWithAttributedString((__bridge CFAttributedStringRef

Get unicode character by glyph index in a CTFontRef or CGFontRef object

喜欢而已 提交于 2019-12-06 05:16:26
问题 The CTFontRef provides excellent method such as CTFontGetGlyphsForCharacters for mapping character(s) to glyph(s). My question is, is there any method for invert mapping? That is say, can I get characters(s) by given glyph(s)? Since I found there is a CTFontCopyCharacterSet for getting all supported characters, I think there will be some nice solutions. 回答1: I think you may end up having to parse the font’s mapping tables yourself. You can obtain access to the tables using

CTFontGetGlyphsForCharacters always returns false

给你一囗甜甜゛ 提交于 2019-12-06 03:04:59
问题 Please help me understand the problem with the following code: NSString *fontName = @"ArialMT"; CGFloat fontSize = 20.0; CTFontRef fontRef = CTFontCreateWithName((CFStringRef)fontName, fontSize, NULL); NSString *characters = @"ABC"; NSUInteger count = characters.length; CGGlyph glyphs[count]; if (CTFontGetGlyphsForCharacters(fontRef, (const unichar*)[characters cStringUsingEncoding:NSUTF8StringEncoding], glyphs, count) == false) NSLog(@"*** CTFontGetGlyphsForCharacters failed."); Any help is

Core Text in Cocoa app

时光怂恿深爱的人放手 提交于 2019-12-06 00:12:32
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 = CFStringCreateWithCString(NULL, "Courier", kCFStringEncodingMacRoman); CTFontRef font = CTFontCreateWithName(font_name,

CoreText: Invalid 'kern' Subtable In CTFont

拜拜、爱过 提交于 2019-12-05 19:36:45
问题 I am using a custom font applied to a CATextLayer. I am using the tutorial and sample code found here. http://www.freetimestudios.com/2010/09/13/custom-fonts-on-the-ipad-and-ios-4/ However, every so often, I get the following error. Nothing in particular seems to trigger it. Can someone shed some light as to what this means? What to check for? CoreText: Invalid 'kern' Subtable In CTFont <name: Intellect, size: 20.000000, matrix: 0x0> CTFontDescriptor <attributes: <CFDictionary 0xac07a80