2
0
mirror of https://github.com/koreader/koreader synced 2024-11-18 03:25:46 +00:00
koreader/spec/unit/textboxwidget_spec.lua
poire-z e699a1ee22 TextBoxWidget: use xtext for text shaping
Alternative code to size, split lines and draw text with
the help of the xtext Lua C module.
Enabled by default (can be disabled via an added menu
item in "Developer options").

New properties can be specified by calling widgets, only
used when xtext is used:
- lang: use specified language instead of the UI language
- para_direction_rtl: true/false to override the default
  direction for the UI language
- auto_para_direction: detect direction of each paragraph
  in text
- alignment_strict: prevent the inversion of the specified
  alignment= that is done when a paragraph direction is
  set or detected as RTL.

Also: fix possible memory leak (present even when not using xtext)
by calling :free() in onCloseWidget() like it's done in ImageWidget.
2019-11-16 18:41:14 +01:00

58 lines
1.8 KiB
Lua

describe("TextBoxWidget module", function()
local TextBoxWidget, Font
setup(function()
require("commonrequire")
Font = require("ui/font")
TextBoxWidget = require("ui/widget/textboxwidget")
end)
it("should select the correct word on HoldWord event", function()
local tw = TextBoxWidget:new{
dimen = {x = 0, y = 0},
face = Font:getFace("cfont", 25),
text = 'YOOOOOOOOOOOOOOOO\nFoo.\nBar.\nFoo welcomes Bar into the fun.',
}
local pos={x=110,y=4}
tw:onHoldStartText(nil, {pos=pos})
tw:onHoldReleaseText(function(w)
assert.is.same(w, 'YOOOOOOOOOOOOOOOO')
end, {pos=pos})
pos={x=0,y=50}
tw:onHoldStartText(nil, {pos=pos})
tw:onHoldReleaseText(function(w)
assert.is.same(w, 'Foo')
end, {pos=pos})
pos={x=20,y=80}
tw:onHoldStartText(nil, {pos=pos})
tw:onHoldReleaseText(function(w)
assert.is.same(w, 'Bar')
end, {pos=pos})
tw:onHoldStartText(nil, {pos={x=50, y=100}})
tw:onHoldReleaseText(function(w)
assert.is.same(w, 'welcomes Bar into')
end, {pos={x=240, y=100}})
tw:onHoldStartText(nil, {pos={x=20, y=80}})
tw:onHoldReleaseText(function(w)
assert.is.same(w, 'Bar.\nFoo welcomes Bar into')
end, {pos={x=240, y=100}})
--[[
-- No more used, not implemented when use_xtext=true
tw:onHoldWord(function(w)
assert.is.same(w, 'YOOOOOOOOOOOOOOOO')
end, {pos={x=110,y=4}})
tw:onHoldWord(function(w)
assert.is.same(w, 'Foo')
end, {pos={x=0,y=50}})
tw:onHoldWord(function(w)
assert.is.same(w, 'Bar')
end, {pos={x=20,y=80}})
]]--
end)
end)