MantisBT - VTK
View Issue Details
0015301VTK(No Category)public2015-02-03 11:512015-04-02 08:42
Luc Habert 
David C. Lonie 
normalminorhave not tried
closedfixed 
 
 
TBD
crash
0015301: problem with vtkFreeTypeTools and Calibri
On a windows 7 system, I ran into a strange issue while trying to render the label for the y-axis of a vtkPlotPoints with Calibri, 18, bold. If the label text contains "AT", vtkFreeTypeTools::RenderCharacter will make an out of bounds acces in the image (vtkFreeTypeTools.cxx line 1477) when trying to render the T. Even stranger: displaying only T does not cause an issue.

The crashing rendering call is performed at vtkOpenGLContextDevice2D.cxx, line 834. The following code reproduces the crash:

    vtkNew<vtkTextRendererStringToImage> ren;
    vtkNew<vtkTextProperty> prop;
    prop->SetFontFile("c:\\Windows\\Fonts\\Calibri.ttf");
    prop->SetFontFamily(VTK_FONT_FILE);

    prop->SetFontSize(18);
    prop->SetBold(true);
    prop->SetOrientation(90);

    vtkNew<vtkImageData> image; // not initialized exactly as in vtkOpenGLContextDevice2D.cxx
    int textDims[2];

    ren->RenderString(prop.GetPointer(), vtkUnicodeString::from_utf8("AT"), image.GetPointer(), textDims);
No tags attached.
Issue History
2015-02-03 11:51Luc HabertNew Issue
2015-02-04 09:45Luc HabertNote Added: 0034153
2015-02-05 11:40Dave DeMarleAssigned To => David C. Lonie
2015-02-05 11:43Dave DeMarleNote Added: 0034156
2015-02-05 12:57David C. LonieNote Added: 0034175
2015-02-12 16:04David C. LonieNote Added: 0034216
2015-02-12 16:04David C. LonieStatusbacklog => active development
2015-02-12 16:04David C. LonieStatusactive development => gerrit review
2015-04-01 13:58David C. LonieNote Added: 0034334
2015-04-02 08:41David C. LonieStatusgerrit review => backlog
2015-04-02 08:42David C. LonieNote Added: 0034335
2015-04-02 08:42David C. LonieStatusbacklog => closed
2015-04-02 08:42David C. LonieResolutionopen => fixed

Notes
(0034153)
Luc Habert   
2015-02-04 09:45   
I have delved deeper with the debuger. The problem is that penX = -12 while the image's extent[0] = -11. This -12 comes from line 1469 that blindly adds the kerning returned by FT_Get_Kerning.

According to FT_Get_Kerning's documentation, this kerning is only valid for horizontal layouts, which I understand means the matrix is not taken into account. This interpretation is consistent with the result we have here: kerningDelta.x < 0 and kerningDelta.y = 0, although we have a vertical orientation.

A quick fix would be to ignore kerning in non-horizontal orientations. Perhaps applying the transform to the kerning would work fine, at least for orientation == 90, 180 or 270.
(0034156)
Dave DeMarle   
2015-02-05 11:43   
Dave L, is Luc's proposed fix:
1) as easy to apply as is sounds
-- If so can you guide Luc on how to submit a patch?
2) likely to cause issues on the dashboard?
-- If so, lets delay any merge until after the imminent 6.2 release
(0034175)
David C. Lonie   
2015-02-05 12:57   
It's close, and a good catch.

The only bit that's not quite right is the interpretation of "horizontal layout". This doesn't refer to a transform, but rather how some languages (Chinese, for example) are sometimes laid out top-to-bottom, rather than left-to-right.

Indeed, the kerning function is ignoring the rotation matrix, as suggested by this mailing list discussion:

http://lists.gnu.org/archive/html/freetype/2001-10/msg00042.html [^]

I don't believe any of the default fonts embedded in VTK actually have kerning, hence why we haven't seen this before ;-)

I'm actually working (a lot) on the text renderers at the moment -- I'll sneak a fix for this in with some other changes soon. It shouldn't cause any issues, as the dashboards should stick with the same ol' unkerned fonts.
(0034216)
David C. Lonie   
2015-02-12 16:04   
Gerrit patch: http://review.source.kitware.com/#/c/19253/ [^]
(0034334)
David C. Lonie   
2015-04-01 13:58   
Gerrit is dead, long live gitlab:

https://gitlab.kitware.com/vtk/vtk/merge_requests/80 [^]

I split this off from the larger change so that we can get it merged faster...
(0034335)
David C. Lonie   
2015-04-02 08:42   
Merged into master: https://gitlab.kitware.com/vtk/vtk/commit/2177e64e63c769a4c7d0638723f09bf40a03bbfd [^]