Refactor and remove dupe getglyphs call
This commit is contained in:
parent
5f1a896100
commit
d129897120
|
@ -677,14 +677,6 @@ _hb_directwrite_shape(hb_shape_plan_t *shape_plan,
|
||||||
|
|
||||||
UINT32 maxGlyphs = 3 * length / 2 + 16;
|
UINT32 maxGlyphs = 3 * length / 2 + 16;
|
||||||
|
|
||||||
#define INITIAL_GLYPH_SIZE 400
|
|
||||||
UINT16* clusters = (UINT16*)malloc(INITIAL_GLYPH_SIZE * sizeof(UINT16));
|
|
||||||
UINT16* glyphs = (UINT16*)malloc(INITIAL_GLYPH_SIZE * sizeof(UINT16));
|
|
||||||
DWRITE_SHAPING_TEXT_PROPERTIES* textProperties = (DWRITE_SHAPING_TEXT_PROPERTIES*)
|
|
||||||
malloc(INITIAL_GLYPH_SIZE * sizeof(DWRITE_SHAPING_TEXT_PROPERTIES));
|
|
||||||
DWRITE_SHAPING_GLYPH_PROPERTIES* glyphProperties = (DWRITE_SHAPING_GLYPH_PROPERTIES*)
|
|
||||||
malloc(INITIAL_GLYPH_SIZE * sizeof(DWRITE_SHAPING_GLYPH_PROPERTIES));
|
|
||||||
|
|
||||||
UINT32 actualGlyphs;
|
UINT32 actualGlyphs;
|
||||||
|
|
||||||
bool backward = HB_DIRECTION_IS_BACKWARD(buffer->props.direction);
|
bool backward = HB_DIRECTION_IS_BACKWARD(buffer->props.direction);
|
||||||
|
@ -694,6 +686,20 @@ _hb_directwrite_shape(hb_shape_plan_t *shape_plan,
|
||||||
mbstowcs((wchar_t*) lang, hb_language_to_string (buffer->props.language), 4);
|
mbstowcs((wchar_t*) lang, hb_language_to_string (buffer->props.language), 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define FAIL(...) \
|
||||||
|
HB_STMT_START { \
|
||||||
|
DEBUG_MSG (DIRECTWRITE, NULL, __VA_ARGS__); \
|
||||||
|
return false; \
|
||||||
|
} HB_STMT_END;
|
||||||
|
|
||||||
|
retry_getglyphs:
|
||||||
|
UINT16* clusters = (UINT16*) malloc (maxGlyphs * sizeof (UINT16));
|
||||||
|
UINT16* glyphs = (UINT16*) malloc (maxGlyphs * sizeof (UINT16));
|
||||||
|
DWRITE_SHAPING_TEXT_PROPERTIES* textProperties = (DWRITE_SHAPING_TEXT_PROPERTIES*)
|
||||||
|
malloc (maxGlyphs * sizeof (DWRITE_SHAPING_TEXT_PROPERTIES));
|
||||||
|
DWRITE_SHAPING_GLYPH_PROPERTIES* glyphProperties = (DWRITE_SHAPING_GLYPH_PROPERTIES*)
|
||||||
|
malloc (maxGlyphs * sizeof (DWRITE_SHAPING_GLYPH_PROPERTIES));
|
||||||
|
|
||||||
hr = analyzer->GetGlyphs(pchars, length,
|
hr = analyzer->GetGlyphs(pchars, length,
|
||||||
fontFace, FALSE,
|
fontFace, FALSE,
|
||||||
backward,
|
backward,
|
||||||
|
@ -701,34 +707,24 @@ _hb_directwrite_shape(hb_shape_plan_t *shape_plan,
|
||||||
maxGlyphs, clusters, textProperties,
|
maxGlyphs, clusters, textProperties,
|
||||||
glyphs, glyphProperties, &actualGlyphs);
|
glyphs, glyphProperties, &actualGlyphs);
|
||||||
|
|
||||||
if (hr == HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER)) {
|
if (unlikely (hr == HRESULT_FROM_WIN32 (ERROR_INSUFFICIENT_BUFFER))) {
|
||||||
free (clusters);
|
free (clusters);
|
||||||
free (glyphs);
|
free (glyphs);
|
||||||
free (textProperties);
|
free (textProperties);
|
||||||
free (glyphProperties);
|
free (glyphProperties);
|
||||||
|
|
||||||
clusters = (UINT16*)malloc(INITIAL_GLYPH_SIZE * sizeof(UINT16));
|
maxGlyphs *= 2;
|
||||||
glyphs = (UINT16*)malloc(INITIAL_GLYPH_SIZE * sizeof(UINT16));
|
|
||||||
textProperties = (DWRITE_SHAPING_TEXT_PROPERTIES*)
|
|
||||||
malloc(INITIAL_GLYPH_SIZE * sizeof(DWRITE_SHAPING_TEXT_PROPERTIES));
|
|
||||||
glyphProperties = (DWRITE_SHAPING_GLYPH_PROPERTIES*)
|
|
||||||
malloc(INITIAL_GLYPH_SIZE * sizeof(DWRITE_SHAPING_GLYPH_PROPERTIES));
|
|
||||||
|
|
||||||
hr = analyzer->GetGlyphs(pchars, length,
|
goto retry_getglyphs;
|
||||||
fontFace, FALSE,
|
|
||||||
backward,
|
|
||||||
&runHead->mScript, lang, NULL, NULL, NULL, 0,
|
|
||||||
maxGlyphs, clusters, textProperties,
|
|
||||||
glyphs, glyphProperties, &actualGlyphs);
|
|
||||||
}
|
}
|
||||||
if (FAILED (hr)) {
|
if (FAILED (hr)) {
|
||||||
//NS_WARNING("Analyzer failed to get glyphs.");
|
FAIL ("Analyzer failed to get glyphs.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
FLOAT advances[400];
|
FLOAT* advances = (FLOAT*) malloc (actualGlyphs * sizeof (FLOAT));
|
||||||
DWRITE_GLYPH_OFFSET offsets[400];
|
DWRITE_GLYPH_OFFSET* offsets = (DWRITE_GLYPH_OFFSET*)
|
||||||
|
malloc(actualGlyphs * sizeof (DWRITE_GLYPH_OFFSET));
|
||||||
|
|
||||||
/* The -2 in the following is to compensate for possible
|
/* The -2 in the following is to compensate for possible
|
||||||
* alignment needed after the WORD array. sizeof(WORD) == 2. */
|
* alignment needed after the WORD array. sizeof(WORD) == 2. */
|
||||||
|
@ -742,14 +738,14 @@ _hb_directwrite_shape(hb_shape_plan_t *shape_plan,
|
||||||
|
|
||||||
#undef ALLOCATE_ARRAY
|
#undef ALLOCATE_ARRAY
|
||||||
|
|
||||||
int font_size = font->face->get_upem();
|
int fontSize = font->face->get_upem();
|
||||||
if (font_size < 0)
|
if (fontSize < 0)
|
||||||
font_size = -font_size;
|
fontSize = -fontSize;
|
||||||
|
|
||||||
if (font_size < 0)
|
if (fontSize < 0)
|
||||||
font_size = -font_size;
|
fontSize = -fontSize;
|
||||||
double x_mult = (double) font->x_scale / font_size;
|
double x_mult = (double) font->x_scale / fontSize;
|
||||||
double y_mult = (double) font->y_scale / font_size;
|
double y_mult = (double) font->y_scale / fontSize;
|
||||||
|
|
||||||
hr = analyzer->GetGlyphPlacements (pchars,
|
hr = analyzer->GetGlyphPlacements (pchars,
|
||||||
clusters,
|
clusters,
|
||||||
|
@ -759,7 +755,7 @@ _hb_directwrite_shape(hb_shape_plan_t *shape_plan,
|
||||||
glyphProperties,
|
glyphProperties,
|
||||||
actualGlyphs,
|
actualGlyphs,
|
||||||
fontFace,
|
fontFace,
|
||||||
font_size,
|
fontSize,
|
||||||
FALSE,
|
FALSE,
|
||||||
backward,
|
backward,
|
||||||
&runHead->mScript,
|
&runHead->mScript,
|
||||||
|
@ -771,36 +767,34 @@ _hb_directwrite_shape(hb_shape_plan_t *shape_plan,
|
||||||
offsets);
|
offsets);
|
||||||
|
|
||||||
if (FAILED (hr)) {
|
if (FAILED (hr)) {
|
||||||
//NS_WARNING("Analyzer failed to get glyph placements.");
|
FAIL ("Analyzer failed to get glyph placements.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int glyphs_len = actualGlyphs;
|
|
||||||
|
|
||||||
/* Ok, we've got everything we need, now compose output buffer,
|
/* Ok, we've got everything we need, now compose output buffer,
|
||||||
* very, *very*, carefully! */
|
* very, *very*, carefully! */
|
||||||
|
|
||||||
/* Calculate visual-clusters. That's what we ship. */
|
/* Calculate visual-clusters. That's what we ship. */
|
||||||
for (unsigned int i = 0; i < glyphs_len; i++)
|
for (unsigned int i = 0; i < actualGlyphs; i++)
|
||||||
vis_clusters[i] = -1;
|
vis_clusters[i] = -1;
|
||||||
for (unsigned int i = 0; i < buffer->len; i++) {
|
for (unsigned int i = 0; i < buffer->len; i++) {
|
||||||
uint32_t *p = &vis_clusters[log_clusters[buffer->info[i].utf16_index()]];
|
uint32_t *p = &vis_clusters[log_clusters[buffer->info[i].utf16_index()]];
|
||||||
//*p = MIN (*p, buffer->info[i].cluster);
|
//*p = MIN (*p, buffer->info[i].cluster);
|
||||||
}
|
}
|
||||||
for (unsigned int i = 1; i < glyphs_len; i++)
|
for (unsigned int i = 1; i < actualGlyphs; i++)
|
||||||
if (vis_clusters[i] == -1)
|
if (vis_clusters[i] == -1)
|
||||||
vis_clusters[i] = vis_clusters[i - 1];
|
vis_clusters[i] = vis_clusters[i - 1];
|
||||||
|
|
||||||
#undef utf16_index
|
#undef utf16_index
|
||||||
|
|
||||||
//if (unlikely (!buffer->ensure (glyphs_len)))
|
if (unlikely (!buffer->ensure (actualGlyphs)))
|
||||||
// FAIL ("Buffer in error");
|
FAIL ("Buffer in error");
|
||||||
|
|
||||||
#undef FAIL
|
#undef FAIL
|
||||||
|
|
||||||
/* Set glyph infos */
|
/* Set glyph infos */
|
||||||
buffer->len = 0;
|
buffer->len = 0;
|
||||||
for (unsigned int i = 0; i < glyphs_len; i++)
|
for (unsigned int i = 0; i < actualGlyphs; i++)
|
||||||
{
|
{
|
||||||
hb_glyph_info_t *info = &buffer->info[buffer->len++];
|
hb_glyph_info_t *info = &buffer->info[buffer->len++];
|
||||||
|
|
||||||
|
@ -815,7 +809,7 @@ _hb_directwrite_shape(hb_shape_plan_t *shape_plan,
|
||||||
|
|
||||||
/* Set glyph positions */
|
/* Set glyph positions */
|
||||||
buffer->clear_positions ();
|
buffer->clear_positions ();
|
||||||
for (unsigned int i = 0; i < glyphs_len; i++)
|
for (unsigned int i = 0; i < actualGlyphs; i++)
|
||||||
{
|
{
|
||||||
hb_glyph_info_t *info = &buffer->info[i];
|
hb_glyph_info_t *info = &buffer->info[i];
|
||||||
hb_glyph_position_t *pos = &buffer->pos[i];
|
hb_glyph_position_t *pos = &buffer->pos[i];
|
||||||
|
@ -833,6 +827,8 @@ _hb_directwrite_shape(hb_shape_plan_t *shape_plan,
|
||||||
free (glyphs);
|
free (glyphs);
|
||||||
free (textProperties);
|
free (textProperties);
|
||||||
free (glyphProperties);
|
free (glyphProperties);
|
||||||
|
free (advances);
|
||||||
|
free (offsets);
|
||||||
|
|
||||||
/* Wow, done! */
|
/* Wow, done! */
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in New Issue