In order to change the font of the text, you need to supply an attributed string to the LineBreakMeasurer. See e655 混合风格的文本 for an example.

    public void drawParagraph(Graphics2D g, String paragraph, float width) {
        LineBreakMeasurer linebreaker = new LineBreakMeasurer(
            new AttributedString(paragraph).getIterator(), g.getFontRenderContext());
    
        float y = 0.0f;
        while (linebreaker.getPosition() < paragraph.length()) {
            TextLayout tl = linebreaker.nextLayout(width);
    
            y += tl.getAscent();
            tl.draw(g, 0, y);
            y += tl.getDescent() + tl.getLeading();
        }
    }

 

Related Examples

相关文章:

  • 2022-12-23
  • 2021-08-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-26
  • 2021-11-17
猜你喜欢
  • 2021-12-27
  • 2022-12-23
  • 2021-10-02
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-16
相关资源
相似解决方案