mirror of
https://github.com/koreader/koreader.git
synced 2025-12-13 20:36:53 +01:00
cre: add Word Gap setting to bottom config panel (#4026)
Maps to crengine's Space Condensing feature (named Word Gap as a similar feature is named for PDF)
This commit is contained in:
@@ -150,6 +150,10 @@ function ReaderFont:onReadSettings(config)
|
|||||||
or G_reader_settings:readSetting("copt_font_hinting") or 2 -- default in cre.cpp
|
or G_reader_settings:readSetting("copt_font_hinting") or 2 -- default in cre.cpp
|
||||||
self.ui.document:setFontHinting(self.font_hinting)
|
self.ui.document:setFontHinting(self.font_hinting)
|
||||||
|
|
||||||
|
self.space_condensing = config:readSetting("space_condensing")
|
||||||
|
or G_reader_settings:readSetting("copt_space_condensing") or 75
|
||||||
|
self.ui.document:setSpaceCondensing(self.space_condensing)
|
||||||
|
|
||||||
self.line_space_percent = config:readSetting("line_space_percent")
|
self.line_space_percent = config:readSetting("line_space_percent")
|
||||||
or G_reader_settings:readSetting("copt_line_spacing")
|
or G_reader_settings:readSetting("copt_line_spacing")
|
||||||
or DCREREADER_CONFIG_LINE_SPACE_PERCENT_MEDIUM
|
or DCREREADER_CONFIG_LINE_SPACE_PERCENT_MEDIUM
|
||||||
@@ -250,6 +254,13 @@ function ReaderFont:onSetFontHinting(mode)
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function ReaderFont:onSetSpaceCondensing(space)
|
||||||
|
self.space_condensing = space
|
||||||
|
self.ui.document:setSpaceCondensing(space)
|
||||||
|
self.ui:handleEvent(Event:new("UpdatePos"))
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
function ReaderFont:onSetFontGamma(gamma)
|
function ReaderFont:onSetFontGamma(gamma)
|
||||||
self.gamma_index = gamma
|
self.gamma_index = gamma
|
||||||
self.ui.document:setGammaIndex(self.gamma_index)
|
self.ui.document:setGammaIndex(self.gamma_index)
|
||||||
@@ -268,6 +279,7 @@ function ReaderFont:onSaveSettings()
|
|||||||
self.ui.doc_settings:saveSetting("font_size", self.font_size)
|
self.ui.doc_settings:saveSetting("font_size", self.font_size)
|
||||||
self.ui.doc_settings:saveSetting("font_embolden", self.font_embolden)
|
self.ui.doc_settings:saveSetting("font_embolden", self.font_embolden)
|
||||||
self.ui.doc_settings:saveSetting("font_hinting", self.font_hinting)
|
self.ui.doc_settings:saveSetting("font_hinting", self.font_hinting)
|
||||||
|
self.ui.doc_settings:saveSetting("space_condensing", self.space_condensing)
|
||||||
self.ui.doc_settings:saveSetting("line_space_percent", self.line_space_percent)
|
self.ui.doc_settings:saveSetting("line_space_percent", self.line_space_percent)
|
||||||
self.ui.doc_settings:saveSetting("gamma_index", self.gamma_index)
|
self.ui.doc_settings:saveSetting("gamma_index", self.gamma_index)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -132,13 +132,6 @@ function CreDocument:init()
|
|||||||
G_reader_settings:readSetting("cre_header_status_font_size"))
|
G_reader_settings:readSetting("cre_header_status_font_size"))
|
||||||
end
|
end
|
||||||
|
|
||||||
-- min space condensing percent (how much we can decrease a space width to
|
|
||||||
-- make text fit on a line) default is 50%
|
|
||||||
if G_reader_settings:readSetting("cre_min_space_condensing_percent") then
|
|
||||||
self._document:setIntProperty("crengine.style.space.condensing.percent",
|
|
||||||
G_reader_settings:readSetting("cre_min_space_condensing_percent"))
|
|
||||||
end
|
|
||||||
|
|
||||||
-- set fallback font face
|
-- set fallback font face
|
||||||
self._document:setStringProperty("crengine.font.fallback.face",
|
self._document:setStringProperty("crengine.font.fallback.face",
|
||||||
G_reader_settings:readSetting("fallback_font") or self.fallback_font)
|
G_reader_settings:readSetting("fallback_font") or self.fallback_font)
|
||||||
@@ -527,6 +520,13 @@ function CreDocument:setFontHinting(mode)
|
|||||||
self._document:setIntProperty("font.hinting.mode", mode)
|
self._document:setIntProperty("font.hinting.mode", mode)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- min space condensing percent (how much we can decrease a space width to
|
||||||
|
-- make text fit on a line) 25...100%
|
||||||
|
function CreDocument:setSpaceCondensing(value)
|
||||||
|
logger.dbg("CreDocument: set space condensing", value)
|
||||||
|
self._document:setIntProperty("crengine.style.space.condensing.percent", value)
|
||||||
|
end
|
||||||
|
|
||||||
function CreDocument:setStyleSheet(new_css_file, appended_css_content )
|
function CreDocument:setStyleSheet(new_css_file, appended_css_content )
|
||||||
logger.dbg("CreDocument: set style sheet:",
|
logger.dbg("CreDocument: set style sheet:",
|
||||||
new_css_file and new_css_file or "no file",
|
new_css_file and new_css_file or "no file",
|
||||||
|
|||||||
@@ -155,6 +155,19 @@ local CreOptions = {
|
|||||||
args = {0, 1, 2},
|
args = {0, 1, 2},
|
||||||
event = "SetFontHinting",
|
event = "SetFontHinting",
|
||||||
name_text_hold_callback = optionsutil.showValues,
|
name_text_hold_callback = optionsutil.showValues,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name = "space_condensing",
|
||||||
|
name_text = S.WORD_GAP,
|
||||||
|
toggle = {S.SMALL, S.MEDIUM, S.LARGE},
|
||||||
|
values = {50, 75, 100},
|
||||||
|
default_value = 75,
|
||||||
|
args = {50, 75, 100},
|
||||||
|
event = "SetSpaceCondensing",
|
||||||
|
name_text_hold_callback = optionsutil.showValues,
|
||||||
|
-- used by showValues
|
||||||
|
name_text_suffix = "%",
|
||||||
|
name_text_true_values = true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -47,12 +47,13 @@ function ToggleSwitch:init()
|
|||||||
-- Item count per row
|
-- Item count per row
|
||||||
self.n_pos = math.ceil(#self.toggle / self.row_count)
|
self.n_pos = math.ceil(#self.toggle / self.row_count)
|
||||||
self.position = nil
|
self.position = nil
|
||||||
|
local border_size = Size.border.thin
|
||||||
|
|
||||||
self.toggle_frame = FrameContainer:new{
|
self.toggle_frame = FrameContainer:new{
|
||||||
background = Blitbuffer.COLOR_WHITE,
|
background = Blitbuffer.COLOR_WHITE,
|
||||||
color = Blitbuffer.COLOR_GREY,
|
color = Blitbuffer.COLOR_GREY,
|
||||||
radius = Size.radius.window,
|
radius = Size.radius.window,
|
||||||
bordersize = Size.border.thin,
|
bordersize = border_size,
|
||||||
padding = Size.padding.small,
|
padding = Size.padding.small,
|
||||||
dim = not self.enabled,
|
dim = not self.enabled,
|
||||||
}
|
}
|
||||||
@@ -63,7 +64,7 @@ function ToggleSwitch:init()
|
|||||||
end
|
end
|
||||||
|
|
||||||
local center_dimen = Geom:new{
|
local center_dimen = Geom:new{
|
||||||
w = self.width / self.n_pos,
|
w = (self.width - border_size*(2*self.n_pos-2)) / self.n_pos,
|
||||||
h = self.height / self.row_count,
|
h = self.height / self.row_count,
|
||||||
}
|
}
|
||||||
local button_width = math.floor(self.width / self.n_pos)
|
local button_width = math.floor(self.width / self.n_pos)
|
||||||
@@ -88,7 +89,7 @@ function ToggleSwitch:init()
|
|||||||
color = Blitbuffer.COLOR_GREY,
|
color = Blitbuffer.COLOR_GREY,
|
||||||
margin = 0,
|
margin = 0,
|
||||||
radius = Size.radius.window,
|
radius = Size.radius.window,
|
||||||
bordersize = Size.border.thin,
|
bordersize = border_size,
|
||||||
padding = 0,
|
padding = 0,
|
||||||
content,
|
content,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -146,7 +146,7 @@ describe("Readerfooter module", function()
|
|||||||
local timeinfo = footer.textGeneratorMap.time()
|
local timeinfo = footer.textGeneratorMap.time()
|
||||||
local page_count = readerui.document:getPageCount()
|
local page_count = readerui.document:getPageCount()
|
||||||
-- stats has not been initialized here, so we get na TB and TC
|
-- stats has not been initialized here, so we get na TB and TC
|
||||||
assert.are.same('1 / '..page_count..' | '..timeinfo..' | => 0 | B:0% | R:1% | TB: na | TC: na',
|
assert.are.same('1 / '..page_count..' | '..timeinfo..' | => 0 | B:0% | R:0% | TB: na | TC: na',
|
||||||
footer.footer_text.text)
|
footer.footer_text.text)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@@ -295,8 +295,8 @@ describe("Readerfooter module", function()
|
|||||||
assert.are.same(365, footer.text_width)
|
assert.are.same(365, footer.text_width)
|
||||||
|
|
||||||
footer:onPageUpdate(100)
|
footer:onPageUpdate(100)
|
||||||
assert.are.same(183, footer.progress_bar.width)
|
assert.are.same(191, footer.progress_bar.width)
|
||||||
assert.are.same(397, footer.text_width)
|
assert.are.same(389, footer.text_width)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it("should support chapter markers", function()
|
it("should support chapter markers", function()
|
||||||
@@ -545,7 +545,7 @@ describe("Readerfooter module", function()
|
|||||||
assert.is.same(0, footer.text_width)
|
assert.is.same(0, footer.text_width)
|
||||||
|
|
||||||
tapFooterMenu(fake_menu, "Progress percentage")
|
tapFooterMenu(fake_menu, "Progress percentage")
|
||||||
assert.are.same('R:1%', footer.footer_text.text)
|
assert.are.same('R:0%', footer.footer_text.text)
|
||||||
assert.is.same(false, footer.has_no_mode)
|
assert.is.same(false, footer.has_no_mode)
|
||||||
assert.is.same(footer.footer_text:getSize().w + footer.text_left_margin,
|
assert.is.same(footer.footer_text:getSize().w + footer.text_left_margin,
|
||||||
footer.text_width)
|
footer.text_width)
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ describe("ReaderLink module", function()
|
|||||||
document = DocumentRegistry:openDocument(sample_epub),
|
document = DocumentRegistry:openDocument(sample_epub),
|
||||||
}
|
}
|
||||||
readerui.rolling:onGotoPage(4)
|
readerui.rolling:onGotoPage(4)
|
||||||
readerui.link:onTap(nil, {pos = {x = 336, y = 668}})
|
readerui.link:onTap(nil, {pos = {x = 306, y = 710}})
|
||||||
assert.is.same(36, readerui.rolling.current_page)
|
assert.is.same(37, readerui.rolling.current_page)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it("should jump to links in pdf page mode", function()
|
it("should jump to links in pdf page mode", function()
|
||||||
@@ -54,8 +54,8 @@ describe("ReaderLink module", function()
|
|||||||
document = DocumentRegistry:openDocument(sample_epub),
|
document = DocumentRegistry:openDocument(sample_epub),
|
||||||
}
|
}
|
||||||
readerui.rolling:onGotoPage(4)
|
readerui.rolling:onGotoPage(4)
|
||||||
readerui.link:onTap(nil, {pos = {x = 336, y = 668}})
|
readerui.link:onTap(nil, {pos = {x = 306, y = 710}})
|
||||||
assert.is.same(36, readerui.rolling.current_page)
|
assert.is.same(37, readerui.rolling.current_page)
|
||||||
readerui.link:onGoBackLink()
|
readerui.link:onGoBackLink()
|
||||||
assert.is.same(4, readerui.rolling.current_page)
|
assert.is.same(4, readerui.rolling.current_page)
|
||||||
end)
|
end)
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ describe("Readertoc module", function()
|
|||||||
end)
|
end)
|
||||||
it("should get page left of chapter", function()
|
it("should get page left of chapter", function()
|
||||||
assert.truthy(toc:getChapterPagesLeft(10, 0) > 10)
|
assert.truthy(toc:getChapterPagesLeft(10, 0) > 10)
|
||||||
assert.truthy(toc:getChapterPagesLeft(100, 0) > 10)
|
assert.truthy(toc:getChapterPagesLeft(101, 0) > 10)
|
||||||
assert.are.same(nil, toc:getChapterPagesLeft(200, 0))
|
assert.are.same(nil, toc:getChapterPagesLeft(200, 0))
|
||||||
end)
|
end)
|
||||||
it("should get page done of chapter", function()
|
it("should get page done of chapter", function()
|
||||||
|
|||||||
Reference in New Issue
Block a user