【问题标题】:'Segoe UI' font with font-face & local带有字体和本地的“Segoe UI”字体
【发布时间】:2012-10-22 15:05:32
【问题描述】:

如果安装在用户的计算机中,我想在网站中使用“Segoe UI”字体。

我已经用@font-face 声明了所有样式,以便使用font-weight 属性来更改字体的粗细(这是一个非常酷的功能!)。

问题是我无法使用 Segoe UI Bold(我认为名称错误)。有什么想法吗?

这里是一个例子。 (4) 和 (5) 相同:http://jsfiddle.net/kxHQR/1/


@font-face {
  font-family: 'Myname';
  font-style: normal;
  font-weight: 700;
  src: local('Segoe UI Bold'), local('SegoeUI-bold'), local('segoeuib');
}
@font-face {
  font-family: 'Myname';
  font-style: normal;
  font-weight: 600;
  src: local('Segoe UI Semibold'), local('SegoeUI-Semibold');
}
@font-face {
  font-family: 'Myname';
  font-style: normal;
  font-weight: 400;
  src: local('Segoe UI'), local('SegoeUI');
}
@font-face {
  font-family: 'Myname';
  font-style: normal;
  font-weight: 300;
  src: local('Segoe UI Light'), local('SegoeUI-Light');
}

/* ... */

BODY {
 font-family: 'Myname';    
}

.boldtext {
    font-family:'Segoe UI';
    font-weight:700;
}
<p style='font-weight:300'>1. Text with font-weight:300. OK</h1>
<p>2. Here is normal text. OK</p>
<p style='font-weight:600'>3. Text with font-weight:600.  OK</p> 
<p style='font-weight:700' >4. Text with font-weight:700. It must be like (5), but it is like (3). :(</p>
<p class='boldtext'>5. Text with font-family:'Segoe UI' (no font-face) and font-weight:700; </p> 

【问题讨论】:

  • FWIW,“Segoe UI Bold”是我的 Windows 字体目录中列出的名称。
  • 它可以在我的 Chrome、FF 和 IE9 机器上运行:jsfiddle.net/kxHQR。请注意,对于 IE8 及更低版本,您需要使用具有旧 IE 语法的自定义字体。
  • 它应该可以正常工作:jsfiddle.net/UcTGP 可能是您缺少字体文件吗?您使用的是什么系统或浏览器?
  • 在您的系统上使用&lt;b style="font-family: Segoe UI"&gt;Sample&lt;/b&gt; 进行测试(没有任何@font-face),或者尝试在文字处理器中使用Segoe UI Bold。听起来字体可能在您的系统中丢失或损坏。该字体可能有些奇怪,因为在我的系统上,font-family: Segoe UI Bold 不会生成它(但这种旧方法适用于 Semibold 和 Light),而我的字体列表工具(适用于 IE)cs.tut.fi/~jkorpela/listfonts1.html 没有列出 Segoe UI粗体。
  • 刚刚发现了同样的事情。有bug贴出:issue 139857,issue 124504

标签: css fonts embed font-face typography


【解决方案1】:

这是来自微软自己的stylesheet for Windows 8 (Metro) apps

/*
Explicitly define a Segoe UI font-family so that we can assign Segoe UI 
Semilight to an appropriate font-weight.
*/
@font-face {
    font-family: "Segoe UI";
    font-weight: 200;
    src: local("Segoe UI Light");
}
@font-face {
    font-family: "Segoe UI";
    font-weight: 300;
    src: local("Segoe UI Semilight");
}
@font-face {
    font-family: "Segoe UI";
    font-weight: 400;
    src: local("Segoe UI");
}
@font-face {
    font-family: "Segoe UI";
    font-weight: 600;
    src: local("Segoe UI Semibold");
}
@font-face {
    font-family: "Segoe UI";
    font-weight: 700;
    src: local("Segoe UI Bold");
}
@font-face {
    font-family: "Segoe UI";
    font-style: italic;
    font-weight: 400;
    src: local("Segoe UI Italic");
}
@font-face {
    font-family: "Segoe UI";
    font-style: italic;
    font-weight: 700;
    src: local("Segoe UI Bold Italic");
}

上述方法对我有用,也是 Open SansGoogle 字体 使用的方法。但是,它与 this 方法完全相反,最初来自 Paul Irish:

@font-face {
    font-family: 'ChunkFiveRegular;
    src: url('whatever source');
    font-weight: normal;
    font-style: normal;
}

Paul Irish 的方法允许(阅读:要求)稍后在 CSS 中设置权重和斜体,但结果是“虚假的”:由于浏览器没有家族中的所有字体,它必须计算权重和人物的造型靠自己来弥补。 Paul 方法的单一且有限的优势在于它可能重置所有浏览器的字体 - 但它确实取决于所使用的字体 - 因为所有浏览器都以不同的方式呈现字体!

我更喜欢微软的方法,因为它允许指定您需要的font-styles 和font-weights,并且浏览器将显示正确的字体文件,而不是计算虚假大小、粗体和斜体。但是,它确实要求您为将要使用的字体系列中的每种字体变体提供一个字体文件。

最后,一切都取决于您将使用什么字体以及如何使用它(不同的粗细、斜体等)。无论您采用哪种方法,根据我自己的经验(以及 Paul recommends),我都建议您使用 FontSquirrel's font-face generator 进行所有网络排版工作。 FontSquirrel 可以通过省略不必要的字符集、压缩字体等方式显着减小字体大小。

【讨论】:

  • 什么意思是“src: local("Segoe UI Italic");" ?字体文件在哪里?它仅适用于带有Windows的计算机吗?我可以自己加载 tff gile 吗?
  • 是的。这些只是这个字体系列中类型的名称——这些只会从安装了它们的计算机上加载。要在您的网站上提供它们,您必须将url() 值添加到每种字体并将它们放在您的服务器上。这个 sn-p 用于说明告诉浏览器显示哪些字体文件的font-weightfont-style 属性的方法。
  • 我似乎无法让这个在 Chrome 37 中工作。但在 IE11 中工作。 Chrome 37 只输出常规,直到你达到 font-weight:700
  • @nitech 你试过从你的服务器上提供字体吗?
  • @pilau 不。我什至没有尝试,因为我读到将字体用作网络字体时存在许可问题。由于字体已安装在我系统的预期目标计算机上,因此不需要。
【解决方案2】:

虽然基本方法是合乎逻辑的,但浏览器似乎很难用它,这显然是由于它们对字体数据的不同处理造成的。看来以下是使用不同权重的 Segoe UI 最有效的方法:

  1. 对于灯光,请使用font-family: Segoe UI Light
  2. 对于常规,只使用font-family: Segoe UI
  3. 对于半粗体,使用font-family: Segoe UI Semibold
  4. 对于粗体,使用font-family: Segoe UI; font-weight: bold

这是混乱且不合逻辑的,但它适用于 Firefox、Chrome、IE、Opera、Safari(在 Win 7 上测试)。

在网页上,最好尝试找到合适的具有不同粗细的免费字体并通过@font-face 使用它。毕竟,Segoe UI 远非通用,没有简单的方法为其设置合适的后备。

【讨论】:

  • 我还注意到,如果硬件渲染关闭(gfx.direct2d.disabled;true),Firefox 不会使用 Segoe UI 的 Light 样式 - 然后它使用默认的 Segoe UI(正常重量)样式.如果硬件渲染打开,它可以工作。
  • @PacMani,您的观察结果在 Firefox 17(Win 7)中无法重现:更改该设置并重新启动浏览器不会影响行为,font-family: Segoe UI Light 仍然有效。
  • K.Korpela:你说得对,我自己不能再复制它了。我想我上次看到我使用的是 Firefox 15。
  • font-family: Segoe UI Light 在 Windows 7 上的 Firefox 16-18 和 Windows 8 上的 FF18 上为我工作。
  • @pilau,我刚刚在 Windows 7 上的 Firefox 18.0.2 上重新测试,我得到了 Segoe UI Light。您是否检查过计算机中的 Segoe UI Light 是否丢失或损坏? (例如,它可以在文字处理器中工作,还是在其他网络浏览器中工作?)
【解决方案3】:
@font-face {
    font-family: 'Segoe UI';
    src: url('./ui/segoeui.eot');
    src: local("Segoe UI"),
         local("Segoe"),
         local("Segoe WP"),
         url('./ui/segoeui.eot?#iefix') format('embedded-opentype'),
         url('./ui/segoeui.woff') format('woff'),
         url('./ui/segoeui.svg#SegoeUI') format('svg');
    font-weight: normal;
    font-style: normal;
}

@font-face {
    font-family: 'Segoe UI Semibold';
    src: url('/semibold/seguisb.eot');
    src: local("Segoe Semibold"),
         local("Segoe WP Semibold"), 
         url('/semibold/seguisb.eot?#iefix') format('embedded-opentype'),
         url('/semibold/seguisb.woff') format('woff'),
         url('/semibold/seguisb.svg#SegoeUISemibold') format('svg');
    font-weight: normal;
    font-style: normal;
}

@font-face {
    font-family: 'Segoe UI Bold';
    src: url('/bold/segoeuib.eot');
    src: local("Segoe Bold"),
         local("Segoe WP Bold"),
         url('/bold/segoeuib.eot?#iefix') format('eot'), /* Wrong format will tell IE9+ to ignore and use WOFF instead. MSHAR-2822 */
         url('/bold/segoeuib.woff') format('woff'),
         url('/bold/segoeuib.svg#SegoeUIBold') format('svg');
    font-weight: normal;
    font-style: normal;
}

@font-face {
    font-family: 'Segoe UI Light';
    src: url('/light/segoeuil.eot');
    src: local("Segoe UI Light"),
         local("Segoe WP Light"),
         url('/light/segoeuil.eot?#iefix') format('embedded-opentype'),
         url('/light/segoeuil.woff') format('woff'),
         url('/light/segoeuil.svg#SegoeUILight') format('svg');
    font-weight: normal;
    font-style: normal;
}

下载:

https://github.com/KingRider/frontcom/tree/master/css/fonts

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-11-22
    • 2014-12-17
    • 1970-01-01
    • 2015-02-22
    • 1970-01-01
    • 2023-03-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多