From 53234fcdc1e7beab5603ebebb12c30dc5e6cbc9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Fern=C3=A1ndez?= <975883+pazos@users.noreply.github.com> Date: Mon, 19 Apr 2021 09:04:31 +0200 Subject: [PATCH] add hasSystemFonts device property (#7535) Add system + user paths to the ReMarkable (has normal linux paths) --- frontend/device/android/device.lua | 1 + frontend/device/generic/device.lua | 3 +++ frontend/device/pocketbook/device.lua | 1 + frontend/device/remarkable/device.lua | 1 + frontend/device/sdl/device.lua | 1 + frontend/document/canvascontext.lua | 1 + frontend/fontlist.lua | 6 +----- frontend/ui/elements/font_settings.lua | 14 +++++++++++--- platform/remarkable/koreader.sh | 3 --- 9 files changed, 20 insertions(+), 11 deletions(-) diff --git a/frontend/device/android/device.lua b/frontend/device/android/device.lua index 82f62c377..0d4c9f66d 100644 --- a/frontend/device/android/device.lua +++ b/frontend/device/android/device.lua @@ -89,6 +89,7 @@ local Device = Generic:new{ hasClipboard = yes, hasOTAUpdates = canUpdateApk, hasFastWifiStatusQuery = yes, + hasSystemFonts = yes, canOpenLink = yes, openLink = function(self, link) if not link or type(link) ~= "string" then return end diff --git a/frontend/device/generic/device.lua b/frontend/device/generic/device.lua index 3da2a9137..477de69b9 100644 --- a/frontend/device/generic/device.lua +++ b/frontend/device/generic/device.lua @@ -106,6 +106,9 @@ local Device = { -- (c.f., https://github.com/koreader/koreader/pull/5211#issuecomment-521304139) hasFastWifiStatusQuery = no, + -- set to yes on devices with system fonts + hasSystemFonts = no, + canOpenLink = no, openLink = no, canExternalDictLookup = no, diff --git a/frontend/device/pocketbook/device.lua b/frontend/device/pocketbook/device.lua index 4b2d276bc..b20f4ecc2 100644 --- a/frontend/device/pocketbook/device.lua +++ b/frontend/device/pocketbook/device.lua @@ -28,6 +28,7 @@ local PocketBook = Generic:new{ isTouchDevice = yes, hasKeys = yes, hasFrontlight = yes, + hasSystemFonts = yes, canSuspend = no, canReboot = yes, canPowerOff = yes, diff --git a/frontend/device/remarkable/device.lua b/frontend/device/remarkable/device.lua index 473274242..965b76fe6 100644 --- a/frontend/device/remarkable/device.lua +++ b/frontend/device/remarkable/device.lua @@ -38,6 +38,7 @@ local Remarkable = Generic:new{ canPowerOff = yes, isTouchDevice = yes, hasFrontlight = no, + hasSystemFonts = yes, display_dpi = 226, -- Despite the SoC supporting it, it's finicky in practice (#6772) canHWInvert = no, diff --git a/frontend/device/sdl/device.lua b/frontend/device/sdl/device.lua index 43581056a..06862aeff 100644 --- a/frontend/device/sdl/device.lua +++ b/frontend/device/sdl/device.lua @@ -64,6 +64,7 @@ local Device = Generic:new{ needsScreenRefreshAfterResume = no, hasColorScreen = yes, hasEinkScreen = no, + hasSystemFonts = yes, canSuspend = no, startTextInput = SDL.startTextInput, stopTextInput = SDL.stopTextInput, diff --git a/frontend/document/canvascontext.lua b/frontend/document/canvascontext.lua index 3dc53439b..5de8d452b 100644 --- a/frontend/document/canvascontext.lua +++ b/frontend/document/canvascontext.lua @@ -42,6 +42,7 @@ function CanvasContext:init(device) self.isKindle = device.isKindle self.isPocketBook = device.isPocketBook self.should_restrict_JIT = device.should_restrict_JIT + self.hasSystemFonts = device.hasSystemFonts self:setColorRenderingEnabled(device.screen.isColorEnabled()) -- NOTE: Kobo's fb is BGR, not RGB. Handle the conversion in MuPDF if needed. diff --git a/frontend/fontlist.lua b/frontend/fontlist.lua index 30f95cbe0..c78aa8fca 100644 --- a/frontend/fontlist.lua +++ b/frontend/fontlist.lua @@ -94,11 +94,7 @@ local function isInFontsBlacklist(f) end local function getExternalFontDir() - if CanvasContext.isAndroid() or - CanvasContext.isDesktop() or - CanvasContext.isEmulator() or - CanvasContext.isPocketBook() - then + if CanvasContext.hasSystemFonts() then return require("frontend/ui/elements/font_settings"):getPath() else return os.getenv("EXT_FONT_DIR") diff --git a/frontend/ui/elements/font_settings.lua b/frontend/ui/elements/font_settings.lua index e3d4acf26..9b05b90ca 100644 --- a/frontend/ui/elements/font_settings.lua +++ b/frontend/ui/elements/font_settings.lua @@ -3,7 +3,10 @@ local logger = require("logger") local util = require("util") local _ = require("gettext") ---[[ Font settings for desktop linux, mac and android ]]-- +--[[ Font settings for systems with multiple font dirs ]]-- + +local LINUX_FONT_PATH = "share/fonts" +local MACOS_FONT_PATH = "Library/fonts" local function getDir(isUser) local home = Device.home_dir @@ -20,11 +23,16 @@ local function getDir(isUser) else return "/ebrmain/adobefonts;/ebrmain/fonts" end + elseif Device:isRemarkable() then + return isUser and string.format("%s/.local/%s", home, LINUX_FONT_PATH) + or string.format("/usr/%s", LINUX_FONT_PATH) elseif Device:isDesktop() or Device:isEmulator() then if jit.os == "OSX" then - return isUser and home .. "/Library/fonts" or "/Library/fonts" + return isUser and string.format("%s/%s", home, MACOS_FONT_PATH) + or string.format("/%s", MACOS_FONT_PATH) else - return isUser and home .. "/.local/share/fonts" or "/usr/share/fonts" + return isUser and string.format("%s/.local/%s", home, LINUX_FONT_PATH) + or string.format("/usr/%s", LINUX_FONT_PATH) end end end diff --git a/platform/remarkable/koreader.sh b/platform/remarkable/koreader.sh index f93d5bd8a..b75864181 100755 --- a/platform/remarkable/koreader.sh +++ b/platform/remarkable/koreader.sh @@ -75,9 +75,6 @@ export TESSDATA_PREFIX="data" # export dict directory export STARDICT_DATA_DIR="data/dict" -# export external font directory -export EXT_FONT_DIR="/usr/share/fonts/ttf;/usr/share/fonts/opentype" - # We'll want to ensure Portrait rotation to allow us to use faster blitting codepaths @ 8bpp, # so remember the current one before fbdepth does its thing. ORIG_FB_ROTA="$(./fbdepth -o)"