When an unbounded recording surface is used multiple times with
different extents for each operation we need the XObject containing
the recording surface to have the same origin for each operation. This
is not possible when the recording surface is converted to PDF
coordinates because each operation has different extents resulting in
a different origin when the Y-axis is flipped (since the flip matrix
depends on the recording surface height which for unbounded surfaces
depends on the extents of the operation that paints the recording
surface).
Switching to cairo coordinates by emitting a Y-axis flip matrix as the
first object of each page allows the recording surface to be emitted
in cairo coordinates. This results in the same origin for all
operations using the recording surface XObject.
since the PS Document Structing Conventions impose a 255 character
line limit. PDF does not require wrapping.
pdf-operators is designed to emit the same output for PS and PDF.
Unfortunately some PDF interpreters don't like strings split with
'\\\n' and some PS interpreters don't like strings split with ')('.
So we are forced to make pdf-operators handling string wrapping
differently for PDF and PS.
Bug 85662
Sometimes as a result of rounding errors in matrix transformations the
matrices in ps/pdf output look like:
0.000000000000000061 1 1 -0.000000000000000061 0 842 cm
This patch rounds to zero matrix elements that are very small compared to
other elements in the same matrix.
Since PDF stores the alpha component of images in a separate stream
which can have a different resolution and encoding to the color
components we can optimize the case where the source and mask are both images.
If the source and mask are both images with the same extents and the
source is opaque, combine the images into a single PDF image (ie the
source is written the the image stream and the mask is written to the
smask stream).
JBIG2 images may have shared global data that is stored in a separate
stream in PDF. The CAIRO_MIME_TYPE_JBIG2 mime type is for the JBIG2
data for each image. All images that use global data must also set
CAIRO_MIME_TYPE_JBIG2_GLOBAL_ID to a unique identifier. One of the
images must also set CAIRO_MIME_TYPE_JBIG2_GLOBAL to the global
data. The global data will be shared by all JBIG2 images with the same
CAIRO_MIME_TYPE_JBIG2_GLOBAL_ID.
If the group contains only a combination of clear and opaque alpha and
only OPERATOR_OVER is used in the group and to paint the group, a
transparency group is not required. This allows the pdf viewer to
replay the group in place.
cairo-pdf-surface.c: In function '_cairo_pdf_surface_add_source_surface.isra.20':
cairo-pdf-surface.c:1461:10: warning: 'unique_id' may be used uninitialized in this function [-Wmaybe-uninitialized]
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
There are only three possible color states: COLOR, GRAYSCALE, or
MONOCHROME thus data and data_size will always be set to some value,
so assert the default is never reached.
Fixes these warning:
cairo-pdf-surface.c:2517:32: warning: ‘data_size’ may be used
uninitialized in this function [-Wuninitialized]
cairo-pdf-surface.c:2338:19: note: ‘data_size’ was declared here
cairo-pdf-surface.c:2446:11: warning: ‘data’ may be used uninitialized
in this function [-Wuninitialized]
cairo-pdf-surface.c:2337:11: note: ‘data’ was declared here
Signed-off-by: Bryce Harrington <b.harrington@samsung.com>
In order to prevent a race between concurrent destroy and use in another
thread, we need to acquire a reference to the snapshot->target under a
mutex. Whilst we hold that reference, it prevents the internal destroy
mechanism from freeing the memory we are using (if we have a pointer to
the original surface) and the client drops their final reference.
Oh boy, talk about opening a can of worms...
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
_cairo_pdf_surface_add_source_surface allocates unique_id with
size unique_id_length but then copies surface_key.unique_id_length into it.
This causes e.g. evince to crash predictably while trying to print with:
*** buffer overflow detected ***: evince terminated
We should be using surface_key.unique_id_length instead.
Reported-by: Dominique Leuenberger <dominique-freedesktop.org@leuenberger.net>
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=49089
Signed-off-by: Jeff Mahoney <jeffm@suse.com>
We need to occasionally force fallbacks whilst testing the PDF
output, so export a debug interface to do so in order to avoid poking
around inside cairo internals.
References: https://bugs.freedesktop.org/show_bug.cgi?id=48577
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
The following Python script was used to compute "Since: 1.X" tags,
based on the first version where a symbol became officially supported.
This script requires a concatenation of the the cairo public headers
for the officially supported beckends to be available as
"../../includes/1.X.0.h".
from sys import argv
import re
syms = {}
def stripcomments(text):
def replacer(match):
s = match.group(0)
if s.startswith('/'):
return ""
else:
return s
pattern = re.compile(
r'//.*?$|/\*.*?\*/|\'(?:\\.|[^\\\'])*\'|"(?:\\.|[^\\"])*"',
re.DOTALL | re.MULTILINE
)
return re.sub(pattern, replacer, text)
for minor in range(12,-2,-2):
version = "1.%d" % minor
names = re.split('([A-Za-z0-9_]+)', stripcomments(open("../../includes/%s.0.h" % version).read()))
for s in names: syms[s] = version
for filename in argv[1:]:
is_public = False
lines = open(filename, "r").read().split("\n")
newlines = []
for i in range(len(lines)):
if lines[i] == "/**":
last_sym = lines[i+1][2:].strip().replace(":", "")
is_public = last_sym.lower().startswith("cairo")
elif is_public and lines[i] == " **/":
if last_sym in syms:
v = syms[last_sym]
if re.search("Since", newlines[-1]): newlines = newlines[:-1]
if newlines[-1].strip() != "*": newlines.append(" *")
newlines.append(" * Since: %s" % v)
else:
print "%s (%d): Cannot determine the version in which '%s' was introduced" % (filename, i, last_sym)
newlines.append(lines[i])
out = open(filename, "w")
out.write("\n".join(newlines))
out.close()
Documentation comments should always start with "/**" and end with
"**/". This is not required by gtk-doc, but it makes the
documentations formatting more consistent and simplifies the checking
of documentation comments.
The following Python script tries to enforce this.
from sys import argv
from sre import search
for filename in argv[1:]:
in_doc = False
lines = open(filename, "r").read().split("\n")
for i in range(len(lines)):
ls = lines[i].strip()
if ls == "/**":
in_doc = True
elif in_doc and ls == "*/":
lines[i] = " **/"
if ls.endswith("*/"):
in_doc = False
out = open(filename, "w")
out.write("\n".join(lines))
out.close()
This fixes most 'documentation comment not closed with **/' warnings
by check-doc-syntax.awk.
Ordinary patterns have their device offsets pre-baked into the pattern
matrix. The difference with raster patterns is that the surface is
generated upon use by the pdf,ps and so its device offset is not known
until then.
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>