Commit graph

12700 commits

Author SHA1 Message Date
Taylor R Campbell
b1ccd52183 Avoid misuse of ctype(3) functions
The ctype(3) character classification and mapping functions have a
peculiarly limited definition (C11, Sec. 7.4 `Character handling
<ctype.h>', p. 200):

	`The header <ctype.h> declares several functions useful for
	 classifying and mapping characters.  In all cases the
	 argument is an int, the value of which shall be
	 representable as an unsigned char or shall equal the value
	 of the macro EOF.  If the argument has any other value, the
	 behavior is undefined.'

In other words, in the most common case of 8-bit char and EOF = -1,
the domain of the 257 allowed arguments is:

	-1, 0, 1, 2, ..., 254, 255

The ctype(3) functions are designed for use with stdio functions like
getchar and fgetc which return int values in the same domain.

In an ABI where char is signed (e.g., x86 SysV ABI used by most
Unixish operating systems), passing an argument of type char as is
can go wrong in two ways:

1. The value of a non-EOF input octet interpreted as `char' may
   coincide, as an integer, with the value of EOF, leading to wrong
   answers for some non-EOF inputs.

   E.g., if EOF = 1, and an input octet has all bits set, i.e., 255
   as an unsigned char, then as a char the value is -1, which will be
   confused with EOF.  In the ISO-8859-1 locale, the code point 255
   is (in Unicode terminology) LATIN SMALL LETTER Y WITH DIAERESIS,
   for which isprint, isalpha, &c., are true.  But isprint, isalpha,
   &c., are false for EOF.  So if char *s points to a string with
   that character, isprint(*s) will return false when it should
   return true.

2. Passing a negative char whose value does not coincide with EOF is
   undefined behaviour.

   This isn't purely theoretical: often the functions are implemented
   by an array lookup, #define isprint(c) (ctypetab[c] & ISPRINT).
   If c is out of range (e.g., 192, ISO-8859-1 for LATIN CAPITAL
   LETTER A WITH GRAVE, which convers to (signed) char as -64), then
   you can get garbage answers by reading uninitialized memory or
   application crashes with SIGSEGV if the page preceding the table
   is unmapped.

If what you have is an arbitrary char (e.g., from a char * string
pointing at user input), then the only correct way to use the
ctype(3) functions is by converting to unsigned char first -- e.g.,
isprint((unsigned char)*s).  (If the functions were defined as macros
that convert to unsigned char first, they would then spuriously
interpret EOF as a non-EOF, so they can't do that themselves.)

It is possible, in some cases, to prove that the input always
actually lies in {0, 1, 2, ..., 127}, so the conversion to unsigned
char is not necessary.  I didn't check whether this was the case --
it's safer to just adopt the habit of always casting char to unsigned
char first before using the ctype(3) macros, which satisfies a
compiler warning on some systems designed to detect this class of
application errors at compile-time.
2023-03-29 09:04:46 +00:00
Uli Schlachter
d2b44eccb7 Merge branch 'patch-1' into 'master'
Delete cairo/perf/make-html.py

See merge request cairo/cairo!448
2023-03-26 09:54:13 +00:00
Emmanuele Bassi
ae60e48ac6 Merge branch 'gi-text-glyphs' into 'master'
[gobject] Bind cairo_glyph_t and cairo_text_cluster_t

See merge request cairo/cairo!468
2023-03-10 13:28:37 +00:00
Behdad Esfahbod
d08e348dd6 [gobject] Bind cairo_glyph_t and cairo_text_cluster_t 2023-03-09 13:04:50 -07:00
Adrian Johnson
d4d027d353 Merge branch 'issue-643' into 'master'
Fix missing glyphs in ft-font

Closes #643

See merge request cairo/cairo!467
2023-03-07 19:22:04 +00:00
Adrian Johnson
2766d9feec ft: Use normal font size when detecting the format
The format may depend on the font size.

Fixes #643
2023-03-07 19:41:39 +10:30
Uli Schlachter
af5a25a7f1 Merge branch 'unused-function' into 'master'
Fix -Wunused-function warnings

See merge request cairo/cairo!449
2023-03-03 15:50:32 +00:00
Uli Schlachter
3b178e8586 Merge branch 'ofz46165' into 'master'
ofz#46165 avoid a divide by zero seen fuzzing libreoffice rendering

See merge request cairo/cairo!351
2023-03-03 15:46:03 +00:00
Adrian Johnson
1f9004b3d0 Merge branch 'issue-3-win32-font-scale' into 'master'
win32 font is very small if the lfHeight of HFONT is exactly -size

Closes #3

See merge request cairo/cairo!466
2023-03-02 21:31:33 +00:00
Emmanuele Bassi
79c6beee90 Merge branch 'drop-xml-surface' into 'master'
Remove XML surface

See merge request cairo/cairo!446
2023-03-02 19:22:44 +00:00
Fujii Hironori
aa0aca3c65 win32 font is very small if the lfHeight of HFONT is exactly -size
cairo_win32_font_face_create_for_hfont is reusing the HFONT object
passed by an argument if possible to create a scaled font. However,
the condition was wrong. It checked the font matrix scale factor is
`-lfHeight`. But it should be `-lfHeight * WIN32_FONT_LOGICAL_SCALE`.

Fixes cairo/cairo#3
2023-03-03 04:15:10 +09:00
Adrian Johnson
beb28b7679 Merge branch 'dont-free-nonheap-object' into 'master'
Open-code bbtree_del to avoid free()ing a non-allocated object

Closes #645

See merge request cairo/cairo!465
2023-03-01 21:22:28 +00:00
Matt Turner
2cd4256652 Open-code bbtree_del to avoid free()ing a non-allocated object
As we do already in _cairo_recording_surface_finish. Otherwise, the
cleanup path of _cairo_recording_surface_create_bbtree() could call
free() on surface->bbtree which is not dynamically allocated.

Closes: https://gitlab.freedesktop.org/cairo/cairo/-/issues/645
2023-03-01 13:07:49 -05:00
Adrian Johnson
70e37e23d3 Merge branch 'dwrite-clip-glyphs' into 'master'
DWrite: region clipping didn't work on win32 surfaces

Closes #641

See merge request cairo/cairo!464
2023-03-01 09:40:05 +00:00
Fujii Hironori
1b62ef3e55 DWrite: region clipping didn't work on win32 surfaces
The following clipping text tests of win32/rgb24 target were visibly
failing because clipping didn't work.

* clip-text
* partial-clip-text-bottom
* partial-clip-text-left
* partial-clip-text-right
* partial-clip-text-top

_cairo_win32_gdi_compositor_glyphs sets the clip. However,
_cairo_dwrite_show_glyphs_on_surface unset it.

Fixes cairo/cairo#641
2023-03-01 13:55:20 +09:00
Adrian Johnson
17114f522b Merge branch 'dwrite-a8-glyph-mask' into 'master'
DWrite: Support antialias and subpixel order font options

See merge request cairo/cairo!460
2023-02-27 08:11:53 +00:00
Fujii Hironori
c33383b10d DWrite: Support antialias and subpixel order font options
Create a new IDWriteRenderingParams object from the given font
options.
2023-02-27 11:55:30 +09:00
Fujii Hironori
950e3fb45d Change the workaround of MinGW dwrite_3.h problem
The DWRITE_COLOR_GLYPH_RUN1 struct definition of the old MinGW
dwrite_3.h was invalid. To work around the problem, dw-extra.h defined
the correct struct definition and all necessary API from dwrite_3.h.
This approach needed to redefine all necessary API.

This change added DWRITE_COLOR_GLYPH_RUN1_WORKAROUND struct and use it
for IDWriteColorGlyphRunEnumerator1::GetCurrentRun.
2023-02-27 11:55:30 +09:00
Adrian Johnson
6a5f2140d7 Merge branch 'issue-569-dwrite-inflate-glyph-bounds' into 'master'
DWrite: Inflate glyph bounds 1px vertically too

Closes #569

See merge request cairo/cairo!461
2023-02-20 22:07:16 +00:00
Adrian Johnson
7a8aa5eb97 Merge branch 'fix-doc-for-cairo_matrix_transform_distance' into 'master'
Fix cairo_matrix_transform_distance documentation

See merge request cairo/cairo!462
2023-02-20 08:27:55 +00:00
Fujii Hironori
5ae029c2cc DWrite: Inflate glyph bounds 1px vertically too
The most top and bottom lines of glyphs were clipped in some fonts and
conditions. The glyph bounds were inflated 1px horizontally. It should
inflate vertically too.

Fixes cairo/cairo#569
2023-02-20 14:16:30 +09:00
Uli Schlachter
83db2efe0a Merge branch 'quartz-colorspace' into 'master'
Better color management for improved performance on some apps.

Closes #330

See merge request cairo/cairo!290
2023-02-18 14:00:56 +00:00
Fujii Hironori
26fe448be3 Fix cairo_matrix_transform_distance documentation
* Use dx and dy instead of dx1 and dy1 to match with the arguments
* Use dx_new and dy_new instead of dx2 and dy2 to match with other parts of the documentation
* Use xx, yx, xy, yy instead of a, b, c, d to match with other parts of the documentation
* Remove the last two sentences that doesn't make sense
2023-02-18 15:33:28 +09:00
John Ralls
951a3dd9a7 [quartz]Conditionally Use Main Display ColorSpace instead of kCGColorSpaceDefaultRGB.
The default RGB colorspace must be converted to the GPU's colorspace
    using CGColorTransformConvertUsingCMSConverter. Profiling has shown this
    function to consume as much as 48% of a redraw cycle in gdk-quartz.

    There seems to be no named colorspace that matches the one stored on the
    display, so we use the one associated with the main display. This has
    some risks for users with multiple monitors but in testing with my own
    two-monitor setup, one of which is HDR and the other not, the colorspace
    was the same for both.

    This is applied to quartz surfaces created with
    cairo_quartz_surface_create(); surfaces created with
    cairo_quartz_surface_create_for_cg_context will inherit the colorspace
    from the context.

    In order to generate PNGs that look right I've converted the
    existing debugging functions for writing a quartz surface to png
    into private functions and wired cairo-boilerplate-quartz to use
    them. Using the generic cairo routine produced washed-out PNGs.

    Fixes https://gitlab.freedesktop.org/cairo/cairo/-/issues/330
2023-02-17 10:25:14 -08:00
Uli Schlachter
d7b9695ee4 Merge branch 'quartz-image-surface' into 'master'
[quartz] Cleanup and make better use of cairo_quartz_image_surface_t.

See merge request cairo/cairo!317
2023-02-17 16:56:55 +00:00
Adrian Johnson
b7d8da7d1f Merge branch 'issue-641-glyph-bounds' into 'master'
DWrite: clipped glyphs in win32 compositor

Closes #641

See merge request cairo/cairo!459
2023-02-16 10:14:07 +00:00
Adrian Johnson
44d83d206e Merge branch 'dwrite-glyph-phase' into 'master'
DWrite: glyph surfaces should take subpixel positions into account

Closes #597

See merge request cairo/cairo!456
2023-02-16 09:49:54 +00:00
John Ralls
e5ed09a1ab [quartz] Replace surface-pattern xfail with latest CI fail image. 2023-02-14 11:53:02 -08:00
John Ralls
6b1b14a236 [quartz] Pretty up the surface-type and zero-size tests. 2023-02-14 11:53:02 -08:00
John Ralls
198d1792cf [quartz] Cleanup and make better use of cairo_quartz_image_surface_t.
Use a CGBitmapContext mapping the underlying image surface's data instead
of maintaining a CGImage. Generalize the quartz surface snapshot mechanism
to work with both cairo_quartz_surface_t and cairo_quartz_image_surface_t
and to use the latter to get a CGContext around non-quartz surfaces.
Use this snapshot machanism to get a CGImageRef when needed from a
cairo_quartz_image_surface_t.
2023-02-14 11:52:57 -08:00
Fujii Hironori
cce89abbb9 DWrite: clipped glyphs in win32 compositor
The win32 compositor is using _cairo_dwrite_show_glyphs_on_surface for
DWrite. It was assuming that a glyph was painted inside 3x3 of the em
square. It should take the actual glyph bounding box by using
GetAlphaTextureBounds.

Fixes cairo/cairo#641
2023-02-14 05:29:47 +09:00
Adrian Johnson
6b5519626c Merge branch 'ft-use-outline-glyph-for-path' into 'master'
FT: Always use the outline glyph to get the path

See merge request cairo/cairo!455
2023-02-11 04:18:18 +00:00
Adrian Johnson
7f6526e652 Merge branch 'enable-colorv1-fonts' into 'master'
Enable COLRv1 fonts

See merge request cairo/cairo!454
2023-02-11 04:18:09 +00:00
Adrian Johnson
f2f2d20a36 Merge branch 'fix-valgrind-errors' into 'master'
Fix some problems found by valgrind

See merge request cairo/cairo!452
2023-02-11 04:18:03 +00:00
Fujii Hironori
adcd1e7325 DWrite: glyph surfaces should take subpixel positions into account
Shift the glyph position by phases taken
by _cairo_scaled_glyph_xphase and _cairo_scaled_glyph_yphase.

Fixes #597
2023-02-10 10:05:57 +09:00
Adrian Johnson
876ee0bb49 Merge branch 'dwrite-argb-glyph-mask' into 'master'
DWrite: Don't convert subpixel antialiasing to grayscale

See merge request cairo/cairo!453
2023-02-09 20:47:44 +00:00
Adrian Johnson
3fc3d8b8f0 FT: Always use the outline glyph to get the path
Trying to extract the path from a color recording does not work in all
cases such as paths in groups.
2023-02-09 20:46:04 +10:30
Adrian Johnson
d01222a693 Enable COLRv1 fonts
Now that FreeType 2.13.0 has been released with a stable COLRv1 API,
the meson configuration can be updated to enable COLRv1 when this
version is available.
2023-02-09 20:09:08 +10:30
Fujii Hironori
1d8032c406 DWrite: Don't convert subpixel antialiasing to grayscale
Reuse the win32 font code to create a glyph mask for a dwrite font.
Renamed a function _compute_mask in cairo-win32-font.c to
_cairo_compute_glyph_mask.
2023-02-09 13:19:36 +09:00
Adrian Johnson
cae2376dd0 Merge branch 'doc-fixes' into 'master'
More random doc fixes

See merge request cairo/cairo!437
2023-02-08 09:53:29 +00:00
Adrian Johnson
a23af71c9d Merge branch 'remove-unused-tee-function' into 'master'
Remove unused _cairo_tee_surface_find_match

See merge request cairo/cairo!447
2023-02-08 09:48:29 +00:00
Adrian Johnson
fe7f1d8cb4 Merge branch 'warnings' into 'master'
Fix some compiler warnings

See merge request cairo/cairo!427
2023-02-08 09:47:42 +00:00
Adrian Johnson
e85c242f0a Implement a font options compare function and use it in gstate
Valgrind is not happy with the memcmp() to compare font options and it
won't work correctly with variations and custom_palette.
2023-02-08 20:09:15 +10:30
Adrian Johnson
4fbc2ea386 truetype: revert use of _cairo_strndup
3d102f25 changed the malloc/memcpy to _cairo_strndup but it won't work
in this case as the string may be UTF-16.
2023-02-08 20:05:52 +10:30
Adrian Johnson
f706ad5aa3 Merge branch 'bug-611-glyph-path' into 'master'
DWrite: More accurate glyph paths for small fonts

Closes #611

See merge request cairo/cairo!451
2023-02-07 21:21:19 +00:00
Fujii Hironori
db4c941c34 DWrite: More accurate glyph paths for small fonts
Applying a transformation matrix to a glyph path after converting
floats to fixed point numbers caused caluculation errors. Apply the
transform before the conversion.

Fixes cairo/cairo#611
2023-02-08 05:41:07 +09:00
Emmanuele Bassi
7f334e0479 Merge branch 'fix-error-handling-docs' into 'master'
Docs: Remove out of date remarks

See merge request cairo/cairo!450
2023-02-07 11:20:56 +00:00
Adrian Johnson
5ede164a61 doc: remove out of date remarks 2023-02-07 21:10:28 +10:30
Khaled Hosny
a74ef93d82 Fix -Wunused-function warnings 2023-02-06 11:42:00 +02:00
Khaled Hosny
59c195dc82 Fix -Wlogical-not-parentheses
The code is doing "if (!double_buf_equal () != 0)" which seems to be a
convoluted way to do "if (!double_buf_equal ())". Fixes:

../test/pattern-getters.c:153:6: warning: logical not is only applied to the left hand side of this comparison [-Wlogical-not-parentheses]
        if (!double_buf_equal (ctx, new_buf, expected_values,
            ^
../test/pattern-getters.c:153:6: note: add parentheses after the '!' to evaluate the comparison first
        if (!double_buf_equal (ctx, new_buf, expected_values,
            ^
             (
../test/pattern-getters.c:153:6: note: add parentheses around left hand side expression to silence this warning
        if (!double_buf_equal (ctx, new_buf, expected_values,
            ^
            (
2023-02-06 11:39:08 +02:00