示例#1
0
    def POST(self, name, glyphid):
        if not is_loggedin():
            return web.notfound()

        master = models.Master.get(fontname=name)
        if not master:
            return web.notfound()

        x = web.input(pointnr='', source='', x='', y='')

        query = models.GlyphOutline.filter(idmaster=master.idmaster,
                                           fontsource=x.source.upper(),
                                           glyphname=glyphid,
                                           pointnr=x.pointnr)
        query.update(dict(x=x.x, y=x.y))
        web.ctx.orm.commit()
        writeGlyphlist(master, glyphid)

        glyphA = models.Glyph.get(idmaster=master.idmaster,
                                  fontsource='A', name=glyphid)
        glyphB = models.Glyph.get(idmaster=master.idmaster,
                                  fontsource='A', name=glyphid)
        import xmltomf
        xmltomf.xmltomf1(master, glyphA, glyphB)
        makefont(working_dir(), master)
        M_glyphjson = get_edges_json(u'%s.log' % master.fontname, glyphid)
        if x.source.upper() == 'A':
            glyphjson = get_edges_json(u'%sA.log' % master.fontname, glyphid)
        else:
            glyphjson = get_edges_json(u'%sB.log' % master.fontname, glyphid)
        return simplejson.dumps({'M': M_glyphjson,
                                 'R': glyphjson})
示例#2
0
    def call_metapost_all_glyphs(self, master):
        writeGlobalParam(self.get_project())

        hasglyphs = False
        for glyph in master.get_glyphs():
            _glyphs = models.Glyph.filter(name=glyph.name)
            _glyphs = _glyphs.filter(models.Glyph.master_id.in_(map(lambda x: x.id, self._masters)))

            glyphs = []
            for m in self._masters:
                for g in _glyphs:
                    if g.master_id == m.id:
                        glyphs.append(g)
                        break

            if session.get('mfparser', '') == 'controlpoints':
                import xmltomf_new_2axes as xmltomf
                xmltomf.xmltomf1(self.get_lft_master(), *list(glyphs))
            else:
                import xmltomf
                xmltomf.xmltomf1(self.get_lft_master(), *list(glyphs))
            hasglyphs = True

        if hasglyphs:
            writeGlyphlist(master)
            makefont_single(self.get_lft_master())
示例#3
0
    def POST(self, name, glyphid):
        if not is_loggedin():
            raise seeother('/login')

        master = models.Master.get(fontname=name)
        if not master:
            return web.notfound()

        x = web.input(idlocal_changed=False, idglobal_changed=False,
                      ab_source='a')

        form = LocalParamForm()
        if x.idlocal_changed:
            # if dropdown value in form has been changed so just refresh
            # data in selected form
            attrs = Settings.get_local_params(x.idlocal_changed, x.ab_source)
            return simplejson.dumps(attrs)
        elif x.idglobal_changed:
            params = models.GlobalParam.get(idglobal=x.idglobal_changed)
            return simplejson.dumps(params.as_dict())

        if 'ab_source' in form.d and form.validates():
            idlocal = form.d.idlocal
            fontsource = form.d.ab_source
            models.Master.update(idmaster=master.idmaster,
                                 values={'idlocal{0}'.format(fontsource.lower()): idlocal})
            master = models.Master.get(fontname=name)

            values = form.d
            del values['ab_source']
            del values['save']
            del values['idlocal']

            models.LocalParam.update(idlocal=idlocal, values=values)

        formg = GlobalParamForm()
        if formg.validates():
            idglobal = formg.d.idglobal
            models.Master.update(idmaster=master.idmaster,
                                 values={'idglobal': idglobal})
            master = models.Master.get(fontname=name)

            values = formg.d
            del values['idglobal']
            del values['save']

            models.GlobalParam.update(idglobal=idglobal, values=values)

        writeGlyphlist(master, glyphid)
        if model.writeGlobalParam(master):
            makefont(working_dir(), master)
        raise seeother('/view/{0}/{1}/settings/'.format(master.fontname, glyphid))
示例#4
0
    def get_glyphs_jsondata(self, glyphid, master):
        self.call_metapost(glyphid)

        project = self.get_project()

        instancelog = project.get_instancelog(self.get_lft_version())
        M_glyphjson = get_edges_json(instancelog, glyphid)

        glyph = models.Glyph.get(master_id=master.id, name=glyphid)
        instancelog = project.get_instancelog(master.version, 'a')
        if session.get('mfparser', '') == 'controlpoints':
            import xmltomf_new_2axes as xmltomf
            xmltomf.xmltomf1(master, glyph)
        else:
            import xmltomf
            xmltomf.xmltomf1(master, glyph)

        writeGlyphlist(master, glyph.name)
        makefont_single(master, cell='A')

        zpoints = get_edges_json_from_db(master, glyphid)

        glyphjson = get_edges_json(instancelog, glyphid)
        return {'M': M_glyphjson, 'R': glyphjson, 'zpoints': zpoints}
示例#5
0
    def POST(self):
        if not is_loggedin():
            raise seeother('/login')

        x = web.input(zipfile={})
        if 'name' in x and models.Master.exists(fontname=x.name):
            return render.create_project(error='Project with this name already exists')

        if 'zipfile' in x and 'name' in x and x.name:
            filename = op.join(working_dir(), x.zipfile.filename)

            try:
                with open(filename, 'w') as fp:
                    fp.write(x.zipfile.file.read())
            except (IOError, OSError):
                return render.create_project(error='Could not upload this file to disk')

            prepare_environment_directory()

            try:
                fzip = zipfile.ZipFile(filename)

                namelist = fzip.namelist()

                iscorrect_ufo = False
                ufo_dirs = []
                for f in namelist:
                    if re.search(r'.ufo[\\/]$', f):
                        ufo_dirs.append(re.sub(r'[\\/]', '', f))
                    if re.search(r'.ufo[\\/]glyphs[\\/].*?.glif$', f, re.IGNORECASE):
                        iscorrect_ufo = True

                if not iscorrect_ufo:
                    return render.create_project(error='Archive does not contain any correct UFO folder')

                FontNameA = ufo_dirs[0]
                try:
                    FontNameB = ufo_dirs[1]
                except IndexError:
                    FontNameB = ''
                master = models.Master.create(fontname=x.name)

                fontpath = master.get_fonts_directory()
                fzip.extractall(fontpath)

                shutil.move(op.join(fontpath, FontNameA),
                            op.join(fontpath, '%sA.UFO' % x.name))
                if FontNameB:
                    shutil.move(op.join(fontpath, FontNameB),
                                op.join(fontpath, '%sB.UFO' % x.name))
                    FontNameB = '%sB.UFO' % x.name

                models.Master.update(idmaster=master.idmaster,
                                     values=dict(fontnamea='%sA.UFO' % x.name,
                                                 fontnameb=FontNameB))

                FontNameA = '%sA.UFO' % x.name
                if not FontNameB:
                    FontNameB = '%sB.UFO' % x.name
                for f in os.listdir(working_dir('commons', user='******')):
                    filename = working_dir(op.join('commons', f),
                                           user='******')
                    try:
                        if filename.endswith('font.mf'):
                            shutil.copy2(filename, op.join(fontpath, mf_filename(FontNameA)))
                            shutil.copy2(filename, op.join(fontpath, mf_filename(FontNameB)))
                            shutil.copy2(filename, op.join(fontpath, mf_filename(x.name)))
                        else:
                            shutil.copy2(filename, fontpath)
                    except (IOError, OSError):
                        raise

                putFontAllglyphs(master)
                writeGlyphlist(master)
                makefont(working_dir(), master)
            except (zipfile.BadZipfile, OSError, IOError):
                if master:
                    models.Master.delete(idmaster=master.idmaster)
                    models.GlyphOutline.delete(idmaster=master.idmaster)
                    models.GlyphParam.delete(idmaster=master.idmaster)

                    fontpath = master.get_fonts_directory()
                    shutil.rmtree(fontpath)
            return seeother('/fonts/')

        return render.create_project(error='Please fill all fields in form')