@@ -563,8 +563,8 @@ class TextAnalysis
563563 // (weak references are fine here, since this class is a transient
564564 // stack-based helper that doesn't need to copy data)
565565 UINT32 mTextLength ;
566- const wchar_t * mText ;
567- const wchar_t * mLocaleName ;
566+ const WCHAR * mText ;
567+ const WCHAR * mLocaleName ;
568568 DWRITE_READING_DIRECTION mReadingDirection ;
569569
570570 // Current processing state.
@@ -674,14 +674,15 @@ _hb_directwrite_shape(hb_shape_plan_t *shape_plan,
674674 return false ;
675675 }
676676
677- uint32_t appUnitsPerDevPixel = 72 ;
678-
679677 UINT32 maxGlyphs = 3 * length / 2 + 16 ;
680678
681- UINT16 clusters[400 ];
682- UINT16 glyphs[400 ];
683- DWRITE_SHAPING_TEXT_PROPERTIES textProperties[400 ];
684- DWRITE_SHAPING_GLYPH_PROPERTIES glyphProperties[400 ];
679+ #define INITIAL_GLYPH_SIZE 400
680+ UINT16* clusters = (UINT16*)malloc (INITIAL_GLYPH_SIZE * sizeof (UINT16));
681+ UINT16* glyphs = (UINT16*)malloc (INITIAL_GLYPH_SIZE * sizeof (UINT16));
682+ DWRITE_SHAPING_TEXT_PROPERTIES* textProperties = (DWRITE_SHAPING_TEXT_PROPERTIES*)
683+ malloc (INITIAL_GLYPH_SIZE * sizeof (DWRITE_SHAPING_TEXT_PROPERTIES));
684+ DWRITE_SHAPING_GLYPH_PROPERTIES* glyphProperties = (DWRITE_SHAPING_GLYPH_PROPERTIES*)
685+ malloc (INITIAL_GLYPH_SIZE * sizeof (DWRITE_SHAPING_GLYPH_PROPERTIES));
685686
686687 UINT32 actualGlyphs;
687688
@@ -694,8 +695,25 @@ _hb_directwrite_shape(hb_shape_plan_t *shape_plan,
694695 maxGlyphs, clusters, textProperties,
695696 glyphs, glyphProperties, &actualGlyphs);
696697
697- if (hr == HRESULT_FROM_WIN32 (ERROR_INSUFFICIENT_BUFFER)) {
698- return false ;
698+ if (hr != HRESULT_FROM_WIN32 (ERROR_INSUFFICIENT_BUFFER)) {
699+ free (clusters);
700+ free (glyphs);
701+ free (textProperties);
702+ free (glyphProperties);
703+
704+ clusters = (UINT16*)malloc (INITIAL_GLYPH_SIZE * sizeof (UINT16));
705+ glyphs = (UINT16*)malloc (INITIAL_GLYPH_SIZE * sizeof (UINT16));
706+ textProperties = (DWRITE_SHAPING_TEXT_PROPERTIES*)
707+ malloc (INITIAL_GLYPH_SIZE * sizeof (DWRITE_SHAPING_TEXT_PROPERTIES));
708+ glyphProperties = (DWRITE_SHAPING_GLYPH_PROPERTIES*)
709+ malloc (INITIAL_GLYPH_SIZE * sizeof (DWRITE_SHAPING_GLYPH_PROPERTIES));
710+
711+ hr = analyzer->GetGlyphs (pchars, length,
712+ fontFace, FALSE ,
713+ buffer->props .direction ,
714+ &runHead->mScript , NULL , NULL , NULL , NULL , 0 ,
715+ maxGlyphs, clusters, textProperties,
716+ glyphs, glyphProperties, &actualGlyphs);
699717 }
700718 if (FAILED (hr)) {
701719 // NS_WARNING("Analyzer failed to get glyphs.");
@@ -780,6 +798,11 @@ _hb_directwrite_shape(hb_shape_plan_t *shape_plan,
780798 info->var2 .u32 = -offsets[i].advanceOffset ;
781799 }
782800
801+ free (clusters);
802+ free (glyphs);
803+ free (textProperties);
804+ free (glyphProperties);
805+
783806 /* Set glyph positions */
784807 buffer->clear_positions ();
785808 for (unsigned int i = 0 ; i < glyphs_len; i++)
0 commit comments