简体   繁体   English

使拉丁字体小于希伯来语(unicode-range)

[英]Making a Latin font smaller than Hebrew (unicode-range)

I have a Hebrew/English site that uses two fonts added with @font-face .我有一个希伯来语/英语网站,它使用两个 fonts 添加了@font-face Using unicode-range I've defined one font to apply only at Hebrew chars and another to apply to all other chars.使用unicode-range我定义了一种字体仅适用于希伯来字符,另一种字体适用于所有其他字符。

The problem is in the fact that my Hebrew font has characters that look noticeably smaller than the ones in the Latin font.问题在于我的希伯来字体中的字符看起来明显小于拉丁字体中的字符。 The easy solution would be to replace one of the fonts and find some other which has chars of a similar size.简单的解决方案是替换其中一个 fonts 并找到其他具有相似大小的字符。 But unfortunately, I have to keep those two fonts.但不幸的是,我必须保留那两个 fonts。 Can't change them.不能改变它们。 So my question is.所以我的问题是。 Is there a way to eg define that all chars in Latin unicode-range should have a font-size of 0.8em ?有没有办法例如定义拉丁语 unicode-range 中的所有字符的font-size0.8em

Keep in mind that an element might contain both Hebrew and Latin chars at the same time.请记住,一个元素可能同时包含希伯来语和拉丁语字符。 So a solution with setting a different class based on the entire site's language would not work.因此,根据整个站点的语言设置不同的 class 的解决方案将不起作用。 It would really have to be defined on the "per-char" level.它真的必须在“每个字符”级别上定义。

Edit: per request in comment I'm adding a code example:编辑:根据评论中的请求,我正在添加一个代码示例:

/* --- --- --- Defining font: --- --- --- */
@font-face {
  font-family: HebrewFontName;

  src: local('HebrewFontName'),
  local('HebrewFontName'),
  url(/fonts/HebrewFontName.otf);
  font-weight: 300;
  unicode-range: U+0590-05FF,
  U+0030-0039;
}

@font-face {
  font-family: HelveticaNeue;

  src: url(/fonts/HelveticaNeueDeskUI-01.ttf);
  font-weight: 400;
}

/* --- --- --- Using font: --- --- --- */
.someElement {
  font-family: 'MigdalRegular', 'HelveticaNeue';
}

You can't currently.你目前不能。

The unicode-range property is intended for determining either to download a font or not. unicode-range属性用于确定是否下载字体。 It doesn't filter the character range to apply the font to.它不会过滤要应用字体的字符范围。

... If the page doesn't use any character in this range, the font is not downloaded; ...如果页面不使用此范围内的任何字符,则不下载字体; if it uses at least one, the whole font is downloaded.如果它至少使用一个,则下载整个字体。

The purpose of this descriptor is to allow the font resources to be segmented so that a browser only needs to download the font resource needed for the text content of a particular page.该描述符的目的是允许对字体资源进行分段,以便浏览器只需要下载特定页面的文本内容所需的字体资源。 For example, a site with many localizations could provide separate font resources for English, Greek and Japanese.例如,具有许多本地化的站点可以为英语、希腊语和日语提供单独的字体资源。 For users viewing the English version of a page, the font resources for Greek and Japanese fonts wouldn't need to be downloaded, saving bandwidth.对于查看英文版页面的用户,无需下载希腊文和日文字体资源fonts,节省带宽。

–– MDN unicode-range –– MDN unicode-range

Your best bet is to use different font for different language segment: by inserting span on the segments.您最好的选择是为不同的语言段使用不同的字体:通过在段上插入span

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

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