/**
 *
 *
 *
 **/

private void parseGlyph() {

int current = 0;
int [] endPtsOfContours;
int [] flags;

   for (int i =0;i<numTables;i++) {

        if (tag[i].equals("glyf") ) current = i;

   }
 
   font3d.glyphArray = new TTFGlyph[numOfGlyphs];

   for (int glyf=0;glyf<numOfGlyphs;glyf++) {
      TTFGlyph glyph = new TTFGlyph();
      font3d.glyphArray[glyf] = glyph;
   int myOffset = (int) offset[current]+offsetForGlyph[glyf]; 
   System.out.println(myOffset+" "+offsetForGlyph[glyf]+" "+(offsetForGlyph[glyf]+ (int) offset[current]));

   short numberOfContours = (short) (arrayOfByte[myOffset++] <<8 | arrayOfByte[myOffset++]) ;
   short xMin = (short) (arrayOfByte[myOffset++] <<8 | arrayOfByte[myOffset++]);   short yMin = (short) (arrayOfByte[myOffset++] << 8 |  arrayOfByte[myOffset++]); 
   short xMax = (short) (arrayOfByte[myOffset++] <<8 | arrayOfByte[myOffset++]);   short yMax = (short) (arrayOfByte[myOffset++] << 8 |  arrayOfByte[myOffset++]); 

   glyph.setInfo(numberOfContours,xMin,yMin,xMax,yMax);

//
// Simple Glyph 
//
//
   if (numberOfContours>=0) {
      endPtsOfContours = new int[numberOfContours];
      glyph.endPtsOfContours  = endPtsOfContours ;
      for (int i=0;i<numberOfContours;i++) {
         endPtsOfContours[i] = arrayOfByte[myOffset++] <<8 | arrayOfByte[myOffset++];
      }

      int instructionLength = arrayOfByte[myOffset++] <<8 | arrayOfByte[myOffset++];
      myOffset+=instructionLength; // skip instructions array

System.out.println(numberOfContours+"["+endPtsOfContours[numberOfContours-1]+"]: "+xMin+" "+yMin+" "+xMax+" "+yMax+" "+instructionLength);

      flags = new int[endPtsOfContours[numberOfContours-1]+1];
      for (int i=0;i<numberOfContours;i++) {
         int start = (i==0) ? 0 : endPtsOfContours[i-1]+1;
         for (int j=start;j<=endPtsOfContours[i];j++) {
            flags[j] =  arrayOfByte[myOffset++] ;
            int[] bitset = new int[8];
            for (int jj=0;jj<8;jj++) bitset[jj]=0x01 & flags[j]>>jj;
//            System.out.println(j+"["+flags[j]+"]: "+bitset[7]+bitset[6]+bitset[5]+bitset[4]+bitset[3]+bitset[2]+bitset[1]+bitset[0]);
            if (isBitSet(flags[j],3) ) { 
                int repeat = arrayOfByte[myOffset++] ;
                while (repeat > 0) {flags[++j] = flags[j-1];repeat--;}
            }
         }
      }

//
// Load X coordinates
//
//

      xCoordinates = new int[endPtsOfContours[numberOfContours-1]+1];
      glyph.xCoordinates = xCoordinates;
      int relative = 0;
      for (int i=0;i<numberOfContours;i++) {
         int start = (i==0) ? 0 : endPtsOfContours[i-1]+1;
         for (int j=start;j<=endPtsOfContours[i];j++) {
            if (!isBitSet(flags[j],1) ) 
               if (isBitSet(flags[j],4) ) relative += 0;
                else relative +=(short) (arrayOfByte[myOffset++] <<8 | arrayOfByte[myOffset++]);
            else 
               if (isBitSet(flags[j],4) ) relative += arrayOfByte[myOffset++] ;
               else relative += -arrayOfByte[myOffset++] ;
            xCoordinates[j] = relative;
//          System.out.println(xCoordinates[j]+" 0x"+new Integer(relative).toHexString(relative));
         }
      }

//
// Load Y coordinates
//
//
      yCoordinates = new int[endPtsOfContours[numberOfContours-1]+1];
      glyph.yCoordinates = yCoordinates;
      relative = 0;
      for (int i=0;i<numberOfContours;i++) {
         int start = (i==0) ? 0 : endPtsOfContours[i-1]+1;
         for (int j=start;j<=endPtsOfContours[i];j++) {
            if (!isBitSet(flags[j],2) )
               if (isBitSet(flags[j],5) ) relative += 0;
               else relative +=(short) (arrayOfByte[myOffset++] <<8 | arrayOfByte[myOffset++]);
            else 
               if (isBitSet(flags[j],5) ) relative += arrayOfByte[myOffset++] ;
               else  relative +=  -arrayOfByte[myOffset++] ;
            yCoordinates[j] = relative;
//          System.out.println(yCoordinates[j]+" 0x"+new Integer(relative).toHexString(relative));
//          System.out.println(i+" "+j+": "+yCoordinates[j]);
         }
      }


   }
//
//
// Composite Glyph 
//
//
   else {
    System.out.println("Composite glyph"); 


















   }

   } // end of glyf loop
}

