1 51 package org.apache.fop.layout; 52 53 import org.apache.fop.datatypes.ColorType; 54 import org.apache.fop.datatypes.CondLength; 55 56 public class BorderAndPadding implements Cloneable { 57 58 public static final int TOP = 0; 59 public static final int RIGHT = 1; 60 public static final int BOTTOM = 2; 61 public static final int LEFT = 3; 62 static final long bDiscard_MASK = 0x100000000L; 65 static final long iLength_MASK = 0x0FFFFFFFFL; 66 private static final long new_ResolvedCondLength(CondLength length) { 67 return (length.isDiscard()?bDiscard_MASK:0) + length.mvalue(); 68 } 69 70 75 public Object clone() throws CloneNotSupportedException { 76 BorderAndPadding bp = (BorderAndPadding) super.clone(); 77 bp.padding = new long[ padding.length]; System.arraycopy( padding, 0, bp.padding, 0, padding.length); 79 bp.borderInfo = (BorderInfo[])borderInfo.clone(); 80 for (int i=0; i<borderInfo.length; i++) { 81 if (borderInfo[i] != null) { 82 bp.borderInfo[i]=(BorderInfo)borderInfo[i].clone(); 83 } 84 } 85 return bp; 86 } 87 88 public static class BorderInfo implements Cloneable { 89 private int mStyle; private ColorType mColor; private long mWidth; 92 93 BorderInfo(int style, CondLength width, ColorType color) { 94 mStyle = style; 95 mWidth = new_ResolvedCondLength(width); 96 mColor = color; 97 } 98 99 public Object clone() throws CloneNotSupportedException { 100 BorderInfo bi = (BorderInfo) super.clone(); 101 bi.mWidth = mWidth; 102 return bi; 104 } 105 } 106 107 private BorderInfo[] borderInfo = new BorderInfo[4]; 108 private long[] padding = new long[4]; 110 public BorderAndPadding() {} 111 112 public void setBorder(int side, int style, CondLength width, 113 ColorType color) { 114 borderInfo[side] = new BorderInfo(style, width, color); 115 } 116 117 public void setPadding(int side, CondLength width) { 118 padding[ side] = new_ResolvedCondLength(width); 119 } 120 121 public void setPaddingLength(int side, int iLength) { 122 padding[side] = iLength + (padding[side] & bDiscard_MASK); 123 } 124 125 public void setBorderLength(int side, int iLength) { 126 borderInfo[side].mWidth = iLength + (borderInfo[side].mWidth & bDiscard_MASK); 127 } 128 129 public int getBorderLeftWidth(boolean bDiscard) { 130 return getBorderWidth(LEFT, bDiscard); 131 } 132 133 public int getBorderRightWidth(boolean bDiscard) { 134 return getBorderWidth(RIGHT, bDiscard); 135 } 136 137 public int getBorderTopWidth(boolean bDiscard) { 138 return getBorderWidth(TOP, bDiscard); 139 } 140 141 public int getBorderBottomWidth(boolean bDiscard) { 142 return getBorderWidth(BOTTOM, bDiscard); 143 } 144 145 public int getPaddingLeft(boolean bDiscard) { 146 return getPadding(LEFT, bDiscard); 147 } 148 149 public int getPaddingRight(boolean bDiscard) { 150 return getPadding(RIGHT, bDiscard); 151 } 152 153 public int getPaddingBottom(boolean bDiscard) { 154 return getPadding(BOTTOM, bDiscard); 155 } 156 157 public int getPaddingTop(boolean bDiscard) { 158 return getPadding(TOP, bDiscard); 159 } 160 161 162 private int getBorderWidth(int side, boolean bDiscard) { 163 if ((borderInfo[side] == null) 164 || (bDiscard && 165 ((borderInfo[side].mWidth&bDiscard_MASK) != 0L) 166 )) { 167 return 0; 168 } else { 169 return (int) (borderInfo[side].mWidth&iLength_MASK); 170 } 171 } 172 173 public ColorType getBorderColor(int side) { 174 if (borderInfo[side] != null) { 175 return borderInfo[side].mColor; 176 } else 177 return null; 178 } 179 180 public int getBorderStyle(int side) { 181 if (borderInfo[side] != null) { 182 return borderInfo[side].mStyle; 183 } else 184 return 0; 185 } 186 187 private int getPadding(int side, boolean bDiscard) { 188 return (int)(padding[side]&iLength_MASK); 189 } 190 191 } 192 | Popular Tags |