コード例 #1
0
    def test_epub3_covers(self):
        # cover image
        ce = partial(self.create_epub, ver=3)
        c = ce([cmi('c.jpg')])
        self.assertIsNone(find_cover_image(c))
        c = ce([cmi('c.jpg')], meta_cover='c.jpg')
        self.assertEqual('c.jpg', find_cover_image(c))
        c = ce([cmi('c.jpg', b'z', 'cover-image'), cmi('d.jpg')], meta_cover='d.jpg')
        self.assertEqual('c.jpg', find_cover_image(c))
        mark_as_cover(c, 'd.jpg')
        self.assertEqual('d.jpg', find_cover_image(c))
        self.assertFalse(c.opf_xpath('//*/@name'))

        # title page
        c = ce([cmi('c.html'), cmi('a.html')])
        self.assertIsNone(find_cover_page(c))
        mark_as_titlepage(c, 'a.html', move_to_start=False)
        self.assertEqual('a.html', find_cover_page(c))
        self.assertEqual('c.html', next(c.spine_names)[0])
        mark_as_titlepage(c, 'a.html', move_to_start=True)
        self.assertEqual('a.html', find_cover_page(c))
        self.assertEqual('a.html', next(c.spine_names)[0])

        # clean opf of all cover information
        c = ce([cmi('c.jpg', b'z', 'cover-image'), cmi('c.html', b'', 'calibre:title-page'), cmi('d.html')],
                             meta_cover='c.jpg', guide=[('c.jpg', 'cover'), ('d.html', 'cover')])
        self.assertEqual(set(clean_opf(c)), {'c.jpg', 'c.html', 'd.html'})
        self.assertFalse(c.opf_xpath('//*/@name'))
        self.assertFalse(c.opf_xpath('//*/@type'))
        for prop in 'cover-image calibre:title-page'.split():
            self.assertEqual([], list(c.manifest_items_with_property(prop)))
コード例 #2
0
ファイル: boss.py プロジェクト: CharlesSong/calibre
    def mark_requested(self, name, action):
        self.commit_dirty_opf()
        c = current_container()
        if action == 'cover':
            mark_as_cover(current_container(), name)
        elif action.startswith('titlepage:'):
            action, move_to_start = action.partition(':')[0::2]
            move_to_start = move_to_start == 'True'
            mark_as_titlepage(current_container(), name, move_to_start=move_to_start)

        if c.opf_name in editors:
            editors[c.opf_name].replace_data(c.raw_data(c.opf_name))
        self.gui.file_list.build(c)
        self.set_modified()
コード例 #3
0
ファイル: boss.py プロジェクト: kmshi/calibre
    def mark_requested(self, name, action):
        self.commit_dirty_opf()
        c = current_container()
        if action == 'cover':
            mark_as_cover(current_container(), name)
        elif action.startswith('titlepage:'):
            action, move_to_start = action.partition(':')[0::2]
            move_to_start = move_to_start == 'True'
            mark_as_titlepage(current_container(),
                              name,
                              move_to_start=move_to_start)

        if c.opf_name in editors:
            editors[c.opf_name].replace_data(c.raw_data(c.opf_name))
        self.gui.file_list.build(c)
        self.set_modified()
コード例 #4
0
    def test_epub2_covers(self):
        # cover image
        ce = partial(self.create_epub, ver=2)
        c = ce([cmi('c.jpg')])
        self.assertIsNone(find_cover_image(c))
        c = ce([cmi('c.jpg')], meta_cover='c.jpg')
        self.assertEqual('c.jpg', find_cover_image(c))
        c = ce([cmi('c.jpg'), cmi('d.jpg')], guide=[('c.jpg', 'cover')])
        self.assertEqual('c.jpg', find_cover_image(c))
        mark_as_cover(c, 'd.jpg')
        self.assertEqual('d.jpg', find_cover_image(c))
        self.assertEqual({'cover':'d.jpg'}, c.guide_type_map)

        # title page
        c = ce([cmi('c.html'), cmi('a.html')])
        self.assertIsNone(find_cover_page(c))
        mark_as_titlepage(c, 'a.html', move_to_start=False)
        self.assertEqual('a.html', find_cover_page(c))
        self.assertEqual('c.html', next(c.spine_names)[0])
        mark_as_titlepage(c, 'a.html', move_to_start=True)
        self.assertEqual('a.html', find_cover_page(c))
        self.assertEqual('a.html', next(c.spine_names)[0])