miile7
miile7

Reputation: 2403

dm-script looses font family when saving images

When I add text annotations to an image without showing the image, the font family is always monospace. How do I fix this?

Edit: After some more testing the problem appears for both, with showImage() and without. When opening the saved image the font family is lost.


I want to open all image files in one directory and add annotations to every file without showing the file to the user. Everything is working fine except that the font family always is monospace.

The following image shows the text added without a call of showImage() on the left. On the right this is the exact same code but with one call of showImage(). As one can see, the font family is wrong. The code is shown below.

Edit: As mentioned above, the right image is equal to the left image when I close the right image and open it again.

Text annotations created with showImage() and without showImage()

String path = "/temporary/path/for/saving/test-img.dm4";

// create dummy image and save it
image img := RealImage("The Image", 4, 512, 512);
img = itheta
img.saveImage(path);

// - - -
// open the image and process it

img := openImage(path);
// img.showImage(); // <- This makes the difference between left and right image 
                    //    *Edit*: Both images loose their font family if they are
                    //    closed and opened again

ImageDisplay disp;
if(img.ImageCountImageDisplays() == 0){
    disp = ImageCreateImageDisplay(img, -2);
}
else{
    disp = img.ImageGetImageDisplay(0);
}

Component text = NewTextAnnotation(100, 300, "Some text", 20);
text.ComponentSetForegroundColor(0, 0, 140);
text.ComponentSetFontFaceName("sans-serif");
disp.ComponentAddChildAtEnd(text);

// save so the image can be opened if it is not shown anyway
img.saveImage(path);

Upvotes: 0

Views: 48

Answers (1)

miile7
miile7

Reputation: 2403

All Credit goes to @BmyGuest. As he suggested in his comment one should only use the fonts that are installed. Fonts like "sans-serif" do not exist. To find out which fonts are installed, use (as @BmyGuest said) the menu when right-clicking an annotation.

If you want to get the fonts installed directly you can use this answer (from @BmyGuest of course :)) which selects all the available fonts.

Upvotes: 0

Related Questions