示例#1
0
 def addCenteredGuides(self):
     doc = self.doc
     layout = doc.Layout()
     hor_p = layout.Width()
     ver_p = layout.Height()
     doc.AddGuideLine(Point(0, ver_p / 2), 1)
     doc.AddGuideLine(Point(hor_p / 2, 0), 0)
    def DrawDragged(self, device, partially):
	sel = self.selection

	if sel == -1:
	    sx, sy = self.start + self.off
	    ex, ey = self.end + self.off
	else:
	    if sel in self.selTop:
		sy = self.drag_cur.y
	    else:
		sy = self.start.y

	    if sel in self.selBottom:
		ey = self.drag_cur.y
	    else:
		ey = self.end.y

	    if sel in self.selLeft:
		sx = self.drag_cur.x
	    else:
		sx = self.start.x

	    if sel in self.selRight:
		ex = self.drag_cur.x
	    else:
		ex = self.end.x

	if sx > ex:
	    tmp = sx; sx = ex; ex = tmp
	if sy < ey:
	    tmp = sy; sy = ey; ey = tmp

	device.DrawRubberRect(Point(sx, sy), Point(ex, ey))
示例#3
0
 def hvcurveto(self):
     dx1, dx2, dy2, dy3 = self.pop_all()
     d1 = self.cur + Point(dx1, 0)
     d2 = d1 + Point(dx2, dy2)
     d3 = d2 + Point(0, dy3)
     self.cur = d3
     self.path.append(tuple(d1) + tuple(d2) + tuple(d3))
示例#4
0
 def vhcurveto(self):
     dy1, dx2, dy2, dx3 = self.pop_all()
     d1 = self.cur + Point(0, dy1)
     d2 = d1 + Point(dx2, dy2)
     d3 = d2 + Point(dx3, 0)
     self.cur = d3
     self.path.append(tuple(d1) + tuple(d2) + tuple(d3))
    def apply_constraint(self, p, state):
	if state:
	    if self.selection in self.selAspect:
		ref_x, ref_y = self.reference
		aspect = self.aspect
		if aspect is None:
		    # width is 0
		    p = Point(self.drag_start.x, p.y)
		else:
		    w = p.x - ref_x
		    h = p.y - ref_y
		    if w == 0:
			w = 0.00001
		    a = h / w
		    if a > 0:
			sign = 1
		    else:
			sign = -1
		    if abs(a) > aspect:
			h = sign * w * aspect
		    else:
			w = sign * h / aspect
		    p = Point(ref_x + w, ref_y + h)
# 	if state & const.AlternateMask:
# 		pi4 = math.pi / 4
# 		off = p - self.drag_start
#                 d = Polar(pi4 * round(math.atan2(off.y, off.x) / pi4))
#                 p = self.drag_start + (off * d) * d
# 		print 'ALT'	
	if state & const.ConstraintMask:# and self.selection == -1:
		pi4 = math.pi / 4
		off = p - self.drag_start
                d = Polar(pi4 * round(math.atan2(off.y, off.x) / pi4))
                p = self.drag_start + (off * d) * d
	return p
示例#6
0
 def ButtonDown(self, p, button, state):
     self.DragStart(p)
     if self.horizontal:
         result = Point(0, p.y - self.point.y)
     else:
         result = Point(p.x - self.point.x, 0)
     return result
 def __init__(self, rect, center=None):
     SelRectBase.__init__(self)
     self.start = Point(rect.left, rect.bottom)
     self.end = Point(rect.right, rect.top)
     if center is None:
         self.center = rect.center()
     else:
         self.center = center
	def RECT(self, size):
		ll = self.trafo(self.Pnt())
		ur = self.trafo(self.Pnt())
		lr = Point(ur.x , ll.y)
		ul = Point(ll.x , ur.y)
		T = transform_base(ll , lr , ul)
		self.setfillstyle()
		apply(self.rectangle , T.coeff())
示例#9
0
 def rect_to_ltrb(self, rct, zero=Point(0, 0)):
     trf = rct.trafo
     P1 = self.trafo(trf(zero))
     P2 = self.trafo(trf(Point(1, 1)))
     left = rndtoint(min(P1.x, P2.x))
     bottom = rndtoint(max(P1.y, P2.y))
     right = rndtoint(max(P1.x, P2.x))
     top = rndtoint(min(P1.y, P2.y))
     return left, top, right, bottom
 def Normalize(self):
     sx, sy = self.start
     ex, ey = self.end
     if sx > ex:
         sx, ex = ex, sx
     if sy > ey:
         sy, ey = ey, sy
     self.start = Point(sx, sy)
     self.end = Point(ex, ey)
示例#11
0
	def TextCaretData(self, text, pos, size):
		from math import tan, pi
		size = size / 1000.0
		x = self.metric.string_width(text, pos) * size
		lly = self.metric.lly * size
		ury = self.metric.ury * size
		t = tan(self.metric.italic_angle * pi / 180.0);
		up = ury - lly
		return Point(x - t * lly, lly), Point(-t * up, up)
示例#12
0
 def addGuidesFrame(self, *arg):
     border = self.var_jump.get()
     doc = self.doc
     layout = doc.Layout()
     hor_p = layout.Width()
     ver_p = layout.Height()
     doc.AddGuideLine(Point(0, 0 + border), 1)
     doc.AddGuideLine(Point(0 + border, 0), 0)
     doc.AddGuideLine(Point(0, ver_p - border), 1)
     doc.AddGuideLine(Point(hor_p - border, 0), 0)
示例#13
0
    def make_gradient_pattern(self):
        name, trafo, start, end = self.gradient_geo
        self.gradient_geo = None
        type, array = self.gradients[name]
        array = array[:]
        if type == 0:
            # linear (axial) gradient
            origdir = end - start
            start = trafo(start)
            end = trafo(end)
            dir = end - start
            try:
                # adjust endpoint to accomodate trafo
                v = trafo.DTransform(origdir.y, -origdir.x).normalized()
                v = Point(v.y, -v.x)  # rotate 90 degrees
                end = start + (v * dir) * v
                dir = end - start
            except ZeroDivisionError:
                pass

            trafo2 = Trafo(dir.x, dir.y, dir.y, -dir.x, start.x, start.y)
            trafo2 = trafo2.inverse()
            left, bottom, right, top = trafo2(self.current_bounding_rect())
            if right > left:
                factor = 1 / (right - left)
                offset = -left * factor
            else:
                factor = 1
                offset = 0
            array = fix_gradient(array, factor, offset)
            pattern = LinearGradient(MultiGradient(array),
                                     (start - end).normalized())
        elif type == 1:
            # radial gradient
            start = trafo(start)
            end = trafo(end)
            left, bottom, right, top = self.current_bounding_rect()
            if left == right or top == bottom:
                # an empty coord_rect????
                center = Point(0, 0)
            else:
                center = Point((start.x - left) / (right - left),
                               (start.y - bottom) / (top - bottom))
            radius = max(hypot(left - start.x, top - start.y),
                         hypot(right - start.x, top - start.y),
                         hypot(right - start.x, bottom - start.y),
                         hypot(left - start.x, bottom - start.y))
            if radius:
                factor = -abs(start - end) / radius
                array = fix_gradient(array, factor, 1)
            pattern = RadialGradient(MultiGradient(array), center)
        else:
            self.add_message(_("Unknown gradient type %d"), type)
            pattern = EmptyPattern
        return pattern
示例#14
0
	def Rectangle(self, rct):
		trf = rct.trafo
		if rct.radius1 != 0 or rct.radius2 != 0:
			self.PolyBezier(rct.Paths(), rct.Properties())
		elif (trf.m12 == 0 and trf.m21 == 0) or (trf.m11 == 0 and trf.m22 == 0):
			self.FillStyle(rct.Properties())
			P1 = trf(Point(0, 0))
			P2 = trf(Point(1, 1))
			self.putlongseq(0x4160 , map(rndtoint , tuple(self.trafo(P1)) \
				+ tuple(self.trafo(P2))))
		else:
			self.PolyBezier(rct.Paths(), rct.Properties())
示例#15
0
 def SetPoint(self, point):
     undo = (self.SetPoint, self.point)
     if type(point) != PointType:
         if type(point) == type(()):
             point = apply(Point, point)
         else:
             if self.horizontal:
                 point = Point(self.point.x, point)
             else:
                 point = Point(point, self.point.y)
     self.point = point
     return undo
 def __init__(self, rect, anchor=None):
     SelRectBase.__init__(self)
     if type(rect) == RectType:
         self.start = Point(rect.left, rect.bottom)
         self.end = Point(rect.right, rect.top)
         self.Normalize()
         self.anchor = anchor
     else:
         # assume type Point and interactive creation
         self.start = rect
         self.end = rect
         self.anchor = None
         self.selection = 5
示例#17
0
	def __init__(self, gradient = None,
					center = Point(0.5, 0.5), direction = Point(1, 0),
					duplicate = None):
		GradientPattern.__init__(self, gradient, duplicate = duplicate)
		self.center = center
		self.direction = direction
		if duplicate is not None:
			if duplicate.__class__ == self.__class__:
				self.center = duplicate.center
				self.direction = duplicate.direction
			elif duplicate.__class__ == LinearGradient:
				self.direction = duplicate.direction
			elif duplicate.__class__ == RadialGradient:
				self.center = duplicate.center
示例#18
0
 def makePageFrame(self):
     doc = self.doc
     layout = doc.Layout()
     hor_p = layout.Width()
     ver_p = layout.Height()
     path = CreatePath()
     path.AppendLine(Point(0, 0))
     path.AppendLine(Point(hor_p, 0))
     path.AppendLine(Point(hor_p, ver_p))
     path.AppendLine(Point(0, ver_p))
     path.AppendLine(Point(0, 0))
     path.AppendLine(path.Node(0))
     path.ClosePath()
     bezier = PolyBezier((path, ))
     doc.Insert(bezier)
    def Transform(self, trafo, rects=None):
        dir = trafo.DTransform(self.direction).normalized()
        if rects:
            r1, r2 = rects
            left, bottom, right, top = r1
            cx, cy = self.center
            cx = cx * right + (1 - cx) * left
            cy = cy * top + (1 - cy) * bottom
            cx, cy = trafo(cx, cy)
            left, bottom, right, top = r2
            len = right - left
            if len:
                cx = (cx - left) / len
            else:
                cx = 0
            len = top - bottom
            if len:
                cy = (cy - bottom) / len
            else:
                cy = 0
            center = Point(cx, cy)
        else:
            center = self.center

        return self.__set_center_and_dir(center, dir)
	def bugmark(self, P):
		P = P - Point(1, 1)
		style = basestyle.Duplicate()
		style.fill_pattern = SolidPattern(StandardColors.black)
		style.line_pattern = SolidPattern(StandardColors.black)
		self.prop_stack.AddStyle(style)
		self.rectangle(2, 0, 0, 2, P.x, P.y)
	def TEXT(self, size):
		P = self.Pnt()
		F = self.Enum()
		S = self.getstr()
		T = Translation(self.trafo(P))
		Py = Point(reff.text.orientation[0]).normalized()
		Px = Point(reff.text.orientation[1]).normalized()
		B = transform_base(Point(0.0, 0.0) , reff.text.expansion * Px , Py)
		self.style = basestyle.Duplicate()
		self.style.font = GetFont(fntlst[self.fntmap[reff.text.fontindex]])
		self.style.font_size = reff.text.height * self.Scale
		self.style.fill_pattern = SolidPattern(apply(CreateRGBColor , reff.text.color))
		O = text.SimpleText(text=S, trafo=T(B),
							halign=text.ALIGN_LEFT, valign=text.ALIGN_BASE,
							properties=self.get_prop_stack())
		self.append_object(O)
 def ButtonDown(self, p, button, state):
     self.drag_state = state
     self.trafo = Identity
     self.trafo_desc = (0, 0)
     SelectAndDrag.DragStart(self, p)
     sel = self.selection
     if sel == self.selCenter:
         self.drag_cur = self.drag_start = self.center
         return p - self.center
     ds_x = ds_y = 0
     if sel in self.selLeft:
         ds_x = self.start.x
     if sel in self.selTop:
         ds_y = self.start.y
     if sel in self.selRight:
         ds_x = self.end.x
     if sel in self.selBottom:
         ds_y = self.end.y
     self.drag_cur = self.drag_start = ds = Point(ds_x, ds_y)
     if sel in self.selTurn:
         vec = ds - self.center
         self.start_angle = math.atan2(vec.y, vec.x)
     else:
         if sel == 2:
             self.reference = self.end.y
         elif sel == 4:
             self.reference = self.start.x
         elif sel == 6:
             self.reference = self.start.y
         elif sel == 8:
             self.reference = self.end.x
     return p - ds
示例#23
0
 def gradient_geometry(self, flag, name, xorig, yorig, angle, length, a, b,
                       c, d, tx, ty):
     trafo = Trafo(a, b, c, d, tx, ty)
     trafo = artboard_trafo_inv(trafo(artboard_trafo))
     start = Point(xorig, yorig)
     end = start + Polar(length, (pi * angle) / 180.0)
     self.gradient_geo = (name, trafo, start, end)
 def Transform(self, trafo, rects=None):
     dx, dy = self.direction
     dx, dy = trafo.DTransform(dy, -dx)
     dir = Point(dy, -dx).normalized()
     if dir * trafo.DTransform(self.direction) < 0:
         dir = -dir
     return self.SetDirection(dir)
	def __init__(self, file, filename, match):
		GenericLoader.__init__(self, file, filename, match)
		self.file = file
		self.curstyle = Style()
		self.verbosity = 0
		self.gdiobjects = []
		self.dcstack = []
		self.curpoint = Point(0, 0)
 def compute_endpoints(self):
     cur = self.drag_cur
     start = self.start
     end = self.end
     sel = self.selection
     if sel in self.selTop:
         start = Point(start.x, cur.y)
     if sel in self.selBottom:
         end = Point(end.x, cur.y)
     if sel in self.selLeft:
         start = Point(cur.x, start.y)
     if sel in self.selRight:
         end = Point(cur.x, end.y)
     if sel == -1:
         start = start + self.off
         end = end + self.off
     return start, end
示例#27
0
 def rmoveto(self):
     dx, dy = self.pop_all()
     self.cur = self.cur + Point(dx, dy)
     if self.in_flex:
         self.flex.append(self.cur)
     else:
         self.new_path()
         self.path.append(tuple(self.cur))
示例#28
0
    def VDistributeSelection(self, y, reference=SELECT):
        if self.is_selection(reference) and y:
            self.document.begin_transaction(TRANSACTION)
            try:
                try:
                    add_undo = self.document.add_undo
                    objects = self.document.selection.GetObjects()
                    if reference == PAGE:
                        brleft, brbottom, brright, brtop = self.document.PageRect(
                        )
                    else:
                        brleft, brbottom, brright, brtop = self.document.selection.coord_rect

                    posv = []
                    total_height = 0
                    for obj in objects:
                        rect = obj.coord_rect
                        posv.append((rect.top, rect.bottom - rect.top, obj))
                        total_height += rect.bottom - rect.top
                    posv.sort()
                    posv.reverse()

                    first_obj_top, first_obj_height, first_obj = posv[0]
                    last_obj_top, last_obj_height, last_obj = posv[-1]

                    # how much influence of the height. 1-no, 0-full
                    part_obj_dict = [None, 1.0, 0.5, 1.0, 0]
                    # influence the height last object
                    first_obj_dict = [
                        None, 0, first_obj_height * 0.5, 0, first_obj_height
                    ]
                    # influence the height last object
                    last_obj_dict = [
                        None, last_obj_height, last_obj_height * 0.5, 0, 0
                    ]
                    # influence the height. 0-no , 1-yes
                    height_obj_dict = [None, 0, 0, 1, 0]

                    brtop += first_obj_dict[y]
                    brbottom -= last_obj_dict[y]
                    brwidth = (brbottom - brtop -
                               total_height * height_obj_dict[y])
                    if reference == EDGE:
                        step = -1 * config.preferences.handle_jump
                    else:
                        step = brwidth / (len(posv) - 1)
                    part = part_obj_dict[y]
                    next = 0
                    for top, height, obj in posv[0:]:
                        off = Point(
                            0, next - top + brtop - height + height * part)
                        self.document.add_undo(obj.Translate(off))
                        next += step + height * height_obj_dict[y]
                    add_undo(self.document.queue_edited())
                except:
                    self.document.abort_transaction()
            finally:
                self.document.end_transaction()
示例#29
0
    def HDistributeSelection(self, x, reference=SELECT):
        if self.is_selection(reference) and x:
            self.document.begin_transaction(TRANSACTION)
            try:
                try:
                    add_undo = self.document.add_undo
                    objects = self.document.selection.GetObjects()
                    if reference == PAGE:
                        brleft, brbottom, brright, brtop = self.document.PageRect(
                        )
                    else:
                        brleft, brbottom, brright, brtop = self.document.selection.coord_rect

                    posh = []
                    total_width = 0
                    for obj in objects:
                        rect = obj.coord_rect
                        posh.append((rect.left, rect.right - rect.left, obj))
                        total_width += rect.right - rect.left
                    posh.sort()

                    first_obj_left, first_obj_width, first_obj = posh[0]
                    last_obj_left, last_obj_width, last_obj = posh[-1]

                    # how much influence of the width. 1-no, 0-full
                    part_obj_dict = [None, 1.0, 0.5, 1.0, 0]
                    # influence the width last object
                    first_obj_dict = [
                        None, 0, first_obj_width * 0.5, 0, first_obj_width
                    ]
                    # influence the width last object
                    last_obj_dict = [
                        None, last_obj_width, last_obj_width * 0.5, 0, 0
                    ]
                    # influence the width. 0-no , 1-yes
                    width_obj_dict = [None, 0, 0, 1, 0]

                    brleft += first_obj_dict[x]
                    brright -= last_obj_dict[x]
                    brwidth = (brright - brleft -
                               total_width * width_obj_dict[x])
                    if reference == EDGE:
                        step = config.preferences.handle_jump
                    else:
                        step = brwidth / (len(posh) - 1)
                    part = part_obj_dict[x]
                    next = 0
                    for left, width, obj in posh[0:]:
                        off = Point(
                            next - left + brleft - width + width * part, 0)
                        self.document.add_undo(obj.Translate(off))
                        next += step + width * width_obj_dict[x]
                    add_undo(self.document.queue_edited())
                except:
                    self.document.abort_transaction()
            finally:
                self.document.end_transaction()
示例#30
0
 def reset(self):
     self.stack = []
     self.ps_stack = []
     self.paths = ()
     self.path = []
     self.closed = 0
     self.in_flex = 0
     self.flex = []
     self.cur = Point(0, 0)