Java 8 TextLayout - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 TextLayout class.

This code example shows how to use the following methods:getAscent, getDescent, getLeading
 
    /** 
     * @return full height of this text run which is sum of ascent, descent and leading 
     */ 
    public float getHeight(){ 
        double h = Math.ceil(_layout.getAscent()) + Math.ceil(_layout.getDescent()) + _layout.getLeading();
        return (float)h;
    } 
 
    /** 
     * 
     * @return width if this text run 
     */ 
    public float getWidth(){ 
        return _layout.getAdvance();
    } 
 
    /** 
     * 
     * @return the string to be painted 
6
CodeRank
This code example shows how to use the following methods:draw
        g.fillRect( x, y-60, 90, 90 );
 
        FontRenderContext frc = ((Graphics2D)g).getFontRenderContext();
        Font f = new Font("Monospaced",Font.BOLD, 70); 
        String s = "" + p.getScore();
        TextLayout tl = new TextLayout(s, f, frc);
        g.setColor( Color.WHITE );
        tl.draw(((Graphics2D)g), x, y );
    } 
} 
6
CodeRank
This code example shows how to use the following methods:getAscent, getDescent, getLeading
  { 
  } 
 
  public void update(TextLayout textLayout)
  { 
    ascent = Math.max(ascent, textLayout.getAscent());
    descent = Math.max(descent, textLayout.getDescent());
    leading = Math.max(leading, textLayout.getLeading());
  } 
 
  public float getLineHeight() 
  { 
    return ascent + descent + leading;
  } 
 
  public float getBaseline() 
  { 
    return ascent + leading;
  } 
 
6
CodeRank
This code example shows how to use the following methods:draw, getBounds
		GenericFontModifier modifier = new GenericFontModifier();
		modifier.setSizeDelta( false );
		modifier.setSize( 8 );
		g.setFont( modifier.modify( font ) );
		 
		TextLayout layout = new TextLayout( text, g.getFont(), ((Graphics2D)g).getFontRenderContext() );
		Rectangle2D bounds = layout.getBounds();
		 
		layout.draw( (Graphics2D)g, 
				(float)(x + getIconWidth() - bounds.getWidth() - bounds.getX() - 1), 
				(float)(y + getIconHeight() - bounds.getHeight() - bounds.getY() - 1 ));
		 
		g.setFont( font );
	} 
	 
	private void drawArrow( Graphics g, int x, int y ){
		g.drawLine( x, y, x+1, y );
		g.drawLine( x+1, y+1, x+2, y+1 );
		g.drawLine( x+2, y+2, x+3, y+2 );
		g.drawLine( x+1, y+3, x+2, y+3 );
6
CodeRank
This code example shows how to use the following methods:getAscent, getDescent, getLeading
        return attributedString;
    } 
 
    public TextLayout getTextLayout(FontRenderContext fontRenderContext) {
        if (!isCachedFontRenderContext(fontRenderContext)) {
            cachedLayout = new TextLayout(attributedString.getIterator(), fontRenderContext);
            cachedFontRenderContext = fontRenderContext;
        } 
        return cachedLayout;
    } 
 
    public float getHeight(FontRenderContext fontRenderContext) {
        TextLayout tl = getTextLayout(fontRenderContext);
        return tl.getLeading() + tl.getAscent() + tl.getDescent();
    } 
 
    public float getVisibleAdvance(FontRenderContext fontRenderContext) {
        TextLayout tl = getTextLayout(fontRenderContext);
        return tl.getVisibleAdvance();
    } 
5
CodeRank
This code example shows how to use the following methods:getAscent, getDescent, getLeading
        linkBox.setBounds(linkBounds);
        add(linkBox);
    } 
 
    public void layout(FontRenderContext fontRenderContext) {
        this.textLayout = new TextLayout(attributedString.getIterator(), fontRenderContext);
        int textHeight = (int) (textLayout.getAscent() + textLayout.getDescent() + textLayout.getLeading());
        int totalHeight = textHeight + getInsetsTop() + getInsetsBottom();
        setHeight(totalHeight);
    } 
 
    public void paintContent(Graphics2D g2) {
        float v = getBaseline();
        AttributedString toRender = attributedString;
//        LinkSpan activeLinkSpan = getPage().getActiveLinkSpan(); 
//        if (activeLinkSpan != null) { 
//            for(LinkBox link : linkMap.keySet()) { 
//                if(link.getLinkSpan().equals(activeLinkSpan)) { 
//                    toRender = linkMap.get(link); 
//                    break; 
5
CodeRank
This code example shows how to use the following methods:getOutline
 
    private static Shape stringToShape(Graphics2D g, String s, float size) {
        FontRenderContext context = g.getFontRenderContext();
        Font font = g.getFont();
        font = font.deriveFont(size);
        TextLayout text = new TextLayout(s, font, context);
        Shape shape = text.getOutline(null);
        shape = justify(shape); 
        return shape; 
    } 
 
    static Region create(Graphics2D g, Dimension size) {
        int count = Names.size();
        Shape[] shapes = new Shape[count];
        double[] widths = new double[count];
        double[] heights = new double[count];
        float fontSize = 32f * size.height / 400;
 
        for (int n=0; n<count; n++) {
            String name = Names.get(n);
5
CodeRank
This code example shows how to use the following methods:draw
  public void displayStatusMessage(String message) {
    if (isSplashscreenVisible()) { 
      return; 
    } 
    resetTextArea(); 
    TextLayout layout = new TextLayout(message, font, renderContext);
    layout.draw(graphics, 105, 333);
    SplashScreen.getSplashScreen().update();
  } 
 
  private void resetTextArea() { 
    Paint oldPaint = graphics.getPaint();
    graphics.setPaint(textAreaGradient);
    graphics.fill(textAreaRectangle);
    graphics.setPaint(oldPaint);
  } 
 
  @Override 
  public void displayVersion(String string) {
    if (isSplashscreenVisible()) { 
5
CodeRank
This code example shows how to use the following methods:getOutline
        getEscherGraphics().drawString(string, x, y);
    } 
 
    public void drawString(AttributedCharacterIterator attributedcharacteriterator, float x, float y)
    { 
        TextLayout textlayout = new TextLayout(attributedcharacteriterator, getFontRenderContext());
        Paint paint1 = getPaint();
        setColor(getColor());
        fill(textlayout.getOutline(AffineTransform.getTranslateInstance(x, y)));
        setPaint(paint1);
    } 
 
    public void drawString(AttributedCharacterIterator attributedcharacteriterator, int x, int y)
    { 
        drawString(attributedcharacteriterator, x, y);
    } 
 
    public void fill(Shape shape) 
    { 
        if (logger.check( POILogger.WARN ))
5
CodeRank
This code example shows how to use the following methods:
    if(layout == null)
    { 
      if(getText() == null || getText().length() == 0) 
        layout = new TextLayout("" + KeyEvent.CHAR_UNDEFINED, font, fontRenderContet);
      else 
        layout = new TextLayout(getText(), font, fontRenderContet);
    } 
    return layout;
  } 
 
} 
5
CodeRank
See Code Examples for Java 8 TextLayout Methods: