You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

_font_i18n.less 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /* font i18n */
  2. :root {
  3. /* customizable localized variables */
  4. :lang(ja) {
  5. --fonts-override: var(--fonts-default-override-ja);
  6. }
  7. :lang(zh-CN) {
  8. --fonts-override: var(--fonts-default-override-zh-cn);
  9. }
  10. :lang(zh-TW) {
  11. --fonts-override: var(--fonts-default-override-zh-tw);
  12. }
  13. :lang(zh-HK) {
  14. --fonts-override: var(--fonts-default-override-zh-hk);
  15. }
  16. :lang(ko) {
  17. --fonts-override: var(--fonts-default-override-ko);
  18. }
  19. }
  20. [lang] {
  21. font-family: var(--fonts-regular);
  22. }
  23. each(@fonts, {
  24. @weights: .gen-weights-all(@value);
  25. @locale: replace(@key, "@", "-");
  26. .font-face-cjk(~"system-ui@{locale}", @weights[@light], 300);
  27. .font-face-cjk(~"system-ui@{locale}", @weights[@regular], 400);
  28. .font-face-cjk(~"system-ui@{locale}", @weights[@medium], 500);
  29. .font-face-cjk(~"system-ui@{locale}", @weights[@bold], 700);
  30. /* Safari on macOS/iOS */
  31. @font-face {
  32. font-family: ~"system-ui@{locale}";
  33. src: local("HelveticaNeue");
  34. unicode-range: U+A0;
  35. }
  36. /* Other browsers on macOS/iOS */
  37. @supports not (-webkit-hyphens:none) {
  38. @font-face {
  39. font-family: ~"system-ui@{locale}";
  40. src: local("HelveticaNeue");
  41. unicode-range: U+20;
  42. }
  43. }
  44. :root {
  45. /* Special handling for Firefox on Windows/Linux */
  46. @supports (-moz-appearance:none) {
  47. --fonts-default-override@{locale}: ~"var(--fonts-proportional), system-ui@{locale}";
  48. }
  49. --fonts-default-override@{locale}: ~"system-ui@{locale}, var(--fonts-proportional)";
  50. }
  51. });
  52. @fonts: {
  53. @ja:
  54. "HiraginoSans-:{W2,W4,W5,W6}", "HiraKakuProN-:{W3,W6}", "Hiragino Kaku Gothic ProN :{W3,W6}",
  55. .shs("JP")[], .shs("J")[], .noto("JP")[], .shs("")[],
  56. /* https://acetaminophen.hatenablog.com/entry/2016/02/15/225009 */
  57. "Yu Gothic :{Regular,Medium,Bold}", "YuGothic :{Regular,Medium,Bold}",
  58. "Droid Sans Japanese:{}", "Meiryo:{, Bold}", "MS PGothic:{}";
  59. @zh-cn:
  60. .pingfang("SC")[],
  61. .shs("CN")[], .shs("SC")[], .noto("SC")[],
  62. "HiraginoSansGB-:{W3,W6}", "Hiragino Sans GB :{W3,W6}",
  63. "Microsoft YaHei:{ Light,, Bold}", "Heiti SC :{Light,Medium}", "SimHei:{}";
  64. @zh-tw:
  65. .pingfang("TC")[],
  66. .shs("TW")[], .shs("TC")[], .noto("TC")[],
  67. "HiraginoSansTC-:{W3,W6}", "Hiragino Sans TC :{W3,W6}",
  68. "Microsoft JhengHei:{ Light,, Bold}", "Heiti TC :{Light,Medium}", "PMingLiU:{}";
  69. @zh-hk:
  70. .pingfang("HK")[],
  71. .shs("HK")[], .shs("HC")[], .noto("HK")[], .shs("TC")[], .noto("TC")[],
  72. "HiraginoSansTC-:{W3,W6}", "Hiragino Sans TC :{W3,W6}",
  73. "Microsoft JhengHei:{ Light,, Bold}", "Heiti TC :{Light,Medium}", "PMingLiU_HKSCS:{}", "PMingLiU:{}";
  74. @ko:
  75. "AppleSDGothicNeo-:{Light,Regular,Medium,SemiBold}",
  76. .shs("KR")[], .shs("K")[], .noto("KR")[],
  77. "NanumBarunGothic:{ Light,, Bold}",
  78. "Malgun Gothic:{ Semilight,, Bold}", "Nanum Gothic:{, Bold}", "Dotum:{}";
  79. }
  80. .noto(@suffix) { @value: "Noto Sans CJK @{suffix} ", "NotoSansCJK@{suffix}-"; }
  81. .shs(@suffix) { @value: replace("Source Han Sans @{suffix} ", " ", " "), "SourceHanSans@{suffix}-"; }
  82. .pingfang(@suffix) { @value: "PingFang@{suffix}-:{Light,Regular,Medium,Semibold}"; }
  83. .font-face-cjk(@family, @src, @weight) {
  84. @font-face {
  85. font-family: @family;
  86. src: @src;
  87. font-weight: @weight;
  88. unicode-range: ~"U+11??, U+2E80-4DBF, U+4E00-9FFF, U+A960-A97F, U+AC00-D7FF, U+F900-FAFF, U+FE00-FE6F, U+FF00-FFEF, U+1F2??, U+2????";
  89. }
  90. }
  91. .gen-weights(@family) when (isstring(@family)) {
  92. @family-str: replace(@family, ":\{.*\}$", "");
  93. // apply standard style names if none is given
  94. // should the font have no styles, use :{}, as in "SimHei:{}"
  95. @weights-str: if(@family = @family-str, "Light,Regular,Medium,Bold", replace(@family, ".*:\{(.*)\}$", "$1"));
  96. @lightest: replace(@weights-str, ",.*", "");
  97. @boldest: replace(@weights-str, ".*,", "");
  98. @2ndboldest: replace(@weights-str, "(?:.*,|)([^,]*),.*$", "$1");
  99. @2ndlightest: if(@2ndboldest = @lightest, @lightest, replace(@weights-str, "^.*?,([^,]*).*", "$1"));
  100. @light: local("@{family-str}@{lightest}");
  101. @regular: local("@{family-str}@{2ndlightest}");
  102. @medium: local("@{family-str}@{2ndboldest}");
  103. @bold: local("@{family-str}@{boldest}");
  104. }
  105. .gen-weights(@family) when not (isstring(@family)) {
  106. .gen-weights-all(@family);
  107. }
  108. .gen-weights(@family, @last) {
  109. @this: .gen-weights(@family);
  110. @light: @last[@light], @this[@light];
  111. @regular: @last[@regular], @this[@regular];
  112. @medium: @last[@medium], @this[@medium];
  113. @bold: @last[@bold], @this[@bold];
  114. }
  115. .gen-weights-all(@family) when not (isstring(@family)) {
  116. .gen-weights-all(@family, length(@family));
  117. }
  118. .gen-weights-all(@family, 1) when not (isstring(@family)) {
  119. .gen-weights(extract(@family, 1));
  120. }
  121. .gen-weights-all(@family, @ctr) when not (isstring(@family)) and (@ctr > 1) and (@ctr <= length(@family)) {
  122. .gen-weights(extract(@family, @ctr), .gen-weights-all(@family, @ctr - 1));
  123. }