def __next__(self):
        "Get the next text segment. Return an 8-element array: (FONTNAME, SIZE, LINEHEIGHT, COLOR, H_ALIGN, V_ALIGN, ANGLE, STR."
        l = []
        changed = 0
        self.old_state = self.ts.copy()

        while self.i < len(self.str):
            if self.str[self.i] == '/':
                self.i = self.i + 1
                ch = self.str[self.i]
                self.i = self.i + 1
                self.old_state = self.ts.copy()
                if ch == '/' or ch == '{' or ch == '}':
                    l.append(ch)
                elif ch in _font_family_map:
                    self.ts.family = _font_family_map[ch]
                    changed = 1
                elif ch == 'F':
                    # /F{font-family}
                    if self.str[self.i] != '{':
                        raise FontException('"{" must follow /F', self.str)
                    self.i += 1
                    istart = self.i
                    while self.str[self.i] != '}':
                        self.i += 1
                        if self.i >= len(self.str):
                            raise FontException('Expecting "/F{...}"', self.str)
                    self.ts.family = self.str[istart:self.i]
                    self.i += 1
                    changed = 1

                elif ch in string.digits:
                    self.i -= 1
                    self.ts.size = self.__parse_int()
                    self.ts.line_height = self.ts.size
                    changed = 1
                elif ch == 'l':
                    self.ts.line_height = self.__parse_int()
                    changed = 1
                elif ch == 'b':
                    self.ts.modifiers.append('b')
                    changed = 1
                elif ch == 'i':
                    self.ts.modifiers.append('i')
                    changed = 1
                elif ch == 'o':
                    self.ts.modifiers.append('q')
                    changed = 1
                elif ch == 'c':
                    self.ts.color = color.gray_scale(self.__parse_float())
                elif ch == 'v':
                    if self.str[self.i] not in 'BTM':
                        raise FontException('Undefined escape sequence "/v%c"' %
                                            self.str[self.i], self.str)
                    self.ts.valign = self.str[self.i]
                    self.i += 1
                    changed = 1
                elif ch == 'h':
                    if self.str[self.i] not in 'LRC':
                        raise FontException('Undefined escape sequence "/h%c"' %
                                            self.str[self.i], self.str)
                    self.ts.halign = self.str[self.i]
                    self.i += 1
                    changed = 1
                elif ch == 'a':
                    self.ts.angle = self.__parse_int()
                    changed = 1
                else:
                    raise FontException('Undefined escape sequence: "/%c"' % ch,
                                        self.str)
            elif self.str[self.i] == '{':
                self.stack.append(self.ts.copy())
                self.i += 1
            elif self.str[self.i] == '}':
                if len(self.stack) == 0:
                    raise FontError('Unmatched "}"', self.str)
                self.ts = self.stack[-1]
                del self.stack[-1]
                self.i += 1
                changed = 1
            else:
                l.append(self.str[self.i])
                self.i += 1

            if changed and len(l) > 0:
                return self.__return_state(self.old_state, ''.join(l))
            else:
                # font change in the beginning of the sequence doesn't count.
                self.old_state = self.ts.copy()
                changed = 0
        if len(l) > 0:
            return self.__return_state(self.old_state, ''.join(l))
        else:
            return None
def __next__ ( self ) : l = [ ] changed = 0 self . old_state = self . ts . copy ( ) while self . i < len ( self . str ) : if self . str [ self . i ] == '/' : self . i = self . i + 1 ch = self . str [ self . i ] self . i = self . i + 1 self . old_state = self . ts . copy ( ) if ch == '/' or ch == '{' or ch == '}' : l . append ( ch ) elif ch in _font_family_map : self . ts . family = _font_family_map [ ch ] changed = 1 elif ch == 'F' : if self . str [ self . i ] != '{' : raise FontException ( '"{" must follow /F' , self . str ) self . i += 1 istart = self . i while self . str [ self . i ] != '}' : self . i += 1 if self . i >= len ( self . str ) : raise FontException ( 'Expecting "/F{...}"' , self . str ) self . ts . family = self . str [ istart : self . i ] self . i += 1 changed = 1 elif ch in string . digits : self . i -= 1 self . ts . size = self . __parse_int ( ) self . ts . line_height = self . ts . size changed = 1 elif ch == 'l' : self . ts . line_height = self . __parse_int ( ) changed = 1 elif ch == 'b' : self . ts . modifiers . append ( 'b' ) changed = 1 elif ch == 'i' : self . ts . modifiers . append ( 'i' ) changed = 1 elif ch == 'o' : self . ts . modifiers . append ( 'q' ) changed = 1 elif ch == 'c' : self . ts . color = color . gray_scale ( self . __parse_float ( ) ) elif ch == 'v' : if self . str [ self . i ] not in 'BTM' : raise FontException ( 'Undefined escape sequence "/v%c"' % self . str [ self . i ] , self . str ) self . ts . valign = self . str [ self . i ] self . i += 1 changed = 1 elif ch == 'h' : if self . str [ self . i ] not in 'LRC' : raise FontException ( 'Undefined escape sequence "/h%c"' % self . str [ self . i ] , self . str ) self . ts . halign = self . str [ self . i ] self . i += 1 changed = 1 elif ch == 'a' : self . ts . angle = self . __parse_int ( ) changed = 1 else : raise FontException ( 'Undefined escape sequence: "/%c"' % ch , self . str ) elif self . str [ self . i ] == '{' : self . stack . append ( self . ts . copy ( ) ) self . i += 1 elif self . str [ self . i ] == '}' : if len ( self . stack ) == 0 : raise FontError ( 'Unmatched "}"' , self . str ) self . ts = self . stack [ - 1 ] del self . stack [ - 1 ] self . i += 1 changed = 1 else : l . append ( self . str [ self . i ] ) self . i += 1 if changed and len ( l ) > 0 : return self . __return_state ( self . old_state , '' . join ( l ) ) else : self . old_state = self . ts . copy ( ) changed = 0 if len ( l ) > 0 : return self . __return_state ( self . old_state , '' . join ( l ) ) else : return None
Get the next text segment. Return an 8-element array: (FONTNAME, SIZE, LINEHEIGHT, COLOR, H_ALIGN, V_ALIGN, ANGLE, STR.