Пример #1
0
    def draw_line(self, gc, x1, y1, x2, y2):
	if isnan(x1) or isnan(x2) or isnan(y1) or isnan(y2):
	    return
	d = self.dpi_factor
	self.check_gc(gc)
	self.file.output(d*x1, d*y1, Op.moveto,
			 d*x2, d*y2, Op.lineto, self.gc.paint())
Пример #2
0
 def draw_line(self, gc, x1, y1, x2, y2):
     if isnan(x1) or isnan(x2) or isnan(y1) or isnan(y2):
         return
     d = self.dpi_factor
     self.check_gc(gc)
     self.file.output(d * x1, d * y1, Op.moveto, d * x2, d * y2, Op.lineto,
                      self.gc.paint())
Пример #3
0
 def draw_lines(self, gc, x, y, transform=None):
     d = self.dpi_factor
     self.check_gc(gc)
     if transform is not None:
         x, y = transform.seq_x_y(x, y)
     nan_at = isnan(x) | isnan(y)
     next_op = Op.moveto
     for i in range(len(x)):
         if nan_at[i]:
             next_op = Op.moveto
         else:
             self.file.output(d * x[i], d * y[i], next_op)
             next_op = Op.lineto
     self.file.output(self.gc.paint())
Пример #4
0
    def draw_lines(self, gc, x, y, transform=None):
	d = self.dpi_factor
	self.check_gc(gc)
	if transform is not None:
	    x, y = transform.seq_x_y(x, y)
	nan_at = isnan(x) | isnan(y)
	next_op = Op.moveto
	for i in range(len(x)):
	    if nan_at[i]:
		next_op = Op.moveto
	    else:
		self.file.output(d*x[i], d*y[i], next_op)
		next_op = Op.lineto
	self.file.output(self.gc.paint())
Пример #5
0
    def draw_markers(self, gc, path, rgbFace, x, y, trans):
        self.check_gc(gc, rgbFace)
        fillp = rgbFace is not None
        marker = self.file.markerObject(path, fillp, self.gc._linewidth)
        x, y = trans.numerix_x_y(asarray(x), asarray(y))
        x, y = self.dpi_factor * x, self.dpi_factor * y
        nan_at = isnan(x) | isnan(y)

        self.file.output(Op.gsave)
        ox, oy = 0, 0
        for i in range(len(x)):
            if nan_at[i]: continue
            dx, dy, ox, oy = x[i] - ox, y[i] - oy, x[i], y[i]
            self.file.output(1, 0, 0, 1, dx, dy, Op.concat_matrix, marker,
                             Op.use_xobject)
        self.file.output(Op.grestore)
Пример #6
0
    def draw_markers(self, gc, path, rgbFace, x, y, trans):
	self.check_gc(gc, rgbFace)
	fillp = rgbFace is not None
	marker = self.file.markerObject(path, fillp, self.gc._linewidth)
	x, y = trans.numerix_x_y(asarray(x), asarray(y))
	x, y = self.dpi_factor * x, self.dpi_factor * y
	nan_at = isnan(x) | isnan(y)

	self.file.output(Op.gsave)
	ox, oy = 0, 0
	for i in range(len(x)):
	    if nan_at[i]: continue
	    dx, dy, ox, oy = x[i]-ox, y[i]-oy, x[i], y[i]
	    self.file.output(1, 0, 0, 1, dx, dy, 
			     Op.concat_matrix,
			     marker, Op.use_xobject)
	self.file.output(Op.grestore)
Пример #7
0
def pdfRepr(obj):
    """Map Python objects to PDF syntax."""

    # Some objects defined later have their own pdfRepr method.
    if 'pdfRepr' in dir(obj):
        return obj.pdfRepr()

    # Floats. PDF does not have exponential notation (1.0e-10) so we
    # need to use %f with some precision.  Perhaps the precision
    # should adapt to the magnitude of the number?
    elif isinstance(obj, float):
        if isnan(obj) or obj in (-infinity, infinity):
            raise ValueError, "Can only output finite numbers in PDF"
        r = "%.10f" % obj
        return r.rstrip('0').rstrip('.')

    # Integers are written as such.
    elif isinstance(obj, (int, long)):
        return "%d" % obj

    # Strings are written in parentheses, with backslashes and parens
    # escaped. Actually balanced parens are allowed, but it is
    # simpler to escape them all. TODO: cut long strings into lines;
    # I believe there is some maximum line length in PDF.
    elif is_string_like(obj):
        return '(' + re.sub(r'([\\()])', r'\\\1', obj) + ')'

    # Dictionaries. The keys must be PDF names, so if we find strings
    # there, we make Name objects from them. The values may be
    # anything, so the caller must ensure that PDF names are
    # represented as Name objects.
    elif isinstance(obj, dict):
        r = ["<<"]
        r.extend([
            "%s %s" % (Name(key).pdfRepr(), pdfRepr(val))
            for key, val in obj.items()
        ])
        r.append(">>")
        return fill(r)

    # Lists.
    elif isinstance(obj, (list, tuple)):
        r = ["["]
        r.extend([pdfRepr(val) for val in obj])
        r.append("]")
        return fill(r)

    # Booleans.
    elif isinstance(obj, bool):
        return ['false', 'true'][obj]

    # The null keyword.
    elif obj is None:
        return 'null'

    # A date.
    elif isinstance(obj, datetime):
        r = obj.strftime('D:%Y%m%d%H%M%S')
        if time.daylight: z = time.altzone
        else: z = time.timezone
        if z == 0: r += 'Z'
        elif z < 0: r += "+%02d'%02d'" % ((-z) // 3600, (-z) % 3600)
        else: r += "-%02d'%02d'" % (z // 3600, z % 3600)
        return pdfRepr(r)

    else:
        raise TypeError, \
            "Don't know a PDF representation for %s objects." \
            % type(obj)
Пример #8
0
def pdfRepr(obj):
    """Map Python objects to PDF syntax."""

    # Some objects defined later have their own pdfRepr method.
    if 'pdfRepr' in dir(obj):
	return obj.pdfRepr()

    # Floats. PDF does not have exponential notation (1.0e-10) so we
    # need to use %f with some precision.  Perhaps the precision
    # should adapt to the magnitude of the number?
    elif isinstance(obj, float):
	if isnan(obj) or obj in (-infinity, infinity):
	    raise ValueError, "Can only output finite numbers in PDF"
	r = "%.10f" % obj
	return r.rstrip('0').rstrip('.')

    # Integers are written as such.
    elif isinstance(obj, (int, long)):
	return "%d" % obj

    # Strings are written in parentheses, with backslashes and parens
    # escaped. Actually balanced parens are allowed, but it is
    # simpler to escape them all. TODO: cut long strings into lines;
    # I believe there is some maximum line length in PDF.
    elif is_string_like(obj):
	return '(' + re.sub(r'([\\()])', r'\\\1', obj) + ')'

    # Dictionaries. The keys must be PDF names, so if we find strings
    # there, we make Name objects from them. The values may be
    # anything, so the caller must ensure that PDF names are
    # represented as Name objects.
    elif isinstance(obj, dict):
	r = ["<<"]
	r.extend(["%s %s" % (Name(key).pdfRepr(),
			     pdfRepr(val))
		  for key, val in obj.items()])
	r.append(">>")
	return fill(r)

    # Lists.
    elif isinstance(obj, (list, tuple)):
	r = ["["]
	r.extend([pdfRepr(val) for val in obj])
	r.append("]")
	return fill(r)

    # Booleans.
    elif isinstance(obj, bool):
	return ['false', 'true'][obj]

    # The null keyword.
    elif obj is None:
	return 'null'

    # A date.
    elif isinstance(obj, datetime):
	r = obj.strftime('D:%Y%m%d%H%M%S')
	if time.daylight: z = time.altzone
	else: z = time.timezone
	if z == 0: r += 'Z'
	elif z < 0: r += "+%02d'%02d'" % ((-z)//3600, (-z)%3600)
	else: r += "-%02d'%02d'" % (z//3600, z%3600)
	return pdfRepr(r)

    else:
	raise TypeError, \
	    "Don't know a PDF representation for %s objects." \
	    % type(obj)