Changeset 905 for trunk/src


Ignore:
Timestamp:
04/13/14 22:33:29 (10 years ago)
Author:
davidb
Message:

Support for bounding box calculation more closely aligned with the actual text drawn on the frame

Location:
trunk/src/org/expeditee
Files:
2 edited

Legend:

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

    r457 r905  
    22
    33import org.expeditee.items.Item;
     4import org.expeditee.items.Text;
    45
    56public class XRawItem extends XItem
     
    1112                this.item = item;
    1213               
    13                 bounding_rect = item.getArea().getBounds();
     14                if (item instanceof Text) {
     15                        // Expecting it to be a text item
     16                        // For it's bounding rectangle, go with the tighter 'PixelBounds' version
     17                       
     18                        Text text_item = (Text)item;
     19                        bounding_rect = text_item.getPixelBoundsUnion();
     20                }
     21                else {
     22                        // Just in case it isn't a text item
     23                        bounding_rect = item.getArea().getBounds();
     24                }
    1425               
    1526        }
  • trunk/src/org/expeditee/items/Text.java

    r879 r905  
    18441844                                }
    18451845
    1846                                 layout.draw(g, 1 + getX() + getJustOffset(layout), y);
     1846                                int ldx = 1+getX()+getJustOffset(layout); // Layout draw x
     1847                               
     1848                                boolean debug = false;
     1849                                if (debug) {
     1850                                        g.setColor(new Color(c.getRed(),c.getGreen(),c.getBlue(),40));
     1851                                        Rectangle layout_rect = layout.getPixelBounds(null, ldx, y);
     1852                                        g.fillRect(layout_rect.x, layout_rect.y, layout_rect.width, layout_rect.height);
     1853                                        g.setColor(c);
     1854                                }
     1855                               
     1856                               
     1857                                layout.draw(g, ldx, y);
    18471858
    18481859                                /*
     
    25922603        }
    25932604
     2605       
     2606       
     2607        public Rectangle getPixelBoundsUnion()
     2608        {
     2609                synchronized (_textLayouts) {
     2610                       
     2611                        int x = getX();
     2612                        int y = getY();
     2613       
     2614                        int min_xl = Integer.MAX_VALUE;
     2615                        int max_xr = Integer.MIN_VALUE;
     2616       
     2617                        int min_yt = Integer.MAX_VALUE;
     2618                        int max_yb = Integer.MIN_VALUE;
     2619               
     2620                       
     2621                        for (int i = 0; i < _textLayouts.size(); i++) {
     2622                                TextLayout layout = _textLayouts.get(i);
     2623
     2624                                int ldx = 1+x+getJustOffset(layout); // Layout draw x                           
     2625                                Rectangle layout_rect = layout.getPixelBounds(null, ldx, y);
     2626                                       
     2627                                int xl = layout_rect.x;
     2628                                int xr = xl + layout_rect.width -1;
     2629                               
     2630                                int yt = layout_rect.y;
     2631                                int yb = yt + layout_rect.height -1;
     2632                               
     2633                                min_xl = Math.min(min_xl,xl);
     2634                                max_xr = Math.max(max_xr,xr);
     2635                               
     2636                                min_yt = Math.min(min_yt,yt);
     2637                                max_yb = Math.max(max_yb,yb);
     2638                        }
     2639                       
     2640                        if ((min_xl >= max_xr) || (min_yt >= max_yb)) {
     2641                                // No valid rectangle are found
     2642                                return null;
     2643                        }
     2644                       
     2645                        return new Rectangle(min_xl,min_yt,max_xr-min_xl+1,max_yb-min_yt+1);
     2646                       
     2647                }
     2648                                       
     2649        }
    25942650        /*
    25952651         * Returns the SIMPLE statement contained by this text item.
Note: See TracChangeset for help on using the changeset viewer.