Skip to content

Commit fbb93c9

Browse files
committed
test/test2.f90 is now creating a SVG file, and test4.f90 a PDF file
1 parent e1ad316 commit fbb93c9

File tree

4 files changed

+20
-17
lines changed

4 files changed

+20
-17
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ All notable changes to the gtk-fortran project are documented in this file. The
99

1010
### Changed
1111
- `src/cairo-auto.f90` and `src/cairo-enums.f90` updated for **Cairo 1.17.8** (generated with the `cfwrapper.py` program under Fedora 38).
12+
- `test/test2.f90` is now creating a SVG file.
13+
- `test/test4.f90` is now creating a PDF file.
1214

1315
## [cairo-fortran 1.0.0]
1416

README.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ $ cd cairo-fortran
5555

5656
## Testing cairo-fortran
5757

58-
Each test prints nothing in the terminal but is creating a PNG file. You should therefore obtain three PNG files in the main directory of the project:
58+
Each test prints nothing in the terminal but is creating an output file in the main directory of the project: `test1.f90` a PNG file, `test2.f90` a SVG file and `test4.f90` a PDF file.
5959

6060
```bash
6161
$ fpm test
@@ -70,10 +70,12 @@ test4 done.
7070
test1 done.
7171
test2 done.
7272
[100%] Project compiled successfully.
73-
$ ls *.png
74-
axis.png chess.png F.png
73+
$ ls *.png *.svg *.pdf
74+
axis.svg chess.pdf F.png
7575
```
7676

77+
See https://cairographics.org/manual/cairo-surfaces.html for other available *surfaces* (for example you could use PostScript).
78+
7779
### Example test1
7880
![test1](pictures/F.png)
7981
### Example test2

test/test2.f90

+7-7
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
! - Draw axis and grid lines
1010
! - Plot a function i(t) = I|\cos(\omega t + \phi)|
1111
! - Draw a line
12-
! - Save the image to disk
12+
! - Save the image to disk in SVG
1313

1414
program test2
1515
use cairo
@@ -32,10 +32,13 @@ program test2
3232
type(cairo_matrix_t), target :: m
3333
integer :: i
3434

35-
! Initialize
36-
surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, &
37-
& int(IMAGE_WIDTH), int(IMAGE_HEIGHT))
35+
! Rendering in a SVG file:
36+
surface = cairo_svg_surface_create("axis.svg"//c_null_char, &
37+
& IMAGE_WIDTH, IMAGE_HEIGHT)
3838
c = cairo_create(surface)
39+
call cairo_svg_surface_restrict_to_version(surface, CAIRO_SVG_VERSION_1_2)
40+
41+
! Initialize
3942
call cairo_set_antialias(c, CAIRO_ANTIALIAS_BEST)
4043

4144
! Set background colour
@@ -93,9 +96,6 @@ program test2
9396
call cairo_line_to(c, 40.d0, -40.d0)
9497
call cairo_stroke(c)
9598

96-
! Write .png
97-
r = cairo_surface_write_to_png(surface, "axis.png"//c_null_char)
98-
9999
! Destroy
100100
call cairo_destroy(c)
101101
call cairo_surface_destroy(surface)

test/test4.f90

+6-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
! - Create a 480x480 image
55
! - Create an internal workspace 8x8
66
! - Draw board
7-
! - Save image to disk
7+
! - Save image to disk in PDF
88

99
program test4
1010
use cairo
@@ -21,10 +21,12 @@ program test4
2121
type(cairo_matrix_t), target :: m
2222
integer :: i, j
2323

24-
! Initialize
25-
surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, &
26-
& int(IMAGE_WIDTH), int(IMAGE_HEIGHT))
24+
! Rendering in a PDF file:
25+
surface = cairo_pdf_surface_create("chess.pdf"//c_null_char, &
26+
& IMAGE_WIDTH, IMAGE_HEIGHT)
2727
c = cairo_create(surface)
28+
29+
! Initialize
2830
call cairo_set_antialias(c, CAIRO_ANTIALIAS_BEST)
2931

3032
! Transform image coordinates (480x480) to my internal workspace (8x8)
@@ -51,9 +53,6 @@ program test4
5153
end do
5254
end do
5355

54-
! Write .png
55-
r = cairo_surface_write_to_png(surface, "chess.png"//c_null_char)
56-
5756
! Destroy
5857
call cairo_destroy(c)
5958
call cairo_surface_destroy(surface)

0 commit comments

Comments
 (0)