1 package org.joshy.html.util; 2 3 import org.joshy.u; 4 import java.util.List ; 5 import java.util.ArrayList ; 6 import java.awt.Point ; 7 import org.joshy.html.*; 8 import org.w3c.dom.*; 9 import org.joshy.html.box.*; 10 public class InlineUtil { 11 12 public static int doTextIndent(Context c, Element elem, int width, LineBox first_line) { 13 if(c.css.hasProperty(elem,"text-indent")) { 14 float indent = c.css.getFloatProperty(elem,"text-indent",width); 15 width = width - (int)indent; 16 first_line.x = first_line.x + (int)indent; 17 } 18 return width; 19 } 20 21 public static void handleFloated(Context c, InlineBox inline, LineBox line, 22 int full_width, Element enclosing_block) { 23 24 if(inline.node == enclosing_block) { 25 return; 26 } 27 if(inline.node.getNodeType() == inline.node.TEXT_NODE) { 30 if(inline.node.getParentNode() == enclosing_block) { 31 return; 32 } 33 } 34 35 String float_val = c.css.getStringProperty(inline.node,"float",false); 36 37 if(float_val == null) { 38 float_val = "none"; 39 } 40 if(float_val.equals("none")) { 41 return; 42 } 43 if(float_val.equals("left")) { 44 inline.x = 0-inline.width; 46 c.getLeftTab().x = inline.width; 48 c.getLeftTab().y += inline.height; 49 } 50 if(float_val.equals("right")) { 51 inline.x = full_width - inline.width; 53 c.getRightTab().x = inline.width; 55 c.getRightTab().y += inline.height; 56 } 57 line.width = line.width - inline.width; 59 inline.floated = true; 61 } 62 63 public static List getInlineNodeList(Node node, Element elem, Context c) { 64 return getInlineNodeList(node,elem,c,false); 65 } 66 public static List getInlineNodeList(Node node, Element elem, Context c, boolean stop_at_blocks) { 67 List list = new ArrayList (); 68 if(node == null) { return list; } 69 if(elem == null) { return list; } 70 if(!elem.hasChildNodes()) { 71 return list; 73 } 74 75 Node curr = node; 77 while(true) { 78 80 if(curr != node) { 82 if(curr.getNodeType() == curr.TEXT_NODE) { 83 list.add(curr); 85 node = curr; 86 continue; 87 } 89 if(InlineLayout.isReplaced(curr)) { 90 list.add(curr); 92 node = curr; 93 continue; 94 } 96 if(InlineLayout.isFloatedBlock(curr,c)) { 97 list.add(curr); 99 node = curr; 100 continue; 101 } 103 if(isBreak(curr)) { 104 list.add(curr); 106 node = curr; 107 continue; 108 } 110 if(stop_at_blocks) { 111 if(InlineLayout.isBlockNode(curr,c)) { 112 return list; 114 } 115 } 116 } 117 118 if(curr.hasChildNodes()) { 119 if(!InlineLayout.isFloatedBlock(curr,c)) { 122 curr = curr.getFirstChild(); 123 continue; 125 } 126 if(InlineLayout.isFloatedBlock(node,c)) { 130 if(node == elem) { 131 curr = curr.getFirstChild(); 132 continue; 133 } 134 } 135 } 136 137 if(curr.getNextSibling() != null) { 138 curr = curr.getNextSibling(); 139 continue; 141 } 142 143 while(true) { 146 curr = curr.getParentNode(); 147 if(curr == elem) { 150 return list; 154 } 156 if(curr.getNextSibling() != null) { 157 curr = curr.getNextSibling(); 158 break; 160 } 161 } 162 } 163 164 } 165 166 167 public static Node nextTextNode(List node_list) { 168 if(node_list.size() < 1) { 169 return null; 170 } 171 Node nd = (Node)node_list.get(0); 172 node_list.remove(nd); 173 return nd; 174 } 175 176 177 public static boolean isBreak(Node node) { 178 if(node instanceof Element) { 179 if(((Element)node).getNodeName().equals("br")) { 180 return true; 181 } 182 } 183 return false; 184 } 185 186 187 } 188 | Popular Tags |