mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Merge pull request #447 from thotypous/master
Avoid off-limits dictionary title and make font size adjustable
This commit is contained in:
@@ -97,6 +97,9 @@ DGESDETECT_DISABLE_DOUBLE_TAP = true
|
||||
-- change this to any numerical value if you want to antomatically save settings when turning pages
|
||||
DAUTO_SAVE_PAGING_COUNT = nil
|
||||
|
||||
-- dictionary font size
|
||||
DDICT_FONT_SIZE = 20
|
||||
|
||||
-- ####################################################################
|
||||
-- following features are not supported right now
|
||||
-- ####################################################################
|
||||
|
||||
@@ -143,7 +143,7 @@ function RenderText:sizeUtf8Text(x, width, face, text, kerning)
|
||||
return { x = pen_x, y_top = pen_y_top, y_bottom = pen_y_bottom}
|
||||
end
|
||||
|
||||
function RenderText:renderUtf8Text(buffer, x, y, face, text, kerning, bgcolor, fgcolor)
|
||||
function RenderText:renderUtf8Text(buffer, x, y, face, text, kerning, bgcolor, fgcolor, width)
|
||||
if not text then
|
||||
DEBUG("renderUtf8Text called without text");
|
||||
return 0
|
||||
@@ -153,9 +153,12 @@ function RenderText:renderUtf8Text(buffer, x, y, face, text, kerning, bgcolor, f
|
||||
-- see: http://freetype.org/freetype2/docs/glyphs/glyphs-4.html
|
||||
local pen_x = 0
|
||||
local prevcharcode = 0
|
||||
local buffer_width = buffer:getWidth()
|
||||
local text_width = buffer:getWidth() - x
|
||||
if width and width < text_width then
|
||||
text_width = width
|
||||
end
|
||||
for _, charcode, uchar in utf8Chars(text) do
|
||||
if pen_x < buffer_width then
|
||||
if pen_x < text_width then
|
||||
local glyph = self:getGlyph(face, charcode, bgcolor, fgcolor)
|
||||
if kerning and (prevcharcode ~= 0) then
|
||||
pen_x = pen_x + face.ftface:getKerning(prevcharcode, charcode)
|
||||
@@ -167,7 +170,7 @@ function RenderText:renderUtf8Text(buffer, x, y, face, text, kerning, bgcolor, f
|
||||
glyph.bb:getWidth(), glyph.bb:getHeight(), 1)
|
||||
pen_x = pen_x + glyph.ax
|
||||
prevcharcode = charcode
|
||||
end -- if pen_x < buffer_width
|
||||
end -- if pen_x < text_width
|
||||
end
|
||||
|
||||
return pen_x
|
||||
|
||||
@@ -31,7 +31,7 @@ local DictQuickLookup = InputContainer:new{
|
||||
dict_index = 1,
|
||||
title_face = Font:getFace("tfont", 22),
|
||||
word_face = Font:getFace("tfont", 22),
|
||||
content_face = Font:getFace("cfont", 20),
|
||||
content_face = Font:getFace("cfont", DDICT_FONT_SIZE),
|
||||
width = nil,
|
||||
height = nil,
|
||||
|
||||
@@ -85,7 +85,7 @@ function DictQuickLookup:update()
|
||||
TextWidget:new{
|
||||
text = self.dictionary,
|
||||
face = self.title_face,
|
||||
width = self.width,
|
||||
width = self.width - self.button_padding,
|
||||
}
|
||||
}
|
||||
-- lookup word
|
||||
|
||||
@@ -47,7 +47,7 @@ function TextWidget:paintTo(bb, x, y)
|
||||
--bb:blitFrom(self._bb, x, y, 0, 0, self._length, self._bb:getHeight())
|
||||
--@TODO Don't use kerning for monospaced fonts. (houqp)
|
||||
RenderText:renderUtf8Text(bb, x, y+self._height*0.7, self.face, self.text,
|
||||
true, self.bgcolor, self.fgcolor)
|
||||
true, self.bgcolor, self.fgcolor, self.width)
|
||||
end
|
||||
|
||||
function TextWidget:free()
|
||||
|
||||
Reference in New Issue
Block a user