Tag: core text

什么是CG栅格数据?

我试图在代码中发现另一个内存泄漏,我似乎无法弄清楚CG栅格数据是什么。 在启用自动快照的情况下浏览VM跟踪器时,CG栅格数据似乎是唯一增加的部分。 没有拨款的增加,这些也在稳步增加。 我不完全确定CG栅格数据是什么,也不知道如何修复它,但在这一点上越来越多的脚印最终导致内存错误和崩溃,所以它不好! 我做我自己的文字渲染(使用CoreText),所以我想这与它有关。 我也在加载图片? 以下是足迹的图像: 更新:这个问题仍然存在,但有趣的是,我可以将它与Uifoundations中的一个泄漏相关联,称为“NSConcreteGlyphGenerator”。 它似乎只发生在实际绘制的CoreText方法中的属性string上的“boundingRectWithSize:”方法。 具体而言,该行是: [displayString boundingRectWithSize:CGSizeMake( self.frame.size.width, self.frame.size.height ) options:0 context:nil]; 慢慢地跟踪它…

来自string的CGPathRef

请问怎样才能得到法文信件的特定阿拉伯语? 我刚刚发现CTFontCreatePathForGlyph会给CGPathRef这样的,但它将是文本的轮廓。 我需要这个真正的文本path来显示文本绘图animation.. 请任何帮助

CATextLayer + NSAttributtedString + CTParagraphStyleRef

我想有一些自定义的行间距的文本,所以我写了一个CTParagraphStyleAttributte的属性string,并将其传递给我的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[] = { {kCTParagraphStyleSpecifierLineSpacingAdjustment, sizeof(CGFloat), &leading}, {kCTParagraphStyleSpecifierAlignment, sizeof(CTTextAlignment), &alignment} }; CTParagraphStyleRef paragraphStyle = CTParagraphStyleCreate(styleSettings, 2)); NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys: (id)ctFont, (id)kCTFontAttributeName, […]

计算字体大小以适应框架 – 核心文本 – NSAttributedString – iOS

我有一些文本,我正在通过NSAttributedString(下面的代码)绘制到一个固定的框架。 目前我很难将文字大小编码为16.我的问题是,有没有一种方法可以计算给定帧的文本的最佳拟合大小? – (void)drawText:(CGContextRef)contextP startX:(float)x startY:(float) y withText:(NSString *)standString { CGContextTranslateCTM(contextP, 0, (bottom-top)*2); CGContextScaleCTM(contextP, 1.0, -1.0); CGRect frameText = CGRectMake(1, 0, (right-left)*2, (bottom-top)*2); NSMutableAttributedString * attrString = [[NSMutableAttributedString alloc] initWithString:standString]; [attrString addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Helvetica-Bold" size:16.0] range:NSMakeRange(0, attrString.length)]; CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((__bridge CFAttributedStringRef)(attrString)); struct CGPath * p = CGPathCreateMutable(); CGPathAddRect(p, NULL, frameText); CTFrameRef frame = CTFramesetterCreateFrame(framesetter, […]

将UITextViews文本replace为属性string

我有一个UITextView ,当用户input文本时,我想要dynamic地格式化文本。 像语法突出显示… 为此,我想使用UITextView … 一切工作正常期待一个问题:我从文本视图中的文本,并从它做一个NSAttributedString 。 我对这个属性string进行了一些编辑,并将其设置为textView.attributedText 。 每当用户键入时都会发生这种情况。 因此,我必须在编辑到attributedText selectedTextRange之前记住selectedTextRange然后将其设置回来,以便用户可以在之前input的地方继续input。 唯一的问题是,一旦文本足够长,需要滚动,如果我input缓慢, UITextView现在将开始滚动到顶部。 这是一些示例代码: – (void)formatTextInTextView:(UITextView *)textView { NSRange selectedRange = textView.selectedRange; NSString *text = textView.text; // This will give me an attributedString with the base text-style NSMutableAttributedString *attributedString = [self attributedStringFromString:text]; NSError *error = nil; NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"#(\\w+)" options:0 error:&error]; NSArray […]

内存使用增长与CTFontCreateWithName和CTFramesetterRef

我正在写一个使用自定义字体(CTFontManagerRegisterFontsForURL)的IOS程序。 我加载字体,将其添加为一个string属性,创build一个framesetter,然后一个框架,并绘制到上下文。 我释放我使用的一切。 仪器不会注意到泄漏,但是: 使用此function时,应用程序所使用的内存会增长并且不会收缩。 当我离开函数时,我的字体的保留计数是2。 这里是代码: CFMutableAttributedStringRef attributedStringRef = CFAttributedStringCreateMutable(kCFAllocatorDefault, 0); CFAttributedStringBeginEditing(attributedStringRef); CFAttributedStringReplaceString(attributedStringRef, CFRangeMake(0, 0), (CFStringRef)label.text); font = CTFontCreateWithName((CFStringRef)label.fontName, label.fontHeight, NULL); 保留字体的数量:1 CFAttributedStringSetAttribute(attributedStringRef, CFRangeMake(0, label.text.length), kCTFontAttributeName, font); CFAttributedStringEndEditing(attributedStringRef); 保留字体的数量:2 CGMutablePathRef path = CGPathCreateMutable(); CGPathAddRect(path, NULL, rect); CFRelease(font); 保留字体的数量:1 CTFramesetterRef frameSetter = CTFramesetterCreateWithAttributedString(attributedStringRef); 保留字体的数量:3 CFRelease(attributedStringRef); CTFrameRef frame = CTFramesetterCreateFrame(frameSetter, CFRangeMake(0, 0), path, NULL); 保留字体的数量:5 CFRelease(frameSetter); […]

iOS中的NSAttributedString中NSBackgroundColorAttributeName-like属性?

我正在计划使用NSAttributedString来突出部分string与用户search的匹配查询。 但是,我找不到一个iOS的等价物NSBackgroundColorAttributeName – 没有kCTBackgroundColorAttributeName 。 这样的事情是否存在,类似于NSForegroundColorAttributeName成为kCTForegroundColorAttributeName的方式?

Objective-C中Android的“Spannable”相当于什么

我在一个iOS应用程序,应该能够突出文本,并使其可点击。 我在iOS中阅读了有关NSAttributedString的内容 ,但它比Android中的Spannable更复杂。 如果没有,还有没有其他的Objective c方法可以做到这一点? 我应该怎么做,使用NSAttributedString单词突出显示一个段落,以及如何使我的文本点击。 更新: 我想要什么,每个单词应该是可点击的,并且可以在一个段落中突出显示为单个单词 。

NSAttributedString上标样式

我想在一个文本块(合法免责声明,自然;))上NSAttributedString所有的®字符的实例,默认方式NSAttributedString不是很好。 如果我只是让字符被使用,而且只使用未经修改的NSString ,它将被渲染成与大写字母相同的大小,并且大致位于基线。 如果我将上标属性添加到NSAttributedString ,如下所示: [attrStr setAttributes:@{(NSString *)kCTSuperscriptAttributeName : @1} range:NSMakeRange(locationOfReg, 1)]; angular色被抬离基线,其大小不变,但行间距现在受到影响,因为升起的angular色会侵入上面的行。 为了显示: 我在Photoshop中创build了这个图像,通过减less字符的大小和移动基线来实现所需的位置。 我知道如何改变iOS的字体大小,但改变基线似乎更棘手。 有关如何实现这一目标的任何build议? 编辑:我想我可以使用上标属性作为一种方法来改变基线。 现在想出一种方法来获取当前的字体大小,并随后减less它以允许在不同大小的文本块上使用相同的方法。