> On 28 Nov 2016, at 23:42, Alastair Houghton <alast...@alastairs-place.net> 
> wrote:
> 
> On 28 Nov 2016, at 16:18, Gerriet M. Denkmann <gerri...@icloud.com> wrote:
>> 
>> 
>>> On 28 Nov 2016, at 22:13, Eric E. Dolecki <edole...@gmail.com> wrote:
>>> 
>>> You could probably use an attributed string and add an attribute for the 
>>> last colon: NSBaselineOffsetAttributeName
>> 
>> Yes; but this would be some rather desperate work-around.
>> 
>> I was rather thinking of UIFontDescriptorFeatureSettingsAttribute with some 
>> Feature type from SFNTLayoutTypes.h (in CoreText).
>> I tried a few types, but no success so far.
> 
> The problem you’ve got is that unless the font has a feature that 
> specifically allows you to change *any* colon (as opposed to a colon between 
> two numerals), you aren’t going to be able to do it by turning on an OpenType 
> feature.  Even if you can, there doesn’t appear to be a standard feature code 
> for this, so you’d be reliant on Apple not changing it in the future.

The WWDC 2015 talk seemed to suggest that there is a standard feature for this.
But there are about 40 feature types in SFNTLayoutTypes.h - no idea what to use.


> What you *could* do instead is get Core Text (or Cocoa Text) to lay out a 
> string e.g. “12:00”, then grab the glyph for the centred colon directly from 
> that string and use it explicitly, e.g. by attaching a 
> kCTGlyphInfoAttributeName attribute to your string with the value set to an 
> appropriately constructed CTGlyphInfoRef.

done once:

CGRect frame = { {0,0},{99,99}};        
UITextView *dummyTextView = [ [UITextView alloc] initWithFrame: frame 
textContainer: nil ];
dummyTextView.text = @“23:21”;
dummyTextView.font = thinFont;
NSLayoutManager *layoutManager = dummyTextView.layoutManager;
[ layoutManager ensureGlyphsForCharacterRange: range ];
[ layoutManager ensureLayoutForCharacterRange: range ];
NSUInteger glyphIndex = [ layoutManager glyphIndexForCharacterAtIndex: 2 ];
centeredColonGlyph = [ layoutManager CGGlyphAtIndex: glyphIndex ];;


and then:

CFMutableAttributedStringRef aStr = (__bridge 
CFMutableAttributedStringRef)attributedString;
CTFontRef fontRiff = (__bridge CTFontRef)thinFont;
CTGlyphInfoRef glyInfRef = CTGlyphInfoCreateWithGlyph( centeredColonGlyph, 
fontRiff, (CFStringRef)@":" );
CFRange range = { (CFIndex)colonIndex, 1 };
CFAttributedStringSetAttribute( aStr, range, kCTGlyphInfoAttributeName, 
glyInfRef );
CFRelease(glyInfRef);

This seems to be working. Nut sure whether there is a more elegant way.

Thanks a lot for your help!


Kind regards,

Gerriet.



_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to