Commit graph

57 commits

Author SHA1 Message Date
Adrian Johnson
8da24bf7fb Make _cairo_calloc() consistent with _cairo_malloc()
ie

  _cairo_calloc(size)
  _cairo_calloc_ab(a, size)
2024-06-21 08:53:01 +09:30
Adrian Johnson
3715d93bdf Create _cairo_calloc() macro to replace calloc()
Not all platforms handle a zero sized allocation in calloc the
same. This macro ensures that _cairo_calloc(0) always returns NULL
similar to _cairo_malloc(0).
2024-05-21 20:20:49 +09:30
Adrian Johnson
293b75a1c4 Update CI to Fedora 40 2024-04-28 21:28:41 +09:30
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
Adrian Johnson
fea2463107 Support color fonts that use the foreground color
COLR fonts can have a layer with the same color as the current text
color. This change passes the current color (if solid) through to
the font backend where it can be used to render color fonts.

scaled_glyph_lookup checks if the foreground color has changed (for
glyph that require it) and requests a new color surface if required.

This also fixes a bug where scaled_glyph_lookup would always request a
color surface for glyphs for glyphs in color fonts that do not have
color.
2021-08-28 18:07:01 +09:30
Adrian Johnson
1998239387 Use _cairo_malloc instead of malloc
_cairo_malloc(0) always returns NULL, but has not been used
consistently.  This patch replaces many calls to malloc() with
_cairo_malloc().

Fixes:  fdo# 101547
CVE: CVE-2017-9814 Heap buffer overflow at cairo-truetype-subset.c:1299
Reviewed-by: Bryce Harrington <bryce@osg.samsung.com>
2018-05-07 16:35:51 -07:00
Adrian Johnson
1220e3c6b8 replace _BSD_SOURCE with _DEFAULT_SOURCE
fixes the warning:

warning: #warning "_BSD_SOURCE and _SVID_SOURCE are deprecated, use _DEFAULT_SOURCE"
2017-09-16 10:04:57 +09:30
Chris Wilson
af9fbd176b Introduce a new compositor architecture
Having spent the last dev cycle looking at how we could specialize the
compositors for various backends, we once again look for the
commonalities in order to reduce the duplication. In part this is
motivated by the idea that spans is a good interface for both the
existent GL backend and pixman, and so they deserve a dedicated
compositor. xcb/xlib target an identical rendering system and so they
should be using the same compositor, and it should be possible to run
that same compositor locally against pixman to generate reference tests.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>

P.S. This brings massive upheaval (read breakage) I've tried delaying in
order to fix as many things as possible but now this one patch does far,
far, far too much. Apologies in advance for breaking your favourite
backend, but trust me in that the end result will be much better. :)
2011-09-12 08:29:48 +01:00
Chris Wilson
b132fae5e8 clip: Rudimentary support for clip-polygon extraction
Step 1, fix the failings sighted recently by tracking clip-boxes as an
explicit property of the clipping and of composition.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2011-07-19 21:14:34 +01:00
Andrea Canciani
a8ae8759f5 path: Always interpret in forward direction
Path are always interpreted in forward direction, so the ability of
interpreting in the opposite direction (which is very unlikely to be
useful at all) can be removed.
2010-12-10 10:58:51 +01:00
Andrea Canciani
1ab6496578 array: Silence warnings
493aaf0f15 made all cairo_array
functions use unsigned int for indexes and sizes.

This commit fixes the compiler warnings about those values being
compared to signed int's.
2010-11-26 13:14:37 +01:00
Adrian Johnson
74873c8224 Fix type1-fallback bbox 2010-11-06 21:15:30 +10:30
Adrian Johnson
52f3db92a7 Type 1 fallback: add support for latin subsets
For latin subsets the /Encoding array maps the latin encoding to the
font glyphs.
2010-10-01 19:15:30 +09:30
Adrian Johnson
edcefa87ed type1: Use correct glyph advance when subsetting type 1 fonts
Previously the glyph advance in font units was used for the widths in
the PDF font dictionary. This only works for Type 1 fonts that use a
[0.001 0 0 0.001 0 0] font matrix.

https://bugs.freedesktop.org/show_bug.cgi?id=28061
2010-05-16 20:52:31 +09:30
Andrea Canciani
b8a7f8621a Update FSF address
I updated the Free Software Foundation address using the following script.

for i in $(git grep Temple | cut -d: -f1 )
do
  sed -e 's/59 Temple Place[, -]* Suite 330, Boston, MA *02111-1307[, ]* USA/51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA/' -i "$i"
done

Fixes http://bugs.freedesktop.org/show_bug.cgi?id=21356
2010-04-27 11:13:38 +02:00
Chris Wilson
c50c8b90c0 Move _cairo_error() to a standalone header
A pending commit will want to include some utility code from cairo and
so we need to extricate the error handling from the PLT symbol hiding.
2010-01-22 22:30:43 +00:00
Chris Wilson
8362c6f726 [type1] Fixup error path during write_charstrings()
On the common error path we attempted to unlock a mutex that was not
always held, so reorder the error paths appropriately.
2009-03-31 12:16:02 +01:00
Chris Wilson
bcb2724920 [path] Mark points as const during _cairo_path_fixed_interpret()
Use const to document the read-only nature of the arguments passed to the
callbacks.
2008-12-12 11:11:49 +00:00
Chris Wilson
e6963a5bfe Mark allocation failures as unlikely.
Use the gcc likelihood annotation to indicate that allocation failures are
extremely unlikely.
2008-11-29 11:20:34 +00:00
Chris Wilson
d1801c23fa Mark if(status) as being unlikely.
The error paths should be hit very rarely during normal operation, so mark
them as being unlikely so gcc may emit better code.
2008-11-29 11:20:33 +00:00
Chris Wilson
47a56e0850 [type1] Bind the RD procedure
As the RD procedure may be called several hundred times for a full font,
it is worth binding.
2008-11-13 11:36:50 +00:00
Chris Wilson
1db8949f2b Ensure that the scaled font is frozen for the lifetime of the scaled glyph.
After discussing the scaled font locking with Behdad, it transpired that it
is not sufficient for a font to be locked for the lifetime of a scaled glyph,
but that the scaled font's glyph cache must be frozen for the glyph'
lifetime.  If the cache is not frozen, then there is a possibility that the
glyph may be evicted before the reference goes out of scope i.e. the glyph
becomes invalid whilst we are trying to use it.

Since the freezing of the cache is the stronger barrier, we remove the
locking/unlocking of the mutex from the backends and instead move the
mutex acquisition into the freeze/thaw routines. Then update the rule on
acquiring glyphs to enforce that the cache is frozen and review the usage
of freeze/thaw by all the backends to ensure that the cache is frozen for
the lifetime of the glyph.
2008-10-22 00:53:55 +01:00
Chris Wilson
12fb8c9b7c [type1] Acquire scaled_font mutex.
In order to perform glyph lookups we need to be holding the mutex for the
scaled_font.
2008-10-19 09:36:51 +01:00
Behdad Esfahbod
5926257770 Revamp the build system.
Quick summary of changes:

  - Move list of cairo source files out of src/Makefile.am and into
    src/Sources.mk,

  - Generate files src/Config.mk and src/Config.mk.win32 that choose
    the right set of source files and headers based on configured
    backends and features.  This drastically simplifies building
    using other build systems.  The src/Makefile.win32 file needs
    to be updated to reflect these changes.

  - Add README files to various directories,

  - Add toplevel HACKING file.
2008-09-02 20:24:08 -04:00
Adrian Johnson
0d5902b716 Type1-fallback: Use correct glyph metrics for .notdef glyph
Bug 15348 references the following PDF that was printing incorrectly
when running through poppler and cairo to generate PostScript.

http://launchpadlibrarian.net/12921700/UbuntuDesktop.pdf

The PostScript output had too much space between each word causing
strings of glyphs printed with the TJ operator to overlap.

The original PDF file contains an CFF font with CID Identity-H
encoding. The PDF file is using character code 0 (glyph 0 due to
Identity-H encoding) as a space character. The CFF specification
defines glyph 0 to be the .notdef glyph.

The PS backend subsets CFF fonts as a Type1-fallback
font. Type1-fallback creates it's own empty .notdef glyph with an
arbitrary glyph advance of 500. The problem here is the TJ operator
used to output the glyphs depends on the glyph advance being
correct. pdf-operators.c uses the glyph advance returned by
_scaled_glyph_init(). However the PostScript interpreter sees the
glyph advance of 500 for .notdef. This problem does not occur when
generating PDF as the PDF font dictionary contains an list of glyph
advances that override the font metrics.

Fix this by making Type1-fallback not treat .notdef as special and to
create it the path and metrics obtained from _scaled_glyph_init(). As
a special case, make it not fail if _scaled_glyph_init() is unable to
return a path for .notdef. This was probably the reason Type1-fallback
previously created it's own .notdef glyph as calling
_scaled_glyph_init(_GLYPH_INFO_PATH) for glyph 0 returns
CAIRO_INT_STATUS_UNSUPPORTED for some fonts.

This ensures the Type1-fallback font metrics match the metrics used
by pdf-operators.c to position the glyphs. This also results in the
removal of some duplicated code.
2008-04-06 00:36:02 +10:30
Adrian Johnson
03d2b098ff Type1-fallback: Use correct glyph advance in Type 1 charstrings
5050c55f93 fixed type1-fallback to use the glyph advance instead of
glyph width in the stored glyph metrics in the font. However it did
not fix the same bug in Type 2 charstrings (used by CFF fallback in
PDF). This problem was not noticed since the glyph widths in the PDF
font dictionary overrides these values.

Fix this in case any software reading cairo PDFs uses these values.
2008-04-06 00:36:02 +10:30
Adrian Johnson
5050c55f93 Use the correct glyph metrics in Type1 fallback
Now that the PS backend is using PDF operators, it uses the glyph
metrics in the font to position each glyph in a string. This exposed a
bug in Type 1 fallback where the glyph width and height was used in
the charstrings instead of x_advance/y_advance. This was causing
strings to print diagonally due to the no zero y_advance.
2008-03-13 21:37:32 +10:30
Chris Wilson
222eb6f140 Define _BSD_SOURCE to enable prototypes for strdup, snprintf.
strdup() and friends require at least _BSD_SOURCE or
_XOPEN_SOURCE >= 500 to be defined for the prototypes to be included.
For the time being, add the define to each source file that requires one
of the BSD functions.
2008-03-12 17:52:16 +00:00
Chris Wilson
3b93d90edd [cairo-type1-fallback] Propagate original error status.
_cairo_error() has already been called at the originating error site, so
remove the duplicate (hard-coded!) call at the return statement.
2008-03-04 09:31:20 +00:00
Chris Wilson
5cbc45488e [cairo-output-stream] Introduce _cairo_output_stream_create_in_error()
Use a utility function to wrap an incoming error status into a new
error stream. As a side-effect, all error streams must be destroyed as
in the general case the caller can not distinguish between a static
error object and one allocated to hold an unusual error status.
2008-01-16 16:40:01 +00:00
Adrian Johnson
1441e165f2 Fix regression in Type1 Fallback
As a result of the changes to improve the status checking,
_cairo_type2_charstrings_init() was failing due to the failure
status returned when the font->output stream is destroyed.
This is because _cairo_type2_charstrings_init() does not
create an output stream.

Fix this by initializing font->output to NULL and only
destroy it if not NULL.
2007-12-02 00:50:28 +10:30
Adrian Johnson
5af1b2280b Make PostScript output text selectable
The glyph names used in the Type42 and Type1 fallback fonts are now of
the form "/uniXXXX" where XXXX is the unicode character for each
glyph. When converted to pdf (eg using ps2pdf), pdf viewers are now
able to correctly extract the text.
2007-10-14 00:11:57 +09:30
Chris Wilson
b8d7d62b08 Fix some trivial syntax warnings for -ansi.
gcc -ansi -pedantic gives a few syntax warnings, principally for use of
'//' comments and a comma at the end of enumerators. Apply these
corrections as they are trivial.
2007-10-10 14:56:52 +01:00
Chris Wilson
29a5aae958 [cairo-type1-fallback] Propagate error from closing the stream.
Propagate the error from destroying the font and closing the output stream.
2007-10-05 15:24:25 +01:00
Chris Wilson
bed8239f03 [cairo-error] Clean up all the warnings and missing _cairo_error() calls.
Every time we assign or return a hard-coded error status wrap that value
with a call to _cairo_error(). So the idiom becomes:
    status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
or
    return _cairo_error (CAIRO_STATUS_INVALID_DASH);

This ensures that a breakpoint placed on _cairo_error() will trigger
immediately cairo detects the error.
2007-10-04 13:31:44 +01:00
Chris Wilson
8ad56b308a [malloc/error] Add call to _cairo_error() after a failed malloc.
Blitz all allocations to ensure that they raise a
_cairo_error(CAIRO_STATUS_NO_MEMORY) on failure.
2007-10-04 00:42:30 +01:00
Chris Wilson
ab6a767cf4 [cairo-scaled-font] Check for allocation failure.
cairo_scaled_font_create() returns a nil object on failure whereas a few
callers were checking for NULL.

Secondly review the public entry points for cairo_scaled_font_*() to
ensure that all check that they will not attempt to overwrite the
read-only nil object.
2007-05-10 17:18:27 +01:00
Adrian Johnson
0c2a653033 Add CFF CID Fallback
Switching to CID font embedding requires a fallback font for
the case where CFF CID or TrueType CID subsetting fails.

The new function _cairo_type2_charstrings_init() added to
cairo-type1-fallback.c creates Type2 charstrings from glyph
paths. _cairo_cff_fallback_init() in cairo-cff-subset.c
wraps these charstrings in a CFF CID font.
2007-04-20 22:30:55 +09:30
Adrian Johnson
073fce5a85 Add support for creating CID/composite font subsets
cairo-scaled-font-subsets.c now provides three functions for creating subsets:

  _cairo_scaled_font_subsets_create_scaled()
    Create a subset for each scaled font with maximum size INT_MAX.

  _cairo_scaled_font_subsets_create_simple()
    Create subsets suitable for embedding as simple fonts in PS/PDF.

  _cairo_scaled_font_subsets_create_composite()
    Create subsets suitable for embedding as composite fonts in PS/PDF.

The _create_simple() and _create_composite() functions both merge
scaled fonts with the same face and an outline path available into
the same subset. _create_composite() has a maximum subset size of
65536 for outline fonts. Bitmap fonts have a separate subset for
each scale with a maximum subset size of 256.

The _create_simple() and _create_composite() functions both reserve
the first glyph in the subset for the .notdef glyph. CID fonts require
CID 0 to be .notdef.

Update Type1, TrueType and CFF subsetting to expect glyph 0 of each
subset to be the .notdef.
2007-04-20 22:29:41 +09:30
Carl Worth
bd98295100 Add a couple of missing newline characters
A return statement that's not at the end of a function really needs
a line of whitespace after it.
2007-04-10 10:14:48 -07:00
Chris Wilson
b4cb0306b4 cairo-type1-fallback - propagate error returns
Add status returns in order to propagate a matrix inversion failure
up through the call stack.
2007-04-09 16:06:51 -07:00
Chris Wilson
a34a32fd99 cairo-type1-fallback - check for an error during cleanup
The cleanup path is shared between the error path and the true path, and
so any error along it can not be ignored.
2007-04-09 15:07:27 +01:00
Behdad Esfahbod
62e864e73c [Type1] Add cairo-type1-private.h that Type1 fallback and subset code share 2007-03-07 16:02:08 -05:00
Carl Worth
cd43c03d16 Fix leak of an output stream in cairo_type1_font_destroy 2007-03-02 12:30:53 -08:00
Behdad Esfahbod
ded08256ef Spell check the docs 2007-01-07 02:08:15 -05:00
Adrian Johnson
9e4a48557e type1 fallback: ensure all functions perform correct status checking 2006-10-23 23:17:06 +09:30
Christian Biesinger
bd5d7c1fb2 Don't return an uninitialized value if _cairo_output_stream_create fails 2006-10-22 20:10:02 +02:00
Christian Biesinger
153f2d1cad Actually return a value from _cairo_type1_fallback_init_* 2006-10-22 20:10:02 +02:00
Adrian Johnson
216c759d46 Type 1 fallback fonts - use binary encoding in PDF files
PDF files require that embedded Type 1 fonts have the encrypted
portion of the font encoded in binary.
2006-10-15 23:07:38 +09:30
Adrian Johnson
9ee0c15941 cairo-type1-fallback.c: return correct error status 2006-10-15 22:48:43 +09:30