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.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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++# mixin as
  13. follows:
  14. ----
  15. @include font(MyFontFamily,
  16. '../../../../mytheme/fonts/myfontfamily');
  17. ----
  18. The statement must be given in the [filename]#styles.scss# file __outside__ the
  19. [literal]#++.mytheme {}++# block.
  20. The first parameter is the name of the font family, which is used to identify
  21. the font. If the font family name contains spaces, you need to use single or
  22. double quotes around the name.
  23. The second parameter is the base name of the font files without an extension,
  24. including a relative path. Notice that the path is relative to the base theme,
  25. where the mixin is defined, not the used theme. We recommend placing custom font
  26. files under a [filename]#fonts# folder in a theme.
  27. Not all browsers support any single font file format, so the base name is
  28. appended with [filename]#.ttf#, [filename]#.eot#, [filename]#.woff#, or
  29. [filename]#.svg# suffix for the font file suitable for a user's browser.
  30. [[themes.fonts.webfonts]]
  31. == Loading Web Fonts
  32. You can load externally served web fonts such as Google Fonts simply by
  33. specifying the loading stylesheet for the UI with the [classname]#@StyleSheet#
  34. annotation.
  35. For example, to load the "Cabin Sketch" font from Google Fonts:
  36. [subs="normal"]
  37. ----
  38. @StyleSheet({"[replaceable]#http://fonts.googleapis.com/css?family=Cabin+Sketch#"})
  39. public class MyUI extends UI {
  40. ...
  41. ----
  42. ifdef::web[]
  43. Note that such web fonts served from a domain different from the Vaadin
  44. application currently link:https://dev.vaadin.com/ticket/16249[do not work
  45. together with] responsive themes, as described in
  46. <<dummy/../../../framework/themes/themes-responsive#themes.responsive,"Responsive
  47. Themes">>. The problem occurs only in Firefox. A SecurityError is shown in the
  48. debug window.
  49. endif::web[]
  50. [[themes.fonts.using]]
  51. == Using Custom Fonts
  52. After loaded, you can use a custom font, or actually font family, by its name in
  53. CSS and otherwise.
  54. ----
  55. .mystyle {
  56. font-family: MyFontFamily;
  57. }
  58. ----
  59. Again, if the font family name contains spaces, you need to use single or double
  60. quotes around the name.