Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8091254

Add withXxx() semantics to Font to create derived versions

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 8u5
    • javafx

      I often want a font that is in some way derived from another font. To do that now is cumbersome and might be error prone and not future proof.

      Something like this has to be done:

      setFont(Font.font(getFont().getFamily(), FontWeight.BOLD, getFont().getSize()));

      It is for instance easy to forget the posture when creating a derived font, like I did above.. There might also be (this I don't know) other settings that can be set on the font but isn't in the constructor. Further it is future proof since new properties on Font can be transferred to the derived font.

      Therefor adding notation like this would be a great improvement to Font, yet it would be very easy to implement.

      Font derivedFont = font.withWeight(..);
      Font derivedFont = font.withSize(..);
      Font derivedFont = font.withFamily(..);
      Font derivedFont = font.withPosture(..);

      The contract should be that only the provided property is changed and everything else is transferred to the derived font, if possible.

      There might also be composite versions, like

      Font derivedFont = font.withWeightSize(..);

            prr Philip Race
            mgrev Mikael Grev
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Imported: