Source for gnu.java.awt.peer.ClasspathFontPeer

   1: /* ClasspathFontPeer.java -- Font peer used by GNU Classpath.
   2:    Copyright (C) 2003, 2004 Free Software Foundation, Inc.
   3: 
   4: This file is part of GNU Classpath.
   5: 
   6: GNU Classpath is free software; you can redistribute it and/or modify
   7: it under the terms of the GNU General Public License as published by
   8: the Free Software Foundation; either version 2, or (at your option)
   9: any later version.
  10: 
  11: GNU Classpath is distributed in the hope that it will be useful, but
  12: WITHOUT ANY WARRANTY; without even the implied warranty of
  13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14: General Public License for more details.
  15: 
  16: You should have received a copy of the GNU General Public License
  17: along with GNU Classpath; see the file COPYING.  If not, write to the
  18: Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  19: 02110-1301 USA.
  20: 
  21: Linking this library statically or dynamically with other modules is
  22: making a combined work based on this library.  Thus, the terms and
  23: conditions of the GNU General Public License cover the whole
  24: combination.
  25: 
  26: As a special exception, the copyright holders of this library give you
  27: permission to link this library with independent modules to produce an
  28: executable, regardless of the license terms of these independent
  29: modules, and to copy and distribute the resulting executable under
  30: terms of your choice, provided that you also meet, for each linked
  31: independent module, the terms and conditions of the license of that
  32: module.  An independent module is a module which is not derived from
  33: or based on this library.  If you modify this library, you may extend
  34: this exception to your version of the library, but you are not
  35: obligated to do so.  If you do not wish to do so, delete this
  36: exception statement from your version. */
  37: 
  38: 
  39: package gnu.java.awt.peer;
  40: 
  41: import gnu.java.awt.ClasspathToolkit;
  42: 
  43: import java.awt.Font;
  44: import java.awt.FontMetrics;
  45: import java.awt.Toolkit;
  46: import java.awt.font.FontRenderContext;
  47: import java.awt.font.GlyphVector;
  48: import java.awt.font.LineMetrics;
  49: import java.awt.font.TextAttribute;
  50: import java.awt.font.TransformAttribute;
  51: import java.awt.geom.AffineTransform;
  52: import java.awt.geom.Rectangle2D;
  53: import java.awt.peer.FontPeer;
  54: import java.text.AttributedCharacterIterator;
  55: import java.text.CharacterIterator;
  56: import java.util.HashMap;
  57: import java.util.LinkedHashMap;
  58: import java.util.Locale;
  59: import java.util.Map;
  60: 
  61: /**
  62:  * A peer for fonts that are used inside Classpath. The purpose of
  63:  * this interface is to abstract from platform-specific font handling
  64:  * in the Classpath implementation of java.awt.Font and related
  65:  * classes.
  66:  *
  67:  * <p><b>State kept by the peer:</b> a peer is generated for each Font
  68:  * object in the default implementation. If you wish to share peers between
  69:  * fonts, you will need to subclass both ClasspathFontPeer and
  70:  * {@link ClasspathToolKit}.</p>
  71:  *
  72:  * <p><b>Thread Safety:</b> Methods of this interface may be called
  73:  * from arbitrary threads at any time. Implementations of the
  74:  * <code>ClasspathFontPeer</code> interface are required to perform
  75:  * the necessary synchronization.</p>
  76:  *
  77:  * @see java.awt.Font#getPeer
  78:  * @see java.awt.Toolkit#getFontPeer
  79:  *
  80:  * @author Sascha Brawer (brawer@dandelis.ch)
  81:  * @author Graydon Hoare (graydon@redhat.com)
  82:  */
  83: public abstract class ClasspathFontPeer
  84:   implements FontPeer
  85: {
  86: 
  87:   /*************************************************************************/
  88: 
  89:   /*
  90:    * Instance Variables
  91:    */
  92: 
  93:   /**
  94:    * The 3 names of this font. all fonts have 3 names, some of which
  95:    * may be equal:
  96:    *
  97:    * logical -- name the font was constructed from
  98:    * family  -- a designer or brand name (Helvetica)
  99:    * face -- specific instance of a design (Helvetica Regular)
 100:    *
 101:    * @see isLogicalFontName
 102:    */
 103: 
 104:   protected String logicalName;
 105:   protected String familyName;
 106:   protected String faceName;
 107: 
 108:   /**
 109:    * The font style, which is a combination (by OR-ing) of the font style
 110:    * constants PLAIN, BOLD and ITALIC, in this class.
 111:    */
 112:   protected int style;
 113: 
 114:   /**
 115:    * The font point size. A point is 1/72 of an inch.
 116:    */
 117:   protected float size;
 118: 
 119:   /**
 120:    * The affine transformation the font is currently subject to.
 121:    */
 122:   protected AffineTransform transform;
 123: 
 124:   static class LRUCache<K,V> extends LinkedHashMap<K,V>
 125:   {
 126:     int max_entries;
 127:     public LRUCache(int max)
 128:     {
 129:       super(max, 0.75f, true);
 130:       max_entries = max;
 131:     }
 132:     protected boolean removeEldestEntry(Map.Entry eldest)
 133:     {
 134:       return size() > max_entries;
 135:     }
 136:   }
 137: 
 138:   private static LRUCache<AffineTransform,TransformAttribute> transCache =
 139:     new LRUCache<AffineTransform,TransformAttribute>(50);
 140: 
 141:   protected static ClasspathToolkit tk()
 142:   {
 143:     return (ClasspathToolkit)(Toolkit.getDefaultToolkit ());
 144:   }
 145: 
 146:   /*
 147:    * Confusingly, a Logical Font is a concept unrelated to
 148:    * a Font's Logical Name.
 149:    *
 150:    * A Logical Font is one of 6 built-in, abstract font types
 151:    * which must be supported by any java environment: SansSerif,
 152:    * Serif, Monospaced, Dialog, and DialogInput.
 153:    *
 154:    * A Font's Logical Name is the name the font was constructed
 155:    * from. This might be the name of a Logical Font, or it might
 156:    * be the name of a Font Face.
 157:    */
 158: 
 159:   protected static boolean isLogicalFontName(String name)
 160:   {
 161:     String uname = name.toUpperCase ();
 162:     return (uname.equals ("SANSSERIF") ||
 163:             uname.equals ("SERIF") ||
 164:             uname.equals ("MONOSPACED") ||
 165:             uname.equals ("DIALOG") ||
 166:             uname.equals ("DIALOGINPUT") ||
 167:             uname.equals ("DEFAULT"));
 168:   }
 169: 
 170:   protected static String logicalFontNameToFaceName (String name)
 171:   {
 172:     String uname = name.toUpperCase ();
 173:     if (uname.equals("SANSSERIF"))
 174:       return "Helvetica";
 175:     else if (uname.equals ("SERIF"))
 176:       return "Times";
 177:     else if (uname.equals ("MONOSPACED"))
 178:       return "Courier";
 179:     else if (uname.equals ("DIALOG"))
 180:       return "Helvetica";
 181:     else if (uname.equals ("DIALOGINPUT"))
 182:       return "Helvetica";
 183:     else if (uname.equals ("DEFAULT"))
 184:       return "Dialog.plain";
 185:     else
 186:       return "Helvetica";
 187:   }
 188: 
 189:   protected static String faceNameToFamilyName (String name)
 190:   {
 191:     return name;
 192:   }
 193: 
 194:   public static void copyStyleToAttrs (int style, Map attrs)
 195:   {
 196:     if ((style & Font.BOLD) == Font.BOLD)
 197:       attrs.put (TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD);
 198:     else
 199:       attrs.put (TextAttribute.WEIGHT, TextAttribute.WEIGHT_REGULAR);
 200: 
 201:     if ((style & Font.ITALIC) == Font.ITALIC)
 202:       attrs.put (TextAttribute.POSTURE, TextAttribute.POSTURE_OBLIQUE);
 203:     else
 204:       attrs.put (TextAttribute.POSTURE, TextAttribute.POSTURE_REGULAR);
 205:   }
 206: 
 207:   protected static void copyFamilyToAttrs (String fam, Map attrs)
 208:   {
 209:     if (fam != null)
 210:       attrs.put (TextAttribute.FAMILY, fam);
 211:   }
 212: 
 213:   public static void copySizeToAttrs (float size, Map attrs)
 214:   {
 215:     attrs.put (TextAttribute.SIZE, new Float (size));
 216:   }
 217: 
 218:   protected static void copyTransformToAttrs (AffineTransform trans, Map attrs)
 219:   {
 220:     if (trans != null)
 221:       {
 222:         TransformAttribute ta;
 223:         synchronized(transCache)
 224:           {
 225:             ta = transCache.get(trans);
 226:             if (ta == null)
 227:               {
 228:                 ta = new TransformAttribute(trans);
 229:                 transCache.put(trans, ta);
 230:               }
 231:           }
 232:         attrs.put(TextAttribute.TRANSFORM, ta);
 233:       }
 234:   }
 235: 
 236: 
 237:   protected void setStandardAttributes (String name, String family, int style,
 238:                                         float size, AffineTransform trans)
 239:   {
 240:     this.logicalName = name;
 241: 
 242:     if (isLogicalFontName (name))
 243:       this.faceName = logicalFontNameToFaceName (name);
 244:     else
 245:       this.faceName = name;
 246: 
 247:     if (family != null)
 248:       this.familyName = family;
 249:     else
 250:       this.familyName = faceNameToFamilyName (faceName);
 251: 
 252:     this.style = style;
 253:     this.size = size;
 254:     this.transform = trans;
 255:   }
 256: 
 257: 
 258:   protected void setStandardAttributes (String name, Map attribs)
 259:   {
 260:     String family = this.familyName;
 261:     AffineTransform trans = this.transform;
 262:     float size = this.size;
 263:     int style = this.style;
 264: 
 265:     if (attribs.containsKey (TextAttribute.FAMILY))
 266:       family = (String) attribs.get (TextAttribute.FAMILY);
 267: 
 268:     if (name == null)
 269:       name = "Default";
 270: 
 271:     if (attribs.containsKey (TextAttribute.WEIGHT))
 272:       {
 273:         Float weight = (Float) attribs.get (TextAttribute.WEIGHT);
 274:         if (weight.floatValue () >= TextAttribute.WEIGHT_BOLD.floatValue ())
 275:           style += Font.BOLD;
 276:       }
 277: 
 278:     if (attribs.containsKey (TextAttribute.POSTURE))
 279:       {
 280:         Float posture = (Float) attribs.get (TextAttribute.POSTURE);
 281:         if (posture.floatValue () >= TextAttribute.POSTURE_OBLIQUE.floatValue ())
 282:           style += Font.ITALIC;
 283:       }
 284: 
 285:     if (attribs.containsKey (TextAttribute.SIZE))
 286:       {
 287:         Float sz = (Float) attribs.get (TextAttribute.SIZE);
 288:         size = sz.floatValue ();
 289: 
 290:         // Pango doesn't accept 0 as a font size.
 291:         if (size < 1)
 292:           size = 1;
 293:       }
 294:     else
 295:       size = 12;
 296: 
 297:     if (attribs.containsKey (TextAttribute.TRANSFORM))
 298:       {
 299:         TransformAttribute ta = (TransformAttribute)
 300:           attribs.get(TextAttribute.TRANSFORM);
 301:         trans = ta.getTransform ();
 302:       }
 303: 
 304:     setStandardAttributes (name, family, style, size, trans);
 305:   }
 306: 
 307:   protected void getStandardAttributes (Map attrs)
 308:   {
 309:     copyFamilyToAttrs (this.familyName, attrs);
 310:     copySizeToAttrs (this.size, attrs);
 311:     copyStyleToAttrs (this.style, attrs);
 312:     copyTransformToAttrs (this.transform, attrs);
 313:   }
 314: 
 315: 
 316:   /* Begin public API */
 317: 
 318:   public ClasspathFontPeer (String name, Map attrs)
 319:   {
 320:     setStandardAttributes (name, attrs);
 321:   }
 322: 
 323:   public ClasspathFontPeer (String name, int style, int size)
 324:   {
 325:     setStandardAttributes (name, (String)null, style,
 326:                            (float)size, (AffineTransform)null);
 327:   }
 328: 
 329:   /**
 330:    * Implementation of {@link Font#getName}
 331:    *
 332:    * @param font the font this peer is being called from. This may be
 333:    * useful if you are sharing peers between Font objects. Otherwise it may
 334:    * be ignored.
 335:    */
 336: 
 337:   public String getName (Font font)
 338:   {
 339:     return logicalName;
 340:   }
 341: 
 342:   /**
 343:    * Implementation of {@link Font#getFamily()}
 344:    *
 345:    * @param font the font this peer is being called from. This may be
 346:    * useful if you are sharing peers between Font objects. Otherwise it may
 347:    * be ignored.
 348:    */
 349: 
 350:   public String getFamily (Font font)
 351:   {
 352:     return familyName;
 353:   }
 354: 
 355:   /**
 356:    * Implementation of {@link Font#getFamily(Locale)}
 357:    *
 358:    * @param font the font this peer is being called from. This may be
 359:    * useful if you are sharing peers between Font objects. Otherwise it may
 360:    * be ignored.
 361:    */
 362: 
 363:   public String getFamily (Font font, Locale lc)
 364:   {
 365:     return familyName;
 366:   }
 367: 
 368:   /**
 369:    * Implementation of {@link Font#getFontName()}
 370:    *
 371:    * @param font the font this peer is being called from. This may be
 372:    * useful if you are sharing peers between Font objects. Otherwise it may
 373:    * be ignored.
 374:    */
 375: 
 376:   public String getFontName (Font font)
 377:   {
 378:     return faceName;
 379:   }
 380: 
 381:   /**
 382:    * Implementation of {@link Font#getFontName(Locale)}
 383:    *
 384:    * @param font the font this peer is being called from. This may be
 385:    * useful if you are sharing peers between Font objects. Otherwise it may
 386:    * be ignored.
 387:    */
 388: 
 389:   public String getFontName (Font font, Locale lc)
 390:   {
 391:     return faceName;
 392:   }
 393: 
 394:   /**
 395:    * Implementation of {@link Font#getSize}
 396:    *
 397:    * @param font the font this peer is being called from. This may be
 398:    * useful if you are sharing peers between Font objects. Otherwise it may
 399:    * be ignored.
 400:    */
 401: 
 402:   public float getSize (Font font)
 403:   {
 404:     return size;
 405:   }
 406: 
 407:   /**
 408:    * Implementation of {@link Font#isPlain}
 409:    *
 410:    * @param font the font this peer is being called from. This may be
 411:    * useful if you are sharing peers between Font objects. Otherwise it may
 412:    * be ignored.
 413:    */
 414: 
 415:   public boolean isPlain (Font font)
 416:   {
 417:     return style == Font.PLAIN;
 418:   }
 419: 
 420:   /**
 421:    * Implementation of {@link Font#isBold}
 422:    *
 423:    * @param font the font this peer is being called from. This may be
 424:    * useful if you are sharing peers between Font objects. Otherwise it may
 425:    * be ignored.
 426:    */
 427: 
 428:   public boolean isBold (Font font)
 429:   {
 430:     return ((style & Font.BOLD) == Font.BOLD);
 431:   }
 432: 
 433:   /**
 434:    * Implementation of {@link Font#isItalic}
 435:    *
 436:    * @param font the font this peer is being called from. This may be
 437:    * useful if you are sharing peers between Font objects. Otherwise it may
 438:    * be ignored.
 439:    */
 440: 
 441:   public boolean isItalic (Font font)
 442:   {
 443:     return ((style & Font.ITALIC) == Font.ITALIC);
 444:   }
 445: 
 446:   /**
 447:    * Implementation of {@link Font#deriveFont(int, float)}
 448:    *
 449:    * @param font the font this peer is being called from. This may be
 450:    * useful if you are sharing peers between Font objects. Otherwise it may
 451:    * be ignored.
 452:    */
 453: 
 454:   public Font deriveFont (Font font, int style, float size)
 455:   {
 456:     Map attrs = new HashMap ();
 457:     getStandardAttributes (attrs);
 458:     copyStyleToAttrs (style, attrs);
 459:     copySizeToAttrs (size, attrs);
 460:     return tk().getFont (logicalName, attrs);
 461:   }
 462: 
 463:   /**
 464:    * Implementation of {@link Font#deriveFont(float)}
 465:    *
 466:    * @param font the font this peer is being called from. This may be
 467:    * useful if you are sharing peers between Font objects. Otherwise it may
 468:    * be ignored.
 469:    */
 470: 
 471:   public Font deriveFont (Font font, float size)
 472:   {
 473:     Map attrs = new HashMap ();
 474:     getStandardAttributes (attrs);
 475:     copySizeToAttrs (size, attrs);
 476:     return tk().getFont (logicalName, attrs);
 477:   }
 478: 
 479:   /**
 480:    * Implementation of {@link Font#deriveFont(int)}
 481:    *
 482:    * @param font the font this peer is being called from. This may be
 483:    * useful if you are sharing peers between Font objects. Otherwise it may
 484:    * be ignored.
 485:    */
 486: 
 487:   public Font deriveFont (Font font, int style)
 488:   {
 489:     Map attrs = new HashMap ();
 490:     getStandardAttributes (attrs);
 491:     copyStyleToAttrs (style, attrs);
 492:     return tk().getFont (logicalName, attrs);
 493:   }
 494: 
 495:   /**
 496:    * Implementation of {@link Font#deriveFont(int, AffineTransform)}
 497:    *
 498:    * @param font the font this peer is being called from. This may be
 499:    * useful if you are sharing peers between Font objects. Otherwise it may
 500:    * be ignored.
 501:    */
 502: 
 503:   public Font deriveFont (Font font, int style, AffineTransform t)
 504:   {
 505:     Map attrs = new HashMap ();
 506:     getStandardAttributes (attrs);
 507:     copyStyleToAttrs (style, attrs);
 508:     copyTransformToAttrs (t, attrs);
 509:     return tk().getFont (logicalName, attrs);
 510:   }
 511: 
 512:   /**
 513:    * Implementation of {@link Font#deriveFont(AffineTransform)}
 514:    *
 515:    * @param font the font this peer is being called from. This may be
 516:    * useful if you are sharing peers between Font objects. Otherwise it may
 517:    * be ignored.
 518:    */
 519: 
 520:   public Font deriveFont (Font font, AffineTransform t)
 521:   {
 522:     Map attrs = new HashMap ();
 523:     getStandardAttributes (attrs);
 524:     copyTransformToAttrs (t, attrs);
 525:     return tk().getFont (logicalName, attrs);
 526:   }
 527: 
 528:   /**
 529:    * Implementation of {@link Font#deriveFont(Map)}
 530:    *
 531:    * @param font the font this peer is being called from. This may be
 532:    * useful if you are sharing peers between Font objects. Otherwise it may
 533:    * be ignored.
 534:    */
 535: 
 536:   public Font deriveFont (Font font, Map attrs)
 537:   {
 538:     return tk().getFont (logicalName, attrs);
 539:   }
 540: 
 541:   /**
 542:    * Implementation of {@link Font#getAttributes()}
 543:    *
 544:    * @param font the font this peer is being called from. This may be
 545:    * useful if you are sharing peers between Font objects. Otherwise it may
 546:    * be ignored.
 547:    */
 548: 
 549:   public Map getAttributes (Font font)
 550:   {
 551:     HashMap h = new HashMap ();
 552:     getStandardAttributes (h);
 553:     return h;
 554:   }
 555: 
 556:   /**
 557:    * Implementation of {@link Font#getAvailableAttributes()}
 558:    *
 559:    * @param font the font this peer is being called from. This may be
 560:    * useful if you are sharing peers between Font objects. Otherwise it may
 561:    * be ignored.
 562:    */
 563: 
 564:   public AttributedCharacterIterator.Attribute[] getAvailableAttributes(Font font)
 565:   {
 566:     AttributedCharacterIterator.Attribute a[] =
 567:       new AttributedCharacterIterator.Attribute[5];
 568:     a[0] = TextAttribute.FAMILY;
 569:     a[1] = TextAttribute.SIZE;
 570:     a[2] = TextAttribute.POSTURE;
 571:     a[3] = TextAttribute.WEIGHT;
 572:     a[4] = TextAttribute.TRANSFORM;
 573:     return a;
 574:   }
 575: 
 576:   /**
 577:    * Implementation of {@link Font#getTransform()}
 578:    *
 579:    * @param font the font this peer is being called from. This may be
 580:    * useful if you are sharing peers between Font objects. Otherwise it may
 581:    * be ignored.
 582:    */
 583: 
 584:   public AffineTransform getTransform (Font font)
 585:   {
 586:     if (transform == null)
 587:       transform = new AffineTransform ();
 588:     return transform;
 589:   }
 590: 
 591:   /**
 592:    * Implementation of {@link Font#isTransformed()}
 593:    *
 594:    * @param font the font this peer is being called from. This may be
 595:    * useful if you are sharing peers between Font objects. Otherwise it may
 596:    * be ignored.
 597:    */
 598: 
 599:   public boolean isTransformed (Font font)
 600:   {
 601:     return ! transform.isIdentity ();
 602:   }
 603: 
 604:   /**
 605:    * Implementation of {@link Font#getItalicAngle()}
 606:    *
 607:    * @param font the font this peer is being called from. This may be
 608:    * useful if you are sharing peers between Font objects. Otherwise it may
 609:    * be ignored.
 610:    */
 611: 
 612:   public float getItalicAngle (Font font)
 613:   {
 614:     if ((style & Font.ITALIC) == Font.ITALIC)
 615:       return TextAttribute.POSTURE_OBLIQUE.floatValue ();
 616:     else
 617:       return TextAttribute.POSTURE_REGULAR.floatValue ();
 618:   }
 619: 
 620: 
 621:   /**
 622:    * Implementation of {@link Font#getStyle()}
 623:    *
 624:    * @param font the font this peer is being called from. This may be
 625:    * useful if you are sharing peers between Font objects. Otherwise it may
 626:    * be ignored.
 627:    */
 628: 
 629:   public int getStyle (Font font)
 630:   {
 631:     return style;
 632:   }
 633: 
 634: 
 635: 
 636: 
 637:   /* Remaining methods are abstract */
 638: 
 639:   /**
 640:    * Implementation of {@link Font#canDisplay(char)}
 641:    *
 642:    * @param font the font this peer is being called from. This may be
 643:    * useful if you are sharing peers between Font objects. Otherwise it may
 644:    * be ignored.
 645:    */
 646: 
 647:   public abstract boolean canDisplay (Font font, int c);
 648: 
 649:   /**
 650:    * Implementation of {@link Font#canDisplay(String)},
 651:    * {@link Font#canDisplay(char [], int, int)}, and
 652:    * {@link Font#canDisplay(CharacterIterator, int, int)}.
 653:    *
 654:    * @param font the font this peer is being called from. This may be
 655:    * useful if you are sharing peers between Font objects. Otherwise it may
 656:    * be ignored.
 657:    */
 658: 
 659:   public abstract int canDisplayUpTo (Font font, CharacterIterator i, int start, int limit);
 660: 
 661: 
 662:   /**
 663:    * Returns the name of this font face inside the family, for example
 664:    * <i>&#x201c;Light&#x201d;</i>.
 665:    *
 666:    * <p>This method is currently not used by {@link Font}. However,
 667:    * this name would be needed by any serious desktop publishing
 668:    * application.
 669:    *
 670:    * @param font the font whose sub-family name is requested.
 671:    *
 672:    * @param locale the locale for which to localize the name.  If
 673:    * <code>locale</code> is <code>null</code>, the returned name is
 674:    * localized to the user&#x2019;s default locale.
 675:    *
 676:    * @return the name of the face inside its family, or
 677:    * <code>null</code> if the font does not provide a sub-family name.
 678:    */
 679: 
 680:   public abstract String getSubFamilyName (Font font, Locale locale);
 681: 
 682: 
 683:   /**
 684:    * Implementation of {@link Font#getPSName()}
 685:    *
 686:    * @param font the font this peer is being called from. This may be
 687:    * useful if you are sharing peers between Font objects. Otherwise it may
 688:    * be ignored.
 689:    */
 690: 
 691:   public abstract String getPostScriptName (Font font);
 692: 
 693: 
 694:   /**
 695:    * Implementation of {@link Font#getNumGlyphs()}
 696:    *
 697:    * @param font the font this peer is being called from. This may be
 698:    * useful if you are sharing peers between Font objects. Otherwise it may
 699:    * be ignored.
 700:    */
 701: 
 702:   public abstract int getNumGlyphs (Font font);
 703: 
 704: 
 705:   /**
 706:    * Implementation of {@link Font#getMissingGlyphCode()}
 707:    *
 708:    * @param font the font this peer is being called from. This may be
 709:    * useful if you are sharing peers between Font objects. Otherwise it may
 710:    * be ignored.
 711:    */
 712: 
 713:   public abstract int getMissingGlyphCode (Font font);
 714: 
 715: 
 716:   /**
 717:    * Implementation of {@link Font#getBaselineFor(char)}
 718:    *
 719:    * @param font the font this peer is being called from. This may be
 720:    * useful if you are sharing peers between Font objects. Otherwise it may
 721:    * be ignored.
 722:    */
 723: 
 724:   public abstract byte getBaselineFor (Font font, char c);
 725: 
 726: 
 727:   /**
 728:    * Returns a name for the specified glyph. This is useful for
 729:    * generating PostScript or PDF files that embed some glyphs of a
 730:    * font. If the implementation follows glyph naming conventions
 731:    * specified by Adobe, search engines can extract the original text
 732:    * from the generated PostScript and PDF files.
 733:    *
 734:    * <p>This method is currently not used by GNU Classpath. However,
 735:    * it would be very useful for someone wishing to write a good
 736:    * PostScript or PDF stream provider for the
 737:    * <code>javax.print</code> package.
 738:    *
 739:    * <p><b>Names are not unique:</b> Under some rare circumstances,
 740:    * the same name can be returned for different glyphs. It is
 741:    * therefore recommended that printer drivers check whether the same
 742:    * name has already been returned for antoher glyph, and make the
 743:    * name unique by adding the string ".alt" followed by the glyph
 744:    * index.</p>
 745:    *
 746:    * <p>This situation would occur for an OpenType or TrueType font
 747:    * that has a <code>post</code> table of format 3 and provides a
 748:    * mapping from glyph IDs to Unicode sequences through a
 749:    * <code>Zapf</code> table. If the same sequence of Unicode
 750:    * codepoints leads to different glyphs (depending on contextual
 751:    * position, for example, or on typographic sophistication level),
 752:    * the same name would get synthesized for those glyphs. To avoid
 753:    * this, the font peer would have to go through the names of all
 754:    * glyphs, which would make this operation very inefficient with
 755:    * large fonts.
 756:    *
 757:    * @param font the font containing the glyph whose name is
 758:    * requested.
 759:    *
 760:    * @param glyphIndex the glyph whose name the caller wants to
 761:    * retrieve.
 762:    *
 763:    * @return the glyph name, or <code>null</code> if a font does not
 764:    * provide glyph names.
 765:    */
 766: 
 767:   public abstract String getGlyphName (Font font, int glyphIndex);
 768: 
 769: 
 770:   /**
 771:    * Implementation of {@link
 772:    * Font#createGlyphVector(FontRenderContext, String)}, {@link
 773:    * Font#createGlyphVector(FontRenderContext, char[])}, and {@link
 774:    * Font#createGlyphVector(FontRenderContext, CharacterIterator)}.
 775:    *
 776:    * @param font the font object that the created GlyphVector will return
 777:    * when it gets asked for its font. This argument is needed because the
 778:    * public API of {@link GlyphVector} works with {@link java.awt.Font},
 779:    * not with font peers.
 780:    */
 781: 
 782:   public abstract GlyphVector createGlyphVector (Font font,
 783:                                                  FontRenderContext frc,
 784:                                                  CharacterIterator ci);
 785: 
 786: 
 787:   /**
 788:    * Implementation of {@link Font#createGlyphVector(FontRenderContext,
 789:    * int[])}.
 790:    *
 791:    * @param font the font object that the created GlyphVector will return
 792:    * when it gets asked for its font. This argument is needed because the
 793:    * public API of {@link GlyphVector} works with {@link java.awt.Font},
 794:    * not with font peers.
 795:    */
 796: 
 797:   public abstract GlyphVector createGlyphVector (Font font,
 798:                                                  FontRenderContext ctx,
 799:                                                  int[] glyphCodes);
 800: 
 801: 
 802:   /**
 803:    * Implementation of {@link Font#layoutGlyphVector(FontRenderContext,
 804:    * char[], int, int, int)}.
 805:    *
 806:    * @param font the font object that the created GlyphVector will return
 807:    * when it gets asked for its font. This argument is needed because the
 808:    * public API of {@link GlyphVector} works with {@link java.awt.Font},
 809:    * not with font peers.
 810:    */
 811: 
 812:   public abstract GlyphVector layoutGlyphVector (Font font,
 813:                                                  FontRenderContext frc,
 814:                                                  char[] chars, int start,
 815:                                                  int limit, int flags);
 816: 
 817: 
 818:   /**
 819:    * Implementation of {@link Font#getFontMetrics()}
 820:    *
 821:    * @param font the font this peer is being called from. This may be
 822:    * useful if you are sharing peers between Font objects. Otherwise it may
 823:    * be ignored.
 824:    */
 825: 
 826:   public abstract FontMetrics getFontMetrics (Font font);
 827: 
 828: 
 829:   /**
 830:    * Implementation of {@link Font#hasUniformLineMetrics()}
 831:    *
 832:    * @param font the font this peer is being called from. This may be
 833:    * useful if you are sharing peers between Font objects. Otherwise it may
 834:    * be ignored.
 835:    */
 836: 
 837:   public abstract boolean hasUniformLineMetrics (Font font);
 838: 
 839: 
 840:   /**
 841:    * Implementation of {@link Font#getLineMetrics(CharacterIterator, int,
 842:    * int, FontRenderContext)}
 843:    *
 844:    * @param font the font this peer is being called from. This may be
 845:    * useful if you are sharing peers between Font objects. Otherwise it may
 846:    * be ignored.
 847:    */
 848: 
 849:   public abstract LineMetrics getLineMetrics (Font font,
 850:                                               CharacterIterator ci,
 851:                                               int begin, int limit,
 852:                                               FontRenderContext rc);
 853: 
 854:   /**
 855:    * Implementation of {@link Font#getMaxCharBounds(FontRenderContext)}
 856:    *
 857:    * @param font the font this peer is being called from. This may be
 858:    * useful if you are sharing peers between Font objects. Otherwise it may
 859:    * be ignored.
 860:    */
 861: 
 862:   public abstract Rectangle2D getMaxCharBounds (Font font,
 863:                                                 FontRenderContext rc);
 864: 
 865: }