Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable28] Feature/fonts improvement #3351

Merged
merged 2 commits into from
Dec 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/assets/fonts
tests/clover.xml
.idea
node_modules/
Expand Down
1 change: 1 addition & 0 deletions .nextcloudignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
src
build
.git
tests
node_modules
Expand Down
6 changes: 6 additions & 0 deletions appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,16 @@ You can also edit your documents off-line with the Collabora Office app from the
<job>OCA\Richdocuments\Backgroundjobs\ObtainCapabilities</job>
<job>OCA\Richdocuments\Backgroundjobs\Cleanup</job>
</background-jobs>
<repair-steps>
<install>
<step>OCA\Richdocuments\Migration\InstallDefaultFonts</step>
</install>
</repair-steps>
<commands>
<command>OCA\Richdocuments\Command\ActivateConfig</command>
<command>OCA\Richdocuments\Command\ConvertToBigInt</command>
<command>OCA\Richdocuments\Command\UpdateEmptyTemplates</command>
<command>OCA\Richdocuments\Command\InstallDefaultFonts</command>
</commands>
<settings>
<admin>OCA\Richdocuments\Settings\Admin</admin>
Expand Down
1 change: 1 addition & 0 deletions assets/fonts/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fonts will be added here during release build thorugh the build/download-fonts.sh script.
93 changes: 93 additions & 0 deletions assets/fonts/AmaticSC-Regular.LICENSE.txt
Original file line number Diff line number Diff line change
@@ -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.
Binary file added assets/fonts/AmaticSC-Regular.ttf
Binary file not shown.
47 changes: 47 additions & 0 deletions build/download-fonts.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
2 changes: 2 additions & 0 deletions composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
8 changes: 8 additions & 0 deletions cypress/e2e/settings.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {

Expand Down Expand Up @@ -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')
Expand Down
1 change: 1 addition & 0 deletions krankerl.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
32 changes: 32 additions & 0 deletions lib/Command/InstallDefaultFonts.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace OCA\Richdocuments\Command;

use OCA\Richdocuments\Service\FontService;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class InstallDefaultFonts extends Command {
public function __construct(private FontService $fontService) {
parent::__construct();
}

protected function configure() {
$this
->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('<error>Failed to install default fonts</error>');
$output->writeln($e->getMessage());
$output->writeln($e->getTraceAsString());
return 1;
}
}
}
27 changes: 27 additions & 0 deletions lib/Migration/InstallDefaultFonts.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace OCA\Richdocuments\Migration;

use OCA\Richdocuments\Service\FontService;
use OCP\IConfig;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;

class InstallDefaultFonts implements IRepairStep {
public function __construct(private IConfig $config, private FontService $fontService) {
}

public function getName(): string {
return 'Install default fonts';
}

public function run(IOutput $output): void {
$appVersion = $this->config->getAppValue('richdocuments', 'installed_version');

if (!empty($appVersion) && version_compare($appVersion, '8.3.0', '>')) {
return;
}

$this->fontService->installDefaultFonts();
}
}
38 changes: 38 additions & 0 deletions lib/Service/FontService.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

namespace OCA\Richdocuments\Service;

use Exception;
use OCA\Richdocuments\AppInfo\Application;
use OCP\Files\IAppData;
use OCP\Files\NotFoundException;
Expand Down Expand Up @@ -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);
}
}
}
2 changes: 1 addition & 1 deletion src/components/AdminSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ export default {
fontXmlHint() {
return `
<remote_font_config>
<url desc="URL of optional JSON file that lists fonts to be included in Online" type="string" default="">${this.fontHintUrl}</url>
<url>${this.fontHintUrl}</url>
</remote_font_config>
`
},
Expand Down
5 changes: 5 additions & 0 deletions tests/psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
<code>Command</code>
</UndefinedClass>
</file>
<file src="lib/Command/InstallDefaultFonts.php">
<UndefinedClass>
<code>Command</code>
</UndefinedClass>
</file>
<file src="lib/Controller/DirectViewController.php">
<InvalidScalarArgument>
<code><![CDATA[$item->getId()]]></code>
Expand Down
Loading