Conversion of DXF to image but fonts pixelated

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?

@marlov,

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

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.

@marlov,

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

Following behind an example illustrating my problem. I renamed the dxf file to .dxf.zip since the dxf extension was not allowed for upload.

test-E341658425100-1.dxf.zip (304.6 KB)
test-E341658425100-1.dxf-arial-ttf.png (51.9 KB)

Output of another tool I got to compare with:
test-E341658425100-1-dxf-expected-output.jpg (79.9 KB)

LOGGING

2019-10-16 09:13:36,734 [main] INFO test.cad.CadTest - Loading file…
2019-10-16 09:13:39,298 [main] INFO test.cad.CadTest - image styles STANDARD -> monos.ttf
2019-10-16 09:13:39,298 [main] INFO test.cad.CadTest - image styles STANDARD 5 mm -> monos.ttf
2019-10-16 09:13:39,298 [main] INFO test.cad.CadTest - image styles ACDINTS -> monos.ttf
2019-10-16 09:13:39,298 [main] INFO test.cad.CadTest - image styles ACDINGDT -> monos.ttf
2019-10-16 09:13:39,298 [main] INFO test.cad.CadTest - image styles STANDARD 7 mm -> monos.ttf
2019-10-16 09:13:39,298 [main] INFO test.cad.CadTest - image styles STANDARD 3.5 mm -> monos.ttf
2019-10-16 09:13:39,298 [main] INFO test.cad.CadTest - image styles STANDARD 2.5 mm -> monos.ttf
2019-10-16 09:13:39,298 [main] INFO test.cad.CadTest - image styles STANDARD 1.8 mm -> monos.ttf
2019-10-16 09:13:39,298 [main] INFO test.cad.CadTest - image styles SANDVIK_STYLE -> simplex.shx
2019-10-16 09:13:39,298 [main] INFO test.cad.CadTest - image styles ACANSGDT -> amgdt.shx
2019-10-16 09:13:39,298 [main] INFO test.cad.CadTest - image styles USER1 -> TXT.SHX
2019-10-16 09:13:39,298 [main] INFO test.cad.CadTest - change primary font name
2019-10-16 09:13:39,298 [main] INFO test.cad.CadTest - image styles STANDARD -> Arial.ttf
2019-10-16 09:13:39,298 [main] INFO test.cad.CadTest - image styles STANDARD 5 mm -> Arial.ttf
2019-10-16 09:13:39,298 [main] INFO test.cad.CadTest - image styles ACDINTS -> Arial.ttf
2019-10-16 09:13:39,298 [main] INFO test.cad.CadTest - image styles ACDINGDT -> Arial.ttf
2019-10-16 09:13:39,298 [main] INFO test.cad.CadTest - image styles STANDARD 7 mm -> Arial.ttf
2019-10-16 09:13:39,298 [main] INFO test.cad.CadTest - image styles STANDARD 3.5 mm -> Arial.ttf
2019-10-16 09:13:39,298 [main] INFO test.cad.CadTest - image styles STANDARD 2.5 mm -> Arial.ttf
2019-10-16 09:13:39,298 [main] INFO test.cad.CadTest - image styles STANDARD 1.8 mm -> Arial.ttf
2019-10-16 09:13:39,298 [main] INFO test.cad.CadTest - image styles SANDVIK_STYLE -> Arial.ttf
2019-10-16 09:13:39,298 [main] INFO test.cad.CadTest - image styles ACANSGDT -> Arial.ttf
2019-10-16 09:13:39,298 [main] INFO test.cad.CadTest - image styles USER1 -> Arial.ttf
2019-10-16 09:13:50,954 [main] INFO test.cad.CadTest - …Finished

@marlov,

Can you please share source file once again. I have tried to extract file from zip but facing error. Please check attachment. There is some kind of issue with attachment.2019-10-16 15_31_01-New Volume (F_).png (4.8 KB)

@Adnan.Ahmad

It’s not a real zip, I just used this allowed extension. Please rename test-E341658425100-1.dxf.zip back to test-E341658425100-1.dxf.

@marlov,

I have been able to observe issue and created an issue with ID CADJAVA-565 to further investigate and resolve the issue. This thread has been linked with the issue so that you may be notified once the issue will be fixed.

@Adnan.Ahmad,

is there a schedule when this issue will be fixed? I need to know because its essential for my evaluation…

Regards!

@marlov,

I like to inform that this issue will be resolved in Aspose.CAD 19.11, which will be released soon.

@Adnan.Ahmad

Perfect, thank you!

@marlov,

Thank you for sharing the feedback.

@Adnan.Ahmad

Happy new year!

I have seen that there are release notes for version 20.1 which include the issue CADJAVA-565. When will the version be available for download?

@marlov,

Happy new year to you as well.

I like to share that at present we are in process of launching Aspose.CAD for Java 20.1. We request for your patience till the product is made available online. We will share the notification with you once the issues resolved in 20.1 are finalized after internal QA process.

The issues you have found earlier (filed as CADJAVA-565) have been fixed in this update.