1 package org.joshy.html.painter; 2 3 import org.joshy.html.*; 4 import org.joshy.html.box.*; 5 import org.joshy.html.util.*; 6 import java.awt.Color ; 7 import java.awt.Rectangle ; 8 import java.awt.Graphics ; 9 import java.awt.Graphics2D ; 10 import java.awt.Font ; 11 import java.awt.font.*; 12 import org.joshy.u; 13 14 public class InlinePainter { 15 16 public static void paintInlineContext(Context c, Box box) { 17 BlockBox block = (BlockBox)box; 18 19 c.getGraphics().translate(box.x,box.y); 22 23 c.getGraphics().setColor(Color.black); 25 for(int i=0; i<block.getChildCount(); i++) { 27 paintLine(c,(LineBox)block.getChild(i)); 30 } 31 32 33 c.getGraphics().translate(-box.x,-box.y); 36 } 38 39 private static void paintLine(Context c, LineBox line) { 40 int lx = line.x; 43 int ly = line.y + line.baseline; 44 45 for(int j=0; j<line.getChildCount(); j++) { 47 paintInline(c,(InlineBox)line.getChild(j),lx,ly,line); 48 } 49 if(c.debugDrawLineBoxes()) { 50 GraphicsUtil.drawBox(c.getGraphics(),line,Color.blue); 51 } 52 } 53 54 59 private static void paintInline(Context c, InlineBox inline, int lx, int ly, LineBox line) { 60 61 if(InlineLayout.isReplaced(inline.node)) { 62 c.getGraphics().translate( line.x, line.y+(line.baseline-inline.height)); 64 Layout layout = (Layout)LayoutFactory.getLayout(inline.node); 65 layout.paint(c,inline); 68 c.getGraphics().translate(-line.x,-(line.y+(line.baseline-inline.height))); 69 return; 70 } 71 72 73 if(InlineLayout.isFloatedBlock(inline.node,c)) { 74 Rectangle oe = c.getExtents(); 77 c.setExtents(new Rectangle (oe.x, 0, oe.width, oe.height)); 80 81 int xoff = line.x + inline.x; 82 int yoff = line.y + (line.baseline - inline.height) + inline.y; 83 c.getGraphics().translate(xoff, yoff); 84 Layout layout = (Layout)LayoutFactory.getLayout(inline.node); 85 layout.paint(c,inline.sub_block); 86 c.getGraphics().translate(-xoff, -yoff); 87 88 c.setExtents(oe); 89 return; 90 } 91 92 93 if(inline.is_break) { 94 return; 95 } 96 97 Graphics g = c.getGraphics(); 98 99 if(inline.relative) { 101 g.translate(inline.left, inline.top); 102 } 103 104 String text = inline.getSubstring(); 108 int iy = ly + inline.y; 109 int ix = lx + inline.x; 110 111 Font oldfont = c.getGraphics().getFont(); 113 c.getGraphics().setFont(inline.getFont()); 114 Color oldcolor = c.getGraphics().getColor(); 115 c.getGraphics().setColor(inline.color); 116 if(text!= null && text.length() > 0) { 119 c.getGraphics().drawString(text,ix,iy); 120 } 121 c.getGraphics().setColor(oldcolor); 122 123 Font cur_font = c.getGraphics().getFont(); 125 126 LineMetrics lm = cur_font.getLineMetrics(text,((Graphics2D )c.getGraphics()).getFontRenderContext()); 127 if(inline.underline) { 128 float down = lm.getUnderlineOffset(); 129 float thick = lm.getUnderlineThickness(); 130 g.fillRect(ix,iy+(int)down,g.getFontMetrics().stringWidth(text),(int)thick); 131 } 132 if(inline.strikethrough) { 133 float down = lm.getStrikethroughOffset(); 134 float thick = lm.getStrikethroughThickness(); 135 g.fillRect(ix,iy+(int)down,g.getFontMetrics().stringWidth(text),(int)thick); 136 } 137 if(inline.overline) { 138 float down = lm.getAscent(); 139 float thick = lm.getUnderlineThickness(); 140 g.fillRect(ix,iy-(int)down,g.getFontMetrics().stringWidth(text),(int)thick); 141 } 142 143 if(c.debugDrawInlineBoxes()) { 144 GraphicsUtil.draw(c.getGraphics(),new Rectangle (lx+inline.x+1,ly+inline.y+1-inline.height, 145 inline.width-2,inline.height-2),Color.green); 146 } 147 148 c.getGraphics().setFont(oldfont); 150 151 if(inline.relative) { 153 g.translate(-inline.left, -inline.top); 154 } 155 } 156 157 } 158 | Popular Tags |