use of java.text.AttributedString in project jdk8u_jdk by JetBrains.
the class BidiConformance method testConstructor1.
private void testConstructor1() {
Bidi bidi;
try {
bidi = new Bidi(null);
errorHandling("Bidi((AttributedCharacterIterator)null) " + "should throw an IAE.");
} catch (IllegalArgumentException e) {
} catch (NullPointerException e) {
errorHandling("Bidi((AttributedCharacterIterator)null) " + "should not throw an NPE but an IAE.");
}
String paragraph = data4Constructor1[1][0];
int start = paragraph.indexOf('<') + 1;
int limit = paragraph.indexOf('>');
AttributedString astr = new AttributedString(paragraph);
astr.addAttribute(TextAttribute.RUN_DIRECTION, TextAttribute.RUN_DIRECTION_RTL);
astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(-61), start, limit);
try {
bidi = new Bidi(astr.getIterator());
for (int i = start; i < limit; i++) {
if (bidi.getLevelAt(i) != 61) {
errorHandling("Bidi(AttributedCharacterIterator).getLevelAt(" + i + ") should not be " + bidi.getLevelAt(i) + " but 60 when BIDI_EMBEDDING is -61.");
}
}
} catch (Exception e) {
errorHandling(" Unexpected exception: " + e);
}
astr = new AttributedString(paragraph);
astr.addAttribute(TextAttribute.RUN_DIRECTION, TextAttribute.RUN_DIRECTION_RTL);
astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(-62), start, limit);
try {
bidi = new Bidi(astr.getIterator());
for (int i = start; i < limit; i++) {
if (bidi.getLevelAt(i) != 1) {
errorHandling("Bidi(AttributedCharacterIterator).getLevelAt() " + "should be 1 when BIDI_EMBEDDING is -62.");
}
}
} catch (Exception e) {
errorHandling(" Unexpected exception: " + e);
}
astr = new AttributedString(paragraph);
astr.addAttribute(TextAttribute.RUN_DIRECTION, TextAttribute.RUN_DIRECTION_RTL);
astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(60), start, limit);
try {
bidi = new Bidi(astr.getIterator());
for (int i = start; i < limit; i++) {
if (bidi.getLevelAt(i) != 61) {
errorHandling("Bidi(AttributedCharacterIterator).getLevelAt() " + "should be 61 when BIDI_EMBEDDING is 60.");
}
}
} catch (Exception e) {
errorHandling(" Unexpected exception: " + e);
}
astr = new AttributedString(paragraph);
astr.addAttribute(TextAttribute.RUN_DIRECTION, TextAttribute.RUN_DIRECTION_RTL);
astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(61), start, limit);
try {
bidi = new Bidi(astr.getIterator());
for (int i = start; i < limit; i++) {
if (bidi.getLevelAt(i) != 61) {
errorHandling("Bidi(AttributedCharacterIterator).getLevelAt(" + i + ") should not be " + bidi.getLevelAt(i) + " but 61 when BIDI_EMBEDDING is 61.");
}
}
} catch (Exception e) {
errorHandling(" Unexpected exception: " + e);
}
astr = new AttributedString(paragraph);
astr.addAttribute(TextAttribute.RUN_DIRECTION, TextAttribute.RUN_DIRECTION_RTL);
astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(62), start, limit);
try {
bidi = new Bidi(astr.getIterator());
for (int i = start; i < limit; i++) {
if (bidi.getLevelAt(i) != 1) {
errorHandling("Bidi(AttributedCharacterIterator).getLevelAt()" + " should not be " + bidi.getLevelAt(i) + " but 1 when BIDI_EMBEDDING is 62.");
}
}
} catch (Exception e) {
errorHandling(" Unexpected exception: " + e);
}
}
use of java.text.AttributedString in project jdk8u_jdk by JetBrains.
the class X11InputMethod method flushText.
/**
* Flushes composed and committed text held in this context.
* This method is invoked in the AWT Toolkit (X event loop) thread context
* and thus inside the AWT Lock.
*/
// NOTE: This method may be called by privileged threads.
// This functionality is implemented in a package-private method
// to insure that it cannot be overridden by client subclasses.
// DO NOT INVOKE CLIENT CODE ON THIS THREAD!
void flushText() {
String flush = (committedText != null ? committedText : "");
if (composedText != null) {
flush += composedText.toString();
}
if (!flush.equals("")) {
AttributedString attrstr = new AttributedString(flush);
postInputMethodEvent(InputMethodEvent.INPUT_METHOD_TEXT_CHANGED, attrstr.getIterator(), flush.length(), null, null, EventQueue.getMostRecentEventTime());
composedText = null;
committedText = null;
}
}
use of java.text.AttributedString in project poi by apache.
the class HwmfGraphics method addAttributes.
private void addAttributes(AttributedString as, HwmfFont font) {
DrawFontManager fontHandler = (DrawFontManager) graphicsCtx.getRenderingHint(Drawable.FONT_HANDLER);
String fontFamily = null;
@SuppressWarnings("unchecked") Map<String, String> fontMap = (Map<String, String>) graphicsCtx.getRenderingHint(Drawable.FONT_MAP);
if (fontMap != null && fontMap.containsKey(font.getFacename())) {
fontFamily = fontMap.get(font.getFacename());
}
if (fontHandler != null) {
fontFamily = fontHandler.getRendererableFont(font.getFacename(), font.getPitchAndFamily());
}
if (fontFamily == null) {
fontFamily = font.getFacename();
}
as.addAttribute(TextAttribute.FAMILY, fontFamily);
as.addAttribute(TextAttribute.SIZE, getFontHeight(font));
as.addAttribute(TextAttribute.STRIKETHROUGH, font.isStrikeOut());
if (font.isUnderline()) {
as.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
}
if (font.isItalic()) {
as.addAttribute(TextAttribute.POSTURE, TextAttribute.POSTURE_OBLIQUE);
}
as.addAttribute(TextAttribute.WEIGHT, font.getWeight());
}
use of java.text.AttributedString in project jdk8u_jdk by JetBrains.
the class CompositionAreaHandler method inputMethodTextChanged.
public void inputMethodTextChanged(InputMethodEvent event) {
AttributedCharacterIterator text = event.getText();
int committedCharacterCount = event.getCommittedCharacterCount();
// extract composed text and prepare it for display
composedText = null;
caret = null;
if (text != null && committedCharacterCount < text.getEndIndex() - text.getBeginIndex()) {
// Create the composition area if necessary
if (compositionArea == null) {
createCompositionArea();
}
// copy the composed text
AttributedString composedTextString;
composedTextString = new AttributedString(text, // skip over committed text
text.getBeginIndex() + committedCharacterCount, text.getEndIndex(), IM_ATTRIBUTES);
composedTextString.addAttribute(TextAttribute.FONT, compositionArea.getFont());
composedText = composedTextString.getIterator();
caret = event.getCaret();
}
if (compositionArea != null) {
compositionArea.setText(composedText, caret);
}
// send any committed text to the text component
if (committedCharacterCount > 0) {
inputMethodContext.dispatchCommittedText(((Component) event.getSource()), text, committedCharacterCount);
// this may have changed the text location, so reposition the window
if (isCompositionAreaVisible()) {
compositionArea.updateWindowLocation();
}
}
// event has been handled, so consume it
event.consume();
}
use of java.text.AttributedString in project poi by apache.
the class BaseTestBugzillaIssues method computeCellWidthFixed.
private double computeCellWidthFixed(Font font, String txt) {
final FontRenderContext fontRenderContext = new FontRenderContext(null, true, true);
AttributedString str = new AttributedString(txt);
copyAttributes(font, str, txt.length());
TextLayout layout = new TextLayout(str.getIterator(), fontRenderContext);
return getFrameWidth(layout);
}
Aggregations