Supposed font issue

Greetings!

I am getting data from Tweeter. It contains any kind of symbols and texts.

DataGrid tries to render content and crashes with error:

System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary. at MS.Internal.FontCache.FontFaceLayoutInfo.IntMap.System.Collections.Generic.IDictionary.get_Item(Int32 i) at Syncfusion.UI.Xaml.Grid.Cells.GridVirtualizingCellRendererBase`2.DrawGlyphs(DrawingContext dc, Rect cellRect, Geometry clipGeometry, DataColumnBase dataColumnBase, GridCell gridCell, String cellvalue) at Syncfusion.UI.Xaml.Grid.Cells.GridVirtualizingCellRendererBase`2.OnRenderContent(DrawingContext dc, Rect cellRect, Geometry clipGeometry, DataColumnBase dataColumnBase, GridCell gridCell, Object dataContext) at Syncfusion.UI.Xaml.Grid.Cells.GridVirtualizingCellRendererBase`2.OnRenderCell(DrawingContext dc, Rect cellRect, DataColumnBase dataColumnBase, Object dataContext) at Syncfusion.UI.Xaml.Grid.Cells.GridCellRendererBase.RenderCell(DrawingContext dc, Rect cellRect, DataColumnBase dataColumnBase, Object dataContext) at Syncfusion.UI.Xaml.Grid.OrientedCellsPanel.OnRender(DrawingContext dc) at System.Windows.UIElement.Arrange(Rect finalRect) at MS.Internal.Helper.ArrangeElementWithSingleChild(UIElement element, Size arrangeSize) at System.Windows.Controls.ContentPresenter.ArrangeOverride(Size arrangeSize) at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect) at System.Windows.UIElement.Arrange(Rect finalRect) at System.Windows.Controls.Border.ArrangeOverride(Size finalSize) at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect) at System.Windows.UIElement.Arrange(Rect finalRect) at System.Windows.Controls.Grid.ArrangeOverride(Size arrangeSize) at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect) at System.Windows.UIElement.Arrange(Rect finalRect) at System.Windows.Controls.Control.ArrangeOverride(Size arrangeBounds) at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect) at System.Windows.UIElement.Arrange(Rect finalRect) at Syncfusion.UI.Xaml.Grid.DataRowBase.ArrangeElement(Rect rect) at Syncfusion.UI.Xaml.Grid.VisualContainer.ArrangeRow() at Syncfusion.UI.Xaml.Grid.VisualContainer.ArrangeOverride(Size finalSize) at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect) at System.Windows.UIElement.Arrange(Rect finalRect) at System.Windows.Controls.ScrollContentPresenter.ArrangeOverride(Size arrangeSize) at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect) at System.Windows.UIElement.Arrange(Rect finalRect) at System.Windows.Controls.Grid.ArrangeOverride(Size arrangeSize) at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect) at System.Windows.UIElement.Arrange(Rect finalRect) at System.Windows.Controls.Control.ArrangeOverride(Size arrangeBounds) at System.Windows.Controls.ScrollViewer.ArrangeOverride(Size arrangeSize) at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect) at System.Windows.UIElement.Arrange(Rect finalRect) at System.Windows.Controls.Border.ArrangeOverride(Size finalSize) at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect) at System.Windows.UIElement.Arrange(Rect finalRect) at System.Windows.Controls.Grid.ArrangeOverride(Size arrangeSize) at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect) at System.Windows.UIElement.Arrange(Rect finalRect) at System.Windows.Controls.Control.ArrangeOverride(Size arrangeBounds) at Syncfusion.UI.Xaml.Grid.SfDataGrid.ArrangeOverride(Size finalSize) at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect) at System.Windows.UIElement.Arrange(Rect finalRect) at System.Windows.Controls.Grid.ArrangeOverride(Size arrangeSize) at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect) at System.Windows.UIElement.Arrange(Rect finalRect) at MS.Internal.Helper.ArrangeElementWithSingleChild(UIElement element, Size arrangeSize) at System.Windows.Controls.ContentPresenter.ArrangeOverride(Size arrangeSize) at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect) at System.Windows.UIElement.Arrange(Rect finalRect) at System.Windows.Controls.Border.ArrangeOverride(Size finalSize) at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect) at System.Windows.UIElement.Arrange(Rect finalRect) at System.Windows.Controls.Control.ArrangeOverride(Size arrangeBounds) at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect) at System.Windows.UIElement.Arrange(Rect finalRect) at System.Windows.Controls.Grid.ArrangeOverride(Size arrangeSize) at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect) at System.Windows.UIElement.Arrange(Rect finalRect) at MS.Internal.Helper.ArrangeElementWithSingleChild(UIElement element, Size arrangeSize) at System.Windows.Controls.ContentPresenter.ArrangeOverride(Size arrangeSize) at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect) at System.Windows.UIElement.Arrange(Rect finalRect) at System.Windows.Controls.Decorator.ArrangeOverride(Size arrangeSize) at System.Windows.Documents.AdornerDecorator.ArrangeOverride(Size finalSize) at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect) at System.Windows.UIElement.Arrange(Rect finalRect) at System.Windows.Controls.Border.ArrangeOverride(Size finalSize) at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect) at System.Windows.UIElement.Arrange(Rect finalRect) at System.Windows.Window.ArrangeOverride(Size arrangeBounds) at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect) at System.Windows.UIElement.Arrange(Rect finalRect) at System.Windows.ContextLayoutManager.UpdateLayout() at System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg) at System.Windows.Media.MediaContext.InvokeOnRenderCallback.DoWork() at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks() at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget) at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget) at System.Windows.Media.MediaContext.Resize(ICompositionTarget resizedCompositionTarget) at System.Windows.Interop.HwndTarget.OnResize() at System.Windows.Interop.HwndTarget.HandleMessage(WindowMessage msg, IntPtr wparam, IntPtr lparam) at System.Windows.Interop.HwndSource.HwndTargetFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler) 


I assume it is some font rendering issue.

How can I fix it?


Thank you in advance.


5 Replies

MA Mohanram Anbukkarasu Syncfusion Team October 22, 2020 12:25 PM UTC

Hi Thilo Brosinsky, 

Thanks for contacting Syncfusion support.  

We are little unclear with reported scenario. The provided details are not sufficient to reproduce the reported issue in our end. You have mentioned that the data contains any kind of symbols and texts, which may be the cause for the reported issue. Kindly share more details about the data you are using in your end. If possible kindly share some sample data with the kind of symbols and texts you have used. It will be more helpful for us to reproduce the same scenario in our end and to provide a prompt solution at earlier.  

Regards, 
Mohanram A. 



CA Christian Andritzky September 15, 2022 05:58 PM UTC

Hi Mohanram,

we ran into exactly the same issue today using Syncfusion NuGet version 20.2.0.48.

There is a bug in the GridVirtualizingCellRendererBase.DrawGlyphs implementation. It throws when the cellvalue text to be rendered contains characters that don't have glyphs in the current font (GlyphTypeface). This leads to a KeyNotFoundException when accessing GlyphTypeface.CharacterToGlyphMap with an unsupported character code.

It can be reproduced (at least on Windows 10) using the "Segoe UI" font and the following text character: "" (code 20132).

It can also be reproduced with the following standalone (WPF) program snippet that is equivalent to the broken part of your DrawGlyphs implementation:

const string cellvalue = "交";
var glyphTypeface = new GlyphTypeface(new Uri(@"C:\Windows\Fonts\segoeui.ttf"));
for (int index = 0; index < cellvalue.Length; ++index)
{
    ushort characterToGlyph = glyphTypeface.CharacterToGlyphMap[cellvalue[index]];
}

Is there a hotfix available?

Thanks and best regards,
Christian Andritzky



VS Vijayarasan Sivanandham Syncfusion Team September 16, 2022 05:35 PM UTC

Hi Christian Andritzky,


The reported issue occurs because the mentioned cell value (ex: ) is not in the specified FontFamily. This is a general query, and it is not related to Syncfusion controls. So, we request that you post the query in the MSDN forum. Once this issue is fixed, it will automatically resolve the GridVirtualizingCellRendererBase.DrawGlyphs method also.

Please get back to us with details if you require any assistance with the Syncfusion controls. We will be happy to assist you.

Regards,

Vijayarasan S



CA Christian Andritzky September 17, 2022 05:06 PM UTC

Hi Vijayarasan,

thanks for the quick reply, but interestingly the same string can be displayed in a SfDataGrid (same version, same font) in a different application. Maybe it does something different so that it uses DrawFormattedText instead of the Syncfusion-crafted DrawGlyphs code path.

So it's definitely a problem on Syncfusion side.

It might be related to the SfDataGrid.UseDrawing property which we set to Default to optimize performance.

Please provide a fix.

Thanks,
Chris A.



VS Vijayarasan Sivanandham Syncfusion Team September 19, 2022 05:04 PM UTC

Hi Christian Andritzky,

By default, GridVirtualizingCellRendererBase.DrawFormattedText method draws the text using System.Windows.Media.FormattedText in our SfDataGrid. We have provided lightweight templates with optimized rendering mode which drastically improves scrolling, loading performance, and also memory foot print by using the System.Windows.Media.GlyphRun that is implemented in DrawGlyphs method of GridVirtualizingCellRendererBase.


So, when you are enabling SfDataGrid.UseDrawing property the DrawGlyphs method draws the text in SDataGrid. As previously stated, the reported issue occurs because the cell value (ex:) is not in the specified FontFamily. The exception occurs from the framework method (GlyphTypeface.CharacterToGlyphMap) itself. So, the reported issue is not related to Syncfusion SfDataGrid.

Regards,
Vijayarasan S


Loader.
Up arrow icon