Skip to content

Commit

Permalink
Merge pull request #35 from 5anniversary/font_weight_raw
Browse files Browse the repository at this point in the history
Fix incorrect font-weight mapping based on Mozilla documentation
  • Loading branch information
zhgchgli0718 authored Sep 3, 2023
2 parents a6cd4d6 + 4a3494f commit 9f70d94
Showing 1 changed file with 39 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,47 @@ struct HTMLTagStyleAttributeToMarkupStyleVisitor: HTMLTagStyleAttributeVisitor {
return MarkupStyle(font: MarkupStyleFont(weight: .style(.regular)))
}
case .rawValue(let value):
return MarkupStyle(font: MarkupStyleFont(weight: .rawValue(value)))
/*
https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight#common_weight_name_mapping
Value Common weight name
100 Thin (Hairline)
200 Extra Light (Ultra Light)
300 Light
400 Normal (Regular)
500 Medium
600 Semi Bold (Demi Bold)
700 Bold
800 Extra Bold (Ultra Bold)
900 Black (Heavy)
950 Extra Black (Ultra Black)
*/
switch value {
case 100:
return MarkupStyle(font: MarkupStyleFont(weight: .style(.thin)))
case 200:
return MarkupStyle(font: MarkupStyleFont(weight: .style(.ultraLight)))
case 300:
return MarkupStyle(font: MarkupStyleFont(weight: .style(.light)))
case 400:
return MarkupStyle(font: MarkupStyleFont(weight: .style(.regular)))
case 500:
return MarkupStyle(font: MarkupStyleFont(weight: .style(.medium)))
case 600:
return MarkupStyle(font: MarkupStyleFont(weight: .style(.semibold)))
case 700:
return MarkupStyle(font: MarkupStyleFont(weight: .style(.bold)))
case 800:
return MarkupStyle(font: MarkupStyleFont(weight: .style(.heavy)))
case 900:
return MarkupStyle(font: MarkupStyleFont(weight: .style(.black)))
case 950:
return MarkupStyle(font: MarkupStyleFont(weight: .style(.black)))
default:
return MarkupStyle(font: MarkupStyleFont(weight: .rawValue(value)))
}
}
}

func visit(_ styleAttribute: FontFamilyHTMLTagStyleAttribute) -> MarkupStyle? {
// e.g. "Times New Roman", Times, serif
// use first match font
Expand Down

0 comments on commit 9f70d94

Please sign in to comment.