Commit graph

8167 commits

Author SHA1 Message Date
Adrian Johnson
54cbe51481 Merge branch 'update-to-fedora-40' into 'master'
Update CI to Fedora 40

See merge request cairo/cairo!546
2024-05-21 09:41:13 +00:00
Adrian Johnson
c75997a4ea Merge branch 'dest-and-uri' into 'master'
Allow links to specify 'dest' and 'uri'

See merge request cairo/cairo!547
2024-05-15 22:12:24 +00:00
Uli Schlachter
877a8a4820 Mark _cairo_debug_svg_render() cairo_public
Without this, building with

  CFLAGS="-DDEBUG_SVG_RENDER" meson setup path/to/source

simply does not work for me:

    test/svg/svg-render.c:74:(.text+0x40): undefined reference to `_cairo_debug_svg_render'
    collect2: error: ld returned 1 exit status

After marking this symbol as exported, this just works.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2024-05-15 17:20:45 +02:00
Adrian Johnson
754f431642 Allow links to specify 'dest' and 'uri'
- If a link has both 'dest' and 'uri', the 'dest' will be used if it
  exists, otherwise it will fallback to using the 'uri'.

- Ensure that a missing 'dest' does not result in an error. Instead a
  warning is printed if CAIRO_DEBUG_TAG is set, and a link to the
  current location is embedded in the PDF. ie the link does
  nothing. Cairo needs to embed a link even if no destination is
  available because when links are embedded at the end of the
  document, the content stream already contains link tags.

- Remove cairo_pdf_interchange_write_forward_links. This code was
  originally used prior to !463 when cairo wrote the links at the end
  of each page. Now the links are written at the end of the document
  so there are no longer any forward links with an unknown
  destination, unless the destination does not exist.

- When 'internal' is not used, use the 'dest' name to reference the
  link. Ensure non ASCII names are correctly encoded.
2024-05-11 19:52:02 +09:30
Adrian Johnson
293b75a1c4 Update CI to Fedora 40 2024-04-28 21:28:41 +09:30
Daniel Holbert
5223f0c932 Switch to calloc in _cairo_cff_font_fallback_create
This makes this function more consistent with _cairo_cff_font_create, the other
function in this file that allocates fonts.
2024-04-25 16:44:00 -07:00
Alan Coopersmith
44e4e11236 Fix alloca undefined on Solaris
Solaris defines alloca in the <alloca.h> header

../src/cairo-colr-glyph-render.c: In function ‘add_sweep_gradient_patches’:
../src/cairo-colr-glyph-render.c:661:14: error: implicit declaration of
 function ‘alloca’ [-Werror=implicit-function-declaration]
  661 |     angles = alloca (sizeof (double) * cl->n_stops);
      |              ^~~~~~

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2024-04-15 10:40:08 -07:00
Adrian Johnson
057a949bb7 Merge branch 'ft-font-accuracy-new' into 'master'
Improve accuracy of computed metrics for FT fonts

See merge request cairo/cairo!533
2024-03-21 20:58:48 +00:00
Marek Kasik
1bd4d59705 Prefer COLRv1 table 2024-03-21 20:55:15 +00:00
Adrian Johnson
bbbc68e619 Merge branch 'surface-error-png' into 'master'
_cairo_surface_create_in_error(): Add PNG_ERROR support

See merge request cairo/cairo!524
2024-02-17 10:01:14 +00:00
Vincent Lefevre
6e5e4bd978 Improve accuracy of computed metrics for FT fonts
In particular, with bitmap fonts, a floating-point error was affecting
y_bearing, yielding a value close to an integer instead of the integer
exactly. The change consists in replacing some operations of the form
A * (1/B) by A/B. Details of the issue in #503.

This new code will not always avoid rounding errors in final values
when these values could be exact, but it makes some of these errors
disappear.

The changes in the src/cairo-ft-font.c code consists of:
* Define the SCALE() macro (with some explanations in a comment).
* Remove the declarations and definitions of x_factor and y_factor.
* Update the code to use SCALE() instead of x_factor and y_factor.
  perl -pi -e 's{(DOUBLE_\w+) ?(\(.*\)) \* ([xy])_factor}
                {SCALE (\1 \2, unscaled->\3_scale)}' \
    src/cairo-ft-font.c
* Replace the remaining 0 * x_factor and 0 * y_factor by 0.
2024-01-22 02:57:20 +01:00
Emmanuele Bassi
586c8acacd Merge branch 'fix-issue-811' into 'master'
Cairo 1.18.0 doesn't draw italic or bold text on Mac

See merge request cairo/cairo!531
2024-01-18 09:32:20 +00:00
Diego Pino Garcia
bd6aa966df [quartz] Fix: Cairo 1.18.0 doesn't draw italic or bold text on Mac
Commit cf351a8a attempted to convert the font generation in
'_cairo_quartz_font_create_for_toy' to use CTFontCreateWithName and that uses
only Postscript Names, meaning with the hyphens.

Commit c6dc5df6 converted back to CGFont. CGFontCreateWithFontName is supposed
to work with Postscript Names, but it seems sometimes it does not.

In case a CGFont cannot be created using Postscript Names, attempt unhyphenated
version of font family name.
2024-01-17 09:07:12 +01:00
Behdad Esfahbod
3bcad03f6b Copy font-options during creation of a fallback font
Specially important for font variations, which before did not
work in PDF, etc, output.

Script surface is not updated. It seems out of date with all
recent additions to cairo_font_options_t, so it loses the
variations :(.

Fixes https://gitlab.freedesktop.org/cairo/cairo/-/issues/819
2024-01-16 18:13:59 -07:00
Behdad Esfahbod
10fffac83c [pdf] Set both fill and stroke colors in show_text_glyphs
Since a user-font might be calling stroke, and PDF has separate
stroke and fill colors.

Note that this bug was not exposed in Poppler. It's probably a
bug there. But multiple other viewers expoed this bug.

Fixes https://gitlab.freedesktop.org/cairo/cairo/-/issues/813
2023-11-30 21:54:07 -05:00
Sam James
c84a13c576
cairo-ps-surface: fix -Walloc-size
GCC 14 introduces a new -Walloc-size included in -Wextra which gives:
```
src/cairo-ps-surface.c:3524:18: warning: allocation of insufficient size ‘1’ for type ‘cairo_ps_form_t’ {aka ‘struct _cairo_ps_form’} with size ‘88’ [-Walloc-size]
```

The calloc prototype is:
```
void *calloc(size_t nmemb, size_t size);
```

So, just swap the number of members and size arguments to match the prototype, as
we're initialising 1 struct of size `sizeof(cairo_ps_form_t)`. GCC then sees we're not
doing anything wrong.

Signed-off-by: Sam James <sam@gentoo.org>
2023-11-05 22:09:21 +00:00
Uli Schlachter
23a643c80d _cairo_surface_create_in_error(): Add PNG_ERROR support
Traditionally, loading a malformed PNG file with
cairo_image_surface_create_from_png() resulted in
CAIRO_STATUS_NO_MEMORY. This was apparently changed in commit
c5ee3f11b5 by adding CAIRO_STATUS_PNG_ERROR and using it for errors
returned from libpng. However, I don't see how this was supposed to
actually work.

There are a couple of error codes supported by
_cairo_surface_create_in_error(). Anything else is turned into
CAIRO_STATUS_NO_MEMORY, which is not a helpful status. For this reason,
CAIRO_STATUS_PNG_ERROR would be turned into CAIRO_STATUS_NO_MEMORY.

This commit adds support for CAIRO_STATUS_PNG_ERROR to
_cairo_surface_create_in_error() so that this error can actually be
returned to the caller.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2023-10-31 14:54:06 +01:00
Ryan Schmidt
85f021b1f1 quartz-font: Fix transposed constants
kCTFontColorGlyphsTrait is available in Mac OS X 10.7 and later.
kCTFontTraitColorGlyphs is available in OS X 10.8 and later.

Fixes build failure on Mac OS X 10.7.

Closes #810
2023-10-24 01:42:38 -05:00
Adrian Johnson
b23f4b3fc2 Require pixman >= 0.40 2023-10-02 15:56:04 +10:30
Adrian Johnson
0fce59ff8d Fix surface type mismatch error in pdf-interchange 2023-10-02 15:46:09 +10:30
Dan Yeaw
27cdee5e4c Fix alloca undefined with MSVC
Conditionally includes malloc.h when compiling with
MSVC so that alloca is defined.
2023-09-30 13:30:51 -04:00
Emmanuele Bassi
05d1a41a1f Post-release version bump to 1.18.1 2023-09-23 15:18:32 +01:00
Emmanuele Bassi
3909090108 Release Cairo 1.18.0 2023-09-23 15:18:32 +01:00
Emmanuele Bassi
3648bf24f6 build: Fix program listing syntax check
The modern gtk-doc syntax for program listing is `|[ ... ]|`.
2023-09-23 15:18:32 +01:00
Emmanuele Bassi
c74bd39df6 docs: Fix closing docblock 2023-09-23 15:18:32 +01:00
Emmanuele Bassi
555b9ddc57 docs: Remove docblock
The gtk-doc parser will not respect `#if 0 ... #endif` blocks.
2023-09-23 15:18:32 +01:00
Emmanuele Bassi
ca646bc24d docs: Add missing docblocks for surface observer API 2023-09-23 15:18:32 +01:00
Emmanuele Bassi
5de85afb75 docs: Add docblocks for missing feature defines 2023-09-23 15:18:32 +01:00
Emmanuele Bassi
e4aa193008 docs: Add missing docblocks for cairo-tee API
The tee API has been left undocumented all this time.
2023-09-23 15:18:31 +01:00
Emmanuele Bassi
ac9ffd3e8a docs: Add missing docblocks for content tags 2023-09-23 15:18:31 +01:00
Emmanuele Bassi
1678bfb2ec Ensure that argument names in declarations match definitions
The name of an argument in the header must match the name of the
argument in the source, otherwise gtk-doc will raise a warning.
2023-09-23 15:18:31 +01:00
Emmanuele Bassi
1b77892a18 docs: Add missing long description for cairo-quartz-font section 2023-09-23 15:18:31 +01:00
Emmanuele Bassi
cfd8356a75 docs: Do not make private symbols with docblocks
Otherwise gtk-doc will warn about undocumented/unused symbols.
2023-09-23 15:18:31 +01:00
Emmanuele Bassi
6c7fb34627 docs: Add missing docblocks for the device observer API 2023-09-23 13:20:07 +01:00
Emmanuele Bassi
98867c6cf3 docs: Add missing section docblock for cairo-tee 2023-09-23 13:19:43 +01:00
Emmanuele Bassi
b770d57b26 Remove pointless CAIRO_HAS_DITHER
The support for dithering is not conditional, and it can be checked
using the Cairo version.
2023-09-23 13:18:34 +01:00
Emmanuele Bassi
7c5d0de2d2 docs: Hide private docs
If a private symbol gets a docblock stanza, gtk-doc becomes *very*
confused.
2023-09-23 13:11:46 +01:00
Emmanuele Bassi
900b713af1 Merge branch 'ebassi/dithering' into 'master'
Enable access to the pixman dithering path

See merge request cairo/cairo!511
2023-09-23 11:49:49 +00:00
Emmanuele Bassi
86d7025af5 Merge branch 'wip-fix-352' into 'master'
Avoid assert when drawing arcs with NaN angles

Closes #352

See merge request cairo/cairo!515
2023-09-23 11:10:16 +00:00
Tim Serong
09643ee1ab Avoid assert when drawing arcs with NaN angles
I hit the problem with _cairo_arc_in_direction() failing the
angle_max >= angle_min assertion earlier this year when using
Thunderbird on openSUSE Tumbleweed.  Thunderbird would crash
when rendering some (but not all) HTML email due to this
assert.  For some reason, one of the angles passed in was
NaN.  Making _cairo_arc_in_direction() return immediately if
either angle is not finite fixed the problem for me, but I
don't know enough about the internals of Cairo to know if
this is, strictly speaking, the "right" fix.  Also, having
tested again today _without_ this change applied, I am now
no longer able to reproduce the problem :-/  I still have the
same version of Cairo installed (1.17.8), but various other
packages on that system have been updated in the meantime,
so maybe that's a factor.  Or maybe I'm just lucky and
haven't hit a "bad" HTML email this time...?

Fixes: https://gitlab.freedesktop.org/cairo/cairo/-/issues/352
Signed-off-by: Tim Serong <tserong@suse.com>
2023-09-19 18:26:39 +10:00
Christian Hesse
e364946957 Fix font options leak in _cairo_gstate_ensure_scaled_font()
Font options are allocated in _cairo_gstate_ensure_scaled_font() for local
processing, but never freed. Run _cairo_font_options_fini() on these and
fix the leak.

Signed-off-by: Christian Hesse <mail@eworm.de>
2023-09-18 23:31:23 +02:00
Uli Schlachter
06864022c8 Fix font options leak in cairo script surface
I added options->variations = strdup("slnt=0,wght=400,wdth=100"); to the
end of _cairo_font_options_init_default(). This makes all font option
objects own some memory that needs to be freed. Then I ran some random
test under valgrind and found memory leaks.

This commit makes the script surface finish the font options that it
contains. This fixes the following valgrind report:

 25 bytes in 1 blocks are definitely lost in loss record 8 of 21
    at 0x48407B4: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
    by 0x4ECBC99: strdup (strdup.c:42)
    by 0x4886B7F: _cairo_font_options_init_default (cairo-font-options.c:86)
    by 0x49768F4: _cairo_script_implicit_context_init (cairo-script-surface.c:3676)
    by 0x4976B22: _cairo_script_surface_create_internal (cairo-script-surface.c:3733)
    by 0x4976EA1: cairo_script_surface_create (cairo-script-surface.c:3962)
    by 0x1B0A97: _cairo_boilerplate_script_create_surface (cairo-boilerplate-script.c:63)
    by 0x129B7F: cairo_test_for_target (cairo-test.c:824)
    by 0x12B37F: _cairo_test_context_run_for_target (cairo-test.c:1545)
    by 0x12C385: _cairo_test_runner_draw (cairo-test-runner.c:258)
    by 0x12DEB5: main (cairo-test-runner.c:962)

Signed-off-by: Uli Schlachter <psychon@znc.in>
2023-09-17 10:00:51 +02:00
Uli Schlachter
29087868cd Fix font options leak in _cairo_surface_copy_similar_properties()
I added options->variations = strdup("slnt=0,wght=400,wdth=100"); to the
end of _cairo_font_options_init_default(). This makes all font option
objects own some memory that needs to be freed. Then I ran some random
test under valgrind and found memory leaks.

_cairo_surface_copy_similar_properties() gets the font options of a
surface via cairo_surface_get_font_options(). This creates a copy of the
font variations that I added above. _cairo_surface_set_font_options()
then copies this again (it calls _cairo_font_options_init_copy). Thus,
the original copy is still owned by
_cairo_surface_copy_similar_properties() and needs to be freed.

This commit fixes four leaks in "valgrind --leak-check=full
./cairo-test-suite -f leaks-set-scaled-font". A random example is:

 25 bytes in 1 blocks are definitely lost in loss record 4 of 25
    at 0x48407B4: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
    by 0x4ECBC99: strdup (strdup.c:42)
    by 0x4886C0C: _cairo_font_options_init_copy (cairo-font-options.c:99)
    by 0x48F1DDE: cairo_surface_get_font_options (cairo-surface.c:1620)
    by 0x48F0691: _cairo_surface_copy_similar_properties (cairo-surface.c:454)
    by 0x48F087C: cairo_surface_create_similar (cairo-surface.c:528)
    by 0x1B168A: _cairo_boilerplate_pdf_create_surface (cairo-boilerplate-pdf.c:92)
    by 0x129B7F: cairo_test_for_target (cairo-test.c:824)
    by 0x12B37F: _cairo_test_context_run_for_target (cairo-test.c:1545)
    by 0x12C385: _cairo_test_runner_draw (cairo-test-runner.c:258)
    by 0x12DEB5: main (cairo-test-runner.c:962)

Signed-off-by: Uli Schlachter <psychon@znc.in>
2023-09-17 09:51:51 +02:00
Uli Schlachter
4c1987b0f0 Fix font options leak in cairo-surface.c
When calling cairo_surface_get_font_options(), a font options instance
is allocated for the surface. Normally, this just initialised some
otherwise uninitialised fields in cairo_surface_t. Since commit
67eeed44, cairo_font_options_t can contain an extra allocation for a
custom palette. Since commit edf9497c3a, cairo_font_options_t can
contain an extra allocation for a string. Before these commit, font
options could just be dropped, but now they need to be freed.

This commit makes cairo_surface_destroy() finish the contained font
options if they were initialised.

I didn't manage to produce a self-contained test case for this leak. I
found it by just looking at the code. However, I found a way to force a
leak: By adding options->variations=strdtup("slnt=0,wght=400,wdth=100");
to the end of _cairo_font_options_init_default(), all font option
instances now cause a leak unless they are finished. With this extra
change, this commit fixes a memory leak that is simply caused by calling
cairo_surface_get_font_options().

Signed-off-by: Uli Schlachter <psychon@znc.in>
2023-09-17 09:45:04 +02:00
Uli Schlachter
7bf743a92f Fix font options leak in scaled font
A scaled font contains font options. Since commit 67eeed44, this can
contain an extra allocation for a custom palette. Since commit
edf9497c3a, this contains an extra allocation for a string. Before these
commit, font options could just be dropped, but now they need to be
freed.

This commit makes the relevant code for creating and finishing scaled
fonts also clean up the font options.

The test added in the previous commit also hits this bug (I only found
these leaks accidentially!). Running "valgrind --leak-check=full
./cairo-test-suite -f leaks-set-scaled-font" no longer reports the following
after this change:

 40 bytes in 1 blocks are definitely lost in loss record 1 of 11
    at 0x48407B4: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
    by 0x4886C62: _cairo_font_options_init_copy (cairo-font-options.c:105)
    by 0x48DAFFB: _cairo_scaled_font_init_key (cairo-scaled-font.c:675)
    by 0x48DC077: cairo_scaled_font_create (cairo-scaled-font.c:1096)
    by 0x15BF08: leaks_set_scaled_font (leaks.c:43)
    by 0x129EF0: cairo_test_for_target (cairo-test.c:938)
    by 0x12B37F: _cairo_test_context_run_for_target (cairo-test.c:1545)
    by 0x12C385: _cairo_test_runner_draw (cairo-test-runner.c:258)
    by 0x12DEB5: main (cairo-test-runner.c:962)

 40 bytes in 1 blocks are definitely lost in loss record 2 of 11
    at 0x48407B4: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
    by 0x4886C62: _cairo_font_options_init_copy (cairo-font-options.c:105)
    by 0x49337BB: _cairo_ft_font_face_scaled_font_create (cairo-ft-font.c:2073)
    by 0x48DC340: cairo_scaled_font_create (cairo-scaled-font.c:1176)
    by 0x15BF08: leaks_set_scaled_font (leaks.c:43)
    by 0x129EF0: cairo_test_for_target (cairo-test.c:938)
    by 0x12B37F: _cairo_test_context_run_for_target (cairo-test.c:1545)
    by 0x12C385: _cairo_test_runner_draw (cairo-test-runner.c:258)
    by 0x12DEB5: main (cairo-test-runner.c:962)

 40 bytes in 1 blocks are definitely lost in loss record 3 of 11
    at 0x48407B4: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
    by 0x4886C62: _cairo_font_options_init_copy (cairo-font-options.c:105)
    by 0x48DB280: _cairo_scaled_font_init (cairo-scaled-font.c:742)
    by 0x4933804: _cairo_ft_font_face_scaled_font_create (cairo-ft-font.c:2076)
    by 0x48DC340: cairo_scaled_font_create (cairo-scaled-font.c:1176)
    by 0x15BF08: leaks_set_scaled_font (leaks.c:43)
    by 0x129EF0: cairo_test_for_target (cairo-test.c:938)
    by 0x12B37F: _cairo_test_context_run_for_target (cairo-test.c:1545)
    by 0x12C385: _cairo_test_runner_draw (cairo-test-runner.c:258)
    by 0x12DEB5: main (cairo-test-runner.c:962)

Signed-off-by: Uli Schlachter <psychon@znc.in>
2023-09-17 09:32:10 +02:00
Uli Schlachter
9529d02f6a Fix font options leak in gstate
cairo_gstate_t contains a cairo_font_options_t. Since commit 67eeed44,
this can contain an extra allocation for a custom palette. Since commit
edf9497c3a, this contains an extra allocation for a string. Before these
commit, font options could just be dropped, but now they need to be
freed.

This commit makes _cairo_gstate_fini() finish the font options to free
the memory allocation.

The new test was run via "valgrind --leak-check=full ./cairo-test-suite
-f leaks-set-scaled-font". The following reported leak goes away thanks
to this commit:

 1,040 bytes in 26 blocks are definitely lost in loss record 6 of 12
    at 0x48407B4: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
    by 0x4886C62: _cairo_font_options_init_copy (cairo-font-options.c:105)
    by 0x488C029: _cairo_gstate_set_font_options (cairo-gstate.c:1757)
    by 0x48841D7: _cairo_default_context_set_scaled_font (cairo-default-context.c:1310)
    by 0x490809A: cairo_set_scaled_font (cairo.c:3318)
    by 0x15BF1F: leaks_set_scaled_font (leaks.c:45)
    by 0x129EF0: cairo_test_for_target (cairo-test.c:938)
    by 0x12B37F: _cairo_test_context_run_for_target (cairo-test.c:1545)
    by 0x12C385: _cairo_test_runner_draw (cairo-test-runner.c:258)
    by 0x12DEB5: main (cairo-test-runner.c:962)

Fixes: https://gitlab.freedesktop.org/cairo/cairo/-/issues/795
Signed-off-by: Uli Schlachter <psychon@znc.in>
2023-09-17 09:22:29 +02:00
Emmanuele Bassi
ac26a16171 Make Cairo dither to Pixman dither conversion static
We don't use it anywhere outside of the image surface, so there's no
need to make it a project-wide private function.

The name is also updated: it's a cairo function, so it should not abuse
the pixman namespace.
2023-09-07 15:42:44 +01:00
Marc Jeanmougin
e6ab85712c Enable access to the pixman dithering path
Newer versions of Pixman allow choosing the dithering format.
2023-09-07 15:42:21 +01:00
Bobby Rong
50c5f3cc76 Fix building with -Werror=format-security
../src/cairo-pdf-surface.c: In function '_cairo_pdf_surface_open_content_stream':
../src/cairo-pdf-surface.c:2537:45: error: format not a string literal and no format arguments [-Werror=format-security]
 2537 |                                             str);
      |                                             ^~~
cc1: some warnings being treated as errors
2023-09-02 00:46:45 +00:00
Emmanuele Bassi
335c713ed7 tee: Remove questionable terminology
The master/slave terms are both inappropriate and inaccurate: the tee
surface replicates the rendering commands from a primary surface to
other surfaces.

This change is a mechanical search-and-replace.
2023-08-17 17:28:56 +01:00