Skip to content

Commit

Permalink
Fix #4976: Make Reader Mode respect accessibility settings (#5983)
Browse files Browse the repository at this point in the history
* Fix #4976: Make Reader Mode respect accessibility settings

* Fix #4976 - Remove unused variable

* Fix #4976 - Fix selected state for font buttons
  • Loading branch information
maleshchenko authored Feb 14, 2020
1 parent 05c22f4 commit c7d6b8d
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ extension BrowserViewController: ReaderModeStyleViewControllerDelegate {
if let tab = tabManager[tabIndex] {
if let readerMode = tab.getContentScript(name: "ReaderMode") as? ReaderMode {
if readerMode.state == ReaderModeState.active {
readerMode.style = style
readerMode.style = ReaderModeStyle(theme: style.theme,
fontType: ReaderModeFontType(type: style.fontType.rawValue),
fontSize: style.fontSize)
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions Client/Frontend/Reader/Reader.css
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,20 @@ body {
font-family: sans-serif;
}

.sans-serif-bold {
font-family: sans-serif;
font-weight: bold;
}

.serif {
font-family: serif;
}

.serif-bold {
font-family: serif;
font-weight: bold;
}

.message {
margin-top: 40px;
display: none;
Expand Down
34 changes: 31 additions & 3 deletions Client/Frontend/Reader/ReaderMode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,37 @@ enum ReaderModeTheme: String {
case sepia = "sepia"
}

private struct FontFamily {
static let serifFamily = [ReaderModeFontType.serif, ReaderModeFontType.serifBold]
static let sansFamily = [ReaderModeFontType.sansSerif, ReaderModeFontType.sansSerifBold]
static let families = [serifFamily, sansFamily]
}

enum ReaderModeFontType: String {
case serif = "serif"
case serifBold = "serif-bold"
case sansSerif = "sans-serif"
case sansSerifBold = "sans-serif-bold"

init(type: String) {
let font = ReaderModeFontType(rawValue: type)
let isBoldFontEnabled = UIAccessibility.isBoldTextEnabled

switch font {
case .serif,
.serifBold:
self = isBoldFontEnabled ? .serifBold : .serif
case .sansSerif,
.sansSerifBold:
self = isBoldFontEnabled ? .sansSerifBold : .sansSerif
case .none:
self = .sansSerif
}
}

func isSameFamily(_ font: ReaderModeFontType) -> Bool {
return !FontFamily.families.filter { $0.contains(font) && $0.contains(self) }.isEmpty
}
}

enum ReaderModeFontSize: Int {
Expand Down Expand Up @@ -128,14 +156,14 @@ struct ReaderModeStyle {
}

let theme = ReaderModeTheme(rawValue: themeRawValue!)
let fontType = ReaderModeFontType(rawValue: fontTypeRawValue!)
let fontType = ReaderModeFontType(type: fontTypeRawValue!)
let fontSize = ReaderModeFontSize(rawValue: fontSizeRawValue!)
if theme == nil || fontType == nil || fontSize == nil {
if theme == nil || fontSize == nil {
return nil
}

self.theme = theme!
self.fontType = fontType!
self.fontType = fontType
self.fontSize = fontSize!
}
}
Expand Down
21 changes: 14 additions & 7 deletions Client/Frontend/Reader/ReaderModeStyleViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@ class ReaderModeStyleViewController: UIViewController, Themeable {
fileprivate func selectFontType(_ fontType: ReaderModeFontType) {
readerModeStyle.fontType = fontType
for button in fontTypeButtons {
button.isSelected = (button.fontType == fontType)
button.isSelected = button.fontType.isSameFamily(fontType)

}
for button in themeButtons {
button.fontType = fontType
Expand Down Expand Up @@ -285,11 +286,13 @@ class FontTypeButton: UIButton {
self.fontType = fontType
accessibilityHint = NSLocalizedString("Changes font type.", comment: "Accessibility hint for the font type buttons in reader mode display settings")
switch fontType {
case .sansSerif:
case .sansSerif,
.sansSerifBold:
setTitle(NSLocalizedString("Sans-serif", comment: "Font type setting in the reading view settings"), for: [])
let f = UIFont(name: "FiraSans-Book", size: DynamicFontHelper.defaultHelper.ReaderStandardFontSize)
titleLabel?.font = f
case .serif:
case .serif,
.serifBold:
setTitle(NSLocalizedString("Serif", comment: "Font type setting in the reading view settings"), for: [])
let f = UIFont(name: "Charis SIL", size: DynamicFontHelper.defaultHelper.ReaderStandardFontSize)
titleLabel?.font = f
Expand Down Expand Up @@ -350,9 +353,11 @@ class FontSizeLabel: UILabel {
var fontType: ReaderModeFontType = .sansSerif {
didSet {
switch fontType {
case .sansSerif:
case .sansSerif,
.sansSerifBold:
font = UIFont(name: "FiraSans-Book", size: DynamicFontHelper.defaultHelper.ReaderBigFontSize)
case .serif:
case .serif,
.serifBold:
font = UIFont(name: "Charis SIL", size: DynamicFontHelper.defaultHelper.ReaderBigFontSize)
}
}
Expand Down Expand Up @@ -391,9 +396,11 @@ class ThemeButton: UIButton {
var fontType: ReaderModeFontType = .sansSerif {
didSet {
switch fontType {
case .sansSerif:
case .sansSerif,
.sansSerifBold:
titleLabel?.font = UIFont(name: "FiraSans-Book", size: DynamicFontHelper.defaultHelper.ReaderStandardFontSize)
case .serif:
case .serif,
.serifBold:
titleLabel?.font = UIFont(name: "Charis SIL", size: DynamicFontHelper.defaultHelper.ReaderStandardFontSize)
}
}
Expand Down

0 comments on commit c7d6b8d

Please sign in to comment.