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
|
-- Show some different font family and style selections.
local Cairo = require "oocairo"
local IMG_WD, IMG_HT = 470, 540
local surface = Cairo.image_surface_create("rgb24", IMG_WD, IMG_HT)
local cr = Cairo.context_create(surface)
local function draw_dot (x, y)
cr:save()
cr:move_to(x, y)
cr:rel_line_to(0, 0)
cr:set_line_width(5)
cr:set_source_rgb(1, 0, 0)
cr:set_line_cap("round")
cr:stroke()
cr:restore()
end
-- White background.
cr:set_source_rgb(1, 1, 1)
cr:paint()
local START_X = 20
local x, y = START_X, 40
cr:set_font_size(30)
for _, family in ipairs{ "Sans", "Times New Roman" } do
for _, slant in ipairs{ "normal", "italic", "oblique" } do
for _, weight in ipairs{ "normal", "bold" } do
cr:select_font_face(family, slant, weight)
local text = family .. ", " .. slant .. ", " .. weight
draw_dot(x, y)
cr:move_to(x, y)
cr:set_source_rgb(0, 0, 0)
cr:show_text(text)
local extents = cr:font_extents()
x = START_X
y = y + extents.height * 1.2
end
end
y = y + 10
end
surface:write_to_png("text-font.png")
-- vi:ts=4 sw=4 expandtab
|