Examples of DSCEvent


Examples of org.apache.xmlgraphics.ps.dsc.events.DSCEvent

    public static DSCHeaderComment checkAndSkipDSC30Header(DSCParser parser)
                throws DSCException, IOException {
        if (!parser.hasNext()) {
            throw new DSCException("File has no content");
        }
        DSCEvent event = parser.nextEvent();
        if (event.getEventType() == HEADER_COMMENT) {
            DSCHeaderComment header = (DSCHeaderComment)event;
            if (!header.isPSAdobe30()) {
                throw new DSCException("PostScript file does not start with '"
                        + DSCConstants.PS_ADOBE_30 + "'");
            }
View Full Code Here

Examples of org.apache.xmlgraphics.ps.dsc.events.DSCEvent

     * @throws DSCException In case of a violation of the DSC spec
     */
    public static DSCComment nextPageOrTrailer(DSCParser parser, PSGenerator gen)
                throws IOException, DSCException {
        while (parser.hasNext()) {
            DSCEvent event = parser.nextEvent();
            if (event.getEventType() == DSC_COMMENT) {
                DSCComment comment = event.asDSCComment();
                if (DSCConstants.PAGE.equals(comment.getName())) {
                    return comment;
                } else if (DSCConstants.TRAILER.equals(comment.getName())) {
                    return comment;
                }
            } else if (event.getEventType() == EOF) {
                //The Trailer may be missing
                return event.asDSCComment();
            }
            if (gen != null) {
                event.generate(gen); //Pipe through to PSGenerator
            }
        }
        return null;
    }
View Full Code Here

Examples of org.apache.xmlgraphics.ps.dsc.events.DSCEvent

            }
        }
       
        //Write the rest
        while (parser.hasNext()) {
            DSCEvent event = parser.nextEvent();
            event.generate(gen);
        }
    }
View Full Code Here

Examples of org.apache.xmlgraphics.ps.dsc.events.DSCEvent

            DSCParser parser;
            try {
                parser = new DSCParser(new ImageInputStreamAdapter(in));
                outerLoop:
                while (parser.hasNext()) {
                    DSCEvent event = parser.nextEvent();
                    switch (event.getEventType()) {
                    case DSCParserConstants.HEADER_COMMENT:
                    case DSCParserConstants.COMMENT:
                        //ignore
                        break;
                    case DSCParserConstants.DSC_COMMENT:
                        DSCComment comment = event.asDSCComment();
                        if (comment instanceof DSCCommentBoundingBox) {
                            DSCCommentBoundingBox bboxComment = (DSCCommentBoundingBox)comment;
                            if (DSCConstants.BBOX.equals(bboxComment.getName()) && bbox == null) {
                                bbox = (Rectangle2D)bboxComment.getBoundingBox().clone();
                                //BoundingBox is good but HiRes is better so continue
View Full Code Here

Examples of org.apache.xmlgraphics.ps.dsc.events.DSCEvent

import junit.framework.TestCase;

public class DSCToolsTestCase extends TestCase {

    public void testEndComment() throws Exception {
        DSCEvent event;
       
        event = new DSCCommentEndComments();
        assertTrue(DSCTools.headerCommentsEndHere(event));

        event = new PostScriptComment("FOPTest");
View Full Code Here

Examples of org.apache.xmlgraphics.ps.dsc.events.DSCEvent

            }
        });

        //Get PostScript language level (may be missing)
        while (true) {
            DSCEvent event = parser.nextEvent();
            if (event == null) {
                reportInvalidDSC();
            }
            if (DSCTools.headerCommentsEndHere(event)) {
                //Set number of pages
                DSCCommentPages pages = new DSCCommentPages(pageCount);
                pages.generate(gen);
                new DSCCommentBoundingBox(documentBoundingBox).generate(gen);
                new DSCCommentHiResBoundingBox(documentBoundingBox).generate(gen);

                PSFontUtils.determineSuppliedFonts(resTracker, fontInfo, fontInfo.getUsedFonts());
                registerSuppliedForms(resTracker, formResources);
               
                //Supplied Resources
                DSCCommentDocumentSuppliedResources supplied
                    = new DSCCommentDocumentSuppliedResources(
                            resTracker.getDocumentSuppliedResources());
                supplied.generate(gen);
               
                //Needed Resources
                DSCCommentDocumentNeededResources needed
                    = new DSCCommentDocumentNeededResources(
                            resTracker.getDocumentNeededResources());
                needed.generate(gen);

                //Write original comment that ends the header comments
                event.generate(gen);
                break;
            }
            if (event.isDSCComment()) {
                DSCComment comment = event.asDSCComment();
                if (DSCConstants.LANGUAGE_LEVEL.equals(comment.getName())) {
                    DSCCommentLanguageLevel level = (DSCCommentLanguageLevel)comment;
                    gen.setPSLevel(level.getLanguageLevel());
                }
            }
            event.generate(gen);
        }
       
        //Skip to the FOPFontSetup
        PostScriptComment fontSetupPlaceholder = parser.nextPSComment("FOPFontSetup", gen);
        if (fontSetupPlaceholder == null) {
            throw new DSCException("Didn't find %FOPFontSetup comment in stream");
        }
        PSFontUtils.writeFontDict(gen, fontInfo, fontInfo.getUsedFonts());
        generateForms(resTracker, userAgent, formResources, gen);

        //Skip the prolog and to the first page
        DSCComment pageOrTrailer = parser.nextDSCComment(DSCConstants.PAGE, gen);
        if (pageOrTrailer == null) {
            throw new DSCException("Page expected, but none found");
        }
       
        //Process individual pages (and skip as necessary)
        while (true) {
            DSCCommentPage page = (DSCCommentPage)pageOrTrailer;
            page.generate(gen);
            pageOrTrailer = DSCTools.nextPageOrTrailer(parser, gen);
            if (pageOrTrailer == null) {
                reportInvalidDSC();
            } else if (!DSCConstants.PAGE.equals(pageOrTrailer.getName())) {
                pageOrTrailer.generate(gen);
                break;
            }
        }
       
        //Write the rest
        while (parser.hasNext()) {
            DSCEvent event = parser.nextEvent();
            event.generate(gen);
        }
    }
View Full Code Here

Examples of org.apache.xmlgraphics.ps.dsc.events.DSCEvent

import junit.framework.TestCase;

public class DSCToolsTestCase extends TestCase {

    public void testEndComment() throws Exception {
        DSCEvent event;

        event = new DSCCommentEndComments();
        assertTrue(DSCTools.headerCommentsEndHere(event));

        event = new PostScriptComment("FOPTest");
View Full Code Here

Examples of org.apache.xmlgraphics.ps.dsc.events.DSCEvent

                    return !event.isComment();
                }

            });
            while (parser.hasNext()) {
                DSCEvent event = parser.nextEvent();

                if (parser.getCurrentEvent().isComment()) {
                    fail("Filter failed. Comment found.");
                }
            }
View Full Code Here

Examples of org.apache.xmlgraphics.ps.dsc.events.DSCEvent

                    if (event.isDSCComment()) {
                        DSCComment comment = event.asDSCComment();
                        if (DSCConstants.BEGIN_PROLOG.equals(comment.getName())) {
                            //Skip until end of prolog
                            while (parser.hasNext()) {
                                DSCEvent e = parser.nextEvent();
                                if (e.isDSCComment()) {
                                    if (DSCConstants.END_PROLOG.equals(
                                            e.asDSCComment().getName())) {
                                        parser.next();
                                        break;
                                    }
                                }

                            }
                        }
                    }
                }
            });

            //Listener for the language level
            parser.addListener(new DSCListener() {
                public void processEvent(DSCEvent event, DSCParser parser)
                        throws IOException, DSCException {
                    if (event instanceof DSCCommentLanguageLevel) {
                        DSCCommentLanguageLevel level = (DSCCommentLanguageLevel)event;
                        results.put("level", new Integer(level.getLanguageLevel()));
                    }
                }
            });
            int count = 0;
            while (parser.hasNext()) {
                DSCEvent event = parser.nextEvent();
                System.out.println(event);
                count++;
            }
            assertEquals(12, count);
            assertEquals(new Integer(1), results.get("level"));
View Full Code Here

Examples of org.apache.xmlgraphics.ps.dsc.events.DSCEvent

    public static DSCHeaderComment checkAndSkipDSC30Header(DSCParser parser)
                throws DSCException, IOException {
        if (!parser.hasNext()) {
            throw new DSCException("File has no content");
        }
        DSCEvent event = parser.nextEvent();
        if (event.getEventType() == HEADER_COMMENT) {
            DSCHeaderComment header = (DSCHeaderComment)event;
            if (!header.isPSAdobe30()) {
                throw new DSCException("PostScript file does not start with '"
                        + DSCConstants.PS_ADOBE_30 + "'");
            }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.