-
Notifications
You must be signed in to change notification settings - Fork 106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Style boldItalics not rendered correctly #51
Comments
This is actually supported, but no used in any of the example theme files. Therefore I close this. |
After some more testing I have discovered a bug that arises from a library design flaw. In the current implementation The styles are applied here: for (style) in theme.styles {
style.regex.enumerateMatches(in: backingString, options: .withoutAnchoringBounds, range: range, using: { (match, flags, stop) in
guard let match = match else { return }
backingStore.addAttributes(style.attributes, range: match.range(at: 0))
})
} The order of I think to fix this issue the |
Maybe the issue can be fixed by improving the regular expression for |
Thanks for bringing this to my attention; the styles do need to be reworked a bit and are probably a part of a massive overhaul that includes separating tokens such as |
Awesome! Let me know if you have an idea how to implement this. I am open to help writing the required code. |
I found it works well if you don't just command it to e.g. "set this to italics", but instead "fetch the current font and add the italic font trait". For bold and italics, I call public func regularize(range: NSRange) {
let font = self.font(at: range.location + range.length / 2)
self.addStyleAttribute(.font, value: font.regularized(), range: range)
}
public func embolden(range: NSRange) {
let font = self.font(at: range.location + range.length / 2)
self.addStyleAttribute(.font, value: font.emboldened(), range: range)
}
public func italicize(range: NSRange) {
let font = self.font(at: range.location + range.length / 2)
self.addStyleAttribute(.font, value: font.italicized(), range: range)
}
public func font(at location: Int) -> UniversalFont {
return self.styleAttribute(.font, at: location) as? UniversalFont
?? UniversalFont.systemFontOfDefaultSize
} With this: public typealias UniversalColor = NSColor
public typealias UniversalFont = NSFont
public typealias UniversalFontDescriptor = NSFontDescriptor
extension UniversalFont {
func italicized() -> UniversalFont {
return NSFontManager().convert(self, toHaveTrait: .italicFontMask)
}
func emboldened() -> UniversalFont {
return NSFontManager().convert(self, toHaveTrait: .boldFontMask)
}
func regularized() -> UniversalFont {
return NSFontManager().convert(self, toHaveTrait: [.unboldFontMask, .unitalicFontMask])
}
static var systemFontOfDefaultSize: UniversalFont {
return UniversalFont.systemFont(ofSize: UniversalFont.systemFontSize)
}
} |
@DivineDominion love that approach! @funkenstrahlen if you want to take a look... |
I just took a look at this and still do not know how to integrate this in to the existing structure. Currently it works like this:
Problems with this approach: Merging of font traits settings for two This could be solved by applying font traits separately after all other styles have been set. However this is not possible because currently there is no access to the |
Maybe there is a way to build this just for |
The following example should render as bold and italics at the same time:
Like this: foobar
However it is only rendered in bold style.
The text was updated successfully, but these errors were encountered: