• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java BrowserCanvas类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.fit.cssbox.layout.BrowserCanvas的典型用法代码示例。如果您正苦于以下问题:Java BrowserCanvas类的具体用法?Java BrowserCanvas怎么用?Java BrowserCanvas使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



BrowserCanvas类属于org.fit.cssbox.layout包,在下文中一共展示了BrowserCanvas类的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: getContentScroll

import org.fit.cssbox.layout.BrowserCanvas; //导入依赖的package包/类
/**
 * This method initializes jScrollPane	
 * 	
 * @return javax.swing.JScrollPane	
 */
private JScrollPane getContentScroll()
{
    if (contentScroll == null)
    {
        contentScroll = new JScrollPane();
        contentScroll.setViewportView(getContentCanvas());
        contentScroll.addComponentListener(new java.awt.event.ComponentAdapter()
        {
            public void componentResized(java.awt.event.ComponentEvent e)
            {
                if (contentCanvas != null && contentCanvas instanceof BrowserCanvas)
                {
                    ((BrowserCanvas) contentCanvas).createLayout(contentScroll.getSize());
                    contentScroll.repaint();
                    //new box tree
                    root = createBoxTree(((BrowserCanvas) contentCanvas).getViewport());
                    boxTree.setModel(new DefaultTreeModel(root));
                }
            }
        });
    }
    return contentScroll;
}
 
开发者ID:mantlik,项目名称:swingbox-javahelp-viewer,代码行数:29,代码来源:BoxBrowser.java


示例2: getRedrawButton

import org.fit.cssbox.layout.BrowserCanvas; //导入依赖的package包/类
/**
 * This method initializes jButton	
 * 	
 * @return javax.swing.JButton	
 */
private JButton getRedrawButton()
{
    if (redrawButton == null)
    {
        redrawButton = new JButton();
        redrawButton.setText("Clear");
        redrawButton.setMnemonic(KeyEvent.VK_UNDEFINED);
        redrawButton.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent e)
            {
                ((BrowserCanvas) contentCanvas).redrawBoxes();
                contentCanvas.repaint();
            }
        });
    }
    return redrawButton;
}
 
开发者ID:mantlik,项目名称:swingbox-javahelp-viewer,代码行数:24,代码来源:BoxBrowser.java


示例3: analyze

import org.fit.cssbox.layout.BrowserCanvas; //导入依赖的package包/类
@Override
public ElementBox analyze(DocumentSource docSource, Dimension dim)
        throws Exception
{
    DOMSource parser = new DefaultDOMSource(docSource);
    w3cdoc = parser.parse();

    // Create the CSS analyzer
    DOMAnalyzer da = new DOMAnalyzer(w3cdoc, docSource.getURL());
    da.attributesToStyles();
    da.addStyleSheet(null, CSSNorm.stdStyleSheet(), DOMAnalyzer.Origin.AGENT);
    da.addStyleSheet(null, CSSNorm.userStyleSheet(), DOMAnalyzer.Origin.AGENT);
    da.getStyleSheets();
    
    BufferedImage tmpImg = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);
    canvas = new BrowserCanvas(da.getRoot(), da, docSource.getURL());
    canvas.setImage(tmpImg);
    canvas.getConfig().setLoadImages(true);
    canvas.getConfig().setLoadBackgroundImages(true);
    canvas.createLayout(dim);

    return canvas.getViewport();
}
 
开发者ID:mantlik,项目名称:swingbox-javahelp-viewer,代码行数:24,代码来源:DefaultAnalyzer.java


示例4: renderBrowserContent

import org.fit.cssbox.layout.BrowserCanvas; //导入依赖的package包/类
/**
 * Render the browser content
 */
public void renderBrowserContent()
{
	JPanel browserCanvas = new BrowserCanvas(
       	da.getRoot(), 
       	da, 
       	new java.awt.Dimension(
       		browserPane.getViewport().getSize().width,
       		browserPane.getViewport().getSize().height
       	), 
       	url
       );
       browserPane.setViewportView(browserCanvas);
       //System.out.println("--OK--");
       
       // Force garbage collection
       System.gc();
}
 
开发者ID:rkocman,项目名称:JSDOMBox,代码行数:21,代码来源:JSDOMBoxTestSuite.java


示例5: renderDocument

import org.fit.cssbox.layout.BrowserCanvas; //导入依赖的package包/类
private BufferedImage renderDocument(Document doc)
{
    //create the media specification
    MediaSpec media = new MediaSpec(mediaType);
    media.setDimensions(windowSize.width, windowSize.height);
    media.setDeviceDimensions(windowSize.width, windowSize.height);

    //Create the CSS analyzer
    DOMAnalyzer da = new DOMAnalyzer(doc, docSource.getURL());
    da.setMediaSpec(media);
    da.attributesToStyles(); //convert the HTML presentation attributes to inline styles
    da.addStyleSheet(null, CSSNorm.stdStyleSheet(), DOMAnalyzer.Origin.AGENT); //use the standard style sheet
    da.addStyleSheet(null, CSSNorm.userStyleSheet(), DOMAnalyzer.Origin.AGENT); //use the additional style sheet
    da.addStyleSheet(null, CSSNorm.formsStyleSheet(), DOMAnalyzer.Origin.AGENT); //render form fields using css
    da.getStyleSheets(); //load the author style sheets
    
    BrowserCanvas contentCanvas = new BrowserCanvas(da.getRoot(), da, docSource.getURL());
    contentCanvas.setAutoMediaUpdate(false); //we have a correct media specification, do not update
    contentCanvas.getConfig().setClipViewport(cropWindow);
    contentCanvas.getConfig().setLoadImages(loadImages);
    contentCanvas.getConfig().setLoadBackgroundImages(loadBackgroundImages);

    contentCanvas.createLayout(windowSize);
    return contentCanvas.getImage();
}
 
开发者ID:radkovo,项目名称:CSSBox,代码行数:26,代码来源:ReferenceTestCase.java


示例6: analyze

import org.fit.cssbox.layout.BrowserCanvas; //导入依赖的package包/类
@Override
public Viewport analyze(DocumentSource docSource, Dimension dim)
        throws Exception
{
    DOMSource parser = new DefaultDOMSource(docSource);
    w3cdoc = parser.parse();

    // Create the CSS analyzer
    DOMAnalyzer da = new DOMAnalyzer(w3cdoc, docSource.getURL());
    da.attributesToStyles();
    da.addStyleSheet(null, CSSNorm.stdStyleSheet(), DOMAnalyzer.Origin.AGENT);
    da.addStyleSheet(null, CSSNorm.userStyleSheet(), DOMAnalyzer.Origin.AGENT);
    da.getStyleSheets();
    
    BufferedImage tmpImg = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);
    canvas = new BrowserCanvas(da.getRoot(), da, docSource.getURL());
    canvas.setImage(tmpImg);
    canvas.getConfig().setLoadImages(true);
    canvas.getConfig().setLoadBackgroundImages(true);
    canvas.createLayout(dim);

    return canvas.getViewport();
}
 
开发者ID:radkovo,项目名称:SwingBox,代码行数:24,代码来源:DefaultAnalyzer.java


示例7: getBoxTree

import org.fit.cssbox.layout.BrowserCanvas; //导入依赖的package包/类
/**
 * This method initializes boxTree	
 * 	
 * @return javax.swing.JTree	
 */
private JTree getBoxTree()
{
    if (boxTree == null)
    {
        boxTree = new JTree();
        boxTree.setModel(new DefaultTreeModel(new DefaultMutableTreeNode("(box tree)")));
        boxTree.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener()
        {
            public void valueChanged(javax.swing.event.TreeSelectionEvent e)
            {
                DefaultMutableTreeNode node = (DefaultMutableTreeNode) boxTree.getLastSelectedPathComponent();
                if (node != null)
                {
                    Box box = (Box) node.getUserObject();
                    if (box != null)
                    {
                        box.drawExtent(((BrowserCanvas) contentCanvas).getImageGraphics());
                        contentCanvas.repaint();
                        displayBoxInfo(box);
                    }
                }
            }
        });
    }
    return boxTree;
}
 
开发者ID:mantlik,项目名称:swingbox-javahelp-viewer,代码行数:32,代码来源:BoxBrowser.java


示例8: locateBox

import org.fit.cssbox.layout.BrowserCanvas; //导入依赖的package包/类
/**
 * Locates a box from its position
 */
private Box locateBox(Box root, int x, int y)
{
    if (root.isVisible())
    {
        Box found = null;
        //Rectangle bounds = root.getAbsoluteContentBounds().intersection(root.getClipBlock().getAbsoluteContentBounds());
        Rectangle bounds = root.getAbsoluteBounds();
        if (bounds.contains(x, y))
        {
            found = root;
            System.out.println("Fnd: " + found);
            found.drawExtent(((BrowserCanvas)cssbox).getImageGraphics());
        }
        
        //find if there is something smallest that fits among the child boxes
        if (root instanceof ElementBox)
        {
            ElementBox eb = (ElementBox) root;
            for (int i = eb.getStartChild(); i < eb.getEndChild(); i++)
            {
                Box inside = locateBox(((ElementBox) root).getSubBox(i), x, y);
                if (inside != null)
                {
                    if (found == null)
                        found = inside;
                    else
                    {
                        if (inside.getAbsoluteBounds().width * inside.getAbsoluteBounds().height < found.getAbsoluteBounds().width * found.getAbsoluteBounds().height)
                            found = inside;
                    }
                }
            }
        }
        return found;
    }
    else
        return null;
}
 
开发者ID:mantlik,项目名称:swingbox-javahelp-viewer,代码行数:42,代码来源:BrowserComparison.java


示例9: initComponents

import org.fit.cssbox.layout.BrowserCanvas; //导入依赖的package包/类
/**
 * Creates and initializes the GUI components
 */
private void initComponents()
{
	documentScroll = new javax.swing.JScrollPane();
	documentScroll.getVerticalScrollBar().setUnitIncrement(16);
	browserCanvas = new BrowserCanvas(da.getRoot(), da, new java.awt.Dimension(1000, 750), url);
	getContentPane().setLayout(new java.awt.GridLayout(1, 0));
	
	setTitle("JSDOMBox Browser");
	setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	
	documentScroll.setViewportView(browserCanvas);
	getContentPane().add(documentScroll);
	pack();
}
 
开发者ID:rkocman,项目名称:JSDOMBox,代码行数:18,代码来源:SimpleExample.java


示例10: getContentScroll

import org.fit.cssbox.layout.BrowserCanvas; //导入依赖的package包/类
/**
 * This method initializes jScrollPane	
 * 	
 * @return javax.swing.JScrollPane	
 */
private JScrollPane getContentScroll()
{
    if (contentScroll == null)
    {
        contentScroll = new JScrollPane();
        contentScroll.setViewportView(getContentCanvas());
        contentScroll.addComponentListener(new java.awt.event.ComponentAdapter()
        {
            public void componentResized(java.awt.event.ComponentEvent e)
            {
                if (contentCanvas != null && contentCanvas instanceof BrowserCanvas)
                {
                    ((BrowserCanvas) contentCanvas).createLayout(contentScroll.getSize(), contentScroll.getViewport().getViewRect());
                    contentScroll.repaint();
                    //new box tree
                    root = createBoxTree(((BrowserCanvas) contentCanvas).getViewport());
                    boxTree.setModel(new DefaultTreeModel(root));
                }
            }
        });
        /*contentScroll.getViewport().addChangeListener(new javax.swing.event.ChangeListener()
        {
            public void stateChanged(ChangeEvent e)
            {
                if (contentCanvas != null && contentCanvas instanceof BrowserCanvas)
                {
                    ((BrowserCanvas) contentCanvas).updateVisibleArea(contentScroll.getViewport().getViewRect());
                    contentScroll.repaint();
                }
            }
        });*/
    }
    return contentScroll;
}
 
开发者ID:radkovo,项目名称:CSSBox,代码行数:40,代码来源:BoxBrowser.java


示例11: getBoxTree

import org.fit.cssbox.layout.BrowserCanvas; //导入依赖的package包/类
/**
 * This method initializes boxTree	
 * 	
 * @return javax.swing.JTree	
 */
private JTree getBoxTree()
{
    if (boxTree == null)
    {
        boxTree = new JTree();
        boxTree.setModel(new DefaultTreeModel(new DefaultMutableTreeNode("(box tree)")));
        boxTree.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener()
        {
            public void valueChanged(javax.swing.event.TreeSelectionEvent e)
            {
                DefaultMutableTreeNode node = (DefaultMutableTreeNode) boxTree.getLastSelectedPathComponent();
                if (node != null)
                {
                    Box box = (Box) node.getUserObject();
                    if (box != null)
                    {
                        box.drawExtent(((BrowserCanvas) contentCanvas).getImageGraphics());
                        contentCanvas.repaint();
                        displayBoxInfo(box);
                        
                        if (box.getNode() != null)
                        {
                            DefaultMutableTreeNode dt = locateObjectInTree(domRoot, box.getNode());
                            if (dt != null)
                            {
                                TreePath dselect = new TreePath(dt.getPath());
                                domTree.setSelectionPath(dselect);
                                domTree.expandPath(dselect);
                                domTree.scrollPathToVisible(dselect);
                            }
                        }
                    }
                }
            }
        });
    }
    return boxTree;
}
 
开发者ID:radkovo,项目名称:CSSBox,代码行数:44,代码来源:BoxBrowser.java


示例12: analyze

import org.fit.cssbox.layout.BrowserCanvas; //导入依赖的package包/类
@Override
  public Viewport analyze(DocumentSource d, Dimension dim)
          throws Exception
  {
  	@SuppressWarnings("resource")
InputStream is = (d != null)? d.getInputStream() : null;
  	
  	if (!(is instanceof DocumentInputStream)) {
  		return super.analyze(d, dim);
  	}
  	
  	DocumentInputStream dIs = (DocumentInputStream) is;
  	
  	w3cdoc = dIs.getDocument();
  	URL address = ((Html5DocumentImpl)w3cdoc).getAddress();
  	
      // Create the CSS analyzer
      DOMAnalyzer da = new DOMAnalyzer(w3cdoc, address);
      da.attributesToStyles();
      da.addStyleSheet(null, CSSNorm.stdStyleSheet(), DOMAnalyzer.Origin.AGENT);
      da.addStyleSheet(null, CSSNorm.userStyleSheet(), DOMAnalyzer.Origin.AGENT);
      da.getStyleSheets();
      
      BufferedImage tmpImg = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);
      canvas = new BrowserCanvas(da.getRoot(), da, address);
      canvas.setImage(tmpImg);
      canvas.getConfig().setLoadImages(true);
      canvas.getConfig().setLoadBackgroundImages(true);
      canvas.createLayout(dim);

      return canvas.getViewport();
  }
 
开发者ID:ITman1,项目名称:ScriptBox,代码行数:33,代码来源:ScriptAnalyzer.java


示例13: main

import org.fit.cssbox.layout.BrowserCanvas; //导入依赖的package包/类
/**
 * main method
 */
public static void main(String[] args)
{
    if (args.length != 1)
    {
        System.err.println("Usage: TextBoxes <url>");
        System.exit(0);
    }
    
    try {
        //Open the network connection 
        DocumentSource docSource = new DefaultDocumentSource(args[0]);
        
        //Parse the input document
        DOMSource parser = new DefaultDOMSource(docSource);
        Document doc = parser.parse();
        
        //Create the CSS analyzer
        DOMAnalyzer da = new DOMAnalyzer(doc, docSource.getURL());
        da.attributesToStyles(); //convert the HTML presentation attributes to inline styles
        da.addStyleSheet(null, CSSNorm.stdStyleSheet(), DOMAnalyzer.Origin.AGENT); //use the standard style sheet
        da.addStyleSheet(null, CSSNorm.userStyleSheet(), DOMAnalyzer.Origin.AGENT); //use the additional style sheet
        da.getStyleSheets(); //load the author style sheets
        
        //Create the browser canvas
        BrowserCanvas browser = new BrowserCanvas(da.getRoot(), da, docSource.getURL());
        //Disable the image loading
        browser.getConfig().setLoadImages(false);
        browser.getConfig().setLoadBackgroundImages(false);
        
        //Create the layout for 1000x600 pixels
        browser.createLayout(new java.awt.Dimension(1000, 600));
        
        //Display the result
        printTextBoxes(browser.getViewport());
        
        docSource.close();
        
    } catch (Exception e) {
        System.err.println("Error: "+e.getMessage());
        e.printStackTrace();
    }

}
 
开发者ID:mantlik,项目名称:swingbox-javahelp-viewer,代码行数:47,代码来源:TextBoxes.java


示例14: getBrowserCanvas

import org.fit.cssbox.layout.BrowserCanvas; //导入依赖的package包/类
public BrowserCanvas getBrowserCanvas()
{
    return (BrowserCanvas) contentCanvas;
}
 
开发者ID:mantlik,项目名称:swingbox-javahelp-viewer,代码行数:5,代码来源:BoxBrowser.java


示例15: renderURL

import org.fit.cssbox.layout.BrowserCanvas; //导入依赖的package包/类
/**
 * Renders the URL and prints the result to the specified output stream in the specified
 * format.
 * @param urlstring the source URL
 * @param out output stream
 * @param type output type
 * @return true in case of success, false otherwise
 * @throws SAXException 
 */
public boolean renderURL(String urlstring, OutputStream out, Type type, String pageFormat) throws IOException, SAXException
{
    if (!urlstring.startsWith("http:") &&
        !urlstring.startsWith("ftp:") &&
        !urlstring.startsWith("file:"))
            urlstring = "http://" + urlstring;
    
    //Open the network connection 
    DocumentSource docSource = new DefaultDocumentSource(urlstring);
  
    //Parse the input document
    DOMSource parser = new DefaultDOMSource(docSource);
    Document doc = parser.parse();
   
    //create the media specification
    MediaSpec media = new MediaSpec(mediaType);
    media.setDimensions(windowSize.width, windowSize.height);
    media.setDeviceDimensions(windowSize.width, windowSize.height);

    //Create the CSS analyzer
    DOMAnalyzer da = new DOMAnalyzer(doc, docSource.getURL());
    da.setMediaSpec(media);
    
    da.attributesToStyles(); //convert the HTML presentation attributes to inline styles
    da.addStyleSheet(null, CSSNorm.stdStyleSheet(), DOMAnalyzer.Origin.AGENT); //use the standard style sheet
    da.addStyleSheet(null, CSSNorm.userStyleSheet(), DOMAnalyzer.Origin.AGENT); //use the additional style sheet
    da.addStyleSheet(null, CSSNorm.formsStyleSheet(), DOMAnalyzer.Origin.AGENT); //render form fields using css
    da.getStyleSheets(); //load the author style sheets

    BrowserCanvas contentCanvas = new BrowserCanvas(da.getRoot(), da, docSource.getURL());
    contentCanvas.setAutoMediaUpdate(false); //we have a correct media specification, do not update
    contentCanvas.getConfig().setClipViewport(cropWindow);
    contentCanvas.getConfig().setLoadImages(loadImages);
    contentCanvas.getConfig().setLoadBackgroundImages(loadBackgroundImages);

    if (type == Type.PNG)
    {
        contentCanvas.createLayout(windowSize);
        ImageIO.write(contentCanvas.getImage(), "png", out);
    }
    else if (type == Type.SVG)
    {
        setDefaultFonts(contentCanvas.getConfig());
        contentCanvas.createLayout(windowSize);
        Writer w = new OutputStreamWriter(out, "utf-8");
        writeSVG(contentCanvas.getViewport(), w);
        w.close();
    }
    else if (type == Type.PDF)
    {
        setDefaultFonts(contentCanvas.getConfig());
        contentCanvas.createLayout(windowSize);
        writePDF(contentCanvas.getViewport(), out, pageFormat);
    }

    docSource.close();

    return true;
}
 
开发者ID:radkovo,项目名称:CSSBoxPdf,代码行数:69,代码来源:PdfImageRenderer.java


示例16: renderURL

import org.fit.cssbox.layout.BrowserCanvas; //导入依赖的package包/类
/**
 * Renders the URL and prints the result to the specified output stream in
 * the specified format.
 * 
 * @param urlstring
 *            the source URL
 * @param out
 *            output stream
 * @param type
 *            output type
 * @return true in case of success, false otherwise
 * @throws SAXException
 */
private boolean renderURL(URL urlstring, URL baseUrl, OutputStream out)
		throws IOException, SAXException {
	// Open the network connection
	DocumentSource docSource = new DefaultDocumentSource(urlstring);


	// Parse the input document
	DOMSource parser = new DefaultDOMSource(docSource);
	Document doc = parser.parse();

	// create the media specification
	MediaSpec media = new MediaSpec(mediaType);
	media.setDimensions(windowSize.width, windowSize.height);
	media.setDeviceDimensions(windowSize.width, windowSize.height);

	// Create the CSS analyzer
	DOMAnalyzer da = new DOMAnalyzer(doc, baseUrl);
	da.setMediaSpec(media);
	da.attributesToStyles(); // convert the HTML presentation attributes to
								// inline styles
	da.addStyleSheet(baseUrl, CSSNorm.stdStyleSheet(),
			DOMAnalyzer.Origin.AGENT); // use the standard style sheet
	da.addStyleSheet(null, CSSNorm.userStyleSheet(),
			DOMAnalyzer.Origin.AGENT); // use the additional style sheet
	da.addStyleSheet(null, CSSNorm.formsStyleSheet(),
			DOMAnalyzer.Origin.AGENT); // render form fields using css
	da.getStyleSheets(); // load the author style sheets

	BrowserCanvas contentCanvas = new BrowserCanvas(da.getRoot(), da,
			baseUrl);
	// contentCanvas.setAutoMediaUpdate(false); // we have a correct media
	// // specification, do not
	// // update
	contentCanvas.getConfig().setClipViewport(cropWindow);
	contentCanvas.getConfig().setLoadImages(loadImages);
	contentCanvas.getConfig().setLoadBackgroundImages(loadBackgroundImages);
	contentCanvas.setPreferredSize(new Dimension(windowSize.width, 10));
	contentCanvas.setAutoSizeUpdate(true);

	setDefaultFonts(contentCanvas.getConfig());

	contentCanvas.createLayout(windowSize);
	contentCanvas.validate();
	ImageIO.write(contentCanvas.getImage(), "png", out);

	// Image image = contentCanvas.createImage(windowSize.width,
	// windowSize.height);

	docSource.close();

	return true;
}
 
开发者ID:riccardove,项目名称:easyjasub,代码行数:66,代码来源:CssBoxPngRenderer.java


示例17: renderURL

import org.fit.cssbox.layout.BrowserCanvas; //导入依赖的package包/类
/**
 * Renders the URL and prints the result to the specified output stream in the specified
 * format.
 * @param urlstring the source URL
 * @param out output stream
 * @param type output type
 * @return true in case of success, false otherwise
 * @throws SAXException 
 */
public boolean renderURL(String urlstring, OutputStream out, Type type) throws IOException, SAXException
{
    if (!urlstring.startsWith("http:") &&
        !urlstring.startsWith("https:") &&
        !urlstring.startsWith("ftp:") &&
        !urlstring.startsWith("file:"))
            urlstring = "http://" + urlstring;
    
    //Open the network connection 
    DocumentSource docSource = new DefaultDocumentSource(urlstring);
    
    //Parse the input document
    DOMSource parser = new DefaultDOMSource(docSource);
    Document doc = parser.parse();
    
    //create the media specification
    MediaSpec media = new MediaSpec(mediaType);
    media.setDimensions(windowSize.width, windowSize.height);
    media.setDeviceDimensions(windowSize.width, windowSize.height);

    //Create the CSS analyzer
    DOMAnalyzer da = new DOMAnalyzer(doc, docSource.getURL());
    da.setMediaSpec(media);
    da.attributesToStyles(); //convert the HTML presentation attributes to inline styles
    da.addStyleSheet(null, CSSNorm.stdStyleSheet(), DOMAnalyzer.Origin.AGENT); //use the standard style sheet
    da.addStyleSheet(null, CSSNorm.userStyleSheet(), DOMAnalyzer.Origin.AGENT); //use the additional style sheet
    da.addStyleSheet(null, CSSNorm.formsStyleSheet(), DOMAnalyzer.Origin.AGENT); //render form fields using css
    da.getStyleSheets(); //load the author style sheets
    
    BrowserCanvas contentCanvas = new BrowserCanvas(da.getRoot(), da, docSource.getURL());
    contentCanvas.setAutoMediaUpdate(false); //we have a correct media specification, do not update
    contentCanvas.getConfig().setClipViewport(cropWindow);
    contentCanvas.getConfig().setLoadImages(loadImages);
    contentCanvas.getConfig().setLoadBackgroundImages(loadBackgroundImages);

    if (type == Type.PNG)
    {
        contentCanvas.createLayout(windowSize);
        ImageIO.write(contentCanvas.getImage(), "png", out);
    }
    else if (type == Type.SVG)
    {
        setDefaultFonts(contentCanvas.getConfig());
        contentCanvas.createLayout(windowSize);
        Writer w = new OutputStreamWriter(out, "utf-8");
        writeSVG(contentCanvas.getViewport(), w);
        w.close();
    }
    
    docSource.close();

    return true;
}
 
开发者ID:radkovo,项目名称:CSSBox,代码行数:63,代码来源:ImageRenderer.java


示例18: makeImage

import org.fit.cssbox.layout.BrowserCanvas; //导入依赖的package包/类
public BufferedImage makeImage(InputStream is, String urlstring , boolean loadImages, boolean loadBackgroundImages) throws IOException, SAXException {


        if (!urlstring.startsWith("http:") &&
                !urlstring.startsWith("ftp:") &&
                !urlstring.startsWith("file:"))
            urlstring = "http://" + urlstring;

        //Open the network connection
//; charset=utf-8
        DocumentSource docSource = new StreamDocumentSource(is, new URL(urlstring), "text/html; charset=utf-8");
//        DocumentSource docSource = new DefaultDocumentSource(urlstring);

        //Parse the input document
        DOMSource parser = new DefaultDOMSource(docSource);
        Document doc = parser.parse();

        //Create the CSS analyzer
        DOMAnalyzer da = new DOMAnalyzer(doc, docSource.getURL());
        da.attributesToStyles(); //convert the HTML presentation attributes to inline styles
        da.addStyleSheet(null, CSSNorm.stdStyleSheet(), DOMAnalyzer.Origin.AGENT); //use the standard style sheet
        da.addStyleSheet(null, CSSNorm.userStyleSheet(), DOMAnalyzer.Origin.AGENT); //use the additional style sheet
        da.addStyleSheet(null, CSSNorm.formsStyleSheet(), DOMAnalyzer.Origin.AGENT); //render form fields using css
        da.getStyleSheets(); //load the author style sheets



//        if (type == TYPE_PNG)
//        {

            BrowserCanvas contentCanvas = new BrowserCanvas(da.getRoot(), da, docSource.getURL());
            contentCanvas.getConfig().setLoadImages(loadImages);
            contentCanvas.getConfig().setLoadBackgroundImages(loadBackgroundImages);
            contentCanvas.createLayout(new java.awt.Dimension(384, 400));
            contentCanvas.setSize(384, 400);
            contentCanvas.setAutoSizeUpdate(false);

            BufferedImage image = contentCanvas.getImage();

//            ImageIO.write(contentCanvas.getImage(), "png", out);

        docSource.close();

//        BufferedImage image = ImageIO.read(new File("stronka.png"));

        int lastYNotWhite = 0;

        for (int yPixel = 0; yPixel < image.getHeight(); yPixel++) {
            for (int xPixel = 0; xPixel < image.getWidth(); xPixel++) {
                int color = image.getRGB(xPixel, yPixel);
                if(color != -328966 && color != Color.WHITE.getRGB()) {  // white?
                    lastYNotWhite = yPixel;
                }
            }
        }

        BufferedImage dest = image.getSubimage(0, 0, 384, lastYNotWhite + 1);
        ImageIO.write(dest, "png", new File("test-result-" + cnt + ".png"));
        cnt++;

        return dest;

//        }
//        else if (type == TYPE_SVG)
//        {
//            BrowserCanvas contentCanvas = new BrowserCanvas(da.getRoot(), da, docSource.getURL());
//            contentCanvas.getConfig().setLoadImages(loadImages);
//            contentCanvas.getConfig().setLoadBackgroundImages(loadBackgroundImages);
//            setDefaultFonts(contentCanvas.getConfig());
//            contentCanvas.createLayout(new java.awt.Dimension(1200, 600));
//            Writer w = new OutputStreamWriter(out, "utf-8");
//            writeSVG(contentCanvas.getViewport(), w);
//            w.close();
//        }



//        return true;
    }
 
开发者ID:2bajty,项目名称:mirkodrukarka,代码行数:80,代码来源:Browser.java



注:本文中的org.fit.cssbox.layout.BrowserCanvas类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java AnnotationSessionFactoryBean类代码示例发布时间:2022-05-22
下一篇:
Java SearchParameters类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap