Beispiel #1
0
        def test_detect(self):
            context = uno.getComponentContext()

            from hwp5.tests.fixtures import open_fixture
            f = open_fixture('sample-5017.hwp', 'rb')
            stream = InputStreamFromFileLike(f)
            mediadesc = dict_to_propseq(dict(InputStream=stream))

            svm = context.ServiceManager
            detector = svm.createInstanceWithContext('hwp5.Detector', context)
            typename, mediadesc2 = detector.detect(mediadesc)
            self.assertEquals('hwp5', typename)
Beispiel #2
0
        def test_filter(self):
            context = uno.getComponentContext()
            from hwp5.tests.fixtures import open_fixture
            f = open_fixture('sample-5017.hwp', 'rb')
            stream = InputStreamFromFileLike(f)
            mediadesc = dict_to_propseq(dict(InputStream=stream))

            svm = context.ServiceManager
            importer = svm.createInstanceWithContext('hwp5.Importer', context)
            desktop = svm.createInstanceWithContext('com.sun.star.frame.Desktop',
                                                    context)
            doc = desktop.loadComponentFromURL('private:factory/swriter', '_blank',
                                               0, ())

            importer.setTargetDocument(doc)
            importer.filter(mediadesc)

            text = doc.getText()

            paragraphs = text.createEnumeration()
            paragraphs = xenumeration_list(paragraphs)
            for paragraph_ix, paragraph in enumerate(paragraphs):
                logger.info('Paragraph %s', paragraph_ix)
                logger.debug('%s', paragraph)

                services = paragraph.SupportedServiceNames
                if 'com.sun.star.text.Paragraph' in services:
                    portions = xenumeration_list(paragraph.createEnumeration())
                    for portion_ix, portion in enumerate(portions):
                        logger.info('Portion %s: %s', portion_ix,
                                     portion.TextPortionType)
                        if portion.TextPortionType == 'Text':
                            logger.info('- %s', portion.getString())
                        elif portion.TextPortionType == 'Frame':
                            logger.debug('%s', portion)
                            textcontent_name = 'com.sun.star.text.TextContent'
                            en = portion.createContentEnumeration(textcontent_name)
                            contents = xenumeration_list(en)
                            for content in contents:
                                logger.debug('content: %s', content)
                                content_services = content.SupportedServiceNames
                                if ('com.sun.star.drawing.GraphicObjectShape' in
                                    content_services):
                                    logger.info('graphic url: %s',
                                                 content.GraphicURL)
                                    logger.info('graphic stream url: %s',
                                                 content.GraphicStreamURL)
                if 'com.sun.star.text.TextTable' in services:
                    pass
                else:
                    pass

            paragraph_portions = paragraphs[0].createEnumeration()
            paragraph_portions = xenumeration_list(paragraph_portions)
            self.assertEquals(u'한글 ', paragraph_portions[0].getString())

            paragraph_portions = paragraphs[16].createEnumeration()
            paragraph_portions = xenumeration_list(paragraph_portions)
            contents = paragraph_portions[1].createContentEnumeration('com.sun.star.text.TextContent')
            contents = xenumeration_list(contents)
            self.assertEquals('image/x-vclgraphic', contents[0].Bitmap.MimeType)
            #self.assertEquals('vnd.sun.star.Package:bindata/BIN0003.png',
            #                  contents[0].GraphicStreamURL)

            graphics = doc.getGraphicObjects()
            graphics = xenumeration_list(graphics.createEnumeration())
            logger.debug('graphic: %s', graphics)

            frames = doc.getTextFrames()
            frames = xenumeration_list(frames.createEnumeration())
            logger.debug('frames: %s', frames)