Home » pdfbox-1.1.0-src » org.apache.fontbox.cff.charset » [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.charset;
   18   
   19   import java.util.ArrayList;
   20   import java.util.List;
   21   
   22   /**
   23    * This is the superclass for all CFFFont charsets.
   24    * 
   25    * @author Villu Ruusmann
   26    * @version $Revision$
   27    */
   28   public abstract class CFFCharset
   29   {
   30       private List<Entry> entries = new ArrayList<Entry>();
   31   
   32       /**
   33        * Determines if the charset is font specific or not.
   34        * @return if the charset is font specific
   35        */
   36       public boolean isFontSpecific()
   37       {
   38           return false;
   39       }
   40   
   41       /**
   42        * Returns the SID corresponding to the given name.
   43        * @param name the given SID
   44        * @return the corresponding SID
   45        */
   46       public int getSID(String name)
   47       {
   48           for(Entry entry : this.entries)
   49           {
   50               if((entry.entryName).equals(name))
   51               {
   52                   return entry.entrySID;
   53               }
   54           }
   55           return -1;
   56       }
   57   
   58       /**
   59        * Returns the name corresponding to the given SID.
   60        * @param sid the given SID
   61        * @return the corresponding name
   62        */
   63       public String getName(int sid)
   64       {
   65           for(Entry entry : this.entries)
   66           {
   67               if(entry.entrySID == sid)
   68               {
   69                   return entry.entryName;
   70               }
   71           }
   72           return null;
   73       }
   74   
   75       /**
   76        * Adds a new SID/name combination to the charset.
   77        * @param sid the given SID
   78        * @param name the given name
   79        */
   80       public void register(int sid, String name)
   81       {
   82           entries.add(new Entry(sid,name));
   83       }
   84   
   85       /**
   86        * A list of all entries within this charset.
   87        * @return a list of all entries
   88        */
   89       public List<Entry> getEntries()
   90       {
   91           return entries;
   92       }
   93   
   94       /**
   95        * This class represents a single SID/name mapping of the charset.
   96        *
   97        */
   98       public static class Entry
   99       {
  100           private int entrySID;
  101           private String entryName;
  102   
  103           /**
  104            * Create a new instance of Entry with the given values.
  105            * @param sid the SID
  106            * @param name the Name
  107            */
  108           protected Entry(int sid, String name) 
  109           {
  110               this.entrySID = sid;
  111               this.entryName = name;
  112           }
  113   
  114           /**
  115            * The SID of this entry.
  116            * @return the SID
  117            */
  118           public int getSID()
  119           {
  120               return entrySID;
  121           }
  122   
  123           /**
  124            * The Name of this entry.
  125            * @return the name
  126            */
  127           public String getName()
  128           {
  129               return entryName;
  130           }
  131           
  132           /**
  133            * {@inheritDoc}
  134            */
  135           public String toString()
  136           {
  137               return "[sid=" + entrySID + ", name=" + entryName + "]";
  138           }
  139       }
  140   }

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