mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Add functions to change font face for all items in Font.fontmap
1. Excluded pgfont from Font.fontmap-items; it was used in helppage.lua to render footer and just duplicated ffont 2. Fixed typo: self.cfont > "cfont" in Font:getFace() 3. 3 small functions to change font face for any member of Font.fontmap
This commit is contained in:
121
font.lua
121
font.lua
@@ -1,37 +1,18 @@
|
||||
|
||||
Font = {
|
||||
fontmap = {
|
||||
-- default font for menu contents
|
||||
cfont = "droid/DroidSans.ttf",
|
||||
-- default font for title
|
||||
tfont = "droid/DroidSans.ttf",
|
||||
-- default font for footer
|
||||
ffont = "droid/DroidSans.ttf",
|
||||
|
||||
-- default font for reading position info
|
||||
rifont = "droid/DroidSans.ttf",
|
||||
|
||||
-- default font for pagination display
|
||||
pgfont = "droid/DroidSans.ttf",
|
||||
|
||||
-- selectmenu: font for item shortcut
|
||||
scfont = "droid/DroidSansMono.ttf",
|
||||
|
||||
-- help page: font for displaying keys
|
||||
hpkfont = "droid/DroidSansMono.ttf",
|
||||
-- font for displaying help messages
|
||||
hfont = "droid/DroidSans.ttf",
|
||||
|
||||
-- font for displaying input content
|
||||
-- we have to use mono here for better distance controlling
|
||||
infont = "droid/DroidSansMono.ttf",
|
||||
|
||||
-- font for info messages
|
||||
infofont = "droid/DroidSans.ttf",
|
||||
cfont = "droid/DroidSans.ttf", -- filemanager: for menu contents
|
||||
tfont = "droid/DroidSans.ttf", -- filemanager: for title
|
||||
ffont = "droid/DroidSans.ttf", -- filemanager: for footer
|
||||
infofont = "droid/DroidSans.ttf", -- info messages
|
||||
rifont = "droid/DroidSans.ttf", -- readers: for reading position info
|
||||
scfont = "droid/DroidSansMono.ttf", -- selectmenu: font for item shortcut
|
||||
hpkfont = "droid/DroidSansMono.ttf", -- help page: font for displaying keys
|
||||
hfont = "droid/DroidSans.ttf", -- help page: font for displaying help messages
|
||||
infont = "droid/DroidSansMono.ttf", -- inputbox: use mono for better distance controlling
|
||||
-- pgfont = "droid/DroidSans.ttf", -- was in use in heppage to render footer
|
||||
-- to be repalced by ffont
|
||||
},
|
||||
|
||||
fontdir = os.getenv("FONTDIR") or "./fonts",
|
||||
|
||||
-- face table
|
||||
faces = {},
|
||||
}
|
||||
@@ -40,7 +21,7 @@ Font = {
|
||||
function Font:getFace(font, size)
|
||||
if not font then
|
||||
-- default to content font
|
||||
font = self.cfont
|
||||
font = "cfont"
|
||||
end
|
||||
|
||||
local face = self.faces[font..size]
|
||||
@@ -89,3 +70,81 @@ function Font:update()
|
||||
self.faces = {}
|
||||
clearGlyphCache()
|
||||
end
|
||||
|
||||
-- NuPogodi, 05.09.12: added function to change fontface for ANY item in Font.fontmap
|
||||
-- choose the Fonts.fontmap-item that has to be changed
|
||||
function Font:chooseItemForFont(initial)
|
||||
local items_list = {}
|
||||
local item_no, item_found = 1, false
|
||||
local description -- additional info to display in menu
|
||||
-- define auxilary function
|
||||
function add_element(_index)
|
||||
if _index == "cfont" then description = "filemanager: menu contents"
|
||||
elseif _index == "tfont" then description = "filemanager: header title"
|
||||
elseif _index == "ffont" then description = "filemanager: footer"
|
||||
elseif _index == "rifont" then description = "readers: reading position info"
|
||||
elseif _index == "scfont" then description = "selectmenu: item shortcuts"
|
||||
elseif _index == "hpkfont" then description = "help page: hotkeys"
|
||||
elseif _index == "hfont" then description = "help page: description"
|
||||
elseif _index == "infont" then description = "inputbox: on-screen keyboard & user input"
|
||||
elseif _index == "infofont" then description = "info messages"
|
||||
else --[[ not included in Font.fontmap ]] description = "nothing; not used anymore"
|
||||
end
|
||||
-- then, search for number of initial item in the list Font.fontmap
|
||||
if not item_found then
|
||||
if _index ~= initial then
|
||||
item_no = item_no + 1
|
||||
else
|
||||
item_found = true
|
||||
end
|
||||
end
|
||||
table.insert(items_list, "[".._index.."] for "..description)
|
||||
end
|
||||
table.foreach(Font.fontmap, add_element)
|
||||
|
||||
-- goto menu to select the item which font should be changed
|
||||
local items_menu = SelectMenu:new{
|
||||
menu_title = "Select item to change",
|
||||
item_array = items_list,
|
||||
current_entry = item_no - 1,
|
||||
own_glyph = 2, -- use Font.fontmap-values to render 'items_menu'-items
|
||||
}
|
||||
local ok, item_font = items_menu:choose(0, fb.bb:getHeight())
|
||||
if not ok then
|
||||
return nil
|
||||
end
|
||||
-- and selecting from the font index included in [...] from the whole string
|
||||
return string.sub(string.match(item_font,"%b[]"), 2, -2)
|
||||
end
|
||||
|
||||
-- choose font for the 'item_font' in Fonts.fontmap
|
||||
function Font:chooseFontForItem(item_font)
|
||||
item_font = item_font or "cfont"
|
||||
local item_no = 0
|
||||
local face_list = Font:getFontList()
|
||||
while face_list[item_no] ~= Font.fontmap[item_font] and item_no < #face_list do
|
||||
item_no = item_no + 1
|
||||
end
|
||||
local fonts_menu = SelectMenu:new{
|
||||
menu_title = "Fonts Menu",
|
||||
item_array = face_list,
|
||||
current_entry = item_no - 1,
|
||||
own_glyph = 1, -- use the item from item_array to render 'fonts_menu'-items
|
||||
}
|
||||
local re, font = fonts_menu:choose(0, G_height)
|
||||
if re then
|
||||
Font.fontmap[item_font] = font
|
||||
Font:update()
|
||||
end
|
||||
end
|
||||
|
||||
-- to remain in menu with Font.fontmap-items until 'Back'
|
||||
function Font:chooseFonts()
|
||||
local item_font = "cfont" -- initial value
|
||||
while item_font ~= nil do
|
||||
item_font = self:chooseItemForFont(item_font)
|
||||
if item_font then
|
||||
self:chooseFontForItem(item_font)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user