def test_get_style_node_by_name(self): idml_file = IDMLPackage(os.path.join(IDMLFILES_DIR, "article-1photo_import-xml.idml"), mode="r") style = Style(idml_file) style_node = style.get_style_node_by_name("CharacterStyle/bold") self.assertEqual( style_node.nsmap, {'idPkg': 'http://ns.adobe.com/AdobeInDesign/idml/1.0/packaging'}) self.assertEqual( etree_dom_to_tree(style_node, True), { 'attrs': { 'FontStyle': 'Bold', 'Imported': 'false', 'KeyboardShortcut': '0 0', 'Name': 'bold', 'Self': 'CharacterStyle/bold' }, 'content': [{ 'attrs': {}, 'content': [{ 'attrs': { 'type': 'string' }, 'content': [], 'tag': 'BasedOn', 'tail': '', 'text': '$ID/[No character style]' }, { 'attrs': { 'type': 'enumeration' }, 'content': [], 'tag': 'PreviewColor', 'tail': '', 'text': 'Nothing' }], 'tag': 'Properties', 'tail': '', 'text': '' }], 'tag': 'CharacterStyle', 'tail': '', 'text': '' })
def _add_styles_from_idml(self, idml_package): """Append styles to their groups or add the group in the Styles file. """ styles = Style(self) styles.working_copy_path = self.working_copy_path styles_root_elt = styles.get_root() for group_to_insert in idml_package.style_groups: group_host = styles_root_elt.xpath(group_to_insert.tag) # Either the group exists. if group_host: for style_to_insert in group_to_insert.iterchildren(): group_host[0].append(copy.deepcopy(style_to_insert)) # or not. else: styles_root_elt.append(copy.deepcopy(group_to_insert)) styles.synchronize()
def style_groups(self): if self._style_groups is None: style_groups = [ copy.deepcopy(elt) for elt in Style(self).style_groups() ] self._style_groups = style_groups return self._style_groups
def test_get_style_node_by_name(self): idml_file = IDMLPackage(os.path.join(IDMLFILES_DIR, "article-1photo_import-xml.idml"), mode="r") style = Style(idml_file) style_node = style.get_style_node_by_name("CharacterStyle/bold") self.assertEqual(style_node.nsmap, {'idPkg': 'http://ns.adobe.com/AdobeInDesign/idml/1.0/packaging'}) self.assertEqual(etree_dom_to_tree(style_node, True), { 'attrs': { 'FontStyle': 'Bold', 'Imported': 'false', 'KeyboardShortcut': '0 0', 'Name': 'bold', 'Self': 'CharacterStyle/bold' }, 'content': [ { 'attrs': {}, 'content': [ { 'attrs': {'type': 'string'}, 'content': [], 'tag': 'BasedOn', 'tail': '', 'text': '$ID/[No character style]' }, { 'attrs': {'type': 'enumeration'}, 'content': [], 'tag': 'PreviewColor', 'tail': '', 'text': 'Nothing' } ], 'tag': 'Properties', 'tail': '', 'text': '' } ], 'tag': 'CharacterStyle', 'tail': '', 'text': '' })
def style(self): if self._style is None: style = Style(self, self.working_copy_path) self._style = style return self._style