Refine search
boolean centered) { AttributedString attributedString = new AttributedString(text); attributedString.addAttribute(TextAttribute.FONT, g.getFont()); attributedString.addAttribute(TextAttribute.FOREGROUND, Color.black); while (measurer.getPosition() < characterIterator.getEndIndex() && currentHeight <= boxHeight) { int height = ((Float) (layout.getDescent() + layout.getAscent() + layout.getLeading())).intValue(); currentY += textLayout.getAscent(); currentX = x + (centered ? ((boxWidth - ((Double) textLayout.getBounds().getWidth()).intValue()) / 2) : 0); textLayout.draw(g,
private AttributedString(AttributedCharacterIterator iterator, int start, int end, Set<Attribute> attributes) { if (start < iterator.getBeginIndex() || end > iterator.getEndIndex() || start > end) { throw new IllegalArgumentException(); iterator.setIndex(start); while (iterator.getIndex() < end) { buffer.append(iterator.current()); iterator.next(); while (it.hasNext()) { AttributedCharacterIterator.Attribute attribute = it.next(); iterator.setIndex(start); while (iterator.getIndex() < end) { Object value = iterator.getAttribute(attribute); int runStart = iterator.getRunStart(attribute); int limit = iterator.getRunLimit(attribute); if ((value instanceof Annotation && runStart >= start && limit <= end) || (value != null && !(value instanceof Annotation))) { addAttribute(attribute, value, (runStart < start ? start : runStart) - start, (limit > end ? end : limit) - start); iterator.setIndex(limit);
int begin = paragraph.getBeginIndex(); int end = paragraph.getEndIndex(); int length = end - begin; char[] text = new char[length + 1]; // One more char for AttributedCharacterIterator.DONE text[0] = paragraph.first(); } else { paragraph.first(); Object direction = paragraph.getAttribute(TextAttribute.RUN_DIRECTION); if (direction != null && direction instanceof Boolean) { if (direction.equals(TextAttribute.RUN_DIRECTION_LTR)) { .getRunLimit(TextAttribute.BIDI_EMBEDDING) - begin + 1) { Object embedding = paragraph.getAttribute(TextAttribute.BIDI_EMBEDDING); if (embedding != null && embedding instanceof Integer) { int embLevel = ((Integer) embedding).intValue(); text[i] = paragraph.next(); embeddings[i - 1] = (byte) embLevel; text[i] = paragraph.next(); Object numericShaper = paragraph.getAttribute(TextAttribute.NUMERIC_SHAPING); if (numericShaper != null && numericShaper instanceof NumericShaper) { ((NumericShaper) numericShaper).shape(text, 0, length);
/** * * @return the string to be painted */ public String getString(){ if (str == null) return ""; AttributedCharacterIterator it = str.getIterator(); StringBuilder buf = new StringBuilder(); for (char c = it.first(); c != CharacterIterator.DONE; c = it.next()) { buf.append(c); } return buf.toString(); }
/** * If fields list is not null, find and add the fields of this format to * the fields list by iterating through its AttributedCharacterIterator * * @param format * the format to find fields for * @param arg * object to format * @param begin * the index where the string this format has formatted begins */ private void handleFormat(Format format, Object arg, int begin, List<FieldContainer> fields) { if (fields == null) { return; } AttributedCharacterIterator iterator = format.formatToCharacterIterator(arg); while (iterator.getIndex() != iterator.getEndIndex()) { int start = iterator.getRunStart(); int end = iterator.getRunLimit(); Iterator<?> it = iterator.getAttributes().keySet().iterator(); while (it.hasNext()) { AttributedCharacterIterator.Attribute attribute = (AttributedCharacterIterator.Attribute) it.next(); Object value = iterator.getAttribute(attribute); fields.add(new FieldContainer(begin + start, begin + end, attribute, value)); } iterator.setIndex(end); } }
FontRenderContext frc = g.getFontRenderContext(); AttributedCharacterIterator textIter = text.getIterator(); LineBreakMeasurer measure = new LineBreakMeasurer(textIter, frc); float yPos = y; float remain = h; AttributedCharacterIterator newLineCheck = text.getIterator(); while (measure.getPosition() < textIter.getEndIndex()) { newLineCheck.setIndex(measure.getPosition()); char ch; while ((ch = newLineCheck.next()) != CharacterIterator.DONE) { if (ch == '\n') { break; TextLayout layout = measure.nextLayout(availWidth, newLineCheck.getIndex(), false); float ascent = layout.getAscent(); yPos += ascent; remain -= ascent; g.setColor(Color.black); layout.draw(g, x + inset, yPos); yPos += layout.getDescent() + layout.getLeading() - 2; 4);
BufferedImage image = GraphicsUtilities.createCompatibleTranslucentImage(size.width, size.height); Graphics2D g2d = image.createGraphics(); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); AttributedString attributedString = new AttributedString(key.text); attributedString.addAttribute(TextAttribute.FONT, key.getFont()); AttributedCharacterIterator charIterator = attributedString.getIterator(); FontRenderContext fontContext = g2d.getFontRenderContext(); while (measurer.getPosition() < charIterator.getEndIndex()) { charIterator.first(); measurer.setPosition(0); while (measurer.getPosition() < charIterator.getEndIndex()) { TextLayout textLayout = measurer.nextLayout(wrapWidth); float ascent = textLayout.getAscent(); g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.8f)); int glowSize = key.glowSize; textLayout.draw(g2d, textX + glowSize / 2 + 1, textY + glowSize / 2 - 1); textLayout.draw(g2d, textX + glowSize / 2 + 1, textY + glowSize / 2 + 1); textLayout.draw(g2d, textX + glowSize / 2 - 1, textY + glowSize / 2 - 1); textLayout.draw(g2d, textX + glowSize / 2 - 1, textY + glowSize / 2 + 1);
/** * @see com.octo.captcha.component.image.textpaster.AbstractTextPaster#pasteText(java.awt.image.BufferedImage, java.text.AttributedString) */ public BufferedImage pasteText(final BufferedImage background, final AttributedString attributedWord) throws CaptchaException { BufferedImage out = copyBackground(background); Graphics2D g2d = pasteBackgroundAndSetTextColor(out, background); g2d.setRenderingHints(renderingHints); g2d.translate(10, background.getHeight() / 2); AttributedCharacterIterator iterator = attributedWord.getIterator(); while (iterator.getIndex() != iterator.getEndIndex()) { AttributedString character = new AttributedString(String.valueOf(iterator.current())); character.addAttribute(TextAttribute.FONT, iterator.getAttribute(TextAttribute.FONT)); pasteCharacter(g2d, character); iterator.next(); } g2d.dispose(); return out; }
@Override public void drawString(AttributedCharacterIterator iter, float x, float y) { Rectangle2D bounds = getFontMetrics().getStringBounds( iter, iter.getBeginIndex(), iter.getEndIndex(), this); bounds.setRect(x, y - bounds.getHeight() + 1, bounds.getWidth(), bounds.getHeight() ); doDraw(OpType.DRAW_STRING_ITER_XY, bounds, iter, x, y); }
this.paintFront.setColor(GraphicUtils.filterColor(colorF, filter)); AttributedString attrString = new AttributedString(this.text); org.mapsforge.map.awt.graphics.AwtPaint awtPaintFront = org.mapsforge.map.awt.graphics.AwtGraphicFactory.getPaint(this.paintFront); attrString.addAttribute(TextAttribute.FOREGROUND, awtPaintFront.color); attrString.addAttribute(TextAttribute.FONT, awtPaintFront.font); AttributedCharacterIterator paragraph = attrString.getIterator(); int paragraphStart = paragraph.getBeginIndex(); int paragraphEnd = paragraph.getEndIndex(); FontRenderContext frc = awtCanvas.getGraphicObject().getFontRenderContext(); LineBreakMeasurer lineMeasurer = new LineBreakMeasurer(paragraph, frc); while (lineMeasurer.getPosition() < paragraphEnd) { TextLayout layout = lineMeasurer.nextLayout(maxTextWidth); layoutHeight += layout.getAscent() + layout.getDescent() + layout.getLeading(); AffineTransform affineTransform = new AffineTransform(); affineTransform.translate(posX, posY); awtCanvas.getGraphicObject().draw(layout.getOutline(affineTransform)); if (filter != Filter.NONE) { this.paintBack.setColor(colorB);
/** * Returns a shape describing the strikethrough line for a given ACI. */ protected Shape getStrikethroughShape() { double y = metrics.getStrikethroughOffset(); float strikethroughThickness = metrics.getStrikethroughThickness(); Stroke strikethroughStroke = new BasicStroke(strikethroughThickness); // Not certain what should be done here... aci.first(); Float dy = (Float) aci.getAttribute(DY); if (dy != null) y += dy.floatValue(); Rectangle2D logicalBounds = gv.getLogicalBounds(); return strikethroughStroke.createStrokedShape( new Line2D.Double( logicalBounds.getMinX() + strikethroughThickness/2.0, offset.getY()+y, logicalBounds.getMaxX() - strikethroughThickness/2.0, offset.getY()+y)); }
|| textLength == fonts[0].canDisplayUpTo(text.toCharArray(), 0, textLength); if (!(text.contains("\n") || labelItem.getAutoWrap() > 0) && singleFont) { FontRenderContext frc = graphics.getFontRenderContext(); TextLayout layout = new TextLayout(text, fonts[0], frc); LineInfo lineInfo = new LineInfo(); List<LineComponent> components = List<FontRange> ranges = buildFontRanges(line, fonts); for (FontRange range : ranges) { graphics.setFont(range.font); FontRenderContext frc = graphics.getFontRenderContext(); TextLayout layout = new TextLayout(range.text, range.font, frc); List<LineComponent> components = buildLineComponents( AttributedCharacterIterator iter = attributed.getIterator(); LineBreakMeasurer lineMeasurer = new LineBreakMeasurer( while (lineMeasurer.getPosition() < iter.getEndIndex()) { attributed.getIterator(null, prevPosition, newPosition); layout = new TextLayout(subIter, graphics.getFontRenderContext()); lineMeasurer.setPosition(newPosition);
private Dimension paintOrGetSize(Graphics2D g, int width) { Insets insets = getInsets(); width -= insets.left + insets.right + margin.left + margin.right; float w = insets.left + insets.right + margin.left + margin.right; float x = insets.left + margin.left, y = insets.top + margin.top; if (width > 0 && text != null && text.length() > 0) { AttributedString as = new AttributedString(getText()); as.addAttribute(TextAttribute.FONT, getFont()); AttributedCharacterIterator aci = as.getIterator(); LineBreakMeasurer lbm = new LineBreakMeasurer(aci, frc); float max = 0; while (lbm.getPosition() < aci.getEndIndex()) { TextLayout textLayout = lbm.nextLayout(width); if (g != null && isJustified() && textLayout.getVisibleAdvance() > 0.80 * width) textLayout = textLayout.getJustifiedLayout(width); if (g != null) textLayout.draw(g, x, y + textLayout.getAscent()); y += textLayout.getDescent() + textLayout.getLeading() + textLayout.getAscent(); max = Math.max(max, textLayout.getVisibleAdvance()); } w += max; } return new Dimension((int)Math.ceil(w), (int)Math.ceil(y) + insets.bottom + margin.bottom); } }
public void paint(Graphics g, int x, int y, String input) { Graphics2D g2d = (Graphics2D) g; int width = g.getClipBounds().width; String[] paragraphs = input.split("\n"); for (String p : paragraphs) { AttributedString attributedString = new AttributedString(p); attributedString.addAttribute(TextAttribute.FONT, (Font) UIManager .get("Label.font")); Color color = (Color) UIManager.get("Label.foreground"); attributedString.addAttribute(TextAttribute.FOREGROUND, color); AttributedCharacterIterator characterIterator = attributedString .getIterator(); FontRenderContext fontRenderContext = g2d.getFontRenderContext(); LineBreakMeasurer measurer = new LineBreakMeasurer(characterIterator, fontRenderContext); while (measurer.getPosition() < characterIterator.getEndIndex()) { TextLayout textLayout = measurer.nextLayout(width); y += textLayout.getAscent(); textLayout.draw(g2d, x, y); y += textLayout.getDescent() + textLayout.getLeading(); } } }
@Override public void draw(Graphics2D g2d, AttributedCharacterIterator arg1) { if (arg1.getAttribute(TextAttribute.PAINT_INFO) != null) { TextPaintInfo info = (TextPaintInfo) arg1.getAttribute(TextAttribute.PAINT_INFO); // TODO: Rest of stuff in info. g2d.setPaint(info.fillPaint); } g2d.fill(this.vec.getOutline()); }
Paint fgPaint; if (fgPaintStyle == null) { fgPaint = (Paint)firstLineAttr.getAttribute(TextAttribute.FOREGROUND); } else { fgPaint = new DrawPaint(ps).getPaint(graphics, fgPaintStyle); float fontSize = (Float)firstLineAttr.getAttribute(TextAttribute.SIZE); Double buSz = bulletStyle.getBulletFontSize(); if (buSz == null) { 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);
/** * Paints the text in each text run. Decorations are not painted here. */ protected void paintTextRuns(List textRuns, Graphics2D g2d) { for (int i = 0; i < textRuns.size(); i++) { TextRun textRun = (TextRun)textRuns.get(i); AttributedCharacterIterator runaci = textRun.getACI(); runaci.first(); TextPaintInfo tpi = (TextPaintInfo)runaci.getAttribute(PAINT_INFO); if ((tpi != null) && (tpi.composite != null)) { g2d.setComposite(tpi.composite); } textRun.getLayout().draw(g2d); } }
boolean emptyParagraph = text.toString().trim().isEmpty(); AttributedCharacterIterator it = at.getIterator(); LineBreakMeasurer measurer = new LineBreakMeasurer(it, graphics.getFontRenderContext()); for (;;) { int startIndex = measurer.getPosition(); nextBreak = it.getEndIndex(); if(endIndex < it.getEndIndex() && text.charAt(endIndex) == '\n'){ measurer.setPosition(endIndex + 1); layout = layout.getJustifiedLayout((float)wrappingWidth); : new AttributedString(it, startIndex, endIndex); DrawTextFragment line = fact.getTextFragment(layout, str); lines.add(line); if(endIndex == it.getEndIndex()) { break;
/** * Draws a string of attributed characters at {@code (x, y)}. * * @param iterator an iterator over the characters ({@code null} not * permitted). * @param x the x-coordinate. * @param y the y-coordinate. */ @Override public void drawString(AttributedCharacterIterator iterator, float x, float y) { Set<Attribute> s = iterator.getAllAttributeKeys(); if (!s.isEmpty()) { TextLayout layout = new TextLayout(iterator, getFontRenderContext()); layout.draw(this, x, y); } else { StringBuilder strb = new StringBuilder(); iterator.first(); for (int i = iterator.getBeginIndex(); i < iterator.getEndIndex(); i++) { strb.append(iterator.current()); iterator.next(); } drawString(strb.toString(), x, y); } }
public void append(String text, Color foreground) { AttributedString replacementText = new AttributedString(plainText + text); replacementText.addAttributes(paragraphText.getIterator().getAttributes(), 0, plainText.length()); AttributedCharacterIterator charIt = paragraphText.getIterator(); while(charIt.current() != AttributedCharacterIterator.DONE) { replacementText.addAttributes(charIt.getAttributes(), charIt.getIndex(), charIt.getEndIndex() + 1); charIt.next(); } replacementText.addAttribute(TextAttribute.FOREGROUND, foreground, plainText.length(), plainText.length() + text.length()); paragraphText = replacementText; computePlainString(); invalidateLayout(); }