cart: empty [ Login ]

DengXian font problem with generated PDF

1 
provegard
9/26/2022 2:14 PM

Hi! I have encountered a problem where text that uses the DengXian font shows up as squares in a generated PDF. I have downloaded the DengXian font from the link in this forum post, and extracted three font files in my test directory: DENG.ttf, DENGB.ttf and DENGL.ttf. This is the code that I use:

C# Code:
const string dirPath = "c:\\temp\\rtd-cadlib-font"; DxfModel.AddTrueTypeFontLookupDirectories(dirPath); var infoDrawingModel = DxfReader.Read(Path.Combine(dirPath, "S1012044.dxf")); using var model = new DxfModel(); var infoDrawingBlock = new DxfBlock("InfoBlock"); model.Blocks.Add(infoDrawingBlock); var cloneContext = new CloneContext(infoDrawingModel, model, ReferenceResolutionType.CloneMissing); infoDrawingBlock.Entities.AddRange(infoDrawingModel.Entities.Select(e => (DxfEntity) cloneContext.Clone(e))); cloneContext.ResolveReferences(); var insert = new DxfInsert(infoDrawingBlock); model.Entities.Add(insert); var outPath = Path.Combine(dirPath, "out.pdf"); File.Delete(outPath); using var fs = File.OpenWrite(outPath); var pdfGraphics = new PdfExporter(fs) { EmbedFonts = true, AutoCloseStream = false }; var graphicsConfig = (GraphicsConfig) GraphicsConfig.WhiteBackground.Clone(); var boundsCalc = new BoundsCalculator(graphicsConfig); boundsCalc.GetBounds(model); var bounds = boundsCalc.Bounds; var paperSize = PaperSizes.GetPaperSize(PaperKind.A4Rotated); // Lengths in inches. var pageWidth = paperSize.Width / 100f; var pageHeight = paperSize.Height / 100f; const float margin = 0; var to2DTransform = DxfUtil.GetScaleTransform( bounds.Corner1, bounds.Corner2, new Point3D(bounds.Center.X, bounds.Corner2.Y, 0d), new Point3D(new Vector3D(margin, margin, 0d) * PdfExporter.InchToPixel), new Point3D(new Vector3D(pageWidth - margin, pageHeight - margin, 0d) * PdfExporter.InchToPixel), new Point3D(new Vector3D(pageWidth / 2d, pageHeight - margin, 0d) * PdfExporter.InchToPixel) ); pdfGraphics.DrawPage(model, graphicsConfig, to2DTransform, paperSize); pdfGraphics.EndDocument();
Note that I add the test directory as a TrueType font path using
Code:
AddTrueTypeFontLookupDirectories
. I have attached the mentioned DXF file (
Code:
S1012044.dxf
) as well as the generated PDF file to this post. For reference, text that uses the SimSun font works just as expected. It's only the DengXian font that appears to be a problem. Can you spot any problem with the DXF file, or do you have any other suggestion as to what I might try next? Best regards, Per Rovegård

Wout
9/28/2022 3:50 PM

Hi, Problem should be fixed now in CadLib 4.0, there was a property not copied in the Clone. I haven't updated the other versions yet. Also add this line if you want to really embed the fonts and use PDF text:

C# Code:
graphicsConfig.TryDrawingTextAsText = true;
Thank you for the report! - Wout

provegard
9/29/2022 12:04 PM

Hi, Thank you! We're on CadLib 6 - when do you think you will have an update available for that version? Regarding TryDrawingTextAsText, we have the following comment in the code:

Code:
// Note: Do not set TryDrawingTextAsText to true, since it causes problems with some Unicode characters // (e.g., Korean or Chinese) - the resulting PDF may contain rectangles instead of the actual font glyphs.
Per

Wout
9/29/2022 1:37 PM

Hi Per, I've just recompiled and released the 6.0 versions as well. - Wout

provegard
10/3/2022 5:41 PM

Hi Wout, I have tested rc24 and it works perfectly. Thank you! // Per

1