Search in sources :

Example 76 with AttributedString

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);
    }
}
Also used : Bidi(java.text.Bidi) AttributedString(java.text.AttributedString) AttributedString(java.text.AttributedString)

Example 77 with AttributedString

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;
    }
}
Also used : AttributedString(java.text.AttributedString) AttributedString(java.text.AttributedString)

Example 78 with AttributedString

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());
}
Also used : AttributedString(java.text.AttributedString) DrawFontManager(org.apache.poi.sl.draw.DrawFontManager) Map(java.util.Map)

Example 79 with AttributedString

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();
}
Also used : AttributedString(java.text.AttributedString) Component(java.awt.Component) AttributedCharacterIterator(java.text.AttributedCharacterIterator)

Example 80 with AttributedString

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);
}
Also used : AttributedString(java.text.AttributedString) FontRenderContext(java.awt.font.FontRenderContext) TextLayout(java.awt.font.TextLayout)

Aggregations

AttributedString (java.text.AttributedString)86 AttributedCharacterIterator (java.text.AttributedCharacterIterator)37 TextLayout (java.awt.font.TextLayout)29 LineBreakMeasurer (java.awt.font.LineBreakMeasurer)16 FontRenderContext (java.awt.font.FontRenderContext)13 Font (java.awt.Font)11 Point (java.awt.Point)11 Paint (java.awt.Paint)10 Graphics2D (java.awt.Graphics2D)9 WeakHashMap (java.util.WeakHashMap)8 Color (java.awt.Color)4 Bidi (java.text.Bidi)4 ArrayList (java.util.ArrayList)4 TreeSet (java.util.TreeSet)4 Rectangle (java.awt.Rectangle)3 HashSet (java.util.HashSet)3 Dimension (java.awt.Dimension)2 Insets (java.awt.Insets)2 AffineTransform (java.awt.geom.AffineTransform)2 Rectangle2D (java.awt.geom.Rectangle2D)2