2

I have custom font file. How do I add it the grails project. Can I use ${resource(dir: , file:'')} for adding it?

4

3 回答 3

1

从任何网站下载您的字体。到webFont Generator。它将生成一个 zip 文件。在其中找到您的 .css 文件并在样式标记中复制并粘贴代码到您的 Web 中。还将所有文件粘贴到同一目录中。它将运行所有浏览器。

@font-face {
font-family: 'Philosopher';
src: url('WebRoot/fonts/philosopher-regular.eot');
src: url('WebRoot/fonts/philosopher-regular.eot?#iefix') format('embedded-opentype'),
     url('WebRoot/fonts/philosopher-regular.woff') format('woff'),
     url('WebRoot/fonts/philosopher-regular.ttf') format('truetype');
font-weight: normal;
font-style: normal;
}

body{
font-size: 13px;
    font-family: "Philosopher";
}

此代码片段适用于 philospher 字体。您可以使用基于此示例的任何字体。享受。

于 2013-10-30T05:00:13.267 回答
1

这个答案不仅限于 Grails,因为您使用 CSS 来做到这一点。SO 中有这个相关问题,它解释了您需要使用 @font-face

您可以使用相对路径并让 Grails 资源为您处理:

将您的字体放在web-app/fonts中(创建目录)

添加到您的 css(考虑到 Delicious-Roman.ttf 文件,替换为您的):

@font-face { font-family: Delicious; src: url('../fonts/Delicious-Roman.ttf'); } 
@font-face { font-family: Delicious; font-weight: bold; src: url('../Delicious-Bold.ttf'); }
于 2013-10-30T00:47:31.890 回答
0

将其放入web-app目录中。您可以创建类似 web-app/fonts 的目录并将其引用为/fonts/yourfont.ttf${resource(dir: 'fonts', file: yourfont.ttf} 请注意,只有在根上下文中运行应用程序时,第一个才有效。

于 2013-10-30T15:35:32.360 回答