1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
-- This demonstrates the different styles of line endings and joins,
-- and some dash patterns.
local Cairo = require "oocairo"
local DEMO_WD, DEMO_HT, LINE_WD, MARGIN = 120, 50, 35, 50
local IMG_WD, IMG_HT = 515, 250
local surface = Cairo.image_surface_create("rgb24", IMG_WD, IMG_HT)
local cr = Cairo.context_create(surface)
-- White background.
cr:set_source_rgb(1, 1, 1)
cr:paint()
-- Line join style.
local x, y = MARGIN/2, IMG_HT - MARGIN/2
for _, joinstyle in ipairs{ "miter", "round", "bevel" } do
cr:move_to(x, y)
cr:line_to(x + DEMO_WD / 2, y - DEMO_HT)
cr:line_to(x + DEMO_WD, y)
cr:set_source_rgb(0, 0, 0)
cr:set_line_join(joinstyle)
cr:set_line_width(LINE_WD)
cr:stroke_preserve()
cr:set_source_rgb(1, 0.5, 0.5)
cr:set_line_join("miter")
cr:set_line_width(2)
cr:stroke()
x = x + DEMO_WD + MARGIN
end
-- Line cap style.
x = MARGIN/2
y = y - DEMO_HT - MARGIN - LINE_WD/2
for _, capstyle in ipairs{ "butt", "round", "square" } do
cr:move_to(x, y)
cr:line_to(x + DEMO_WD, y)
cr:set_source_rgb(0, 0, 0)
cr:set_line_cap(capstyle)
cr:set_line_width(LINE_WD)
cr:stroke_preserve()
cr:set_source_rgb(1, 0.5, 0.5)
cr:set_line_cap("butt")
cr:set_line_width(2)
cr:stroke()
x = x + DEMO_WD + MARGIN
end
-- Dash patterns.
x = MARGIN/2
y = y - MARGIN/2 - LINE_WD/2
cr:set_line_width(2)
cr:set_source_rgb(0, 0, 0);
for _, dashpat in ipairs{ {}, {3}, {3,6,9} } do
for offset = 0, #dashpat do
cr:set_dash(dashpat, offset)
cr:move_to(x, y)
cr:line_to(IMG_WD - MARGIN, y)
cr:stroke()
y = y - 5
end
y = y - 5
end
surface:write_to_png("stroke-style.png")
-- vi:ts=4 sw=4 expandtab
|