use of sun.font.AttributeValues in project jdk8u_jdk by JetBrains.
the class Font method getAttributeValues.
/**
* Return the AttributeValues object associated with this
* font. Most of the time, the internal object is null.
* If required, it will be created from the 'standard'
* state on the font. Only non-default values will be
* set in the AttributeValues object.
*
* <p>Since the AttributeValues object is mutable, and it
* is cached in the font, care must be taken to ensure that
* it is not mutated.
*/
private AttributeValues getAttributeValues() {
if (values == null) {
AttributeValues valuesTmp = new AttributeValues();
valuesTmp.setFamily(name);
// expects the float value.
valuesTmp.setSize(pointSize);
if ((style & BOLD) != 0) {
// WEIGHT_BOLD
valuesTmp.setWeight(2);
}
if ((style & ITALIC) != 0) {
// POSTURE_OBLIQUE
valuesTmp.setPosture(.2f);
}
// for streaming compatibility
valuesTmp.defineAll(PRIMARY_MASK);
values = valuesTmp;
}
return values;
}
use of sun.font.AttributeValues in project jdk8u_jdk by JetBrains.
the class Font method getTransform.
/**
* Returns a copy of the transform associated with this
* <code>Font</code>. This transform is not necessarily the one
* used to construct the font. If the font has algorithmic
* superscripting or width adjustment, this will be incorporated
* into the returned <code>AffineTransform</code>.
* <p>
* Typically, fonts will not be transformed. Clients generally
* should call {@link #isTransformed} first, and only call this
* method if <code>isTransformed</code> returns true.
*
* @return an {@link AffineTransform} object representing the
* transform attribute of this <code>Font</code> object.
*/
public AffineTransform getTransform() {
/* The most common case is the identity transform. Most callers
* should call isTransformed() first, to decide if they need to
* get the transform, but some may not. Here we check to see
* if we have a nonidentity transform, and only do the work to
* fetch and/or compute it if so, otherwise we return a new
* identity transform.
*
* Note that the transform is _not_ necessarily the same as
* the transform passed in as an Attribute in a Map, as the
* transform returned will also reflect the effects of WIDTH and
* SUPERSCRIPT attributes. Clients who want the actual transform
* need to call getRequestedAttributes.
*/
if (nonIdentityTx) {
AttributeValues values = getAttributeValues();
AffineTransform at = values.isNonDefault(ETRANSFORM) ? new AffineTransform(values.getTransform()) : new AffineTransform();
if (values.getSuperscript() != 0) {
// can't get ascent and descent here, recursive call to this fn,
// so use pointsize
// let users combine super- and sub-scripting
int superscript = values.getSuperscript();
double trans = 0;
int n = 0;
boolean up = superscript > 0;
int sign = up ? -1 : 1;
int ss = up ? superscript : -superscript;
while ((ss & 7) > n) {
int newn = ss & 7;
trans += sign * (ssinfo[newn] - ssinfo[n]);
ss >>= 3;
sign = -sign;
n = newn;
}
trans *= pointSize;
double scale = Math.pow(2. / 3., n);
at.preConcatenate(AffineTransform.getTranslateInstance(0, trans));
at.scale(scale, scale);
// note on placement and italics
// We preconcatenate the transform because we don't want to translate along
// the italic angle, but purely perpendicular to the baseline. While this
// looks ok for superscripts, it can lead subscripts to stack on each other
// and bring the following text too close. The way we deal with potential
// collisions that can occur in the case of italics is by adjusting the
// horizontal spacing of the adjacent glyphvectors. Examine the italic
// angle of both vectors, if one is non-zero, compute the minimum ascent
// and descent, and then the x position at each for each vector along its
// italic angle starting from its (offset) baseline. Compute the difference
// between the x positions and use the maximum difference to adjust the
// position of the right gv.
}
if (values.isNonDefault(EWIDTH)) {
at.scale(values.getWidth(), 1f);
}
return at;
}
return new AffineTransform();
}
use of sun.font.AttributeValues in project jdk8u_jdk by JetBrains.
the class Font method deriveFont.
/**
* Creates a new <code>Font</code> object by replicating the current
* <code>Font</code> object and applying a new set of font attributes
* to it.
*
* @param attributes a map of attributes enabled for the new
* <code>Font</code>
* @return a new <code>Font</code> object.
* @since 1.2
*/
public Font deriveFont(Map<? extends Attribute, ?> attributes) {
if (attributes == null) {
return this;
}
AttributeValues newValues = getAttributeValues().clone();
newValues.merge(attributes, RECOGNIZED_MASK);
return new Font(newValues, name, style, createdFont, font2DHandle);
}
use of sun.font.AttributeValues in project jdk8u_jdk by JetBrains.
the class Font method readObject.
/**
* Reads the <code>ObjectInputStream</code>.
* Unrecognized keys or values will be ignored.
*
* @param s the <code>ObjectInputStream</code> to read
* @serial
* @see #writeObject(java.io.ObjectOutputStream)
*/
private void readObject(java.io.ObjectInputStream s) throws java.lang.ClassNotFoundException, java.io.IOException {
s.defaultReadObject();
if (pointSize == 0) {
pointSize = (float) size;
}
if (fRequestedAttributes != null) {
// init
values = getAttributeValues();
AttributeValues extras = AttributeValues.fromSerializableHashtable(fRequestedAttributes);
if (!AttributeValues.is16Hashtable(fRequestedAttributes)) {
// if legacy stream, undefine these
extras.unsetDefault();
}
values = getAttributeValues().merge(extras);
this.nonIdentityTx = values.anyNonDefault(EXTRA_MASK);
this.hasLayoutAttributes = values.anyNonDefault(LAYOUT_MASK);
// don't need it any more
fRequestedAttributes = null;
}
}
use of sun.font.AttributeValues in project jdk8u_jdk by JetBrains.
the class Font method deriveFont.
/**
* Creates a new <code>Font</code> object by replicating this
* <code>Font</code> object and applying a new style and transform.
* @param style the style for the new <code>Font</code>
* @param trans the <code>AffineTransform</code> associated with the
* new <code>Font</code>
* @return a new <code>Font</code> object.
* @throws IllegalArgumentException if <code>trans</code> is
* <code>null</code>
* @since 1.2
*/
public Font deriveFont(int style, AffineTransform trans) {
AttributeValues newValues = getAttributeValues().clone();
int oldStyle = (this.style != style) ? this.style : -1;
applyStyle(style, newValues);
applyTransform(trans, newValues);
return new Font(newValues, null, oldStyle, createdFont, font2DHandle);
}
Aggregations