DyslexiaFont.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\Theming\Themes;
  8. use OCA\Theming\ITheme;
  9. class DyslexiaFont extends DefaultTheme implements ITheme {
  10. public function getId(): string {
  11. return 'opendyslexic';
  12. }
  13. public function getType(): int {
  14. return ITheme::TYPE_FONT;
  15. }
  16. public function getTitle(): string {
  17. return $this->l->t('Dyslexia font');
  18. }
  19. public function getEnableLabel(): string {
  20. return $this->l->t('Enable dyslexia font');
  21. }
  22. public function getDescription(): string {
  23. return $this->l->t('OpenDyslexic is a free typeface/font designed to mitigate some of the common reading errors caused by dyslexia.');
  24. }
  25. public function getCSSVariables(): array {
  26. $variables = parent::getCSSVariables();
  27. $originalFontFace = $variables['--font-face'];
  28. $variables = [
  29. '--font-face' => 'OpenDyslexic, ' . $originalFontFace
  30. ];
  31. return $variables;
  32. }
  33. public function getCustomCss(): string {
  34. $fontPathWoff = $this->urlGenerator->linkTo('theming', 'fonts/OpenDyslexic-Regular.woff');
  35. $fontPathOtf = $this->urlGenerator->linkTo('theming', 'fonts/OpenDyslexic-Regular.otf');
  36. $fontPathTtf = $this->urlGenerator->linkTo('theming', 'fonts/OpenDyslexic-Regular.ttf');
  37. $boldFontPathWoff = $this->urlGenerator->linkTo('theming', 'fonts/OpenDyslexic-Bold.woff');
  38. $boldFontPathOtf = $this->urlGenerator->linkTo('theming', 'fonts/OpenDyslexic-Bold.otf');
  39. $boldFontPathTtf = $this->urlGenerator->linkTo('theming', 'fonts/OpenDyslexic-Bold.ttf');
  40. return "
  41. @font-face {
  42. font-family: 'OpenDyslexic';
  43. font-style: normal;
  44. font-weight: 400;
  45. src: url('$fontPathWoff') format('woff'),
  46. url('$fontPathOtf') format('opentype'),
  47. url('$fontPathTtf') format('truetype');
  48. }
  49. @font-face {
  50. font-family: 'OpenDyslexic';
  51. font-style: normal;
  52. font-weight: 700;
  53. src: url('$boldFontPathWoff') format('woff'),
  54. url('$boldFontPathOtf') format('opentype'),
  55. url('$boldFontPathTtf') format('truetype');
  56. }
  57. ";
  58. }
  59. }