Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
ocaml-cairo/examples/tips_letter.ml
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
28 lines (23 sloc)
858 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* This file is part of the tutorial | |
http://cairo.forge.ocamlcore.org/tutorial/ | |
*) | |
open Cairo | |
let () = | |
let alphabet = "AbCdEfGhIjKlMnOpQrStUvWxYz" in | |
let surface = Cairo.Image.create Cairo.Image.ARGB32 ~w:780 ~h:30 in | |
let cr = Cairo.create surface in | |
(* Examples are in 26.0 x 1.0 coordinate space *) | |
Cairo.scale cr 30. 30.; | |
Cairo.set_font_size cr 0.8; | |
(* Drawing code goes here *) | |
Cairo.set_source_rgb cr 0.0 0.0 0.0; | |
Cairo.select_font_face cr "Georgia" ~weight:Bold; | |
for i = 0 to String.length alphabet - 1 do | |
let letter = String.make 1 (alphabet.[i]) in | |
let te = Cairo.text_extents cr letter in | |
Cairo.move_to cr (float i +. 0.5 -. te.x_bearing -. te.width /. 2.) | |
(0.5 -. te.y_bearing -. te.height /. 2.); | |
Cairo.show_text cr letter; | |
done; | |
(* Write output *) | |
Cairo.PNG.write surface "tips_letter.png" |