core-text

CGFont and CTFont functionality in portable Swift (e.g. Ubuntu, etc)?

三世轮回 提交于 2019-12-02 16:48:33
问题 Swift on macOS, the import Foundation statement is sufficient to link with CGFont, CTFont and related functions. import Foundation public struct FontMetric { let cgFont: CGFont private let ctFont: CTFont // ... However, for Swift on Ubuntu, the CGFont, CTFont and related functions cause "undeclared type" errors: FontMetric.swift:21:17: error: use of undeclared type 'CGFont' let cgFont: CGFont ^~~~~~ FontMetric.swift:24:25: error: use of undeclared type 'CTFont' private let ctFont: CTFont ^~~~

iOS: How do you measure the width and height of a string using Quartz?

蓝咒 提交于 2019-12-02 16:46:40
Before I ask my questions, this is from Apple's documentation re: how to determine the width of a string using Quartz: If text measurements are important to your application, it is possible to calculate them using Quartz 2D functions. However, you might first consider using ATSUI, whose strength is in text layout and measurement. ATSUI has several functions that obtain text metrics. Not only can you obtain after-layout text metrics, but in the rare cases you need them, you can obtain before-layout text metrics. Unlike Quartz, for which you must perform the calculations yourself, ATSUI computes

iPhone CoreText: Find the pixel coordinates of a substring

自古美人都是妖i 提交于 2019-12-02 16:01:11
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/library/ios/#documentation/Carbon/Reference/CTRunRef/Reference/reference.html ) which looks promising, but

Display japanese Text with furigana in UILabel

こ雲淡風輕ζ 提交于 2019-12-02 15:57:56
问题 for my app, few month ago, i've take the code from this site to use CTRubyAnnotation. This code, with few changes to make work with swift 4, work perfectly. from this work I've create a class in which I written a function to use that code. this is the class in swift 4 import UIKit extension String { func find(pattern: String) -> NSTextCheckingResult? { do { let re = try NSRegularExpression(pattern: pattern, options: []) return re.firstMatch( in: self, options: [], range: NSMakeRange(0, self

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

落爺英雄遲暮 提交于 2019-12-02 15:19:22
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 them manually, but it's too hard keeping complex text layout behaviors. So I'm finding a way to draw

Display japanese Text with furigana in UILabel

天涯浪子 提交于 2019-12-02 12:24:39
for my app, few month ago, i've take the code from this site to use CTRubyAnnotation. This code, with few changes to make work with swift 4, work perfectly. from this work I've create a class in which I written a function to use that code. this is the class in swift 4 import UIKit extension String { func find(pattern: String) -> NSTextCheckingResult? { do { let re = try NSRegularExpression(pattern: pattern, options: []) return re.firstMatch( in: self, options: [], range: NSMakeRange(0, self.utf16.count)) } catch { return nil } } func replace(pattern: String, template: String) -> String { do {

iOS Monospaced Custom Font

◇◆丶佛笑我妖孽 提交于 2019-12-02 11:25:18
问题 I have a custom font included in my Xcode 7, iOS 9 targeted project. I want to make the font monospaced. I tried this, and didn't work: let originalFont = UIFont(name: "My Custom Font", size: 18) let originalFontDescriptor = originalFont!.fontDescriptor() let fontDescriptorFeatureSettings = [ [ UIFontFeatureTypeIdentifierKey: kNumberSpacingType, UIFontFeatureSelectorIdentifierKey: kMonospacedNumbersSelector ] ] let fontDescriptorAttributes = [UIFontDescriptorFeatureSettingsAttribute:

iOS: finding correct font size to fit in a UILabel depending on its size

好久不见. 提交于 2019-12-02 10:33:15
I have a UILabel whose property text I would like to set paragraphs of text to using NSString . I have an array in which I store a sequence of characters that represent a text paragraph. The paragraph doesn't have to fit/included perfectly within this UILabel . If the paragraph doesn't end, I would move on to the next label. Let say if I had rect size of this UILabel 160 X 240, how could I be able to determine the correct font size in order to fill this string of the UILabel within nicely? Is there a mathematical way for the calculation of font size based upon the size of the rect on the

How to get all characters of the font with CTFontCopyCharacterSet() in Swift?

只愿长相守 提交于 2019-12-02 10:22:28
问题 How does one get all characters of the font with CTFontCopyCharacterSet() in Swift? ... for macOS? The issue occured when implementing the approach from an OSX: CGGlyph to UniChar answer in Swift. func createUnicodeFontMap() { // Get all characters of the font with CTFontCopyCharacterSet(). let cfCharacterSet: CFCharacterSet = CTFontCopyCharacterSet(ctFont) // let cfCharacterSetStr = "\(cfCharacterSet)" print("CFCharacterSet: \(cfCharacterSet)") // Map all Unicode characters to corresponding

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

筅森魡賤 提交于 2019-12-02 08:53:17
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 = CTLineGetGlyphRuns(line) let nsRuns:Array<AnyObject> = ctRuns as NSArray nsRuns.count // == 1 // Playground