robofab.features.substitute
index
/code/projects/robofab/Lib/robofab/features/substitute.py

Set of objects that process lists of glyphs and performs substitutions.
 
 
Things that need to be supported:
- group lookups in SequenceToSingle
- SingleToSequence class (ligature decomposition)
- allow contextual lookup to match and replace more than one glyph
        ((['a', 'b'], ['c', 'd'], ['e', 'f']), ['c.alt', 'd.alt'])
- support group names in place of lists. this should be optional.
   this will require that all groups should be prefixed by '@'

 
Classes
       
robofab.features.featureTools.SortedDict(__builtin__.object)
Substitute
_BaseListFeature(__builtin__.list)
ContextualSingleToSingle
SequenceToSingle
SingleToSingle
__builtin__.dict(__builtin__.object)
Random

 
class ContextualSingleToSingle(_BaseListFeature)
    Replace a of glyph with another glyph if
it is contained in a specified sequence.
 
Behavior: list
 
Substitution Structure:
[
((leading glyphs, before, trailing glyphs), after)
]
- typical structure
        (('A', 'a', 'Z'), 'a.alt')
-the leading glyphs can be a list and/or the trailing glyphs can be a list
        ((['A', 'B'], 'a', 'Z'), 'a.alt')
        (('A', 'a', ['Y', 'Z']), 'a.alt')
        ((['A', 'B'], 'a', ['Y', 'Z']), 'a.alt')
        - these lists contain another list representing a group of glyphs that can be matched
                (([['A', 'A.alt'], ['B', 'B.alt']], 'a', [['Y', 'Y.alt'], ['Z', 'Z.alt']]), 'a.alt')
- before can be a list
        (('A', ['a', 'a.alt1'], 'Z'), 'a.alt2')
- after can be a list as long as before is a list of the same length
        (('A', ['a', 'b'], 'Z'), ['a.alt', 'b.alt'])
- the front or back can be set to None indicating that anything can be in that position
        ((None, 'a', ['a', 'b']), 'a.swash')
 
Allows Sub-Lookups: No
 
 
Method resolution order:
ContextualSingleToSingle
_BaseListFeature
__builtin__.list
__builtin__.object

Methods defined here:
processString(self, glyphString)
processStringX(self, glyphString)

Methods inherited from _BaseListFeature:
__init__(self, substitution)

Data and other attributes inherited from _BaseListFeature:
__dict__ = <dictproxy object at 0x10bb3b0>
dictionary for instance variables (if defined)
__weakref__ = <attribute '__weakref__' of '_BaseListFeature' objects>
list of weak references to the object (if defined)

Methods inherited from __builtin__.list:
__add__(...)
x.__add__(y) <==> x+y
__contains__(...)
x.__contains__(y) <==> y in x
__delitem__(...)
x.__delitem__(y) <==> del x[y]
__delslice__(...)
x.__delslice__(i, j) <==> del x[i:j]
 
Use of negative indices is not supported.
__eq__(...)
x.__eq__(y) <==> x==y
__ge__(...)
x.__ge__(y) <==> x>=y
__getattribute__(...)
x.__getattribute__('name') <==> x.name
__getitem__(...)
x.__getitem__(y) <==> x[y]
__getslice__(...)
x.__getslice__(i, j) <==> x[i:j]
 
Use of negative indices is not supported.
__gt__(...)
x.__gt__(y) <==> x>y
__hash__(...)
x.__hash__() <==> hash(x)
__iadd__(...)
x.__iadd__(y) <==> x+=y
__imul__(...)
x.__imul__(y) <==> x*=y
__iter__(...)
x.__iter__() <==> iter(x)
__le__(...)
x.__le__(y) <==> x<=y
__len__(...)
x.__len__() <==> len(x)
__lt__(...)
x.__lt__(y) <==> x<y
__mul__(...)
x.__mul__(n) <==> x*n
__ne__(...)
x.__ne__(y) <==> x!=y
__repr__(...)
x.__repr__() <==> repr(x)
__rmul__(...)
x.__rmul__(n) <==> n*x
__setitem__(...)
x.__setitem__(i, y) <==> x[i]=y
__setslice__(...)
x.__setslice__(i, j, y) <==> x[i:j]=y
 
Use  of negative indices is not supported.
append(...)
L.append(object) -- append object to end
count(...)
L.count(value) -> integer -- return number of occurrences of value
extend(...)
L.extend(iterable) -- extend list by appending elements from the iterable
index(...)
L.index(value, [start, [stop]]) -> integer -- return first index of value
insert(...)
L.insert(index, object) -- insert object before index
pop(...)
L.pop([index]) -> item -- remove and return item at index (default last)
remove(...)
L.remove(value) -- remove first occurrence of value
reverse(...)
L.reverse() -- reverse *IN PLACE*
sort(...)
L.sort(cmpfunc=None) -- stable sort *IN PLACE*; cmpfunc(x, y) -> -1, 0, 1

Data and other attributes inherited from __builtin__.list:
__new__ = <built-in method __new__ of type object at 0xa866c57c>
T.__new__(S, ...) -> a new object with type S, a subtype of T

 
class Random(__builtin__.dict)
    Replace a of glyph with randomly selected
glyph from an established list of alternates.
 
Behavior: dict
 
Substitution Structure:
{
glyph name : [alternates]
}
- typical structure
        'a' : ['a.alt1', 'a.alt2']
 
Allows Sub-Lookups: No
 
 
Method resolution order:
Random
__builtin__.dict
__builtin__.object

Methods defined here:
__init__(self, substitution)
processString(self, glyphString)

Data and other attributes defined here:
__dict__ = <dictproxy object at 0x10bb090>
dictionary for instance variables (if defined)
__weakref__ = <attribute '__weakref__' of 'Random' objects>
list of weak references to the object (if defined)

Methods inherited from __builtin__.dict:
__cmp__(...)
x.__cmp__(y) <==> cmp(x,y)
__contains__(...)
x.__contains__(y) <==> y in x
__delitem__(...)
x.__delitem__(y) <==> del x[y]
__eq__(...)
x.__eq__(y) <==> x==y
__ge__(...)
x.__ge__(y) <==> x>=y
__getattribute__(...)
x.__getattribute__('name') <==> x.name
__getitem__(...)
x.__getitem__(y) <==> x[y]
__gt__(...)
x.__gt__(y) <==> x>y
__hash__(...)
x.__hash__() <==> hash(x)
__iter__(...)
x.__iter__() <==> iter(x)
__le__(...)
x.__le__(y) <==> x<=y
__len__(...)
x.__len__() <==> len(x)
__lt__(...)
x.__lt__(y) <==> x<y
__ne__(...)
x.__ne__(y) <==> x!=y
__repr__(...)
x.__repr__() <==> repr(x)
__setitem__(...)
x.__setitem__(i, y) <==> x[i]=y
clear(...)
D.clear() -> None.  Remove all items from D.
copy(...)
D.copy() -> a shallow copy of D
get(...)
D.get(k[,d]) -> D[k] if k in D, else d.  d defaults to None.
has_key(...)
D.has_key(k) -> True if D has a key k, else False
items(...)
D.items() -> list of D's (key, value) pairs, as 2-tuples
iteritems(...)
D.iteritems() -> an iterator over the (key, value) items of D
iterkeys(...)
D.iterkeys() -> an iterator over the keys of D
itervalues(...)
D.itervalues() -> an iterator over the values of D
keys(...)
D.keys() -> list of D's keys
pop(...)
D.pop(k[,d]) -> v, remove specified key and return the corresponding value
If key is not found, d is returned if given, otherwise KeyError is raised
popitem(...)
D.popitem() -> (k, v), remove and return some (key, value) pair as a
2-tuple; but raise KeyError if D is empty
setdefault(...)
D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if k not in D
update(...)
D.update(E) -> None.  Update D from E: for k in E.keys(): D[k] = E[k]
values(...)
D.values() -> list of D's values

Data and other attributes inherited from __builtin__.dict:
__new__ = <built-in method __new__ of type object at 0xa866d054>
T.__new__(S, ...) -> a new object with type S, a subtype of T
fromkeys = <built-in method fromkeys of type object at 0x1150480>
dict.fromkeys(S[,v]) -> New dict with keys from S and values equal to v.
v defaults to None.

 
class SequenceToSingle(_BaseListFeature)
    Replace a sequence of glyphs with a single glyph.
 
Behavior: list
 
Substitution Structure:
[
(before, after)
]
- typical structure
        (['a', 'b'], 'a_b')
 
Allows Sub-Lookups: Yes
 
XXX NOT YET SUPPORTED:
-before can be a list:
        ([['a', 'b'], ['a.alt', 'b.alt']], 'a_b')
- after can be a list as long as before is a list of the same length
        ([['a', 'b'], ['a.alt', 'b.alt']], ['a_b', 'a.alt_b.alt'])
 
 
Method resolution order:
SequenceToSingle
_BaseListFeature
__builtin__.list
__builtin__.object

Methods defined here:
processString(self, glyphString)

Methods inherited from _BaseListFeature:
__init__(self, substitution)

Data and other attributes inherited from _BaseListFeature:
__dict__ = <dictproxy object at 0x10bb3b0>
dictionary for instance variables (if defined)
__weakref__ = <attribute '__weakref__' of '_BaseListFeature' objects>
list of weak references to the object (if defined)

Methods inherited from __builtin__.list:
__add__(...)
x.__add__(y) <==> x+y
__contains__(...)
x.__contains__(y) <==> y in x
__delitem__(...)
x.__delitem__(y) <==> del x[y]
__delslice__(...)
x.__delslice__(i, j) <==> del x[i:j]
 
Use of negative indices is not supported.
__eq__(...)
x.__eq__(y) <==> x==y
__ge__(...)
x.__ge__(y) <==> x>=y
__getattribute__(...)
x.__getattribute__('name') <==> x.name
__getitem__(...)
x.__getitem__(y) <==> x[y]
__getslice__(...)
x.__getslice__(i, j) <==> x[i:j]
 
Use of negative indices is not supported.
__gt__(...)
x.__gt__(y) <==> x>y
__hash__(...)
x.__hash__() <==> hash(x)
__iadd__(...)
x.__iadd__(y) <==> x+=y
__imul__(...)
x.__imul__(y) <==> x*=y
__iter__(...)
x.__iter__() <==> iter(x)
__le__(...)
x.__le__(y) <==> x<=y
__len__(...)
x.__len__() <==> len(x)
__lt__(...)
x.__lt__(y) <==> x<y
__mul__(...)
x.__mul__(n) <==> x*n
__ne__(...)
x.__ne__(y) <==> x!=y
__repr__(...)
x.__repr__() <==> repr(x)
__rmul__(...)
x.__rmul__(n) <==> n*x
__setitem__(...)
x.__setitem__(i, y) <==> x[i]=y
__setslice__(...)
x.__setslice__(i, j, y) <==> x[i:j]=y
 
Use  of negative indices is not supported.
append(...)
L.append(object) -- append object to end
count(...)
L.count(value) -> integer -- return number of occurrences of value
extend(...)
L.extend(iterable) -- extend list by appending elements from the iterable
index(...)
L.index(value, [start, [stop]]) -> integer -- return first index of value
insert(...)
L.insert(index, object) -- insert object before index
pop(...)
L.pop([index]) -> item -- remove and return item at index (default last)
remove(...)
L.remove(value) -- remove first occurrence of value
reverse(...)
L.reverse() -- reverse *IN PLACE*
sort(...)
L.sort(cmpfunc=None) -- stable sort *IN PLACE*; cmpfunc(x, y) -> -1, 0, 1

Data and other attributes inherited from __builtin__.list:
__new__ = <built-in method __new__ of type object at 0xa866c57c>
T.__new__(S, ...) -> a new object with type S, a subtype of T

 
class SingleToSingle(_BaseListFeature)
    Replace a of glyph with another glyph.
 
Behavior: list
 
Substitution Structure:
[
(before, after)
]
- typical structure
        ('a', 'a.alt')
-before can be a list:
        (['a', 'a.alt1'], 'a.alt2')
- after can be a list as long as before is a list of the same length
        (['a', 'b'], ['a.alt', 'b.alt'])
        
Allows Sub-Lookups: No
 
 
Method resolution order:
SingleToSingle
_BaseListFeature
__builtin__.list
__builtin__.object

Methods defined here:
processString(self, glyphString)

Methods inherited from _BaseListFeature:
__init__(self, substitution)

Data and other attributes inherited from _BaseListFeature:
__dict__ = <dictproxy object at 0x5317d0>
dictionary for instance variables (if defined)
__weakref__ = <attribute '__weakref__' of '_BaseListFeature' objects>
list of weak references to the object (if defined)

Methods inherited from __builtin__.list:
__add__(...)
x.__add__(y) <==> x+y
__contains__(...)
x.__contains__(y) <==> y in x
__delitem__(...)
x.__delitem__(y) <==> del x[y]
__delslice__(...)
x.__delslice__(i, j) <==> del x[i:j]
 
Use of negative indices is not supported.
__eq__(...)
x.__eq__(y) <==> x==y
__ge__(...)
x.__ge__(y) <==> x>=y
__getattribute__(...)
x.__getattribute__('name') <==> x.name
__getitem__(...)
x.__getitem__(y) <==> x[y]
__getslice__(...)
x.__getslice__(i, j) <==> x[i:j]
 
Use of negative indices is not supported.
__gt__(...)
x.__gt__(y) <==> x>y
__hash__(...)
x.__hash__() <==> hash(x)
__iadd__(...)
x.__iadd__(y) <==> x+=y
__imul__(...)
x.__imul__(y) <==> x*=y
__iter__(...)
x.__iter__() <==> iter(x)
__le__(...)
x.__le__(y) <==> x<=y
__len__(...)
x.__len__() <==> len(x)
__lt__(...)
x.__lt__(y) <==> x<y
__mul__(...)
x.__mul__(n) <==> x*n
__ne__(...)
x.__ne__(y) <==> x!=y
__repr__(...)
x.__repr__() <==> repr(x)
__rmul__(...)
x.__rmul__(n) <==> n*x
__setitem__(...)
x.__setitem__(i, y) <==> x[i]=y
__setslice__(...)
x.__setslice__(i, j, y) <==> x[i:j]=y
 
Use  of negative indices is not supported.
append(...)
L.append(object) -- append object to end
count(...)
L.count(value) -> integer -- return number of occurrences of value
extend(...)
L.extend(iterable) -- extend list by appending elements from the iterable
index(...)
L.index(value, [start, [stop]]) -> integer -- return first index of value
insert(...)
L.insert(index, object) -- insert object before index
pop(...)
L.pop([index]) -> item -- remove and return item at index (default last)
remove(...)
L.remove(value) -- remove first occurrence of value
reverse(...)
L.reverse() -- reverse *IN PLACE*
sort(...)
L.sort(cmpfunc=None) -- stable sort *IN PLACE*; cmpfunc(x, y) -> -1, 0, 1

Data and other attributes inherited from __builtin__.list:
__new__ = <built-in method __new__ of type object at 0xa866c57c>
T.__new__(S, ...) -> a new object with type S, a subtype of T

 
class Substitute(robofab.features.featureTools.SortedDict)
    The main substitution object.
 
-All features should be registered by passing
a feature name and a substitution structure
to the registerFeature method.
 
-Glyph lists are prcessed with the processGlyphList
method. This will send back a list of glyphs that have
been processed according to the available features.
 
-To turn a feature on or off, call it as you would a dict
and set the "on" attribute.
 
need to support:
order(): return and ordered list of all features that are on
setOrder(list): set the firing order
 
 
Method resolution order:
Substitute
robofab.features.featureTools.SortedDict
__builtin__.object

Methods defined here:
processGlyphList(self, glyphList)
registerFeature(self, name, typeOfFeature, substitution)

Methods inherited from robofab.features.featureTools.SortedDict:
__getitem__(self, key)
__init__(self)
__len__(self)
__setitem__(self, key, value)
clear(self)
copy(self)
get(self, key, default=None)
has_key(self, key)
items(self)
keys(self)
update(self, other)
values(self)

Data and other attributes inherited from robofab.features.featureTools.SortedDict:
__dict__ = <dictproxy object at 0x531890>
dictionary for instance variables (if defined)
__weakref__ = <attribute '__weakref__' of 'SortedDict' objects>
list of weak references to the object (if defined)

 
Functions
       
breakGlyphString(glyphString)
take a / delimited list with and turn
it into a list of glyph names
'/a/b/c/' -> ['a', 'b', 'c']
makeGlyphString(glyphList)
take a list of glyph names and turn them into
a / delimited list with a preceding and following /
['a', 'b', 'c'] -> '/a/b/c/'

 
Data
        CNTX_SING_2_SING = 'contextual_single_to_single'
RAND = 'random'
SAFE_NONE = <robofab.features.featureTools.SafeNone object at 0x52a810>
SEP_MARK = '/'
SEQ_2_SING = 'sequence_to_single'
SING_2_SING = 'single_to_single'