Conversion of DXF to image but fonts pixelated


#1

I’m evaluating Aspose.CAD for Java to build a CAD viewer for our application and have a question. The CAD is converted to an image, which is displayed in the frontend. The problem is that the texts are pixelated and hard to read. How can I solve this problem?

I tried to substitute the fonts as proposed in the developer guide (CadStyleTableObject.setPrimaryFontName()) but it doesn’t change anything.
How do I have to specify the font in the method - only the name like ‘Arial’ or with extension ‘Arial.ttf’?
Which are the available fonts or do I have to specify a setting in Aspose/Java installation?


#2

@marlov,

Can you please share source file so that we may further investigate to help you out.


#3

SOURCE

public static void main(String[] args) {
        String dataDir = getDataDir();
        String srcFile = dataDir + "test-4510339.dxf";

    // Load a CAD drawing in an instance of CadImage
    LOG.info("Loading file...");
    try (CadImage image = (CadImage) Image.load(srcFile)) {

        // logging
        for (Object style : image.getStyles()) {
            LOG.info("image styles  " + ((CadStyleTableObject) style).getStyleName() + " -> " + ((CadStyleTableObject) style).getPrimaryFontName());
        }

        LOG.info("change primary font name");
        // Iterate over the items of CadStylesDictionary and set the font name
        for (Object style : image.getStyles()) {
            ((CadStyleTableObject) style).setPrimaryFontName("Arial.ttf");
        }

        // logging
        for (Object style : image.getStyles()) {
            LOG.info("image styles  " + ((CadStyleTableObject) style).getStyleName() + " -> " + ((CadStyleTableObject) style).getPrimaryFontName());
        }

        // Create an instance of CadRasterizationOptions
        CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
        rasterizationOptions.setDrawType(CadDrawTypeMode.UseObjectColor);
        rasterizationOptions.setPageHeight(2000);
        rasterizationOptions.setPageWidth(2000);

        // Export to PNG format
        PngOptions pngOptions = new PngOptions();
        pngOptions.setVectorRasterizationOptions(rasterizationOptions);
        image.save(srcFile + "-arial-ttf.png", pngOptions);
    }

    LOG.info("...Finished");
}

LOGGING OUTPUT

2019-10-15 10:04:58,756 [main] INFO test.cad.CadTest - Loading file…
2019-10-15 10:05:01,757 [main] INFO test.cad.CadTest - image styles STANDARD -> monos.ttf
2019-10-15 10:05:01,757 [main] INFO test.cad.CadTest - image styles -> genltshp.shx
2019-10-15 10:05:01,757 [main] INFO test.cad.CadTest - image styles ACISOGDT -> amgdt.shx
2019-10-15 10:05:01,757 [main] INFO test.cad.CadTest - image styles MM_STANDARD -> monos.ttf
2019-10-15 10:05:01,757 [main] INFO test.cad.CadTest - change primary font name
2019-10-15 10:05:01,757 [main] INFO test.cad.CadTest - image styles STANDARD -> Arial.ttf
2019-10-15 10:05:01,757 [main] INFO test.cad.CadTest - image styles -> Arial.ttf
2019-10-15 10:05:01,757 [main] INFO test.cad.CadTest - image styles ACISOGDT -> Arial.ttf
2019-10-15 10:05:01,757 [main] INFO test.cad.CadTest - image styles MM_STANDARD -> Arial.ttf
2019-10-15 10:05:13,927 [main] INFO test.cad.CadTest - …Finished

I tried with Arial and Arial.ttf but the resulting image doesn’t change.


#4

@marlov,

Can you please share source dxf file and generated result with us.