I have custom font file. How do I add it the grails project. Can I use ${resource(dir: , file:'')} for adding it?
3 Answers
This answer is not limited to Grails, since you use CSS to do it. There's this related question in SO, it explains that you need to use @font-face.
You can use relative paths and let Grails resources handle it you:
Put your font in web-app/fonts (create the directory)
Add to your css (considering the file Delicious-Roman.ttf, replace to yours):
@font-face { font-family: Delicious; src: url('../fonts/Delicious-Roman.ttf'); }
@font-face { font-family: Delicious; font-weight: bold; src: url('../Delicious-Bold.ttf'); }

- 1
- 1
Download your font from any website. got to webFont Generator. It will generate a zip file . in which got to your .css file and copy and paste code in your web within style tag. also paste all file within same directory. it will run all browser.
@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";
}
this code snippet is true for philospher font. You can use any font based on this example. Enjoy.

- 1,729
- 2
- 16
- 30
Put it into web-app
dir.
You can create directory like web-app/fonts and reference it as /fonts/yourfont.ttf
or as ${resource(dir: 'fonts', file: yourfont.ttf}
Notice that the first works only if you run your application in a root context.

- 1,077
- 4
- 21
- 55