diff --git a/appinfo/info.xml b/appinfo/info.xml index 20feb659e0..1c1c910f5b 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -35,6 +35,7 @@ You can also edit your documents off-line with the Collabora Office app from the OCA\Richdocuments\Command\ActivateConfig OCA\Richdocuments\Command\ConvertToBigInt OCA\Richdocuments\Command\UpdateEmptyTemplates + OCA\Richdocuments\Command\InstallDefaultFonts OCA\Richdocuments\Settings\Admin @@ -42,4 +43,9 @@ You can also edit your documents off-line with the Collabora Office app from the OCA\Richdocuments\Settings\Personal OCA\Richdocuments\Settings\Section + + + OCA\Richdocuments\Migration\InstallDefaultFonts + + diff --git a/assets/fonts/AmaticSC-Regular.ttf b/assets/fonts/AmaticSC-Regular.ttf new file mode 100644 index 0000000000..b860368bec Binary files /dev/null and b/assets/fonts/AmaticSC-Regular.ttf differ diff --git a/cypress/e2e/settings.spec.js b/cypress/e2e/settings.spec.js index 3adefbb183..6771523cb5 100644 --- a/cypress/e2e/settings.spec.js +++ b/cypress/e2e/settings.spec.js @@ -21,6 +21,7 @@ import { User } from '@nextcloud/cypress' const usesHttps = Cypress.env('baseUrl').substr(0, 5) === 'https' const collaboraUrl = Cypress.env('collaboraUrl') +const defaultFonts = ['AmaticSC-Regular.ttf'] describe('Office admin settings', function() { @@ -77,6 +78,13 @@ describe('Office admin settings', function() { .scrollIntoView() .should('be.visible') + cy.get('#font-settings') + .scrollIntoView() + .should('be.visible') + defaultFonts.forEach(font => { + cy.get('.settings-entry.font-list-settings').contains(font) + }) + // FIXME: Template settings only get visible after reload cy.reload() cy.get('#richdocuments-templates') diff --git a/lib/Command/InstallDefaultFonts.php b/lib/Command/InstallDefaultFonts.php new file mode 100644 index 0000000000..2a1416ed91 --- /dev/null +++ b/lib/Command/InstallDefaultFonts.php @@ -0,0 +1,32 @@ +setName('richdocuments:install-fonts') + ->setDescription('Install default fonts'); + } + + protected function execute(InputInterface $input, OutputInterface $output) { + try { + $this->fontService->installDefaultFonts(); + return 0; + } catch (\Exception $e) { + $output->writeln('Failed to install default fonts'); + $output->writeln($e->getMessage()); + $output->writeln($e->getTraceAsString()); + return 1; + } + } +} diff --git a/lib/Migration/InstallDefaultFonts.php b/lib/Migration/InstallDefaultFonts.php new file mode 100644 index 0000000000..58a69a1374 --- /dev/null +++ b/lib/Migration/InstallDefaultFonts.php @@ -0,0 +1,27 @@ +config->getAppValue('richdocuments', 'installed_version'); + + if (version_compare($appVersion, '8.2.2') < 1) { + return; + } + + $this->fontService->installDefaultFonts(); + } +} diff --git a/lib/Service/FontService.php b/lib/Service/FontService.php index 67c168bd91..e41d97721b 100644 --- a/lib/Service/FontService.php +++ b/lib/Service/FontService.php @@ -23,6 +23,7 @@ namespace OCA\Richdocuments\Service; +use Exception; use OCA\Richdocuments\AppInfo\Application; use OCP\Files\IAppData; use OCP\Files\NotFoundException; @@ -242,4 +243,41 @@ private function generateFontOverview(ISimpleFile $fontFile): void { // in the UI and display a fallback message } } + + /** + * @throws Exception + */ + public function installDefaultFonts(): void { + $dirPath = __DIR__ . '/../../assets/fonts'; + + if (!is_dir($dirPath)) { + throw new Exception("Directory \"$dirPath\" does not exist!"); + } + + $handle = opendir($dirPath); + + if (!$handle) { + throw new Exception("Failed opening directory \"$dirPath\"!"); + } + + while (false !== ($fileName = readdir($handle))) { + if ($fileName === '.' || $fileName === '..') { + continue; + } + + $filePath = $dirPath . '/' . $fileName; + + if (!is_file($filePath)) { + continue; + } + + $fileHandle = fopen($filePath, 'r'); + + if (!$fileHandle) { + continue; + } + + $this->uploadFontFile($fileName, $fileHandle); + } + } } diff --git a/tests/psalm-baseline.xml b/tests/psalm-baseline.xml index c55752e530..6297e9bbba 100644 --- a/tests/psalm-baseline.xml +++ b/tests/psalm-baseline.xml @@ -33,6 +33,11 @@ Command + + + Command + + getId()]]>