Skip to content

Fortran bindings for the Cairo vector graphics library

License

Notifications You must be signed in to change notification settings

vmagnin/cairo-fortran

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cairo-fortran

logo

This repository contains Fortran bindings for the Cairo vector graphics library. It was extracted from the gtk-fortran project, as a separate fpm package, for people who don't need the GTK stuff.

Remark: this repository was cloned from the now unavailable @brocolis' repository (latest 5th September 2021 version).

Requirements and dependencies

You need:

  • a modern Fortran compiler, for example GFortran or the Intel ifort/ifx compilers. See the Fortran-lang.org compilers page for other compilers.
  • The Cairo development files (libcairo2-dev package in Ubuntu).
  • The Fortran Package Manager fpm.

Installation in Linux

For example, in Ubuntu:

$ sudo apt install gfortran libcairo2-dev

Concerning fpm, see the fpm documentation.

If you have a GitHub account, just clone the repository:

$ git clone [email protected]:vmagnin/cairo-fortran.git
$ cd cairo-fortran

Installation in Windows

You can use for example the MSYS2 environment:

Install the following packages via the MSYS2-MSYS shell:

  • build tools:
    • $ pacman -S mingw-w64-ucrt-x86_64-toolchain base-devel (it will install gcc, gdb, gfortran, python, make, pkgconf...)
  • git:
    • $ pacman -S git
  • Cairo and its dependencies:
    • $ pacman -S mingw-w64-ucrt-x86_64-cairo
  • Fortran Package Manager fpm:
    • $ pacman -S mingw-w64-ucrt-x86_64-fpm

Then start the MSYS2-UCRT64 shell.

If you have a GitHub account, just clone the repository:

$ git clone [email protected]:vmagnin/cairo-fortran.git
$ cd cairo-fortran

Testing cairo-fortran

Each test prints nothing in the terminal but creates 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.

$ fpm test
cairo-auto.f90                         done.
cairo-enums.f90                        done.
cairo-types.f90                        done.
libcairo-fortran.a                     done.
test4.f90                              done.
test1.f90                              done.
test2.f90                              done.
test4                                  done.
test1                                  done.
test2                                  done.
[100%] Project compiled successfully.
$ ls *.png *.svg *.pdf
axis.svg  chess.pdf  F.png

Note that Cairo has many other rendering devices not tested here (e.g. PostScript). See https://cairographics.org/manual/cairo-surfaces.html for other available surfaces.

Example test1

test1

Example test2

test2

Example test4

test4

Other examples

These examples use cairo-fortran as a fpm dependency:

fpm

To use cairo-fortran within your own fpm project, add the following dependency to your project fpm.toml file:

[dependencies]
cairo-fortran = {git = "https://github.com/vmagnin/cairo-fortran" }

License

Cairo-fortran is licensed under the GNU General Public License version 3 or later, with the additional permissions described in the GCC Runtime Library Exception version 3.1.

Cairo documentation and tutorials

Original project

Vincent MAGNIN, James TAPPIN, Jens HUNGER, Jerry DE LISLE, "gtk-fortran: a GTK+ binding to build Graphical User Interfaces in Fortran", Journal of Open Source Software, 4(34), 1109, 12th January 2019, https://doi.org/10.21105/joss.01109