use of sun.font.Decoration in project jdk8u_jdk by JetBrains.
the class TextLine method fastCreateTextLine.
/**
* Create a TextLine from the text. The Font must be able to
* display all of the text.
* attributes==null is equivalent to using an empty Map for
* attributes
*/
public static TextLine fastCreateTextLine(FontRenderContext frc, char[] chars, Font font, CoreMetrics lm, Map<? extends Attribute, ?> attributes) {
boolean isDirectionLTR = true;
byte[] levels = null;
int[] charsLtoV = null;
Bidi bidi = null;
int characterCount = chars.length;
boolean requiresBidi = false;
byte[] embs = null;
AttributeValues values = null;
if (attributes != null) {
values = AttributeValues.fromMap(attributes);
if (values.getRunDirection() >= 0) {
isDirectionLTR = values.getRunDirection() == 0;
requiresBidi = !isDirectionLTR;
}
if (values.getBidiEmbedding() != 0) {
requiresBidi = true;
byte level = (byte) values.getBidiEmbedding();
embs = new byte[characterCount];
for (int i = 0; i < embs.length; ++i) {
embs[i] = level;
}
}
}
if (!requiresBidi) {
requiresBidi = Bidi.requiresBidi(chars, 0, chars.length);
}
if (requiresBidi) {
int bidiflags = values == null ? Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT : values.getRunDirection();
bidi = new Bidi(chars, 0, embs, 0, chars.length, bidiflags);
if (!bidi.isLeftToRight()) {
levels = BidiUtils.getLevels(bidi);
int[] charsVtoL = BidiUtils.createVisualToLogicalMap(levels);
charsLtoV = BidiUtils.createInverseMap(charsVtoL);
isDirectionLTR = bidi.baseIsLeftToRight();
}
}
Decoration decorator = Decoration.getDecoration(values);
// no extra info yet, bidi determines run and line direction
int layoutFlags = 0;
TextLabelFactory factory = new TextLabelFactory(frc, chars, bidi, layoutFlags);
TextLineComponent[] components = new TextLineComponent[1];
components = createComponentsOnRun(0, chars.length, chars, charsLtoV, levels, factory, font, lm, frc, decorator, components, 0);
int numComponents = components.length;
while (components[numComponents - 1] == null) {
numComponents -= 1;
}
if (numComponents != components.length) {
TextLineComponent[] temp = new TextLineComponent[numComponents];
System.arraycopy(components, 0, temp, 0, numComponents);
components = temp;
}
return new TextLine(frc, components, lm.baselineOffsets, chars, 0, chars.length, charsLtoV, levels, isDirectionLTR);
}
use of sun.font.Decoration in project jdk8u_jdk by JetBrains.
the class TextLine method getComponents.
/**
* Returns an array (in logical order) of the TextLineComponents representing
* the text. The components are both logically and visually contiguous.
*/
public static TextLineComponent[] getComponents(StyledParagraph styledParagraph, char[] chars, int textStart, int textLimit, int[] charsLtoV, byte[] levels, TextLabelFactory factory) {
FontRenderContext frc = factory.getFontRenderContext();
int numComponents = 0;
TextLineComponent[] tempComponents = new TextLineComponent[1];
int pos = textStart;
do {
int runLimit = Math.min(styledParagraph.getRunLimit(pos), textLimit);
Decoration decorator = styledParagraph.getDecorationAt(pos);
Object graphicOrFont = styledParagraph.getFontOrGraphicAt(pos);
if (graphicOrFont instanceof GraphicAttribute) {
// AffineTransform baseRot = styledParagraph.getBaselineRotationAt(pos);
// !!! For now, let's assign runs of text with both fonts and graphic attributes
// a null rotation (e.g. the baseline rotation goes away when a graphic
// is applied.
AffineTransform baseRot = null;
GraphicAttribute graphicAttribute = (GraphicAttribute) graphicOrFont;
do {
int chunkLimit = firstVisualChunk(charsLtoV, levels, pos, runLimit);
GraphicComponent nextGraphic = new GraphicComponent(graphicAttribute, decorator, charsLtoV, levels, pos, chunkLimit, baseRot);
pos = chunkLimit;
++numComponents;
if (numComponents >= tempComponents.length) {
tempComponents = expandArray(tempComponents);
}
tempComponents[numComponents - 1] = nextGraphic;
} while (pos < runLimit);
} else {
Font font = (Font) graphicOrFont;
tempComponents = createComponentsOnRun(pos, runLimit, chars, charsLtoV, levels, factory, font, null, frc, decorator, tempComponents, numComponents);
pos = runLimit;
numComponents = tempComponents.length;
while (tempComponents[numComponents - 1] == null) {
numComponents -= 1;
}
}
} while (pos < textLimit);
TextLineComponent[] components;
if (tempComponents.length == numComponents) {
components = tempComponents;
} else {
components = new TextLineComponent[numComponents];
System.arraycopy(tempComponents, 0, components, 0, numComponents);
}
return components;
}
use of sun.font.Decoration in project jdk8u_jdk by JetBrains.
the class StyledParagraph method insertChar.
/**
* Return a StyledParagraph reflecting the insertion of a single character
* into the text. This method will attempt to reuse the given paragraph,
* but may create a new paragraph.
* @param aci an iterator over the text. The text should be the same as the
* text used to create (or most recently update) oldParagraph, with
* the exception of inserting a single character at insertPos.
* @param chars the characters in aci
* @param insertPos the index of the new character in aci
* @param oldParagraph a StyledParagraph for the text in aci before the
* insertion
*/
public static StyledParagraph insertChar(AttributedCharacterIterator aci, char[] chars, int insertPos, StyledParagraph oldParagraph) {
// If the styles at insertPos match those at insertPos-1,
// oldParagraph will be reused. Otherwise we create a new
// paragraph.
char ch = aci.setIndex(insertPos);
int relativePos = Math.max(insertPos - aci.getBeginIndex() - 1, 0);
Map<? extends Attribute, ?> attributes = addInputMethodAttrs(aci.getAttributes());
Decoration d = Decoration.getDecoration(attributes);
if (!oldParagraph.getDecorationAt(relativePos).equals(d)) {
return new StyledParagraph(aci, chars);
}
Object f = getGraphicOrFont(attributes);
if (f == null) {
FontResolver resolver = FontResolver.getInstance();
int fontIndex = resolver.getFontIndex(ch);
f = resolver.getFont(fontIndex, attributes);
}
if (!oldParagraph.getFontOrGraphicAt(relativePos).equals(f)) {
return new StyledParagraph(aci, chars);
}
// insert into existing paragraph
oldParagraph.length += 1;
if (oldParagraph.decorations != null) {
insertInto(relativePos, oldParagraph.decorationStarts, oldParagraph.decorations.size());
}
if (oldParagraph.fonts != null) {
insertInto(relativePos, oldParagraph.fontStarts, oldParagraph.fonts.size());
}
return oldParagraph;
}
Aggregations