Skip to content

Commit 5d73c1e

Browse files
committed
Reduce font size for superscript and subscript.
1 parent f2425b8 commit 5d73c1e

File tree

4 files changed

+46
-2
lines changed

4 files changed

+46
-2
lines changed

Aztec/Classes/Converters/StringAttributesToAttributes/Implementations/SubscriptStringAttributeConverter.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ open class SubscriptStringAttributeConverter: StringAttributeConverter {
4242
return false
4343
}
4444

45-
return baselineOffset.intValue < 0;
45+
return baselineOffset.intValue <= -4;
4646
}
4747
}
4848

Aztec/Classes/Converters/StringAttributesToAttributes/Implementations/SuperscriptStringAttributeConverter.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ open class SuperscriptStringAttributeConverter: StringAttributeConverter {
4242
return false
4343
}
4444

45-
return baselineOffset.intValue > 0;
45+
return baselineOffset.intValue >= 4;
4646
}
4747
}
4848

Aztec/Classes/Formatters/Implementations/SubscriptFormatter.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,26 @@ class SubscriptFormatter: StandardAttributeFormatter {
77
attributeValue: NSNumber(-4),
88
htmlRepresentationKey: .subHtmlRepresentation)
99
}
10+
11+
override func apply(to attributes: [NSAttributedString.Key: Any], andStore representation: HTMLRepresentation?) -> [NSAttributedString.Key: Any] {
12+
var resultingAttributes = super.apply(to: attributes, andStore: representation)
13+
guard let currentFont = attributes[.font] as? UIFont else {
14+
return resultingAttributes
15+
}
16+
let font = UIFont(descriptor: currentFont.fontDescriptor, size: currentFont.pointSize - 2)
17+
resultingAttributes[.font] = font
18+
return resultingAttributes
19+
}
20+
21+
override func remove(from attributes: [NSAttributedString.Key: Any]) -> [NSAttributedString.Key: Any] {
22+
var resultingAttributes = super.remove(from: attributes)
23+
24+
guard let currentFont = attributes[.font] as? UIFont else {
25+
return resultingAttributes
26+
}
27+
let font = UIFont(descriptor: currentFont.fontDescriptor, size: currentFont.pointSize + 2)
28+
resultingAttributes[.font] = font
29+
30+
return resultingAttributes
31+
}
1032
}

Aztec/Classes/Formatters/Implementations/SuperscriptFormatter.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,26 @@ class SuperscriptFormatter: StandardAttributeFormatter {
77
attributeValue: NSNumber(4),
88
htmlRepresentationKey: .supHtmlRepresentation)
99
}
10+
11+
override func apply(to attributes: [NSAttributedString.Key: Any], andStore representation: HTMLRepresentation?) -> [NSAttributedString.Key: Any] {
12+
var resultingAttributes = super.apply(to: attributes, andStore: representation)
13+
guard let currentFont = attributes[.font] as? UIFont else {
14+
return resultingAttributes
15+
}
16+
let font = UIFont(descriptor: currentFont.fontDescriptor, size: currentFont.pointSize - 2)
17+
resultingAttributes[.font] = font
18+
return resultingAttributes
19+
}
20+
21+
override func remove(from attributes: [NSAttributedString.Key: Any]) -> [NSAttributedString.Key: Any] {
22+
var resultingAttributes = super.remove(from: attributes)
23+
24+
guard let currentFont = attributes[.font] as? UIFont else {
25+
return resultingAttributes
26+
}
27+
let font = UIFont(descriptor: currentFont.fontDescriptor, size: currentFont.pointSize + 2)
28+
resultingAttributes[.font] = font
29+
30+
return resultingAttributes
31+
}
1032
}

0 commit comments

Comments
 (0)