| 786 | | localAnchors = {} |
|---|
| 787 | | foundAnchor = None |
|---|
| 788 | | accX = accent.getAnchors() |
|---|
| 789 | | #temporarily store the anchors found in the accent |
|---|
| 790 | | for anchor in accX: |
|---|
| 791 | | localAnchors[anchor.name] = anchor.position |
|---|
| 792 | | #look through the list of possible accent positions |
|---|
| 793 | | for anchorName in accentAnchors: |
|---|
| 794 | | #if we have an anchor in the accent that matches something in the list |
|---|
| 795 | | if anchorName in localAnchors: |
|---|
| 796 | | #if this anchor name matches an anchor position that the user has requested, we have a winner |
|---|
| 797 | | if ''.join(['_', accentPosition]) == anchorName: |
|---|
| 798 | | foundAnchor = anchorName |
|---|
| 799 | | break |
|---|
| 800 | | if foundAnchor: |
|---|
| 801 | | #grab the coordinates of the found anchor |
|---|
| 802 | | accentAnchorX, accentAnchorY = localAnchors[foundAnchor] |
|---|
| 803 | | #get the coordinates for the cooresponding anchor in the baseGlyph |
|---|
| 804 | | try: |
|---|
| 805 | | baseX, baseY = anchors[foundAnchor[1:]] |
|---|
| 806 | | except KeyError: |
|---|
| 807 | | errors["anchor '%s' not found in glyph '%s' of font %s"%(foundAnchor[1:], baseName, self.info.postscriptFullName)]=1 |
|---|
| 808 | | continue |
|---|
| 809 | | #calculate the accent componet offset values |
|---|
| 810 | | xShift = baseX - accentAnchorX |
|---|
| 811 | | yShift = baseY - accentAnchorY |
|---|
| 812 | | #add the accent to the destination glyph |
|---|
| 813 | | if not preflight: |
|---|
| 814 | | destGlyph.appendComponent(accentName, offset=(xShift, yShift)) |
|---|
| 815 | | #if the found anchor the anchor that it was just aligned to, make the values for that anchor the new standard |
|---|
| 816 | | if foundAnchor[1:] in localAnchors: |
|---|
| 817 | | newX, newY = localAnchors[foundAnchor[1:]] |
|---|
| 818 | | newX = newX+xShift |
|---|
| 819 | | newY = newY+yShift |
|---|
| 820 | | anchors[foundAnchor[1:]] = (newX, newY) |
|---|
| 821 | | #adjust the width if the user has requested it |
|---|
| 822 | | if adjustWidth and not preflight: |
|---|
| 823 | | for accentName, accentPosition in accentNames: |
|---|
| 824 | | #accent might not be present in the font -- the user has been warned already |
|---|
| 825 | | try: |
|---|
| 826 | | accent = self[accentName] |
|---|
| 827 | | except IndexError: |
|---|
| 828 | | continue |
|---|
| 829 | | if accent is None: continue |
|---|
| 830 | | #not sure what this does... |
|---|
| 831 | | #if accentPosition == 'right' or accentPosition == '_left': |
|---|
| 832 | | # for component in destGlyph.getComponents(): |
|---|
| 833 | | # if component.baseName == accentName: |
|---|
| 834 | | |
|---|
| 835 | | #set the right and left margins only if the accent has been added to the right or left |
|---|
| 836 | | if accentPosition == 'right': |
|---|
| 837 | | destGlyph.rightMargin = self[accentName].rightMargin |
|---|
| 838 | | elif accentPosition == 'left': |
|---|
| 839 | | destGlyph.leftMargin = self[accentName].leftMargin |
|---|
| 840 | | if preflight: |
|---|
| 841 | | return errors.keys() |
|---|
| 842 | | if printErrors: |
|---|
| 843 | | for px in errors.keys(): |
|---|
| 844 | | print px |
|---|
| | 775 | shift = None |
|---|
| | 776 | for accentAnchor in accent.getAnchors(): |
|---|
| | 777 | if '_'+anchorName == accentAnchor.name: |
|---|
| | 778 | shift = anchors[anchorName][0] - accentAnchor.position[0], anchors[anchorName][1] - accentAnchor.position[1] |
|---|
| | 779 | destGlyph.appendComponent(accentName, offset=shift) |
|---|
| | 780 | break |
|---|
| | 781 | if shift is not None: |
|---|
| | 782 | for accentAnchor in accent.getAnchors(): |
|---|
| | 783 | if accentAnchor.name in anchors: |
|---|
| | 784 | anchors[accentAnchor.name] = shift[0]+accentAnchor.position[0], shift[1]+accentAnchor.position[1] |
|---|
| | 785 | if printErrors: |
|---|
| | 786 | for px in errors.keys(): |
|---|
| | 787 | print px |
|---|