当前位置: 首页>>代码示例>>Java>>正文


Java DOMAnalyzer.setMediaSpec方法代码示例

本文整理汇总了Java中org.fit.cssbox.css.DOMAnalyzer.setMediaSpec方法的典型用法代码示例。如果您正苦于以下问题:Java DOMAnalyzer.setMediaSpec方法的具体用法?Java DOMAnalyzer.setMediaSpec怎么用?Java DOMAnalyzer.setMediaSpec使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.fit.cssbox.css.DOMAnalyzer的用法示例。


在下文中一共展示了DOMAnalyzer.setMediaSpec方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: renderDocument

import org.fit.cssbox.css.DOMAnalyzer; //导入方法依赖的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

示例2: renderURL

import org.fit.cssbox.css.DOMAnalyzer; //导入方法依赖的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

示例3: renderURL

import org.fit.cssbox.css.DOMAnalyzer; //导入方法依赖的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

示例4: renderURL

import org.fit.cssbox.css.DOMAnalyzer; //导入方法依赖的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


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