Using the subset embedded font feature causes rendering bugs

Hi,


I was using the new subset font feature introduced in 17.5 and noticed that there are 3 separate bugs. I’m currently trying to use google’s noto sans cjk font family available here:
https://www.google.com/get/noto/#sans-jpan

1) Even though the google noto fonts are otf, calling FontRepository.OpenFont(otfStream, FontTypes.OTF) throws an exception. Using FontTypes.TTF seems to be a workaround.
2) There are rendering issues with the light font that are similar to an earlier post I’ve made here. There are characters that overlap on top of each other in the second line of text. Also, the embedded subset font causes an error to be generated: "When opening up the pdf, the font ‘RWKTIP+NotoSansCJKJPLight’ contains bad /Widths."
3) I’ve created a line object that disappears when doc.FontUtilities.SubsetFonts(Document.FontSubsetStrategy.SubsetEmbeddedFontsOnly); is called. If I comment out the SubsetFonts call, the line object correctly renders.

Here’s the attached sample code that can reproduce the issue:

using (var otfStream = new FileStream(@“NotoSansCJKjp-Light.otf”, FileMode.Open))
using (var otfStream2 = new FileStream(@“NotoSansCJKjp-Bold.otf”, FileMode.Open))
using (var imageStream = new FileStream(@“logo.jpg”, FileMode.Open))
using (var outputStream = new FileStream(@“streamsubsetfont.pdf”, FileMode.Create, FileAccess.ReadWrite))
{
FontRepository.OpenFont(otfStream, FontTypes.TTF);
FontRepository.OpenFont(otfStream2, FontTypes.TTF);

Document doc = new Document();
doc.IsLinearized = true;
Page page = doc.Pages.Add();
page.PageInfo.Width = Aspose.Pdf.PageSize.PageLetter.Width;
page.PageInfo.Height = Aspose.Pdf.PageSize.PageLetter.Height;
page.PageInfo.Margin = new Aspose.Pdf.MarginInfo(27, 27, 27, 27);

TextFragment newText1 = new TextFragment(“っぬむ知個ねへ人人生而自由,在尊严和权利上一律平等。他们赋 有理性和良心, 并应以兄弟关系的精神互相对待。”);
newText1.TextState.Font = FontRepository.FindFont(@“Noto Sans CJK JP Bold”);
newText1.TextState.FontSize = 10;
newText1.TextState.LineSpacing = 5;

TextFragment newText2 = new TextFragment(“っぬむ知個ねへ人人生而自由,在尊严和权利上一律平等。他们赋 有理性和良心, 并应以兄弟关系的精神互相对待。”);
newText2.TextState.Font = FontRepository.FindFont(@“Noto Sans CJK JP Light”);
newText2.TextState.FontSize = 10;
newText2.TextState.LineSpacing = 5;

page.Paragraphs.Add(newText1);
page.Paragraphs.Add(newText2);

doc.ProcessParagraphs();

var imageStamp = new ImageStamp(imageStream)
{
BottomMargin = 27,
LeftMargin = 27,
Height = 7.5,
Width = 37.5,
HorizontalAlignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Bottom
};

var textStamp = new TextStamp(“Test”);
textStamp.TextState.FontSize = 6;
textStamp.TextState.LineSpacing = 3;
textStamp.TextState.Font = FontRepository.FindFont(@“Noto Sans CJK JP Light”);
textStamp.BottomMargin = 27;
textStamp.HorizontalAlignment = HorizontalAlignment.Center;
textStamp.VerticalAlignment = VerticalAlignment.Bottom;

var pageNumberStamp = new PageNumberStamp { Background = false };
pageNumberStamp.TextState.FontSize = 6;
pageNumberStamp.TextState.Font = FontRepository.FindFont(@“Noto Sans CJK JP Light”);
pageNumberStamp.TextState.LineSpacing = 3;
pageNumberStamp.Format = $“© Test | # of {doc.Pages.Count}”;
pageNumberStamp.BottomMargin = 27;
pageNumberStamp.RightMargin = 27;
pageNumberStamp.HorizontalAlignment = HorizontalAlignment.Right;
pageNumberStamp.VerticalAlignment = VerticalAlignment.Bottom;
pageNumberStamp.StartingNumber = 1;

page.AddStamp(imageStamp);
page.AddStamp(textStamp);
page.AddStamp(pageNumberStamp);

page.Header = new HeaderFooter { Margin = new MarginInfo(0, 0, 0, 0) };
var footerLineGraph = new Aspose.Pdf.Drawing.Graph((float)page.MediaBox.Width, (float)page.MediaBox.Height);
var footerLineLength = (float)(page.PageInfo.Width - 2 * page.PageInfo.Margin.Left);
var posArray = new[] { 27, 42, 27 + footerLineLength, 42 };
var footerLine = new Aspose.Pdf.Drawing.Line(posArray)
{
GraphInfo = { LineWidth = 0.75f }
};
footerLineGraph.Shapes.Add(footerLine);
page.Header.Paragraphs.Add(footerLineGraph);

doc.FontUtilities.SubsetFonts(Document.FontSubsetStrategy.SubsetEmbeddedFontsOnly);
doc.Save(outputStream);
}


Hi Daniel,

Thank you for contacting support.
dfactset:
1) Even though the google noto fonts are otf, calling FontRepository.OpenFont(otfStream, FontTypes.OTF) throws an exception. Using FontTypes.TTF seems to be a workaround.
We have logged this feature request under the ticket ID PDFNET-42862 in our issue tracking system. We have linked your post to this ticket and will keep you informed regarding any available updates.

In reference to the other two issues, we are unable to generate output PDF in our environment because the FindFont method shows an error "Font Noto Sans CJK JP Bold was not found". Please recheck and confirm us about the font names which you are using in the code.

That is the correct font name. If you look at the font returned by the OpenFont functions you can see that they are correct. It looks like on my machine those calls were working because I installed those two fonts with windows, so that can be the workaround to get it reproducing. Shouldn’t it be possible to call FontRepository.OpenFont and then call FontRepository.FindFont to open up the same font again later? Is there some other way to open up the font without having to register it with windows and call OpenFont each time?

Hi Daniel,


Thank you for the inquiry. If you require to use the custom fonts from other than system default font path, then you need to add that folder path into font repository as following.

[.NET, C#]
<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”>String fontFolderPath = “C:\temp\”;<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”>
FolderFontSource fs = <span class=“kwrd” style=“color: rgb(0, 0, 255); font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre;”>new<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”> FolderFontSource(fontFolderPath);<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”>
FontRepository.Sources.Add(fs);<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”>
FontRepository.FindFont(@“Noto Sans CJK JP Bold”);
<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”>
dfactset:
2) There are rendering issues with the light font that are similar to an earlier post I’ve made here. There are characters that overlap on top of each other in the second line of text. Also, the embedded subset font causes an error to be generated: "When opening up the pdf, the font ‘RWKTIP+NotoSansCJKJPLight’ contains bad /Widths."
We managed to replicate the error on opening up the output PDF. It has been logged under the ticket ID PDFNET-42874 in our bug tracking system. We will keep you informed regarding any available updates. We have attached the output PDF to this reply and please highlight the issue of overlapping characters with the help of a snapshot.
dfactset:
3) I’ve created a line object that disappears when doc.FontUtilities.SubsetFonts(Document.FontSubsetStrategy.SubsetEmbeddedFontsOnly); is called. If I comment out the SubsetFonts call, the line object correctly renders.
We are investigating your third scenario and will share our findings with you soon.

@dfactset,

We are sorry for the delay. We managed to replicate the problem of disappeared horizontal line in the footer. It has been logged under the ticket ID PDFNET-43111 in our bug tracking system. We have linked your post to this ticket and will keep you informed regarding any available updates.

Best Regards,
Imran Rafique

The issues you have found earlier (filed as PDFNET-42862) have been fixed in this update. This message was posted using BugNotificationTool from Downloads module by asad.ali

Hi,

We were wondering are there any updates on PDFNET-42874 and PDFNET-43111?

Thanks

@dfactset

Thanks for your inquiry.

We regret to share that these issues are not yet resolved due to high number of pending issues in the queue. However, we have recorded your concerns and escalated the issues to next level of priority. As soon as some definite update are available, we will surely inform you. Please spare us little time.

We are sorry for the inconvenience.

Any updates?

@dfactset

Regretfully, the tickets could not get resolved yet. Your concerns have already been recorded and we will surely notify you once we make some progress towards tickets resolution. Your patience is highly appreciated in this regard.

We apologize for the inconvenience and the delay.