1 /* cairo - a vector graphics library with display and print output
2  *
3  * Copyright © 2002 University of Southern California
4  * Copyright © 2005 Red Hat, Inc.
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it either under the terms of the GNU Lesser General Public
8  * License version 2.1 as published by the Free Software Foundation
9  * (the "LGPL") or, at your option, under the terms of the Mozilla
10  * Public License Version 1.1 (the "MPL"). If you do not alter this
11  * notice, a recipient may use your version of this file under either
12  * the MPL or the LGPL.
13  *
14  * You should have received a copy of the LGPL along with this library
15  * in the file COPYING-LGPL-2.1; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA
17  * You should have received a copy of the MPL along with this library
18  * in the file COPYING-MPL-1.1
19  *
20  * The contents of this file are subject to the Mozilla Public License
21  * Version 1.1 (the "License"); you may not use this file except in
22  * compliance with the License. You may obtain a copy of the License at
23  * http://www.mozilla.org/MPL/
24  *
25  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
26  * OF ANY KIND, either express or implied. See the LGPL or the MPL for
27  * the specific language governing rights and limitations.
28  *
29  * The Original Code is the cairo graphics library.
30  *
31  * The Initial Developer of the Original Code is University of Southern
32  * California.
33  *
34  * Contributor(s):
35  *	Carl D. Worth <cworth@cworth.org>
36  */
37 
38 /*
39  * These definitions are solely for use by the implementation of cairo
40  * and constitute no kind of standard.  If you need any of these
41  * functions, please drop me a note.  Either the library needs new
42  * functionality, or there's a way to do what you need using the
43  * existing published interfaces. cworth@cworth.org
44  */
45 
46 #ifndef _CAIROINT_H_
47 #define _CAIROINT_H_
48 
49 #if HAVE_CONFIG_H
50 #include "config.h"
51 #endif
52 
53 #ifdef _MSC_VER
54 #define cairo_public __declspec(dllexport)
55 #endif
56 
57 #include <assert.h>
58 #include <stdlib.h>
59 #include <string.h>
60 #include <stdarg.h>
61 #include <stddef.h>
62 
63 #ifdef _MSC_VER
64 #define _USE_MATH_DEFINES
65 #endif
66 #include <math.h>
67 #include <limits.h>
68 #include <stdio.h>
69 
70 #include "cairo.h"
71 #include <pixman.h>
72 
73 #include "cairo-compiler-private.h"
74 #include "cairo-error-private.h"
75 
76 #if CAIRO_HAS_PDF_SURFACE    || \
77     CAIRO_HAS_PS_SURFACE     || \
78     CAIRO_HAS_SCRIPT_SURFACE || \
79     CAIRO_HAS_XML_SURFACE
80 #define CAIRO_HAS_DEFLATE_STREAM 1
81 #endif
82 
83 #if CAIRO_HAS_PS_SURFACE  || \
84     CAIRO_HAS_PDF_SURFACE || \
85     CAIRO_HAS_SVG_SURFACE || \
86     CAIRO_HAS_WIN32_SURFACE
87 #define CAIRO_HAS_FONT_SUBSET 1
88 #endif
89 
90 #if CAIRO_HAS_PS_SURFACE  || \
91     CAIRO_HAS_PDF_SURFACE || \
92     CAIRO_HAS_FONT_SUBSET
93 #define CAIRO_HAS_PDF_OPERATORS 1
94 #endif
95 
96 CAIRO_BEGIN_DECLS
97 
98 #if _WIN32 && !_WIN32_WCE /* Permissions on WinCE? No worries! */
99 cairo_private FILE *
100 _cairo_win32_tmpfile (void);
101 #define tmpfile() _cairo_win32_tmpfile()
102 #endif
103 
104 #undef MIN
105 #define MIN(a, b) ((a) < (b) ? (a) : (b))
106 
107 #undef MAX
108 #define MAX(a, b) ((a) > (b) ? (a) : (b))
109 
110 #if _XOPEN_SOURCE >= 600 || defined (_ISOC99_SOURCE)
111 #define ISFINITE(x) isfinite (x)
112 #else
113 #define ISFINITE(x) ((x) * (x) >= 0.) /* check for NaNs */
114 #endif
115 
116 #ifndef FALSE
117 #define FALSE 0
118 #endif
119 
120 #ifndef TRUE
121 #define TRUE 1
122 #endif
123 
124 #ifndef M_PI
125 #define M_PI 3.14159265358979323846
126 #endif
127 
128 #ifndef M_SQRT2
129 #define M_SQRT2 1.41421356237309504880
130 #endif
131 
132 #ifndef M_SQRT1_2
133 #define M_SQRT1_2 0.707106781186547524400844362104849039
134 #endif
135 
136 #undef  ARRAY_LENGTH
137 #define ARRAY_LENGTH(__array) ((int) (sizeof (__array) / sizeof (__array[0])))
138 
139 #undef STRINGIFY
140 #undef STRINGIFY_ARG
141 #define STRINGIFY(macro_or_string)    STRINGIFY_ARG (macro_or_string)
142 #define STRINGIFY_ARG(contents)       #contents
143 
144 #if defined (__GNUC__)
145 #define cairo_container_of(ptr, type, member) ({ \
146     const __typeof__ (((type *) 0)->member) *mptr__ = (ptr); \
147     (type *) ((char *) mptr__ - offsetof (type, member)); \
148 })
149 #else
150 #define cairo_container_of(ptr, type, member) \
151     ((type *)((char *) (ptr) - (char *) &((type *)0)->member))
152 #endif
153 
154 
155 #define ASSERT_NOT_REACHED		\
156 do {					\
157     assert (!"reached");		\
158 } while (0)
159 #define COMPILE_TIME_ASSERT1(condition, line)		\
160     typedef int compile_time_assertion_at_line_##line##_failed [(condition)?1:-1]
161 #define COMPILE_TIME_ASSERT0(condition, line)	COMPILE_TIME_ASSERT1(condition, line)
162 #define COMPILE_TIME_ASSERT(condition)		COMPILE_TIME_ASSERT0(condition, __LINE__)
163 
164 #define CAIRO_ALPHA_IS_CLEAR(alpha) ((alpha) <= ((double)0x00ff / (double)0xffff))
165 #define CAIRO_ALPHA_SHORT_IS_CLEAR(alpha) ((alpha) <= 0x00ff)
166 
167 #define CAIRO_ALPHA_IS_OPAQUE(alpha) ((alpha) >= ((double)0xff00 / (double)0xffff))
168 #define CAIRO_ALPHA_SHORT_IS_OPAQUE(alpha) ((alpha) >= 0xff00)
169 #define CAIRO_ALPHA_IS_ZERO(alpha) ((alpha) <= 0.0)
170 
171 #define CAIRO_COLOR_IS_CLEAR(color) CAIRO_ALPHA_SHORT_IS_CLEAR ((color)->alpha_short)
172 #define CAIRO_COLOR_IS_OPAQUE(color) CAIRO_ALPHA_SHORT_IS_OPAQUE ((color)->alpha_short)
173 
174 /* Reverse the bits in a byte with 7 operations (no 64-bit):
175  * Devised by Sean Anderson, July 13, 2001.
176  * Source: http://graphics.stanford.edu/~seander/bithacks.html#ReverseByteWith32Bits
177  */
178 #define CAIRO_BITSWAP8(c) ((((c) * 0x0802LU & 0x22110LU) | ((c) * 0x8020LU & 0x88440LU)) * 0x10101LU >> 16)
179 
180 /* Return the number of 1 bits in mask.
181  *
182  * GCC 3.4 supports a "population count" builtin, which on many targets is
183  * implemented with a single instruction. There is a fallback definition
184  * in libgcc in case a target does not have one, which should be just as
185  * good as the open-coded solution below, (which is "HACKMEM 169").
186  */
187 static inline int cairo_const
_cairo_popcount(uint32_t mask)188 _cairo_popcount (uint32_t mask)
189 {
190 #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
191     return __builtin_popcount (mask);
192 #else
193 #ifdef __cplusplus
194     int y;
195 #else
196     register int y;
197 #endif
198 
199     y = (mask >> 1) &033333333333;
200     y = mask - y - ((y >>1) & 033333333333);
201     return (((y + (y >> 3)) & 030707070707) % 077);
202 #endif
203 }
204 
205 static cairo_always_inline cairo_bool_t
_cairo_is_little_endian(void)206 _cairo_is_little_endian (void)
207 {
208     static const int i = 1;
209     return *((char *) &i) == 0x01;
210 }
211 
212 #ifdef WORDS_BIGENDIAN
213 #define CAIRO_BITSWAP8_IF_LITTLE_ENDIAN(c) (c)
214 #else
215 #define CAIRO_BITSWAP8_IF_LITTLE_ENDIAN(c) CAIRO_BITSWAP8(c)
216 #endif
217 
218 #ifdef WORDS_BIGENDIAN
219 
220 #define cpu_to_be16(v) (v)
221 #define be16_to_cpu(v) (v)
222 #define cpu_to_be32(v) (v)
223 #define be32_to_cpu(v) (v)
224 
225 #else
226 
227 static inline uint16_t cairo_const
cpu_to_be16(uint16_t v)228 cpu_to_be16(uint16_t v)
229 {
230     return (v << 8) | (v >> 8);
231 }
232 
233 static inline uint16_t cairo_const
be16_to_cpu(uint16_t v)234 be16_to_cpu(uint16_t v)
235 {
236     return cpu_to_be16 (v);
237 }
238 
239 static inline uint32_t cairo_const
cpu_to_be32(uint32_t v)240 cpu_to_be32(uint32_t v)
241 {
242     return (v >> 24) | ((v >> 8) & 0xff00) | ((v << 8) & 0xff0000) | (v << 24);
243 }
244 
245 static inline uint32_t cairo_const
be32_to_cpu(uint32_t v)246 be32_to_cpu(uint32_t v)
247 {
248     return cpu_to_be32 (v);
249 }
250 
251 #endif
252 
253 /* Unaligned big endian access
254  */
255 
get_unaligned_be16(const unsigned char * p)256 static inline uint16_t get_unaligned_be16 (const unsigned char *p)
257 {
258     return p[0] << 8 | p[1];
259 }
260 
get_unaligned_be32(const unsigned char * p)261 static inline uint32_t get_unaligned_be32 (const unsigned char *p)
262 {
263     return (uint32_t)p[0] << 24 | p[1] << 16 | p[2] << 8 | p[3];
264 }
265 
put_unaligned_be16(uint16_t v,unsigned char * p)266 static inline void put_unaligned_be16 (uint16_t v, unsigned char *p)
267 {
268     p[0] = (v >> 8) & 0xff;
269     p[1] = v & 0xff;
270 }
271 
put_unaligned_be32(uint32_t v,unsigned char * p)272 static inline void put_unaligned_be32 (uint32_t v, unsigned char *p)
273 {
274     p[0] = (v >> 24) & 0xff;
275     p[1] = (v >> 16) & 0xff;
276     p[2] = (v >> 8)  & 0xff;
277     p[3] = v & 0xff;
278 }
279 
280 /* The glibc versions of ispace() and isdigit() are slow in UTF-8 locales.
281  */
282 
283 static inline int cairo_const
_cairo_isspace(int c)284 _cairo_isspace (int c)
285 {
286     return (c == 0x20 || (c >= 0x09 && c <= 0x0d));
287 }
288 
289 static inline int cairo_const
_cairo_isdigit(int c)290 _cairo_isdigit (int c)
291 {
292     return (c >= '0' && c <= '9');
293 }
294 
295 static inline int cairo_const
_cairo_isalpha(int c)296 _cairo_isalpha (int c)
297 {
298     return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
299 }
300 
301 #include "cairo-types-private.h"
302 #include "cairo-cache-private.h"
303 #include "cairo-reference-count-private.h"
304 #include "cairo-spans-private.h"
305 #include "cairo-surface-private.h"
306 
307 cairo_private void
308 _cairo_box_from_doubles (cairo_box_t *box,
309 			 double *x1, double *y1,
310 			 double *x2, double *y2);
311 
312 cairo_private void
313 _cairo_box_to_doubles (const cairo_box_t *box,
314 		       double *x1, double *y1,
315 		       double *x2, double *y2);
316 
317 cairo_private void
318 _cairo_box_from_rectangle (cairo_box_t                 *box,
319 			   const cairo_rectangle_int_t *rectangle);
320 
321 cairo_private void
322 _cairo_box_round_to_rectangle (const cairo_box_t     *box,
323 			       cairo_rectangle_int_t *rectangle);
324 
325 cairo_private void
326 _cairo_box_add_curve_to (cairo_box_t         *extents,
327 			 const cairo_point_t *a,
328 			 const cairo_point_t *b,
329 			 const cairo_point_t *c,
330 			 const cairo_point_t *d);
331 
332 cairo_private void
333 _cairo_boxes_get_extents (const cairo_box_t *boxes,
334 			  int num_boxes,
335 			  cairo_box_t *extents);
336 
337 cairo_private extern const cairo_rectangle_int_t _cairo_empty_rectangle;
338 cairo_private extern const cairo_rectangle_int_t _cairo_unbounded_rectangle;
339 
340 static inline void
_cairo_unbounded_rectangle_init(cairo_rectangle_int_t * rect)341 _cairo_unbounded_rectangle_init (cairo_rectangle_int_t *rect)
342 {
343     *rect = _cairo_unbounded_rectangle;
344 }
345 
346 cairo_private_no_warn cairo_bool_t
347 _cairo_rectangle_intersect (cairo_rectangle_int_t *dst,
348 			    const cairo_rectangle_int_t *src);
349 
350 static inline cairo_bool_t
_cairo_rectangle_intersects(const cairo_rectangle_int_t * dst,const cairo_rectangle_int_t * src)351 _cairo_rectangle_intersects (const cairo_rectangle_int_t *dst,
352 			     const cairo_rectangle_int_t *src)
353 {
354     return !(src->x >= dst->x + (int) dst->width ||
355 	     src->x + (int) src->width <= dst->x ||
356 	     src->y >= dst->y + (int) dst->height ||
357 	     src->y + (int) src->height <= dst->y);
358 }
359 
360 static inline cairo_bool_t
_cairo_rectangle_contains_rectangle(const cairo_rectangle_int_t * a,const cairo_rectangle_int_t * b)361 _cairo_rectangle_contains_rectangle (const cairo_rectangle_int_t *a,
362 				     const cairo_rectangle_int_t *b)
363 {
364     return (a->x <= b->x &&
365 	    a->x + (int) a->width >= b->x + (int) b->width &&
366 	    a->y <= b->y &&
367 	    a->y + (int) a->height >= b->y + (int) b->height);
368 }
369 
370 cairo_private void
371 _cairo_rectangle_int_from_double (cairo_rectangle_int_t *recti,
372 				  const cairo_rectangle_t *rectf);
373 
374 /* Extends the dst rectangle to also contain src.
375  * If one of the rectangles is empty, the result is undefined
376  */
377 cairo_private void
378 _cairo_rectangle_union (cairo_rectangle_int_t *dst,
379 			const cairo_rectangle_int_t *src);
380 
381 cairo_private cairo_bool_t
382 _cairo_box_intersects_line_segment (const cairo_box_t *box,
383 	                            cairo_line_t *line) cairo_pure;
384 
385 cairo_private cairo_bool_t
386 _cairo_spline_intersects (const cairo_point_t *a,
387 			  const cairo_point_t *b,
388 			  const cairo_point_t *c,
389 			  const cairo_point_t *d,
390 			  const cairo_box_t *box) cairo_pure;
391 
392 typedef struct {
393     const cairo_user_data_key_t *key;
394     void *user_data;
395     cairo_destroy_func_t destroy;
396 } cairo_user_data_slot_t;
397 
398 cairo_private void
399 _cairo_user_data_array_init (cairo_user_data_array_t *array);
400 
401 cairo_private void
402 _cairo_user_data_array_fini (cairo_user_data_array_t *array);
403 
404 cairo_private void *
405 _cairo_user_data_array_get_data (cairo_user_data_array_t     *array,
406 				 const cairo_user_data_key_t *key);
407 
408 cairo_private cairo_status_t
409 _cairo_user_data_array_set_data (cairo_user_data_array_t     *array,
410 				 const cairo_user_data_key_t *key,
411 				 void			     *user_data,
412 				 cairo_destroy_func_t	      destroy);
413 
414 cairo_private cairo_status_t
415 _cairo_user_data_array_copy (cairo_user_data_array_t		*dst,
416 			     const cairo_user_data_array_t	*src);
417 
418 cairo_private void
419 _cairo_user_data_array_foreach (cairo_user_data_array_t     *array,
420 				void (*func) (const void *key,
421 					      void *elt,
422 					      void *closure),
423 				void *closure);
424 
425 #define _CAIRO_HASH_INIT_VALUE 5381
426 
427 cairo_private unsigned long
428 _cairo_hash_string (const char *c);
429 
430 cairo_private unsigned long
431 _cairo_hash_bytes (unsigned long hash,
432 		   const void *bytes,
433 		   unsigned int length);
434 
435 /* We use bits 24-27 to store phases for subpixel positions */
436 #define _cairo_scaled_glyph_index(g) ((g)->hash_entry.hash & 0xffffff)
437 #define _cairo_scaled_glyph_xphase(g) (int)(((g)->hash_entry.hash >> 24) & 3)
438 #define _cairo_scaled_glyph_yphase(g) (int)(((g)->hash_entry.hash >> 26) & 3)
439 #define _cairo_scaled_glyph_set_index(g, i)  ((g)->hash_entry.hash = (i))
440 
441 #include "cairo-scaled-font-private.h"
442 
443 struct _cairo_font_face {
444     /* hash_entry must be first */
445     cairo_hash_entry_t hash_entry;
446     cairo_status_t status;
447     cairo_reference_count_t ref_count;
448     cairo_user_data_array_t user_data;
449     const cairo_font_face_backend_t *backend;
450 };
451 
452 cairo_private void
453 _cairo_default_context_reset_static_data (void);
454 
455 cairo_private void
456 _cairo_toy_font_face_reset_static_data (void);
457 
458 cairo_private void
459 _cairo_ft_font_reset_static_data (void);
460 
461 cairo_private void
462 _cairo_win32_font_reset_static_data (void);
463 
464 #if CAIRO_HAS_COGL_SURFACE
465 void
466 _cairo_cogl_context_reset_static_data (void);
467 #endif
468 
469 /* the font backend interface */
470 
471 struct _cairo_unscaled_font_backend {
472     cairo_bool_t (*destroy) (void	*unscaled_font);
473 };
474 
475 /* #cairo_toy_font_face_t - simple family/slant/weight font faces used for
476  * the built-in font API
477  */
478 
479 typedef struct _cairo_toy_font_face {
480     cairo_font_face_t base;
481     const char *family;
482     cairo_bool_t owns_family;
483     cairo_font_slant_t slant;
484     cairo_font_weight_t weight;
485 
486     cairo_font_face_t *impl_face; /* The non-toy font face this actually uses */
487 } cairo_toy_font_face_t;
488 
489 typedef enum _cairo_scaled_glyph_info {
490     CAIRO_SCALED_GLYPH_INFO_METRICS	 = (1 << 0),
491     CAIRO_SCALED_GLYPH_INFO_SURFACE	 = (1 << 1),
492     CAIRO_SCALED_GLYPH_INFO_PATH	 = (1 << 2),
493     CAIRO_SCALED_GLYPH_INFO_RECORDING_SURFACE = (1 << 3),
494     CAIRO_SCALED_GLYPH_INFO_COLOR_SURFACE = (1 << 4)
495 } cairo_scaled_glyph_info_t;
496 
497 typedef struct _cairo_scaled_font_subset {
498     cairo_scaled_font_t *scaled_font;
499     unsigned int font_id;
500     unsigned int subset_id;
501 
502     /* Index of glyphs array is subset_glyph_index.
503      * Value of glyphs array is scaled_font_glyph_index.
504      */
505     unsigned long *glyphs;
506     char          **utf8;
507     char          **glyph_names;
508     int           *to_latin_char;
509     unsigned long *latin_to_subset_glyph_index;
510     unsigned int num_glyphs;
511     cairo_bool_t is_composite;
512     cairo_bool_t is_scaled;
513     cairo_bool_t is_latin;
514 } cairo_scaled_font_subset_t;
515 
516 struct _cairo_scaled_font_backend {
517     cairo_font_type_t type;
518 
519     void
520     (*fini)		(void			*scaled_font);
521 
522     cairo_warn cairo_int_status_t
523     (*scaled_glyph_init)	(void			     *scaled_font,
524 				 cairo_scaled_glyph_t	     *scaled_glyph,
525 				 cairo_scaled_glyph_info_t    info);
526 
527     /* A backend only needs to implement this or ucs4_to_index(), not
528      * both. This allows the backend to do something more sophisticated
529      * then just converting characters one by one.
530      */
531     cairo_warn cairo_int_status_t
532     (*text_to_glyphs) (void                       *scaled_font,
533 		       double		           x,
534 		       double		           y,
535 		       const char	          *utf8,
536 		       int		           utf8_len,
537 		       cairo_glyph_t	         **glyphs,
538 		       int		          *num_glyphs,
539 		       cairo_text_cluster_t      **clusters,
540 		       int		          *num_clusters,
541 		       cairo_text_cluster_flags_t *cluster_flags);
542 
543     unsigned long
544     (*ucs4_to_index)		(void			     *scaled_font,
545 				 uint32_t		      ucs4);
546 
547     /* Read data from a sfnt font table.
548      * @scaled_font: font
549      * @tag: 4 byte table name specifying the table to read.
550      * @offset: offset into the table
551      * @buffer: buffer to write data into. Caller must ensure there is sufficient space.
552      *          If NULL, return the size of the table in @length.
553      * @length: If @buffer is NULL, the size of the table will be returned in @length.
554      *          If @buffer is not null, @length specifies the number of bytes to read.
555      *
556      * If less than @length bytes are available to read this function
557      * returns CAIRO_INT_STATUS_UNSUPPORTED. Note that requesting more
558      * bytes than are available in the table may continue reading data
559      * from the following table and return success. If this is
560      * undesirable the caller should first query the table size. If an
561      * error occurs the output value of @length is undefined.
562      *
563      * Returns CAIRO_INT_STATUS_UNSUPPORTED if not a sfnt style font or table not found.
564      */
565     cairo_warn cairo_int_status_t
566     (*load_truetype_table)(void		        *scaled_font,
567                            unsigned long         tag,
568                            long                  offset,
569                            unsigned char        *buffer,
570                            unsigned long        *length);
571 
572     /* ucs4 is set to -1 if the unicode character could not be found
573      * for the glyph */
574     cairo_warn cairo_int_status_t
575     (*index_to_ucs4)(void                       *scaled_font,
576 		     unsigned long               index,
577                      uint32_t                   *ucs4);
578 
579     /* Determine if this scaled font differs from the outlines in the font tables.
580      * eg synthesized bold/italic or a non default variant of a variable font.
581      */
582     cairo_warn cairo_int_status_t
583     (*is_synthetic)(void                       *scaled_font,
584 		    cairo_bool_t               *is_synthetic);
585 
586     /* For type 1 fonts, return the glyph name for a given glyph index.
587      * A glyph index and list of glyph names in the Type 1 fonts is provided.
588      * The function returns the index of the glyph in the list of glyph names.
589      * @scaled_font: font
590      * @glyph_names: the names of each glyph in the Type 1 font in the
591      *   order they appear in the CharStrings array
592      * @num_glyph_names: the number of names in the glyph_names array
593      * @glyph_index: the given glyph index
594      * @glyph_array_index: (index into glyph_names) the glyph name corresponding
595      *  to the glyph_index
596      */
597 
598     cairo_warn cairo_int_status_t
599     (*index_to_glyph_name)(void                 *scaled_font,
600 			   char                **glyph_names,
601 			   int                   num_glyph_names,
602 			   unsigned long         glyph_index,
603 			   unsigned long        *glyph_array_index);
604 
605     /* Read data from a PostScript font.
606      * @scaled_font: font
607      * @offset: offset into the table
608      * @buffer: buffer to write data into. Caller must ensure there is sufficient space.
609      *          If NULL, return the size of the table in @length.
610      * @length: If @buffer is NULL, the size of the table will be returned in @length.
611      *          If @buffer is not null, @length specifies the number of bytes to read.
612      *
613      * If less than @length bytes are available to read this function
614      * returns CAIRO_INT_STATUS_UNSUPPORTED. If an error occurs the
615      * output value of @length is undefined.
616      *
617      * Returns CAIRO_INT_STATUS_UNSUPPORTED if not a Type 1 font.
618      */
619     cairo_warn cairo_int_status_t
620     (*load_type1_data)    (void		        *scaled_font,
621                            long                  offset,
622                            unsigned char        *buffer,
623                            unsigned long        *length);
624 
625     cairo_bool_t
626     (*has_color_glyphs)   (void                 *scaled_font);
627 };
628 
629 struct _cairo_font_face_backend {
630     cairo_font_type_t	type;
631 
632     cairo_warn cairo_status_t
633     (*create_for_toy)  (cairo_toy_font_face_t	*toy_face,
634 			cairo_font_face_t      **font_face);
635 
636     /* The destroy() function is allowed to resurrect the font face
637      * by re-referencing. This is needed for the FreeType backend.
638      */
639     cairo_bool_t
640     (*destroy)     (void			*font_face);
641 
642     cairo_warn cairo_status_t
643     (*scaled_font_create) (void				*font_face,
644 			   const cairo_matrix_t		*font_matrix,
645 			   const cairo_matrix_t		*ctm,
646 			   const cairo_font_options_t	*options,
647 			   cairo_scaled_font_t	       **scaled_font);
648 
649     cairo_font_face_t *
650     (*get_implementation) (void				*font_face,
651 			   const cairo_matrix_t		*font_matrix,
652 			   const cairo_matrix_t		*ctm,
653 			   const cairo_font_options_t	*options);
654 };
655 
656 extern const cairo_private struct _cairo_font_face_backend _cairo_user_font_face_backend;
657 
658 /* concrete font backends */
659 #if CAIRO_HAS_FT_FONT
660 
661 extern const cairo_private struct _cairo_font_face_backend _cairo_ft_font_face_backend;
662 
663 #endif
664 
665 #if CAIRO_HAS_WIN32_FONT
666 
667 extern const cairo_private struct _cairo_font_face_backend _cairo_win32_font_face_backend;
668 
669 #endif
670 
671 #if CAIRO_HAS_QUARTZ_FONT
672 
673 extern const cairo_private struct _cairo_font_face_backend _cairo_quartz_font_face_backend;
674 
675 #endif
676 
677 #define CAIRO_EXTEND_SURFACE_DEFAULT CAIRO_EXTEND_NONE
678 #define CAIRO_EXTEND_GRADIENT_DEFAULT CAIRO_EXTEND_PAD
679 #define CAIRO_FILTER_DEFAULT CAIRO_FILTER_GOOD
680 
681 extern const cairo_private cairo_solid_pattern_t _cairo_pattern_clear;
682 extern const cairo_private cairo_solid_pattern_t _cairo_pattern_black;
683 extern const cairo_private cairo_solid_pattern_t _cairo_pattern_white;
684 
685 struct _cairo_surface_attributes {
686     cairo_matrix_t matrix;
687     cairo_extend_t extend;
688     cairo_filter_t filter;
689     cairo_bool_t has_component_alpha;
690     int		   x_offset;
691     int		   y_offset;
692     void	   *extra;
693 };
694 
695 #define CAIRO_FONT_SLANT_DEFAULT   CAIRO_FONT_SLANT_NORMAL
696 #define CAIRO_FONT_WEIGHT_DEFAULT  CAIRO_FONT_WEIGHT_NORMAL
697 
698 #define CAIRO_WIN32_FONT_FAMILY_DEFAULT "Arial"
699 #define CAIRO_QUARTZ_FONT_FAMILY_DEFAULT  "Helvetica"
700 #define CAIRO_FT_FONT_FAMILY_DEFAULT     ""
701 #define CAIRO_USER_FONT_FAMILY_DEFAULT     "@cairo:"
702 
703 #if   CAIRO_HAS_WIN32_FONT
704 
705 #define CAIRO_FONT_FAMILY_DEFAULT CAIRO_WIN32_FONT_FAMILY_DEFAULT
706 #define CAIRO_FONT_FACE_BACKEND_DEFAULT &_cairo_win32_font_face_backend
707 
708 #elif CAIRO_HAS_QUARTZ_FONT
709 
710 #define CAIRO_FONT_FAMILY_DEFAULT CAIRO_QUARTZ_FONT_FAMILY_DEFAULT
711 #define CAIRO_FONT_FACE_BACKEND_DEFAULT &_cairo_quartz_font_face_backend
712 
713 #elif CAIRO_HAS_FT_FONT
714 
715 #define CAIRO_FONT_FAMILY_DEFAULT CAIRO_FT_FONT_FAMILY_DEFAULT
716 #define CAIRO_FONT_FACE_BACKEND_DEFAULT &_cairo_ft_font_face_backend
717 
718 #else
719 
720 #define CAIRO_FONT_FAMILY_DEFAULT CAIRO_FT_FONT_FAMILY_DEFAULT
721 #define CAIRO_FONT_FACE_BACKEND_DEFAULT &_cairo_user_font_face_backend
722 
723 #endif
724 
725 #define CAIRO_GSTATE_OPERATOR_DEFAULT	CAIRO_OPERATOR_OVER
726 #define CAIRO_GSTATE_TOLERANCE_DEFAULT	0.1
727 #define CAIRO_GSTATE_FILL_RULE_DEFAULT	CAIRO_FILL_RULE_WINDING
728 #define CAIRO_GSTATE_LINE_WIDTH_DEFAULT	2.0
729 #define CAIRO_GSTATE_LINE_CAP_DEFAULT	CAIRO_LINE_CAP_BUTT
730 #define CAIRO_GSTATE_LINE_JOIN_DEFAULT	CAIRO_LINE_JOIN_MITER
731 #define CAIRO_GSTATE_MITER_LIMIT_DEFAULT	10.0
732 #define CAIRO_GSTATE_DEFAULT_FONT_SIZE  10.0
733 
734 #define CAIRO_SURFACE_RESOLUTION_DEFAULT 72.0
735 #define CAIRO_SURFACE_FALLBACK_RESOLUTION_DEFAULT 300.0
736 
737 typedef struct _cairo_stroke_face {
738     cairo_point_t ccw;
739     cairo_point_t point;
740     cairo_point_t cw;
741     cairo_slope_t dev_vector;
742     cairo_point_double_t dev_slope;
743     cairo_point_double_t usr_vector;
744     double length;
745 } cairo_stroke_face_t;
746 
747 /* cairo.c */
748 
749 static inline double cairo_const
_cairo_restrict_value(double value,double min,double max)750 _cairo_restrict_value (double value, double min, double max)
751 {
752     if (value < min)
753 	return min;
754     else if (value > max)
755 	return max;
756     else
757 	return value;
758 }
759 
760 /* C99 round() rounds to the nearest integral value with halfway cases rounded
761  * away from 0. _cairo_round rounds halfway cases toward positive infinity.
762  * This matches the rounding behaviour of _cairo_lround. */
763 static inline double cairo_const
_cairo_round(double r)764 _cairo_round (double r)
765 {
766     return floor (r + .5);
767 }
768 
769 #if DISABLE_SOME_FLOATING_POINT
770 cairo_private int
771 _cairo_lround (double d) cairo_const;
772 #else
773 static inline int cairo_const
_cairo_lround(double r)774 _cairo_lround (double r)
775 {
776     return _cairo_round (r);
777 }
778 #endif
779 
780 cairo_private uint16_t
781 _cairo_half_from_float (float f) cairo_const;
782 
783 cairo_private cairo_bool_t
784 _cairo_operator_bounded_by_mask (cairo_operator_t op) cairo_const;
785 
786 cairo_private cairo_bool_t
787 _cairo_operator_bounded_by_source (cairo_operator_t op) cairo_const;
788 
789 enum {
790     CAIRO_OPERATOR_BOUND_BY_MASK = 1 << 1,
791     CAIRO_OPERATOR_BOUND_BY_SOURCE = 1 << 2,
792 };
793 
794 cairo_private uint32_t
795 _cairo_operator_bounded_by_either (cairo_operator_t op) cairo_const;
796 /* cairo-color.c */
797 cairo_private const cairo_color_t *
798 _cairo_stock_color (cairo_stock_t stock) cairo_pure;
799 
800 #define CAIRO_COLOR_WHITE       _cairo_stock_color (CAIRO_STOCK_WHITE)
801 #define CAIRO_COLOR_BLACK       _cairo_stock_color (CAIRO_STOCK_BLACK)
802 #define CAIRO_COLOR_TRANSPARENT _cairo_stock_color (CAIRO_STOCK_TRANSPARENT)
803 
804 cairo_private uint16_t
805 _cairo_color_double_to_short (double d) cairo_const;
806 
807 cairo_private void
808 _cairo_color_init_rgba (cairo_color_t *color,
809 			double red, double green, double blue,
810 			double alpha);
811 
812 cairo_private void
813 _cairo_color_multiply_alpha (cairo_color_t *color,
814 			     double	    alpha);
815 
816 cairo_private void
817 _cairo_color_get_rgba (cairo_color_t *color,
818 		       double	     *red,
819 		       double	     *green,
820 		       double	     *blue,
821 		       double	     *alpha);
822 
823 cairo_private void
824 _cairo_color_get_rgba_premultiplied (cairo_color_t *color,
825 				     double	   *red,
826 				     double	   *green,
827 				     double	   *blue,
828 				     double	   *alpha);
829 
830 cairo_private cairo_bool_t
831 _cairo_color_equal (const cairo_color_t *color_a,
832                     const cairo_color_t *color_b) cairo_pure;
833 
834 cairo_private cairo_bool_t
835 _cairo_color_stop_equal (const cairo_color_stop_t *color_a,
836 			 const cairo_color_stop_t *color_b) cairo_pure;
837 
838 cairo_private cairo_content_t
839 _cairo_color_get_content (const cairo_color_t *color) cairo_pure;
840 
841 /* cairo-font-face.c */
842 
843 extern const cairo_private cairo_font_face_t _cairo_font_face_nil;
844 extern const cairo_private cairo_font_face_t _cairo_font_face_nil_file_not_found;
845 
846 cairo_private void
847 _cairo_font_face_init (cairo_font_face_t               *font_face,
848 		       const cairo_font_face_backend_t *backend);
849 
850 cairo_private cairo_bool_t
851 _cairo_font_face_destroy (void *abstract_face);
852 
853 cairo_private cairo_status_t
854 _cairo_font_face_set_error (cairo_font_face_t *font_face,
855 	                    cairo_status_t     status);
856 
857 cairo_private void
858 _cairo_unscaled_font_init (cairo_unscaled_font_t               *font,
859 			   const cairo_unscaled_font_backend_t *backend);
860 
861 cairo_private_no_warn cairo_unscaled_font_t *
862 _cairo_unscaled_font_reference (cairo_unscaled_font_t *font);
863 
864 cairo_private void
865 _cairo_unscaled_font_destroy (cairo_unscaled_font_t *font);
866 
867 /* cairo-font-face-twin.c */
868 
869 cairo_private cairo_font_face_t *
870 _cairo_font_face_twin_create_fallback (void);
871 
872 cairo_private cairo_status_t
873 _cairo_font_face_twin_create_for_toy (cairo_toy_font_face_t   *toy_face,
874 				      cairo_font_face_t      **font_face);
875 
876 /* cairo-font-face-twin-data.c */
877 
878 extern const cairo_private int8_t _cairo_twin_outlines[];
879 extern const cairo_private uint16_t _cairo_twin_charmap[128];
880 
881 /* cairo-font-options.c */
882 
883 cairo_private void
884 _cairo_font_options_init_default (cairo_font_options_t *options);
885 
886 cairo_private void
887 _cairo_font_options_init_copy (cairo_font_options_t		*options,
888 			       const cairo_font_options_t	*other);
889 
890 cairo_private void
891 _cairo_font_options_fini (cairo_font_options_t *options);
892 
893 cairo_private void
894 _cairo_font_options_set_round_glyph_positions (cairo_font_options_t   *options,
895 					       cairo_round_glyph_positions_t  round);
896 
897 cairo_private cairo_round_glyph_positions_t
898 _cairo_font_options_get_round_glyph_positions (const cairo_font_options_t *options);
899 
900 /* cairo-hull.c */
901 cairo_private cairo_status_t
902 _cairo_hull_compute (cairo_pen_vertex_t *vertices, int *num_vertices);
903 
904 /* cairo-lzw.c */
905 cairo_private unsigned char *
906 _cairo_lzw_compress (unsigned char *data, unsigned long *size_in_out);
907 
908 /* cairo-misc.c */
909 cairo_private cairo_status_t
910 _cairo_validate_text_clusters (const char		   *utf8,
911 			       int			    utf8_len,
912 			       const cairo_glyph_t	   *glyphs,
913 			       int			    num_glyphs,
914 			       const cairo_text_cluster_t  *clusters,
915 			       int			    num_clusters,
916 			       cairo_text_cluster_flags_t   cluster_flags);
917 
918 cairo_private unsigned long
919 _cairo_string_hash (const char *str, int len);
920 
921 cairo_private cairo_status_t
922 _cairo_intern_string (const char **str_inout, int len);
923 
924 cairo_private void
925 _cairo_intern_string_reset_static_data (void);
926 
927 cairo_private const char *
928 _cairo_get_locale_decimal_point (void);
929 
930 cairo_private double
931 _cairo_strtod (const char *nptr, char **endptr);
932 
933 /* cairo-path-fixed.c */
934 cairo_private cairo_path_fixed_t *
935 _cairo_path_fixed_create (void);
936 
937 cairo_private void
938 _cairo_path_fixed_init (cairo_path_fixed_t *path);
939 
940 cairo_private cairo_status_t
941 _cairo_path_fixed_init_copy (cairo_path_fixed_t *path,
942 			     const cairo_path_fixed_t *other);
943 
944 cairo_private void
945 _cairo_path_fixed_fini (cairo_path_fixed_t *path);
946 
947 cairo_private void
948 _cairo_path_fixed_destroy (cairo_path_fixed_t *path);
949 
950 cairo_private cairo_status_t
951 _cairo_path_fixed_move_to (cairo_path_fixed_t  *path,
952 			   cairo_fixed_t	x,
953 			   cairo_fixed_t	y);
954 
955 cairo_private void
956 _cairo_path_fixed_new_sub_path (cairo_path_fixed_t *path);
957 
958 cairo_private cairo_status_t
959 _cairo_path_fixed_rel_move_to (cairo_path_fixed_t *path,
960 			       cairo_fixed_t	   dx,
961 			       cairo_fixed_t	   dy);
962 
963 cairo_private cairo_status_t
964 _cairo_path_fixed_line_to (cairo_path_fixed_t *path,
965 			   cairo_fixed_t	x,
966 			   cairo_fixed_t	y);
967 
968 cairo_private cairo_status_t
969 _cairo_path_fixed_rel_line_to (cairo_path_fixed_t *path,
970 			       cairo_fixed_t	   dx,
971 			       cairo_fixed_t	   dy);
972 
973 cairo_private cairo_status_t
974 _cairo_path_fixed_curve_to (cairo_path_fixed_t	*path,
975 			    cairo_fixed_t x0, cairo_fixed_t y0,
976 			    cairo_fixed_t x1, cairo_fixed_t y1,
977 			    cairo_fixed_t x2, cairo_fixed_t y2);
978 
979 cairo_private cairo_status_t
980 _cairo_path_fixed_rel_curve_to (cairo_path_fixed_t *path,
981 				cairo_fixed_t dx0, cairo_fixed_t dy0,
982 				cairo_fixed_t dx1, cairo_fixed_t dy1,
983 				cairo_fixed_t dx2, cairo_fixed_t dy2);
984 
985 cairo_private cairo_status_t
986 _cairo_path_fixed_close_path (cairo_path_fixed_t *path);
987 
988 cairo_private cairo_bool_t
989 _cairo_path_fixed_get_current_point (cairo_path_fixed_t *path,
990 				     cairo_fixed_t	*x,
991 				     cairo_fixed_t	*y);
992 
993 typedef cairo_status_t
994 (cairo_path_fixed_move_to_func_t) (void		 *closure,
995 				   const cairo_point_t *point);
996 
997 typedef cairo_status_t
998 (cairo_path_fixed_line_to_func_t) (void		 *closure,
999 				   const cairo_point_t *point);
1000 
1001 typedef cairo_status_t
1002 (cairo_path_fixed_curve_to_func_t) (void	  *closure,
1003 				    const cairo_point_t *p0,
1004 				    const cairo_point_t *p1,
1005 				    const cairo_point_t *p2);
1006 
1007 typedef cairo_status_t
1008 (cairo_path_fixed_close_path_func_t) (void *closure);
1009 
1010 cairo_private cairo_status_t
1011 _cairo_path_fixed_interpret (const cairo_path_fixed_t	  *path,
1012 		       cairo_path_fixed_move_to_func_t	  *move_to,
1013 		       cairo_path_fixed_line_to_func_t	  *line_to,
1014 		       cairo_path_fixed_curve_to_func_t	  *curve_to,
1015 		       cairo_path_fixed_close_path_func_t *close_path,
1016 		       void				  *closure);
1017 
1018 cairo_private cairo_status_t
1019 _cairo_path_fixed_interpret_flat (const cairo_path_fixed_t *path,
1020 		       cairo_path_fixed_move_to_func_t	  *move_to,
1021 		       cairo_path_fixed_line_to_func_t	  *line_to,
1022 		       cairo_path_fixed_close_path_func_t *close_path,
1023 		       void				  *closure,
1024 		       double				  tolerance);
1025 
1026 
1027 cairo_private cairo_bool_t
1028 _cairo_path_bounder_extents (const cairo_path_fixed_t *path,
1029 			     cairo_box_t *box);
1030 
1031 cairo_private cairo_bool_t
1032 _cairo_path_fixed_extents (const cairo_path_fixed_t *path,
1033 			   cairo_box_t *box);
1034 
1035 cairo_private void
1036 _cairo_path_fixed_approximate_clip_extents (const cairo_path_fixed_t	*path,
1037 					    cairo_rectangle_int_t *extents);
1038 
1039 cairo_private void
1040 _cairo_path_fixed_approximate_fill_extents (const cairo_path_fixed_t *path,
1041 					    cairo_rectangle_int_t *extents);
1042 
1043 cairo_private void
1044 _cairo_path_fixed_fill_extents (const cairo_path_fixed_t	*path,
1045 				cairo_fill_rule_t	 fill_rule,
1046 				double			 tolerance,
1047 				cairo_rectangle_int_t	*extents);
1048 
1049 cairo_private void
1050 _cairo_path_fixed_approximate_stroke_extents (const cairo_path_fixed_t *path,
1051 					      const cairo_stroke_style_t *style,
1052 					      const cairo_matrix_t *ctm,
1053 					      cairo_bool_t vector,
1054 					      cairo_rectangle_int_t *extents);
1055 
1056 cairo_private cairo_status_t
1057 _cairo_path_fixed_stroke_extents (const cairo_path_fixed_t *path,
1058 				  const cairo_stroke_style_t *style,
1059 				  const cairo_matrix_t *ctm,
1060 				  const cairo_matrix_t *ctm_inverse,
1061 				  double tolerance,
1062 				  cairo_rectangle_int_t *extents);
1063 
1064 cairo_private void
1065 _cairo_path_fixed_transform (cairo_path_fixed_t	*path,
1066 			     const cairo_matrix_t	*matrix);
1067 
1068 cairo_private cairo_bool_t
1069 _cairo_path_fixed_is_box (const cairo_path_fixed_t *path,
1070                           cairo_box_t *box);
1071 
1072 cairo_private cairo_bool_t
1073 _cairo_path_fixed_is_rectangle (const cairo_path_fixed_t *path,
1074 				cairo_box_t        *box);
1075 
1076 /* cairo-path-in-fill.c */
1077 cairo_private cairo_bool_t
1078 _cairo_path_fixed_in_fill (const cairo_path_fixed_t	*path,
1079 			   cairo_fill_rule_t	 fill_rule,
1080 			   double		 tolerance,
1081 			   double		 x,
1082 			   double		 y);
1083 
1084 /* cairo-path-fill.c */
1085 cairo_private cairo_status_t
1086 _cairo_path_fixed_fill_to_polygon (const cairo_path_fixed_t *path,
1087 				   double              tolerance,
1088 				   cairo_polygon_t      *polygon);
1089 
1090 cairo_private cairo_status_t
1091 _cairo_path_fixed_fill_rectilinear_to_polygon (const cairo_path_fixed_t *path,
1092 					       cairo_antialias_t antialias,
1093 					       cairo_polygon_t *polygon);
1094 
1095 cairo_private cairo_status_t
1096 _cairo_path_fixed_fill_rectilinear_to_boxes (const cairo_path_fixed_t *path,
1097 					     cairo_fill_rule_t fill_rule,
1098 					     cairo_antialias_t antialias,
1099 					     cairo_boxes_t *boxes);
1100 
1101 cairo_private cairo_region_t *
1102 _cairo_path_fixed_fill_rectilinear_to_region (const cairo_path_fixed_t	*path,
1103 					      cairo_fill_rule_t	 fill_rule,
1104 					      const cairo_rectangle_int_t *extents);
1105 
1106 cairo_private cairo_status_t
1107 _cairo_path_fixed_fill_to_traps (const cairo_path_fixed_t   *path,
1108 				 cairo_fill_rule_t	     fill_rule,
1109 				 double			     tolerance,
1110 				 cairo_traps_t		    *traps);
1111 
1112 /* cairo-path-stroke.c */
1113 cairo_private cairo_status_t
1114 _cairo_path_fixed_stroke_to_polygon (const cairo_path_fixed_t	*path,
1115 				     const cairo_stroke_style_t	*stroke_style,
1116 				     const cairo_matrix_t	*ctm,
1117 				     const cairo_matrix_t	*ctm_inverse,
1118 				     double		 tolerance,
1119 				     cairo_polygon_t	*polygon);
1120 
1121 cairo_private cairo_int_status_t
1122 _cairo_path_fixed_stroke_to_tristrip (const cairo_path_fixed_t	*path,
1123 				      const cairo_stroke_style_t*style,
1124 				      const cairo_matrix_t	*ctm,
1125 				      const cairo_matrix_t	*ctm_inverse,
1126 				      double			 tolerance,
1127 				      cairo_tristrip_t		 *strip);
1128 
1129 cairo_private cairo_status_t
1130 _cairo_path_fixed_stroke_dashed_to_polygon (const cairo_path_fixed_t	*path,
1131 					    const cairo_stroke_style_t	*stroke_style,
1132 					    const cairo_matrix_t	*ctm,
1133 					    const cairo_matrix_t	*ctm_inverse,
1134 					    double		 tolerance,
1135 					    cairo_polygon_t	*polygon);
1136 
1137 cairo_private cairo_int_status_t
1138 _cairo_path_fixed_stroke_rectilinear_to_boxes (const cairo_path_fixed_t	*path,
1139 					       const cairo_stroke_style_t	*stroke_style,
1140 					       const cairo_matrix_t	*ctm,
1141 					       cairo_antialias_t	 antialias,
1142 					       cairo_boxes_t		*boxes);
1143 
1144 cairo_private cairo_int_status_t
1145 _cairo_path_fixed_stroke_to_traps (const cairo_path_fixed_t	*path,
1146 				   const cairo_stroke_style_t	*stroke_style,
1147 				   const cairo_matrix_t	*ctm,
1148 				   const cairo_matrix_t	*ctm_inverse,
1149 				   double		 tolerance,
1150 				   cairo_traps_t	*traps);
1151 
1152 cairo_private cairo_int_status_t
1153 _cairo_path_fixed_stroke_polygon_to_traps (const cairo_path_fixed_t	*path,
1154 					   const cairo_stroke_style_t	*stroke_style,
1155 					   const cairo_matrix_t	*ctm,
1156 					   const cairo_matrix_t	*ctm_inverse,
1157 					   double		 tolerance,
1158 					   cairo_traps_t	*traps);
1159 
1160 cairo_private cairo_status_t
1161 _cairo_path_fixed_stroke_to_shaper (cairo_path_fixed_t	*path,
1162 				   const cairo_stroke_style_t	*stroke_style,
1163 				   const cairo_matrix_t	*ctm,
1164 				   const cairo_matrix_t	*ctm_inverse,
1165 				   double		 tolerance,
1166 				   cairo_status_t (*add_triangle) (void *closure,
1167 								   const cairo_point_t triangle[3]),
1168 				   cairo_status_t (*add_triangle_fan) (void *closure,
1169 								       const cairo_point_t *midpt,
1170 								       const cairo_point_t *points,
1171 								       int npoints),
1172 				   cairo_status_t (*add_quad) (void *closure,
1173 							       const cairo_point_t quad[4]),
1174 				   void *closure);
1175 
1176 /* cairo-scaled-font.c */
1177 
1178 cairo_private void
1179 _cairo_scaled_font_freeze_cache (cairo_scaled_font_t *scaled_font);
1180 
1181 cairo_private void
1182 _cairo_scaled_font_thaw_cache (cairo_scaled_font_t *scaled_font);
1183 
1184 cairo_private void
1185 _cairo_scaled_font_reset_cache (cairo_scaled_font_t *scaled_font);
1186 
1187 cairo_private cairo_status_t
1188 _cairo_scaled_font_set_error (cairo_scaled_font_t *scaled_font,
1189 			      cairo_status_t status);
1190 
1191 cairo_private cairo_scaled_font_t *
1192 _cairo_scaled_font_create_in_error (cairo_status_t status);
1193 
1194 cairo_private void
1195 _cairo_scaled_font_reset_static_data (void);
1196 
1197 cairo_private cairo_status_t
1198 _cairo_scaled_font_register_placeholder_and_unlock_font_map (cairo_scaled_font_t *scaled_font);
1199 
1200 cairo_private void
1201 _cairo_scaled_font_unregister_placeholder_and_lock_font_map (cairo_scaled_font_t *scaled_font);
1202 
1203 cairo_private cairo_status_t
1204 _cairo_scaled_font_init (cairo_scaled_font_t               *scaled_font,
1205 			 cairo_font_face_t		   *font_face,
1206 			 const cairo_matrix_t              *font_matrix,
1207 			 const cairo_matrix_t              *ctm,
1208 			 const cairo_font_options_t	   *options,
1209 			 const cairo_scaled_font_backend_t *backend);
1210 
1211 cairo_private cairo_status_t
1212 _cairo_scaled_font_set_metrics (cairo_scaled_font_t	    *scaled_font,
1213 				cairo_font_extents_t	    *fs_metrics);
1214 
1215 /* This should only be called on an error path by a scaled_font constructor */
1216 cairo_private void
1217 _cairo_scaled_font_fini (cairo_scaled_font_t *scaled_font);
1218 
1219 cairo_private cairo_status_t
1220 _cairo_scaled_font_font_extents (cairo_scaled_font_t  *scaled_font,
1221 				 cairo_font_extents_t *extents);
1222 
1223 cairo_private cairo_status_t
1224 _cairo_scaled_font_glyph_device_extents (cairo_scaled_font_t	 *scaled_font,
1225 					 const cairo_glyph_t	 *glyphs,
1226 					 int                      num_glyphs,
1227 					 cairo_rectangle_int_t   *extents,
1228 					 cairo_bool_t		 *overlap);
1229 
1230 cairo_private cairo_bool_t
1231 _cairo_scaled_font_glyph_approximate_extents (cairo_scaled_font_t	 *scaled_font,
1232 					      const cairo_glyph_t	 *glyphs,
1233 					      int                      num_glyphs,
1234 					      cairo_rectangle_int_t   *extents);
1235 
1236 cairo_private cairo_status_t
1237 _cairo_scaled_font_show_glyphs (cairo_scaled_font_t *scaled_font,
1238 				cairo_operator_t     op,
1239 				const cairo_pattern_t *source,
1240 				cairo_surface_t	    *surface,
1241 				int		     source_x,
1242 				int		     source_y,
1243 				int		     dest_x,
1244 				int		     dest_y,
1245 				unsigned int	     width,
1246 				unsigned int	     height,
1247 				cairo_glyph_t	    *glyphs,
1248 				int		     num_glyphs,
1249 				cairo_region_t	    *clip_region);
1250 
1251 cairo_private cairo_status_t
1252 _cairo_scaled_font_glyph_path (cairo_scaled_font_t *scaled_font,
1253 			       const cairo_glyph_t *glyphs,
1254 			       int                  num_glyphs,
1255 			       cairo_path_fixed_t  *path);
1256 
1257 cairo_private void
1258 _cairo_scaled_glyph_set_metrics (cairo_scaled_glyph_t *scaled_glyph,
1259 				 cairo_scaled_font_t *scaled_font,
1260 				 cairo_text_extents_t *fs_metrics);
1261 
1262 cairo_private void
1263 _cairo_scaled_glyph_set_surface (cairo_scaled_glyph_t *scaled_glyph,
1264 				 cairo_scaled_font_t *scaled_font,
1265 				 cairo_image_surface_t *surface);
1266 
1267 cairo_private void
1268 _cairo_scaled_glyph_set_path (cairo_scaled_glyph_t *scaled_glyph,
1269 			      cairo_scaled_font_t *scaled_font,
1270 			      cairo_path_fixed_t *path);
1271 
1272 cairo_private void
1273 _cairo_scaled_glyph_set_recording_surface (cairo_scaled_glyph_t *scaled_glyph,
1274                                            cairo_scaled_font_t *scaled_font,
1275                                            cairo_surface_t *recording_surface);
1276 
1277 cairo_private void
1278 _cairo_scaled_glyph_set_color_surface (cairo_scaled_glyph_t *scaled_glyph,
1279 		                       cairo_scaled_font_t *scaled_font,
1280 		                       cairo_image_surface_t *surface);
1281 
1282 cairo_private cairo_int_status_t
1283 _cairo_scaled_glyph_lookup (cairo_scaled_font_t *scaled_font,
1284 			    unsigned long index,
1285 			    cairo_scaled_glyph_info_t info,
1286 			    cairo_scaled_glyph_t **scaled_glyph_ret);
1287 
1288 cairo_private double
1289 _cairo_scaled_font_get_max_scale (cairo_scaled_font_t *scaled_font);
1290 
1291 cairo_private void
1292 _cairo_scaled_font_map_destroy (void);
1293 
1294 /* cairo-stroke-style.c */
1295 
1296 cairo_private void
1297 _cairo_stroke_style_init (cairo_stroke_style_t *style);
1298 
1299 cairo_private cairo_status_t
1300 _cairo_stroke_style_init_copy (cairo_stroke_style_t *style,
1301 			       const cairo_stroke_style_t *other);
1302 
1303 cairo_private void
1304 _cairo_stroke_style_fini (cairo_stroke_style_t *style);
1305 
1306 cairo_private void
1307 _cairo_stroke_style_max_distance_from_path (const cairo_stroke_style_t *style,
1308 					    const cairo_path_fixed_t *path,
1309                                             const cairo_matrix_t *ctm,
1310                                             double *dx, double *dy);
1311 cairo_private void
1312 _cairo_stroke_style_max_line_distance_from_path (const cairo_stroke_style_t *style,
1313 						 const cairo_path_fixed_t *path,
1314 						 const cairo_matrix_t *ctm,
1315 						 double *dx, double *dy);
1316 
1317 cairo_private void
1318 _cairo_stroke_style_max_join_distance_from_path (const cairo_stroke_style_t *style,
1319 						 const cairo_path_fixed_t *path,
1320 						 const cairo_matrix_t *ctm,
1321 						 double *dx, double *dy);
1322 
1323 cairo_private double
1324 _cairo_stroke_style_dash_period (const cairo_stroke_style_t *style);
1325 
1326 cairo_private double
1327 _cairo_stroke_style_dash_stroked (const cairo_stroke_style_t *style);
1328 
1329 cairo_private cairo_bool_t
1330 _cairo_stroke_style_dash_can_approximate (const cairo_stroke_style_t *style,
1331 					  const cairo_matrix_t *ctm,
1332 					  double tolerance);
1333 
1334 cairo_private void
1335 _cairo_stroke_style_dash_approximate (const cairo_stroke_style_t *style,
1336 				      const cairo_matrix_t *ctm,
1337 				      double tolerance,
1338 				      double *dash_offset,
1339 				      double *dashes,
1340 				      unsigned int *num_dashes);
1341 
1342 
1343 /* cairo-surface.c */
1344 
1345 cairo_private cairo_bool_t
1346 _cairo_surface_has_mime_image (cairo_surface_t *surface);
1347 
1348 cairo_private cairo_status_t
1349 _cairo_surface_copy_mime_data (cairo_surface_t *dst,
1350 			       cairo_surface_t *src);
1351 
1352 cairo_private_no_warn cairo_int_status_t
1353 _cairo_surface_set_error (cairo_surface_t	*surface,
1354 			  cairo_int_status_t	 status);
1355 
1356 cairo_private void
1357 _cairo_surface_set_resolution (cairo_surface_t *surface,
1358                                double x_res,
1359                                double y_res);
1360 
1361 cairo_private cairo_surface_t *
1362 _cairo_surface_create_for_rectangle_int (cairo_surface_t *target,
1363 					 const cairo_rectangle_int_t *extents);
1364 
1365 cairo_private cairo_surface_t *
1366 _cairo_surface_create_scratch (cairo_surface_t	    *other,
1367 			       cairo_content_t	     content,
1368 			       int		     width,
1369 			       int		     height,
1370 			       const cairo_color_t  *color);
1371 
1372 cairo_private void
1373 _cairo_surface_init (cairo_surface_t			*surface,
1374 		     const cairo_surface_backend_t	*backend,
1375 		     cairo_device_t			*device,
1376 		     cairo_content_t			 content,
1377 		     cairo_bool_t                        is_vector);
1378 
1379 cairo_private void
1380 _cairo_surface_set_font_options (cairo_surface_t       *surface,
1381 				 cairo_font_options_t  *options);
1382 
1383 cairo_private cairo_status_t
1384 _cairo_surface_paint (cairo_surface_t	*surface,
1385 		      cairo_operator_t	 op,
1386 		      const cairo_pattern_t *source,
1387 		      const cairo_clip_t	    *clip);
1388 
1389 cairo_private cairo_image_surface_t *
1390 _cairo_surface_map_to_image (cairo_surface_t  *surface,
1391 			     const cairo_rectangle_int_t *extents);
1392 
1393 cairo_private_no_warn cairo_int_status_t
1394 _cairo_surface_unmap_image (cairo_surface_t       *surface,
1395 			    cairo_image_surface_t *image);
1396 
1397 cairo_private cairo_status_t
1398 _cairo_surface_mask (cairo_surface_t	*surface,
1399 		     cairo_operator_t	 op,
1400 		     const cairo_pattern_t	*source,
1401 		     const cairo_pattern_t	*mask,
1402 		     const cairo_clip_t		*clip);
1403 
1404 cairo_private cairo_status_t
1405 _cairo_surface_fill_stroke (cairo_surface_t	    *surface,
1406 			    cairo_operator_t	     fill_op,
1407 			    const cairo_pattern_t   *fill_source,
1408 			    cairo_fill_rule_t	     fill_rule,
1409 			    double		     fill_tolerance,
1410 			    cairo_antialias_t	     fill_antialias,
1411 			    cairo_path_fixed_t	    *path,
1412 			    cairo_operator_t	     stroke_op,
1413 			    const cairo_pattern_t   *stroke_source,
1414 			    const cairo_stroke_style_t    *stroke_style,
1415 			    const cairo_matrix_t	    *stroke_ctm,
1416 			    const cairo_matrix_t	    *stroke_ctm_inverse,
1417 			    double		     stroke_tolerance,
1418 			    cairo_antialias_t	     stroke_antialias,
1419 			    const cairo_clip_t	    *clip);
1420 
1421 cairo_private cairo_status_t
1422 _cairo_surface_stroke (cairo_surface_t		*surface,
1423 		       cairo_operator_t		 op,
1424 		       const cairo_pattern_t	*source,
1425 		       const cairo_path_fixed_t	*path,
1426 		       const cairo_stroke_style_t	*style,
1427 		       const cairo_matrix_t		*ctm,
1428 		       const cairo_matrix_t		*ctm_inverse,
1429 		       double			 tolerance,
1430 		       cairo_antialias_t	 antialias,
1431 		       const cairo_clip_t		*clip);
1432 
1433 cairo_private cairo_status_t
1434 _cairo_surface_fill (cairo_surface_t	*surface,
1435 		     cairo_operator_t	 op,
1436 		     const cairo_pattern_t *source,
1437 		     const cairo_path_fixed_t	*path,
1438 		     cairo_fill_rule_t	 fill_rule,
1439 		     double		 tolerance,
1440 		     cairo_antialias_t	 antialias,
1441 		     const cairo_clip_t	*clip);
1442 
1443 cairo_private cairo_status_t
1444 _cairo_surface_show_text_glyphs (cairo_surface_t	    *surface,
1445 				 cairo_operator_t	     op,
1446 				 const cairo_pattern_t	    *source,
1447 				 const char		    *utf8,
1448 				 int			     utf8_len,
1449 				 cairo_glyph_t		    *glyphs,
1450 				 int			     num_glyphs,
1451 				 const cairo_text_cluster_t *clusters,
1452 				 int			     num_clusters,
1453 				 cairo_text_cluster_flags_t  cluster_flags,
1454 				 cairo_scaled_font_t	    *scaled_font,
1455 				 const cairo_clip_t		    *clip);
1456 
1457 cairo_private cairo_status_t
1458 _cairo_surface_tag (cairo_surface_t	        *surface,
1459 		    cairo_bool_t                 begin,
1460 		    const char                  *tag_name,
1461 		    const char                  *attributes);
1462 
1463 cairo_private cairo_status_t
1464 _cairo_surface_acquire_source_image (cairo_surface_t         *surface,
1465 				     cairo_image_surface_t  **image_out,
1466 				     void                   **image_extra);
1467 
1468 cairo_private void
1469 _cairo_surface_release_source_image (cairo_surface_t        *surface,
1470 				     cairo_image_surface_t  *image,
1471 				     void                   *image_extra);
1472 
1473 cairo_private cairo_surface_t *
1474 _cairo_surface_snapshot (cairo_surface_t *surface);
1475 
1476 cairo_private void
1477 _cairo_surface_attach_snapshot (cairo_surface_t *surface,
1478 				cairo_surface_t *snapshot,
1479 				cairo_surface_func_t detach_func);
1480 
1481 cairo_private cairo_surface_t *
1482 _cairo_surface_has_snapshot (cairo_surface_t *surface,
1483 			     const cairo_surface_backend_t *backend);
1484 
1485 cairo_private void
1486 _cairo_surface_detach_snapshot (cairo_surface_t *snapshot);
1487 
1488 cairo_private cairo_status_t
1489 _cairo_surface_begin_modification (cairo_surface_t *surface);
1490 
1491 cairo_private_no_warn cairo_bool_t
1492 _cairo_surface_get_extents (cairo_surface_t         *surface,
1493 			    cairo_rectangle_int_t   *extents);
1494 
1495 cairo_private cairo_bool_t
1496 _cairo_surface_has_device_transform (cairo_surface_t *surface) cairo_pure;
1497 
1498 cairo_private void
1499 _cairo_surface_release_device_reference (cairo_surface_t *surface);
1500 
1501 /* cairo-image-surface.c */
1502 
1503 /* XXX: In cairo 1.2.0 we added a new %CAIRO_FORMAT_RGB16_565 but
1504  * neglected to adjust this macro. The net effect is that it's
1505  * impossible to externally create an image surface with this
1506  * format. This is perhaps a good thing since we also neglected to fix
1507  * up things like cairo_surface_write_to_png() for the new format
1508  * (-Wswitch-enum will tell you where). Is it obvious that format was
1509  * added in haste?
1510  *
1511  * The reason for the new format was to allow the xlib backend to be
1512  * used on X servers with a 565 visual. So the new format did its job
1513  * for that, even without being considered "valid" for the sake of
1514  * things like cairo_image_surface_create().
1515  *
1516  * Since 1.2.0 we ran into the same situation with X servers with BGR
1517  * visuals. This time we invented #cairo_internal_format_t instead,
1518  * (see it for more discussion).
1519  *
1520  * The punchline is that %CAIRO_FORMAT_VALID must not consider any
1521  * internal format to be valid. Also we need to decide if the
1522  * RGB16_565 should be moved to instead be an internal format. If so,
1523  * this macro need not change for it. (We probably will need to leave
1524  * an RGB16_565 value in the header files for the sake of code that
1525  * might have that value in it.)
1526  *
1527  * If we do decide to start fully supporting RGB16_565 as an external
1528  * format, then %CAIRO_FORMAT_VALID needs to be adjusted to include
1529  * it. But that should not happen before all necessary code is fixed
1530  * to support it (at least cairo_surface_write_to_png() and a few spots
1531  * in cairo-xlib-surface.c--again see -Wswitch-enum).
1532  */
1533 #define CAIRO_FORMAT_VALID(format) ((format) >= CAIRO_FORMAT_ARGB32 &&		\
1534                                     (format) <= CAIRO_FORMAT_RGBA128F)
1535 
1536 /* pixman-required stride alignment in bytes. */
1537 #define CAIRO_STRIDE_ALIGNMENT (sizeof (uint32_t))
1538 #define CAIRO_STRIDE_FOR_WIDTH_BPP(w,bpp) \
1539    ((((bpp)*(w)+7)/8 + CAIRO_STRIDE_ALIGNMENT-1) & -CAIRO_STRIDE_ALIGNMENT)
1540 
1541 #define CAIRO_CONTENT_VALID(content) ((content) && 			         \
1542 				      (((content) & ~(CAIRO_CONTENT_COLOR |      \
1543 						      CAIRO_CONTENT_ALPHA |      \
1544 						      CAIRO_CONTENT_COLOR_ALPHA))\
1545 				       == 0))
1546 
1547 cairo_private int
1548 _cairo_format_bits_per_pixel (cairo_format_t format) cairo_const;
1549 
1550 cairo_private cairo_format_t
1551 _cairo_format_from_content (cairo_content_t content) cairo_const;
1552 
1553 cairo_private cairo_format_t
1554 _cairo_format_from_pixman_format (pixman_format_code_t pixman_format);
1555 
1556 cairo_private cairo_content_t
1557 _cairo_content_from_format (cairo_format_t format) cairo_const;
1558 
1559 cairo_private cairo_content_t
1560 _cairo_content_from_pixman_format (pixman_format_code_t pixman_format);
1561 
1562 cairo_private cairo_surface_t *
1563 _cairo_image_surface_create_for_pixman_image (pixman_image_t		*pixman_image,
1564 					      pixman_format_code_t	 pixman_format);
1565 
1566 cairo_private pixman_format_code_t
1567 _cairo_format_to_pixman_format_code (cairo_format_t format);
1568 
1569 cairo_private cairo_bool_t
1570 _pixman_format_from_masks (cairo_format_masks_t *masks,
1571 			   pixman_format_code_t *format_ret);
1572 
1573 cairo_private cairo_bool_t
1574 _pixman_format_to_masks (pixman_format_code_t	 pixman_format,
1575 			 cairo_format_masks_t	*masks);
1576 
1577 cairo_private void
1578 _cairo_image_scaled_glyph_fini (cairo_scaled_font_t *scaled_font,
1579 				cairo_scaled_glyph_t *scaled_glyph);
1580 
1581 cairo_private void
1582 _cairo_image_reset_static_data (void);
1583 
1584 cairo_private void
1585 _cairo_image_compositor_reset_static_data (void);
1586 
1587 cairo_private cairo_surface_t *
1588 _cairo_image_surface_create_with_pixman_format (unsigned char		*data,
1589 						pixman_format_code_t	 pixman_format,
1590 						int			 width,
1591 						int			 height,
1592 						int			 stride);
1593 
1594 cairo_private cairo_surface_t *
1595 _cairo_image_surface_create_with_content (cairo_content_t	content,
1596 					  int			width,
1597 					  int			height);
1598 
1599 cairo_private void
1600 _cairo_image_surface_assume_ownership_of_data (cairo_image_surface_t *surface);
1601 
1602 cairo_private cairo_image_surface_t *
1603 _cairo_image_surface_coerce (cairo_image_surface_t	*surface);
1604 
1605 cairo_private cairo_image_surface_t *
1606 _cairo_image_surface_coerce_to_format (cairo_image_surface_t	*surface,
1607 			               cairo_format_t		 format);
1608 
1609 cairo_private cairo_image_transparency_t
1610 _cairo_image_analyze_transparency (cairo_image_surface_t      *image);
1611 
1612 cairo_private cairo_image_color_t
1613 _cairo_image_analyze_color (cairo_image_surface_t      *image);
1614 
1615 /* cairo-pen.c */
1616 cairo_private int
1617 _cairo_pen_vertices_needed (double	    tolerance,
1618 			    double	    radius,
1619 			    const cairo_matrix_t  *matrix);
1620 
1621 cairo_private cairo_status_t
1622 _cairo_pen_init (cairo_pen_t	*pen,
1623 		 double		 radius,
1624 		 double		 tolerance,
1625 		 const cairo_matrix_t	*ctm);
1626 
1627 cairo_private void
1628 _cairo_pen_init_empty (cairo_pen_t *pen);
1629 
1630 cairo_private cairo_status_t
1631 _cairo_pen_init_copy (cairo_pen_t *pen, const cairo_pen_t *other);
1632 
1633 cairo_private void
1634 _cairo_pen_fini (cairo_pen_t *pen);
1635 
1636 cairo_private cairo_status_t
1637 _cairo_pen_add_points (cairo_pen_t *pen, cairo_point_t *point, int num_points);
1638 
1639 cairo_private int
1640 _cairo_pen_find_active_cw_vertex_index (const cairo_pen_t *pen,
1641 					const cairo_slope_t *slope);
1642 
1643 cairo_private int
1644 _cairo_pen_find_active_ccw_vertex_index (const cairo_pen_t *pen,
1645 					 const cairo_slope_t *slope);
1646 
1647 cairo_private void
1648 _cairo_pen_find_active_cw_vertices (const cairo_pen_t *pen,
1649 				     const cairo_slope_t *in,
1650 				     const cairo_slope_t *out,
1651 				     int *start, int *stop);
1652 
1653 cairo_private void
1654 _cairo_pen_find_active_ccw_vertices (const cairo_pen_t *pen,
1655 				     const cairo_slope_t *in,
1656 				     const cairo_slope_t *out,
1657 				     int *start, int *stop);
1658 
1659 /* cairo-polygon.c */
1660 cairo_private void
1661 _cairo_polygon_init (cairo_polygon_t   *polygon,
1662 		     const cairo_box_t *boxes,
1663 		     int		num_boxes);
1664 
1665 cairo_private void
1666 _cairo_polygon_init_with_clip (cairo_polygon_t *polygon,
1667 			       const cairo_clip_t *clip);
1668 
1669 cairo_private cairo_status_t
1670 _cairo_polygon_init_boxes (cairo_polygon_t *polygon,
1671 			   const cairo_boxes_t *boxes);
1672 
1673 cairo_private cairo_status_t
1674 _cairo_polygon_init_box_array (cairo_polygon_t *polygon,
1675 			       cairo_box_t *boxes,
1676 			       int num_boxes);
1677 
1678 cairo_private void
1679 _cairo_polygon_limit (cairo_polygon_t *polygon,
1680 		     const cairo_box_t *limits,
1681 		     int num_limits);
1682 
1683 cairo_private void
1684 _cairo_polygon_limit_to_clip (cairo_polygon_t *polygon,
1685 			      const cairo_clip_t *clip);
1686 
1687 cairo_private void
1688 _cairo_polygon_fini (cairo_polygon_t *polygon);
1689 
1690 cairo_private_no_warn cairo_status_t
1691 _cairo_polygon_add_line (cairo_polygon_t *polygon,
1692 			 const cairo_line_t *line,
1693 			 int top, int bottom,
1694 			 int dir);
1695 
1696 cairo_private_no_warn cairo_status_t
1697 _cairo_polygon_add_external_edge (void *polygon,
1698 				  const cairo_point_t *p1,
1699 				  const cairo_point_t *p2);
1700 
1701 cairo_private_no_warn cairo_status_t
1702 _cairo_polygon_add_contour (cairo_polygon_t *polygon,
1703 			    const cairo_contour_t *contour);
1704 
1705 cairo_private void
1706 _cairo_polygon_translate (cairo_polygon_t *polygon, int dx, int dy);
1707 
1708 cairo_private cairo_status_t
1709 _cairo_polygon_reduce (cairo_polygon_t *polygon,
1710 		       cairo_fill_rule_t fill_rule);
1711 
1712 cairo_private cairo_status_t
1713 _cairo_polygon_intersect (cairo_polygon_t *a, int winding_a,
1714 			  cairo_polygon_t *b, int winding_b);
1715 
1716 cairo_private cairo_status_t
1717 _cairo_polygon_intersect_with_boxes (cairo_polygon_t *polygon,
1718 				     cairo_fill_rule_t *winding,
1719 				     cairo_box_t *boxes,
1720 				     int num_boxes);
1721 
1722 static inline cairo_bool_t
_cairo_polygon_is_empty(const cairo_polygon_t * polygon)1723 _cairo_polygon_is_empty (const cairo_polygon_t *polygon)
1724 {
1725     return
1726 	polygon->num_edges == 0 ||
1727 	polygon->extents.p2.x <= polygon->extents.p1.x;
1728 }
1729 
1730 #define _cairo_polygon_status(P) ((cairo_polygon_t *) (P))->status
1731 
1732 /* cairo-spline.c */
1733 cairo_private cairo_bool_t
1734 _cairo_spline_init (cairo_spline_t *spline,
1735 		    cairo_spline_add_point_func_t add_point_func,
1736 		    void *closure,
1737 		    const cairo_point_t *a, const cairo_point_t *b,
1738 		    const cairo_point_t *c, const cairo_point_t *d);
1739 
1740 cairo_private cairo_status_t
1741 _cairo_spline_decompose (cairo_spline_t *spline, double tolerance);
1742 
1743 cairo_private cairo_status_t
1744 _cairo_spline_bound (cairo_spline_add_point_func_t add_point_func,
1745 		     void *closure,
1746 		     const cairo_point_t *p0, const cairo_point_t *p1,
1747 		     const cairo_point_t *p2, const cairo_point_t *p3);
1748 
1749 /* cairo-matrix.c */
1750 cairo_private void
1751 _cairo_matrix_get_affine (const cairo_matrix_t *matrix,
1752 			  double *xx, double *yx,
1753 			  double *xy, double *yy,
1754 			  double *x0, double *y0);
1755 
1756 cairo_private void
1757 _cairo_matrix_transform_bounding_box (const cairo_matrix_t *matrix,
1758 				      double *x1, double *y1,
1759 				      double *x2, double *y2,
1760 				      cairo_bool_t *is_tight);
1761 
1762 cairo_private void
1763 _cairo_matrix_transform_bounding_box_fixed (const cairo_matrix_t *matrix,
1764 					    cairo_box_t          *bbox,
1765 					    cairo_bool_t         *is_tight);
1766 
1767 cairo_private cairo_bool_t
1768 _cairo_matrix_is_invertible (const cairo_matrix_t *matrix) cairo_pure;
1769 
1770 cairo_private cairo_bool_t
1771 _cairo_matrix_is_scale_0 (const cairo_matrix_t *matrix) cairo_pure;
1772 
1773 cairo_private double
1774 _cairo_matrix_compute_determinant (const cairo_matrix_t *matrix) cairo_pure;
1775 
1776 cairo_private cairo_status_t
1777 _cairo_matrix_compute_basis_scale_factors (const cairo_matrix_t *matrix,
1778 					   double *sx, double *sy, int x_major);
1779 
1780 static inline cairo_bool_t
_cairo_matrix_is_identity(const cairo_matrix_t * matrix)1781 _cairo_matrix_is_identity (const cairo_matrix_t *matrix)
1782 {
1783     return (matrix->xx == 1.0 && matrix->yx == 0.0 &&
1784 	    matrix->xy == 0.0 && matrix->yy == 1.0 &&
1785 	    matrix->x0 == 0.0 && matrix->y0 == 0.0);
1786 }
1787 
1788 static inline cairo_bool_t
_cairo_matrix_is_translation(const cairo_matrix_t * matrix)1789 _cairo_matrix_is_translation (const cairo_matrix_t *matrix)
1790 {
1791     return (matrix->xx == 1.0 && matrix->yx == 0.0 &&
1792 	    matrix->xy == 0.0 && matrix->yy == 1.0);
1793 }
1794 
1795 static inline cairo_bool_t
_cairo_matrix_is_scale(const cairo_matrix_t * matrix)1796 _cairo_matrix_is_scale (const cairo_matrix_t *matrix)
1797 {
1798     return matrix->yx == 0.0 && matrix->xy == 0.0;
1799 }
1800 
1801 cairo_private cairo_bool_t
1802 _cairo_matrix_is_integer_translation(const cairo_matrix_t *matrix,
1803 				     int *itx, int *ity);
1804 
1805 cairo_private cairo_bool_t
1806 _cairo_matrix_has_unity_scale (const cairo_matrix_t *matrix);
1807 
1808 cairo_private cairo_bool_t
1809 _cairo_matrix_is_pixel_exact (const cairo_matrix_t *matrix) cairo_pure;
1810 
1811 cairo_private double
1812 _cairo_matrix_transformed_circle_major_axis (const cairo_matrix_t *matrix,
1813 					     double radius) cairo_pure;
1814 
1815 cairo_private cairo_bool_t
1816 _cairo_matrix_is_pixman_translation (const cairo_matrix_t     *matrix,
1817 				     cairo_filter_t            filter,
1818 				     int                      *out_x_offset,
1819 				     int                      *out_y_offset);
1820 
1821 cairo_private cairo_status_t
1822 _cairo_matrix_to_pixman_matrix_offset (const cairo_matrix_t	*matrix,
1823 				       cairo_filter_t            filter,
1824 				       double                    xc,
1825 				       double                    yc,
1826 				       pixman_transform_t	*out_transform,
1827 				       int                      *out_x_offset,
1828 				       int                      *out_y_offset);
1829 
1830 cairo_private void
1831 _cairo_debug_print_matrix (FILE *file, const cairo_matrix_t *matrix);
1832 
1833 cairo_private void
1834 _cairo_debug_print_rect (FILE *file, const cairo_rectangle_int_t *rect);
1835 
1836 cairo_private cairo_status_t
1837 _cairo_bentley_ottmann_tessellate_rectilinear_polygon (cairo_traps_t	 *traps,
1838 						       const cairo_polygon_t *polygon,
1839 						       cairo_fill_rule_t	  fill_rule);
1840 
1841 cairo_private cairo_status_t
1842 _cairo_bentley_ottmann_tessellate_polygon (cairo_traps_t         *traps,
1843 					   const cairo_polygon_t *polygon,
1844 					   cairo_fill_rule_t      fill_rule);
1845 
1846 cairo_private cairo_status_t
1847 _cairo_bentley_ottmann_tessellate_traps (cairo_traps_t *traps,
1848 					 cairo_fill_rule_t fill_rule);
1849 
1850 cairo_private cairo_status_t
1851 _cairo_bentley_ottmann_tessellate_rectangular_traps (cairo_traps_t *traps,
1852 						     cairo_fill_rule_t fill_rule);
1853 
1854 cairo_private cairo_status_t
1855 _cairo_bentley_ottmann_tessellate_boxes (const cairo_boxes_t *in,
1856 					 cairo_fill_rule_t fill_rule,
1857 					 cairo_boxes_t *out);
1858 
1859 cairo_private cairo_status_t
1860 _cairo_bentley_ottmann_tessellate_rectilinear_traps (cairo_traps_t *traps,
1861 						     cairo_fill_rule_t fill_rule);
1862 
1863 cairo_private cairo_status_t
1864 _cairo_bentley_ottmann_tessellate_rectilinear_polygon_to_boxes (const cairo_polygon_t *polygon,
1865 								cairo_fill_rule_t fill_rule,
1866 								cairo_boxes_t *boxes);
1867 
1868 cairo_private void
1869 _cairo_trapezoid_array_translate_and_scale (cairo_trapezoid_t *offset_traps,
1870 					    cairo_trapezoid_t *src_traps,
1871 					    int num_traps,
1872 					    double tx, double ty,
1873 					    double sx, double sy);
1874 
1875 #if CAIRO_HAS_DRM_SURFACE
1876 
1877 cairo_private void
1878 _cairo_drm_device_reset_static_data (void);
1879 
1880 #endif
1881 
1882 cairo_private void
1883 _cairo_clip_reset_static_data (void);
1884 
1885 cairo_private void
1886 _cairo_pattern_reset_static_data (void);
1887 
1888 /* cairo-unicode.c */
1889 
1890 cairo_private int
1891 _cairo_utf8_get_char_validated (const char *p,
1892 				uint32_t   *unicode);
1893 
1894 cairo_private cairo_status_t
1895 _cairo_utf8_to_ucs4 (const char *str,
1896 		     int	 len,
1897 		     uint32_t  **result,
1898 		     int	*items_written);
1899 
1900 cairo_private int
1901 _cairo_ucs4_to_utf8 (uint32_t    unicode,
1902 		     char       *utf8);
1903 
1904 cairo_private int
1905 _cairo_ucs4_to_utf16 (uint32_t    unicode,
1906 		      uint16_t   *utf16);
1907 
1908 #if CAIRO_HAS_WIN32_FONT || CAIRO_HAS_QUARTZ_FONT || CAIRO_HAS_PDF_OPERATORS
1909 # define CAIRO_HAS_UTF8_TO_UTF16 1
1910 #endif
1911 #if CAIRO_HAS_UTF8_TO_UTF16
1912 cairo_private cairo_status_t
1913 _cairo_utf8_to_utf16 (const char *str,
1914 		      int	  len,
1915 		      uint16_t  **result,
1916 		      int	 *items_written);
1917 #endif
1918 
1919 cairo_private void
1920 _cairo_matrix_multiply (cairo_matrix_t *r,
1921 			const cairo_matrix_t *a,
1922 			const cairo_matrix_t *b);
1923 
1924 /* cairo-observer.c */
1925 
1926 cairo_private void
1927 _cairo_observers_notify (cairo_list_t *observers, void *arg);
1928 
1929 /* Open a file with a UTF-8 filename */
1930 cairo_private cairo_status_t
1931 _cairo_fopen (const char *filename, const char *mode, FILE **file_out);
1932 
1933 /* Avoid unnecessary PLT entries.  */
1934 slim_hidden_proto (cairo_clip_preserve);
1935 slim_hidden_proto (cairo_close_path);
1936 slim_hidden_proto (cairo_create);
1937 slim_hidden_proto (cairo_curve_to);
1938 slim_hidden_proto (cairo_destroy);
1939 slim_hidden_proto (cairo_fill_preserve);
1940 slim_hidden_proto (cairo_font_face_destroy);
1941 slim_hidden_proto (cairo_font_face_get_user_data);
1942 slim_hidden_proto_no_warn (cairo_font_face_reference);
1943 slim_hidden_proto (cairo_font_face_set_user_data);
1944 slim_hidden_proto (cairo_font_options_equal);
1945 slim_hidden_proto (cairo_font_options_hash);
1946 slim_hidden_proto (cairo_font_options_merge);
1947 slim_hidden_proto (cairo_font_options_set_antialias);
1948 slim_hidden_proto (cairo_font_options_set_hint_metrics);
1949 slim_hidden_proto (cairo_font_options_set_hint_style);
1950 slim_hidden_proto (cairo_font_options_set_subpixel_order);
1951 slim_hidden_proto (cairo_font_options_status);
1952 slim_hidden_proto (cairo_format_stride_for_width);
1953 slim_hidden_proto (cairo_get_current_point);
1954 slim_hidden_proto (cairo_get_line_width);
1955 slim_hidden_proto (cairo_get_matrix);
1956 slim_hidden_proto (cairo_get_scaled_font);
1957 slim_hidden_proto (cairo_get_target);
1958 slim_hidden_proto (cairo_get_tolerance);
1959 slim_hidden_proto (cairo_glyph_allocate);
1960 slim_hidden_proto (cairo_glyph_free);
1961 slim_hidden_proto (cairo_image_surface_create);
1962 slim_hidden_proto (cairo_image_surface_create_for_data);
1963 slim_hidden_proto (cairo_image_surface_get_data);
1964 slim_hidden_proto (cairo_image_surface_get_format);
1965 slim_hidden_proto (cairo_image_surface_get_height);
1966 slim_hidden_proto (cairo_image_surface_get_stride);
1967 slim_hidden_proto (cairo_image_surface_get_width);
1968 slim_hidden_proto (cairo_line_to);
1969 slim_hidden_proto (cairo_mask);
1970 slim_hidden_proto (cairo_matrix_init);
1971 slim_hidden_proto (cairo_matrix_init_identity);
1972 slim_hidden_proto (cairo_matrix_init_rotate);
1973 slim_hidden_proto (cairo_matrix_init_scale);
1974 slim_hidden_proto (cairo_matrix_init_translate);
1975 slim_hidden_proto (cairo_matrix_invert);
1976 slim_hidden_proto (cairo_matrix_multiply);
1977 slim_hidden_proto (cairo_matrix_scale);
1978 slim_hidden_proto (cairo_matrix_transform_distance);
1979 slim_hidden_proto (cairo_matrix_transform_point);
1980 slim_hidden_proto (cairo_matrix_translate);
1981 slim_hidden_proto (cairo_move_to);
1982 slim_hidden_proto (cairo_new_path);
1983 slim_hidden_proto (cairo_paint);
1984 slim_hidden_proto (cairo_pattern_add_color_stop_rgba);
1985 slim_hidden_proto (cairo_pattern_create_for_surface);
1986 slim_hidden_proto (cairo_pattern_create_rgb);
1987 slim_hidden_proto (cairo_pattern_create_rgba);
1988 slim_hidden_proto (cairo_pattern_destroy);
1989 slim_hidden_proto (cairo_pattern_get_extend);
1990 slim_hidden_proto (cairo_mesh_pattern_curve_to);
1991 slim_hidden_proto (cairo_mesh_pattern_get_control_point);
1992 slim_hidden_proto (cairo_mesh_pattern_get_corner_color_rgba);
1993 slim_hidden_proto (cairo_mesh_pattern_get_patch_count);
1994 slim_hidden_proto (cairo_mesh_pattern_get_path);
1995 slim_hidden_proto (cairo_mesh_pattern_line_to);
1996 slim_hidden_proto (cairo_mesh_pattern_move_to);
1997 slim_hidden_proto (cairo_mesh_pattern_set_corner_color_rgba);
1998 slim_hidden_proto_no_warn (cairo_pattern_reference);
1999 slim_hidden_proto (cairo_pattern_set_matrix);
2000 slim_hidden_proto (cairo_pop_group);
2001 slim_hidden_proto (cairo_push_group_with_content);
2002 slim_hidden_proto_no_warn (cairo_path_destroy);
2003 slim_hidden_proto (cairo_recording_surface_create);
2004 slim_hidden_proto (cairo_rel_line_to);
2005 slim_hidden_proto (cairo_restore);
2006 slim_hidden_proto (cairo_save);
2007 slim_hidden_proto (cairo_scale);
2008 slim_hidden_proto (cairo_scaled_font_create);
2009 slim_hidden_proto (cairo_scaled_font_destroy);
2010 slim_hidden_proto (cairo_scaled_font_extents);
2011 slim_hidden_proto (cairo_scaled_font_get_ctm);
2012 slim_hidden_proto (cairo_scaled_font_get_font_face);
2013 slim_hidden_proto (cairo_scaled_font_get_font_matrix);
2014 slim_hidden_proto (cairo_scaled_font_get_font_options);
2015 slim_hidden_proto (cairo_scaled_font_glyph_extents);
2016 slim_hidden_proto_no_warn (cairo_scaled_font_reference);
2017 slim_hidden_proto (cairo_scaled_font_status);
2018 slim_hidden_proto (cairo_scaled_font_get_user_data);
2019 slim_hidden_proto (cairo_scaled_font_set_user_data);
2020 slim_hidden_proto (cairo_scaled_font_text_to_glyphs);
2021 slim_hidden_proto (cairo_set_font_matrix);
2022 slim_hidden_proto (cairo_set_font_options);
2023 slim_hidden_proto (cairo_set_font_size);
2024 slim_hidden_proto (cairo_set_line_cap);
2025 slim_hidden_proto (cairo_set_line_join);
2026 slim_hidden_proto (cairo_set_line_width);
2027 slim_hidden_proto (cairo_set_matrix);
2028 slim_hidden_proto (cairo_set_operator);
2029 slim_hidden_proto (cairo_set_source);
2030 slim_hidden_proto (cairo_set_source_rgb);
2031 slim_hidden_proto (cairo_set_source_surface);
2032 slim_hidden_proto (cairo_set_tolerance);
2033 slim_hidden_proto (cairo_status);
2034 slim_hidden_proto (cairo_stroke);
2035 slim_hidden_proto (cairo_stroke_preserve);
2036 slim_hidden_proto (cairo_surface_copy_page);
2037 slim_hidden_proto (cairo_surface_create_similar_image);
2038 slim_hidden_proto (cairo_surface_destroy);
2039 slim_hidden_proto (cairo_surface_finish);
2040 slim_hidden_proto (cairo_surface_flush);
2041 slim_hidden_proto (cairo_surface_get_device_offset);
2042 slim_hidden_proto (cairo_surface_get_device_scale);
2043 slim_hidden_proto (cairo_surface_get_font_options);
2044 slim_hidden_proto (cairo_surface_get_mime_data);
2045 slim_hidden_proto (cairo_surface_has_show_text_glyphs);
2046 slim_hidden_proto (cairo_surface_mark_dirty);
2047 slim_hidden_proto (cairo_surface_mark_dirty_rectangle);
2048 slim_hidden_proto_no_warn (cairo_surface_reference);
2049 slim_hidden_proto (cairo_surface_set_device_offset);
2050 slim_hidden_proto (cairo_surface_set_device_scale);
2051 slim_hidden_proto (cairo_surface_set_fallback_resolution);
2052 slim_hidden_proto (cairo_surface_set_mime_data);
2053 slim_hidden_proto (cairo_surface_show_page);
2054 slim_hidden_proto (cairo_surface_status);
2055 slim_hidden_proto (cairo_surface_supports_mime_type);
2056 slim_hidden_proto (cairo_text_cluster_allocate);
2057 slim_hidden_proto (cairo_text_cluster_free);
2058 slim_hidden_proto (cairo_toy_font_face_create);
2059 slim_hidden_proto (cairo_toy_font_face_get_slant);
2060 slim_hidden_proto (cairo_toy_font_face_get_weight);
2061 slim_hidden_proto (cairo_translate);
2062 slim_hidden_proto (cairo_transform);
2063 slim_hidden_proto (cairo_user_font_face_create);
2064 slim_hidden_proto (cairo_user_font_face_set_init_func);
2065 slim_hidden_proto (cairo_user_font_face_set_render_glyph_func);
2066 slim_hidden_proto (cairo_user_font_face_set_unicode_to_glyph_func);
2067 slim_hidden_proto (cairo_device_to_user);
2068 slim_hidden_proto (cairo_user_to_device);
2069 slim_hidden_proto (cairo_user_to_device_distance);
2070 slim_hidden_proto (cairo_version_string);
2071 slim_hidden_proto (cairo_region_create);
2072 slim_hidden_proto (cairo_region_create_rectangle);
2073 slim_hidden_proto (cairo_region_create_rectangles);
2074 slim_hidden_proto (cairo_region_copy);
2075 slim_hidden_proto (cairo_region_reference);
2076 slim_hidden_proto (cairo_region_destroy);
2077 slim_hidden_proto (cairo_region_equal);
2078 slim_hidden_proto (cairo_region_status);
2079 slim_hidden_proto (cairo_region_get_extents);
2080 slim_hidden_proto (cairo_region_num_rectangles);
2081 slim_hidden_proto (cairo_region_get_rectangle);
2082 slim_hidden_proto (cairo_region_is_empty);
2083 slim_hidden_proto (cairo_region_contains_rectangle);
2084 slim_hidden_proto (cairo_region_contains_point);
2085 slim_hidden_proto (cairo_region_translate);
2086 slim_hidden_proto (cairo_region_subtract);
2087 slim_hidden_proto (cairo_region_subtract_rectangle);
2088 slim_hidden_proto (cairo_region_intersect);
2089 slim_hidden_proto (cairo_region_intersect_rectangle);
2090 slim_hidden_proto (cairo_region_union);
2091 slim_hidden_proto (cairo_region_union_rectangle);
2092 slim_hidden_proto (cairo_region_xor);
2093 slim_hidden_proto (cairo_region_xor_rectangle);
2094 
2095 #if CAIRO_HAS_PNG_FUNCTIONS
2096 
2097 slim_hidden_proto (cairo_surface_write_to_png_stream);
2098 
2099 #endif
2100 
2101 CAIRO_END_DECLS
2102 
2103 #include "cairo-mutex-private.h"
2104 #include "cairo-fixed-private.h"
2105 #include "cairo-wideint-private.h"
2106 #include "cairo-malloc-private.h"
2107 #include "cairo-hash-private.h"
2108 
2109 #if HAVE_VALGRIND
2110 #include <memcheck.h>
2111 
2112 #define VG(x) x
2113 
2114 cairo_private void
2115 _cairo_debug_check_image_surface_is_defined (const cairo_surface_t *surface);
2116 
2117 #else
2118 
2119 #define VG(x)
2120 #define _cairo_debug_check_image_surface_is_defined(X)
2121 
2122 #endif
2123 
2124 cairo_private void
2125 _cairo_debug_print_path (FILE *stream, const cairo_path_fixed_t *path);
2126 
2127 cairo_private void
2128 _cairo_debug_print_polygon (FILE *stream, cairo_polygon_t *polygon);
2129 
2130 cairo_private void
2131 _cairo_debug_print_traps (FILE *file, const cairo_traps_t *traps);
2132 
2133 cairo_private void
2134 _cairo_debug_print_clip (FILE *stream, const cairo_clip_t *clip);
2135 
2136 #if 0
2137 #define TRACE(x) fprintf (stderr, "%s: ", __FILE__), fprintf x
2138 #define TRACE_(x) x
2139 #else
2140 #define TRACE(x)
2141 #define TRACE_(x)
2142 #endif
2143 
2144 #endif
2145