当前位置: 首页>>代码示例>>Java>>正文


Java TextLayout.isLeftToRight方法代码示例

本文整理汇总了Java中java.awt.font.TextLayout.isLeftToRight方法的典型用法代码示例。如果您正苦于以下问题:Java TextLayout.isLeftToRight方法的具体用法?Java TextLayout.isLeftToRight怎么用?Java TextLayout.isLeftToRight使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.awt.font.TextLayout的用法示例。


在下文中一共展示了TextLayout.isLeftToRight方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: render

import java.awt.font.TextLayout; //导入方法依赖的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

示例2: paint

import java.awt.font.TextLayout; //导入方法依赖的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

示例3: drawText

import java.awt.font.TextLayout; //导入方法依赖的package包/类
private void drawText( Graphics g, int w, int h ) {
    Graphics2D g2 = (Graphics2D) g;
    g2.setColor(Color.white);
    g2.fillRect(0, 0, w, h);
    g2.setColor(Color.black);

    /// sets font, RenderingHints.
    setParams( g2 );

    /// If flag is set, recalculate fontMetrics and reset the scrollbar
    if ( updateFontMetrics || isPrinting ) {
        /// NOTE: re-calculates in case G2 transform
        /// is something other than NONE
        calcFontMetrics( g2, w, h );
        updateFontMetrics = false;
    }
    /// Calculate the amount of text that can be drawn...
    calcTextRange();

    /// Draw according to the set "Text to Use" mode
    if ( textToUse == RANGE_TEXT || textToUse == ALL_GLYPHS ) {
        int charToDraw = drawStart;
        if ( showGrid )
          drawGrid( g2 );

        for ( int i = 0; i < numCharDown && charToDraw <= drawEnd; i++ ) {
          for ( int j = 0; j < numCharAcross && charToDraw <= drawEnd; j++, charToDraw++ ) {
              int gridLocX = j * gridWidth + canvasInset_X;
              int gridLocY = i * gridHeight + canvasInset_Y;

              modeSpecificDrawChar( g2, charToDraw,
                                    gridLocX + gridWidth / 2,
                                    gridLocY + maxAscent );

          }
        }
    }
    else if ( textToUse == USER_TEXT ) {
        g2.drawRect( 0, 0, w - 1, h - 1 );
        for ( int i = drawStart; i <= drawEnd; i++ ) {
            int lineStartX = canvasInset_Y;
            int lineStartY = ( i - drawStart ) * gridHeight + maxAscent;
            modeSpecificDrawLine( g2, userText[i], lineStartX, lineStartY );
        }
    }
    else {
        float xPos, yPos = (float) canvasInset_Y;
        g2.drawRect( 0, 0, w - 1, h - 1 );
        for ( int i = drawStart; i <= drawEnd; i++ ) {
            TextLayout oneLine = (TextLayout) lineBreakTLs.elementAt( i );
            xPos =
              oneLine.isLeftToRight() ?
              canvasInset_X : ( (float) w - oneLine.getAdvance() - canvasInset_X );

            float fmData[] = {0, oneLine.getAscent(), 0, oneLine.getDescent(), 0, oneLine.getLeading()};
            if (g2Transform != NONE) {
                AffineTransform at = getAffineTransform(g2Transform);
                at.transform( fmData, 0, fmData, 0, 3);
            }
            //yPos += oneLine.getAscent();
            yPos += fmData[1]; // ascent
            //oneLine.draw( g2, xPos, yPos );
            tlDrawLine( g2, oneLine, xPos, yPos );
            //yPos += oneLine.getDescent() + oneLine.getLeading();
            yPos += fmData[3] + fmData[5]; // descent + leading
        }
    }
    g2.dispose();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:70,代码来源:FontPanel.java


注:本文中的java.awt.font.TextLayout.isLeftToRight方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。