core-text

What is CG Raster Data?

安稳与你 提交于 2019-12-03 09:32:55
I'm trying to find another memory leak in my code, and I can't seem to figure out what CG Raster Data is. While going through the VM Tracker with automatic snapshots enabled, the CG Raster Data seems to be the only part that increases. These also increase steadily without the allocations increasing. I'm not entirely sure what the CG Raster Data is, nor how I would fix it, but at this point the increasing footprint eventually causes a memory error and crash, so it's not good! I do my own text rendering (using CoreText), so I'm thinking that has something to do with it. I also am loading

Core Text - Height of glyph

吃可爱长大的小学妹 提交于 2019-12-03 07:43:51
问题 I have 2 attributed strings say 'A' and '.' I need to calculate the height of each of these strings. Currently the height returned is the same for both, it seems to return the maximum possible height for the tallest character in a given font (even if that character isn't present in the string). I would like to get the exact pixel height for each of these characters, so that I can resize a view around them that fits the character (glyph) snugly. I've tried using

UILabel default kerning different from CATextLayer

北城余情 提交于 2019-12-03 06:38:14
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:90.0]; [self.view addSubview:label1]; // // CATextLayer // UILabel *label2 = [[UILabel alloc]

Core Text - Get Pixel Coordinates from NSRange

蹲街弑〆低调 提交于 2019-12-03 06:22:25
问题 How would I get a CGRect from an NSRange for text rendered with Core Text? I am using Core Text with an NSAttributedString . 回答1: It is an absolute pain but can be done. You need to get all of the lines in the frame using CTFrameGetLines() , check if their character range is in the range you're looking for using CTLineGetStringRange() , use CTLineGetTypographicBounds() to find how big the line itself would render as, and use CTLineGetOffsetForStringIndex() to determine the actual position of

How to use CTRunDelegate in iPad?

佐手、 提交于 2019-12-03 06:22:22
问题 I am a developing an iPad application in which i have to use CTRunDelegate . I have defined all the the callbacks that are required viz CTRunDelegateGetAscentCallback , CTRunDelegateGetDescentCallback , CTRunDelegateGetWidthCallback . I dont know how to use CTRunDelegateRef object that I am creating. Right now what is happening is that my callbacks are not getting called. Any pointers in this regard will be highly appreciated. Thanx in advance. 回答1: You should add your run delegate as an

Drawing Text with Core Graphics

旧城冷巷雨未停 提交于 2019-12-03 06:20:39
问题 I need to draw centered text to a CGContext. I started with a Cocoa approach. I created a NSCell with the text and tried to draw it thus: NSGraphicsContext* newCtx = [NSGraphicsContext graphicsContextWithGraphicsPort:bitmapContext flipped:true]; [NSGraphicsContext saveGraphicsState]; [NSGraphicsContext setCurrentContext:newCtx]; [pCell setFont:font]; [pCell drawWithFrame:rect inView:nil]; [NSGraphicsContext restoreGraphicsState]; But the CGBitmapContext doesn't seem to have the text rendered

Does CoreText support Small Caps?

混江龙づ霸主 提交于 2019-12-03 04:31:01
问题 Does CoreText have any facility for selecting a SmallCaps variant of a font, or for synthesizing small caps if the font doesn't have that feature? I can't find anything in the CoreText documentation that talks about small caps, though there are facilities for dealing with font variations/features. Has anyone done anything similar to this? 回答1: It's generally easiest to use CTFontDescriptorCreateCopyWithFeature . As you mentioned in your own answer, this will only work for fonts that actually

How to highlight CoreText with changing highlight colors?

末鹿安然 提交于 2019-12-03 03:42:26
I have a subclass of UIView that implements code to draw CoreText. In the application, that UIView is drawn inside a UIScrollView. Here is the code that I currently use in drawRect: to render an NSAttributedString: CGContextRef context = UIGraphicsGetCurrentContext(); float viewHeight = self.bounds.size.height; CGContextTranslateCTM(context, 0, viewHeight); CGContextScaleCTM(context, 1.0, -1.0); CGContextSetTextMatrix(context, CGAffineTransformMakeScale(1.0, 1.0)); CGMutablePathRef path = CGPathCreateMutable(); CGRect bounds = CGRectMake(PADDING_LEFT, -PADDING_TOP, self.bounds.size.width-20.0,

iOS: How do you measure the width and height of a string using Quartz?

≡放荡痞女 提交于 2019-12-03 03:15:42
问题 Before I ask my questions, this is from Apple's documentation re: how to determine the width of a string using Quartz: If text measurements are important to your application, it is possible to calculate them using Quartz 2D functions. However, you might first consider using ATSUI, whose strength is in text layout and measurement. ATSUI has several functions that obtain text metrics. Not only can you obtain after-layout text metrics, but in the rare cases you need them, you can obtain before

Display NSAttributedString using CoreText

匆匆过客 提交于 2019-12-03 03:14:31
I have heard that I can display a NSAttributedString using CoreText, can anyone say me how (The simplest way)? Please, don't answer with CATextLayer or OHAttributedLabel. I know that there are a lot of questions about this in this forum, but I haven't find the answer Thanks!! I think that the simplest way (using Core Text) is: // Create the CTLine with the attributed string CTLineRef line = CTLineCreateWithAttributedString(attrString); // Set text position and draw the line into the graphics context called context CGContextSetTextPosition(context, x, y); CTLineDraw(line, context); // Clean up