-
Notifications
You must be signed in to change notification settings - Fork 964
Cairo Linux + macOS #2357
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cairo Linux + macOS #2357
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces cross-platform Cairo support for Linux and updates macOS Cairo to version 1.8.4. The changes enable Cairo samples to work on Linux using system-installed Cairo libraries while maintaining compatibility with Windows and macOS through bundled libraries. Additionally, all Cairo samples are updated to use OpenGL rendering on Linux/macOS instead of the deprecated Renderer2d.
Key changes include:
- Linux Cairo integration via FindCairo.cmake module and conditional CMakeLists.txt updates
- macOS Cairo library update to version 1.8.4 with universal binary support
- Platform-specific rendering path changes for Linux/macOS Cairo samples
- Modernization of sample code (Twitter API → Mastodon API migration)
Reviewed Changes
Copilot reviewed 36 out of 39 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| samples//src/.cpp | Updated Cairo samples to use conditional rendering paths (OpenGL for Linux/macOS, direct window surface for Windows) |
| samples/*/proj/cmake/CMakeLists.txt | Added Linux-specific Cairo build configuration using system libraries |
| proj/cmake/modules/FindCairo.cmake | New CMake module for locating system Cairo libraries on Linux |
| blocks/Cairo/src/Cairo.cpp | Added Linux font handling and fixed compatibility issues |
| blocks/Cairo/include/ | Updated macOS Cairo headers to version 1.8.4 |
| docs/htmlsrc/guides/linux-notes/ | Updated documentation for Cairo installation requirements |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| { | ||
| mCairoSurface = cairo_ps_surface_create( filePath.string().c_str(), widthInPoints, heightInPoints ); | ||
| cairo_ps_surface_set_eps( mCairoSurface, TRUE ); | ||
| cairo_ps_surface_set_eps( mCairoSurface, 1 ); |
Copilot
AI
Sep 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using magic number 1 instead of a boolean constant. Consider using true or defining a named constant to improve code readability and maintainability.
| cairo_ps_surface_set_eps( mCairoSurface, 1 ); | |
| cairo_ps_surface_set_eps( mCairoSurface, true ); |
| mCtx.setFontMatrix( fontMatrix ); | ||
| TextBox tbox = TextBox().font( *font ).text( span.getString() ); | ||
| std::vector<std::pair<uint16_t,vec2> > glyphs = tbox.measureGlyphs(); | ||
| auto glyphs = tbox.measureGlyphs(); |
Copilot
AI
Sep 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Using auto for type deduction where the explicit type would improve code clarity. Consider using the explicit return type from measureGlyphs() to make the code more self-documenting.
| auto glyphs = tbox.measureGlyphs(); | |
| std::vector<std::pair<uint16_t, vec2>> glyphs = tbox.measureGlyphs(); |
|
One additional note, this PR fixes the GoodNightMorning sample, moving it off of a long-deprecated Twitter API and using a Mastadon API insead. |
This PR introduces Linux support for Cairo, and updates macOS Cairo library to the latest release, 1.8.4.
To use Cairo on Linux, you'll need to
sudo apt install libcairo2-devbut the include cmake projects should build out of the box after that. This PR also includes documentation updates to that effect, and a FindCairo.cmake file.On macOS, the included static libraries are "fat" binaries, supporting both x86_64 and arm64.
For both Linux and now macOS, the Cairo samples render to a
gl::Texturerather than using Renderer2d. For Linux, an equivalent doesn't exist, and on macOS, Apple recently introduced some breaking changes that IMO mean we should probably deprecate that infrequently used code path.Tested on Ubuntu 24.04, macOS 14.5, and Windows 11.