For some unknown reason, text layer loses its boldness when editing it (please see attached input/output files)… even removing all the code, just doing UpdateLayerData is enough for the format to be changed.
Please advise:
var loadOptions = new PsdLoadOptions();
loadOptions.LoadEffectsResource = true;
using (PsdImage image = (PsdImage)Image.Load(@opt.Input, loadOptions))
{
foreach (var layerItem in image.Layers.OfType<TextLayer>())
{
// ### omitted code ### //
layerItem.TextData.UpdateLayerData();
}
image.Save(@opt.Output);
}
sample.zip (63.6 KB)
@gonzalo.gatti.ethofy
It seems that you are experiencing an issue where the bold formatting of text layers is lost when calling the UpdateLayerData
method in Aspose.PSD. This is a known issue that has been reported, where the bold formatting can shift from one portion of text to another after processing the file.
To address this, you might want to ensure that you are using the latest version of Aspose.PSD, as updates often include bug fixes and improvements. If you are already on the latest version and the issue persists, it may be beneficial to report this behavior to Aspose support, as they can provide more specific guidance or updates regarding the issue.
In the meantime, you can try the following workaround:
- Before calling
UpdateLayerData
, check the properties of the text layer to ensure that the formatting is as expected.
- After calling
UpdateLayerData
, reapply the bold formatting if it has changed.
Here’s a sample code snippet that demonstrates how you might reapply the formatting:
var loadOptions = new PsdLoadOptions();
loadOptions.LoadEffectsResource = true;
using (PsdImage image = (PsdImage)Image.Load(@opt.Input, loadOptions))
{
foreach (var layerItem in image.Layers.OfType<TextLayer>())
{
// Store the current formatting
var currentFontStyle = layerItem.TextData.FontStyle;
// Update the layer data
layerItem.TextData.UpdateLayerData();
// Reapply the bold formatting if necessary
if (!currentFontStyle.HasFlag(FontStyle.Bold))
{
layerItem.TextData.FontStyle |= FontStyle.Bold;
}
}
image.Save(@opt.Output);
}
This code checks the current font style before updating the layer data and reapplies the bold formatting if it was lost.
If the problem continues, please consider sharing your findings with Aspose support for further assistance.
Sources:
[1]: Bold formatting moved from one text portion to another