home *** CD-ROM | disk | FTP | other *** search
/ com!online 2002 April / comcd0402.iso / homepage / javaspecial / 03_01 / kubik / KubikFont.java < prev    next >
Encoding:
Java Source  |  1999-05-18  |  6.3 KB  |  322 lines

  1. /**
  2.  * This class provides vertex and surface data for 3D letters.
  3.  * <P>
  4.  * author: Michael Kraus<BR>
  5.  * version: 1.2<BR>
  6.  * date: 1999/5/17<BR>
  7.  * environment: JDK 1.0.2<BR>
  8.  * email: <A href="michael.kraus@informatik.uni-muenchen.de">michael.kraus@informatik.uni-muenchen.de</A><BR>
  9.  * homepage: <A href="www.informatik.uni-muenchen.de/~michael.kraus">www.informatik.uni-muenchen.de/~michael.kraus</A>
  10.  */
  11.  
  12. public class KubikFont
  13. {
  14.     private static int X=0;
  15.     private static int Y=1;
  16.     private static int Z=2;
  17.  
  18.     private static int local[][][]=
  19.     {
  20.         {    // 'A'
  21.             {-3,-5},{3,-5},{3,5},{1,5},{1,1},{-1,1},{-1,5},{-3,5},
  22.             {-1,-3},{1,-3},{1,-1},{-1,-1}
  23.         },
  24.         {    // 'B'
  25.             {-3,-5},{3,-5},{3,-2},{1,0},{3,2},{3,5},{-3,5},
  26.             {-1,-3},{1,-3},{-1,-1},
  27.             {-1,1},{1,3},{-1,3}
  28.         },
  29.         {    // 'C'
  30.             {-3,-5},{3,-5},{3,-3},{-1,-3},{-1,3},{3,3},{3,5},
  31.             {-3,5}
  32.         },
  33.         {    // 'D'
  34.             {-3,-5},{0,-5},{4,-1},{4,1},{0,5},{-3,5},
  35.             {-1,-3},{2,0},{-1,3}
  36.         },
  37.         {    // 'E'
  38.             {-3,-5},{3,-5},{3,-3},{-1,-3},{-1,-1},{3,-1},{3,1},{-1,1},{-1,3},{3,3},{3,5},{-3,5}
  39.         },
  40.         {    // 'F'
  41.             {-3,-5},{3,-5},{3,-3},{-1,-3},{-1,-1},{3,-1},{3,1},{-1,1},{-1,5},{-3,5}
  42.         },
  43.         {    // 'G'
  44.             {-3,-5},{3,-5},{3,-3},{-1,-3},{-1,3},{1,3},{1,-1},{3,-1},{3,5},{-3,5}
  45.         },
  46.         {    // 'H'
  47.             {-3,-5},{-1,-5},{-1,-1},{1,-1},{1,-5},{3,-5},{3,5},{1,5},{1,1},{-1,1},{-1,5},{-3,5}
  48.         },
  49.         {    // 'I'
  50.             {-1,-5},{1,-5},{1,5},{-1,5}
  51.         },
  52.         {    // 'J'
  53.             {-3,1},{-1,1},{-1,3},{1,3},{1,-5},{3,-5},{3,5},{-3,5}
  54.         },
  55.         {    // 'K'
  56.             {-3,-5},{-1,-5},{-1,-1},{1,-5},{4,-5},{1,0},{4,5},{1,5},{-1,1},{-1,5},{-3,5}
  57.         },
  58.         {    // 'L'
  59.             {-3,-5},{-1,-5},{-1,3},{3,3},{3,5},{-3,5}
  60.         },
  61.         {    // 'M'
  62.             {-4,-5},{-2,-5},{0,-1},{2,-5},{4,-5},{4,5},{2,5},{2,-1},{0,3},{-2,-1},{-2,5},{-4,5}
  63.         },
  64.         {    // 'N'
  65.             {-3,-5},{-1,-5},{1,0},{1,-5},{3,-5},{3,5},{1,5},{-1,0},{-1,5},{-3,5}
  66.         },
  67.         {    // 'O'
  68.             {-3,-5},{3,-5},{3,5},{-3,5},
  69.             {-1,-3},{1,-3},{1,3},{-1,3}
  70.         },
  71.         {    // 'P'
  72.             {-3,-5},{3,-5},{3,1},{-1,1},{-1,5},{-3,5},
  73.             {-1,-3},{1,-3},{1,-1},{-1,-1}
  74.         },
  75.         {    // 'Q'
  76.             {-3,-5},{3,-5},{3,4},{4,6},{3,7},{2,5},{-3,5},
  77.             {-1,-3},{1,-3},{1,0},{0,1},{1,3},{-1,3}
  78.         },
  79.         {    // 'R'
  80.             {-3,-5},{3,-5},{3,1},{1,1},{4,5},{1,5},{-1,2},{-1,5},{-3,5},
  81.             {-1,-3},{1,-3},{1,-1},{-1,-1}
  82.         },
  83.         {    // 'S'
  84.             {-3,-5},{3,-5},{3,-3},{-1,-3},{-1,-1},{3,-1},{3,5},{-3,5},{-3,3},{1,3},{1,1},{-3,1}
  85.         },
  86.         {    // 'T'
  87.             {-3,-5},{3,-5},{3,-3},{1,-3},{1,5},{-1,5},{-1,-3},{-3,-3}
  88.         },
  89.         {    // 'U'
  90.             {-3,-5},{-1,-5},{-1,3},{1,3},{1,-5},{3,-5},{3,5},{-3,5}
  91.         },
  92.         {    // 'V'
  93.             {-3,-5},{-1,-5},{0,0},{1,-5},{3,-5},{1,5},{-1,5}
  94.         },
  95.         {    // 'W'
  96.             {-4,5},{-2,5},{0,1},{2,5},{4,5},{4,-5},{2,-5},{2,1},{0,-3},{-2,1},{-2,-5},{-4,-5}
  97.         },
  98.         {    // 'X'
  99.             {-3,-5},{-1,-5},{0,-3},{1,-5},{3,-5},{1,0},{3,5},{1,5},{0,3},{-1,5},{-3,5},{-1,0}
  100.         },
  101.         {    // 'Y'
  102.             {-3,-5},{-1,-5},{0,-3},{1,-5},{3,-5},{1,0},{1,5},{-1,5},{-1,0}
  103.         },
  104.         {    // 'Z'
  105.             {-3,-5},{3,-5},{3,-3},{0,3},{3,3},{3,5},{-3,5},{-3,3},{0,-3},{-3,-3}
  106.         }
  107.     };
  108.  
  109.     private static int surface[][][]=
  110.     {
  111.         {    // 'A'
  112.             {0,1,2,3,4,5,6,7},
  113.             {8,9,10,11}
  114.         },
  115.         {    // 'B'
  116.             {0,1,2,3,4,5,6},
  117.             {7,8,9},
  118.             {10,11,12}
  119.         },
  120.         {    // 'C'
  121.             {0,1,2,3,4,5,6,7}
  122.         },
  123.         {    // 'D'
  124.             {0,1,2,3,4,5},
  125.             {6,7,8}
  126.         },
  127.         {    // 'E'
  128.             {0,1,2,3,4,5,6,7,8,9,10,11}
  129.         },
  130.         {    // 'F'
  131.             {0,1,2,3,4,5,6,7,8,9}
  132.         },
  133.         {    // 'G'
  134.             {0,1,2,3,4,5,6,7,8,9}
  135.         },
  136.         {    // 'H'
  137.             {0,1,2,3,4,5,6,7,8,9,10,11}
  138.         },
  139.         {    // 'I'
  140.             {0,1,2,3}
  141.         },
  142.         {    // 'J'
  143.             {0,1,2,3,4,5,6,7}
  144.         },
  145.         {    // 'K'
  146.             {0,1,2,3,4,5,6,7,8,9,10}
  147.         },
  148.         {    // 'L'
  149.             {0,1,2,3,4,5}
  150.         },
  151.         {    // 'M'
  152.             {0,1,2,3,4,5,6,7,8,9,10,11}
  153.         },
  154.         {    // 'N'
  155.             {0,1,2,3,4,5,6,7,8,9}
  156.         },
  157.         {    // 'O'
  158.             {0,1,2,3},
  159.             {4,5,6,7}
  160.         },
  161.         {    // 'P'
  162.             {0,1,2,3,4,5},
  163.             {6,7,8,9}
  164.         },
  165.         {    // 'Q'
  166.             {0,1,2,3,4,5,6},
  167.             {7,8,9,10,11,12}
  168.         },
  169.         {    // 'R'
  170.             {0,1,2,3,4,5,6,7,8},
  171.             {9,10,11,12}
  172.         },
  173.         {    // 'S'
  174.             {0,1,2,3,4,5,6,7,8,9,10,11}
  175.         },
  176.         {    // 'T'
  177.             {0,1,2,3,4,5,6,7}
  178.         },
  179.         {    // 'U'
  180.             {0,1,2,3,4,5,6,7}
  181.         },
  182.         {    // 'V'
  183.             {0,1,2,3,4,5,6}
  184.         },
  185.         {    // 'W'
  186.             {0,1,2,3,4,5,6,7,8,9,10,11}
  187.         },
  188.         {    // 'X'
  189.             {0,1,2,3,4,5,6,7,8,9,10,11}
  190.         },
  191.         {    // 'Y'
  192.             {0,1,2,3,4,5,6,7,8}
  193.         },
  194.         {    // 'Z'
  195.             {0,1,2,3,4,5,6,7,8,9}
  196.         }
  197.     };
  198.  
  199.     private static int width[]=
  200.     {
  201.         6,6,6,6,6,6,6,6,2,6,6,6,8,6,6,6,6,6,6,6,6,6,8,6,6,6
  202.     };
  203.  
  204.     private static int height=10;
  205.  
  206.     private static int ZOOM=10;
  207.  
  208.     public static int SPACEWIDTH=2*ZOOM;
  209.     public static int LINEHEIGHT=(height+2)*ZOOM;
  210.  
  211.     public static int[][] getLocal(char name)
  212.     {
  213.         int n;
  214.  
  215.         int size=local[name-'A'].length;
  216.  
  217.         int newlocal[][]=new int[2*size][3];
  218.  
  219.         for(n=0;n<size;n++)
  220.         {
  221.             newlocal[n][X]=ZOOM*local[name-'A'][n][X];
  222.             newlocal[n][Y]=ZOOM*local[name-'A'][n][Y];
  223.             newlocal[n][Z]=-ZOOM;
  224.  
  225.             newlocal[n+size][X]=ZOOM*local[name-'A'][n][X];
  226.             newlocal[n+size][Y]=ZOOM*local[name-'A'][n][Y];
  227.             newlocal[n+size][Z]=ZOOM;
  228.         }
  229.  
  230.         return newlocal;
  231.     }
  232.  
  233.     public static int[][] getLocal(String string)
  234.     {
  235.         int n;
  236.         int m;
  237.         int size;
  238.         int newlocal[][];
  239.         int pointer;
  240.  
  241.         size=0;
  242.  
  243.         for(n=0;n<string.length();n++)
  244.             size+=local[string.charAt(n)-'A'].length;
  245.  
  246.         newlocal=new int[2*size][3];
  247.  
  248.         pointer=0;
  249.  
  250.         for(m=0;m<string.length();m++)
  251.             for(n=0;n<local[string.charAt(m)-'A'].length;n++)
  252.             {
  253.                 newlocal[pointer][X]=ZOOM*local[string.charAt(m)-'A'][n][X];
  254.                 newlocal[pointer][Y]=ZOOM*local[string.charAt(m)-'A'][n][Y];
  255.                 newlocal[pointer][Z]=-ZOOM;
  256.  
  257.                 newlocal[pointer+size][X]=ZOOM*local[string.charAt(m)-'A'][n][X];
  258.                 newlocal[pointer+size][Y]=ZOOM*local[string.charAt(m)-'A'][n][Y];
  259.                 newlocal[pointer+size][Z]=ZOOM;
  260.  
  261.                 pointer++;
  262.             }
  263.  
  264.         return newlocal;
  265.     }
  266.  
  267.     public static int[][] getSurface(char name)
  268.     {
  269.         int n;
  270.         int m;
  271.         int l;
  272.  
  273.         int size=surface[name-'A'].length;
  274.         int nsize;
  275.  
  276.         m=2*size;
  277.  
  278.         for(n=0;n<size;n++)
  279.             m+=surface[name-'A'][n].length;
  280.  
  281.         int newsurface[][]=new int[m][];
  282.  
  283.         for(n=0;n<size;n++)
  284.         {
  285.             nsize=surface[name-'A'][n].length;
  286.  
  287.             newsurface[n]=new int[nsize];
  288.  
  289.             for(m=0;m<nsize;m++)
  290.                 newsurface[n][m]=surface[name-'A'][n][m];
  291.  
  292.             newsurface[n+size]=new int[nsize];
  293.  
  294.             for(m=0;m<nsize;m++)
  295.                 newsurface[n+size][m]=newsurface[n][m]+local[name-'A'].length;
  296.         }
  297.  
  298.         for(l=2*size,n=0;n<size;n++)
  299.         {
  300.             nsize=newsurface[n].length;
  301.  
  302.             for(m=0;m<nsize;m++,l++)
  303.             {
  304.                 newsurface[l]=new int[4];
  305.  
  306.                 newsurface[l][0]=newsurface[n][m];
  307.                 newsurface[l][1]=newsurface[n][(m+1)%nsize];
  308.                 newsurface[l][2]=newsurface[n+size][(m+1)%nsize];
  309.                 newsurface[l][3]=newsurface[n+size][m];
  310.             }
  311.         }
  312.  
  313.         return newsurface;
  314.     }
  315.  
  316.     public static int getWidth(char name)
  317.     {
  318.         return width[name-'A']*ZOOM;
  319.     }
  320. }
  321.  
  322.