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