Skip to content

Fontstack with @font-face #5

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

Merged
merged 1 commit into from
Feb 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions templates/base/head.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,6 @@
<link rel="stylesheet" href="{{StaticUrlPrefix}}/css/easymde.css?v={{MD5 AppVer}}">
{{end}}
<link rel="stylesheet" href="{{StaticUrlPrefix}}/css/index.css?v={{MD5 AppVer}}">
<script>
if (navigator.userAgent.match('Windows')) { document.documentElement.style.setProperty('--fonts-system-ui', 'Segoe UI'); }
</script>
<noscript>
<style>
.dropdown:hover > .menu { display: block; }
Expand Down
45 changes: 6 additions & 39 deletions web_src/less/_base.less
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
:root {
/* documented customizable variables */
--fonts-proportional: var(--fonts-system-ui), "Roboto", "Helvetica Neue", "Arial", "Noto Sans", "Liberation Sans";
--fonts-proportional: system-ui, -apple-system, "Segoe UI", "Roboto", "Helvetica Neue", "Arial", "Noto Sans", "Liberation Sans", sans-serif;
--fonts-monospace: "SFMono-Regular", "Menlo", "Monaco", "Consolas", "Liberation Mono", "Courier New", monospace;
--fonts-emoji: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", "Twemoji Mozilla";
--fonts-emoji: system-emoji;
/* other variables */
--fonts-system-ui: system-ui, -apple-system; // will be replaced with "Segoe UI" if user agent is Windows
--fonts-regular: var(--fonts-proportional), var(--fonts-emoji), sans-serif;
--fonts-regular: var(--fonts-emoji), var(--fonts-proportional);
--border-radius: .28571429rem;
--opacity-disabled: .55;
--color-primary: #4183c4;
Expand Down Expand Up @@ -116,42 +115,10 @@
--checkbox-mask-indeterminate: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M2 7.75A.75.75 0 012.75 7h10a.75.75 0 010 1.5h-10A.75.75 0 012 7.75z"></path></svg>');
}

:root:lang(ja) {
--fonts-regular: var(--fonts-proportional), var(--fonts-emoji), "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", "Source Han Sans JP", "Noto Sans CJK JP", "Droid Sans Japanese", "Meiryo", "MS PGothic", sans-serif;
}

:root:lang(zh-CN) {
--fonts-regular: var(--fonts-proportional), var(--fonts-emoji), "PingFang SC", "Hiragino Sans GB", "Source Han Sans CN", "Source Han Sans SC", "Noto Sans CJK SC", "Microsoft YaHei", "Heiti SC", "SimHei", sans-serif;
}

:root:lang(zh-TW) {
--fonts-regular: var(--fonts-proportional), var(--fonts-emoji), "PingFang TC", "Hiragino Sans TC", "Source Han Sans TW", "Source Han Sans TC", "Noto Sans CJK TC", "Microsoft JhengHei", "Heiti TC", "PMingLiU", sans-serif;
}

:root:lang(zh-HK) {
--fonts-regular: var(--fonts-proportional), var(--fonts-emoji), "PingFang HK", "Hiragino Sans TC", "Source Han Sans HK", "Source Han Sans TC", "Noto Sans CJK TC", "Microsoft JhengHei", "Heiti TC", "PMingLiU_HKSCS", "PMingLiU", sans-serif;
}

:root:lang(ko) {
--fonts-regular: var(--fonts-proportional), var(--fonts-emoji), "Apple SD Gothic Neo", "NanumBarunGothic", "Malgun Gothic", "Gulim", "Dotum", "Nanum Gothic", "Source Han Sans KR", "Noto Sans CJK KR", sans-serif;
}

@font-face {
font-family: "Yu Gothic";
src: local("Yu Gothic Regular"), local("Yu Gothic Medium");
font-weight: 300;
}

@font-face {
font-family: "Yu Gothic";
src: local("Yu Gothic Medium");
font-weight: 400;
}

@font-face {
font-family: "Yu Gothic";
src: local("Yu Gothic Bold");
font-weight: 700;
font-family: system-emoji;
src: local("Apple Color Emoji"), local("Segoe UI Emoji"), local("Noto Color Emoji"), local("Twemoji Mozilla");
unicode-range: ~"U+2310-329F, U+FE0?, U+1F000-1FAFF";
}

textarea {
Expand Down
108 changes: 108 additions & 0 deletions web_src/less/_font_i18n.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/* font i18n */
:root {
/* customizable localized variables */
:lang(ja) {
--fonts-regular: var(--fonts-emoji), system-ui-ja, var(--fonts-proportional);
}
:lang(zh-CN) {
--fonts-regular: var(--fonts-emoji), system-ui-zh-cn, var(--fonts-proportional);
}
:lang(zh-TW) {
--fonts-regular: var(--fonts-emoji), system-ui-zh-tw, var(--fonts-proportional);
}
:lang(zh-HK) {
--fonts-regular: var(--fonts-emoji), system-ui-zh-hk, var(--fonts-proportional);
}
:lang(ko) {
--fonts-regular: var(--fonts-emoji), system-ui-ko, var(--fonts-proportional);
}
}

[lang] {
font-family: var(--fonts-regular);
}

each(@fonts, {
@weights: .gen-weights-all(@value);
@locale: replace(@key, "@", "-");
.font-face-cjk(~"system-ui@{locale}", @weights[@light], 300);
.font-face-cjk(~"system-ui@{locale}", @weights[@regular], 400);
.font-face-cjk(~"system-ui@{locale}", @weights[@medium], 500);
.font-face-cjk(~"system-ui@{locale}", @weights[@bold], 700);
});

@fonts: {
@ja:
"HiraginoSans-:{W2,W4,W5,W6}", "Hiragino Kaku Gothic ProN :{W3,W6}",
.shs("JP")[], .shs("J")[], .noto("JP")[], .shs("")[],
/* https://acetaminophen.hatenablog.com/entry/2016/02/15/225009 */
"Yu Gothic :{Regular,Medium,Medium,Bold}", "YuGothic :{Regular,Medium,Medium,Bold}",
"Droid Sans Japanese:{}", "Meiryo:{, Bold}", "MS PGothic:{}";
@zh-cn:
.pingfang("SC")[],
.shs("CN")[], .shs("SC")[], .noto("SC")[],
"HiraginoSansGB-:{W3,W6}", "Hiragino Sans GB :{W3,W6}",
"Microsoft YaHei:{ Light,, Bold}", "Heiti SC :{Light,Medium}", "SimHei:{}";
@zh-tw:
.pingfang("TC")[],
.shs("TW")[], .shs("TC")[], .noto("TC")[],
"HiraginoSansTC-:{W3,W6}", "Hiragino Sans TC :{W3,W6}",
"Microsoft JhengHei:{ Light,, Bold}", "Heiti TC :{Light,Medium}", "PMingLiU:{}";
@zh-hk:
.pingfang("HK")[],
.shs("HK")[], .shs("HC")[], .noto("HK")[], .shs("TC")[], .noto("TC")[],
"Microsoft JhengHei:{ Light,, Bold}", "Heiti TC :{Light,Medium}", "PMingLiU_HKSCS:{}", "PMingLiU:{}";
@ko:
"AppleSDGothicNeo-:{Light,Regular,Medium,Semibold}",
.shs("KR")[], .shs("K")[], .noto("KR")[],
"NanumBarunGothic:{ Light,, Bold}",
"Malgun Gothic:{ Semilight,, Bold}", "Nanum Gothic:{, Bold}", "Dotum:{}";
}

.noto(@suffix) { @value: "Noto Sans CJK @{suffix} ", "NotoSansCJK@{suffix}-"; }
.shs(@suffix) { @value: replace("Source Han Sans @{suffix} ", " ", " "), "SourceHanSans@{suffix}-"; }
.pingfang(@suffix) { @value: "PingFang@{suffix}-:{Light,Regular,Medium,Semibold}"; }
.font-face-cjk(@family, @src, @weight) {
@font-face {
font-family: @family;
src: @src;
font-weight: @weight;
unicode-range: ~"U+11??, U+2E80-4DBF, U+AC00-D7FF, U+4E00-9FFF, U+FF00-FFEF, U+1F2??";
}
}

.gen-weights(@family) when (isstring(@family)) {
@family-str: replace(@family, ":\{.*\}$", "");
// apply standard style names if none is given
// should the font have no styles, use :{}, as in "SimHei:{}"
@weights-str: if(@family = @family-str, "Light,Regular,Medium,Bold", replace(@family, ".*:\{(.*)\}$", "$1"));
@lightest: replace(@weights-str, ",.*", "");
@boldest: replace(@weights-str, ".*,", "");
@2ndboldest: replace(@weights-str, "(?:.*,|)([^,]*),.*$", "$1");
@2ndlightest: if(@2ndboldest = @lightest, @lightest, replace(@weights-str, "^.*?,([^,]*).*", "$1"));

@light: local("@{family-str}@{lightest}");
@regular: local("@{family-str}@{2ndlightest}");
@medium: local("@{family-str}@{2ndboldest}");
@bold: local("@{family-str}@{boldest}");
}
.gen-weights(@family) when not (isstring(@family)) {
.gen-weights-all(@family);
}
.gen-weights(@family, @last) {
@this: .gen-weights(@family);

@light: @last[@light], @this[@light];
@regular: @last[@regular], @this[@regular];
@medium: @last[@medium], @this[@medium];
@bold: @last[@bold], @this[@bold];
}
.gen-weights-all(@family) when not (isstring(@family)) {
.gen-weights-all(@family, length(@family));
}
.gen-weights-all(@family, 1) when not (isstring(@family)) {
.gen-weights(extract(@family, 1));
}
.gen-weights-all(@family, @ctr) when not (isstring(@family)) and (@ctr > 1) and (@ctr <= length(@family)) {
.gen-weights(extract(@family, @ctr), .gen-weights-all(@family, @ctr - 1));
}
1 change: 1 addition & 0 deletions web_src/less/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

@import "_svg";
@import "_tribute";
@import "_font_i18n";
@import "_base";
@import "_markdown";
@import "_home";
Expand Down