mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Merge pull request #312 from chrox/master
rescale font size when fallbacks to fallback fonts
This commit is contained in:
@@ -3,12 +3,12 @@ require "dbg" -- for DEBUG()
|
||||
Font = {
|
||||
fontmap = {
|
||||
-- default font for menu contents
|
||||
cfont = "droid/DroidSansFallback.ttf",
|
||||
cfont = "freefont/FreeSerif.ttf",
|
||||
-- default font for title
|
||||
--tfont = "NimbusSanL-BoldItal.cff",
|
||||
tfont = "droid/DroidSansFallback.ttf",
|
||||
tfont = "freefont/FreeSerif.ttf",
|
||||
-- default font for footer
|
||||
ffont = "droid/DroidSansFallback.ttf",
|
||||
ffont = "freefont/FreeSerif.ttf",
|
||||
|
||||
-- default font for reading position info
|
||||
rifont = "droid/DroidSans.ttf",
|
||||
@@ -32,9 +32,9 @@ Font = {
|
||||
infofont = "droid/DroidSans.ttf",
|
||||
},
|
||||
fallbacks = {
|
||||
[1] = "freefont/FreeSans.ttf",
|
||||
[2] = "droid/DroidSans.ttf",
|
||||
[3] = "droid/DroidSansFallback.ttf",
|
||||
[1] = "droid/DroidSansFallback.ttf",
|
||||
[2] = "freefont/FreeSans.ttf",
|
||||
[3] = "droid/DroidSans.ttf",
|
||||
},
|
||||
|
||||
fontdir = os.getenv("FONTDIR") or "./fonts",
|
||||
@@ -50,7 +50,7 @@ function Font:getFace(font, size)
|
||||
font = self.cfont
|
||||
end
|
||||
|
||||
local size = math.floor(scaleByDPI(size))
|
||||
local size = scaleByDPI(size)
|
||||
|
||||
local face = self.faces[font..size]
|
||||
-- build face if not found
|
||||
|
||||
@@ -68,10 +68,11 @@ function getGlyph(face, charcode, bgcolor, fgcolor)
|
||||
local rendered_glyph = face.ftface:renderGlyph(charcode, bgcolor, fgcolor)
|
||||
if face.ftface:checkGlyph(charcode) == 0 then
|
||||
for index, font in pairs(Font.fallbacks) do
|
||||
DEBUG("fallback to font", font)
|
||||
local fb_face = Font:getFace(font, face.size)
|
||||
-- rescale face size by DPI since it will be scaled in getFace again
|
||||
local fb_face = Font:getFace(font, rescaleByDPI(face.size))
|
||||
if fb_face.ftface:checkGlyph(charcode) ~= 0 then
|
||||
rendered_glyph = fb_face.ftface:renderGlyph(charcode, bgcolor, fgcolor)
|
||||
DEBUG("fallback to font", font)
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
@@ -134,11 +134,20 @@ function Screen:scaleByDPI(px)
|
||||
return math.floor(px * self:getDPI()/167)
|
||||
end
|
||||
|
||||
function Screen:rescaleByDPI(px)
|
||||
return math.ceil(px * 167/self:getDPI())
|
||||
end
|
||||
|
||||
-- make a shortcut to Screen:scaleByDPI
|
||||
function scaleByDPI(px)
|
||||
return Screen:scaleByDPI(px)
|
||||
end
|
||||
|
||||
-- make a shortcut to Screen:rescaleByDPI
|
||||
function rescaleByDPI(px)
|
||||
return Screen:rescaleByDPI(px)
|
||||
end
|
||||
|
||||
function Screen:getPitch()
|
||||
return self.fb:getPitch()
|
||||
end
|
||||
|
||||
BIN
resources/fonts/freefont/FreeSerif.ttf
Normal file
BIN
resources/fonts/freefont/FreeSerif.ttf
Normal file
Binary file not shown.
Reference in New Issue
Block a user