Save This Page
Home » pdfbox-1.1.0-src » org.apache.fontbox.cff » [javadoc | source]
    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  You may obtain a copy of the License at
    8    *
    9    *      http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    * Unless required by applicable law or agreed to in writing, software
   12    * distributed under the License is distributed on an "AS IS" BASIS,
   13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    * See the License for the specific language governing permissions and
   15    * limitations under the License.
   16    */
   17   package org.apache.fontbox.cff;
   18   
   19   import java.util.Arrays;
   20   import java.util.Collections;
   21   import java.util.LinkedHashMap;
   22   import java.util.Map;
   23   
   24   /**
   25    * This class represents a CharStringCommand.
   26    * 
   27    * @author Villu Ruusmann
   28    * @version $Revision$
   29    */
   30   public class CharStringCommand
   31   {
   32   
   33       private Key commandKey = null;
   34   
   35       /**
   36        * Constructor with one value.
   37        * 
   38        * @param b0 value
   39        */
   40       public CharStringCommand(int b0)
   41       {
   42           setKey(new Key(b0));
   43       }
   44   
   45       /**
   46        * Constructor with two values.
   47        * 
   48        * @param b0 value1
   49        * @param b1 value2
   50        */
   51       public CharStringCommand(int b0, int b1)
   52       {
   53           setKey(new Key(b0, b1));
   54       }
   55   
   56       /**
   57        * Constructor with an array as values.
   58        * 
   59        * @param values array of values
   60        */
   61       public CharStringCommand(int[] values)
   62       {
   63           setKey(new Key(values));
   64       }
   65   
   66       /**
   67        * The key of the CharStringCommand.
   68        * @return the key
   69        */
   70       public Key getKey()
   71       {
   72           return commandKey;
   73       }
   74   
   75       private void setKey(Key key)
   76       {
   77           commandKey = key;
   78       }
   79   
   80       /**
   81        * {@inheritDoc}
   82        */
   83       public String toString()
   84       {
   85           return getKey().toString();
   86       }
   87   
   88       /**
   89        * {@inheritDoc}
   90        */
   91       public int hashCode()
   92       {
   93           return getKey().hashCode();
   94       }
   95   
   96       /**
   97        * {@inheritDoc}
   98        */
   99       public boolean equals(Object object)
  100       {
  101           if (object instanceof CharStringCommand)
  102           {
  103               CharStringCommand that = (CharStringCommand) object;
  104               return getKey().equals(that.getKey());
  105           }
  106           return false;
  107       }
  108   
  109       /**
  110        * A static class to hold one or more int values as key. 
  111        */
  112       public static class Key
  113       {
  114   
  115           private int[] keyValues = null;
  116   
  117           /**
  118            * Constructor with one value.
  119            * 
  120            * @param b0 value
  121            */
  122           public Key(int b0)
  123           {
  124               setValue(new int[] { b0 });
  125           }
  126   
  127           /**
  128            * Constructor with two values.
  129            * 
  130            * @param b0 value1
  131            * @param b1 value2
  132            */
  133           public Key(int b0, int b1)
  134           {
  135               setValue(new int[] { b0, b1 });
  136           }
  137   
  138           /**
  139            * Constructor with an array as values.
  140            * 
  141            * @param values array of values
  142            */
  143           public Key(int[] values)
  144           {
  145               setValue(values);
  146           }
  147   
  148           /**
  149            * Array the with the values.
  150            * 
  151            * @return array with the values
  152            */
  153           public int[] getValue()
  154           {
  155               return keyValues;
  156           }
  157   
  158           private void setValue(int[] value)
  159           {
  160               keyValues = value;
  161           }
  162   
  163           /**
  164            * {@inheritDoc}
  165            */
  166           public String toString()
  167           {
  168               return Arrays.toString(getValue());
  169           }
  170   
  171           /**
  172            * {@inheritDoc}
  173            */
  174           public int hashCode()
  175           {
  176               if (keyValues[0] == 12)
  177               {
  178                   if (keyValues.length > 1)
  179                   {
  180                       return keyValues[0] ^ keyValues[1];
  181                   }
  182               }
  183               return keyValues[0];
  184           }
  185   
  186           /**
  187            * {@inheritDoc}
  188            */
  189           public boolean equals(Object object)
  190           {
  191               if (object instanceof Key)
  192               {
  193                   Key that = (Key) object;
  194                   if (keyValues[0] == 12 && that.keyValues[0] == 12)
  195                   {
  196                       if (keyValues.length > 1 && that.keyValues.length > 1)
  197                       {
  198                           return keyValues[1] == that.keyValues[1];
  199                       }
  200   
  201                       return keyValues.length == that.keyValues.length;
  202                   }
  203                   return keyValues[0] == that.keyValues[0];
  204               }
  205               return false;
  206           }
  207       }
  208   
  209       /**
  210        * A map with the Type1 vocabulary.
  211        */
  212       public static final Map<Key, String> TYPE1_VOCABULARY;
  213   
  214       static
  215       {
  216           Map<Key, String> map = new LinkedHashMap<Key, String>();
  217           map.put(new Key(1), "hstem");
  218           map.put(new Key(3), "vstem");
  219           map.put(new Key(4), "vmoveto");
  220           map.put(new Key(5), "rlineto");
  221           map.put(new Key(6), "hlineto");
  222           map.put(new Key(7), "vlineto");
  223           map.put(new Key(8), "rrcurveto");
  224           map.put(new Key(9), "closepath");
  225           map.put(new Key(10), "callsubr");
  226           map.put(new Key(11), "return");
  227           map.put(new Key(12), "escape");
  228           map.put(new Key(12, 0), "dotsection");
  229           map.put(new Key(12, 1), "vstem3");
  230           map.put(new Key(12, 2), "hstem3");
  231           map.put(new Key(12, 6), "seac");
  232           map.put(new Key(12, 7), "sbw");
  233           map.put(new Key(12, 12), "div");
  234           map.put(new Key(12, 16), "callothersubr");
  235           map.put(new Key(12, 17), "pop");
  236           map.put(new Key(12, 33), "setcurrentpoint");
  237           map.put(new Key(13), "hsbw");
  238           map.put(new Key(14), "endchar");
  239           map.put(new Key(21), "rmoveto");
  240           map.put(new Key(22), "hmoveto");
  241           map.put(new Key(30), "vhcurveto");
  242           map.put(new Key(31), "hvcurveto");
  243   
  244           TYPE1_VOCABULARY = Collections.unmodifiableMap(map);
  245       }
  246   
  247       /**
  248        * A map with the Type2 vocabulary.
  249        */
  250       public static final Map<Key, String> TYPE2_VOCABULARY;
  251   
  252       static
  253       {
  254           Map<Key, String> map = new LinkedHashMap<Key, String>();
  255           map.put(new Key(1), "hstem");
  256           map.put(new Key(3), "vstem");
  257           map.put(new Key(4), "vmoveto");
  258           map.put(new Key(5), "rlineto");
  259           map.put(new Key(6), "hlineto");
  260           map.put(new Key(7), "vlineto");
  261           map.put(new Key(8), "rrcurveto");
  262           map.put(new Key(10), "callsubr");
  263           map.put(new Key(11), "return");
  264           map.put(new Key(12), "escape");
  265           map.put(new Key(12, 3), "and");
  266           map.put(new Key(12, 4), "or");
  267           map.put(new Key(12, 5), "not");
  268           map.put(new Key(12, 9), "abs");
  269           map.put(new Key(12, 10), "add");
  270           map.put(new Key(12, 11), "sub");
  271           map.put(new Key(12, 12), "div");
  272           map.put(new Key(12, 14), "neg");
  273           map.put(new Key(12, 15), "eq");
  274           map.put(new Key(12, 18), "drop");
  275           map.put(new Key(12, 20), "put");
  276           map.put(new Key(12, 21), "get");
  277           map.put(new Key(12, 22), "ifelse");
  278           map.put(new Key(12, 23), "random");
  279           map.put(new Key(12, 24), "mul");
  280           map.put(new Key(12, 26), "sqrt");
  281           map.put(new Key(12, 27), "dup");
  282           map.put(new Key(12, 28), "exch");
  283           map.put(new Key(12, 29), "index");
  284           map.put(new Key(12, 30), "roll");
  285           map.put(new Key(12, 34), "hflex");
  286           map.put(new Key(12, 35), "flex");
  287           map.put(new Key(12, 36), "hflex1");
  288           map.put(new Key(12, 37), "flex1");
  289           map.put(new Key(14), "endchar");
  290           map.put(new Key(18), "hstemhm");
  291           map.put(new Key(19), "hintmask");
  292           map.put(new Key(20), "cntrmask");
  293           map.put(new Key(21), "rmoveto");
  294           map.put(new Key(22), "hmoveto");
  295           map.put(new Key(23), "vstemhm");
  296           map.put(new Key(24), "rcurveline");
  297           map.put(new Key(25), "rlinecurve");
  298           map.put(new Key(26), "vvcurveto");
  299           map.put(new Key(27), "hhcurveto");
  300           map.put(new Key(28), "shortint");
  301           map.put(new Key(29), "callgsubr");
  302           map.put(new Key(30), "vhcurveto");
  303           map.put(new Key(31), "hvcurveto");
  304   
  305           TYPE2_VOCABULARY = Collections.unmodifiableMap(map);
  306       }
  307   }

Save This Page
Home » pdfbox-1.1.0-src » org.apache.fontbox.cff » [javadoc | source]