简体   繁体   English

在Java中从Font对象创建一个Shape对象

[英]Create a Shape Object from Font Object in Java

I have a font object and a String. 我有一个字体对象和一个字符串。 I want to return a Shape Object that is a representation of the String. 我想返回一个Shape对象,它是String的表示形式。 I have a whole bunch of other classes that will display the String and take care of it. 我有一大堆其他类将显示String并处理它。

I'm having trouble figuring out how to do this when I do not have a graphics/graphics2d object. 当我没有 graphics / graphics2d对象时,我无法弄清楚如何执行此操作 Any Help? 任何帮助? I have searched the net but had trouble finding helpful links. 我在网上搜索但很难找到有用的链接。

public class SpecializationOfTester extends ParentTester {

    private String      str;
    private Font        font;


    public SpecializationOfTester(String str, Font font) {
        this.font = font;
        this.str = str;
    }

    public Shape getShape()
    {
        Shape           s;
        //
        //
        return s;
    }

}

Thanks 谢谢

You can use GlyphVector#getOutline() , as mentioned here . 您可以使用GlyphVector#getOutline()如提及这里 You can create a graphics context in a BufferedImage , as discussed in Using Headless Mode in the Java SE Platform . 您可以在BufferedImage创建图形上下文,如Java SE平台中的使用无头模式中所述

See also these appealing examples: 另见这些吸引人的例子:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM