Implement pl:u for accessing shared fonts

Fonts are stored in an array of TTF data with an 8 byte header
containing a magic and an XOR'd length. Instead of requiring users to
provide original Nintendo fonts we pack open source replacements.
They are generated with the scripts here
https://github.com/FearlessTobi/yuzu_system_archives. All the fonts are
licenced under the Open Font or Apache 2 License so we can include them
all freely.
This commit is contained in:
Billy Laws 2020-07-04 21:52:07 +01:00 committed by ◱ PixelyIon
parent 4df50cefee
commit 801382e43a
15 changed files with 253 additions and 0 deletions

View File

@ -102,6 +102,7 @@ add_library(skyline SHARED
${source_DIR}/skyline/services/visrv/IManagerDisplayService.cpp
${source_DIR}/skyline/services/visrv/IManagerRootService.cpp
${source_DIR}/skyline/services/visrv/ISystemDisplayService.cpp
${source_DIR}/skyline/services/pl/IPlatformServiceManager.cpp
${source_DIR}/skyline/vfs/partition_filesystem.cpp
${source_DIR}/skyline/vfs/rom_filesystem.cpp
${source_DIR}/skyline/vfs/os_backing.cpp

View File

@ -59,6 +59,7 @@ namespace skyline::service {
visrv_ISystemDisplayService,
visrv_IManagerDisplayService,
hosbinder_IHOSBinderDriver,
pl_IPlatformServiceManager
};
/**
@ -82,6 +83,7 @@ namespace skyline::service {
{"nvdrv:s", Service::nvdrv_INvDrvServices},
{"nvdrv:t", Service::nvdrv_INvDrvServices},
{"vi:m", Service::visrv_IManagerRootService},
{"pl:u", Service::pl_IPlatformServiceManager}
};
class ServiceManager;

View File

@ -0,0 +1,75 @@
// SPDX-License-Identifier: MPL-2.0
// Copyright © 2020 Skyline Team and Contributors (https://github.com/skyline-emu/)
#include <kernel/types/KProcess.h>
#include "resources/FontChineseSimplified.ttf.h"
#include "resources/FontChineseTraditional.ttf.h"
#include "resources/FontExtendedChineseSimplified.ttf.h"
#include "resources/FontKorean.ttf.h"
#include "resources/FontNintendoExtended.ttf.h"
#include "resources/FontStandard.ttf.h"
#include "IPlatformServiceManager.h"
namespace skyline::service::pl {
/**
* @brief This holds an entry in the the font table
*/
struct FontEntry {
u8 *data; //!< The font TTF data
size_t length; //!< The length of the font TTF data
size_t offset; //!< The offset of the font in shared memory
};
std::array<FontEntry, 6> fontTable = {{
{FontChineseSimplified, FontExtendedChineseSimplifiedLength},
{FontChineseTraditional, FontChineseTraditionalLength},
{FontExtendedChineseSimplified, FontExtendedChineseSimplifiedLength},
{FontKorean, FontKoreanLength},
{FontNintendoExtended, FontNintendoExtendedLength},
{FontStandard, FontStandardLength}
}};
IPlatformServiceManager::IPlatformServiceManager(const DeviceState &state, ServiceManager &manager) : fontSharedMem(std::make_shared<kernel::type::KSharedMemory>(state, NULL, constant::FontSharedMemSize, memory::Permission{true, false, false})), BaseService(state, manager, Service::pl_IPlatformServiceManager, "pl:IPlatformServiceManager", {
{0x1, SFUNC(IPlatformServiceManager::GetLoadState)},
{0x2, SFUNC(IPlatformServiceManager::GetSize)},
{0x3, SFUNC(IPlatformServiceManager::GetSharedMemoryAddressOffset)},
{0x4, SFUNC(IPlatformServiceManager::GetSharedMemoryNativeHandle)}
}) {
constexpr u32 SharedFontResult = 0x7f9a0218; //!< This is the decrypted magic for a single font in the shared font data
constexpr u32 SharedFontMagic = 0x36f81a1e; //!< This is the encrypted magic for a single font in the shared font data
constexpr u32 SharedFontKey = SharedFontMagic ^SharedFontResult; //!< This is the XOR key for encrypting the font size
auto pointer = reinterpret_cast<u32 *>(fontSharedMem->kernel.address);
for (auto &font : fontTable) {
*pointer++ = SharedFontResult;
*pointer++ = font.length ^ SharedFontKey;
font.offset = reinterpret_cast<u64>(pointer) - fontSharedMem->kernel.address;
memcpy(pointer, font.data, font.length);
pointer = reinterpret_cast<u32 *>(reinterpret_cast<u64>(pointer) + font.length);
}
}
void IPlatformServiceManager::GetLoadState(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {
constexpr u32 FontLoaded = 1; //!< This is returned to show that all fonts have been loaded into memory
response.Push(FontLoaded);
}
void IPlatformServiceManager::GetSize(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {
auto fontId = request.Pop<u32>();
response.Push<u32>(fontTable.at(fontId).length);
}
void IPlatformServiceManager::GetSharedMemoryAddressOffset(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {
auto fontId = request.Pop<u32>();
response.Push<u32>(fontTable.at(fontId).offset);
}
void IPlatformServiceManager::GetSharedMemoryNativeHandle(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {
auto handle = state.process->InsertItem<type::KSharedMemory>(fontSharedMem);
response.copyHandles.push_back(handle);
}
}

View File

@ -0,0 +1,46 @@
// SPDX-License-Identifier: MPL-2.0
// Copyright © 2020 Skyline Team and Contributors (https://github.com/skyline-emu/)
#pragma once
#include <services/base_service.h>
#include <services/serviceman.h>
namespace skyline {
namespace constant {
constexpr u32 FontSharedMemSize = 0x1100000; //!< This is the total size of the font shared memory
}
namespace service::pl {
/**
* @brief IPlatformServiceManager is used to access shared fonts (https://switchbrew.org/wiki/Shared_Database_services#pl:u.2C_pl:s)
*/
class IPlatformServiceManager : public BaseService {
private:
std::shared_ptr<kernel::type::KSharedMemory> fontSharedMem; //!< This shared memory stores the TTF data of all shared fonts
public:
IPlatformServiceManager(const DeviceState &state, ServiceManager &manager);
/**
* @brief This returns the loading state of the requested font (https://switchbrew.org/wiki/Shared_Database_services#GetLoadState)
*/
void GetLoadState(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response);
/**
* @brief This returns the size of the requested font (https://switchbrew.org/wiki/Shared_Database_services#GetSize)
*/
void GetSize(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response);
/**
* @brief This returns the offset in shared memory of the requested font (https://switchbrew.org/wiki/Shared_Database_services#GetSharedMemoryAddressOffset)
*/
void GetSharedMemoryAddressOffset(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response);
/**
* @brief This returns a handle to the whole font shared memory (https://switchbrew.org/wiki/Shared_Database_services#GetSharedMemoryNativeHandle)
*/
void GetSharedMemoryNativeHandle(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response);
};
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,4 @@
#### Skyline FOSS Shared Fonts: (Credit to [FearlessTobi/yuzu_system_archives](https://github.com/FearlessTobi/yuzu_system_archives) for font choice)
* [FontStandard](FontStandard.ttf.h), [FontKorean](FontKorean.ttf.h), [FontChineseSimplified](FontChineseSimplified.ttf.h) and [FontChineseTraditional](FontChineseTraditional.ttf.h) are using [Open Sans Regular(https://fonts.google.com/specimen/Open+Sans), which is licensed under (Apache 2.0)[https://www.apache.org/licenses/LICENSE-2.0]
* [FontNintendoExtended](FontNintendoExtended.ttf.h) is using [Roboto](https://fonts.google.com/specimen/Roboto), which is licensed under (Apache 2.0)[https://www.apache.org/licenses/LICENSE-2.0]
* [FontExtendedChineseSimplified](FontExtendedChineseSimplified.ttf.h) is using [Source Sans Pro](https://fonts.google.com/specimen/Source+Sans+Pro), which is licensed under (Open Font License)[https://scripts.sil.org/cms/scripts/page.php?site_id=nrsi&id=OFL]

View File

@ -15,6 +15,7 @@
#include "fssrv/IFileSystemProxy.h"
#include "services/nvdrv/INvDrvServices.h"
#include "visrv/IManagerRootService.h"
#include "pl/IPlatformServiceManager.h"
#include "serviceman.h"
namespace skyline::service {
@ -66,6 +67,9 @@ namespace skyline::service {
case Service::visrv_IManagerRootService:
serviceObj = std::make_shared<visrv::IManagerRootService>(state, *this);
break;
case Service::pl_IPlatformServiceManager:
serviceObj = std::make_shared<pl::IPlatformServiceManager>(state, *this);
break;
default:
throw exception("CreateService called on missing object, type: {}", serviceType);
}

View File

@ -626,4 +626,92 @@ Exhibit B - "Incompatible With Secondary Licenses" Notice\n
This Source Code Form is "Incompatible With Secondary Licenses", as
defined by the Mozilla Public License, v. 2.0.
</string>
<string name="sil_open_font_license">
-----------------------------------------------------------\n
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007\n
-----------------------------------------------------------\n
\n
PREAMBLE\n
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.\n
\n
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.\n
\n
DEFINITIONS\n
"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.\n
\n
"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).\n
\n
"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).\n
\n
"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.\n
\n
"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.\n
\n
PERMISSION &amp; CONDITIONS\n
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:\n
\n
1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.
\n
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.\n
\n
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.\n
\n
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.\n
\n
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.\n
\n
TERMINATION\n
This license becomes null and void if any of the above conditions are
not met.\n
\n
DISCLAIMER\n
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.
</string>
</resources>

View File

@ -59,6 +59,12 @@
<string name="ktstd_description">We use Kotlin Standard Library for accessing convenience functions in Kotlin (Apache License 2.0)</string>
<string name="mtico">Material Design Icons</string>
<string name="mtico_description">We use Material Design Icons to have consistent iconography throughout the application (Apache License 2.0)</string>
<string name="open_sans">Open Sans</string>
<string name="open_sans_description">We use Open Sans as our FOSS shared font replacement for Latin, Korean and Chinese (Apache License 2.0)</string>
<string name="roboto">Roboto</string>
<string name="roboto_description">We use Roboto as our FOSS shared font replacement for Nintendo\'s extended character set (Apache License 2.0)</string>
<string name="source_sans_pro">Source Sans Pro</string>
<string name="source_sans_pro_description">We use Source Sans Pro as our FOSS shared font replacement for Extended Chinese (SIL Open Font License 1.1)</string>
<string name="perf_stats">Show Performance Statistics</string>
<string name="perf_stats_desc_off">Performance Statistics will not be shown</string>
<string name="perf_stats_desc_on">Performance Statistics will be shown in the top-left corner</string>

View File

@ -127,5 +127,20 @@
libraryUrl="https://material.io/resources/icons"
app:summary="@string/mtico_description"
app:title="@string/mtico" />
<emu.skyline.preference.LicensePreference
libraryLicense="@string/apache2_license"
libraryUrl="https://fonts.google.com/specimen/Open+Sans"
app:summary="@string/open_sans_description"
app:title="@string/open_sans" />
<emu.skyline.preference.LicensePreference
libraryLicense="@string/apache2_license"
libraryUrl="https://fonts.google.com/specimen/Roboto"
app:summary="@string/roboto_description"
app:title="@string/roboto" />
<emu.skyline.preference.LicensePreference
libraryLicense="@string/sil_open_font_license"
libraryUrl="https://fonts.google.com/specimen/Source+Sans+Pro"
app:summary="@string/source_sans_pro_description"
app:title="@string/source_sans_pro" />
</PreferenceCategory>
</androidx.preference.PreferenceScreen>