Esempio n. 1
0
    def attribModel(self) :
        
        attrList = []
        
        defaultFloc = self._fileLoc("gid")
        attrList.append(Attribute('glyph number', self.__getattribute__, None, False, defaultFloc, False, 'gid')) # read-only
        attrList.append(Attribute('GDL name', self.GDLName, None, fileLoc=defaultFloc))  ## self.setGDL
        attrList.append(Attribute('Postscript', self.__getattribute__, None, False, defaultFloc, False, 'psname')) #read-only
        #attrList.append(Attribute('USV', self.__getattribute__, self.__setattr__, False, False, 'uid'))
        attrList.append(Attribute('USV', self.__getattribute__, None, False, defaultFloc, False, 'uid'))
        attrList.append(Attribute('comment', self.__getattribute__, None, False, None, False, 'comment')) ## self.__setattr__, False, 'comment'))

        for a in sorted(self.properties.keys()) :
            # classes
            attrList.append(Attribute(a, self.getProperty, None, False, self._fileLoc(a), True, a))  ## self.setPropertyX
            
        for a in sorted(self.gdlProperties.keys()) :
            # breakweight, dir, mirror, etc.
            if a == "*actualForPseudo*" :
                actual = self.getGdlProperty("*actualForPseudo*")
                if actual != 0 :
                    attrList.append(Attribute(a, self.getGdlProperty, None, False, self._fileLoc(a), False, a)) ## self.setGdlProperty
            elif a == "*skipPasses*" :
                attrList.append(Attribute(a, self.getGdlPropertyWithBinary, None, False, None, False, a))
            else :
                attrList.append(Attribute(a, self.getGdlProperty, None, False, self._fileLoc(a), False, a))  ## self.setGdlProperty
                
        topModel = AttribModel(attrList) # top-level structure
        
        # points
        ptAttrList = []
        ptModel = AttribModel(ptAttrList, topModel) # sub-tree for points
        for k in sorted(self.anchors.keys()) :
            ptAttrList.append(Attribute(k, self.getPoint, None, False, self._fileLoc(k), False, k))  ## self.setPoint
        topModel.add(Attribute('points', None, None, True, None, False, ptModel))
        
        # user-defined
        #try : self.userProperties
        #except : self.userProperties = {}
        if len(self.userProperties) :
            userAttrList = []
            userModel = AttribModel(userAttrList, topModel) # sub-tree for user-defined attrs
            for k in sorted(self.userProperties.keys()) :
                userAttrList.append(Attribute(k, self.getUserProperty, None, False, self._fileLoc(k), False, k))
            topModel.add(Attribute('user-defined', None, None, True, None, False, userModel))
        
        # justification - TODO clean up line-and-file stuff for multiple levels
        if len(self.justifies) :
            jModel = AttribModel([], topModel)  # sub-tree for justify attrs
            for (iLevel, j) in enumerate(self.justifies) :
                jlAttrs = [] # list of justify attrs at this level
                lModel = AttribModel(jlAttrs, jModel)  # sub-tree for this level
                for k in j.keys() :
                    fullName = "justify." + string(iLevel) + "." + k
                    jlAttrs.append(Attribute(k, self.getJustify, None, False,
                            self._fileLoc(fullName), iLevel, k))
                jModel.add(Attribute(str(iLevel), None, None, True, None, False, lModel))
            topModel.add(Attribute('justify', None, None, True, None, False, jModel))
        
        # collision
        colAttrList = []
        if (len(self.collisionProps)) :
            colModel = AttribModel(colAttrList, topModel) # sub-tree for collision
            for k in self.sortedCollKeys(self.collisionProps.keys()) :
                colAttrList.append(Attribute(k, self.getCollisionAnnot, None, False, self._fileLoc("collision."+k), False, k))
            topModel.add(Attribute('collision', None, None, True, None, False, colModel))
            
        #sequence
        seqAttrList = []
        if (len(self.sequenceProps)) :
            seqModel = AttribModel(seqAttrList, topModel) #sub-tree for sequence
            for k in self.sortedSeqKeys(self.sequenceProps.keys()) :
                seqAttrList.append(Attribute(k, self.getSequence, None, False, self._fileLoc("sequence."+k), False, k))
            topModel.add(Attribute('sequence', None, None, True, None, False, seqModel)) 
            
        # octaboxes
        octaAttrList = []
        if (len(self.octaboxProps)) :
            octaModel = AttribModel(octaAttrList, topModel) # sub-tree for octaboxes
            for k in sorted(self.octaboxProps.keys()) :
                octaAttrList.append(Attribute(k, self.getOctabox, None, False, None, False, k))
            topModel.add(Attribute('octabox', None, None, True, None, False, octaModel))
        
        return topModel
Esempio n. 2
0
    def attribModel(self) :
        
        attrList = []
        
        defaultFloc = self._fileLoc("gid")
        attrList.append(Attribute('glyph number', self.__getattribute__, None, False, defaultFloc, 'gid')) # read-only
        attrList.append(Attribute('GDL name', self.GDLName, None, fileLoc=defaultFloc))  ## self.setGDL
        attrList.append(Attribute('Postscript', self.__getattribute__, None, False, defaultFloc, 'psname')) #read-only
        #attrList.append(Attribute('USV', self.__getattribute__, self.__setattr__, False, 'uid'))
        attrList.append(Attribute('USV', self.__getattribute__, None, False, defaultFloc, 'uid'))
        attrList.append(Attribute('comment', self.__getattribute__, None, False, None, 'comment')) ## self.__setattr__, False, 'comment'))

        for a in sorted(self.properties.keys()) :
            # classes
            attrList.append(Attribute(a, self.getProperty, None, False, self._fileLoc(a), a))  ## self.setPropertyX
            
        for a in sorted(self.gdlProperties.keys()) :
            # breakweight, dir, mirror, etc.
            if a == "*actualForPseudo*" :
                actual = self.getGdlProperty("*actualForPseudo*")
                if actual != 0 :
                    attrList.append(Attribute(a, self.getGdlProperty, None, False, self._fileLoc(a), a)) ## self.setGdlProperty
            elif a == "*skipPasses*" :
                attrList.append(Attribute(a, self.getGdlPropertyWithBinary, None, False, None, a))
            else :
                attrList.append(Attribute(a, self.getGdlProperty, None, False, self._fileLoc(a), a))  ## self.setGdlProperty
                
        topModel = AttribModel(attrList) # top-level structure
        
        # points
        ptAttrList = []
        ptModel = AttribModel(ptAttrList, topModel) # sub-tree for points
        for k in sorted(self.anchors.keys()) :
            ptAttrList.append(Attribute(k, self.getPoint, None, False, self._fileLoc(k), k))  ## self.setPoint
        topModel.add(Attribute('points', None, None, True, None, ptModel))
        
        # user-defined
        #try : self.userProperties
        #except : self.userProperties = {}
        if len(self.userProperties) :
            userAttrList = []
            userModel = AttribModel(userAttrList, topModel) # sub-tree for user-defined attrs
            for k in sorted(self.userProperties.keys()) :
                userAttrList.append(Attribute(k, self.getUserProperty, None, False, self._fileLoc(k), k))
            topModel.add(Attribute('user-defined', None, None, True, None, userModel))
        
        # justification - TODO clean up line-and-file stuff for multiple levels
        if len(self.justifies) :
            jModel = AttribModel([], topModel)  # sub-tree for justify attrs
            for (iLevel, j) in enumerate(self.justifies) :
                jlAttrs = [] # list of justify attrs at this level
                lModel = AttribModel(jlAttrs, jModel)  # sub-tree for this level
                for k in j.keys() :
                    fullName = "justify." + string(iLevel) + "." + k
                    jlAttrs.append(Attribute(k, self.getJustify, None, False,
                            self._fileLoc(fullName), iLevel, k))
                jModel.add(Attribute(str(iLevel), None, None, True, None, lModel))
            topModel.add(Attribute('justify', None, None, True, None, jModel))
        
        # collision
        colAttrList = []
        if (len(self.collisionProps)) :
            colModel = AttribModel(colAttrList, topModel) # sub-tree for collision
            for k in self.sortedCollKeys(self.collisionProps.keys()) :
                colAttrList.append(Attribute(k, self.getCollisionAnnot, None, False, self._fileLoc("collision."+k), k))
            topModel.add(Attribute('collision', None, None, True, None, colModel))
            
        #sequence
        seqAttrList = []
        if (len(self.sequenceProps)) :
            seqModel = AttribModel(seqAttrList, topModel) #sub-tree for sequence
            for k in self.sortedSeqKeys(self.sequenceProps.keys()) :
                seqAttrList.append(Attribute(k, self.getSequence, None, False, self._fileLoc("sequence."+k), k))
            topModel.add(Attribute('sequence', None, None, True, None, seqModel)) 
            
        # octaboxes
        octaAttrList = []
        if (len(self.octaboxProps)) :
            octaModel = AttribModel(octaAttrList, topModel) # sub-tree for octaboxes
            for k in sorted(self.octaboxProps.keys()) :
                octaAttrList.append(Attribute(k, self.getOctabox, None, False, None, k))
            topModel.add(Attribute('octabox', None, None, True, None, octaModel))
        
        return topModel
Esempio n. 3
0
    def attribModel(self):
        res = []
        for pair in (('index', 'index'), ('glyph number', 'gid'),
                     ('slot ID', 'id'), ('breakweight', 'break'),
                     ('insert', 'insert'), ('justification', 'justification')):
            label, attr = pair
            if hasattr(self, attr):
                res.append(
                    Attribute(label, self.__getattribute__, None, False, None,
                              False, attr))
        for k in ('origin', 'advance', 'shift'):
            if hasattr(self, k):
                res.append(
                    Attribute(k, self.getPos, None, False, None, False, k))
        for k in ('before', 'after'):
            res.append(
                Attribute(k, self.getCharInfo, None, False, None, False, k))

        crem = {}
        if hasattr(self, 'collision'):
            cres = []
            cres.append(Attribute('flags', self.getColFlagsAnnot, None, False))
            cres.append(
                Attribute('status', self.getColStatusAnnot, None, False))
            ##cres.append(Attribute('margin', self.getColMargin, None, False))
            ##cres.append(Attribute('marginmin', self.getColMarginMin, None, False))
            cres.append(
                Attribute('margin', self.getColMarginAttrs, None, False))
            cres.append(Attribute('min', self.getColLimitMin, None, False))
            cres.append(Attribute('max', self.getColLimitMax, None, False))
            cres.append(Attribute('offset', self.getColOffset, None, False))
            flagOverlap = 256
            #if self.getColFlags() & flagOverlap :
            #    cres.append(Attribute('maxoverlap', self.getColMaxOverlap, None, False))
            #else :
            #    cres.append(Attribute('maxoverlap', self.getColMaxOverlapInvalid, None, False))
            ##cres.append(Attribute('order', self.getColOrderAttrs, None, False))
            cres.append(Attribute('exclude', self.getColExclAttrs, None,
                                  False))
            if self.colPending:
                cres.append(
                    Attribute('pending', self.getColPending, None, False))
            #if self.colKernPending :
            #    cres.append(Attribute('', self.getColKernPending, None, False))

            for rk in 'xysd':
                if len(self.getColRemoves()[rk]):
                    trem = []
                    for v in self.getColRemoves()[rk]:
                        if v[2] == "exclude":  # exclude is not a good label for this
                            label = "weighted"
                        elif v[2] == "remove":
                            label = "absolute"
                        else:
                            label = v[2]
                        trem.append(
                            Attribute(label + '(' + str(v[1]) + ')', getVal,
                                      None, False, None, False, v[3]))
                    crem[rk] = trem

        if hasattr(self, 'collision') and self.hasSequenceAttrs():
            sres = []
            sres.append(Attribute('class', self.getSeqClassAttrs, None, False))
            sres.append(Attribute('order', self.getSeqOrderAttr, None, False))
            sres.append(Attribute('above', self.getSeqAboveAttrs, None, False))
            sres.append(Attribute('below', self.getSeqBelowAttrs, None, False))
            sres.append(
                Attribute('valign', self.getSeqValignAttrs, None, False))
        else:
            sres = None

        if hasattr(self, 'parent'):
            res.append(
                Attribute('parent slot', self.getParent, None, False, None,
                          False, 'parent'))
            res.append(Attribute('parent offset', self.getOffset, None, False))

        resAttrib = AttribModel(res)

        if hasattr(self, 'collision'):
            cAttrib = AttribModel(cres, resAttrib)
            resAttrib.add(
                Attribute('collision', None, None, True, None, False, cAttrib))
            if len(crem):
                cremAttrib = AttribModel([], cAttrib)
                cAttrib.add(
                    Attribute('removals', None, None, True, None, False,
                              cremAttrib))
                for k in 'xysd':
                    if k not in crem: continue
                    v = crem[k]
                    tmodel = AttribModel(v, cremAttrib)
                    cremAttrib.add(
                        Attribute(k, None, None, True, None, False, tmodel))
            r = self.getColResults()
            if len(r):
                crAttribModel = AttribModel([], cAttrib)
                cAttrib.add(
                    Attribute('results', None, None, True, None, False,
                              crAttribModel))
                for k in 'xysd':
                    if k not in r: continue
                    v = r[k]
                    lModel = AttribModel([], crAttribModel)
                    crAttribModel.add(
                        Attribute(k, None, None, True, None, False, lModel))
                    lModel.add(
                        Attribute(
                            'totalRange', getVal, None, False, None, False,
                            "[%d, %d]" % (v.ranges[0][0], v.ranges[0][1])))
                    lModel.add(
                        Attribute('legalRanges', getVal, None, False, None,
                                  False, v.ranges[1:]))
                    lModel.add(
                        Attribute('bestVal', getVal, None, False, None, False,
                                  v.val))
                    lModel.add(
                        Attribute('bestCost', getVal, None, False, None, False,
                                  v.cost))

        if sres:
            sAttrib = AttribModel(sres, resAttrib)
            resAttrib.add(
                Attribute('sequence', None, None, True, None, False, sAttrib))

        ures = []
        for i in range(len(self.user)):
            ures.append(
                Attribute(str(i + 1), self.getUser, None, False, None, False,
                          i))

        uAttrib = AttribModel(ures, resAttrib)
        resAttrib.add(
            Attribute('user attributes', None, None, True, None, False,
                      uAttrib))
        return resAttrib
Esempio n. 4
0
    def attribModel(self) :
        res = []
        for pair in (('index', 'index'), ('glyph number','gid'), ('slot ID', 'id'), 
                ('breakweight', 'break'), ('insert', 'insert'), ('justification', 'justification')) :
            label,attr = pair
            if hasattr(self, attr) :
                res.append(Attribute(label, self.__getattribute__, None, False, None, attr))
        for k in ('origin', 'advance', 'shift') :
            if hasattr(self, k) :
                res.append(Attribute(k, self.getPos, None, False, None, k))
        for k in ('before', 'after') :
            res.append(Attribute(k, self.getCharInfo, None, False, None, k))
            
        crem = {}
        if hasattr(self, 'collision') :
            cres = []
            cres.append(Attribute('flags', self.getColFlagsAnnot, None, False))
            cres.append(Attribute('status', self.getColStatusAnnot, None, False))
            ##cres.append(Attribute('margin', self.getColMargin, None, False))
            ##cres.append(Attribute('marginmin', self.getColMarginMin, None, False))
            cres.append(Attribute('margin', self.getColMarginAttrs, None, False))
            cres.append(Attribute('min', self.getColLimitMin, None, False))
            cres.append(Attribute('max', self.getColLimitMax, None, False))
            cres.append(Attribute('offset', self.getColOffset, None, False))
            flagOverlap = 256
            #if self.getColFlags() & flagOverlap :
            #    cres.append(Attribute('maxoverlap', self.getColMaxOverlap, None, False))
            #else :
            #    cres.append(Attribute('maxoverlap', self.getColMaxOverlapInvalid, None, False))
            ##cres.append(Attribute('order', self.getColOrderAttrs, None, False))
            cres.append(Attribute('exclude', self.getColExclAttrs, None, False))
            if self.colPending :
                cres.append(Attribute('pending', self.getColPending, None, False))
            #if self.colKernPending :
            #    cres.append(Attribute('', self.getColKernPending, None, False))
            
            for rk in 'xysd' :
                if len(self.getColRemoves()[rk]) :
                    trem = []
                    for v in self.getColRemoves()[rk] :
                        if v[2] == "exclude" : # exclude is not a good label for this
                            label = "weighted"
                        elif v[2] == "remove" :
                            label = "absolute"
                        else :
                            label = v[2]
                        trem.append(Attribute(label+'('+str(v[1])+')', getVal, None, False, None, v[3]))
                    crem[rk] = trem

        if hasattr(self, 'collision') and self.hasSequenceAttrs() :
            sres = []
            sres.append(Attribute('class', self.getSeqClassAttrs, None, False))
            sres.append(Attribute('order', self.getSeqOrderAttr, None, False))
            sres.append(Attribute('above', self.getSeqAboveAttrs, None, False))
            sres.append(Attribute('below', self.getSeqBelowAttrs, None, False))
            sres.append(Attribute('valign', self.getSeqValignAttrs, None, False))
        else :
            sres = None
            
        if hasattr(self, 'parent') :
            res.append(Attribute('parent slot', self.getParent, None, False, None, 'parent'))
            res.append(Attribute('parent offset', self.getOffset, None, False))
            
        resAttrib = AttribModel(res)

        if hasattr(self, 'collision') :
            cAttrib = AttribModel(cres, resAttrib)
            resAttrib.add(Attribute('collision', None, None, True, None, cAttrib))
            if len(crem) :
                cremAttrib = AttribModel([], cAttrib)
                cAttrib.add(Attribute('removals', None, None, True, None, cremAttrib))
                for k in 'xysd' :
                    if k not in crem : continue
                    v = crem[k]
                    tmodel = AttribModel(v, cremAttrib)
                    cremAttrib.add(Attribute(k, None, None, True, None, tmodel))
            r = self.getColResults()
            if len(r) :
                crAttribModel = AttribModel([], cAttrib)
                cAttrib.add(Attribute('results', None, None, True, None, crAttribModel))
                for k in 'xysd' :
                    if k not in r : continue
                    v = r[k]
                    lModel = AttribModel([], crAttribModel)
                    crAttribModel.add(Attribute(k, None, None, True, None, lModel))
                    lModel.add(Attribute('totalRange', getVal, None, False, None, "[%d, %d]" % (v.ranges[0][0], v.ranges[0][1])))
                    lModel.add(Attribute('legalRanges', getVal, None, False, None, v.ranges[1:]))
                    lModel.add(Attribute('bestVal', getVal, None, False, None, v.val))
                    lModel.add(Attribute('bestCost', getVal, None, False, None, v.cost))
            
        if sres :
            sAttrib = AttribModel(sres, resAttrib)
            resAttrib.add(Attribute('sequence', None, None, True, None, sAttrib))

        ures = []
        for i in range(len(self.user)) :
            ures.append(Attribute(str(i+1), self.getUser, None, False, None, i))
            
        uAttrib = AttribModel(ures, resAttrib)
        resAttrib.add(Attribute('user attributes', None, None, True, None, uAttrib))
        return resAttrib