简体   繁体   English

如何在CakePHP中使用自定义字体?

[英]How to use custom fonts in CakePHP?

I am trying to use a custom font in CakePHP but it doesn't seem to be working. 我正在尝试在CakePHP中使用自定义字体,但似乎无法正常工作。

I am getting the font from http://www.dafont.com/ssf4-abuket.font (A Street Fighter font!!). 我从http://www.dafont.com/ssf4-abuket.font (一种Street Fighter字体!)获取字体。 And I store the ttf font file to webroot/css. 然后将ttf字体文件存储到webroot / css。

This is my CSS: 这是我的CSS:

@font-face {
    font-family: 'SF';
    src: url('StreetFighter.ttf') format('truetype');
}

p {
    height: 50%;
    margin: 30px 0;
    text-align: center;
    font-size: 2.2rem;
    font-family: 'SF';
    color: #000;
}

However, when I use a different font such as the Arkitech from http://www.1001freefonts.com/ with the same code but different filename it works. 但是,当我使用其他字体(例如来自http://www.1001freefonts.com/的Arkitech)使用相同的代码但使用不同的文件名时,它可以工作。

As you are only having a .ttf file for your font-face, not all browsers can use .ttf font files. 由于您的字体只有一个.ttf文件,因此并非所有浏览器都可以使用.ttf字体文件。 You have to declare alternative font formats in the @font-face css. 您必须在@ font-face css中声明其他字体格式。

You can generate these other font formats with an online converter. 您可以使用在线转换器生成其他字体格式。 (for example: http://freedockstar.com/fontface/ ). (例如: http : //freedockstar.com/fontface/ )。

Then you need to have the following font-face declaration: 然后,您需要具有以下字体声明:

@font-face {
font-family: 'SF';
src: url('StreetFighter.eot'); /* IE9 Compat Modes */
src: url('StreetFighter.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
     url('StreetFighter.woff') format('woff'), /* Modern Browsers */
     url('StreetFighter.ttf')  format('truetype'), /* Safari, Android, iOS */
     url('StreetFighter.svg') format('svg'); /* Legacy iOS */
}

I've tried your font with this tool and it generates a working preview of your webfont. 我已经使用此工具尝试了您的字体,它会生成您的Webfont的工作预览。

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

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