core-text

How to properly compensate CGContextRef coordinate system, so the origin is at the top left corner

£可爱£侵袭症+ 提交于 2019-12-11 14:22:42
问题 I'm trying to draw text using CoreText. I have the following code: CGContextRef uiContext = UIGraphicsGetCurrentContext(); NSMutableDictionary<NSAttributedStringKey,id> *attributes = [NSMutableDictionary<NSAttributedStringKey,id> new]; [attributes setObject:UIColor.redColor forKey:NSForegroundColorAttributeName]; [attributes setObject:[UIFont systemFontOfSize:40] forKey:NSFontAttributeName]; NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:@"Str" attributes

UITextView vs UILabel+ScrollView

左心房为你撑大大i 提交于 2019-12-11 12:48:34
问题 Im working on a an app that requires a view Controller to display a nice amount of hebrew(non-english) text in it. The text is an AttributedString from a Rich Text File There are 4 things that I need the view to do. Smooth Scrolling Get the range of a word so I can auto-scroll to it (like scrollRangeToVisible ) Change the font smoothly (I'd like to use a UISlider to change the font) Load quickly In a sense Im looking for the capabilities of a e-reader just I only need one column and I want it

Text becomes invisible when stroke is added

人走茶凉 提交于 2019-12-11 10:56:19
问题 I have next issue (sample code below): I'm use CATextLayer and NSAttributedString to displaying stylized text. All work fine until I had added stroke to attributes. When I add stroke - text becomes invisible and in display I can see only stroke. Please, I can't understand what happens, why I can't use both text and stroke? Thanks. UIFont* font = [UIFont fontWithName: size:]; UIColor* strokeColor = [UIColor colorWithRed: green: blue: alpha:1.f]; UIColor* foregroundColor = [UIColor colorWithRed

Core Text - How to know if text is Right to Left

橙三吉。 提交于 2019-12-11 07:45:43
问题 How can we know if the text of a CTRun is right to left? Thanks 回答1: I do not have practical experience with CTRun , but from the documentation is seems that CTRunStatus CTRunGetStatus(CTRunRef run) returns the information you need, the return value is a bitfield: enum { kCTRunStatusNoStatus = 0, kCTRunStatusRightToLeft = (1 << 0), kCTRunStatusNonMonotonic = (1 << 1), kCTRunStatusHasNonIdentityMatrix = (1 << 2) }; typedef uint32_t CTRunStatus; 来源: https://stackoverflow.com/questions/18022882

CTFrameGetLineOrigins Got Incorrect Origins

半腔热情 提交于 2019-12-11 06:27:59
问题 I Use CTFrameGetLineOrigins for get the origin of each line. But it always returns wrong line origin. The code: CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetTextMatrix(context, CGAffineTransformIdentity); CGContextTranslateCTM(context, 0, self.bounds.size.height); CGContextScaleCTM(context, 1.0, -1.0); CTFontRef font = CTFontCreateUIFontForLanguage(kCTFontUserFontType, self.font.pointSize, NULL); CFAttributedStringSetAttribute(attrString, CFRangeMake(0,

OpenType Font Parsing for Pleasure and Profit (anyone understand these stupid tables?)

本秂侑毒 提交于 2019-12-11 05:55:06
问题 So, this is mainly for fun, I'm poking around and trying to find my way inside a few fonts and I have a few questions I'd really appreciate some help on if anyone has done this kind of stuff. cmap table The fonts I am testing with contain several cmap subtables of different formats. I can read them, but I don't understand which I should be using. ie. what is the strategy for choosing the most appropriate subtable? Does this even make sense? glyf table This is really making my head hurt. I'm

CTRunGetImageBounds returns incorrect x coordinate on iOS 10 and below

∥☆過路亽.° 提交于 2019-12-11 05:19:32
问题 I'm working with CoreText and am trying to add link support to a custom label on iOS 11/12 however I need to support older software versions too. To do this, I check if the user's touch intersects and of the link text bounds. To get the bounds, I simply call CTRunGetImageBounds(run, context, CFRangeMake(0, 0)) . This works perfectly on iOS 11 and 12 but is broken on 9 and 10. I get a rect back along the lines of (250,8.1,100,30) on iOS 11 but on iOS 9, however, the same function call returns

nsattributedstring tappable iOS

旧城冷巷雨未停 提交于 2019-12-11 04:36:33
问题 I figured out how to make in core text a url tappable but i can not figure out how to make other words tappable like 'my name is @george' . I would like @george to be tappable in core text. Is there a way? I am trying like this to make it tappable: CFAttributedStringSetAttribute(string, CFRangeMake( 0, mystring.length ), kCTFontAttributeName, ctFontBold ); CFAttributedStringSetAttribute(string, CFRangeMake( mystring.length, linestring.length ), kCTFontAttributeName, ctFont);

UITextView text background colour

二次信任 提交于 2019-12-11 04:08:30
问题 I am trying to get a transparent UITextView, and I know how to set it. What I also want is like a coloured background right under the text that has been shown. Again the text view background will set the entire view rectangle to a given colour, what I want is colour just under the text. Any easy way of achieving such thing? 回答1: From what I can tell you're trying to accomplish a highlighting effect on the text. If this is the case you could use NSAttributedString. It allows you to set the

how to fill triangle in swift using Core graphics

怎甘沉沦 提交于 2019-12-11 04:01:55
问题 I am not able to fill a path triangle using swift. I used the following code, which make a stroke. let view = UIView(frame: CGRectMake(0, 0, 300, 300)) let shape = CAShapeLayer() view.layer.addSublayer(shape) shape.opacity = 0.5 shape.lineWidth = 2 shape.lineJoin = kCALineJoinMiter shape.strokeColor = UIColor(hue: 0.786, saturation: 0.79, brightness: 0.53, alpha: 1.0).CGColor shape.fillColor = UIColor(hue: 0.786, saturation: 0.15, brightness: 0.89, alpha: 1.0).CGColor let context =