mirror of
https://github.com/exyte/Macaw.git
synced 2024-09-11 05:05:23 +03:00
renamed kern to kerning, fixed tests for kerning attribute
This commit is contained in:
parent
ca65880621
commit
14db8659e3
@ -168,6 +168,25 @@ class NodeBoundsTests: XCTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func testTextWithKerning() {
|
||||
let texts = ["", "Hello, World", "Hello,\nWorld", "\nHello\n,\nWorld"]
|
||||
let kernings : [Float] = [-1.0, -0.5, 0.5, 1.0]
|
||||
|
||||
texts.forEach { (text) in
|
||||
kernings.forEach({ (kerning) in
|
||||
let text = Text(text: text, kerning: kerning)
|
||||
|
||||
let stringAttributes = [NSAttributedString.Key.font: MFont.systemFont(ofSize: MFont.systemFontSize),
|
||||
NSAttributedString.Key.kern: NSNumber(value: kerning)]
|
||||
let size = text.text.size(withAttributes: stringAttributes)
|
||||
let targetRect = Rect(x: 0.0, y: 0.0, w: size.width.doubleValue, h: size.height.doubleValue)
|
||||
|
||||
checkBounds(rect1: text.bounds, rect2: targetRect)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Group
|
||||
|
||||
func testSimpleGroupZeroBounds() {
|
||||
|
@ -8,8 +8,6 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
import Foundation
|
||||
|
||||
#if os(OSX)
|
||||
import AppKit
|
||||
|
||||
|
@ -41,21 +41,21 @@ open class Text: Node {
|
||||
get { return baselineVar.value }
|
||||
set(val) { baselineVar.value = val }
|
||||
}
|
||||
|
||||
|
||||
public let kerningVar: Variable<Float>
|
||||
open var kerning: Float {
|
||||
get { return kerningVar.value }
|
||||
set(val) { kerningVar.value = val}
|
||||
get { return kerningVar.value }
|
||||
set(val) { kerningVar.value = val }
|
||||
}
|
||||
|
||||
public init(text: String, font: Font? = nil, fill: Fill? = Color.black, stroke: Stroke? = nil, align: Align = .min, baseline: Baseline = .top, kern: Float = 0.0, place: Transform = Transform.identity, opaque: Bool = true, opacity: Double = 1, clip: Locus? = nil, mask: Node? = nil, effect: Effect? = nil, visible: Bool = true, tag: [String] = []) {
|
||||
public init(text: String, font: Font? = nil, fill: Fill? = Color.black, stroke: Stroke? = nil, align: Align = .min, baseline: Baseline = .top, kerning: Float = 0.0, place: Transform = Transform.identity, opaque: Bool = true, opacity: Double = 1, clip: Locus? = nil, mask: Node? = nil, effect: Effect? = nil, visible: Bool = true, tag: [String] = []) {
|
||||
self.textVar = Variable<String>(text)
|
||||
self.fontVar = Variable<Font?>(font)
|
||||
self.fillVar = Variable<Fill?>(fill)
|
||||
self.strokeVar = Variable<Stroke?>(stroke)
|
||||
self.alignVar = Variable<Align>(align)
|
||||
self.baselineVar = Variable<Baseline>(baseline)
|
||||
self.kerningVar = Variable<Float>(kern)
|
||||
self.kerningVar = Variable<Float>(kerning)
|
||||
super.init(
|
||||
place: place,
|
||||
opaque: opaque,
|
||||
@ -82,7 +82,9 @@ open class Text: Node {
|
||||
}
|
||||
var stringAttributes: [NSAttributedString.Key: AnyObject] = [:]
|
||||
stringAttributes[NSAttributedString.Key.font] = font
|
||||
stringAttributes[NSAttributedString.Key.kern] = NSNumber(value: self.kerning)
|
||||
if self.kerning != 0.0 {
|
||||
stringAttributes[NSAttributedString.Key.kern] = NSNumber(value: self.kerning)
|
||||
}
|
||||
let size = (text as NSString).size(withAttributes: stringAttributes)
|
||||
return Rect(
|
||||
x: calculateAlignmentOffset(font: font),
|
||||
|
@ -67,9 +67,9 @@ class TextRenderer: NodeRenderer {
|
||||
attributes[NSAttributedString.Key.strokeWidth] = width as NSObject?
|
||||
}
|
||||
if text.kerning != 0.0 {
|
||||
attributes[NSAttributedString.Key.kern] = NSNumber(value: text.kerning)
|
||||
attributes[NSAttributedString.Key.kern] = NSNumber(value: text.kerning)
|
||||
}
|
||||
|
||||
|
||||
if attributes.count > 1 {
|
||||
MGraphicsPushContext(context)
|
||||
message.draw(in: getBounds(font), withAttributes: attributes)
|
||||
@ -134,12 +134,12 @@ class TextRenderer: NodeRenderer {
|
||||
return .zero
|
||||
}
|
||||
|
||||
var textAttributes : [NSAttributedString.Key: Any] = [NSAttributedString.Key.font: font]
|
||||
if (text.kerning != 0.0){
|
||||
textAttributes[NSAttributedString.Key.kern] = NSNumber(value: text.kerning)
|
||||
var textAttributes: [NSAttributedString.Key: Any] = [NSAttributedString.Key.font: font]
|
||||
if text.kerning != 0.0 {
|
||||
textAttributes[NSAttributedString.Key.kern] = NSNumber(value: text.kerning)
|
||||
}
|
||||
if let stroke = text.stroke {
|
||||
textAttributes[NSAttributedString.Key.strokeWidth] = NSNumber(value: stroke.width)
|
||||
textAttributes[NSAttributedString.Key.strokeWidth] = NSNumber(value: stroke.width)
|
||||
}
|
||||
let textSize = NSString(string: text.text).size(withAttributes: textAttributes)
|
||||
return CGRect(x: calculateAlignmentOffset(text, font: font),
|
||||
|
Loading…
Reference in New Issue
Block a user