core-text

how to set attributes in NSAttributedString in iOS?

随声附和 提交于 2019-12-02 05:03:35
I'm trying to set the infamous NSFontAttributeName property of an NSAttributedString in iOS but it just doesn't seem to work: first off, none of the NS constants seem defined for iOS I read somewhere that I could instead work around it by passing the CoreText consts instead. Fine... but still, The attribute expects an NSFont and I'm stuck with UIFont or CTFontRef, neither of which seems to work: this doesn't work: CTFontRef ctFont = CTFontCreateWithName((CFStringRef)[UIFont boldSystemFontOfSize:16].fontName, [UIFont boldSystemFontOfSize:16].pointSize, NULL); [myAttString addAttribute:(NSString

OSX: CGGlyph to UniChar

妖精的绣舞 提交于 2019-12-01 22:44:34
问题 I am currently writing a simple bitmap font generator using CoreGraphics and CoreText. I am retrieving the kerning table of a font with: CFDataRef kernTable = CTFontCopyTable(m_ctFontRef, kCTFontTableKern, kCTFontTableOptionNoOptions); and then parse it which works fine. The kerning pairs give me the glyph indices (i.e. CGGlyph) for the kerning pairs, and I need to translate them to unicode (i.e. UniChar), which unfortunately does not seem super easy. The closest I got was using:

NSLayoutManager boundingRectForGlyphRange off by some Points

一笑奈何 提交于 2019-12-01 17:08:38
I want to "highlight" specific words in UITextView, not with a solid color (which would be possible via NSAttributedString ), but rather with a gradient and maybe some other fancy effects. Hence, I decided it would be necessary to manually create a view and overlay (or underlay) it using the bounding rectangles of the given text. To my surprise this turned out to be pretty straightforward. Example is inside a UIViewController, txtView being a UITextView connected as IBOutlet : override func viewDidLayoutSubviews() { super.viewDidLayoutSubviews() // Converting to NSString as I need a NSRange

NSLayoutManager boundingRectForGlyphRange off by some Points

邮差的信 提交于 2019-12-01 16:34:06
问题 I want to "highlight" specific words in UITextView, not with a solid color (which would be possible via NSAttributedString ), but rather with a gradient and maybe some other fancy effects. Hence, I decided it would be necessary to manually create a view and overlay (or underlay) it using the bounding rectangles of the given text. To my surprise this turned out to be pretty straightforward. Example is inside a UIViewController, txtView being a UITextView connected as IBOutlet : override func

Core Text in UITableviewCell's content overlapping and repeating and superimpose on the other cells

寵の児 提交于 2019-12-01 14:38:35
I am using Core Text to add text to UITableviewCell's content but arabic content seems to be overlapping and repeating itself as I scroll and superimpose on the other cells. I am also using other elements on the page which appear just fine and are not repeating . Just the Core Text seems to be repeating. I cant figure out why . Here is my code: - (CTFontRef)newCustomFontWithName:(NSString *)aFontName ofType:(NSString *)type attributes:(NSDictionary *)attributes { NSString *fontPath = [[NSBundle mainBundle] pathForResource:aFontName ofType:type]; NSData *data = [[NSData alloc]

Core Text in UITableviewCell's content overlapping and repeating and superimpose on the other cells

家住魔仙堡 提交于 2019-12-01 12:42:33
问题 I am using Core Text to add text to UITableviewCell's content but arabic content seems to be overlapping and repeating itself as I scroll and superimpose on the other cells. I am also using other elements on the page which appear just fine and are not repeating . Just the Core Text seems to be repeating. I cant figure out why . Here is my code: - (CTFontRef)newCustomFontWithName:(NSString *)aFontName ofType:(NSString *)type attributes:(NSDictionary *)attributes { NSString *fontPath = [

Space between the last 2 lines of a paragraph is larger?

只愿长相守 提交于 2019-12-01 11:19:04
I draw the text using CTFramesetter, I have set kCTParagraphStyleSpecifierParagraphSpacing , kCTParagraphStyleSpecifierLineSpacing , kCTParagraphStyleSpecifierParagraphSpacingBefore all to 0.0. As you can see in the image, the space between the last 2 lines of a paragraph is much larger than others'. There're in total 15 lines in this image, I pasted their ascent , descent , leading , origin.y in the following, we can see that the ascent and descent on the 5th and 10th line are larger than others', I couldn't find any specifier to set to avoid this weird layout. Any ideas? 1 ascent=20.639999,

How does Apple's text rendering draw a glyph that a font doesn't have?

爱⌒轻易说出口 提交于 2019-12-01 07:32:33
问题 I have a basic understanding of fonts and encoding, but recently I had to do something outside of my comfort zone: Turn the character ✖ ( 0x2716 "heavy multiplication x") into a CGPathRef . I used Core Text's CTFontGetGlyphsForCharacters to accomplish this job. I understand that a CGGlyph is effectively an index into the set of glyphs supported by the given font. I soon discovered that this glyph is only supported by a very few fonts on iOS, including Zapf Dingbats, which is the one I chose.

iOS Drawing text in the centre of shapes

荒凉一梦 提交于 2019-12-01 04:17:31
I'm trying to draw text in the centre of shapes in iOS, an example would be Microsoft Office's insert shape see: https://www.dropbox.com/s/cgqyyuvy6hcv5g8/Screenshot%202014-01-21%2013.48.17.png I have an array of coordinates that are used to form the shape, which works fine for creating the actual shape. My first tactic was following this stackoverflow question: Core Text With Asymmetric Shape on iOS however I can only get it to draw the text at the bottom of the shape. Is there any way to centre the text vertically and horizontally? I then had a look at the new TextKit but I got stuck with

Aligning multiple sized text vertical center instead of baseline with Core Text in iOS

≡放荡痞女 提交于 2019-12-01 01:48:12
Is it possible to align multiple sized text by bounding center (of each size) instead of baseline? I tried CTRunDelegate feature, but it doesn't work. It was possible with CTRunDelegateCallbacks.getAscent and CTRunDelegateCallbacks.getDescent , but the feature doesn't work. Only CTRunDelegateCallbacks.getWidth worked. I succeed to laying out multiple sized text, images, and any objects, but only baseline-alignment supported. The run delegate methods getAscent and getDescent are, in fact, called (it is working in my own code). Of course, it makes sense that this doesn't change the baseline (and