Example #1
0
 /**
  * This will get the width of a character.
  *
  * @param name The character to get the width for.
  * @return The width of the character.
  * @throws IOException If this AFM file does not handle the character.
  */
 public float getCharacterWidth(String name) throws IOException {
   float result = 0;
   CharMetric metric = (CharMetric) charMetricsMap.get(name);
   if (metric == null) {
     result = 0;
     // don't throw an exception right away.
     // throw new IOException( "Unknown AFM(" + getFullName() + ") characer '" + name + "'" );
   } else {
     result = metric.getWx();
   }
   return result;
 }
Example #2
0
 /**
  * This will get the width of a character.
  *
  * @param name The character to get the width for.
  * @return The width of the character.
  * @throws IOException If this AFM file does not handle the character.
  */
 public float getCharacterHeight(String name) throws IOException {
   float result = 0;
   CharMetric metric = charMetricsMap.get(name);
   if (metric == null) {
     result = 0;
     // don't throw an exception right away.
     // throw new IOException( "Unknown AFM(" + getFullName() + ") characer '" + name + "'" );
   } else {
     if (metric.getWy() == 0) {
       result = metric.getBoundingBox().getHeight();
     } else {
       result = metric.getWy();
     }
   }
   return result;
 }
Example #3
0
  /**
   * This will get the average width of a character.
   *
   * @return The width of the character.
   * @throws IOException If this AFM file does not handle the character.
   */
  public float getAverageCharacterWidth() throws IOException {
    float average = 0;
    float totalWidths = 0;
    float characterCount = 0;
    Iterator iter = charMetricsMap.values().iterator();
    while (iter.hasNext()) {
      CharMetric metric = (CharMetric) iter.next();
      if (metric.getWx() > 0) {
        totalWidths += metric.getWx();
        characterCount += 1;
      }
    }
    if (totalWidths > 0) {
      average = totalWidths / characterCount;
    }

    return average;
  }
Example #4
0
 /**
  * This will add another character metric.
  *
  * @param metric The character metric to add.
  */
 public void addCharMetric(CharMetric metric) {
   charMetrics.add(metric);
   charMetricsMap.put(metric.getName(), metric);
 }