core-text

iOS Quartz embed font in pdf

不想你离开。 提交于 2019-12-01 01:15:41
问题 I'm trying to generate a PDF page with text that has custom symbols (e.g. "€") using a custom font. I've created a PDF context and page using UIGraphicsBeginPDFContextToData and UIGraphicsBeginPDFPage. My code for rendering text looks something like: NSString *fontFile = [[NSBundle mainBundle] pathForResource:@"somefont.otf" ofType:nil]; CGDataProviderRef dataProvider = CGDataProviderCreateWithFilename([fontFile cStringUsingEncoding:NSASCIIStringEncoding]); CGFontRef cgfont =

Core Text: Render to an Odd Shape

老子叫甜甜 提交于 2019-11-30 22:06:40
I am trying to render text to a shape that isn't a rectangle. The following code works when I add a rectangular path but not when I add an elliptical path. Ultimately, I'd like to draw to any path (L shape, etc), has anyone had any luck with this? -(void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetTextMatrix(context, CGAffineTransformIdentity); CGMutablePathRef path = CGPathCreateMutable(); float w = 200.0; float h = 300.0; CGRect bounds = CGRectMake(10.0, 10.0, w, h); // I draw using only one of the following lines CGPathAddRect(path, NULL, bounds

Detecting tapped character. UITextView characterRangeAtPoint always returns nil

廉价感情. 提交于 2019-11-30 21:20:27
I'm trying to determine, which particular character in UITextView has been tapped. I tried to use characterRangeAtPoint: method. But it always returns nil, wherever in the UITextView I tap. I even wrote and run the following piece of code: for (int x = 0; x<1000; x++) { pos.x = x; for (int y = 0; y<1000; y++) { pos.y = y; UITextRange * range = [textView characterRangeAtPoint:pos]; if (range!=nil) { NSLog(@"x: %f, y: %f", pos.x, pos.y); } } } Well, it never reaches the NSLog string. What am I doing wrong? This is an iOS 7 bug. characterRangeAtPoint: always returns nil , unless some text has

Detecting tapped character. UITextView characterRangeAtPoint always returns nil

一笑奈何 提交于 2019-11-30 17:43:37
问题 I'm trying to determine, which particular character in UITextView has been tapped. I tried to use characterRangeAtPoint: method. But it always returns nil, wherever in the UITextView I tap. I even wrote and run the following piece of code: for (int x = 0; x<1000; x++) { pos.x = x; for (int y = 0; y<1000; y++) { pos.y = y; UITextRange * range = [textView characterRangeAtPoint:pos]; if (range!=nil) { NSLog(@"x: %f, y: %f", pos.x, pos.y); } } } Well, it never reaches the NSLog string. What am I

Rendering CoreText within an irregular shape

微笑、不失礼 提交于 2019-11-30 17:16:21
问题 I'm looking for guidance on implementing a view that renders an NSAttributedString within a polygon with holes, wrapping and reflowing text to fit the geometry. It's not CoreText that's the issue, but the general problem of partitioning an irregular shape into an ordered sequence of squat rectangles. Similar questions haven't been answered fully: How to fill a shape with text in Javascript https://stackoverflow.com/q/3048305 CoreText's CTFramesetter does not support rendering into a CGPath

CTFramesetterSuggestFrameSizeWithConstraints with clipping attributes returning zero height

我与影子孤独终老i 提交于 2019-11-30 16:22:10
H! I'm writing a textview with subviews clipping features. The idea is to make all text draw around all subviews. The problem is to get it's content height. Due to the lack of documentation, I decided that the attributes dictionary for CTFramesetterSuggestFrameSizeWithConstraints is the same as for the CTFramesetterCreateFrame. Here is my clipping paths code: -(CFDictionaryRef)clippingPathsDictionary{ if(self.subviews.count==0)return NULL; NSMutableArray *pathsArray = [[NSMutableArray alloc] init]; CGAffineTransform transform = CGAffineTransformIdentity; transform = CGAffineTransformScale

CATextLayer + NSAttributtedString + CTParagraphStyleRef

雨燕双飞 提交于 2019-11-30 15:57:30
问题 I want to have some text with a custom line-spacing, so I wrote an attribute string with CTParagraphStyleAttributte and pass it to my CATextLayer : UIFont *font = [UIFont systemFontOfSize:20]; CTFontRef ctFont = CTFontCreateWithName((CFStringRef)font.fontName, font.pointSize, NULL); CGColorRef cgColor = [UIColor whiteColor].CGColor; CGFloat leading = 25.0; CTTextAlignment alignment = kCTRightTextAlignment; // just for test purposes const CTParagraphStyleSetting styleSettings[] = {

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

二次信任 提交于 2019-11-30 14:55:57
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. 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-ctfont-object

Line spacing and paragraph alignment in CoreText

ε祈祈猫儿з 提交于 2019-11-30 14:43:08
I am using CoreText to render multiple columns of text. However, when I set the first letter of the 1st paragraph to a bold, larger font than the rest of the text, I incur 2 issues (both visible in the attached image): The spacing underneath the first line is too big (I understand that this is because the 1st character could be a g,y,p,q etc. Lines below the first line now do not line up with corresponding lines in the next column. Any advice on how to overcome these 2 issues would be greatly appreciated, thank you. marco According to the documentation

CGContextSelectFont equivalent

时光毁灭记忆、已成空白 提交于 2019-11-30 11:08:32
In iOS7 CGContextSelectFont is deprecated. Deprecation message says that I have to use Core Text, but I don't know which is the exact equivalent of this piece of code: CGContextSelectFont(context, "Helvetica", kBarLabelSize, kCGEncodingMacRoman); CGContextSetTextDrawingMode(context, kCGTextFill); CGContextSetRGBFillColor(context, 0, 0, 0, 1.0); CGContextSetTextMatrix (context, CGAffineTransformMake(1.0, 0.0, 0.0, -1.0, 0.0, 0.0)); CGContextShowTextAtPoint(context, barX, barY, [@"Some text" cStringUsingEncoding:NSUTF8StringEncoding], [barValue length]); I've been able to create the font with