TstAddBorder.sel

#!./Selene
-- When drawing a text on a low contrast display, it would be useful to add some
-- borders around glyphs in order to improve the readiness.
--
-- This is a tentative to do it by moving background the text.


Selene.UseDirectFB("--dfb:quiet,no-vt")
DirectFB.init( DirectFB.CooperativeConst('FULLSCREEN') );	-- Set display cooperative mode

local srf = SelSurface.create { caps=SelSurface.CapabilityConst('PRIMARY') } -- create a primary surface
local w,h = srf:GetSize()	-- Retrieve its size
srf:Clear( 0xff, 0xff, 0, 0xff )	-- berk


local txt = "This is a test"	-- Text to display
local font = SelFont.create("/usr/lib/ruby/gems/2.1.0/gems/rdoc-4.2.0/lib/rdoc/generator/template/darkfish/fonts/Lato-Regular.ttf", { height=40, width=35} )
local fontw, fonth = font:StringWidth(txt), font:GetHeight() -- get the size needed to display the text
local ssrf,err = srf:SubSurface( 50,50, fontw+4, fonth+4 )	-- Create a subsurface
if not ssrf then
	print('erreur :', err)
	return
end
ssrf:SetFont( font )	-- use our font
ssrf:SetColor( 0x00, 0x00, 0x00, 0xff)	-- background (black)
ssrf:DrawString(txt, 0,0)
ssrf:DrawString(txt, 4,4)

print "Hit 'enter' key to exit"
io.stdin:read'*l'	-- wait for enter

ssrf:SetColor( 0xff, 0x00, 0x00, 0xff)	-- Red
ssrf:DrawString(txt, 2,2)

print "Hit 'enter' key to exit"
io.stdin:read'*l'	-- wait for enter
generated by LDoc 1.4.6 Last updated 2022-09-05 22:24:51