Example #1
0
 def test_decode(self):
     paratext_record = self.hwp5file.bodytext.section(0).record(1)
     payload = paratext_record['payload']
     controlchar = ControlChar.decode(payload[0:16])
     self.assertEqual(dict(code=ord(ControlChar.SECTION_COLUMN_DEF),
                           chid='secd',
                           param=b'\x00' * 8), controlchar)
Example #2
0
 def test_decode(self):
     paratext_record = self.hwp5file.bodytext.section(0).record(1)
     payload = paratext_record['payload']
     controlchar = ControlChar.decode(payload[0:16])
     self.assertEquals(dict(code=ord(ControlChar.SECTION_COLUMN_DEF),
                            chid='secd',
                            param='\x00' * 8), controlchar)
Example #3
0
def range_shaped_textchunk_events(paratext_context, range_shaped_textchunks):
    for (startpos, endpos), (shape, none), chunk in range_shaped_textchunks:
        if isinstance(chunk, basestring):
            textitem = (Text, dict(text=chunk,
                                   charshape_id=shape), paratext_context)
            yield STARTEVENT, textitem
            yield ENDEVENT, textitem
        elif isinstance(chunk, dict):
            code = chunk['code']
            uch = unichr(code)
            name = ControlChar.get_name_by_code(code)
            kind = ControlChar.kinds[uch]
            chunk_attributes = dict(name=name,
                                    code=code,
                                    kind=kind,
                                    charshape_id=shape)
            if code in (0x9, 0xa, 0xd):  # http://www.w3.org/TR/xml/#NT-Char
                chunk_attributes['char'] = uch
            ctrlch = (ControlChar, chunk_attributes, paratext_context)
            yield STARTEVENT, ctrlch
            yield ENDEVENT, ctrlch
Example #4
0
def range_shaped_textchunk_events(paratext_context, range_shaped_textchunks):
    for (startpos, endpos), (shape, none), chunk in range_shaped_textchunks:
        if isinstance(chunk, basestring):
            textitem = (Text,
                        dict(text=chunk, charshape_id=shape),
                        paratext_context)
            yield STARTEVENT, textitem
            yield ENDEVENT, textitem
        elif isinstance(chunk, dict):
            code = chunk['code']
            uch = unichr(code)
            name = ControlChar.get_name_by_code(code)
            kind = ControlChar.kinds[uch]
            chunk_attributes = dict(name=name,
                                    code=code,
                                    kind=kind,
                                    charshape_id=shape)
            if code in (0x9, 0xa, 0xd):  # http://www.w3.org/TR/xml/#NT-Char
                chunk_attributes['char'] = uch
            ctrlch = (ControlChar, chunk_attributes, paratext_context)
            yield STARTEVENT, ctrlch
            yield ENDEVENT, ctrlch
Example #5
0
 def test_find(self):
     from hwp5.binmodel import ControlChar
     bytes = '\x41\x00'
     self.assertEquals((2, 2), ControlChar.find(bytes, 0))
Example #6
0
 def test_find(self):
     bytes = b'\x41\x00'
     self.assertEqual((2, 2), ControlChar.find(bytes, 0))
Example #7
0
 def test_find(self):
     from hwp5.binmodel import ControlChar
     bytes = '\x41\x00'
     self.assertEquals((2, 2), ControlChar.find(bytes, 0))
Example #8
0
 def test_find(self):
     bytes = b'\x41\x00'
     self.assertEqual((2, 2), ControlChar.find(bytes, 0))