def test_map_struct_with_xarray(self): xarray_type = X_ARRAY(self.BasicStruct, ref_member('count')) class StructWithXArray(object): __metaclass__ = StructType @staticmethod def attributes(): yield UINT16, 'count' yield dict(type=xarray_type, name='items') bin_item = dict(type=StructWithXArray) events = bintype_map_events(bin_item) self.assertEquals((STARTEVENT, bin_item), events.next()) self.assertEquals((None, dict(type=UINT16, name='count')), events.next()) self.assertEquals((STARTEVENT, dict(type=xarray_type, name='items')), events.next()) self.assertEquals((STARTEVENT, dict(type=self.BasicStruct)), events.next()) self.assertEquals((None, dict(type=UINT16, name='a')), events.next()) self.assertEquals((None, dict(type=UINT16, name='b')), events.next()) self.assertEquals((ENDEVENT, dict(type=self.BasicStruct)), events.next()) self.assertEquals((ENDEVENT, dict(type=xarray_type, name='items')), events.next()) self.assertEquals((ENDEVENT, bin_item), events.next())
def test_resolve_xarray(self): xarray_type = X_ARRAY(UINT16, ref_member('a')) class StructWithXArray(object): __metaclass__ = StructType @staticmethod def attributes(): yield UINT16, 'a' yield dict(name='b', type=xarray_type) static_events = bintype_map_events(dict(type=StructWithXArray)) static_events = list(static_events) events = static_to_mutable(iter(static_events)) events = resolve_typedefs(events, dict()) ev, struct = events.next() self.assertEquals((STARTEVENT, struct), (ev, struct)) self.assertEquals((None, dict(name='a', type=UINT16)), events.next()) struct['value'] = dict(a=0) self.assertEquals( (STARTEVENT, dict(name='b', count=0, type=xarray_type)), events.next()) self.assertEquals( (ENDEVENT, dict(name='b', count=0, type=xarray_type)), events.next()) self.assertEquals((ENDEVENT, struct), events.next()) events = static_to_mutable(iter(static_events)) events = resolve_typedefs(events, dict()) ev, struct = events.next() self.assertEquals((STARTEVENT, struct), (ev, struct)) self.assertEquals((None, dict(name='a', type=UINT16)), events.next()) struct['value'] = dict(a=1) self.assertEquals( (STARTEVENT, dict(name='b', count=1, type=xarray_type)), events.next()) self.assertEquals((None, dict(type=UINT16)), events.next()) self.assertEquals( (ENDEVENT, dict(name='b', count=1, type=xarray_type)), events.next()) self.assertEquals((ENDEVENT, struct), events.next()) events = static_to_mutable(iter(static_events)) events = resolve_typedefs(events, dict()) ev, struct = events.next() self.assertEquals((STARTEVENT, struct), (ev, struct)) self.assertEquals((None, dict(name='a', type=UINT16)), events.next()) struct['value'] = dict(a=2) self.assertEquals( (STARTEVENT, dict(name='b', count=2, type=xarray_type)), events.next()) self.assertEquals((None, dict(type=UINT16)), events.next()) self.assertEquals((None, dict(type=UINT16)), events.next()) self.assertEquals( (ENDEVENT, dict(name='b', count=2, type=xarray_type)), events.next()) self.assertEquals((ENDEVENT, struct), events.next())
def attributes(cls): ''' 표 70 표 개체 속성 ''' yield cls.Flags, 'flags' yield UINT16, 'rows' yield UINT16, 'cols' yield HWPUNIT16, 'cellspacing' # 표 72 안쪽 여백 정보 yield Margin, 'padding' yield dict(type=X_ARRAY(UINT16, ref_member('rows')), name='rowcols') yield UINT16, 'borderfill_id' yield dict(type=N_ARRAY(UINT16, ZoneInfo), name='validZones', version=(5, 0, 0, 7))
def attributes(cls): yield cls.Flags, 'flags' yield HWPUNIT16, 'spacing' def not_same_widths(context, values): ''' flags.same_widths == 0 ''' return not values['flags'].same_widths def n_entries(member_ref): def n_entries(context, values): n_columns = member_ref(context, values) return n_columns - 1 return n_entries yield dict(name='column0', type=Column0, condition=not_same_widths) yield dict(name='columns', type=X_ARRAY(Column, n_entries(ref_member_flag('flags', 'count'))), condition=not_same_widths) yield UINT16, 'attr2' yield Border, 'splitter'
def attributes(cls): ''' 표 57 문단의 레이아웃 ''' yield dict(name='linesegs', type=X_ARRAY(LineSeg, ref_parent_member('linesegs')))
def attributes(): yield dict(name='range_tags', type=X_ARRAY(RangeTag, ref_parent_member('rangetags')))
def attributes(): ''' 표 56 문단의 글자 모양 ''' yield dict(name='charshapes', type=X_ARRAY(ARRAY(UINT32, 2), ref_parent_member('charshapes')))
def attributes(cls): ''' 표 78 개체 요소 속성 ''' yield dict(type=CHID, name='chid0', condition=parent_must_be_gso) yield CHID, 'chid' yield SHWPUNIT, 'x_in_group' yield SHWPUNIT, 'y_in_group' yield WORD, 'level_in_group' yield WORD, 'local_version' yield SHWPUNIT, 'initial_width' yield SHWPUNIT, 'initial_height' yield SHWPUNIT, 'width' yield SHWPUNIT, 'height' yield cls.Flags, 'flags' yield WORD, 'angle' yield Coord, 'rotation_center' ''' 표 79 Rendering 정보 ''' yield WORD, 'scalerotations_count' yield Matrix, 'translation' yield dict(type=X_ARRAY(ScaleRotationMatrix, ref_member('scalerotations_count')), name='scalerotations') # # Container # yield dict(type=N_ARRAY(WORD, CHID), name='controls', condition=chid_is_container) # # Rectangle # ''' 표 81 테두리 선 정보 ''' yield dict(type=BorderLine, name='border', condition=chid_is_rect) ''' 표 83 Outline style ''' # TODO: Outline ??? yield dict(type=cls.FillFlags, name='fill_flags', condition=chid_is_rect) yield dict(type=UINT16, name='unknown', condition=chid_is_rect) yield dict(type=UINT8, name='unknown1', condition=chid_is_rect) yield dict(type=FillColorPattern, name='fill_colorpattern', condition=chid_is_rect_and_fill_colorpattern) yield dict(type=FillGradation, name='fill_gradation', condition=chid_is_rect_and_fill_gradation) yield dict(type=FillImage, name='fill_image', condition=chid_is_rect_and_fill_image) yield dict(type=UINT32, name='fill_shape', condition=chid_is_rect) yield dict(type=BYTE, name='fill_blur_center', condition=chid_is_rect_and_fill_gradation) # TODO: 아래 두 필드: chid == $rec일 때만인지 확인 필요 yield dict(type=HexBytes(5), name='unknown2', condition=chid_is_rect, version=(5, 0, 2, 4)) yield dict(type=HexBytes(16), name='unknown3', condition=chid_is_rect, version=(5, 0, 2, 4)) # # Line # yield dict(type=BorderLine, name='line', condition=chid_is_line)