core-text

How to draw images among rich-text with CoreText? (iOS)

笑着哭i 提交于 2019-12-03 03:14:00
问题 I can draw rich-text with Core Text, the problem is placing images flowing with the text. (iOS SDK 4.1) I'm try to drawing some kind of rich-text. Problem is designer placed many icons among text. So the text what I have to draw is something like this: Here is a word <an icon image>, and another words. The image(<another icon>) should be placed like a glyph. It's part of text, not an example. <icon> are images. (This is not a code. Just an illustration.) I can draw this by laying out all of

iPhone CoreText: Find the pixel coordinates of a substring

≡放荡痞女 提交于 2019-12-03 02:31:23
问题 Here's a screenshot of the twitter app for reference: http://screencast.com/t/YmFmYmI4M What I want to do is place a floating pop-over on top of a substring in an NSAttributedString that could span multiple lines. NSAttributedString is a requirement for the project. In the screenshot supplied, you can see that links are background-highlighted, so it leads me to believe that they're using CoreText and NSAttributedStrings. I also found something called CTRunRef ( http://developer.apple.com

CoreText crashes when run in multiple threads

萝らか妹 提交于 2019-12-03 02:21:13
I have a very weird problem with core text, which sometimes randomly and sometimes reproducibly crashes my application. I use it to lay out and render a couple of pages. I do this asynchronously in the background to not block the user interface. While this works fine in general, it sometimes crashes. All these crashes happen on the very same line: framesetter = CTFramesetterCreateWithAttributedString((CFAttributedStringRef)myText); In fact, they also also seem to come from a similar point in the framework. I know you don't like it, but here's the head of a crash log: Thread 8 Crashed: 0 ???

CTRunGetImageBounds returning inaccurate results

人盡茶涼 提交于 2019-12-03 00:43:43
I am using Core Text to draw some text. I would like to get the various run bounds, but when I call CTRunGetImageBounds , the rect that is returned is the correct size, but in the wrong location. Specifically, the line origin is at the end of the text as a whole. - (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); self.transform = CGAffineTransformMakeScale(1.0, -1.0); CGContextSetTextMatrix(context, CGAffineTransformIdentity); [[UIColor whiteColor] set]; CGContextFillRect(context, self.bounds); NSMutableAttributedString* attrString = [

Core Text - Height of glyph

流过昼夜 提交于 2019-12-02 21:11:39
I have 2 attributed strings say 'A' and '.' I need to calculate the height of each of these strings. Currently the height returned is the same for both, it seems to return the maximum possible height for the tallest character in a given font (even if that character isn't present in the string). I would like to get the exact pixel height for each of these characters, so that I can resize a view around them that fits the character (glyph) snugly. I've tried using CTFramesetterSuggestFrameSizeWithConstraints() and CTLineGetTypographicBounds() but it returns a number similar to the attributed

How to use CTRunDelegate in iPad?

╄→гoц情女王★ 提交于 2019-12-02 19:46:40
I am a developing an iPad application in which i have to use CTRunDelegate . I have defined all the the callbacks that are required viz CTRunDelegateGetAscentCallback , CTRunDelegateGetDescentCallback , CTRunDelegateGetWidthCallback . I dont know how to use CTRunDelegateRef object that I am creating. Right now what is happening is that my callbacks are not getting called. Any pointers in this regard will be highly appreciated. Thanx in advance. You should add your run delegate as an attribute for a range of characters in your attributed string. See Core Text String Attributes . When drawing,

Core Text - Get Pixel Coordinates from NSRange

若如初见. 提交于 2019-12-02 19:46:11
How would I get a CGRect from an NSRange for text rendered with Core Text? I am using Core Text with an NSAttributedString . It is an absolute pain but can be done. You need to get all of the lines in the frame using CTFrameGetLines() , check if their character range is in the range you're looking for using CTLineGetStringRange() , use CTLineGetTypographicBounds() to find how big the line itself would render as, and use CTLineGetOffsetForStringIndex() to determine the actual position of the start/end character of the range (if the line is just a subrange of the desired range). Combining all of

Drawing Text with Core Graphics

无人久伴 提交于 2019-12-02 19:44:03
I need to draw centered text to a CGContext. I started with a Cocoa approach. I created a NSCell with the text and tried to draw it thus: NSGraphicsContext* newCtx = [NSGraphicsContext graphicsContextWithGraphicsPort:bitmapContext flipped:true]; [NSGraphicsContext saveGraphicsState]; [NSGraphicsContext setCurrentContext:newCtx]; [pCell setFont:font]; [pCell drawWithFrame:rect inView:nil]; [NSGraphicsContext restoreGraphicsState]; But the CGBitmapContext doesn't seem to have the text rendered on it. Possibly because I have to pass nil for the inView: parameter. So I tried switching text

Swift: Extracting / downcasting CFType based CoreText types in a CFArray

杀马特。学长 韩版系。学妹 提交于 2019-12-02 19:36:20
问题 I am trying to port elements of the CoreAnimationText sample to Swift. I cannot figure out though, how to extract or downcast the elements of CTRun from an array, in order to pass them to functions that expect and act upon the Swift-ified CTRun type. I either get runtime errors or linking errors from the playground snippet below import CoreText import QuartzCore let text = NSAttributedString(string: "hello") var line: CTLine = CTLineCreateWithAttributedString(text) var ctRuns:CFArray =

Does CoreText support Small Caps?

谁说我不能喝 提交于 2019-12-02 18:47:46
Does CoreText have any facility for selecting a SmallCaps variant of a font, or for synthesizing small caps if the font doesn't have that feature? I can't find anything in the CoreText documentation that talks about small caps, though there are facilities for dealing with font variations/features. Has anyone done anything similar to this? It's generally easiest to use CTFontDescriptorCreateCopyWithFeature . As you mentioned in your own answer, this will only work for fonts that actually implement the feature you are requesting. The answer appears to be a qualified Yes. It supports fonts that