1 17 18 19 20 package org.apache.fop.layoutmgr; 21 22 import org.apache.fop.fo.Constants; 23 24 42 public class KnuthPenalty extends KnuthElement { 43 44 45 public static final int FLAGGED_PENALTY = 50; 46 47 private int penalty; 48 private boolean bFlagged; 49 private int breakClass = -1; 50 51 60 public KnuthPenalty(int w, int p, boolean f, Position pos, boolean bAux) { 61 super(w, pos, bAux); 62 penalty = p; 63 bFlagged = f; 64 } 65 66 76 public KnuthPenalty(int w, int p, boolean f, 77 int iBreakClass, Position pos, boolean bAux) { 78 super(w, pos, bAux); 79 penalty = p; 80 bFlagged = f; 81 breakClass = iBreakClass; 82 } 83 84 85 public boolean isPenalty() { 86 return true; 87 } 88 89 92 public int getP() { 93 return penalty; 94 } 95 96 100 public void setP(int p) { 101 this.penalty = p; 102 } 103 104 105 public boolean isFlagged() { 106 return bFlagged; 107 } 108 109 110 public boolean isForcedBreak() { 111 return penalty == -KnuthElement.INFINITE; 112 } 113 114 115 public int getBreakClass() { 116 return breakClass; 117 } 118 119 123 public void setBreakClass(int cl) { 124 this.breakClass = cl; 125 } 126 127 128 public String toString() { 129 StringBuffer sb = new StringBuffer (64); 130 if (isAuxiliary()) { 131 sb.append("aux. "); 132 } 133 sb.append("penalty"); 134 sb.append(" p="); 135 if (getP() < 0) { 136 sb.append("-"); 137 } 138 if (Math.abs(getP()) == INFINITE) { 139 sb.append("INFINITE"); 140 } else { 141 sb.append(getP()); 142 } 143 if (isFlagged()) { 144 sb.append(" [flagged]"); 145 } 146 sb.append(" w="); 147 sb.append(getW()); 148 if (isForcedBreak()) { 149 sb.append(" (forced break"); 150 switch (getBreakClass()) { 151 case Constants.EN_PAGE: 152 sb.append(", page"); 153 break; 154 case Constants.EN_COLUMN: 155 sb.append(", column"); 156 break; 157 case Constants.EN_EVEN_PAGE: 158 sb.append(", even page"); 159 break; 160 case Constants.EN_ODD_PAGE: 161 sb.append(", odd page"); 162 break; 163 default: 164 } 165 sb.append(")"); 166 } 167 return sb.toString(); 168 } 169 170 } 171 | Popular Tags |