フォントキャッシュの更新
Aspose.PSD for Javaを使用すると、開発者はフォントキャッシュを更新する可能性を追加できます。以下はその機能のコードデモンストレーションです。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getDataDir(ForceFontCache.class) + "DrawingAndFormattingImages/"; | |
try (PsdImage image = (PsdImage) Image.load(dataDir + "sample.psd")) { | |
image.save(dataDir + "NoFont.psd"); | |
} | |
System.out.println("You have 2 minutes to install the font"); | |
Thread.sleep(2 * 60 * 1000); | |
OpenTypeFontsCache.updateCache(); | |
try (PsdImage image1 = (PsdImage) Image.load(dataDir + "sample.psd")) { | |
image1.save(dataDir + "HasFont.psd"); | |
} |
欠落フォントの置換設定
Aspose.PSD for Javaを使用すると、開発者は欠落しているフォントを置換することができます。以下のサンプルコードを使用すると、PSDドキュメントをラスター画像(PNG、JPG、BMP形式に)保存する際に、デフォルトフォント名を設定できます。このデフォルトフォントは、現在のオペレーティングシステムで見つからないフォントすべての置換フォントとして使用されます。以下はその機能のコードデモンストレーションです。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getDataDir(FontReplacement.class) + "DrawingAndFormattingImages/"; | |
// Load an image in an instance of image and setting default replacement font. | |
PsdLoadOptions psdLoadOptions = new PsdLoadOptions(); | |
psdLoadOptions.setDefaultReplacementFont("Arial"); | |
try (PsdImage psdImage = (PsdImage) Image.load(dataDir + "Cloud_AzPlat_Banner3A_SB_EN_US_160x600_chinese_font.psd", psdLoadOptions)) { | |
PngOptions pngOptions = new PngOptions(); | |
psdImage.save(dataDir + "replaced_font.png", pngOptions); | |
} |