/** * Initialize the paragraph-specific data. */ private void paragraphInit(byte aBaseline, CoreMetrics lm, Map<? extends Attribute, ?> paragraphAttrs, char[] text) { baseline = aBaseline; // normalize to current baseline baselineOffsets = TextLine.getNormalizedOffsets(lm.baselineOffsets, baseline); justifyRatio = AttributeValues.getJustification(paragraphAttrs); NumericShaper shaper = AttributeValues.getNumericShaping(paragraphAttrs); if (shaper != null) { shaper.shape(text, 0, text.length); } }
/** * 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); valuesTmp.setSize(pointSize); // expects the float value. if ((style & BOLD) != 0) { valuesTmp.setWeight(2); // WEIGHT_BOLD } if ((style & ITALIC) != 0) { valuesTmp.setPosture(.2f); // POSTURE_OBLIQUE } valuesTmp.defineAll(PRIMARY_MASK); // for streaming compatibility values = valuesTmp; } return values; }
private Font(AttributeValues values, String oldName, int oldStyle, boolean created, Font2DHandle handle) { this.createdFont = created; if (created) { this.font2DHandle = handle; String newName = null; if (oldName != null) { newName = values.getFamily(); if (oldName.equals(newName)) newName = null; } int newStyle = 0; if (oldStyle == -1) { newStyle = -1; } else { if (values.getWeight() >= 2f) newStyle = BOLD; if (values.getPosture() >= .2f) newStyle |= ITALIC; if (oldStyle == newStyle) newStyle = -1; } if (handle.font2D instanceof CompositeFont) { if (newStyle != -1 || newName != null) { FontManager fm = FontManagerFactory.getInstance(); this.font2DHandle = fm.getNewComposite(newName, newStyle, handle); } } else if (newName != null) { this.createdFont = false; this.font2DHandle = null; } } initFromValues(values); }
/** * Initialize the standard Font fields from the values object. */ private void initFromValues(AttributeValues values) { this.values = values; values.defineAll(PRIMARY_MASK); // for 1.5 streaming compatibility this.name = values.getFamily(); this.pointSize = values.getSize(); this.size = (int)(values.getSize() + 0.5); if (values.getWeight() >= 2f) this.style |= BOLD; // not == 2f if (values.getPosture() >= .2f) this.style |= ITALIC; // not == .2f this.nonIdentityTx = values.anyNonDefault(EXTRA_MASK); this.hasLayoutAttributes = values.anyNonDefault(LAYOUT_MASK); }
/** * 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; } // Handle fRequestedAttributes. // in 1.5, we always streamed out the font values plus // TRANSFORM, SUPERSCRIPT, and WIDTH, regardless of whether the // values were default or not. In 1.6 we only stream out // defined values. So, 1.6 streams in from a 1.5 stream, // it check each of these values and 'undefines' it if the // value is the default. if (fRequestedAttributes != null) { values = getAttributeValues(); // init AttributeValues extras = AttributeValues.fromSerializableHashtable(fRequestedAttributes); if (!AttributeValues.is16Hashtable(fRequestedAttributes)) { extras.unsetDefault(); // if legacy stream, undefine these } values = getAttributeValues().merge(extras); this.nonIdentityTx = values.anyNonDefault(EXTRA_MASK); this.hasLayoutAttributes = values.anyNonDefault(LAYOUT_MASK); fRequestedAttributes = null; // don't need it any more } }
/** * Creates a new <code>Font</code> object by replicating this * <code>Font</code> object and applying a new style and size. * @param style the style for the new <code>Font</code> * @param size the size for the new <code>Font</code> * @return a new <code>Font</code> object. * @since 1.2 */ public Font deriveFont(int style, float size){ if (values == null) { return new Font(name, style, size, createdFont, font2DHandle); } AttributeValues newValues = getAttributeValues().clone(); int oldStyle = (this.style != style) ? this.style : -1; applyStyle(style, newValues); newValues.setSize(size); return new Font(newValues, null, oldStyle, createdFont, font2DHandle); }
/** * Creates a new <code>Font</code> object by replicating the current * <code>Font</code> object and applying a new size to it. * @param size the size for the new <code>Font</code>. * @return a new <code>Font</code> object. * @since 1.2 */ public Font deriveFont(float size){ if (values == null) { return new Font(name, style, size, createdFont, font2DHandle); } AttributeValues newValues = getAttributeValues().clone(); newValues.setSize(size); return new Font(newValues, null, -1, createdFont, font2DHandle); }
/** * Creates a new <code>Font</code> object by replicating the current * <code>Font</code> object and applying a new style to it. * @param style the style for the new <code>Font</code> * @return a new <code>Font</code> object. * @since 1.2 */ public Font deriveFont(int style){ if (values == null) { return new Font(name, style, size, createdFont, font2DHandle); } AttributeValues newValues = getAttributeValues().clone(); int oldStyle = (this.style != style) ? this.style : -1; applyStyle(style, newValues); return new Font(newValues, null, oldStyle, createdFont, font2DHandle); }