Skip to content

Commit

Permalink
#391 add direction for text serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniil Manin committed Jun 14, 2019
1 parent 3d3a0f4 commit ef54a20
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
16 changes: 16 additions & 0 deletions MacawTests/SceneSerialization.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ class NodeSerializer {
if let baselineString = dictionary["baseline"] as? String {
text.baseline = baselineForString(baselineString)
}
if let directionString = dictionary["direction"] as? String{
text.direction = directionForString(directionString)
}

return text
}
Expand Down Expand Up @@ -174,6 +177,9 @@ extension Text: Serializable {
}
result["align"] = align.toString()
result["baseline"] = "\(baseline)"
if direction != .lre {
result["direction"] = "\(direction)"
}
return result
}
}
Expand Down Expand Up @@ -629,3 +635,13 @@ fileprivate func baselineForString(_ string: String) -> Baseline {
default: return .top
}
}

fileprivate func directionForString(_ string: String) -> Direction {
switch string {
case "lre": return .lre
case "lro": return .lro
case "rle": return .rle
case "rlo": return .rlo
default: return .lre
}
}
14 changes: 7 additions & 7 deletions Source/model/draw/Direction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,24 @@ public enum Direction {
}

extension Direction {

var attributedStringValue: NSArray {
switch self {
case .lre:
return [NSNumber(integerLiteral: 0)]
return [NSNumber(value: 0)]
case .rle:
return [NSNumber(integerLiteral: 1)]
return [NSNumber(value: 1)]
case .lro:
return [NSNumber(integerLiteral: 2)]
return [NSNumber(value: 2)]
case .rlo:
return [NSNumber(integerLiteral: 3)]
return [NSNumber(value: 3)]
}
}

static func from(direction: String?, unicodebidi: String?) -> Direction {
let direction = direction ?? "ltr"
let unicodebidi = unicodebidi ?? "normal"

switch (direction, unicodebidi) {
case ("ltr", "bidi-override"):
return .lro
Expand Down

0 comments on commit ef54a20

Please sign in to comment.