Skip to content

Latest commit

 

History

History
131 lines (65 loc) · 5.01 KB

Samples.md

File metadata and controls

131 lines (65 loc) · 5.01 KB

Sample programs

This is roughly a copy of the sample code listed at cairographics.org/samples. These examples are C code and assume that you've already set up a Cairo surface and Cairo Context.

This (samples) directory contains ports of these examples to julia, additionally creating the Surface and Context, adding a time-stamp to the image, and saving the result to a .png file.

arc

Example of using the arc path operator sample_arc.jl. Note: The path creation starts without current point, otherwise there would be a linesegment first, before starting of the arc.

arc .png

arc_negative

Example of using the arc_negative path operator sample_arc_negative.jl.

arc_negative .png

clip

A clip path, a circle is defined, then the drawing is done sample_clip.jl.

clip .png

clip image

Like the previous, but now inserting a picture by reading a .png to an Image Surface. Note: the function is called read_from_png and creates an Image Surface; while in pure C cairo this would be a call of cairo_image_surface_create_from_png sample_clip_image.jl.

clip image.png

curve rectangle

Example of more complex path construction, here a rectangle constructed be four bezier segments. Note: Different as in the original example, this here now puts the path construction and stroke and fill operations into a function with coordinates and corner radius as arguments sample_curve_rectangle.jl.

curve rectangle .png

curve to

Example of using the curve to path operator, which adds a cubic Bézier spline to the current path sample_curve_to.jl.

curve to .png

dash

Example of using a dash line pattern for stroking a path. Note: the julia set_dash uses the length of the dash array to set the ndash internally sample_dash.jl.

dash .png

fill and stroke 2

Example of creating a path of non connected areas and fill - while preserving the path - and stroke sample_fill_and_stroke2.jl.

fill and stroke2 .png

fill style

Exmaple of using the different fill rules. The same path is filled and stroked sample_fill_style.jl. Note: the julia function is called set_fill_type while the pure C cairo is called with set_fill_rule.

fill style .png

gradient

Example of gradients - both linear and radiant - as definition and used for filling sample_gradient.jl.

gradient .png

image

Example of painting with a Image Surface as source sample_image.jl.

image .png

image pattern

Example of painting with a Image Surface as pattern [sample_imagepattern.jl] (sample_imagepattern.jl).

imagepattern .png

multi segment caps

Example of stroking a path with non connected segments sample_multi_segment_caps.jl.

multi segment caps .png

rounded rectangle

Example of more path operators, custom shape could be wrapped in a function sample_rounded_rectangle.jl.

rounded rectangle .png

set line caps

Examples of the line cap settings sample_set_line_cap.jl.

set line cap .png

set line join

Examples of the line join settings sample_set_line_join.jl.

set line join .png

text

Example of setting text, one with text_show, second with text_path extending the current path and fill and stroke the outline sample_text.jl.

text .png

text align center

Example of getting the text extents, then centering the text around 128.0,128.0 sample_text_align_center.jl.

text align center.png

text extents

Example of getting the text extents, plotting the dimension sample_text_extents.jl.

text extents .png

copy path

Example of getting the path to a single character via text_path, copy_path and convert to an Array of CairoPathEntry sample_copy_path.jl.

copy path .png