001/*
002 * To change this template, choose Tools | Templates and open the template in the editor.
003 */
004
005package armyc2.c2sd.renderer.utilities;
006
007import armyc2.c2sd.renderer.R;
008
009import android.content.Context;
010import android.util.Log;
011
012import java.io.BufferedInputStream;
013import java.io.DataInputStream;
014import java.io.IOException;
015import java.util.HashMap;
016import java.util.logging.Level;
017
018/**
019 *
020 * @author michael.spinelli
021 */
022public class UnitFontLookup
023{
024
025    private static boolean _initCalled = false;
026    private static UnitFontLookup _instance;
027    private boolean _ready = false;
028    private static HashMap<String, UnitFontLookupInfo> hashMapB = new HashMap<String, UnitFontLookupInfo>();
029    private static HashMap<String, UnitFontLookupInfo> hashMapC = new HashMap<String, UnitFontLookupInfo>();
030
031    // UNKNOWN FILL Indexes
032    private static final int FillIndexUZ = 800;// Unknown
033    private static final int FillIndexUP = 849;// Space
034    private static final int FillIndexUA = 825;// Air
035    private static final int FillIndexUG = 800;// Ground
036    private static final int FillIndexUGE = 800;// Ground Equipment
037    private static final int FillIndexUS = 800;// Sea Surface
038    private static final int FillIndexUU = 837;// Subsurface
039    private static final int FillIndexUF = 800;// SOF
040    // FRIENDLY FILL Indexes
041    private static final int FillIndexFZ = 812;
042    private static final int FillIndexFP = 843;
043    private static final int FillIndexFA = 819;
044    private static final int FillIndexFG = 803;
045    private static final int FillIndexFGE = 812;
046    private static final int FillIndexFS = 812;
047    private static final int FillIndexFU = 831;
048    private static final int FillIndexFF = 803;
049    // NEUTRAL FILL Indexes
050    private static final int FillIndexNZ = 809;
051    private static final int FillIndexNP = 846;
052    private static final int FillIndexNA = 822;
053    private static final int FillIndexNG = 809;
054    private static final int FillIndexNGE = 809;
055    private static final int FillIndexNS = 809;
056    private static final int FillIndexNU = 834;
057    private static final int FillIndexNF = 809;
058    // HOSTILE FILL Indexes
059    private static final int FillIndexHZ = 806;
060    private static final int FillIndexHP = 840;
061    private static final int FillIndexHA = 816;
062    private static final int FillIndexHG = 806;
063    private static final int FillIndexHGE = 806;
064    private static final int FillIndexHS = 806;
065    private static final int FillIndexHU = 828;
066    private static final int FillIndexHF = 806;
067
068    // Font positions for new layout
069    // 770-799: small fills, inside the frame
070    // 800-900: regular fills with solid & dashed frame
071    // 1000 - 3000?: Warfighting - A -
072    // 3000 - 3200?: SigInt - D - 80 only need fill/frame/symbol
073    // 3200? - 3400?: Stability Operations Symbology - E - 60 w/ 6 that need 4 symbols & 6 with secondary
074    // symbol / fill
075    // 4000+: Emergency Management Symbols - G -
076
077    //
078    public boolean getReady()
079    {
080        return this._ready;
081    }
082
083    private UnitFontLookup()
084    {
085
086    }
087
088    public static synchronized UnitFontLookup getInstance()
089    {
090        if (_instance == null) {
091            _instance = new UnitFontLookup();
092        }
093        return _instance;
094    }
095
096    public synchronized void init(Context context)
097    {
098        if (_initCalled == false) {
099            _instance = new UnitFontLookup();
100
101            try {
102                DataInputStream dis = new DataInputStream(new BufferedInputStream(context.getResources().openRawResource(R.raw.unitfontmappings)));
103                readBinary(dis);
104                dis.close();
105            } catch (IOException e) {
106                Log.e("UnitFontLookup", "Could not load", e);
107            }
108
109            _initCalled = true;
110        }
111    }
112
113    /**
114     * we only have font lookups for F,H,N,U. But the shapes match one of these four for the remaining
115     * affiliations. So we convert the string to a base affiliation before we do the lookup.
116     * 
117     * @param symbolID
118     * @return
119     */
120    private String resolveAffiliation(String symbolID)
121    {
122        String code = symbolID.substring(0);
123        String affiliation = symbolID.substring(1, 2);
124
125        if (affiliation.equals("F") || // friendly
126                affiliation.equals("H") || // hostile
127                affiliation.equals("U") || // unknown
128                affiliation.equals("N"))// neutral
129            return code;
130        else if (affiliation.equals("S"))// suspect
131            code = code.substring(0, 1) + "H" + code.substring(2, 15);
132        else if (affiliation.equals("L"))// exercise neutral
133            code = code.substring(0, 1) + "N" + code.substring(2, 15);
134        else if (affiliation.equals("A") || // assumed friend
135                affiliation.equals("D") || // exercise friend
136                affiliation.equals("M") || // exercise assumed friend
137                affiliation.equals("K") || // faker
138                affiliation.equals("J"))// joker
139            code = code.substring(0, 1) + "F" + code.substring(2, 15);
140        else if (affiliation.equals("P") || // pending
141                affiliation.equals("G") || // exercise pending
142                affiliation.equals("O") || // ? brought it over from mitch's code
143                affiliation.equals("W"))// exercise unknown
144            code = code.substring(0, 1) + "U" + code.substring(2, 15);
145        else
146            code = code.substring(0, 1) + "U" + code.substring(2, 15);
147
148        return code;
149    }
150
151    public static UnitFontLookupInfo adjustSubSurfaceIfNot2525C(UnitFontLookupInfo original)
152    {
153        UnitFontLookupInfo result = null;
154
155        return result;
156    }
157
158    /**
159     * 2525C returns the character index for the fill frame based on the symbol code.
160     * 
161     * @param SymbolID 15 character symbol ID
162     * @param symStd 0 for 2525B, 1 for 2525C
163     * @return fill character index
164     */
165    public static int getFillCode(String SymbolID, int symStd)
166    {
167        int returnVal = -1;
168
169        char scheme = 0;
170        char battleDimension = 0;
171        char status = 0;
172        char affiliation = 0;
173        char grdtrkSubset = 0;
174        // char foo = 'a';
175
176        try {
177            // to upper
178            if (SymbolID != null && SymbolID.length() >= 10) {
179                scheme = SymbolID.charAt(0);// S,O,E,I,etc...
180                affiliation = SymbolID.charAt(1);// F,H,N,U,etc...
181                battleDimension = SymbolID.charAt(2);// P,A,G,S,U,F,X,Z
182                status = SymbolID.charAt(3);// A,P,C,D,X,F
183                grdtrkSubset = SymbolID.charAt(4);
184
185                if (scheme == 'S')// Warfighting symbols
186                {
187                    if (affiliation == 'F' || affiliation == 'A' || affiliation == 'D' || affiliation == 'M'
188                            || affiliation == 'J' || affiliation == 'K') {
189                        if (battleDimension == 'F' || battleDimension == 'G')// ground & SOF
190                        {
191                            if (battleDimension == 'F' || (battleDimension == 'G' && (grdtrkSubset == 'U'
192                                    || grdtrkSubset == 'I' || grdtrkSubset == '0' || grdtrkSubset == '-'))) {
193                                returnVal = 803;
194                            } else if (battleDimension == 'G' && grdtrkSubset == 'E') {
195                                returnVal = 812;
196                            } else
197                                returnVal = 803;
198                        } else if (battleDimension == 'A')// Air
199                        {
200                            returnVal = 819;
201                        } else if (battleDimension == 'S')// SeaSurface
202                        {
203                            returnVal = getSeaSurfaceFill(SymbolID);
204                        } else if (battleDimension == 'U')// Subsurface
205                        {
206                            returnVal = getSubSurfaceFill(SymbolID);
207                        } else if (battleDimension == 'P')// space
208                        {
209                            if (symStd == 0)
210                                returnVal = 819;
211                            else
212                                returnVal = 843;
213                        } else// if(battleDimension=='Z')//unknown
214                        {
215                            returnVal = 812;// index in font file
216                        }
217
218                    } else if (affiliation == 'H' || affiliation == 'S')// hostile,suspect
219                    {
220                        if (battleDimension == 'Z')// unknown
221                        {
222                            returnVal = 806;// index in font file
223                        } else if (battleDimension == 'F' || battleDimension == 'G')// ground & SOF
224                        {
225                            returnVal = 806;
226                        } else if (battleDimension == 'A')// Air
227                        {
228                            returnVal = 816;
229                        } else if (battleDimension == 'S')// SeaSurface
230                        {
231                            returnVal = getSeaSurfaceFill(SymbolID);
232                        } else if (battleDimension == 'U')// Subsurface
233                        {
234                            returnVal = getSubSurfaceFill(SymbolID);
235                        } else if (battleDimension == 'P')// space
236                        {
237                            if (symStd == 0)
238                                returnVal = 816;
239                            else
240                                returnVal = 840;
241                        } else
242                            returnVal = 806;
243                    } else if (affiliation == 'N' || affiliation == 'L')// neutral,exercise neutral
244                    {
245                        if (battleDimension == 'Z')// unknown
246                        {
247                            returnVal = 809;// index in font file
248                        } else if (battleDimension == 'F' || battleDimension == 'G')// ground & SOF
249                        {
250                            returnVal = 809;
251                        } else if (battleDimension == 'A')// Air
252                        {
253                            returnVal = 822;
254                        } else if (battleDimension == 'S')// SeaSurface
255                        {
256                            returnVal = getSeaSurfaceFill(SymbolID);
257                        } else if (battleDimension == 'U')// Subsurface
258                        {
259                            returnVal = getSubSurfaceFill(SymbolID);
260                        } else if (battleDimension == 'P')// space
261                        {
262                            if (symStd == 0)
263                                returnVal = 822;
264                            else
265                                returnVal = 846;
266                        } else
267                            returnVal = 809;
268                    } else /*
269                            * if(affiliation == 'P' || affiliation == 'U' || affiliation == 'G' || affiliation
270                            * == 'W')
271                            */ // these or any bad values
272                    {
273
274                        if (battleDimension == 'Z' || // unknown
275                                battleDimension == 'G' || // ground
276                                battleDimension == 'F')// SOF
277                        {
278                            returnVal = 800;// index in font file
279                        } else if (battleDimension == 'A')// Air
280                        {
281                            returnVal = 825;
282                        } else if (battleDimension == 'S')// SeaSurface
283                        {
284                            returnVal = getSeaSurfaceFill(SymbolID);
285                        } else if (battleDimension == 'U')// Subsurface
286                        {
287                            returnVal = getSubSurfaceFill(SymbolID);
288                        } else if (battleDimension == 'P')// space
289                        {
290                            if (symStd == 0)
291                                returnVal = 825;
292                            else
293                                returnVal = 849;
294                        } else
295                            returnVal = 800;
296                    }
297                } // end if scheme == 's'
298                else if (scheme == 'E')// Emergency Management Symbols
299                {
300                    if (battleDimension != 'N')// if not EMS natural event
301                    {
302                        if (affiliation == 'F' || affiliation == 'A' || affiliation == 'D'
303                                || affiliation == 'M' || affiliation == 'J' || affiliation == 'K') {
304
305                            // EMS symbols break some rules about symbol codes
306                            if (SymbolUtilities.isEMSEquipment(SymbolID))
307                                returnVal = 812;
308                            else
309                                returnVal = 803;
310                        } else if (affiliation == 'H' || affiliation == 'S')// hostile,suspect
311                        {
312                            returnVal = 806;// index in font file
313
314                        } else if (affiliation == 'N' || affiliation == 'L')// neutral,exercise neutral
315                        {
316                            returnVal = 809;
317                        } else /*
318                                * if(affiliation == 'P' || affiliation == 'U' || affiliation == 'G' ||
319                                * affiliation == 'W')
320                                */
321                        {
322                            returnVal = 800;// index in font file
323                        }
324                    } else // natural events do not have a fill/frame
325                    {
326                        returnVal = -1;
327                    }
328                } // end if scheme == 'E'
329                else if (scheme == 'I')// Also default behavior
330                {
331                    if (affiliation == 'F' || affiliation == 'A' || affiliation == 'D' || affiliation == 'M'
332                            || affiliation == 'J' || affiliation == 'K') {
333                        if (battleDimension == 'Z')// unknown
334                        {
335                            returnVal = 812;// index in font file
336                        } else if (battleDimension == 'F' || battleDimension == 'G' || battleDimension == 'S')// ground
337                                                                                                              // &
338                                                                                                              // SOF
339                                                                                                              // &
340                                                                                                              // sea
341                                                                                                              // surface
342                        {
343                            if (scheme == 'I')
344                                returnVal = 812;
345                            else
346                                returnVal = 803;
347                        } else if (battleDimension == 'A')// Air
348                        {
349                            returnVal = 819;
350                        } else if (battleDimension == 'U')// Subsurface
351                        {
352                            returnVal = 831;
353                        } else if (battleDimension == 'P')// space
354                        {
355                            if (symStd == 0)
356                                returnVal = 819;
357                            else
358                                returnVal = 843;
359                        } else {
360                            if (scheme == 'I')
361                                returnVal = 812;
362                            else
363                                returnVal = 803;
364                        }
365                    }
366                    if (affiliation == 'H' || affiliation == 'S')// hostile,suspect
367                    {
368                        if (battleDimension == 'Z')// unknown
369                        {
370                            returnVal = 806;// index in font file
371                        } else if (battleDimension == 'F' || battleDimension == 'G' || battleDimension == 'S')// ground
372                                                                                                              // &
373                                                                                                              // SOF
374                                                                                                              // &
375                                                                                                              // sea
376                                                                                                              // surface
377                        {
378                            returnVal = 806;
379                        } else if (battleDimension == 'A')// Air
380                        {
381                            returnVal = 816;
382                        } else if (battleDimension == 'U')// Subsurface
383                        {
384                            returnVal = 828;
385                        } else if (battleDimension == 'P')// space
386                        {
387                            if (symStd == 0)
388                                returnVal = 816;
389                            else
390                                returnVal = 840;
391                        } else {
392                            returnVal = 806;
393                        }
394                    }
395                    if (affiliation == 'N' || affiliation == 'L')// neutral,exercise neutral
396                    {
397                        if (battleDimension == 'Z')// unknown
398                        {
399                            returnVal = 809;// index in font file
400                        } else if (battleDimension == 'F' || battleDimension == 'G' || battleDimension == 'S')// ground
401                                                                                                              // &
402                                                                                                              // SOF
403                                                                                                              // &
404                                                                                                              // sea
405                                                                                                              // surface
406                        {
407                            returnVal = 809;
408                        } else if (battleDimension == 'A')// Air
409                        {
410                            returnVal = 822;
411                        } else if (battleDimension == 'U')// Subsurface
412                        {
413                            returnVal = 834;
414                        } else if (battleDimension == 'P')// space
415                        {
416                            if (symStd == 0)
417                                returnVal = 822;
418                            else
419                                returnVal = 846;
420                        } else {
421                            returnVal = 809;
422                        }
423                    } else if (affiliation == 'P' || affiliation == 'U' || affiliation == 'G'
424                            || affiliation == 'W') {
425
426                        if (battleDimension == 'Z' || // unknown
427                                battleDimension == 'G' || // ground
428                                battleDimension == 'S' || // sea surface
429                                battleDimension == 'F')// SOF
430                        {
431                            returnVal = 800;// index in font file
432                        } else if (battleDimension == 'A')// Air
433                        {
434                            returnVal = 825;
435                        } else if (battleDimension == 'U')// Subsurface
436                        {
437                            returnVal = 837;
438                        } else if (battleDimension == 'P')// Space
439                        {
440                            if (symStd == 0)
441                                returnVal = 825;
442                            else
443                                returnVal = 849;
444                        } else {
445                            returnVal = 800;
446                        }
447                    }
448                } // end if scheme == 'I'
449                else// scheme = 'O' and anything else
450                {
451                    if (affiliation == 'F' || affiliation == 'A' || affiliation == 'D' || affiliation == 'M'
452                            || affiliation == 'J' || affiliation == 'K') {
453                        returnVal = 803;
454                    } else if (affiliation == 'H' || affiliation == 'S')// hostile,suspect
455                    {
456                        returnVal = 806;// index in font file
457                    } else if (affiliation == 'N' || affiliation == 'L')// neutral,exercise neutral
458                    {
459                        returnVal = 809;
460                    } else /*
461                            * if(affiliation == 'P' || affiliation == 'U' || affiliation == 'G' || affiliation
462                            * == 'W')
463                            */
464                    {
465                        returnVal = 800;// index in font file
466                    }
467                } // end default
468
469            }
470
471        } catch (Exception exc) {
472            ErrorLogger.LogException("UnitFontLookup", "getFillCode", exc, Level.SEVERE);
473        }
474
475        return returnVal + 57000;
476    }
477
478    public static int getFrameCode(String SymbolID, int FillCode)
479    {
480        int returnVal = 0;
481        char status = SymbolID.charAt(3);
482
483        if (status == 'A')
484            returnVal = FillCode + 2;
485        else// P, C, D, X, F
486            returnVal = FillCode + 1;
487
488        if (returnVal == 847)
489            returnVal = 852;
490
491        if (SymbolUtilities.isSeaSurface(SymbolID)) {
492            returnVal = getSeaSurfaceFrame(SymbolID, FillCode);
493        }
494        if (SymbolUtilities.isSubSurface(SymbolID)) {
495            returnVal = getSubSurfaceFrame(SymbolID, FillCode);
496        }
497
498        return returnVal;
499
500    }
501
502    private static int getSeaSurfaceFill(String SymbolID)
503    {
504        char affiliation = 0;
505        char status = 0;
506        int returnVal = 0;
507
508        try {
509            affiliation = SymbolID.charAt(1);// F,H,N,U,etc...
510            status = SymbolID.charAt(3);// A,P,C,D,X,F
511
512            if (SymbolUtilities.getBasicSymbolID(SymbolID).equalsIgnoreCase("S*S*O-----*****")) {
513                return 2016;
514            } else {
515                if (affiliation == 'F' || affiliation == 'A' || affiliation == 'D' || affiliation == 'M'
516                        || affiliation == 'J' || affiliation == 'K') {
517                    return FillIndexFS;
518                } else if (affiliation == 'H' || affiliation == 'S')// hostile,suspect
519                {
520                    return FillIndexHS;
521                } else if (affiliation == 'N' || affiliation == 'L')// neutral,exercise neutral
522                {
523                    return FillIndexNS;
524                } else if (affiliation == 'P' || affiliation == 'U' || affiliation == 'G'
525                        || affiliation == 'W') {
526                    return FillIndexUS;
527                }
528            }
529        } catch (Exception exc) {
530            ErrorLogger.LogException("UnitFontLookupC", "getSeaSurfaceFill", exc);
531            return FillIndexUG;
532        }
533        return FillIndexUG;
534    }
535
536    private static int getSubSurfaceFill(String SymbolID)
537    {
538        char affiliation = 0;
539        char status = 0;
540        int returnVal = 0;
541
542        returnVal = 831;
543
544        try {
545            affiliation = SymbolID.charAt(1);// F,H,N,U,etc...
546            status = SymbolID.charAt(3);// A,P,C,D,X,F
547
548            if (affiliation == 'F' || affiliation == 'A' || affiliation == 'D' || affiliation == 'M'
549                    || affiliation == 'J' || affiliation == 'K') {
550                returnVal = 831;//
551            } else if (affiliation == 'H' || affiliation == 'S')// hostile,suspect
552            {
553                returnVal = 828;// index in font file
554
555            } else if (affiliation == 'N' || affiliation == 'L')// neutral,exercise neutral
556            {
557                returnVal = 834;
558            } else if (affiliation == 'P' || affiliation == 'U' || affiliation == 'G' || affiliation == 'W') {
559                returnVal = 837;// index in font file
560            }
561
562            // appears in USAS so we check in both standards
563            if (SymbolUtilities.getBasicSymbolID(SymbolID).equalsIgnoreCase("S*U*X-----*****")) {
564                if (status == 'A')
565                    returnVal = returnVal + 2;
566                else
567                    returnVal++;
568            }
569
570            // Special check for sea mine graphics
571            // 2525C///////////////////////////////////////////////////////////////
572            if (RendererSettings.getInstance().getSymbologyStandard() == RendererSettings.Symbology_2525C) {
573                if (SymbolID.indexOf("WM") == 4 || // Sea Mine
574                        SymbolID.indexOf("WDM") == 4 || // Sea Mine Decoy
575                        SymbolUtilities.getBasicSymbolID(SymbolID).equalsIgnoreCase("S*U*E-----*****")
576                        || SymbolUtilities.getBasicSymbolID(SymbolID).equalsIgnoreCase("S*U*V-----*****")) {
577                    returnVal++;
578
579                    if (status == 'A')
580                        returnVal++;
581
582                } else if (SymbolUtilities.getBasicSymbolID(SymbolID).equalsIgnoreCase("S*U*ND----*****")) {
583                    returnVal = 2121;
584                }
585            } else// 2525Bch2////////////////////////////////////////////////////////
586            {
587                if (SymbolID.indexOf("WM") == 4)// Sea Mine
588                {
589                    if (SymbolID.indexOf("----", 6) == 6 || SymbolID.indexOf("D---", 6) == 6)
590                        returnVal = 2059;//
591                    else if (SymbolID.indexOf("G---", 6) == 6)
592                        returnVal = 2062;
593                    else if (SymbolID.indexOf("GD--", 6) == 6)
594                        returnVal = 2064;
595                    else if (SymbolID.indexOf("M---", 6) == 6)
596                        returnVal = 2073;
597                    else if (SymbolID.indexOf("MD--", 6) == 6)
598                        returnVal = 2075;
599                    else if (SymbolID.indexOf("F---", 6) == 6)
600                        returnVal = 2084;
601                    else if (SymbolID.indexOf("FD--", 6) == 6)
602                        returnVal = 2086;
603                    else if (SymbolID.indexOf("O---", 6) == 6 || SymbolID.indexOf("OD--", 6) == 6)
604                        returnVal = 2094;
605
606                } else if (SymbolID.indexOf("WDM") == 4)// Sea Mine Decoy
607                {
608                    returnVal = 2115;
609                } else if (SymbolUtilities.getBasicSymbolID(SymbolID).equalsIgnoreCase("S*U*ND----*****")) {
610                    returnVal = 2121;
611                } //
612            }
613        } catch (Exception exc) {
614            ErrorLogger.LogException("UnitFontLookupC", "getSubSurfaceFill", exc);
615            return FillIndexUU;
616        }
617
618        return returnVal;
619    }
620
621    private static int getSeaSurfaceFrame(String SymbolID, int fillCode)
622    {
623        int returnVal = fillCode + 1;
624
625        if (SymbolUtilities.getBasicSymbolID(SymbolID).equalsIgnoreCase("S*S*O-----*****"))
626            returnVal = -1;
627        else {
628            if (SymbolID.charAt(3) == 'A' || SymbolID.charAt(3) == 'a')
629                return fillCode + 2;
630            else
631                return fillCode + 1;
632        }
633
634        return returnVal;
635    }
636
637    private static int getSubSurfaceFrame(String SymbolID, int fillCode)
638    {
639        int returnVal = 0;
640
641        returnVal = 831;
642
643        try {
644            // Special check for sea mine graphics
645            // 2525C///////////////////////////////////////////////////////////////
646            if (RendererSettings.getInstance().getSymbologyStandard() == RendererSettings.Symbology_2525C) {
647                if (SymbolID.indexOf("WM") == 4 || // Sea Mine
648                        SymbolID.indexOf("WDM") == 4 || // Sea Mine Decoy
649                        SymbolUtilities.getBasicSymbolID(SymbolID).equalsIgnoreCase("S*U*E-----*****")
650                        || SymbolUtilities.getBasicSymbolID(SymbolID).equalsIgnoreCase("S*U*V-----*****")
651                        || SymbolUtilities.getBasicSymbolID(SymbolID).equalsIgnoreCase("S*U*X-----*****")) {
652                    returnVal = -1;
653                } else if (SymbolUtilities.getBasicSymbolID(SymbolID).equalsIgnoreCase("S*U*ND----*****")) {
654                    returnVal = -1;
655                } else {
656                    if (SymbolID.charAt(3) == 'A' || SymbolID.charAt(3) == 'a')
657                        return fillCode + 2;
658                    else
659                        return fillCode + 1;
660                } //
661            } else// 2525Bch2////////////////////////////////////////////////////////
662            {
663                if (SymbolID.indexOf("WM") == 4)// Sea Mine
664                {
665                    returnVal = -1;
666
667                } else if (SymbolID.indexOf("WDM") == 4)// Sea Mine Decoy
668                {
669                    returnVal = -1;
670                } else if (SymbolUtilities.getBasicSymbolID(SymbolID).equalsIgnoreCase("S*U*ND----*****")) {
671                    returnVal = -1;
672                } //
673                else if (SymbolUtilities.getBasicSymbolID(SymbolID).equalsIgnoreCase("S*U*X-----*****")) {
674                    returnVal = -1;
675                } else {
676                    if (SymbolID.charAt(3) == 'A' || SymbolID.charAt(3) == 'a')
677                        return fillCode + 2;
678                    else
679                        return fillCode + 1;
680                }
681            }
682        } catch (Exception exc) {
683            ErrorLogger.LogException("UnitFontLookupC", "getSubSurfaceFrame", exc);
684            return fillCode;
685        }
686
687        return returnVal;
688    }
689
690    /**
691     * 
692     * @param SymbolID
693     * @return
694     * @deprecated
695     */
696    public UnitFontLookupInfo getLookupInfo(String SymbolID)
697    {
698        return getLookupInfo(SymbolID, RendererSettings.getInstance().getSymbologyStandard());
699    }
700
701    /**
702     * 
703     * @param SymbolID
704     * @param symbologyStandard
705     * @return
706     */
707    public UnitFontLookupInfo getLookupInfo(String SymbolID, int symbologyStandard)
708    {
709        UnitFontLookupInfo data = null;
710        try {
711            String code = SymbolUtilities.getBasicSymbolID(SymbolID);
712
713            if (code.length() >= 10) {
714                code = code.substring(0, 10) + "*****";
715            }
716
717            try {
718                if (symbologyStandard == RendererSettings.Symbology_2525B) {
719                    if (hashMapB.containsKey(code)) {
720                        data = hashMapB.get(code);
721                    }
722                } else {
723                    if (hashMapC.containsKey(code)) {
724                        data = hashMapC.get(code);
725                    }
726                }
727            } catch (Exception exc) {
728                Log.e("UnitFontLookup", exc.getMessage(), exc);
729
730            } catch (Throwable thrown) {
731                Log.wtf("UnitFontLookup", thrown.getMessage(), thrown);
732                Exception ex = new Exception(thrown.getMessage());
733                ErrorLogger.LogException("UnitFontLookup", "getLookupInfo(" + String.valueOf(SymbolID) + ")",
734                        ex, Level.WARNING);
735            }
736            return data;
737        } catch (Exception exc) {
738            ErrorLogger.LogException("UnitFontLookup", "getLookupInfo(" + String.valueOf(SymbolID) + ")", exc,
739                    Level.WARNING);
740            return null;
741        }
742    }
743
744    /**
745     *
746     * @param charIndex - Fill Character Index
747     * @return
748     */
749    public static float getUnitRatioHeight(int charIndex)
750    {
751        int characterIndex = charIndex - 57000;
752
753        if (characterIndex == FillIndexHP || characterIndex == FillIndexHA || characterIndex == FillIndexHU
754                || characterIndex == (FillIndexHU + 1) || characterIndex == (FillIndexHU + 2)
755                || characterIndex == FillIndexUP || characterIndex == FillIndexUA
756                || characterIndex == FillIndexUU || characterIndex == (FillIndexUU + 1)
757                || characterIndex == (FillIndexUU + 2)) {
758            return 1.3f;
759        } else if (characterIndex == FillIndexHZ || characterIndex == FillIndexHG
760                || characterIndex == FillIndexHGE || characterIndex == FillIndexHS
761                || characterIndex == FillIndexHF || characterIndex == FillIndexUZ
762                || characterIndex == FillIndexUG || characterIndex == FillIndexUGE
763                || characterIndex == FillIndexUS || characterIndex == FillIndexUF) {
764            return 1.44f;
765        } else if (characterIndex == FillIndexFGE || characterIndex == FillIndexFP
766                || characterIndex == FillIndexFA || characterIndex == FillIndexFU
767                || characterIndex == (FillIndexFU + 1) || characterIndex == (FillIndexFU + 2)
768                || characterIndex == FillIndexFZ || characterIndex == FillIndexFS
769                || characterIndex == FillIndexNP || characterIndex == FillIndexNA
770                || characterIndex == FillIndexNU || characterIndex == (FillIndexNU + 1)
771                || characterIndex == (FillIndexNU + 2)) {
772            return 1.2f;
773        } else if (characterIndex == FillIndexNZ || characterIndex == FillIndexNG
774                || characterIndex == FillIndexNGE || characterIndex == FillIndexNS
775                || characterIndex == FillIndexNF) {
776            return 1.1f;
777        } else if (characterIndex == FillIndexFG || characterIndex == FillIndexFGE) {
778            return 1.0f;
779        } else {
780            return 1.2f;
781        }
782    }
783
784    /**
785     *
786     * @param charIndex - Fill Character Index
787     * @return
788     */
789    public static float getUnitRatioWidth(int charIndex)
790    {
791        int characterIndex = charIndex - 57000;
792        if (characterIndex == FillIndexUP || characterIndex == FillIndexUA || characterIndex == FillIndexUU
793                || characterIndex == FillIndexUU + 1 || characterIndex == FillIndexUU + 2
794                || characterIndex == FillIndexFG || characterIndex == FillIndexFF) {
795            return 1.5f;
796        } else if (characterIndex == FillIndexHZ || characterIndex == FillIndexHG
797                || characterIndex == FillIndexHGE || characterIndex == FillIndexHS
798                || characterIndex == FillIndexHF || characterIndex == FillIndexUZ
799                || characterIndex == FillIndexUG || characterIndex == FillIndexUGE
800                || characterIndex == FillIndexUS || characterIndex == FillIndexUF) {
801            return 1.44f;
802        } else if (characterIndex == FillIndexFZ || characterIndex == FillIndexFGE
803                || characterIndex == FillIndexFS) {
804            return 1.2f;
805        } else {
806            return 1.1f;
807        }
808    }
809
810    /*
811     * public static void main(String args[]) { int mapping =
812     * UnitFontLookup.instance().getCharCodeFromSymbol("G*FPPTN---****X"); String junk = ""; }
813     */
814
815    private void readBinary(DataInputStream dis) throws IOException
816    {
817        int count = dis.readInt();
818        for (int i = 0; i < count; i++) {
819            UnitFontLookupInfo def = UnitFontLookupInfo.readBinary(dis);
820            hashMapB.put(def._SymbolID, def);
821        }
822
823        count = dis.readInt();
824        for (int i = 0; i < count; i++) {
825            UnitFontLookupInfo def = UnitFontLookupInfo.readBinary(dis);
826            hashMapC.put(def._SymbolID, def);
827        }
828    }
829}