简体   繁体   English

W3C CSS 验证器在@font-face unicode-range 上给出错误

[英]W3C CSS validator is giving errors on @font-face unicode-range

Since few days ago W3C CSS validator started to be more strict and started to give errors on this type of CSS3 implementation (this type of CSS3 files are everywhere and they were used for example by Google Fonts):从几天前开始,W3C CSS 验证器开始变得更加严格,并开始在这种类型的 CSS3 实现上报错(这种类型的 CSS3 文件无处不在,例如被 Google Fonts 使用):

/* vietnamese */
@font-face {
  font-family: 'Nunito';
  font-style: normal;
  font-weight: 400;
  src: local('Nunito Regular'), local('Nunito-Regular'), url("fonts/XRXV3I6Li01BKofIOuaBXso.woff2") format('woff2');
  unicode-range: U+0102-0103, U+0110-0111, U+1EA0-1EF9, U+20AB;
  font-display: fallback;
}
/* latin-ext */
@font-face {
  font-family: 'Nunito';
  font-style: normal;
  font-weight: 400;
  src: local('Nunito Regular'), local('Nunito-Regular'), url("fonts/XRXV3I6Li01BKofIO-aBXso.woff2") format('woff2');
  unicode-range: U+0100-024F, U+0259, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF;
  font-display: fallback;
}
/* latin */
@font-face {
  font-family: 'Nunito';
  font-style: normal;
  font-weight: 400;
  src: local('Nunito Regular'), local('Nunito-Regular'), url("fonts/XRXV3I6Li01BKofINeaB.woff2") format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
  font-display: fallback;
}
/* vietnamese */
@font-face {
  font-family: 'Nunito';
  font-style: normal;
  font-weight: 700;
  src: local('Nunito Bold'), local('Nunito-Bold'), url("fonts/XRXW3I6Li01BKofAjsOUbuvISTs.woff2") format('woff2');
  unicode-range: U+0102-0103, U+0110-0111, U+1EA0-1EF9, U+20AB;
  font-display: fallback;
}
/* latin-ext */
@font-face {
  font-family: 'Nunito';
  font-style: normal;
  font-weight: 700;
  src: local('Nunito Bold'), local('Nunito-Bold'), url("fonts/XRXW3I6Li01BKofAjsOUb-vISTs.woff2") format('woff2');
  unicode-range: U+0100-024F, U+0259, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF;
  font-display: fallback;
}
/* latin */
@font-face {
  font-family: 'Nunito';
  font-style: normal;
  font-weight: 700;
  src: local('Nunito Bold'), local('Nunito-Bold'), url("fonts/XRXW3I6Li01BKofAjsOUYevI.woff2") format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
  font-display: fallback;
}

With the following error on unicode-range : Too many values or values are not recognizedunicode-range上出现以下错误: Too many values or values are not recognized

Apparently many developers have used unicode ranges with multiple values and multiples ranges for their fonts because MDN says it is OK , but apparently it is not, since according to W3C docs, the syntax for unicode-range is:显然,许多开发人员已经为他们的字体使用了具有多个值和多个范围的 unicode 范围,因为MDN 说没问题,但显然不是,因为根据 W3C 文档, unicode-range语法是:

unicode-range: single codepoint | codepoint range | wildcard range | initial | inherit;

That is, apparently many ranges are not possible.也就是说,显然许多范围是不可能的。

How to tackle this issue?如何解决这个问题?

This seems to be a very strict approach of W3C since many browsers support several ranges, and it indeed saves bandwidth because allows more flexibility on which font files are to be downloaded.这似乎是 W3C 的一种非常严格的方法,因为许多浏览器支持多个范围,并且它确实节省了带宽,因为在下载哪些字体文件时允许更大的灵活性。

EDIT: This answer is no longer valid because there was a bug on in the validator , see: https://stackoverflow.com/a/69711789/724039编辑:此答案不再有效,因为验证器中存在错误,请参阅: https ://stackoverflow.com/a/69711789/724039

The correct solution is was to follow the 'docs' at MDN Webdocs: unicode-range正确的解决方案 遵循MDN Webdocs 上的“文档”:unicode-range

change: unicode-range: U+0102-0103, U+0110-0111, U+1EA0-1EF9, U+20AB;更改: unicode-range: U+0102-0103, U+0110-0111, U+1EA0-1EF9, U+20AB;

to:至:

unicode-range: U+0102-0103;
unicode-range: U+0110-0111;
unicode-range: U+1EA0-1EF9;
unicode-range: U+20AB;

This is a defect of the validator.这是验证器的缺陷。

The CSS Fonts Specification defines the unicode-range property as CSS 字体规范将unicode-range属性定义为

Value: <urange>#

where <urange> can be any of其中<urange>可以是任何

single codepoint (eg U+416)<br> a Unicode codepoint, represented as one to six hexadecimal digits interval range (eg U+400-4ff)<br> represented as two hyphen-separated Unicode codepoints indicating the inclusive start and end codepoints of a range wildcard range (eg U+4??)<br> defined by the set of codepoints implied when trailing '?' characters signify any hexadecimal digit

And the # means # 表示

... that the preceding type, word, or group occurs one or more times, separated by comma tokens (which may optionally be surrounded by white space and/or comments). ... 前面的类型、单词或组出现一次或多次,用逗号分隔(可以选择用空格和/或注释包围)。

The specification underlines this formal definition in prose:该规范在散文中强调了这个正式的定义:

This descriptor defines the set of Unicode codepoints that may be supported by the font face for which it is declared.此描述符定义了一组 Unicode 代码点,这些代码点可能被声明的字体支持。 The descriptor value is a comma-delimited list of Unicode range () values.描述符值是以逗号分隔的 Unicode 范围 () 值列表。

It also provides examples.它还提供了示例。 Example 30 is particular useful:示例 30特别有用:

@font-face {
  font-family: STIXGeneral;
  src: local(STIXGeneral), url(/stixfonts/STIXGeneral.otf);
  unicode-range: U+000-49F, U+2000-27FF, U+2900-2BFF, U+1D400-1D7FF;
}

If you submit this to the CSS validator, it will report the same error.如果您将此提交给 CSS 验证器,它将报告相同的错误。 Since the spec is authoritative, the validator must be in error.由于规范是权威的,验证器肯定是错误的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM