Refine search
/** * Formats the specified object using the rules of this format and returns * an {@code AttributedCharacterIterator} with the formatted string and no * attributes. * <p> * Subclasses should return an {@code AttributedCharacterIterator} with the * appropriate attributes. * * @param object * the object to format. * @return an {@code AttributedCharacterIterator} with the formatted object * and attributes. * @throws IllegalArgumentException * if the object cannot be formatted by this format. */ public AttributedCharacterIterator formatToCharacterIterator(Object object) { return new AttributedString(format(object)).getIterator(); }
public AttributedCharacterIterator iterator() { AttributedString aString = new AttributedString(String .valueOf(character)); aString.addAttribute(TextAttribute.FONT, font, 0, 1); return aString.getIterator(); }
public void paintComponent(Graphics g) { super.paintComponent(g); AttributedString as = new AttributedString("I love you 104 gazillion"); as.addAttribute(TextAttribute.SUPERSCRIPT, TextAttribute.SUPERSCRIPT_SUPER, 13, 14); as.addAttribute(TextAttribute.FOREGROUND, Color.RED, 2, 6); g.drawString(as.getIterator(), 20, 20); }
AttributedString as = new AttributedString(buffer.toString()); return as.getIterator();
/** * Check if the Fonts are installed correctly so that Java can compute the size of * columns. * * If a Cell uses a Font which is not available on the operating system then Java may * fail to return useful Font metrics and thus lead to an auto-computed size of 0. * * This method allows to check if computing the sizes for a given Font will succeed or not. * * @param font The Font that is used in the Cell * @return true if computing the size for this Font will succeed, false otherwise */ public static boolean canComputeColumnWidth(Font font) { // not sure what is the best value sample-here, only "1" did not work on some platforms... AttributedString str = new AttributedString("1w"); copyAttributes(font, str, 0, "1w".length()); TextLayout layout = new TextLayout(str.getIterator(), fontRenderContext); return (layout.getBounds().getWidth() > 0); }
private AttributedCharacterIterator formatToCharacterIteratorImpl(Date date) { StringBuffer buffer = new StringBuffer(); ArrayList<FieldPosition> fields = new ArrayList<FieldPosition>(); // format the date, and find fields formatImpl(date, buffer, null, fields); // create and AttributedString with the formatted buffer AttributedString as = new AttributedString(buffer.toString()); // add DateFormat field attributes to the AttributedString for (FieldPosition pos : fields) { Format.Field attribute = pos.getFieldAttribute(); as.addAttribute(attribute, attribute, pos.getBeginIndex(), pos.getEndIndex()); } // return the CharacterIterator from AttributedString return as.getIterator(); }
/** * Get default character width using the Workbook's default font * * @param wb the workbook to get the default character width from * @return default character width in pixels */ @Internal public static int getDefaultCharWidth(final Workbook wb) { Font defaultFont = wb.getFontAt( 0); AttributedString str = new AttributedString(String.valueOf(defaultChar)); copyAttributes(defaultFont, str, 0, 1); TextLayout layout = new TextLayout(str.getIterator(), fontRenderContext); return (int) layout.getAdvance(); }
public AttributedCharacterIterator formatToCharacterIterator(Object object) { if (object == null) { throw new NullPointerException("object == null"); } if (!(object instanceof Number)) { throw new IllegalArgumentException("object not a Number: " + object.getClass()); } Number number = (Number) object; FieldPositionIterator fpIter = new FieldPositionIterator(); String text; if (number instanceof BigInteger || number instanceof BigDecimal) { text = new String(formatDigitList(this.address, number.toString(), fpIter)); } else if (number instanceof Double || number instanceof Float) { double dv = number.doubleValue(); text = new String(formatDouble(this.address, dv, fpIter)); } else { long lv = number.longValue(); text = new String(formatLong(this.address, lv, fpIter)); } AttributedString as = new AttributedString(text); while (fpIter.next()) { Format.Field field = fpIter.field(); as.addAttribute(field, field, fpIter.start(), fpIter.limit()); } // return the CharacterIterator from AttributedString return as.getIterator(); }
/** * Replace a tab with the effective number of white spaces. */ private String tab2space(TextRun tr) { AttributedString string = new AttributedString(" "); String fontFamily = tr.getFontFamily(); if (fontFamily == null) { fontFamily = "Lucida Sans"; } string.addAttribute(TextAttribute.FAMILY, fontFamily); Double fs = tr.getFontSize(); if (fs == null) { fs = 12d; } string.addAttribute(TextAttribute.SIZE, fs.floatValue()); TextLayout l = new TextLayout(string.getIterator(), new FontRenderContext(null, true, true)); double wspace = l.getAdvance(); Double tabSz = paragraph.getDefaultTabSize(); if (tabSz == null) { tabSz = wspace*4; } int numSpaces = (int)Math.ceil(tabSz / wspace); StringBuilder buf = new StringBuilder(); for(int i = 0; i < numSpaces; i++) { buf.append(' '); } return buf.toString(); }
boolean centered) { AttributedString attributedString = new AttributedString(text); attributedString.addAttribute(TextAttribute.FONT, g.getFont()); Color.black); AttributedCharacterIterator characterIterator = attributedString.getIterator();
boolean emptyParagraph = text.toString().trim().isEmpty(); AttributedCharacterIterator it = at.getIterator(); LineBreakMeasurer measurer = new LineBreakMeasurer(it, graphics.getFontRenderContext()); for (;;) { : new AttributedString(it, startIndex, endIndex); DrawTextFragment line = fact.getTextFragment(layout, str); lines.add(line);
AttributedString as = new AttributedString(text); as.addAttribute(TextAttribute.FOREGROUND, g.getPaint()); as.addAttribute(TextAttribute.FONT, g.getFont()); AttributedCharacterIterator aci = as.getIterator(); FontRenderContext frc = new FontRenderContext(null, true,
AttributedString str = new AttributedString(dfm.mapFontCharset(graphics,buFont,buCharacter)); str.addAttribute(TextAttribute.FOREGROUND, fgPaint); str.addAttribute(TextAttribute.FAMILY, buFont.getTypeface()); str.addAttribute(TextAttribute.SIZE, fontSize); TextLayout layout = new TextLayout(str.getIterator(), graphics.getFontRenderContext()); DrawFactory fact = DrawFactory.getInstance(graphics); return fact.getTextFragment(layout, str);
AttributedString str = new AttributedString(types); str.addAttribute(TextAttribute.FONT, boxTextFont); TextMeasurer measure = new TextMeasurer(str.getIterator(), g.getFontRenderContext()); int breakIndex = measure.getLineBreakIndex(0, availableWidth); if (breakIndex < types.length()) { str = new AttributedString(types); str.addAttribute(TextAttribute.FONT, boxTextFontNarrow); measure = new TextMeasurer(str.getIterator(), g.getFontRenderContext()); breakIndex = measure.getLineBreakIndex(0, availableWidth);
private WrappedLines breakLines(Graphics2D g) { Dimension size = label.getSize(); float maxWidth = size.width; AttributedString attributedText = new AttributedString(label.getText(), textAttributes()); AttributedCharacterIterator textIterator = attributedText.getIterator(); FontRenderContext fontRendering = g.getFontRenderContext(); LineBreakMeasurer measurer = new LineBreakMeasurer(textIterator, fontRendering); WrappedLines lines = new WrappedLines(); while(measurer.getPosition() < textIterator.getEndIndex()) { TextLayout layout = measurer.nextLayout(maxWidth); lines.add(layout); } return lines; }
int wrapWidth = Math.max(0, key.wrap ? size.width - key.glowSize : Integer.MAX_VALUE); AttributedString attributedString = new AttributedString(key.text); attributedString.addAttribute(TextAttribute.FONT, key.getFont()); AttributedCharacterIterator charIterator = attributedString.getIterator(); FontRenderContext fontContext = g2d.getFontRenderContext();
AttributedString str = new AttributedString(nameStr); str.addAttribute(TextAttribute.FONT, boxTextFont); TextMeasurer measure = new TextMeasurer(str.getIterator(), g.getFontRenderContext()); int breakIndex = measure.getLineBreakIndex(0, availableWidth); if (breakIndex < nameStr.length()) { str = new AttributedString(nameStr); str.addAttribute(TextAttribute.FONT, boxTextFontNarrow); measure = new TextMeasurer(str.getIterator(), g.getFontRenderContext()); breakIndex = measure.getLineBreakIndex(0, availableWidth);
/** * Creates an <code>AttributedCharacterIterator</code> for the String <code>s</code>. * * @param s String to create AttributedCharacterIterator from * @return AttributedCharacterIterator wrapping s */ static AttributedCharacterIterator createAttributedCharacterIterator(String s) { return new java.text.AttributedString(s).getIterator(); }
/** * Creates an <code>AttributedCharacterIterator</code> for the String <code>s</code>. * * @param s String to create AttributedCharacterIterator from * @return AttributedCharacterIterator wrapping s */ static AttributedCharacterIterator createAttributedCharacterIterator(String s) { return new java.text.AttributedString(s).getIterator(); }
/** * Creates an <code>AttributedCharacterIterator</code> for the String * <code>s</code>. * * @param s String to create AttributedCharacterIterator from * @return AttributedCharacterIterator wrapping s */ AttributedCharacterIterator createAttributedCharacterIterator(String s) { AttributedString as = new AttributedString(s); return as.getIterator(); }