Git Product home page Git Product logo

radkovo / cssbox Goto Github PK

View Code? Open in Web Editor NEW
232.0 232.0 80.0 5.04 MB

CSSBox is an (X)HTML/CSS rendering engine written in pure Java. Its primary purpose is to provide a complete information about the rendered page suitable for further processing. However, it also allows displaying the rendered document.

Home Page: http://cssbox.sourceforge.net/

License: GNU Lesser General Public License v3.0

Java 99.41% Shell 0.04% CSS 0.55%

cssbox's People

Contributors

czaurel avatar dbmalkovsky avatar dependabot[bot] avatar huangyifu avatar janzeleny avatar jebailey avatar radkovo avatar s-n-ushakov avatar soundasleep avatar xchoch07 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cssbox's Issues

DefaultDOMSource Document#getElementById() doesn't work

I found that if you try to load a Document via DefaultDOMSource, #getElementById() always returns null.

As far as I can tell, this is because cssbox is using NekoHTML as its XML parser, and it's not set up to be a validating parser, and Xerces is the underlying parser, that requires it to be a validating parser in order for id="..." to work . I think?

However I did find a fix on sourceforge by adding a custom filter to NekoHTML:

    @Override
    public Document parse() throws SAXException, IOException
    {
        //temporay NekoHTML fix until nekohtml gets fixed
        if (!neko_fixed)
        {
            HTMLElements.Element li = HTMLElements.getElement(HTMLElements.LI);
            HTMLElements.Element[] oldparents = li.parent;
            li.parent = new HTMLElements.Element[oldparents.length + 1];
            for (int i = 0; i < oldparents.length; i++)
                li.parent[i] = oldparents[i];
            li.parent[oldparents.length] = HTMLElements.getElement(HTMLElements.MENU);
            neko_fixed = true;
        }
        
        // start tweak
        HTMLConfiguration config = new HTMLConfiguration();
        XMLDocumentFilter idEnhancer = new DefaultFilter() {
            @Override
            public void startElement(QName element, XMLAttributes attributes, Augmentations augs) throws XNIException {
                int idx = attributes.getIndex("id");
                if (idx > -1) {
                    attributes.setType(idx, "ID");
                    Augmentations attrsAugs = attributes.getAugmentations(idx);
                    attrsAugs.putItem(Constants.ATTRIBUTE_DECLARED, Boolean.TRUE);
                }
                super.startElement(element, attributes, augs);
            }
        };
        XMLDocumentFilter[] filters = { idEnhancer };
        config.setProperty("http://cyberneko.org/html/properties/filters", filters);
        // end tweak
        
        DOMParser parser = new DOMParser(config);
        parser.setProperty("http://cyberneko.org/html/properties/names/elems", "lower");
        if (charset != null)
            parser.setProperty("http://cyberneko.org/html/properties/default-encoding", charset);
        parser.parse(new org.xml.sax.InputSource(getDocumentSource().getInputStream()));
        return parser.getDocument();
    }

I think this could be added to DefaultDOMSource, or HTMLConfiguration, but I'd imagine you'd want to add test cases as well, and I'm not sure what the implications of this might be.

InlineBox vs. Blockbox in 4.17 -> no more rendering possible

Version 4.17 can no longer render any of our html parts, whereas Version 4.16 rendered everything.

This might be an older issue that went into the code again, - seems quite similar to #47

org.fit.cssbox.layout.InlineBox cannot be cast to org.fit.cssbox.layout.BlockBox: java.lang.ClassCastException: org.fit.cssbox.layout.InlineBox cannot be cast to org.fit.cssbox.layout.BlockBox
at org.fit.cssbox.layout.BlockBox.computeEfficientMargins(BlockBox.java:756) [cssbox-4.17.jar:]
at org.fit.cssbox.layout.ElementBox.initSubtree(ElementBox.java:295) [cssbox-4.17.jar:]
at org.fit.cssbox.layout.Viewport.initSubtree(Viewport.java:145) [cssbox-4.17.jar:]

SSL Conection HTTPS

Hi, I had a problem with HTTPS , for generating images, I solved this problem, but do not know if it affects other parts of the API, I can submit the code to contribute?

Nested tags (with inline styles) don't work for styles with text-decoration

It seems that having nested (nonblock)tags (like "span") with inline style information, where the outer block has a "text-decoration: underline" for example, and an inner block having any other style like "font-weight: bold", the inner block overwrites the outer blocks text-decoration style with "text-decoration: none"

For Example (does not work):
<div class="whatever"><span style="text-decoration: underline;">AAA<span style="font-weight: bold;">TEST TEST TEST</span></span></div>
Here only the first word is underlined, the TEST words are only bold

<div class="whatever"><span style="text-decoration: underline;"><span style="font-weight: bold;">TEST TEST TEST</span></span></div>
Here the TEST words are only bold

but this works:
<div class="whatever"><span style="font-weight: bold;">AAA<span style="text-decoration: underline;">TEST TEST TEST</span></span></div>
Here ALL words are bold, and the TEST words are also underlined

<div class="whatever"><span style="font-weight: bold;"><span style="text-decoration: underline;">TEST TEST TEST</span></span></div>
Here ALL words are bold and underlined

I'd also like to mention that this happens when the styles are defined via short/old notation:
WRONG RESULT: <div class="whatever"><u>AAA<b>TEST TEST TEST</b></u></div>
WRONG RESULT: <div class="whatever"><u><b>TEST TEST TEST</b></u></div>
CORRECT RESULT: <div class="whatever"><b>AAA<u>TEST TEST TEST</u></b></div>
CORRECT RESULT: <div class="whatever"><b><u>TEST TEST TEST</u></b></div>

NullPointerException for some urls

Hello,
I'm getting NullPointerException during processing of some urls. Unfortunately I don't have any free example of such urls.

java.lang.NullPointerException: null
    at cz.vutbr.web.csskit.antlr.CSSInputStream.urlStream(CSSInputStream.java:86) ~[jstyleparser-1.21.jar:na]
    at cz.vutbr.web.csskit.antlr.CSSInputStream.setEncoding(CSSInputStream.java:253) ~[jstyleparser-1.21.jar:na]
    at cz.vutbr.web.csskit.antlr.DefaultCSSLexer_CSSLexer.mCHARSET(DefaultCSSLexer_CSSLexer.java:340) ~[jstyleparser-1.21.jar:na]
    at cz.vutbr.web.csskit.antlr.DefaultCSSLexer_CSSLexer.mTokens(DefaultCSSLexer_CSSLexer.java:3896) ~[jstyleparser-1.21.jar:na]
    at cz.vutbr.web.csskit.antlr.CSSTokenRecovery.nextToken(CSSTokenRecovery.java:127) ~[jstyleparser-1.21.jar:na]
    at cz.vutbr.web.csskit.antlr.DefaultCSSLexer.nextToken(DefaultCSSLexer.java:130) ~[jstyleparser-1.21.jar:na]
    at org.antlr.runtime.BufferedTokenStream.fetch(BufferedTokenStream.java:143) ~[antlr-runtime-3.5.2.jar:3.5.2]
    at org.antlr.runtime.BufferedTokenStream.sync(BufferedTokenStream.java:137) ~[antlr-runtime-3.5.2.jar:3.5.2]
    at org.antlr.runtime.CommonTokenStream.setup(CommonTokenStream.java:137) ~[antlr-runtime-3.5.2.jar:3.5.2]
    at org.antlr.runtime.CommonTokenStream.LT(CommonTokenStream.java:94) ~[antlr-runtime-3.5.2.jar:3.5.2]
    at cz.vutbr.web.csskit.antlr.DefaultCSSParser_CSSParser.stylesheet(DefaultCSSParser_CSSParser.java:486) ~[jstyleparser-1.21.jar:na]
    at cz.vutbr.web.csskit.antlr.DefaultCSSParser.stylesheet(DefaultCSSParser.java:253) ~[jstyleparser-1.21.jar:na]
    at cz.vutbr.web.csskit.antlr.CSSParserFactory.getAST(CSSParserFactory.java:99) [jstyleparser-1.21.jar:na]
    at cz.vutbr.web.csskit.antlr.CSSParserFactory.feedParser(CSSParserFactory.java:382) [jstyleparser-1.21.jar:na]
    at cz.vutbr.web.csskit.antlr.CSSParserFactory.createTreeParser(CSSParserFactory.java:349) [jstyleparser-1.21.jar:na]
    at cz.vutbr.web.csskit.antlr.CSSParserFactory.parseAndImport(CSSParserFactory.java:306) [jstyleparser-1.21.jar:na]
    at cz.vutbr.web.csskit.antlr.CSSParserFactory.append(CSSParserFactory.java:264) [jstyleparser-1.21.jar:na]
    at cz.vutbr.web.csskit.antlr.CSSParserFactory.append(CSSParserFactory.java:295) [jstyleparser-1.21.jar:na]
    at cz.vutbr.web.css.CSSFactory$CSSAssignTraversal.processNode(CSSFactory.java:775) [jstyleparser-1.21.jar:na]
    at cz.vutbr.web.css.CSSFactory$CSSAssignTraversal.processNode(CSSFactory.java:744) [jstyleparser-1.21.jar:na]
    at cz.vutbr.web.domassign.Traversal.listTraversal(Traversal.java:43) [jstyleparser-1.21.jar:na]
    at cz.vutbr.web.css.CSSFactory.getUsedStyles(CSSFactory.java:532) [jstyleparser-1.21.jar:na]
    at cz.vutbr.web.css.CSSFactory.getUsedStyles(CSSFactory.java:552) [jstyleparser-1.21.jar:na]
    at org.fit.cssbox.css.DOMAnalyzer.getStyleSheets(DOMAnalyzer.java:382) [cssbox-4.10.jar:na]
    at org.fit.cssbox.css.DOMAnalyzer.getStyleSheets(DOMAnalyzer.java:394) [cssbox-4.10.jar:na]

Text containing &lt; or &gt; are decoded to < or > symbols when parsed

Hi @radkovo ,

We are using CSSBox DOM parser for parsing the HTML source, here is the implementation:

try (DocumentSource docSource = new StreamDocumentSource(JAFIOUtils.toInputStream(htmlSource),
null, "text/html;charset=UTF-8")) {
LOGGER.error("Before parse "+htmlSource);
// Parse the input document
DOMSource parser = new DefaultDOMSource(docSource);
Document doc = parser.parse();
LOGGER.error("After parse "+doc.getFirstChild().getTextContent());
}

For example lets consider the input source or htmlSource is <style></style>Test User &lt;[email protected]&gt;
After parsing the output will be Test User <[email protected]>.

Here the text content which contains email field enclosed with &lt; and &gt; are decoded to < and >, but as per our requirement, the parser should not decode &lt; and &gt; to < and >.

How to retain the text as it is without decoding or encoding text in this case, @radkovo could you please provide the solution for this issue?

Double draw

createStrokedShape(... and sideShape(xxx on class CSSStroke creates a thick border because we are using a rectangle on else statement instead of a line.

Width and Padding

Hi,

I think I found issue in the calculations of boxs width.

In BlockBox.java line 2037, you get the content width:
content.width = dec.getLength(width, auto, 0, 0, contw);

That value includes the padding, so when using totalWidth in ElementBox.java line 814:
public int totalWidth() { return emargin.left + border.left + padding.left + content.width + padding.right + border.right + emargin.right; }

So the padding is calculated twice.

not properly closed connection/file?

I have some "cannot delete file" problems on Windows when using DefaultDocumentSource against local files. That problem disappears when reading the source using a try-with-resources construct myself.

I think the problem is due to the fact that the result of getInputStream() in the following source code line

parser.parse(new org.xml.sax.InputSource(getDocumentSource().getInputStream()));

does not get stored and thereby cannot be closed explicitly/in time.

Elements with display: none should not affect the layout of other elements

Given the following HTML:

<!DOCTYPE html>
<html>
<head>
  <link rel="stylesheet" href="base.css">
</head>
<body>
  <label type="toggle-button">
    <input type="radio" name="elementx">
    Hello
  </label>
</body>
</html>

And the following CSS:

label[type="toggle-button"] {
  border: 1px solid white;
  color: white;
  display: inline-block;
  margin: 0;
  padding: 16px;
}

label[type="toggle-button"] > input[type="radio"] {
    display: none;
}

The <input> should not be displayed (and thus not affecting the layout of the parent <label>), but it seems to be affecting layout:

image

In fact you can change the properties of the display: none; input, for example:

label[type="toggle-button"] > input[type="radio"] {
    display: none;
    padding: 64px;
    margin: 64px;
}

This renders as:

image

(This might be an issue in jStyleParser, not sure)

EDIT: An ugly workaround is to set the margin/padding to negative values:

label[type="toggle-button"] > input[type="radio"] {
    display: none;
    padding: -10px;
    margin: -10px;
}

can't see iframes as Boxes

Hi
when i was using css box to render html page. can't see iframes in boxes.
is there any ways i create iframe element boxes

DOMAnalyzer.localizeStyles does not support Media

Expected behavior when localizing the style sheets is that the the Media queries that are currently meeting the media specification would be inserted as part of the localization. What's occurring is that during the localization, the iteration is checking to determine if the item in the stylesheet is an instanceof RuleSet. Media queries are defined as a RuleMediaImpl instance and are not being added.

Register custom fonts from font-face rules with AWT

AFAIK, the @font-face rules are only parsed but not used for actually doing anything with the font files. A basic implementation, which uses the font-family and src parts to call GraphicsEnvironment.registerFont could be pretty useful for using custom TTFs.

sequence number (letter) at ordered list gone while using custom css

I'm trying to render next HTML page using latest ver. of CSSBox 4.13 and ImageRenderer class:

<head>
<link rel="stylesheet" type="text/css" href="quill.snow.css">
</head>
<body class="ql-editor">
<ol><li><strong>Heres text one - test one </strong></li><li class="ql-indent-1">One</li><li><strong>Heres text two - test one </strong></li><li class="ql-indent-1">Two</li></ol>
</body>

Where quill.snow.css - https://cdn.quilljs.com/1.0.0/quill.snow.css (from https://github.com/quilljs/quill)

And sequence number or letter in my ordered list just gone. Here's image from Chrome and CSSBox output: https://goo.gl/cMTAAA

It's probably problem of CSS parser, but how I can fix it? Do someone have any clue?

NPE when browsing to ACID2 test

URL

http://www.webstandards.org/files/acid2/test.html

Stack trace

java.lang.NullPointerException
    at org.fit.cssbox.layout.HTMLBoxFactory.createSubtreeObject(HTMLBoxFactory.java:173)
    at org.fit.cssbox.layout.HTMLBoxFactory.createBox(HTMLBoxFactory.java:99)
    at org.fit.cssbox.layout.BoxFactory.createBox(BoxFactory.java:734)
    at org.fit.cssbox.layout.BoxFactory.createElementBox(BoxFactory.java:447)
    at org.fit.cssbox.layout.BoxFactory.createSubtree(BoxFactory.java:263)
    at org.fit.cssbox.layout.BoxFactory.createBoxTree(BoxFactory.java:213)
    at org.fit.cssbox.layout.BoxFactory.createSubtree(BoxFactory.java:309)
    at org.fit.cssbox.layout.BoxFactory.createBoxTree(BoxFactory.java:213)
    at org.fit.cssbox.layout.BoxFactory.createSubtree(BoxFactory.java:304)
    at org.fit.cssbox.layout.BoxFactory.createBoxTree(BoxFactory.java:213)
    at org.fit.cssbox.layout.BoxFactory.createSubtree(BoxFactory.java:304)
    at org.fit.cssbox.layout.BoxFactory.createBoxTree(BoxFactory.java:213)
    at org.fit.cssbox.layout.BoxFactory.createSubtree(BoxFactory.java:304)
    at org.fit.cssbox.layout.BoxFactory.createBoxTree(BoxFactory.java:213)
    at org.fit.cssbox.layout.BoxFactory.createSubtree(BoxFactory.java:304)
    at org.fit.cssbox.layout.BoxFactory.createBoxTree(BoxFactory.java:213)
    at org.fit.cssbox.layout.BoxFactory.createSubtree(BoxFactory.java:304)
    at org.fit.cssbox.layout.BoxFactory.createBoxTree(BoxFactory.java:213)
    at org.fit.cssbox.layout.BoxFactory.createSubtree(BoxFactory.java:304)
    at org.fit.cssbox.layout.BoxFactory.createViewportTree(BoxFactory.java:169)
    at org.fit.cssbox.layout.BrowserCanvas.createLayout(BrowserCanvas.java:169)
    at org.fit.cssbox.demo.BoxBrowser.displayURL(BoxBrowser.java:169)
    at org.fit.cssbox.demo.BoxBrowser$4.actionPerformed(BoxBrowser.java:700)
    at javax.swing.JTextField.fireActionPerformed(JTextField.java:508)
    at javax.swing.JTextField.postActionEvent(JTextField.java:721)
    at javax.swing.JTextField$NotifyAction.actionPerformed(JTextField.java:836)
    at javax.swing.SwingUtilities.notifyAction(SwingUtilities.java:1663)
    at javax.swing.JComponent.processKeyBinding(JComponent.java:2882)
    at javax.swing.JComponent.processKeyBindings(JComponent.java:2929)
    at javax.swing.JComponent.processKeyEvent(JComponent.java:2845)
    at java.awt.Component.processEvent(Component.java:6302)
    at java.awt.Container.processEvent(Container.java:2234)
    at java.awt.Component.dispatchEventImpl(Component.java:4881)
    at java.awt.Container.dispatchEventImpl(Container.java:2292)
    at java.awt.Component.dispatchEvent(Component.java:4703)
    at java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1954)
    at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(DefaultKeyboardFocusManager.java:806)
    at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(DefaultKeyboardFocusManager.java:1074)
    at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:945)
    at java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:771)
    at java.awt.Component.dispatchEventImpl(Component.java:4752)
    at java.awt.Container.dispatchEventImpl(Container.java:2292)
    at java.awt.Window.dispatchEventImpl(Window.java:2750)
    at java.awt.Component.dispatchEvent(Component.java:4703)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
    at java.awt.EventQueue.access$500(EventQueue.java:97)
    at java.awt.EventQueue$3.run(EventQueue.java:709)
    at java.awt.EventQueue$3.run(EventQueue.java:703)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:86)
    at java.awt.EventQueue$4.run(EventQueue.java:731)
    at java.awt.EventQueue$4.run(EventQueue.java:729)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

InlineBox mistook as BlockBox

here is a stack dump:

Exception in thread "main" java.lang.ClassCastException: org.fit.cssbox.layout.InlineBox cannot be cast to org.fit.cssbox.layout.BlockBox
at org.fit.cssbox.layout.BlockBox.computeEfficientMargins(BlockBox.java:749)
at org.fit.cssbox.layout.ElementBox.initSubtree(ElementBox.java:295)
at org.fit.cssbox.layout.Viewport.initSubtree(Viewport.java:145)
at org.fit.cssbox.layout.BrowserCanvas.createLayout(BrowserCanvas.java:172)
at org.fit.cssbox.layout.BrowserCanvas.createLayout(BrowserCanvas.java:142)

"content" with escapes in pseudo-element does not render correctly

Not sure if this is a bug in CSSBox or jStyleParser. If a pseudoelement uses CSS unicode escapes in a content declaration, the escapes are written verbatim to the output. This is a problem that specifically affects the fontawesome stylesheet.

Repro:

<style>
.foo::before {
    content: "\0040";
}
</style>
<span class="foo">yo</span>

Expected:

"@yo"

Actual:

"\0040yo"

Rendering at a higher resolution

I'm using CSSBox to render some HTML/CSS to PNGs and would like to render at double the resolution for higher resolution displays (i.e. Retina).

I've looked through the docs and haven't found anything obvious to allow this, but maybe I'm overlooking something. The only option I've found so far is to change all sizes to ems (rems don't seem to work) and set the body font-size to double.

Warnings being issued by CSSBox

I am using CSSBox but I am seeing the warnings in my log which are originating out of CSSBox

msg: Unable to find method for property azimuth
msg: Unable to find method for property cue-after
msg: Unable to find method for property cue-after
msg: Unable to find method for property page-break.
category: cz.vutbr.web.domassign.DeclarationTransformer

I searched my codebase for the class DeclarationTransformer. I found that my code uses CSSBox and CSSBox uses DeclrationTransformer.

Can you please let me know how can I stop these warnings because they are flooding my logs.

DomParser crashes on null pointer exception

Hello,

First of all, I want to say thanks for developing such a great tool, I really enjoy using your tool. However, I encounter an issue, that I didn't find an answer yet. Basically, the rendering of some pages lead to a null pointer exception.

For instance, if you use the BoxBrowser demo, available in the project, and pass it a stackoverflow url, for instance:

https://stackoverflow.com/questions/42728417/qquickview-content-not-resizing-properly

this leads to the following error:

*** Error: null
java.lang.NullPointerException
at org.fit.cssbox.layout.ElementBox.getAbsoluteContentX(ElementBox.java:823)
at org.fit.cssbox.layout.Box.getAbsoluteContentBounds(Box.java:647)
at org.fit.cssbox.layout.BlockBox.updateStaticPosition(BlockBox.java:1487)
at org.fit.cssbox.layout.BlockBox.absolutePositions(BlockBox.java:1396)
at org.fit.cssbox.layout.Viewport.absolutePositionsChildren(Viewport.java:440)
at org.fit.cssbox.layout.Viewport.updateBounds(Viewport.java:374)
at org.fit.cssbox.layout.BrowserCanvas.createLayout(BrowserCanvas.java:181)
at org.fit.cssbox.demo.BoxBrowser.displayURL(BoxBrowser.java:167)
at org.fit.cssbox.demo.BoxBrowser$5.actionPerformed(BoxBrowser.java:712)
at java.desktop/javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1967)
at java.desktop/javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2308)
at java.desktop/javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:405)
at java.desktop/javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:262)
at java.desktop/javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:279)
at java.desktop/java.awt.Component.processMouseEvent(Component.java:6635)
at java.desktop/javax.swing.JComponent.processMouseEvent(JComponent.java:3342)
at java.desktop/java.awt.Component.processEvent(Component.java:6400)
at java.desktop/java.awt.Container.processEvent(Container.java:2263)
at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:5011)
at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2321)
at java.desktop/java.awt.Component.dispatchEvent(Component.java:4843)
at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4918)
at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Container.java:4547)
at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Container.java:4488)
at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2307)
at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2772)
at java.desktop/java.awt.Component.dispatchEvent(Component.java:4843)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:772)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:95)
at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:745)
at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:743)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:742)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)

Is there a simple reason for this behavior or did I discover a bug?

Thanks a lot

Examples do not work

Hi,

I think this issue is most likely of my own problem, but I just could not figure it out. I downloaded the latest stable version 4.15, and then headed to run examples first, but the SimpleBrowser example gave me a blank window whatever the url I feed it (a screenshot is attached below), and the ImageRenderer also produced blank image. I first ran the examples with Java SE 12, and then switched to Java SE 7, but didn't get any better. I believe I have missed some important steps in running the codes as I am a Java newbie, but I couldn't make it out. Would very appreciate if someone could shed a light.

Screenshot from 2019-05-30 16-31-50

Thanks!

Image Caching in Failed URLs

Hello, I have identified an Issue with the Failed URL caching. I would like to contribute to fix this issue.

The Failed URLs are stored in a cache, if an exception occurs or if the image is null it is stored in the Failed URL cache. Lets assume that there was a network error and an exception occurred. So the URL will be stored in the cache. If we try to get the image again when there are no network errors, the URL will be ignored by the ContentImage because its in the failed URL cache.

But at this moment what should happen is the image should be loaded from the source without being ignored and the image should be returned.

My Solution is simple. I simply removed the Failed URL cache. Storing failed URLs is not a good idea as it can ignore an image being loaded from the source when the image is retrievable.

I also used Google Guava Cache as it's a good caching technology.

I would like to contribute to fix this issue.

support @media for responsive html

CSSBox could be the perfect tool for inlining css which is required for proper email formatting. Only problem is that all the settings I have tried seem to strip out the @media queries which need to be left in for responsive because client is unknown. Is it possible to achieve something where the @media is left in the body style tag?

...
 <body style="...">
    <style type="text/css">
          @media only screen and (max-width: 596px) {
                 .small-float-center {
                      margin: 0 auto !important; float: none !important; text-align: center !important;
                  }
          }
     </style>
      ...

Slow BoxFactory

Hi

I am using CSSBox for extracting info about size/positions of html elements on websites. For that purpose, I am using BoxFactory class but it is very slow. It takes around 2-3 second to generate Viewport for pages that does not have so much content. For example:
https://www.pracuj.pl/praca/senior-data-specialist-krakow,oferta,6303360 - takes around 4-5 seconds to generate Viewport.

Is there any way to make it faster?

` public static void main(String[] args) throws IOException, SAXException {

    String url = "https://www.pracuj.pl/praca/senior-data-specialist-krakow,oferta,6303360";


    Instant start = Instant.now();
    DocumentSource docSource = new DefaultDocumentSource(url);
    DOMSource parser = new DefaultDOMSource(docSource);
    Document doc = parser.parse();

    Instant finish = Instant.now();
    System.out.println("Parser " + (Duration.between(finish, start).toMillis()));

    start = Instant.now();
    DOMAnalyzer da = new DOMAnalyzer(doc, docSource.getURL());
    da.attributesToStyles();
    da.addStyleSheet((URL) null, CSSNorm.stdStyleSheet(), DOMAnalyzer.Origin.AGENT);
    da.addStyleSheet((URL) null, CSSNorm.userStyleSheet(), DOMAnalyzer.Origin.AGENT);
    da.getStyleSheets();
    finish = Instant.now();
    System.out.println("Styles " + (Duration.between(finish, start).toMillis()));


    start = Instant.now();
    BoxFactory boxFactory = new BoxFactory(da, docSource.getURL());
    BrowserConfig config = new BrowserConfig();
    config.setLoadBackgroundImages(false);
    config.setLoadImages(false);
    boxFactory.setConfig(config);
    boxFactory.reset();
    finish = Instant.now();
    System.out.println("Factory init " + (Duration.between(finish, start).toMillis()));

    VisualContext ctx = new VisualContext(null, boxFactory);
    start = Instant.now();

    Viewport viewport = boxFactory.createViewportTree(da.getRoot(), new BufferedImage(1000, 600, 1).createGraphics(), ctx, 1000, 600);

    finish = Instant.now();
    System.out.println("Factory run " + (Duration.between(finish, start).toMillis()));

    viewport.initSubtree();
    viewport.doLayout(600, true, true);


}`

Thanks.

NormalOutput should encode text node value

I encounter problem while inlining css. The html mail content contents html tags, such as all html document should starts <html> tag.
NormalOutput print plain node value without encode html tag, it breaks the whole html document structure.

I saw the source code between line 111 to 114.

   else if (n.getNodeType() == Node.TEXT_NODE)
        {
            p.print(n.getNodeValue());
        }

The background-image from style is not draw.

When i try to draw this template:
String template = "<!DOCTYPE html>" + "<html>" + " <head> " + " <meta charset=\"UTF-8\">" + " <style type=\"text/css\">" + " .bordered {" + " border: 2px solid #73AD21;" + " padding: 20px;" + " width: 1000px; " + " height: 1000px;" + " background-color: red;" + " overflow: hidden;" + " background-image: url(http://pngimg.com/uploads/scratches/scratches_PNG6173.png);" + " }" + " </style>" + " </head>" + " <body>" + " <div class=\"bordered\">" + " Test text" + " </div>" + " </body>" + "</html>";
the background image isnt draw.
This result is repeated regardless of the type and other parameters of the image.
My version is to investigate in the direction that in the class BackgroundImage: 137 it turns out to be clipped.width = 0.

Update Layout without creating from scratch

Hi,
There is a way to update layout (recalculate boxes position/size when viewport is resized for example), without creating layout from scratch? Usually CSS styles and fonts doesn't change, so (for example) creating a VisualContext every time size is changed it seems a little expensive for me.

Another question related to this one: could I recalculate only a "part" of document tree? Just a subtree for example?

Thanks

SVG output for HTML/CSS

Hi,

We are trying to render an SVG image from HTML/CSS.
The CSS has border radius (border-radius: 2px;) and some mixed relative/absolute positioning.
The outcome is not satisfying unfortunately.

I can share with you the CSS, HTML and rendered SVG, perhaps somewhere else than on github if you are interested to see what comes out.

It seems, some CSS is not recognised, or perhaps wrongly applied.

Thanks for you work,
Cheers Christophe

no fontmanager in java.library.path

err info : Handler dispatch failed; nested exception is java.lang.UnsatisfiedLinkError: no fontmanager in java.library.path

im run cssbox centos has this info, but i run in the mac os hasn't this problem, this why?

4.13 version margins looks bad on simple template

For example this will looks ok in 4.12:

<!DOCTYPE html>
<html lang="en">
  <body>
    <div>
      <img src="{Some image url}"/>
    </div>
  </body>
</html>

But on 4.13 we get black margins on the right, botom and a little bit on the top and left.

Incorrectly getting src attribute in HTMLBoxFactory::createSubtreeImg

Hi!

I'm having some issues with an image embedded in the HTML as a Base64 string, such as:

<img src="data:image/gif;base64,/9j/4AAQSkZJRgA+BAQ.........>

This line in HTMLBoxFactory::createSubtreeImg:

src = URLDecoder.decode(HTMLNorm.getAttribute(e, "src"), "UTF-8");

Will transform all '+' characters in the Base64 string into whitespaces, therefore making it incorrect for posterior decoding.

This issue is related to commit: 4c26b6f.

Thank you!

Dose not support "letter-spacing"?

i read that use jStyleParser..
this can support css2.1
but,when i try use CSSBOX through an HTML string create a picture,it cant's work...
'letter-spacing' not properly rendered...
What should I do?

data: url

Hi,

I'm wondering why the data: url is excluded from ImageRenderer. It seems to work okay for html to png conversions.

from renderURL:

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

http://www.phpied.com/data-urls-what-are-they-and-how-to-use/

Regards,

Lori

Upgrade CSSbox to use active NekoHTML?

It seems that CssBox is set up to use nekohtml 1.9.22, of which development seems to have ceased in 2015.

Nekohtml has since been forked into a new project https://github.com/HtmlUnit/htmlunit-neko which has active development (2.59.0 was released 14 days ago).

Is there any appetite for upgrading Cssbox to use the newer nekohtml?

Alternatively is there a way to configure a local installation to use this nekohtml instead?

(I ask because I'm hitting some weird bugs that I think are due to nekohtml's parsing.)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.