Changeset 713


Ignore:
Timestamp:
01/16/14 16:23:39 (10 years ago)
Author:
ngw8
Message:

Web parser now creates Expeditee rectangles for elements that have a background colour

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/io/WebParser.java

    r701 r713  
    33import java.awt.Color;
    44import java.awt.Font;
     5import java.awt.FontMetrics;
    56import java.awt.image.BufferedImage;
    67import java.io.File;
     
    243244                                                                );
    244245
    245                                                 WebParser.addPageToFrame(doc, null, window, webEngine, frame);
     246                                                WebParser.addPageToFrame(doc, window, webEngine, frame);
    246247
    247248                                                progressBar.set(100);
     
    308309         * @throws IllegalAccessException
    309310         */
    310         private static void addPageToFrame(Node rootElement, Color parentBgColor, Object window, Object webEngine, Frame frame) throws InvocationTargetException, IllegalAccessException,
     311        private static void addPageToFrame(Node rootElement, Object window, Object webEngine, Frame frame) throws InvocationTargetException, IllegalAccessException,
    311312                        IllegalArgumentException {
    312313               
    313314                Node currentNode = rootElement;
    314 
    315                 Color bgColor = null;
    316315
    317316                if (currentNode.getNodeType() == Node.TEXT_NODE || currentNode.getNodeType() == Node.ELEMENT_NODE) {
     
    343342                        float height = Float.valueOf(JavaFX.JSObjectGetMember.invoke(bounds, "height").toString());
    344343
    345                         // Have to get the bg color even if the element isn't visible, so it can be cascaded down to child elements
    346                         // Always returns in format "rgb(x,x,x)" or "rgba(x,x,x,x)"
    347                         String bgColorString = (String) JavaFX.JSObjectCall.invoke(style, "getPropertyValue", new Object[] { "background-color" });
    348 
    349                         bgColor = rgbStringToColor(bgColorString);
    350 
    351                         bgColor = (bgColor != null ? bgColor : parentBgColor);
    352                        
    353 
    354344                        // Checking if the element is actually visible on the page
    355345                        if (WebParser.elementVisible(x, y, width, height, style)) {
     
    365355                                        String color = (String) JavaFX.JSObjectCall.invoke(style, "getPropertyValue", new Object[] { "color" });
    366356                                       
     357                                        // Always returns in format "rgb(x,x,x)" or "rgba(x,x,x,x)"
     358                                        String bgColorString = (String) JavaFX.JSObjectCall.invoke(style, "getPropertyValue", new Object[] { "background-color" });
     359
    367360                                        String align = (String) JavaFX.JSObjectCall.invoke(style, "getPropertyValue", new Object[] { "text-align" });
    368361                                       
     
    468461                                        }
    469462
    470                                         t = frame.addText(Math.round(x), Math.round(y), textContent, null);
     463                                        // Adding the text to the frame. Expeditee text seems to be positioned relative to the baseline of the first line, so
     464                                        // the font size has to be added to the y-position
     465                                        t = frame.addText(Math.round(x), Math.round(y + fontSizeFloat), textContent, null);
    471466
    472467                                        t.setColor(rgbStringToColor(color));
    473                                         t.setBackgroundColor(bgColor);
     468                                        t.setBackgroundColor(rgbStringToColor(bgColorString));
    474469                                        t.setFont(font);
    475470                                        t.setSize(fontSizeFloat);
     
    503498                                } else if (currentNode.getNodeType() == Node.ELEMENT_NODE) {
    504499
     500                                        // Always returns in format "rgb(x,x,x)" or "rgba(x,x,x,x)"
     501                                        String bgColorString = (String) JavaFX.JSObjectCall.invoke(style, "getPropertyValue", new Object[] { "background-color" });
     502
     503                                        Color bgColor = rgbStringToColor(bgColorString);
     504
     505                                        // If the element has a background color then add it (to Expeditee) as a rectangle with that background color
     506                                        if (bgColor != null) {
     507                                                System.out.println("bg");
     508                                                frame.addRectangle(Math.round(x), Math.round(y), Math.round(width), Math.round(height), 0, null, bgColor);
     509                                        }
     510
    505511                                        // background image, returns in format "url(protocol://absolute/path/to/img.extension)" for images,
    506512                                        // may also return gradients, data, etc. (not handled yet). Only need to add bg image on
     
    511517
    512518                                        if (bgImage.startsWith("url(")) {
    513 
    514519                                                bgImage = bgImage.substring(4, bgImage.length() - 1);
    515520
     
    599604
    600605                        while (childNode != null) {
    601                                 addPageToFrame(childNode, bgColor, window, webEngine, frame);
     606                                addPageToFrame(childNode, window, webEngine, frame);
    602607                                childNode = childNode.getNextSibling();
    603608                        }
Note: See TracChangeset for help on using the changeset viewer.