001package armyc2.c2sd.renderer.utilities; 002 003import android.graphics.Point; 004import android.graphics.PointF; 005import android.graphics.Rect; 006import android.graphics.RectF; 007 008 009public class SymbolDimensions { 010 011 /** 012 * 013 * @param charIndex 014 * @param fontSize 015 * @return float[] [offsetX,offsetY,w,h] 016 */ 017 public static float[] getUnitBounds(int charIndex, float fontSize) 018 { 019 020 int index = charIndex; 021 RectF rect = null; 022 float[] dimensions = {0f,0f,0f,0f}; 023 024 025 switch(index - 57000) 026 { 027 case 800: 028 case 801: 029 case 802: 030 //rect = RectUtilities.makeRectF(0,0,60.8f,60.8f);//unknown 031 dimensions[2]=60.8f; 032 dimensions[3]=60.8f; 033 break; 034 case 803: 035 case 804: 036 case 805: 037 //rect = RectUtilities.makeRectF(0,0,65,47);//friendly//65,45 038 dimensions[2]=62.547f; 039 dimensions[3]=44.52632f; 040 break; 041 case 806: 042 case 807: 043 case 808: 044 //rect = RectUtilities.makeRectF(0,0,62.5f,62.5f);//hostile 045 dimensions[2]=62.5f; 046 dimensions[3]=62.5f; 047 break; 048 case 809: 049 case 810: 050 case 811: 051 //rect = RectUtilities.makeRectF(0,0,50.05f,50.05f);//neutral 052 dimensions[2]=47.6085f; 053 dimensions[3]=47.6085f; 054 break; 055 case 812: 056 case 813: 057 case 814: 058 //rect = RectUtilities.makeRectF(0,0,54.75f,54.75f);//friendly equipment 059 dimensions[2]=51.0625f; 060 dimensions[3]=51.0625f; 061 break; 062 case 816: 063 case 817: 064 case 818: 065 case 840: 066 case 841: 067 case 842: 068 //rect = RectUtilities.makeRectF(0,16,50.3f,53);//air & space hostile 069 dimensions[1]=8f; 070 dimensions[2]=47.8463f; 071 dimensions[3]=53f; 072 break; 073 case 819: 074 case 820: 075 case 821: 076 case 843: 077 case 844: 078 case 845: 079 //rect = RectUtilities.makeRectF(0,11,46.5f,48);//air space friendly 080 dimensions[1]=6f; 081 dimensions[2]=46.5f; 082 dimensions[3]=48f; 083 break; 084 case 822: 085 case 823: 086 case 824: 087 case 846: 088 case 847: 089 case 848: 090 //rect = RectUtilities.makeRectF(0,11,47,48);//air space neutral 091 dimensions[1]=6f; 092 dimensions[2]=47f; 093 dimensions[3]=48f; 094 break; 095 case 825: 096 case 826: 097 case 827: 098 case 849: 099 case 850: 100 case 851: 101 //rect = RectUtilities.makeRectF(0,11,64.7f,56);//air space unknown 102 dimensions[1]=6.5f; 103 dimensions[2]=64.7f; 104 dimensions[3]=56f; 105 break; 106 case 828: 107 case 829: 108 case 830: 109 //rect = RectUtilities.makeRectF(0,-17,50.3f,53);//subsurface hostile 110 dimensions[1]=-8f; 111 dimensions[2]=47.8463f; 112 dimensions[3]=53f; 113 break; 114 case 831: 115 case 832: 116 case 833: 117 //rect = RectUtilities.makeRectF(0,-12,46.6f,48);//subsurface friendly 118 dimensions[1]=-6f; 119 dimensions[2]=46.6f; 120 dimensions[3]=48f; 121 break; 122 case 834: 123 case 835: 124 case 836: 125 //rect = RectUtilities.makeRectF(0,-12,46.5f,48);//subsurface neutral 126 dimensions[1]=-6f; 127 dimensions[2]=46.5f; 128 dimensions[3]=48f; 129 break; 130 case 837: 131 case 838: 132 case 839: 133 rect = RectUtilities.makeRectF(0,0,64.7f,56f);//subsurface unknown 134 dimensions[1]=-6f; 135 dimensions[2]=64.7f; 136 dimensions[3]=56f; 137 //rect = RectUtilities.makeRectF(0,-12,64.7f,56);//subsurface unknown 138 break; 139 default: 140 //rect = RectUtilities.makeRectF(0,0,54,54); 141 dimensions[2]=54f; 142 dimensions[3]=54f; 143 break; 144 } 145 146 float ratio = 1; 147 if(fontSize != 50) 148 { 149 ratio = fontSize / 50f; 150 //I only measured for a font size of 50. if we get the ratio and multiply the values 151 //by it, we in theory should have a correct adjusted rectangle. 152 //rect = RectUtilities.makeRectF(0,(rect.top*ratio), (rect.width()*ratio), (rect.height()*ratio)); 153 dimensions[1] = dimensions[1] * ratio; 154 dimensions[2] = dimensions[2] * ratio; 155 dimensions[3] = dimensions[3] * ratio; 156 } 157 158 //return RectUtilities.makeRectFromRectF(rect); 159 return dimensions; 160 } 161 162 public static Rect getSymbolBounds(String symbolID, int symStd, float fontSize) 163 { 164 165 SinglePointLookupInfo spli = SinglePointLookup.getInstance().getSPLookupInfo(symbolID,symStd); 166 167 RectF rect = new RectF(0,0,spli.getWidth(), spli.getHeight()); 168 169 if(fontSize != 60)//adjust boundaries ratio if font size is not at the default setting. 170 { 171 double ratio = fontSize/60.0; 172 173 rect = RectUtilities.makeRectF(0f,0f,(float)(rect.width()*ratio), (float)(rect.height()*ratio)); 174 } 175 176 return new Rect((int)rect.left, (int)rect.top, (int)(rect.right + 0.5), (int)(rect.bottom + 0.5)); 177 } 178 179 /** 180 * 181 * */ 182 public static Point getSymbolCenter(String symbolID, RectF bounds) 183 { 184 String basicID = SymbolUtilities.getBasicSymbolID(symbolID); 185 PointF center = new PointF(); 186 187 if(basicID.equals("G*G*GPUUB-****X")|| 188 basicID.equals("G*G*GPUUL-****X") || 189 basicID.equals("G*G*GPUUS-****X") || 190 basicID.equals("G*G*GPRI--****X") || 191 basicID.equals("G*G*GPWE--****X") || 192 basicID.equals("G*G*GPWG--****X") || 193 basicID.equals("G*G*GPWM--****X")|| 194 basicID.equals("G*G*GPP---****X") || 195 basicID.equals("G*G*GPPC--****X") || 196 basicID.equals("G*G*GPPL--****X") || 197 basicID.equals("G*G*GPPP--****X") || 198 basicID.equals("G*G*GPPR--****X") || 199 basicID.equals("G*G*GPPA--****X") || 200 basicID.equals("G*G*APD---****X") || 201 basicID.equals("G*G*OPP---****X") || 202 basicID.substring(0,7).equals("G*M*OAO") ||//antitank obstacles 203 basicID.equals("G*M*BCP---****X") || 204 basicID.equals("G*F*PCS---****X") || 205 basicID.equals("G*F*PCB---****X") || 206 basicID.equals("G*F*PCR---****X") || 207 basicID.equals("G*F*PCH---****X") || 208 basicID.equals("G*F*PCL---****X") || 209 basicID.substring(0, 5).equals("G*S*P") ||//combat service suppport/points 210 basicID.equals("G*O*ED----****X") || 211 basicID.equals("G*O*EP----****X") || 212 basicID.equals("G*O*EV----****X") || 213 basicID.equals("G*O*SB----****X") || 214 basicID.equals("G*O*SBM---****X") || 215 basicID.equals("G*O*SBN---****X") || 216 basicID.equals("G*O*SS----****X") || 217 basicID.equals("G*G*GPPN--****X") || //entry control point 218 basicID.equals("G*S*PX----****X") || //ambulance exchange point 219 basicID.equals("G*O*ES----****X") || //emergency distress call 220 SymbolUtilities.isNBC(basicID) || 221 SymbolUtilities.isDeconPoint(basicID) || 222 SymbolUtilities.isCheckPoint(basicID)) 223 { 224 //center on bottom middle 225 center.x = bounds.width()/2; 226 center.y = bounds.height(); 227 } 228 else if(SymbolUtilities.isSonobuoy(basicID)) 229 { 230 //bottom third 231 center.x = bounds.width()/2; 232 center.y = (int)((bounds.height() * 0.75)); 233 } 234 else if ((basicID.substring(0, 7).equals("G*G*GPO") && (basicID.charAt(7) == ('-')) == false))//antitank mine w/ handling device 235 { 236 //upper third 237 center.x = bounds.width()/2; 238 center.y = (int)((bounds.height() * 0.33)); 239 } 240 else if(basicID.equals("G*M*OMD---****X")) 241 { 242 //upper third 243 center.x = bounds.width()/2; 244 center.y = (int)((bounds.height() * 0.28)); 245 } 246 else if (basicID.substring(0, 7).equals("G*G*DPO"))//OBSERVATION POST/OUTPOST 247 { 248 if (basicID.charAt(7) == ('C'))//combat outpost 249 { 250 center.x = bounds.width()/2; 251 center.y = (int)((bounds.height() * 0.55)); 252 } 253 else//everything else under OBSERVATION POST/OUTPOST 254 { 255 center.x = bounds.width()/2; 256 center.y = (int)((bounds.height() * 0.65)); 257 } 258 } 259 else if(basicID.equals("G*G*GPWD--****X")||//drop point 260 basicID.equals("G*G*PN----****X") ||//dummy minefield static 261 basicID.equals("G*M*OB----****X") ||//booby trap 262 basicID.equals("G*M*OME---****X") ||//antitank mine directional 263 basicID.equals("G*M*OMW---****X") ||//wide area mines 264 basicID.equals("G*M*OMP---****X") ||//anti-personnel mines 265 basicID.equals("G*M*OHTL--****X") ||//Aviation/tower/low 266 basicID.equals("G*M*OHTH--****X") ||//Aviation/tower/high 267 basicID.equals("G*O*HM----****X") ||// 268 basicID.equals("G*O*HI----****X") ||// 269 basicID.equals("G*O*SM----****X")) 270 { 271 if(basicID.equals("G*G*GPWD--****X"))//drop point 272 { 273 center.x = bounds.width()/2; 274 center.y = (int)((bounds.height() * 0.87)); 275 } 276 else if(basicID.equals("G*G*PN----****X"))//dummy minefield static 277 { 278 center.x = bounds.width()/2; 279 center.y = (int)((bounds.height() * 0.69)); 280 } 281 else if(basicID.equals("G*M*OB----****X"))//booby trap 282 { 283 center.x = bounds.width()/2; 284 center.y = (int)((bounds.height() * 0.79)); 285 } 286 else if(basicID.equals("G*M*OME---****X"))//antitank mine directional 287 { 288 center.x = bounds.width()/2; 289 center.y = (int)((bounds.height() * 0.77)); 290 } 291 else if(basicID.equals("G*M*OMW---****X"))//wide area mines 292 { 293 center.x = bounds.width()/2; 294 center.y = (int)((bounds.height() * 0.3)); 295 } 296 else if(basicID.equals("G*M*OMP---****X"))//anti personnel mines 297 { 298 center.x = bounds.width()/2; 299 center.y = (int)((bounds.height()) * 0.64); 300 } 301 else if(basicID.equals("G*M*OHTL--****X"))//Aviation/tower/low//2525C 302 { 303 center.x = bounds.width()/2; 304 center.y = (int)((bounds.height() * 0.88)); 305 } 306 else if(basicID.equals("G*M*OHTH--****X"))//Aviation/tower/high//2525C 307 { 308 center.x = bounds.width()/2; 309 center.y = (int)((bounds.height() * 0.90)); 310 } 311 else if(basicID.equals("G*O*HM----****X"))//sea mine-like 312 { 313 center.x = bounds.width()/2; 314 center.y = (int)((bounds.height() * 0.65)); 315 } 316 else if(basicID.equals("G*O*HI----****X")) 317 { 318 center.x = bounds.width()/2; 319 center.y = (int)((bounds.height() * 0.58)); 320 } 321 else if(basicID.equals("G*O*SM----****X")) 322 { 323 center.x = 0; 324 center.y = (int)((bounds.height() * 0.5)); 325 } 326 327 328 } 329 else if(basicID.equals("G*O*SS----****X")) 330 { 331 center.x = 0; 332 center.y = (int)((bounds.height() * 0.45)); 333 } 334 else 335 { 336 //center on center 337 center.x = bounds.width()/2; 338 center.y = bounds.height()/2; 339 } 340 341 return new Point(Math.round(center.x),Math.round(center.y)); 342 } 343 } 344