You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

themes-fonts.asciidoc 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. ---
  2. title: Custom Fonts
  3. order: 9
  4. layout: page
  5. ---
  6. [[themes.fonts]]
  7. = Custom Fonts
  8. In addition to using the built-in fonts of the browser and the web fonts
  9. included in the Vaadin themes, you can use custom web fonts.
  10. [[themes.fonts.loading]]
  11. == Loading Local Fonts
  12. You can load locally served web fonts with the [literal]#++font-face++# mixin as
  13. follows:
  14. ----
  15. @include font-face('MyFontFamily',
  16. '../../../../mytheme/fonts/myfontfamily', 400, normal);
  17. ----
  18. The first argument is the name of the font family (e.g. 'Helvetica'). The second argument is the path to the font files in the theme folder (prefixed by four double-dots to escape the mixin path), excluding file extension. The third arguments is the font weight (normal, bold, 400, 600, etc). The fourth argument is the style (normal/italic).
  19. The statement must be given in the [filename]#styles.scss# file __outside__ the
  20. [literal]#++.mytheme {}++# block, after [literal]#++@import "mytheme.scss"++# or in a separate stylesheet imported there.
  21. We recommend placing custom font files under a [filename]#fonts# folder in a theme.
  22. Not all browsers support any single font file format, so the base name is
  23. appended with [filename]#.ttf#, [filename]#.eot#, [filename]#.woff#, or
  24. [filename]#.svg# suffix for the font file suitable for a user's browser. It is recommended to provide the font in all four formats to support all browsers.
  25. [[themes.fonts.webfonts]]
  26. == Loading Web Fonts
  27. You can load externally served web fonts such as Google Fonts simply by
  28. specifying the loading stylesheet for the UI with the [classname]#@StyleSheet#
  29. annotation.
  30. For example, to load the "Cabin Sketch" font from Google Fonts:
  31. [subs="normal"]
  32. ----
  33. @StyleSheet({"[replaceable]#http://fonts.googleapis.com/css?family=Cabin+Sketch#"})
  34. public class MyUI extends UI {
  35. ...
  36. ----
  37. [[themes.fonts.using]]
  38. == Using Custom Fonts
  39. After loaded, you can use a custom font, or actually font family, by its name in
  40. CSS and otherwise.
  41. ----
  42. .mystyle {
  43. font-family: MyFontFamily;
  44. }
  45. ----
  46. If the font family name contains spaces, you need to use single or double
  47. quotes around the name.