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
Font menu: add symbols for default and fallback fonts #3941
Merged
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e6285f7
Font menu: add symbols for default and fallback fonts
poire-z 007f753
fix luacheck
poire-z b2c5d8e
fix some spaces
poire-z 7b81b38
use unicode 'replace character' symbol for fallback font
poire-z 297220c
update Hold message
poire-z 5c432e9
"an HTML document"
poire-z 4906996
bump crengine for: Fix updating fallback font
poire-z File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
local CenterContainer = require("ui/widget/container/centercontainer") | ||
local ConfirmBox = require("ui/widget/confirmbox") | ||
local Device = require("device") | ||
local Event = require("ui/event") | ||
local Input = Device.input | ||
|
@@ -51,19 +52,46 @@ function ReaderFont:init() | |
local face_list = cre.getFontFaces() | ||
for k,v in ipairs(face_list) do | ||
table.insert(self.face_table, { | ||
text = v, | ||
text_func = function() | ||
-- defaults are hardcoded in credocument.lua | ||
local default_font = G_reader_settings:readSetting("cre_font") or self.ui.document.default_font | ||
local fallback_font = G_reader_settings:readSetting("fallback_font") or self.ui.document.fallback_font | ||
local text = v | ||
if v == default_font then | ||
text = text .. " ★" | ||
end | ||
if v == fallback_font then | ||
text = text.." ♻" | ||
end | ||
return text | ||
end, | ||
callback = function() | ||
self:setFont(v) | ||
end, | ||
hold_callback = function() | ||
self:makeDefault(v) | ||
hold_may_update_menu = true, | ||
hold_callback = function(refresh_menu_func) | ||
self:makeDefault(v, refresh_menu_func) | ||
end, | ||
checked_func = function() | ||
return v == self.font_face | ||
end | ||
}) | ||
face_list[k] = {text = v} | ||
end | ||
if self:hasFontsTestSample() then | ||
self.face_table[#self.face_table].separator = true | ||
table.insert(self.face_table, { | ||
text = _("Generate fonts test html document"), | ||
callback = function() | ||
UIManager:show(ConfirmBox:new{ | ||
text = _("Would you like to generate a html document showing some sample text rendered with each available font?"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. an HTML document |
||
ok_callback = function() | ||
self:buildFontsTestDocument() | ||
end | ||
}) | ||
end | ||
}) | ||
end | ||
self.ui.menu:registerToMainMenu(self) | ||
end | ||
|
||
|
@@ -100,10 +128,12 @@ end | |
|
||
function ReaderFont:onReadSettings(config) | ||
self.font_face = config:readSetting("font_face") | ||
or G_reader_settings:readSetting("cre_font") | ||
or self.ui.document.default_font | ||
self.ui.document:setFontFace(self.font_face) | ||
|
||
self.header_font_face = config:readSetting("header_font_face") | ||
or G_reader_settings:readSetting("header_font") | ||
or self.ui.document.header_font | ||
self.ui.document:setHeaderFont(self.header_font_face) | ||
|
||
|
@@ -256,17 +286,22 @@ function ReaderFont:setFont(face) | |
end | ||
end | ||
|
||
function ReaderFont:makeDefault(face) | ||
function ReaderFont:makeDefault(face, refresh_menu_func) | ||
if face then | ||
UIManager:show(MultiConfirmBox:new{ | ||
text = T( _("Set %1 as fallback font? Characters not found in the active font are shown in the fallback font instead."), face), | ||
choice1_text = _("Default"), | ||
choice1_callback = function() | ||
G_reader_settings:saveSetting("cre_font", face) | ||
if refresh_menu_func then refresh_menu_func() end | ||
end, | ||
choice2_text = _("Fallback"), | ||
choice2_callback = function() | ||
G_reader_settings:saveSetting("fallback_font", face) | ||
if self.ui.document:setFallbackFontFace(face) then | ||
G_reader_settings:saveSetting("fallback_font", face) | ||
self.ui:handleEvent(Event:new("UpdatePos")) | ||
end | ||
if refresh_menu_func then refresh_menu_func() end | ||
end, | ||
}) | ||
end | ||
|
@@ -302,4 +337,63 @@ function ReaderFont:onAdjustPinch(ges) | |
return true | ||
end | ||
|
||
function ReaderFont:hasFontsTestSample() | ||
local font_test_sample = require("datastorage"):getSettingsDir() .. "/fonts-test-sample.html" | ||
local lfs = require("libs/libkoreader-lfs") | ||
return lfs.attributes(font_test_sample, "mode") == "file" | ||
end | ||
|
||
function ReaderFont:buildFontsTestDocument() | ||
local font_test_sample = require("datastorage"):getSettingsDir() .. "/fonts-test-sample.html" | ||
local f = io.open(font_test_sample, "r") | ||
if not f then return nil end | ||
local html_sample = f:read("*all") | ||
f:close() | ||
local dir = G_reader_settings:readSetting("home_dir") | ||
if not dir then dir = require("apps/filemanager/filemanagerutil").getDefaultDir() end | ||
if not dir then dir = "." end | ||
local fonts_test_path = dir .. "/fonts-test-all.html" | ||
f = io.open(fonts_test_path, "w") | ||
-- Using <section><title>...</title></section> allows for a TOC to be built | ||
f:write(string.format([[ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<html> | ||
<head> | ||
<title>%s</title> | ||
</head> | ||
<body> | ||
<section id="list"><title>%s</title></section> | ||
]], _("Available fonts test document"), _("AVAILABLE FONTS"))) | ||
local face_list = cre.getFontFaces() | ||
f:write("<div style='margin: 2em'>\n") | ||
for _, font_name in ipairs(face_list) do | ||
local font_id = font_name:gsub(" ", "_"):gsub("'", "_") | ||
f:write(string.format(" <div><a href='#%s'>%s</a></div>\n", font_id, font_name)) | ||
end | ||
f:write("</div>\n\n") | ||
for _, font_name in ipairs(face_list) do | ||
local font_id = font_name:gsub(" ", "_"):gsub("'", "_") | ||
f:write(string.format("<section id='%s'><title>%s</title></section>\n", font_id, font_name)) | ||
f:write(string.format("<div style='font-family: %s'>\n", font_name)) | ||
f:write(html_sample) | ||
f:write("\n</div>\n\n") | ||
end | ||
f:write("</body></html>\n") | ||
f:close() | ||
UIManager:show(ConfirmBox:new{ | ||
text = T(_("Document created as:\n%1\n\nWould you like to read it now?"), fonts_test_path), | ||
ok_callback = function() | ||
-- close current ReaderUI in 1 sec, and create a new one | ||
UIManager:scheduleIn(1.0, function() | ||
local ReaderUI = require("apps/reader/readerui") | ||
local reader = ReaderUI:_getRunningInstance() | ||
if reader then | ||
reader:onClose() | ||
end | ||
ReaderUI:showReader(fonts_test_path) | ||
end) | ||
end, | ||
}) | ||
end | ||
|
||
return ReaderFont |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Recycling? :-P
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not much choice with what's available in Noto fonts (including the updated ones, seen no other symbols than the ones I'm used to).
test_unichars.html.txt : sample file where I do my icon shopping.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a (couple of) relatively small NotoSymbols fonts that we could pull if you fancy something in there... ;).
Getting the relevant menu entry to use them over the default UI font might get tricky, though...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we should be fine with what we have.
Btw, the greek glyphs have been corrected in your updated Noto Sans CJK, and they have also been included in the main Noto Sans, so good idea to update them :)