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.LinkedHashMap;
   21   import java.util.Map;
   22   
   23   /**
   24    * This class represents a CFF operator.
   25    * @author Villu Ruusmann
   26    * @version $Revision: 1.0 $
   27    */
   28   public class CFFOperator
   29   {
   30   
   31       private Key operatorKey = null;
   32       private String operatorName = null;
   33   
   34       private CFFOperator(Key key, String name)
   35       {
   36           setKey(key);
   37           setName(name);
   38       }
   39   
   40       /**
   41        * The key of the operator.
   42        * @return the key
   43        */
   44       public Key getKey()
   45       {
   46           return operatorKey;
   47       }
   48   
   49       private void setKey(Key key)
   50       {
   51           operatorKey = key;
   52       }
   53   
   54       /**
   55        * The name of the operator.
   56        * @return the name
   57        */
   58       public String getName()
   59       {
   60           return operatorName;
   61       }
   62   
   63       private void setName(String name)
   64       {
   65           operatorName = name;
   66       }
   67   
   68       /**
   69        * {@inheritDoc}
   70        */
   71       public String toString()
   72       {
   73           return getName();
   74       }
   75   
   76       /**
   77        * {@inheritDoc}
   78        */
   79       public int hashCode()
   80       {
   81           return getKey().hashCode();
   82       }
   83   
   84       /**
   85        * {@inheritDoc}
   86        */
   87       public boolean equals(Object object)
   88       {
   89           if (object instanceof CFFOperator)
   90           {
   91               CFFOperator that = (CFFOperator) object;
   92               return getKey().equals(that.getKey());
   93           }
   94           return false;
   95       }
   96   
   97       private static void register(Key key, String name)
   98       {
   99           CFFOperator operator = new CFFOperator(key, name);
  100           keyMap.put(key, operator);
  101           nameMap.put(name, operator);
  102       }
  103   
  104       /**
  105        * Returns the operator corresponding to the given key.
  106        * @param key the given key
  107        * @return the corresponding operator
  108        */
  109       public static CFFOperator getOperator(Key key)
  110       {
  111           return keyMap.get(key);
  112       }
  113   
  114       /**
  115        * Returns the operator corresponding to the given name.
  116        * @param key the given name
  117        * @return the corresponding operator
  118        */
  119       public static CFFOperator getOperator(String name)
  120       {
  121           return nameMap.get(name);
  122       }
  123   
  124       /**
  125        * This class is a holder for a key value. It consists of one or two bytes.  
  126        * @author Villu Ruusmann
  127        */
  128       public static class Key
  129       {
  130           private int[] value = null;
  131   
  132           /**
  133            * Constructor.
  134            * @param b0 the one byte value
  135            */
  136           public Key(int b0)
  137           {
  138               this(new int[] { b0 });
  139           }
  140   
  141           /**
  142            * Constructor.
  143            * @param b0 the first byte of a two byte value
  144            * @param b1 the second byte of a two byte value
  145            */
  146           public Key(int b0, int b1)
  147           {
  148               this(new int[] { b0, b1 });
  149           }
  150   
  151           private Key(int[] value)
  152           {
  153               setValue(value);
  154           }
  155   
  156           /**
  157            * Returns the value of the key.
  158            * @return the value
  159            */
  160           public int[] getValue()
  161           {
  162               return value;
  163           }
  164   
  165           private void setValue(int[] value)
  166           {
  167               this.value = value;
  168           }
  169   
  170           /**
  171            * {@inheritDoc}
  172            */
  173           public String toString()
  174           {
  175               return Arrays.toString(getValue());
  176           }
  177   
  178           /**
  179            * {@inheritDoc}
  180            */
  181           public int hashCode()
  182           {
  183               return Arrays.hashCode(getValue());
  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                   return Arrays.equals(getValue(), that.getValue());
  195               }
  196               return false;
  197           }
  198       }
  199   
  200       private static Map<CFFOperator.Key, CFFOperator> keyMap = new LinkedHashMap<CFFOperator.Key, CFFOperator>();
  201       private static Map<String, CFFOperator> nameMap = new LinkedHashMap<String, CFFOperator>();
  202   
  203       static
  204       {
  205           // Top DICT
  206           register(new Key(0), "version");
  207           register(new Key(1), "Notice");
  208           register(new Key(12, 0), "Copyright");
  209           register(new Key(2), "FullName");
  210           register(new Key(3), "FamilyName");
  211           register(new Key(4), "Weight");
  212           register(new Key(12, 1), "isFixedPitch");
  213           register(new Key(12, 2), "ItalicAngle");
  214           register(new Key(12, 3), "UnderlinePosition");
  215           register(new Key(12, 4), "UnderlineThickness");
  216           register(new Key(12, 5), "PaintType");
  217           register(new Key(12, 6), "CharstringType");
  218           register(new Key(12, 7), "FontMatrix");
  219           register(new Key(13), "UniqueID");
  220           register(new Key(5), "FontBBox");
  221           register(new Key(12, 8), "StrokeWidth");
  222           register(new Key(14), "XUID");
  223           register(new Key(15), "charset");
  224           register(new Key(16), "Encoding");
  225           register(new Key(17), "CharStrings");
  226           register(new Key(18), "Private");
  227           register(new Key(12, 20), "SyntheticBase");
  228           register(new Key(12, 21), "PostScript");
  229           register(new Key(12, 22), "BaseFontName");
  230           register(new Key(12, 23), "BaseFontBlend");
  231           register(new Key(12, 30), "ROS");
  232           register(new Key(12, 31), "CIDFontVersion");
  233           register(new Key(12, 32), "CIDFontRevision");
  234           register(new Key(12, 33), "CIDFontType");
  235           register(new Key(12, 34), "CIDCount");
  236           register(new Key(12, 35), "UIDBase");
  237           register(new Key(12, 36), "FDArray");
  238           register(new Key(12, 37), "FDSelect");
  239           register(new Key(12, 38), "FontName");
  240   
  241           // Private DICT
  242           register(new Key(6), "BlueValues");
  243           register(new Key(7), "OtherBlues");
  244           register(new Key(8), "FamilyBlues");
  245           register(new Key(9), "FamilyOtherBlues");
  246           register(new Key(12, 9), "BlueScale");
  247           register(new Key(12, 10), "BlueShift");
  248           register(new Key(12, 11), "BlueFuzz");
  249           register(new Key(10), "StdHW");
  250           register(new Key(11), "StdVW");
  251           register(new Key(12, 12), "StemSnapH");
  252           register(new Key(12, 13), "StemSnapV");
  253           register(new Key(12, 14), "ForceBold");
  254           register(new Key(12, 15), "LanguageGroup");
  255           register(new Key(12, 16), "ExpansionFactor");
  256           register(new Key(12, 17), "initialRandomSeed");
  257           register(new Key(19), "Subrs");
  258           register(new Key(20), "defaultWidthX");
  259           register(new Key(21), "nominalWidthX");
  260       }
  261   }

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