1 17 18 19 20 21 27 28 package org.apache.fop.render.rtf.rtflib.tools; 29 30 34 public class ImageUtil { 35 36 40 43 private ImageUtil () { 44 } 45 46 47 51 59 public static int getInt (String value) { 60 String retString = new String (); 61 StringBuffer s = new StringBuffer (value); 62 int len = s.length (); 63 64 for (int i = 0; i < len; i++) { 65 if (Character.isDigit (s.charAt (i))) { 66 retString += s.charAt (i); 67 } else { 68 break; 71 } 72 } 73 74 if (retString.length () == 0) { 75 return -1; 76 } else { 77 return Integer.parseInt (retString); 78 } 79 } 80 81 89 public static boolean isPercent (String value) { 90 if (value.endsWith ("%")) { 91 return true; 92 93 } 94 95 return false; 96 } 97 98 109 public static boolean compareHexValues (byte[] pattern, byte[] data, int searchAt, 110 boolean searchForward) { 111 if (searchAt >= data.length) { 112 return false; 113 114 } 115 116 int pLen = pattern.length; 117 118 if (searchForward) { 119 if (pLen >= (data.length - searchAt)) { 120 return false; 121 122 } 123 124 for (int i = 0; i < pLen; i++) { 125 if (pattern[i] != data[searchAt + i]) { 126 return false; 127 } 128 } 129 130 return true; 131 } else { 132 if (pLen > (searchAt + 1)) { 133 return false; 134 135 } 136 137 for (int i = 0; i < pLen; i++) { 138 if (pattern[pLen - i - 1] != data[searchAt - i]) { 139 return false; 140 } 141 } 142 143 return true; 144 } 145 } 146 147 157 public static int getIntFromByteArray (byte[] data, int startAt, int length, 158 boolean searchForward) { 159 int bit = 8; 160 int bitMoving = length * bit; 161 int retVal = 0; 162 163 if (startAt >= data.length) { 164 return retVal; 165 166 } 167 168 if (searchForward) { 169 if (length >= (data.length - startAt)) { 170 return retVal; 171 172 } 173 174 for (int i = 0; i < length; i++) { 175 bitMoving -= bit; 176 int iData = (int) data[startAt + i]; 177 if (iData < 0) { 178 iData += 256; 179 } 180 retVal += iData << bitMoving; 181 } 182 } else { 183 if (length > (startAt + 1)) { 184 return retVal; 185 186 } 187 188 for (int i = 0; i < length; i++) { 189 bitMoving -= bit; 190 int iData = (int) data[startAt - i]; 191 if (iData < 0) { 192 iData += 256; 193 } 194 retVal += iData << bitMoving; } 195 } 196 197 return retVal; 198 } 199 } 200 | Popular Tags |