# Path: resources/lib/pdfminer/utils.py
# def mult_matrix(m1, m0):
#     (a1, b1, c1, d1, e1, f1) = m1
#     (a0, b0, c0, d0, e0, f0) = m0
#     """Returns the multiplication of two matrices."""
#     return (a0*a1+c0*b1,    b0*a1+d0*b1,
#             a0*c1+c0*d1,    b0*c1+d0*d1,
#             a0*e1+c0*f1+e0, b0*e1+d0*f1+f0)
# 
# Path: resources/lib/pdfminer/utils.py
# def translate_matrix(m, v):
#     """Translates a matrix by (x, y)."""
#     (a, b, c, d, e, f) = m
#     (x, y) = v
#     return (a, b, c, d, x*a+y*c+e, x*b+y*d+f)
# 
# Path: resources/lib/pdfminer/utils.py
# def enc(x, codec='ascii'):
#     """Encodes a string for SGML/XML/HTML"""
#     x = x.replace('&', '&amp;').replace('>', '&gt;').replace('<', '&lt;').replace('"', '&quot;')
#     return x.encode(codec, 'xmlcharrefreplace')
# 
# Path: resources/lib/pdfminer/utils.py
# def bbox2str(bbox):
#     (x0, y0, x1, y1) = bbox
#     return '%.3f,%.3f,%.3f,%.3f' % (x0, y0, x1, y1)
# 
# Path: resources/lib/pdfminer/utils.py
# def isnumber(x):
#     return isinstance(x, (int, long, float))
# 
# Path: resources/lib/pdfminer/pdffont.py
# class PDFUnicodeNotDefined(PDFFontError):
#     pass


from .utils import mult_matrix
from .utils import translate_matrix
from .utils import enc
from .utils import bbox2str
from .utils import isnumber
from .pdffont import PDFUnicodeNotDefined
        font = textstate.font
        text = ''
        for obj in seq:
            if not isinstance(obj, str):
                continue
            chars = font.decode(obj)
            for cid in chars:
                try:
                    char = font.to_unichr(cid)
                    text += char
                except PDFUnicodeNotDefined:
                    pass
        self.outfp.write(enc(text, self.codec))
        return

    def begin_page(self, page, ctm):
        self.outfp.write('<page id="%s" bbox="%s" rotate="%d">' %
                         (self.pageno, bbox2str(page.mediabox), page.rotate))
        return

    def end_page(self, page):
        self.outfp.write('</page>\n')
        self.pageno += 1
        return

    def begin_tag(self, tag, props=None):
        s = ''
        if isinstance(props, dict):
            s = ''.join(' %s="%s"' % (enc(k), enc(str(v))) for (k, v)
                        in sorted(props.iteritems()))

# Path: resources/lib/pdfminer/utils.py
# def mult_matrix(m1, m0):
#     (a1, b1, c1, d1, e1, f1) = m1
#     (a0, b0, c0, d0, e0, f0) = m0
#     """Returns the multiplication of two matrices."""
#     return (a0*a1+c0*b1,    b0*a1+d0*b1,
#             a0*c1+c0*d1,    b0*c1+d0*d1,
#             a0*e1+c0*f1+e0, b0*e1+d0*f1+f0)
# 
# Path: resources/lib/pdfminer/utils.py
# def translate_matrix(m, v):
#     """Translates a matrix by (x, y)."""
#     (a, b, c, d, e, f) = m
#     (x, y) = v
#     return (a, b, c, d, x*a+y*c+e, x*b+y*d+f)
# 
# Path: resources/lib/pdfminer/utils.py
# def enc(x, codec='ascii'):
#     """Encodes a string for SGML/XML/HTML"""
#     x = x.replace('&', '&amp;').replace('>', '&gt;').replace('<', '&lt;').replace('"', '&quot;')
#     return x.encode(codec, 'xmlcharrefreplace')
# 
# Path: resources/lib/pdfminer/utils.py
# def bbox2str(bbox):
#     (x0, y0, x1, y1) = bbox
#     return '%.3f,%.3f,%.3f,%.3f' % (x0, y0, x1, y1)
# 
# Path: resources/lib/pdfminer/utils.py
# def isnumber(x):
#     return isinstance(x, (int, long, float))
# 
# Path: resources/lib/pdfminer/pdffont.py
# class PDFUnicodeNotDefined(PDFFontError):
#     pass


# Path: resources/lib/pdfminer/pdfdevice.py
from .utils import mult_matrix
from .utils import translate_matrix
from .utils import enc
from .utils import bbox2str
from .utils import isnumber
from .pdffont import PDFUnicodeNotDefined

        font = textstate.font
        text = ''
        for obj in seq:
            if not isinstance(obj, str):
                continue
            chars = font.decode(obj)
            for cid in chars:
                try:
                    char = font.to_unichr(cid)
                    text += char
                except PDFUnicodeNotDefined:
                    pass
        self.outfp.write(enc(text, self.codec))
        return

    def begin_page(self, page, ctm):
        self.outfp.write('<page id="%s" bbox="%s" rotate="%d">' %
                         (self.pageno, bbox2str(page.mediabox), page.rotate))
        return

    def end_page(self, page):
        self.outfp.write('</page>\n')
        self.pageno += 1
        return

    def begin_tag(self, tag, props=None):
        s = ''
        if isinstance(props, dict):
            s = ''.join(' %s="%s"' % (enc(k), enc(str(v))) for (k, v)
                        in sorted(props.iteritems()))

        self.outfp.write('<%s%s>' % (enc(tag.name), s))