示例#1
0
def read_metric(ps_name):
    for afm in ps_to_filename[ps_name]:
        afm = afm + '.afm'
        filename = find_in_path(config.font_path, afm)
        if filename:
            if __debug__:
                import time
                start = time.clock()
            metric = read_afm_file(filename)
            if __debug__:
                pdebug('timing', 'time to read afm %s: %g', afm,
                       time.clock() - start)
            return metric
    else:
        if not _warned_about_afm.get(afm):
            warn(USER,
                 _("I cannot find the metrics for the font %(ps_name)s.\n"
                   "The file %(afm)s is not in the font_path.\n"
                   "I'll use the metrics for %(fallback)s instead."),
                 ps_name = ps_name, afm = afm,
                 fallback = config.preferences.fallback_font)
            _warned_about_afm[afm] = 1
        if ps_name != config.preferences.fallback_font:
            return read_metric(config.preferences.fallback_font)
        else:
            raise SketchError("Can't load metrics for fallback font %s",
                              config.preferences.fallback_font)
示例#2
0
文件: font.py 项目: shumik/skencil-c
def read_metric(ps_name):
    for afm in ps_to_filename[ps_name]:
	afm = afm + '.afm'
	filename = find_in_path(config.font_path, afm)
	if filename:
	    if __debug__:
		import time
		start = time.clock()
	    metric = read_afm_file(filename)
	    if __debug__:
		pdebug('timing', 'time to read afm %s: %g', afm,
		       time.clock() - start)
	    return metric
    else:
	if not _warned_about_afm.get(afm):
	    warn(USER,
                 _("I cannot find the metrics for the font %(ps_name)s.\n"
                   "The file %(afm)s is not in the font_path.\n"
                   "I'll use the metrics for %(fallback)s instead."),
		 ps_name = ps_name, afm = afm,
                 fallback = config.preferences.fallback_font)
	    _warned_about_afm[afm] = 1
        if ps_name != config.preferences.fallback_font:
            return read_metric(config.preferences.fallback_font)
        else:
            raise SketchError("Can't load metrics for fallback font %s",
                              config.preferences.fallback_font)
示例#3
0
    def ObjectRemoved(self, object):
	if object in self.stack:
	    idx = self.stack.index(object)
	    undo = (self.set_stack, self.stack[:])
	    self.stack[idx] = self.stack[idx].AsUndynamicStyle()
	    pdebug('properties', 'made style undynamic')
	    return undo
	return NullUndo
示例#4
0
    def RedrawMethod(self, region=None):
        # draw the document
        if __debug__:
            if self.time_redraw:
                import time
                start = time.clock()
        if self.move_window_count >= 2:
            self.clear_window(update=0)
        self.move_window_count = 0

        region = self.do_clear(region)

        # draw document
        self.gc.InitClip()
        self.gc.ResetFontCache()
        if region:
            self.gc.PushClip()
            self.gc.ClipRegion(region)

        tkwin = self.tkwin
        if region:
            x, y, w, h = region.ClipBox()
            if x < 0:
                w = w - x
                x = 0
            if y < 0:
                h = h - y
                y = 0
            if w > tkwin.width:
                w = tkwin.width
            if h > tkwin.height:
                h = tkwin.height
        else:
            x = y = 0
            w = tkwin.width
            h = tkwin.height
        p1 = self.WinToDoc(x - 1, y - 1)
        p2 = self.WinToDoc(x + w + 1, y + h + 1)
        rect = Rect(p1, p2)

        self.gc.SetFillColor(StandardColors.white)
        self.gc.gc.FillRectangle(x, y, w, h)  # XXX ugly to access gc.gc

        #	draw paper
        if self.show_page_outline:
            w, h = self.document.PageSize()
            self.gc.DrawPageOutline(w, h)

        self.document.Draw(self.gc, rect)
        if region:
            self.gc.PopClip()

        if __debug__:
            if self.time_redraw:
                pdebug('timing', 'redraw', time.clock() - start)

        return region
示例#5
0
    def do_reload(self):
        index = self.module_list.curselection()
        index = string.atoi(index[0])

        pdebug(None, 'reloading', self.modules[index])
        try:
            reload(self.modules[index][1])
        except:
            warn_tb(INTERNAL)
示例#6
0
    def do_reload(self):
        index = self.module_list.curselection()
        index = string.atoi(index[0])

        pdebug(None, "reloading", self.modules[index])
        try:
            reload(self.modules[index][1])
        except:
            warn_tb(INTERNAL)
示例#7
0
文件: view.py 项目: shumik/skencil-c
    def RedrawMethod(self, region = None):
	# draw the document
	if __debug__:
	    if self.time_redraw:
		import time
		start = time.clock()
	if self.move_window_count >= 2:
	    self.clear_window(update = 0)
	self.move_window_count = 0

	region = self.do_clear(region)

	# draw document
	self.gc.InitClip()
	self.gc.ResetFontCache()
	if region:
	    self.gc.PushClip()
	    self.gc.ClipRegion(region)

        tkwin = self.tkwin
	if region:
	    x, y, w, h = region.ClipBox()
            if x < 0:
                w = w - x; x = 0
            if y < 0:
                h = h - y; y = 0
            if w > tkwin.width:
                w = tkwin.width
            if h > tkwin.height:
                h = tkwin.height
	else:
	    x = y = 0
	    w = tkwin.width
	    h = tkwin.height
	p1 = self.WinToDoc(x - 1, y - 1)
	p2 = self.WinToDoc(x + w + 1, y + h + 1)
	rect = Rect(p1, p2)

        self.gc.SetFillColor(StandardColors.white)
        self.gc.gc.FillRectangle(x, y, w, h) # XXX ugly to access gc.gc

	#	draw paper
	if self.show_page_outline:
	    w, h = self.document.PageSize()
	    self.gc.DrawPageOutline(w, h)


	self.document.Draw(self.gc, rect)
	if region:
	    self.gc.PopClip()

	if __debug__:
	    if self.time_redraw:
		pdebug('timing', 'redraw', time.clock() - start)

	return region
示例#8
0
文件: font.py 项目: shumik/skencil-c
def read_outlines(ps_name):
    filename = font_file_name(ps_name)
    if filename:
	if __debug__:
	    pdebug('font', 'read_outlines: %s', filename)

	import Sketch.Lib.type1
	return Sketch.Lib.type1.read_outlines(filename)
    else:
	raise SketchInternalError('Cannot find file for font %s' % ps_name)
示例#9
0
    def drop_color(self, event):
	self['cursor'] = self.drag_old_cursor
	w = self.winfo_containing(event.x_root, event.y_root)
	while w and w != self:
	    if __debug__:
		pdebug('DND', 'trying to drop on', w)
	    try:
		accepts = w.accept_drop
	    except AttributeError:
		accepts = ()
	    if DROP_COLOR in accepts:
		x = event.x_root - w.winfo_rootx()
		y = event.y_root - w.winfo_rooty()
		w.DropAt(x, y, DROP_COLOR, self.drag_start)
		break
	    if w != w.winfo_toplevel():
		parent = self.tk.call('winfo', 'parent', w._w)
		w = self.nametowidget(parent)
	    else:
		break
示例#10
0
    def DeleteNodes(self):
	new_paths = []
	for path in self.paths:
	    if path.selection_count() > 0:
		newpath = delete_segments(path)
	    else:
		newpath = path
	    if newpath.len > 1:
		new_paths.append(newpath)
	    else:
		# all nodes of path have been deleted
		if __debug__:
		    pdebug('bezier', 'path removed')
	if new_paths:
	    return self.set_paths(new_paths)
	else:
	    if __debug__:
		pdebug('bezier', 'PolyBezier removed')
	    self.document.DeselectObject(self.object)
	    return self.parent.Remove(self.object)
示例#11
0
 def drop_color(self, event):
     self['cursor'] = self.drag_old_cursor
     w = self.winfo_containing(event.x_root, event.y_root)
     while w and w != self:
         if __debug__:
             pdebug('DND', 'trying to drop on', w)
         try:
             accepts = w.accept_drop
         except AttributeError:
             accepts = ()
         if DROP_COLOR in accepts:
             x = event.x_root - w.winfo_rootx()
             y = event.y_root - w.winfo_rooty()
             w.DropAt(x, y, DROP_COLOR, self.drag_start)
             break
         if w != w.winfo_toplevel():
             parent = self.tk.call('winfo', 'parent', w._w)
             w = self.nametowidget(parent)
         else:
             break
示例#12
0
def read_outlines(ps_name):
    filename = font_file_name(ps_name)
    if filename:
        if __debug__:
            pdebug('font', 'read_outlines: %s', filename)

        import Sketch.Lib.type1
        return Sketch.Lib.type1.read_outlines(filename)
    else:
        if not _warned_about_outlines.get(ps_name):
            warn(USER,
                 _("I cannot find the outlines for the font %(ps_name)s.\n"
                   "The file with basename(s) %(filename)s is not found in the font_path.\n"
                   "I'll use the outlines for %(fallback)s instead."),
                 ps_name = ps_name, filename = ps_to_filename[ps_name],
                 fallback = config.preferences.fallback_font)
            _warned_about_outlines[ps_name] = 1
        if ps_name != config.preferences.fallback_font:
            return read_outlines(config.preferences.fallback_font)
        else:
            raise SketchInternalError('Cannot find file for font %s' % ps_name)
示例#13
0
 def ComputeTrafo(self, oldStart, oldEnd, start, end):
     oldDelta = oldEnd - oldStart
     delta = end - start
     if self.selection == -1:
         # a translation.
         return _("Move Objects"), start - oldStart
     else:
         try:
             m11 = delta.x / oldDelta.x
         except ZeroDivisionError:
             m11 = 0
             if __debug__:
                 pdebug(None, 'ComputeTrafo: ZeroDivisionError')
         try:
             m22 = delta.y / oldDelta.y
         except ZeroDivisionError:
             m22 = 0
             if __debug__:
                 pdebug(None, 'ComputeTrafo: ZeroDivisionError')
         offx = start.x - m11 * oldStart.x
         offy = start.y - m22 * oldStart.y
         return _("Resize Objects"), Trafo(m11, 0, 0, m22, offx, offy)
示例#14
0
    def ComputeTrafo(self, oldStart, oldEnd, start, end):
	oldDelta = oldEnd - oldStart
	delta	 = end - start
	if self.selection == -1:
	    # a translation.
	    return _("Move Objects"), start - oldStart
	else:
	    try:
		m11 = delta.x / oldDelta.x
	    except ZeroDivisionError:
		m11 = 0
		if __debug__:
		    pdebug(None, 'ComputeTrafo: ZeroDivisionError')
	    try:
		m22 = delta.y / oldDelta.y
	    except ZeroDivisionError:
		m22 = 0
		if __debug__:
		    pdebug(None, 'ComputeTrafo: ZeroDivisionError')
	    offx = start.x - m11 * oldStart.x
	    offy = start.y - m22 * oldStart.y
	    return _("Resize Objects"), Trafo(m11, 0, 0, m22, offx, offy)
示例#15
0
		raise
	    else:
		raise SketchLoadError(_("error %s:%s in line %d:\n%s")
				      % (sys.exc_info()[:2] +(num, `line`)))

	self.end_all()
	if self.page_layout:
	    self.object.load_SetLayout(self.page_layout)
	for style in self.style_dict.values():
	    self.object.load_AddStyle(style)
	self.object.load_Completed()

	self.object.meta.native_format = 1

	if __debug__:
	    pdebug('timing', 'time:', time.clock() - start_time)
	return self.object


def call_function(function, args, kwargs):
    if hasattr(function, 'im_func'):
        args = (function.im_self,) + args
        function = function.im_func
    code = function.func_code
    if code.co_flags & 0x000C:
        # uses *args or **kwargs
        return 0
    args = args[:code.co_argcount]
    argnames = code.co_varnames[:code.co_argcount]
    for key in kwargs.keys():
        if key not in argnames:
示例#16
0
 def __del__(self):
     pdebug('__del__', '__del__', self)
     self.object.Destroy()
示例#17
0
            else:
                raise SketchLoadError(
                    _("error %s:%s in line %d:\n%s") % (sys.exc_info()[:2] +
                                                        (num, ` line `)))

        self.end_all()
        if self.page_layout:
            self.object.load_SetLayout(self.page_layout)
        for style in self.style_dict.values():
            self.object.load_AddStyle(style)
        self.object.load_Completed()

        self.object.meta.native_format = 1

        if __debug__:
            pdebug('timing', 'time:', time.clock() - start_time)
        return self.object


def call_function(function, args, kwargs):
    if hasattr(function, 'im_func'):
        args = (function.im_self, ) + args
        function = function.im_func
    code = function.func_code
    if code.co_flags & 0x000C:
        # uses *args or **kwargs
        return 0
    args = args[:code.co_argcount]
    argnames = code.co_varnames[:code.co_argcount]
    for key in kwargs.keys():
        if key not in argnames:
示例#18
0
文件: arrow.py 项目: shumik/skencil-c
    def __cmp__(self, other):
	if __debug__:
	    pdebug(None, 'Arrow.__cmp__, %s', other)
	if isinstance(other, self.__class__):
	    return cmp(self.path, other.path)
	return cmp(id(self), id(other))
示例#19
0
文件: font.py 项目: shumik/skencil-c
			fontlist.append(tuple(info[:-1]))
			_add_ps_filename(psname, info[-1])
			fontmap[psname] = tuple(info[1:-1])
		    elif len(info) == 2:
			psname, basename = info
			_add_ps_filename(psname, basename)
		    else:
			warn(INTERNAL,'%s:%d: line must have exactly 6 fields',
			     filename, line_nr)
		file.close()
	    except IOError, value:
		warn(USER, _("Cannot load sfd file %(filename)s:%(message)s;"
                             "ignoring it"),
		     filename = filename, message = value.strerror)
    if __debug__:
	pdebug('timing', 'time to read font dirs: %g', time.clock() - start)

def make_family_to_fonts():
    families = {}
    for item in fontlist:
	family = item[1]
	fontname = item[0]
	if families.has_key(family):
	    families[family] = families[family] + (fontname,)
	else:
	    families[family] = (fontname,)
    return families



xlfd_template = "%s--%s-*-*-*-*-*-%s"
示例#20
0
文件: skapp.py 项目: shumik/skencil-c
    def __del__(self):
	pdebug('__del__', '__del__', self)
	self.object.Destroy()
示例#21
0
    def __del__(self):
	if __debug__:
	    pdebug('__del__', '__del__', self)
示例#22
0
 def __cmp__(self, other):
     if __debug__:
         pdebug(None, 'Arrow.__cmp__, %s', other)
     if isinstance(other, self.__class__):
         return cmp(self.path, other.path)
     return cmp(id(self), id(other))
示例#23
0
    def __del__(self):
	pdebug('__del__', '__del__', self)
示例#24
0
                        fontlist.append(tuple(info[:-1]))
                        _add_ps_filename(psname, info[-1])
                        fontmap[psname] = tuple(info[1:-1])
                    elif len(info) == 2:
                        psname, basename = info
                        _add_ps_filename(psname, basename)
                    else:
                        warn(INTERNAL,'%s:%d: line must have exactly 6 fields',
                             filename, line_nr)
                file.close()
            except IOError, value:
                warn(USER, _("Cannot load sfd file %(filename)s:%(message)s;"
                             "ignoring it"),
                     filename = filename, message = value.strerror)
    if __debug__:
        pdebug('timing', 'time to read font dirs: %g', time.clock() - start)

def make_family_to_fonts():
    families = {}
    for item in fontlist:
        family = item[1]
        fontname = item[0]
        if families.has_key(family):
            families[family] = families[family] + (fontname,)
        else:
            families[family] = (fontname,)
    return families



xlfd_template = "%s--%s-*-*-*-*-*-%s"
示例#25
0
 def __del__(self):
     pdebug('__del__', '__del__', self)