core-text

iOS CTFramesetterCreateWithAttributedString not sizing correctly

为君一笑 提交于 2019-12-13 02:54:35
问题 I am building an app that takes a few different text files and strings them together, then builds a pdf out of them. I needed to add the file's text add separate times so I can add in hyperlinks to the text from each file. I have made some progress and got it to display almost accurately, but it appears CTFramesetterCreateWithAttributedString is not sizing correctly. For example, the first of the three files displays too much, in other words, after the text ends there is a blank page that

Setting line spacing in a CTFrame

删除回忆录丶 提交于 2019-12-13 02:35:38
问题 I'm working in a kind of QR Code generator, it's a Mac app. I know how draw the text, but I don't know how I can set line spacing. My code: // Prepare font CTFontRef font = CTFontCreateWithName(CFSTR("LucidaSansUnicode"), 16, NULL); // Create Path CGMutablePathRef gpath = CGPathCreateMutable(); CGPathAddRect(gpath, NULL, CGRectMake(10, 0, pixelsWidth, pixelsHigh)); CGContextSetTextDrawingMode (newcontext, kCGTextFill); CGContextSetGrayFillColor(newcontext, 0.0, 1.0); // Create an attributed

iOS CoreText get list of registered fonts via CTFontManagerRegisterGraphicsFont

£可爱£侵袭症+ 提交于 2019-12-12 15:37:15
问题 I am registering fonts dynamically via the following: - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{ if ([url isFileURL]) { // Handle file being passed in NSLog(@"handleOpenURL: %@",url.absoluteString); NSData *inData = [NSData dataWithContentsOfURL:url]; CFErrorRef error; CGDataProviderRef provider = CGDataProviderCreateWithCFData((CFDataRef)inData); CGFontRef fontRef =

Linker can't find CTFontCreateWithNameAndOptions

核能气质少年 提交于 2019-12-12 11:07:45
问题 I am trying to use CTFontCreateWithNameAndOptions() from CoreText and the linker is saying "Symbol(s) not found", specifically for _CTFontCreateWithNameAndOptions . I added CoreText.framework and am importing <CoreText/CoreText.h>. It compiles fine, but the linker fails. Here's the declaration in CTFont.h: CTFontRef CTFontCreateWithNameAndOptions( CFStringRef name, CGFloat size, const CGAffineTransform *matrix, CTFontOptions options ) CT_AVAILABLE_STARTING( __MAC_10_6, __IPHONE_3_2); Here's

Problem while using CTFontRef in a loop to create NSMutableAttributedString

有些话、适合烂在心里 提交于 2019-12-12 09:17:31
问题 I need to create a NSMutableAttributedString with different CTFontRef and CTParagraphStyleRef for different range in that string. I try creating it by putting the following code in a loop and change range as I need, CTFontRef normalFontRef = CTFontCreateWithName((CFStringRef)@"CourierNewPSMT", fontsize, NULL); NSDictionary* normalFontAttribute = [[NSDictionary alloc] initWithObjectsAndKeys:(id)normalFontRef,(NSString*)kCTFontAttributeName, nil]; [attributedString addAttributes

Issue when appending a CTFrame to a Swift Array

百般思念 提交于 2019-12-12 01:37:42
问题 I have a CoreText that works in Objective-C and the migration to Swift is driving me nuts. This is the (simplified) code: var ctFramesArray: Array<CTFrame> = CTFrame[]() ctFramesArray.append(ctFrame) The ctFrame is a valid object. I can inspect it with the debugger, println() it, and the project runs fine rendering the CoreText columns properly. The ctFramesArray reports zero objects after being created and before appending the first ctFrame object. But I have a run time error (EXEC_BAD

Draw line in UILabel before and after text

人走茶凉 提交于 2019-12-11 20:01:46
问题 I want to draw a line before and after a string in UILabel exactly like the following image: PS: the text is not static, so i can't tell what is the exact text width, otherwise i would put two static lines before and after the text. PS: Also i can't put the label above a line and give the label background color same to the view background because i have gradient color in the lower view. 回答1: I Hope below is what you was looking for... #import "ViewController.h" @interface ViewController () {

Unicode Scalars in iOS

﹥>﹥吖頭↗ 提交于 2019-12-11 19:53:07
问题 Is it possible to create a custom Unicode scalar value in iOS or to map an existing value to a bitmap glyph? I'm curious to see if one can create custom characters and strings like Apple's emoji. 回答1: According to the documentation, this is possible. let customChar = "\u{5436}" 来源: https://stackoverflow.com/questions/25578183/unicode-scalars-in-ios

CGFontGetGlyphBBoxes wrong result

纵然是瞬间 提交于 2019-12-11 17:05:34
问题 I have been trying to measure glyph bounds precisely but this code prints out 916!!! The real width of this is 69. - (void)drawRect:(NSRect)dirtyRect { CGContextRef main = [[NSGraphicsContext currentContext] graphicsPort]; CGContextSetTextMatrix(main, CGAffineTransformIdentity); CGGlyph g; CGPoint p = CGPointMake(100, 100); CGRect rect = CGRectMake(0, 0, 0, 0); CGFontRef font = CGFontCreateWithFontName((CFStringRef)@"Arial"); g = CGFontGetGlyphWithGlyphName(font, CFSTR("L")); CGContextSetFont

CoreText memory leak from CTFramesetterCreateWithAttributedString

梦想与她 提交于 2019-12-11 14:43:33
问题 I'm coming across a problematic leak which - thanks to Instruments - appears to be coming from CTFrameSetterCreateWithAttributedString. The call stack is below. 1 CoreText -[_CTNativeGlyphStorage prepareWithCapacity:preallocated:] 2 CoreText -[_CTNativeGlyphStorage initWithCount:] 3 CoreText +[_CTNativeGlyphStorage newWithCount:] 4 CoreText TTypesetterAttrString::Initialize(__CFAttributedString const*) 5 CoreText TTypesetterAttrString::TTypesetterAttrString(__CFAttributedString const*) 6