diff --git a/.gitignore b/.gitignore index ede8050d02..6549d6b6a2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +/assets/fonts tests/clover.xml .idea node_modules/ diff --git a/.nextcloudignore b/.nextcloudignore index d3a72d88c0..491a43ceaa 100644 --- a/.nextcloudignore +++ b/.nextcloudignore @@ -1,4 +1,5 @@ src +build .git tests node_modules diff --git a/appinfo/info.xml b/appinfo/info.xml index 3b2b7fa67b..65efcc9c24 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -31,10 +31,16 @@ You can also edit your documents off-line with the Collabora Office app from the OCA\Richdocuments\Backgroundjobs\ObtainCapabilities OCA\Richdocuments\Backgroundjobs\Cleanup + + + OCA\Richdocuments\Migration\InstallDefaultFonts + + OCA\Richdocuments\Command\ActivateConfig OCA\Richdocuments\Command\ConvertToBigInt OCA\Richdocuments\Command\UpdateEmptyTemplates + OCA\Richdocuments\Command\InstallDefaultFonts OCA\Richdocuments\Settings\Admin diff --git a/assets/fonts/.gitkeep b/assets/fonts/.gitkeep new file mode 100644 index 0000000000..f0234b9523 --- /dev/null +++ b/assets/fonts/.gitkeep @@ -0,0 +1 @@ +Fonts will be added here during release build thorugh the build/download-fonts.sh script. \ No newline at end of file diff --git a/assets/fonts/AmaticSC-Regular.LICENSE.txt b/assets/fonts/AmaticSC-Regular.LICENSE.txt new file mode 100644 index 0000000000..f77af8218e --- /dev/null +++ b/assets/fonts/AmaticSC-Regular.LICENSE.txt @@ -0,0 +1,93 @@ +Copyright 2015 The Amatic SC Project Authors (https://github.com/googlefonts/AmaticSC) + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +http://scripts.sil.org/OFL + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/assets/fonts/AmaticSC-Regular.ttf b/assets/fonts/AmaticSC-Regular.ttf new file mode 100644 index 0000000000..fc4c36261a Binary files /dev/null and b/assets/fonts/AmaticSC-Regular.ttf differ diff --git a/build/download-fonts.sh b/build/download-fonts.sh new file mode 100755 index 0000000000..3a8bf8667a --- /dev/null +++ b/build/download-fonts.sh @@ -0,0 +1,47 @@ +#!/bin/bash +# +# Download font files and put them into the assets/fonts folder for the release + +FONTLIST=( + "https://github.com/google/fonts/raw/main/ofl/amaticsc/AmaticSC-Regular.ttf" + "https://github.com/google/fonts/raw/main/ofl/amaticsc/AmaticSC-Bold.ttf" + "https://github.com/google/fonts/blob/main/ofl/caveat/Caveat%5Bwght%5D.ttf" + "https://github.com/google/fonts/raw/main/ofl/comfortaa/Comfortaa%5Bwght%5D.ttf" + "https://github.com/google/fonts/raw/main/ofl/ebgaramond/EBGaramond%5Bwght%5D.ttf" + "https://github.com/google/fonts/raw/main/ofl/lexend/Lexend%5Bwght%5D.ttf" + "https://github.com/google/fonts/raw/main/ofl/lobster/Lobster-Regular.ttf" + "https://github.com/google/fonts/raw/main/ofl/lora/Lora%5Bwght%5D.ttf" + "https://github.com/google/fonts/raw/main/ofl/montserrat/Montserrat%5Bwght%5D.ttf" + "https://github.com/google/fonts/raw/main/ofl/nunito/Nunito%5Bwght%5D.ttf" + "https://github.com/google/fonts/raw/main/ofl/oswald/Oswald%5Bwght%5D.ttf" + "https://github.com/google/fonts/raw/main/ofl/pacifico/Pacifico-Regular.ttf" + "https://github.com/google/fonts/raw/main/ofl/playfairdisplay/PlayfairDisplay%5Bwght%5D.ttf" + "https://github.com/google/fonts/blob/main/ofl/roboto/Roboto%5Bwdth%2Cwght%5D.ttf" + "https://github.com/google/fonts/raw/main/apache/robotomono/RobotoMono%5Bwght%5D.ttf" + "https://github.com/google/fonts/blob/main/ofl/spectral/Spectral-Regular.ttf" +) + +rm assets/fonts/* + +function urldecode() { : "${*//+/ }"; echo -e "${_//%/\\x}"; } + +for font in "${FONTLIST[@]}"; do + echo "$font" + wget -q -P assets/fonts/ $font + + FILENAME=$(urldecode "$(basename "$font")") + + if [[ $FILENAME == *"wght"* ]]; then + NEWFILENAME=$(echo $FILENAME | sed 's/\[wght\]/-wght/g') + NEWFILENAME=$(echo $NEWFILENAME | sed 's/\[wdth,wght\]/-wdtg-wght/g') + mv assets/fonts/$FILENAME assets/fonts/$NEWFILENAME + else + NEWFILENAME=$(echo $FILENAME) + fi + + echo "$FILENAME" + FONTNAME=$(echo $NEWFILENAME | sed 's/.ttf//g') + + echo "$(dirname $font)/OFL.txt" + wget -q -O "assets/fonts/$FONTNAME.LICENSE.txt" "$(dirname $font)/OFL.txt" +done \ No newline at end of file diff --git a/composer/composer/autoload_classmap.php b/composer/composer/autoload_classmap.php index 2e92308c27..804e1b123a 100644 --- a/composer/composer/autoload_classmap.php +++ b/composer/composer/autoload_classmap.php @@ -14,6 +14,7 @@ 'OCA\\Richdocuments\\Capabilities' => $baseDir . '/../lib/Capabilities.php', 'OCA\\Richdocuments\\Command\\ActivateConfig' => $baseDir . '/../lib/Command/ActivateConfig.php', 'OCA\\Richdocuments\\Command\\ConvertToBigInt' => $baseDir . '/../lib/Command/ConvertToBigInt.php', + 'OCA\\Richdocuments\\Command\\InstallDefaultFonts' => $baseDir . '/../lib/Command/InstallDefaultFonts.php', 'OCA\\Richdocuments\\Command\\UpdateEmptyTemplates' => $baseDir . '/../lib/Command/UpdateEmptyTemplates.php', 'OCA\\Richdocuments\\Controller\\AssetsController' => $baseDir . '/../lib/Controller/AssetsController.php', 'OCA\\Richdocuments\\Controller\\DirectViewController' => $baseDir . '/../lib/Controller/DirectViewController.php', @@ -45,6 +46,7 @@ 'OCA\\Richdocuments\\Listener\\ReferenceListener' => $baseDir . '/../lib/Listener/ReferenceListener.php', 'OCA\\Richdocuments\\Listener\\ShareLinkListener' => $baseDir . '/../lib/Listener/ShareLinkListener.php', 'OCA\\Richdocuments\\Middleware\\WOPIMiddleware' => $baseDir . '/../lib/Middleware/WOPIMiddleware.php', + 'OCA\\Richdocuments\\Migration\\InstallDefaultFonts' => $baseDir . '/../lib/Migration/InstallDefaultFonts.php', 'OCA\\Richdocuments\\Migration\\Version2060Date20200302131958' => $baseDir . '/../lib/Migration/Version2060Date20200302131958.php', 'OCA\\Richdocuments\\Migration\\Version2060Date20200302132145' => $baseDir . '/../lib/Migration/Version2060Date20200302132145.php', 'OCA\\Richdocuments\\Migration\\Version30704Date20200626072306' => $baseDir . '/../lib/Migration/Version30704Date20200626072306.php', diff --git a/composer/composer/autoload_static.php b/composer/composer/autoload_static.php index 401deeb4e8..078f8c9771 100644 --- a/composer/composer/autoload_static.php +++ b/composer/composer/autoload_static.php @@ -29,6 +29,7 @@ class ComposerStaticInitRichdocuments 'OCA\\Richdocuments\\Capabilities' => __DIR__ . '/..' . '/../lib/Capabilities.php', 'OCA\\Richdocuments\\Command\\ActivateConfig' => __DIR__ . '/..' . '/../lib/Command/ActivateConfig.php', 'OCA\\Richdocuments\\Command\\ConvertToBigInt' => __DIR__ . '/..' . '/../lib/Command/ConvertToBigInt.php', + 'OCA\\Richdocuments\\Command\\InstallDefaultFonts' => __DIR__ . '/..' . '/../lib/Command/InstallDefaultFonts.php', 'OCA\\Richdocuments\\Command\\UpdateEmptyTemplates' => __DIR__ . '/..' . '/../lib/Command/UpdateEmptyTemplates.php', 'OCA\\Richdocuments\\Controller\\AssetsController' => __DIR__ . '/..' . '/../lib/Controller/AssetsController.php', 'OCA\\Richdocuments\\Controller\\DirectViewController' => __DIR__ . '/..' . '/../lib/Controller/DirectViewController.php', @@ -60,6 +61,7 @@ class ComposerStaticInitRichdocuments 'OCA\\Richdocuments\\Listener\\ReferenceListener' => __DIR__ . '/..' . '/../lib/Listener/ReferenceListener.php', 'OCA\\Richdocuments\\Listener\\ShareLinkListener' => __DIR__ . '/..' . '/../lib/Listener/ShareLinkListener.php', 'OCA\\Richdocuments\\Middleware\\WOPIMiddleware' => __DIR__ . '/..' . '/../lib/Middleware/WOPIMiddleware.php', + 'OCA\\Richdocuments\\Migration\\InstallDefaultFonts' => __DIR__ . '/..' . '/../lib/Migration/InstallDefaultFonts.php', 'OCA\\Richdocuments\\Migration\\Version2060Date20200302131958' => __DIR__ . '/..' . '/../lib/Migration/Version2060Date20200302131958.php', 'OCA\\Richdocuments\\Migration\\Version2060Date20200302132145' => __DIR__ . '/..' . '/../lib/Migration/Version2060Date20200302132145.php', 'OCA\\Richdocuments\\Migration\\Version30704Date20200626072306' => __DIR__ . '/..' . '/../lib/Migration/Version30704Date20200626072306.php', diff --git a/cypress/e2e/settings.spec.js b/cypress/e2e/settings.spec.js index 8ea1ead195..3df9538b88 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() { @@ -79,6 +80,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/krankerl.toml b/krankerl.toml index a7398b7508..39210c65c8 100644 --- a/krankerl.toml +++ b/krankerl.toml @@ -2,6 +2,7 @@ before_cmds = [ "composer install --working-dir=composer/", "composer dump --working-dir=composer/", + "bash ./build/download-fonts.sh", "npm ci", "npm run build" ] 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..8b58d1f791 --- /dev/null +++ b/lib/Migration/InstallDefaultFonts.php @@ -0,0 +1,27 @@ +config->getAppValue('richdocuments', 'installed_version'); + + if (!empty($appVersion) && version_compare($appVersion, '8.3.0', '>')) { + return; + } + + $this->fontService->installDefaultFonts(); + } +} diff --git a/lib/Service/FontService.php b/lib/Service/FontService.php index 67c168bd91..99b8ea7d3a 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 (\str_starts_with($fileName, '.') || \str_ends_with($fileName, '.txt')) { + continue; + } + + $filePath = $dirPath . '/' . $fileName; + + if (!is_file($filePath)) { + continue; + } + + $fileHandle = fopen($filePath, 'r'); + + if (!$fileHandle) { + continue; + } + + $this->uploadFontFile($fileName, $fileHandle); + } + } } diff --git a/src/components/AdminSettings.vue b/src/components/AdminSettings.vue index 73b01be088..b63423d7e1 100644 --- a/src/components/AdminSettings.vue +++ b/src/components/AdminSettings.vue @@ -527,7 +527,7 @@ export default { fontXmlHint() { return ` - ${this.fontHintUrl} + ${this.fontHintUrl} ` }, diff --git a/tests/psalm-baseline.xml b/tests/psalm-baseline.xml index 1679e0105f..7ed92ff27d 100644 --- a/tests/psalm-baseline.xml +++ b/tests/psalm-baseline.xml @@ -33,6 +33,11 @@ Command + + + Command + + getId()]]>