Ejemplo n.º 1
0
    def _add_spread_elements_from_idml(self, idml_package, at, only, translation):
        """ Append idml_package spread elements into self.spread[0] <Spread> node. """

        spread_dest_filename = self.get_spread_by_xpath(at)
        spread_dest = Spread(self, spread_dest_filename, self.working_copy_path)
        spread_dest_elt = spread_dest.dom.xpath("./Spread")[0]

        only_node = idml_package.xml_structure.xpath(only)[0]

        # Add spread elements on the same layer. We start by that because the order in the
        # Spread file is the z-position on the Layer.
        only_layer = idml_package.get_structure_element_layer_id(only_node)
        spread_elts_to_add = idml_package.get_spread_elements_by_layer(layer_id=only_layer,
                                                                       excluded_tags=["Guide"])

        # Then add the tagged elements that may be on others layers.
        for node in only_node.iter():
            if node.get("XMLContent") is None:
                continue
            spread_elt = idml_package.get_spread_elem_by_id(node.get("XMLContent"))
            # Image and EPS element are included in a Rectangle.
            if spread_elt.tag in ["Image", "EPS"]:
                spread_elt = spread_elt.getparent()
            if spread_elt not in spread_elts_to_add:
                spread_elts_to_add.append(spread_elt)

        def _add_spread_element(spread_dest_elt, spread_elt):
            spread_elt_copy = copy.deepcopy(spread_elt)
            self.apply_translation_to_element(spread_elt_copy, translation)
            spread_dest_elt.append(spread_elt_copy)

        map(lambda s: _add_spread_element(spread_dest_elt, s), spread_elts_to_add)

        spread_dest.synchronize()
        self.init_lazy_references()
Ejemplo n.º 2
0
    def test_has_any_item_on_layer(self):
        idml_file = IDMLPackage(os.path.join(IDMLFILES_DIR, "4-pages-layers-with-guides.idml"), mode="r")
        spreads = idml_file.spreads

        # Spread_ud8.xml
        spread1 = Spread(idml_file, spreads[0])
        self.assertFalse(spread1.has_any_item_on_layer("unknown_layer"))
        self.assertTrue(spread1.has_any_item_on_layer("u2db"))
Ejemplo n.º 3
0
    def test_is_recto(self):
        idml_file = IDMLPackage(os.path.join(IDMLFILES_DIR, "magazineA-courrier-des-lecteurs-3pages.idml"), mode="r")
        spread1 = Spread(idml_file, idml_file.spreads[0])
        page1 = spread1.pages[0]
        self.assertTrue(page1.is_recto)

        spread2 = Spread(idml_file, idml_file.spreads[1])
        page2 = spread2.pages[0]
        page3 = spread2.pages[1]
        self.assertFalse(page2.is_recto)
        self.assertTrue(page3.is_recto)
Ejemplo n.º 4
0
    def test_pages(self):
        idml_file = IDMLPackage(os.path.join(IDMLFILES_DIR, "4-pages.idml"), mode="r")
        spreads = idml_file.spreads

        spread1 = Spread(idml_file, spreads[0])
        spread1_pages = spread1.pages
        self.assertEqual(len(spread1_pages), 1)
        self.assertEqual(spread1_pages[0].node.tag, "Page")

        spread2 = Spread(idml_file, spreads[1])
        spread2_pages = spread2.pages
        self.assertEqual(len(spread2_pages), 2)
        self.assertEqual(spread2_pages[0].node.tag, "Page")
        self.assertEqual(spread2_pages[1].node.tag, "Page")
Ejemplo n.º 5
0
 def spreads_objects(self):
     if self._spreads_objects is None:
         spreads_objects = [
             Spread(self, s, self.working_copy_path) for s in self.spreads
         ]
         self._spreads_objects = spreads_objects
     return self._spreads_objects
Ejemplo n.º 6
0
    def test_geometric_bounds(self):
        idml_file = IDMLPackage(os.path.join(
            IDMLFILES_DIR, "magazineA-courrier-des-lecteurs-3pages.idml"),
                                mode="r")
        spread = Spread(idml_file, idml_file.spreads[1])

        page3 = spread.pages[1]
        self.assertEqual(page3.geometric_bounds, [
            Decimal('0'),
            Decimal('0'),
            Decimal('759.6850393700788'),
            Decimal('566.9291338582677')
        ])

        page3.geometric_bounds = [
            Decimal('210'),
            Decimal('297'),
            Decimal('10.51'),
            Decimal('7.23')
        ]
        self.assertEqual(page3.geometric_bounds, [
            Decimal('210'),
            Decimal('297'),
            Decimal('10.51'),
            Decimal('7.23')
        ])
Ejemplo n.º 7
0
    def test_page_items(self):
        idml_file = IDMLPackage(os.path.join(
            IDMLFILES_DIR, "magazineA-courrier-des-lecteurs-3pages.idml"),
                                mode="r")
        spread = Spread(idml_file, idml_file.spreads[1])

        page1 = spread.pages[0]
        self.assertEqual([i.tag for i in page1.page_items], ["Rectangle"])

        page2 = spread.pages[1]
        self.assertEqual([i.tag for i in page2.page_items], [
            'Rectangle',
            'TextFrame',
            'Polygon',
            'Polygon',
            'Polygon',
            'GraphicLine',
            'Polygon',
            'Polygon',
            'Oval',
            'Rectangle',
        ])

        # test the setter
        page2.page_items = ["foo", "bar"]
        self.assertEqual(page2.page_items, ["foo", "bar"])
Ejemplo n.º 8
0
    def test_set_face(self):
        idml_file = IDMLPackage(os.path.join(IDMLFILES_DIR, "magazineA-courrier-des-lecteurs.idml"), mode="r")
        spread2 = Spread(idml_file, idml_file.spreads[1])
        page2 = spread2.pages[0]
        self.assertEqual(page2.face, VERSO)

        page2.set_face(RECTO)
        self.assertEqual(page2.face, RECTO)
Ejemplo n.º 9
0
    def add_new_spread(self, working_copy_path):
        """Create a new empty Spread in the working copy from the last one. """

        last_spread = self.spreads_objects[-1]
        # TODO : make sure the filename does not exists.
        new_spread_name = increment_filename(last_spread.name)
        new_spread_wc_path = os.path.join(working_copy_path, new_spread_name)
        shutil.copy2(os.path.join(working_copy_path, last_spread.name),
                     new_spread_wc_path)
        self._spreads_objects = None

        new_spread = Spread(self, new_spread_name, working_copy_path)
        new_spread.clear()
        new_spread.node.set("Self", new_spread.get_node_name_from_xml_name())

        self.designmap.add_spread(new_spread)
        self.designmap.synchronize()

        # The spread synchronization is done outside.
        return new_spread
Ejemplo n.º 10
0
    def _add_spread_elements_from_idml(self, idml_package, at, only,
                                       translation):
        """ Append idml_package spread elements into self.spread[0] <Spread> node. """

        spread_dest_filename = self.get_spread_by_xpath(at)
        spread_dest = Spread(self, spread_dest_filename,
                             self.working_copy_path)
        spread_dest_elt = spread_dest.dom.xpath("./Spread")[0]

        only_node = idml_package.xml_structure.xpath(only)[0]

        # Add spread elements on the same layer. We start by that because the order in the
        # Spread file is the z-position on the Layer.
        only_layer = idml_package.get_structure_element_layer_id(only_node)
        spread_elts_to_add = idml_package.get_spread_elements_by_layer(
            layer_id=only_layer, excluded_tags=["Guide"])

        # Then add the tagged elements that may be on others layers.
        for node in only_node.iter():
            if node.get("XMLContent") is None:
                continue
            spread_elt = idml_package.get_spread_elem_by_id(
                node.get("XMLContent"))
            # Image and EPS element are included in a Rectangle.
            if spread_elt.tag in ["Image", "EPS"]:
                spread_elt = spread_elt.getparent()
            if spread_elt not in spread_elts_to_add:
                spread_elts_to_add.append(spread_elt)

        def _add_spread_element(spread_dest_elt, spread_elt):
            spread_elt_copy = copy.deepcopy(spread_elt)
            self.apply_translation_to_element(spread_elt_copy, translation)
            spread_dest_elt.append(spread_elt_copy)

        map(lambda s: _add_spread_element(spread_dest_elt, s),
            spread_elts_to_add)

        spread_dest.synchronize()
        self.init_lazy_references()
Ejemplo n.º 11
0
    def add_new_spread(self, working_copy_path):
        """Create a new empty Spread in the working copy from the last one. """

        last_spread = self.spreads_objects[-1]
        # TODO : make sure the filename does not exists.
        new_spread_name = increment_filename(last_spread.name)
        new_spread_wc_path = os.path.join(working_copy_path, new_spread_name)
        shutil.copy2(
            os.path.join(working_copy_path, last_spread.name),
            new_spread_wc_path
        )
        self._spreads_objects = None

        new_spread = Spread(self, new_spread_name, working_copy_path)
        new_spread.clear()
        new_spread.node.set("Self", new_spread.get_node_name_from_xml_name())

        self.designmap.add_spread(new_spread)
        self.designmap.synchronize()

        # The spread synchronization is done outside.
        return new_spread
Ejemplo n.º 12
0
    def test_has_any_guide_on_layer(self):
        # Package with 2 layers, each one having guides.
        idml_file = IDMLPackage(os.path.join(IDMLFILES_DIR, "4-pages-layers-with-guides.idml"), mode="r")
        spreads = idml_file.spreads

        # Spread_ud8.xml
        spread1 = Spread(idml_file, spreads[0])
        self.assertFalse(spread1.has_any_guide_on_layer("unknown_layer"))
        self.assertTrue(spread1.has_any_guide_on_layer("u2db"))
        self.assertTrue(spread1.has_any_guide_on_layer("ua4"))

        # Package with one layer and no guides.
        idml_file = IDMLPackage(os.path.join(IDMLFILES_DIR, "4-pages.idml"), mode="r")
        spreads = idml_file.spreads

        # Spread_ub6.xml
        spread1 = Spread(idml_file, spreads[0])
        self.assertFalse(spread1.has_any_guide_on_layer("ub3"))
Ejemplo n.º 13
0
    def test_coordinates(self):
        idml_file = IDMLPackage(os.path.join(IDMLFILES_DIR, "magazineA-courrier-des-lecteurs-3pages.idml"), mode="r")
        spread = Spread(idml_file, idml_file.spreads[1])

        page2 = spread.pages[0]
        self.assertEqual(page2.coordinates, {
            'x1': Decimal('-566.9291338582677'),
            'y1': Decimal('-379.8425196850394'),
            'x2': Decimal('0E-13'),
            'y2': Decimal('379.8425196850394')
        })

        page3 = spread.pages[1]
        self.assertEqual(page3.coordinates, {
            'x1': Decimal('0'),
            'y1': Decimal('-379.8425196850394'),
            'x2': Decimal('566.9291338582677'),
            'y2': Decimal('379.8425196850394'),
        })