當前位置: 首頁>>代碼示例>>Java>>正文


Java LineBreakMeasurer類代碼示例

本文整理匯總了Java中java.awt.font.LineBreakMeasurer的典型用法代碼示例。如果您正苦於以下問題:Java LineBreakMeasurer類的具體用法?Java LineBreakMeasurer怎麽用?Java LineBreakMeasurer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


LineBreakMeasurer類屬於java.awt.font包,在下文中一共展示了LineBreakMeasurer類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getLineBreakMeasurers

import java.awt.font.LineBreakMeasurer; //導入依賴的package包/類
private LineBreakMeasurer[] getLineBreakMeasurers(Graphics2D g) {
    if (lbmTexto == null && (Texto != null && !Texto.equals(""))) {
        lbmTexto = new LineBreakMeasurer[Textos.length];
        for (int i = 0; i < lbmTexto.length; i++) {
            String tmp = Textos[i].isEmpty()? " " : Textos[i];
            AttributedString attribString = new AttributedString(tmp);
            attribString.addAttribute(TextAttribute.FONT, getFont());
            //attribString.addAttribute(TextAttribute.FONT, getFont());
            AttributedCharacterIterator attribCharIterator = attribString.getIterator();
            //FontRenderContext frc = new FontRenderContext(null, true, false);
            FontRenderContext frc = g.getFontRenderContext();
            lbmTexto[i] = new LineBreakMeasurer(attribCharIterator, frc);
        }
    }
    return lbmTexto;
}
 
開發者ID:chcandido,項目名稱:brModelo,代碼行數:17,代碼來源:DesenhadorDeTexto.java

示例2: getPreferredSize

import java.awt.font.LineBreakMeasurer; //導入依賴的package包/類
@Override
public Dimension getPreferredSize(JComponent c) {
    String tipText = ((JToolTip)c).getTipText();
    if (tipText == null || tipText.isEmpty()) {
        return new Dimension(0, 0);
    }

    float x = 0f;
    float y = 0f;
    for (String line : lineBreak.split(tipText)) {
        if (line.isEmpty()) {
            y += LEADING;
            continue;
        }
        AttributedCharacterIterator styledText
            = new AttributedString(line).getIterator();
        LineBreakMeasurer measurer = new LineBreakMeasurer(styledText, frc);

        while (measurer.getPosition() < styledText.getEndIndex()) {

            TextLayout layout = measurer.nextLayout(maximumWidth);

            x = Math.max(x, layout.getVisibleAdvance());
            y += layout.getAscent() + layout.getDescent() + layout.getLeading();

        }
    }
    return new Dimension((int) (x + 2 * margin),
                         (int) (y + 2 * margin));

}
 
開發者ID:wintertime,項目名稱:FreeCol,代碼行數:32,代碼來源:FreeColToolTipUI.java

示例3: measureExactLineBreakIndex

import java.awt.font.LineBreakMeasurer; //導入依賴的package包/類
protected int measureExactLineBreakIndex(float width, int endLimit, boolean requireWord)
{
	//FIXME would it be faster to create and cache a LineBreakMeasurer for the whole paragraph?
	Map<Attribute, Object> attributes = new HashMap<Attribute, Object>();
	// we only need the font as it includes the size and style
	attributes.put(TextAttribute.FONT, fontInfo.fontInfo.font);
	
	String textLine = paragraphText.substring(paragraphPosition, endLimit);
	AttributedString attributedLine = new AttributedString(textLine, attributes);

	// we need a fresh iterator for the line
	BreakIterator breakIterator = paragraphTruncateAtChar ? BreakIterator.getCharacterInstance()
			: BreakIterator.getLineInstance();
	LineBreakMeasurer breakMeasurer = new LineBreakMeasurer(attributedLine.getIterator(), 
			breakIterator, context.getFontRenderContext());
	int breakIndex = breakMeasurer.nextOffset(width, endLimit - paragraphPosition, requireWord) 
			+ paragraphPosition;
	if (logTrace)
	{
		log.trace("exact line break index measured at " + (paragraphOffset + breakIndex));
	}
	
	return breakIndex;
}
 
開發者ID:TIBCOSoftware,項目名稱:jasperreports,代碼行數:25,代碼來源:SimpleTextLineWrapper.java

示例4: drawTextInBoundedArea

import java.awt.font.LineBreakMeasurer; //導入依賴的package包/類
private static void drawTextInBoundedArea(Graphics2D g2d, int x1, int y1,
        int x2, int y2, String text) {
  float interline = 1;
  float width = x2 - x1;
  AttributedString as = new AttributedString(text);
  as.addAttribute(TextAttribute.FOREGROUND, g2d.getPaint());
  as.addAttribute(TextAttribute.FONT, g2d.getFont());
  AttributedCharacterIterator aci = as.getIterator();
  FontRenderContext frc = new FontRenderContext(null, true, false);
  LineBreakMeasurer lbm = new LineBreakMeasurer(aci, frc);
  while (lbm.getPosition() < text.length()) {
    TextLayout tl = lbm.nextLayout(width);
    y1 += tl.getAscent();
    tl.draw(g2d, x1, y1);
    y1 += tl.getDescent() + tl.getLeading() + (interline - 1.0f) * tl.
            getAscent();
    if (y1 > y2) {
      break;
    }
  }
}
 
開發者ID:hopshadoop,項目名稱:hopsworks,代碼行數:22,代碼來源:GraphicsUtils.java

示例5: pixelDataFromString

import java.awt.font.LineBreakMeasurer; //導入依賴的package包/類
private final static void pixelDataFromString(int width, int height, String str, java.awt.Font font, int[] pixels, LineBreakMeasurer measurer) {
	measurer.setPosition(0);
	g2d.clearRect(0, 0, width, height);
	g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
	g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
	float wrapping_width = width;
	float y = 0;
	int length = str.length();
	while (measurer.getPosition() < length) {
		TextLayout layout = measurer.nextLayout(wrapping_width);
		y += (layout.getAscent());
		float x = layout.isLeftToRight() ? 0 : (wrapping_width - layout.getAdvance());

		layout.draw(g2d, x, y);
		y += layout.getDescent() + layout.getLeading();
	}
	image.getRaster().getDataElements(0, 0, image.getWidth(), image.getHeight(), pixels);
}
 
開發者ID:sunenielsen,項目名稱:tribaltrouble,代碼行數:19,代碼來源:Test.java

示例6: nextLayout

import java.awt.font.LineBreakMeasurer; //導入依賴的package包/類
/**
* @param wrappingWidth width of the layout
* @param frCtx for possible new instance of LineBreakMeasurer
* @return next TextLayout that is to be rendered
*/
private TextLayout nextLayout(float wrappingWidth, FontRenderContext frc) {
    TextLayout l;

    if (currentLayout == textLayouts.size()) {
        LineBreakMeasurer old = lineBreakMeasurer;
        LineBreakMeasurer measurer = getMeasurer(frc);
        if (measurer == null) {
            return null;
        }
        l = measurer.nextLayout(wrappingWidth);
        textLayouts.add(l);

        if (old != measurer) { // new line
            startLayouts.add(l);
        }

    } else {
        l = (TextLayout) textLayouts.get(currentLayout);
    }
    currentLayout++; // advance to next
    return l;
}
 
開發者ID:CharlesSkelton,項目名稱:studio,代碼行數:28,代碼來源:DefaultPrintable.java

示例7: drawText

import java.awt.font.LineBreakMeasurer; //導入依賴的package包/類
private void drawText(Graphics2D g2, String text, float width) {
	FontRenderContext frc = g2.getFontRenderContext();

	AttributedString styledText = new AttributedString(text);
	AttributedCharacterIterator aci = styledText.getIterator();
	int start = aci.getBeginIndex();
	int end = aci.getEndIndex();
	LineBreakMeasurer measurer = new LineBreakMeasurer(aci, frc);
	measurer.setPosition(start);

	float x = 0, y = 0;
	while (measurer.getPosition() < end) {
		TextLayout layout = measurer.nextLayout(width);

		y += layout.getAscent();
		float dx = layout.isLeftToRight() ? 0 : width - layout.getAdvance();

		layout.draw(g2, x + dx, y);
		y += layout.getDescent() + layout.getLeading();
	}
}
 
開發者ID:pfichtner,項目名稱:jrunalyzer,代碼行數:22,代碼來源:SelectedWaypointRenderer.java

示例8: wrapLines

import java.awt.font.LineBreakMeasurer; //導入依賴的package包/類
private String wrapLines(String s, float wrappingWidth, FontRenderContext frc, String lineBreak) {
    AttributedCharacterIterator aci = new AttributedString(s).getIterator();
    int end = aci.getEndIndex();
    LineBreakMeasurer measurer = new LineBreakMeasurer(aci, frc);
    StringBuffer output = new StringBuffer();
    int position = 0;
    int lastPosition = 0;
    do {
        measurer.nextLayout(wrappingWidth);
        position = measurer.getPosition();
        output.append(s, lastPosition, position);
        output.append(lineBreak);
        lastPosition = position;
    } while (position < end);
    return output.toString();
}
 
開發者ID:wikipathways,項目名稱:reactome2gpml-converter,代碼行數:17,代碼來源:ReactomeToGPMLConverter.java

示例9: setFont

import java.awt.font.LineBreakMeasurer; //導入依賴的package包/類
@Override
public void setFont(Font f) {
    super.setFont(f);
    atText.addAttribute(TextAttribute.FONT,
                        usesSpecificFont() ? getFont() : getMainFont());
    lbm = new LineBreakMeasurer(atText.getIterator(), DEFAULT_FRC);
    invalidate();
}
 
開發者ID:sharwell,項目名稱:zgrnbviewer,代碼行數:9,代碼來源:MultilineText.java

示例10: getPreferredSize

import java.awt.font.LineBreakMeasurer; //導入依賴的package包/類
public Dimension getPreferredSize(JComponent c) {
    String tipText = ((JToolTip)c).getTipText();
    if (tipText == null) {
        return new Dimension(0, 0);
    }

    float x = 0f;
    float y = 0f;
    for (String line : lineBreak.split(((JToolTip) c).getTipText())) {
        AttributedCharacterIterator styledText
            = new AttributedString(line).getIterator();
        LineBreakMeasurer measurer = new LineBreakMeasurer(styledText, frc);

        while (measurer.getPosition() < styledText.getEndIndex()) {

            TextLayout layout = measurer.nextLayout(maximumWidth);

            x = Math.max(x, layout.getVisibleAdvance());
            y += layout.getAscent() + layout.getDescent() + layout.getLeading();

        }
    }
    return new Dimension((int) (x + 2 * margin),
                         (int) (y + 2 * margin));

}
 
開發者ID:vishal-mittal,項目名稱:SOEN6471-FreeCol,代碼行數:27,代碼來源:FreeColToolTipUI.java

示例11: countLines

import java.awt.font.LineBreakMeasurer; //導入依賴的package包/類
private static int countLines(JTextArea textArea)
{
	AttributedString text = new AttributedString(textArea.getText());
	FontRenderContext frc = textArea.getFontMetrics(textArea.getFont()).getFontRenderContext();
	AttributedCharacterIterator charIt = text.getIterator();
	LineBreakMeasurer lbm = new LineBreakMeasurer(charIt, frc);
	float formatWidth = (float) textArea.getSize().width;
	lbm.setPosition(charIt.getBeginIndex());
	
	int numLines =0;
	while (lbm.getPosition()<charIt.getEndIndex())
	{
		lbm.nextLayout(formatWidth);
		numLines++;
	}	
	return numLines;
}
 
開發者ID:PM-Master,項目名稱:Harmonia-1.5,代碼行數:18,代碼來源:MessageController.java

示例12: paintOrGetSize

import java.awt.font.LineBreakMeasurer; //導入依賴的package包/類
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);
}
 
開發者ID:visit,項目名稱:spark-svn-mirror,代碼行數:25,代碼來源:JMultilineLabel.java

示例13: render

import java.awt.font.LineBreakMeasurer; //導入依賴的package包/類
@Override
public void render(final Graphics2D g) {
  if (this.displayedText == null || this.displayedText.isEmpty() || !Game.getRenderEngine().canRender(this.entity)) {
    return;
  }

  final Point2D location = Game.getCamera().getViewPortLocation(this.entity);
  RenderEngine.renderImage(g, this.bubble, new Point2D.Double(location.getX() + this.entity.getWidth() / 2.0 - this.textBoxWidth / 2.0 - PADDING, location.getY() - this.height - PADDING));

  g.setColor(SPEAK_FONT_COLOR);
  final FontRenderContext frc = g.getFontRenderContext();

  final String text = this.displayedText;
  final AttributedString styledText = new AttributedString(text);
  styledText.addAttribute(TextAttribute.FONT, this.font);
  final AttributedCharacterIterator iterator = styledText.getIterator();
  final LineBreakMeasurer measurer = new LineBreakMeasurer(iterator, frc);
  measurer.setPosition(0);
  final float x = (float) Game.getCamera().getViewPortLocation(this.entity).getX() + this.entity.getWidth() / 2.0f - this.textBoxWidth / 2.0f;
  float y = (float) Game.getCamera().getViewPortLocation(this.entity).getY() - this.height;
  while (measurer.getPosition() < text.length()) {
    final TextLayout layout = measurer.nextLayout(this.textBoxWidth);

    y += layout.getAscent();
    final float dx = layout.isLeftToRight() ? 0 : this.textBoxWidth - layout.getAdvance();
    layout.draw(g, x + dx, y);
    y += layout.getDescent() + layout.getLeading();
  }
}
 
開發者ID:gurkenlabs,項目名稱:litiengine,代碼行數:30,代碼來源:SpeechBubble.java

示例14: paint

import java.awt.font.LineBreakMeasurer; //導入依賴的package包/類
@Override
public void paint(Graphics g, JComponent c) {
    if (c.isOpaque()) {
        ImageLibrary.drawTiledImage("image.background.FreeColToolTip", g, c, null);
    }

    g.setColor(Color.BLACK); // FIXME: find out why this is necessary

    Graphics2D graphics = (Graphics2D)g;
    float x = margin;
    float y = margin;
    for (String line : lineBreak.split(((JToolTip) c).getTipText())) {
        if (line.isEmpty()) {
            y += LEADING;
            continue;
        }
        AttributedCharacterIterator styledText =
            new AttributedString(line).getIterator();

        LineBreakMeasurer measurer = new LineBreakMeasurer(styledText, frc);

        while (measurer.getPosition() < styledText.getEndIndex()) {

            TextLayout layout = measurer.nextLayout(maximumWidth);

            y += (layout.getAscent());
            float dx = layout.isLeftToRight() ?
                0 : (maximumWidth - layout.getAdvance());

            layout.draw(graphics, x + dx, y);
            y += layout.getDescent() + layout.getLeading();
        }
    }
 }
 
開發者ID:FreeCol,項目名稱:freecol,代碼行數:35,代碼來源:FreeColToolTipUI.java

示例15: test

import java.awt.font.LineBreakMeasurer; //導入依賴的package包/類
public void test() {

        // construct a paragraph as follows: MIXED + [SPACING + WORD] + ...
        StringBuffer text = new StringBuffer(MIXED);
        for (int i=0; i < NUM_WORDS; i++) {
            text.append(SPACING);
            text.append(WORD);
        }

        AttributedString attrString = new AttributedString(text.toString());
        attrString.addAttribute(TextAttribute.SIZE, new Float(24.0));

        LineBreakMeasurer measurer = new LineBreakMeasurer(attrString.getIterator(),
                                                           DEFAULT_FRC);

        // get width of a space-word sequence, in context
        int sequenceLength = WORD.length()+SPACING.length();
        measurer.setPosition(text.length() - sequenceLength);

        TextLayout layout = measurer.nextLayout(10000.0f);

        if (layout.getCharacterCount() != sequenceLength) {
            throw new Error("layout length is incorrect!");
        }

        final float sequenceAdvance = layout.getVisibleAdvance();

        float wrappingWidth = sequenceAdvance * 2;

        // now run test with a variety of widths
        while (wrappingWidth < (sequenceAdvance*NUM_WORDS)) {
            measurer.setPosition(0);
            checkMeasurer(measurer,
                          wrappingWidth,
                          sequenceAdvance,
                          text.length());
            wrappingWidth += sequenceAdvance / 5;
        }
    }
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:40,代碼來源:TestLineBreakWithFontSub.java


注:本文中的java.awt.font.LineBreakMeasurer類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。