How to set the font

Hello,

When I save PSD to png file, the console output print these lines.
Font cache was not available for : STSongti-SC-Black
Font cache was not available for : STSongti-SC-Black
Font cache was not available for : STSongti-SC-Black
Font cache was not available for : STSongti-SC-Black
Font cache was not available for : STSongti-SC-Black
Font cache was not available for : ArialMT
PSD text was supposedly updated from 屜ㅐ쾏�㟿Ā� to 就像这样!
Font cache was not available for : MicrosoftYaHei
Font cache was not available for : MicrosoftYaHei

and the out png file is not correct, the text is displayed very strange.
the flowing is my code, it is very simple.

   String dataDir = Utils.getDataDir(SavingToDisk.class) + "Conversion/";
   String sourceFile = dataDir + "6.psd";
   String destName = dataDir + "result.png";

    // load PSD image and replace the non found fonts.
    Image image = Image.load(sourceFile);
    
    PsdImage psdImage = (PsdImage)image;
    psdImage.save(destName, new PngOptions());

result.png (18.7 KB)

@ideologist0

Can you please make sure if the fonts used in your source PSD are actually available on machine where you are performing conversion. The issue you are observing is owing to missing fonts.

你在对文本图层做更新的时候 可以修改字体么?
或者说 你可以更改文本图层的字体吗?

Yes, the PSD file is edited on my computer and the program is running on my computer.

不可以的,目前没有找到办法

你有遇到过 文本图层修改后消失 需要双击图层 或者排个横板才能出现这种吗

遇到过的,经常出现这个问题

心态崩了,太难受了。
这个产品的文本图层,font属性是只读的,而且updateText没有对应的重载方法,巨难受。
我在想是不是因为他们的产品有aspose.font 所以封装为只读= = 如果我们修改字体 就需要我们连携这样子

感觉应该不是,应该还是接口没有实现呢,我看ITextStyle里面的方法也不太够用

超级难受啊,如果这个实现不了,可能要想其他的方案了。

同样 太难受了
= = 如果技术支持无法给出方案 已经在准备其他方案了

@ideologist0

I have seen similar question from your in another thread as well and have responded for your convenience there.

How do I update fonts for individual text layers
https://forum.aspose.com/t/how-do-i-update-fonts-for-individual-text-layers/223812/3

你们解决了,我目前也遇到这个问题,十分痛苦

@Kevin_Bowen

Can you please try using the following sample code on your end.

            string outputFilePng = "result_fontEditTest.png";
            string outputFilePsd = "fontEditTest.psd";

            void AssertAreEqual(object expected, object actual)
            {
                if (!object.Equals(expected, actual))
                {
                    throw new Exception("Objects are not equal.");
                }
            }

            using (var image = new PsdImage(500, 500))
            {
                FillLayer backgroundFillLayer = FillLayer.CreateInstance(FillType.Color);
                ((IColorFillSettings)backgroundFillLayer.FillSettings).Color = Color.White;
                image.AddLayer(backgroundFillLayer);

                TextLayer textLayer = image.AddTextLayer("Text 1", new Rectangle(10, 35, image.Width, 35));

                ITextPortion firstPortion = textLayer.TextData.Items[0];
                firstPortion.Style.FontName = FontSettings.GetAdobeFontName("Comic Sans MS");

                var secondPortion = textLayer.TextData.ProducePortion();
                secondPortion.Text = "Text 2";
                secondPortion.Paragraph.Apply(firstPortion.Paragraph);
                secondPortion.Style.Apply(firstPortion.Style);
                secondPortion.Style.FontName = FontSettings.GetAdobeFontName("Arial");

                textLayer.TextData.AddPortion(secondPortion);
                textLayer.TextData.UpdateLayerData();

                image.Save(outputFilePng, new PngOptions());
                image.Save(outputFilePsd);
            }

            using (var image = (PsdImage)Image.Load(outputFilePsd))
            {
                TextLayer textLayer = (TextLayer)image.Layers[2];

                string adobeFontName1 = FontSettings.GetAdobeFontName("Comic Sans MS");
                string adobeFontName2 = FontSettings.GetAdobeFontName("Arial");

                AssertAreEqual(adobeFontName1, textLayer.TextData.Items[0].Style.FontName);
                AssertAreEqual(adobeFontName2, textLayer.TextData.Items[1].Style.FontName);
            }

感谢你的回答,但是我的问题是,我的系统已经安装了我想要的字体,却在程序运行过程中提示“Font cache was not available for : ArialMTStd-Light
Font cache was not available for : Arial” 导致PSD上面的字体并不能正确渲染。

@Kevin_Bowen

The implementation that I have shared is actually accessing the installed fonts in your system. Can you please share your exact code along with source file and environment details along with snapshot of the issue with us.

FormatTextPortions.zip (1.4 KB)

This is a file from the example to modify the font content. My PC environment, Win10, has installed these fonts, but the program keeps failing.My Java JDK version is JDk14.

Trying to install font family Microsoft YaHei Light at C:\WINDOWS\Fonts\msyhl.ttc to private collection
Font family Microsoft YaHei Light with style Regular is not available: please, try to reinstall this font
Trying to install font family SimSun at C:\WINDOWS\Fonts\simsun.ttc to private collection
Font family SimSun with style Regular is not available: please, try to reinstall this font
Trying to install font family NSimSun at C:\WINDOWS\Fonts\simsun.ttc to private collection
Font family NSimSun with style Regular is not available: please, try to reinstall this font
Trying to install font family STXinwei at C:\WINDOWS\Fonts\STXINWEI.TTF to private collection
Font family STXinwei with style Regular is not available: please, try to reinstall this font
Trying to install font family Microsoft YaHei at C:\WINDOWS\Fonts\msyhbd.ttc to private collection
Font family Microsoft YaHei with style Bold is not available: please, try to reinstall this font
Trying to install font family Monotype Corsiva at C:\WINDOWS\Fonts\MTCORSVA.TTF to private collection
Font family Monotype Corsiva with style Regular is not available: please, try to reinstall this font
Trying to install font family STHupo at C:\WINDOWS\Fonts\STHUPO.TTF to private collection
Font family STHupo with style Regular is not available: please, try to reinstall this font
Trying to install font family STXingkai at C:\WINDOWS\Fonts\STXINGKA.TTF to private collection
Font family STXingkai with style Regular is not available: please, try to reinstall this font
Trying to install font family STKaiti at C:\WINDOWS\Fonts\STKAITI.TTF to private collection
Font family STKaiti with style Regular is not available: please, try to reinstall this font
Trying to install font family Yu Gothic UI Semibold at C:\WINDOWS\Fonts\YuGothB.ttc to private collection
Font family Yu Gothic UI Semibold with style Regular is not available: please, try to reinstall this font
Trying to install font family SimHei at C:\WINDOWS\Fonts\simhei.ttf to private collection
Font family SimHei with style Regular is not available: please, try to reinstall this font
Trying to install font family Youthness at C:\WINDOWS\Fonts\Youthness Regular Demo.ttf to private collection
Font family Youthness with style Regular is not available: please, try to reinstall this font
Trying to install font family STFangsong at C:\WINDOWS\Fonts\STFANGSO.TTF to private collection
Font family STFangsong with style Regular is not available: please, try to reinstall this font
Trying to install font family STSong at C:\WINDOWS\Fonts\STSONG.TTF to private collection
Font family STSong with style Regular is not available: please, try to reinstall this font
Trying to install font family FangSong at C:\WINDOWS\Fonts\simfang.ttf to private collection
Font family FangSong with style Regular is not available: please, try to reinstall this font
Trying to install font family FZYaoTi at C:\WINDOWS\Fonts\FZYTK.TTF to private collection
Font family FZYaoTi with style Regular is not available: please, try to reinstall this font
Trying to install font family STZhongsong at C:\WINDOWS\Fonts\STZHONGS.TTF to private collection
Font family STZhongsong with style Regular is not available: please, try to reinstall this font
Trying to install font family Microsoft JhengHei Light at C:\WINDOWS\Fonts\msjhl.ttc to private collection
Font family Microsoft JhengHei Light with style Regular is not available: please, try to reinstall this font
Trying to install font family Microsoft JhengHei at C:\WINDOWS\Fonts\msjh.ttc to private collection
Font family Microsoft JhengHei with style Regular is not available: please, try to reinstall this font
Trying to install font family FZShuTi at C:\WINDOWS\Fonts\FZSTK.TTF to private collection
Font family FZShuTi with style Regular is not available: please, try to reinstall this font
Trying to install font family DengXian at C:\WINDOWS\Fonts\Dengb.ttf to private collection
Font family DengXian with style Bold is not available: please, try to reinstall this font
Trying to install font family LiSu at C:\WINDOWS\Fonts\SIMLI.TTF to private collection
Font family LiSu with style Regular is not available: please, try to reinstall this font
Trying to install font family KaiTi at C:\WINDOWS\Fonts\simkai.ttf to private collection
Font family KaiTi with style Regular is not available: please, try to reinstall this font
Trying to install font family Microsoft JhengHei at C:\WINDOWS\Fonts\msjhbd.ttc to private collection
Font family Microsoft JhengHei with style Bold is not available: please, try to reinstall this font
Trying to install font family Palace Script MT at C:\WINDOWS\Fonts\PALSCRI.TTF to private collection
Font family Palace Script MT with style Regular is not available: please, try to reinstall this font
Trying to install font family Microsoft YaHei at C:\WINDOWS\Fonts\msyh.ttc to private collection
Font family Microsoft YaHei with style Regular is not available: please, try to reinstall this font
Trying to install font family YouYuan at C:\WINDOWS\Fonts\SIMYOU.TTF to private collection
Font family YouYuan with style Regular is not available: please, try to reinstall this font
Trying to install font family Arial MT Std at C:\WINDOWS\Fonts\Arial MT Std Light.otf to private collection
Font family Arial MT Std with style Regular is not available: please, try to reinstall this font
Trying to install font family STCaiyun at C:\WINDOWS\Fonts\STCAIYUN.TTF to private collection
Font family STCaiyun with style Regular is not available: please, try to reinstall this font
Trying to install font family STXihei at C:\WINDOWS\Fonts\STXIHEI.TTF to private collection
Font family STXihei with style Regular is not available: please, try to reinstall this font
Trying to install font family DengXian at C:\WINDOWS\Fonts\Deng.ttf to private collection
Font family DengXian with style Regular is not available: please, try to reinstall this font
Trying to install font family STLiti at C:\WINDOWS\Fonts\STLITI.TTF to private collection
Font family STLiti with style Regular is not available: please, try to reinstall this font
Trying to install font family MingLiU-ExtB at C:\WINDOWS\Fonts\mingliub.ttc to private collection
Font family MingLiU-ExtB with style Regular is not available: please, try to reinstall this font
Trying to install font family PMingLiU-ExtB at C:\WINDOWS\Fonts\mingliub.ttc to private collection
Font family PMingLiU-ExtB with style Regular is not available: please, try to reinstall this font
Trying to install font family MingLiU_HKSCS-ExtB at C:\WINDOWS\Fonts\mingliub.ttc to private collection
Font family MingLiU_HKSCS-ExtB with style Regular is not available: please, try to reinstall this font
Trying to install font family DengXian Light at C:\WINDOWS\Fonts\Dengl.ttf to private collection
Font family DengXian Light with style Regular is not available: please, try to reinstall this font
Font cache was not available for : AdobeInvisFont
Font cache was not available for : AdobeInvisFont
Font cache was not available for : MyriadPro-Regular

@Kevin_Bowen

Can you please share the source file so that I may log the issue in our issue tracking system based on that.