Core Text

RSS for tag

Create text layouts, optimize font handling, and access font metrics and glyph data using Core Text.

Posts under Core Text tag

23 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

Unstable text layout in NSLayoutManager
Hey, Maybe someone can explain me why NSLayoutManager is giving me "unstable" layout? It's like it decides to include line-height-multiple of 1.2 sometimes: We're doing some custom text rendering and if I change font size by a bit (or other property), then suddenly there is this extra text spacing. What we noticed so far is that there is something special about the first font that was set on NSTextStorage, in that case text has no extra spacing. Once you change it to slightly modified font else - the extra spacing is introduced. It's not NSParagraphStyle.lineHeightMultiple - if I set it to something non default then it acts as extra, but doesn't solve the "layout instability" issue. Any clue what's causing this? or how to make it to be stable?
0
0
565
Jul ’23
Cursor Disappearing with Multiple NSTextViews
I have a Mac app, Notenik, written with AppKit, that dynamically generates an Edit view that is used to edit multiple fields for a Note. Sometimes, depending on a user's request, multiple NSTextViews end up appearing within the same parent view (a tab, if that matters). Lately I and some of my users have noticed that, when moving from one NSTextView to another (either by tabbing or by clicking), the cursor initially fails to appear. Once the user starts editing within the NSTextView, the cursor appears and acts normally. And this doesn't occur when moving from an ordinary text field to an NSTextView -- only when moving from one NSTextView to another. But it is troubling and confusing to users that the cursor initially disappears. I'm not sure exactly when this started happening, but it has not been happening for very long. Although I make frequent updates to the app, this section of code has had no recent changes, so I am at a loss to explain this behavior, or to correct it. Any help would be appreciated.
1
0
827
Aug ’23
Text Kit not word-wrapping first/last lines in UITextView
When using an exclusion path with an UITextView, the text view is not properly wrapping the words for the first and last line in the example shown (lower text). It does render properly using word-wrap with Core Text (top example).(Hmm - the image link I provided in the HTML here works with the preview, but not the post. The example image is at: http i.stack.imgur.com/Z91ge.pngHere is the code for the UITextView (both this and the Core Text example use the same size bezier path, and both use the appropriate corresponding font and paragraph settings; wrap by word and centered):NSString *testText = @"Text Kit exclusion paths ..."; / UIBezierPath *viewPath = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, 280, 280)]; UIBezierPath *shapePath = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(10, 10, 265, 265)]; viewPath.usesEvenOddFillRule = true; shapePath.usesEvenOddFillRule = true; [shapePath appendPath:viewPath]; NSMutableAttributedString *title = [[NSMutableAttributedString alloc]initWithString:testText]; UIFont *font = [UIFont fontWithName:@"BradleyHandITCTT-Bold" size:14]; [title addAttribute:NSFontAttributeName value:font range:NSMakeRange(0, title.length)]; [title addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, title.length)]; NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; [paragraphStyle setAlignment:NSTextAlignmentCenter]; [paragraphStyle setLineBreakMode:NSLineBreakByWordWrapping]; [title addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, title.length)]; UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(0.0, 370.0, 280, 280)]; textView.textContainerInset = UIEdgeInsetsMake(0,0,0,0); textView.textContainer.exclusionPaths = @[shapePath]; [textView.textContainer setLineBreakMode:NSLineBreakByWordWrapping]; textView.contentInset = UIEdgeInsetsMake(0,0,0,0); textView.attributedText = title; textView.backgroundColor = [UIColor clearColor];It is worth noting that the Text Kit is respecting the word wrapping rules except for the first and (possibly last) line where the text does not actually fit. I need this to work with a UITextView because text entry is required, or I would be done with my Core Text example.I have tried everything I can think of to reliably work-around the issue. I don't fully understand how UITextView is working with Core Text (or I would expect to get the same results which I don’t), so any suggestions would be greatly appreciated.
3
0
2.0k
Oct ’23