private void ReleaseIfNotNull(TextLayoutResult textLayoutResult) { if (textLayoutResult.pDWriteTextLayout != IntPtr.Zero) { try { UnsafeNativeMethods.ReleaseTextLayout(ref textLayoutResult); textLayoutResult.pDWriteTextLayout = IntPtr.Zero; } catch (Exception e) when(e is COMException || e is AccessViolationException) { Trace.WriteLine($"Error releasing {nameof(textLayoutResult)} - {e.Message}"); textLayoutResult.pDWriteTextLayout = IntPtr.Zero; } } }
public virtual void OverflowWrapBreakWordProperty() { PdfDocument pdfDoc = new PdfDocument(new PdfWriter(new MemoryStream())); pdfDoc.AddNewPage(); Document doc = new Document(pdfDoc); RootRenderer documentRenderer = doc.GetRenderer(); Text text = new Text("wooow"); TextRenderer textRenderer = (TextRenderer)text.GetRenderer(); textRenderer.SetParent(documentRenderer); // overflow is set here to mock LineRenderer#layout behavior documentRenderer.SetProperty(Property.OVERFLOW_X, OverflowPropertyValue.VISIBLE); float fullWordWidth = textRenderer.GetMinMaxWidth().GetMaxWidth(); LayoutArea layoutArea = new LayoutArea(1, new Rectangle(fullWordWidth / 2, AbstractRenderer.INF)); TextLayoutResult result = (TextLayoutResult)textRenderer.Layout(new LayoutContext(layoutArea)); NUnit.Framework.Assert.IsFalse(result.IsWordHasBeenSplit()); textRenderer.SetProperty(Property.OVERFLOW_WRAP, OverflowWrapPropertyValue.BREAK_WORD); result = (TextLayoutResult)textRenderer.Layout(new LayoutContext(layoutArea)); NUnit.Framework.Assert.IsTrue(result.IsWordHasBeenSplit()); }