raqm: avoid declaring variables in for statement for C89 compatibility

This commit is contained in:
nulano 2020-11-25 18:01:49 +00:00 committed by Andrew Murray
parent c3fce854f2
commit f2b2d53ca8

View File

@ -220,6 +220,7 @@ static bool
_raqm_init_text_info (raqm_t *rq)
{
hb_language_t default_lang;
size_t i;
if (rq->text_info)
return true;
@ -229,7 +230,7 @@ _raqm_init_text_info (raqm_t *rq)
return false;
default_lang = hb_language_get_default ();
for (size_t i = 0; i < rq->text_len; i++)
for (i = 0; i < rq->text_len; i++)
{
rq->text_info[i].ftface = NULL;
rq->text_info[i].lang = default_lang;
@ -242,10 +243,12 @@ _raqm_init_text_info (raqm_t *rq)
static void
_raqm_free_text_info (raqm_t *rq)
{
size_t i;
if (!rq->text_info)
return;
for (size_t i = 0; i < rq->text_len; i++)
for (i = 0; i < rq->text_len; i++)
{
if (rq->text_info[i].ftface)
FT_Done_Face (rq->text_info[i].ftface);
@ -551,6 +554,7 @@ raqm_set_language (raqm_t *rq,
size_t len)
{
hb_language_t language;
size_t i;
size_t end = start + len;
if (!rq)
@ -572,7 +576,7 @@ raqm_set_language (raqm_t *rq,
return false;
language = hb_language_from_string (lang, -1);
for (size_t i = start; i < end; i++)
for (i = start; i < end; i++)
{
rq->text_info[i].lang = language;
}
@ -646,6 +650,8 @@ _raqm_set_freetype_face (raqm_t *rq,
size_t start,
size_t end)
{
size_t i;
if (!rq)
return false;
@ -658,7 +664,7 @@ _raqm_set_freetype_face (raqm_t *rq,
if (!rq->text_info)
return false;
for (size_t i = start; i < end; i++)
for (i = start; i < end; i++)
{
if (rq->text_info[i].ftface)
FT_Done_Face (rq->text_info[i].ftface);
@ -832,6 +838,8 @@ _raqm_shape (raqm_t *rq);
bool
raqm_layout (raqm_t *rq)
{
size_t i;
if (!rq)
return false;
@ -841,7 +849,7 @@ raqm_layout (raqm_t *rq)
if (!rq->text_info)
return false;
for (size_t i = 0; i < rq->text_len; i++)
for (i = 0; i < rq->text_len; i++)
{
if (!rq->text_info[i].ftface)
return false;
@ -879,6 +887,9 @@ raqm_glyph_t *
raqm_get_glyphs (raqm_t *rq,
size_t *length)
{
size_t i;
raqm_run_t *run;
size_t count = 0;
if (!rq || !rq->runs || !length)
@ -888,7 +899,7 @@ raqm_get_glyphs (raqm_t *rq,
return NULL;
}
for (raqm_run_t *run = rq->runs; run != NULL; run = run->next)
for (run = rq->runs; run != NULL; run = run->next)
count += hb_buffer_get_length (run->buffer);
*length = count;
@ -906,7 +917,7 @@ raqm_get_glyphs (raqm_t *rq,
RAQM_TEST ("Glyph information:\n");
count = 0;
for (raqm_run_t *run = rq->runs; run != NULL; run = run->next)
for (run = rq->runs; run != NULL; run = run->next)
{
size_t len;
hb_glyph_info_t *info;
@ -916,7 +927,7 @@ raqm_get_glyphs (raqm_t *rq,
info = hb_buffer_get_glyph_infos (run->buffer, NULL);
position = hb_buffer_get_glyph_positions (run->buffer, NULL);
for (size_t i = 0; i < len; i++)
for (i = 0; i < len; i++)
{
rq->glyphs[count + i].index = info[i].codepoint;
rq->glyphs[count + i].cluster = info[i].cluster;
@ -939,18 +950,18 @@ raqm_get_glyphs (raqm_t *rq,
{
#ifdef RAQM_TESTING
RAQM_TEST ("\nUTF-32 clusters:");
for (size_t i = 0; i < count; i++)
for (i = 0; i < count; i++)
RAQM_TEST (" %02d", rq->glyphs[i].cluster);
RAQM_TEST ("\n");
#endif
for (size_t i = 0; i < count; i++)
for (i = 0; i < count; i++)
rq->glyphs[i].cluster = _raqm_u32_to_u8_index (rq,
rq->glyphs[i].cluster);
#ifdef RAQM_TESTING
RAQM_TEST ("UTF-8 clusters: ");
for (size_t i = 0; i < count; i++)
for (i = 0; i < count; i++)
RAQM_TEST (" %02d", rq->glyphs[i].cluster);
RAQM_TEST ("\n");
#endif
@ -983,9 +994,11 @@ typedef struct {
static void
_raqm_reverse_run (_raqm_bidi_run *run, const size_t len)
{
size_t i;
assert (run);
for (size_t i = 0; i < len / 2; i++)
for (i = 0; i < len / 2; i++)
{
_raqm_bidi_run temp = run[i];
run[i] = run[len - 1 - i];
@ -1002,6 +1015,7 @@ _raqm_reorder_runs (const FriBidiCharType *types,
/* output */
size_t *run_count)
{
size_t i;
FriBidiLevel level;
FriBidiLevel last_level = -1;
FriBidiLevel max_level = 0;
@ -1021,8 +1035,7 @@ _raqm_reorder_runs (const FriBidiCharType *types,
/* L1. Reset the embedding levels of some chars:
4. any sequence of white space characters at the end of the line. */
for (int i = len - 1;
i >= 0 && FRIBIDI_IS_EXPLICIT_OR_BN_OR_WS (types[i]); i--)
for (i = len; i-- > 0 && FRIBIDI_IS_EXPLICIT_OR_BN_OR_WS (types[i]); )
{
levels[i] = FRIBIDI_DIR_TO_LEVEL (base_dir);
}
@ -1030,13 +1043,13 @@ _raqm_reorder_runs (const FriBidiCharType *types,
/* Find max_level of the line. We don't reuse the paragraph
* max_level, both for a cleaner API, and that the line max_level
* may be far less than paragraph max_level. */
for (int i = len - 1; i >= 0; i--)
for (i = len; i-- > 0; )
{
if (levels[i] > max_level)
max_level = levels[i];
}
for (size_t i = 0; i < len; i++)
for (i = 0; i < len; i++)
{
if (levels[i] != last_level)
count++;
@ -1064,14 +1077,16 @@ _raqm_reorder_runs (const FriBidiCharType *types,
/* L2. Reorder. */
for (level = max_level; level > 0; level--)
{
for (int i = count - 1; i >= 0; i--)
for (i = count; i-- > 0; )
{
if (runs[i].level >= level)
{
int end = i;
for (i--; (i >= 0 && runs[i].level >= level); i--)
for (; (i > 0 && runs[i - 1].level >= level); i--)
;
_raqm_reverse_run (runs + i + 1, end - i);
_raqm_reverse_run (runs + i, end - i + 1);
if (i-- == 0)
break;
}
}
}
@ -1083,6 +1098,8 @@ _raqm_reorder_runs (const FriBidiCharType *types,
static bool
_raqm_itemize (raqm_t *rq)
{
size_t i, j;
raqm_run_t *run;
FriBidiParType par_type = FRIBIDI_PAR_ON;
FriBidiCharType *types;
#ifdef USE_FRIBIDI_EX_API
@ -1185,7 +1202,7 @@ _raqm_itemize (raqm_t *rq)
RAQM_TEST ("Number of runs before script itemization: %zu\n\n", run_count);
RAQM_TEST ("Fribidi Runs:\n");
for (size_t i = 0; i < run_count; i++)
for (i = 0; i < run_count; i++)
{
RAQM_TEST ("run[%zu]:\t start: %zu\tlength: %zu\tlevel: %d\n",
i, runs[i].pos, runs[i].len, runs[i].level);
@ -1194,7 +1211,7 @@ _raqm_itemize (raqm_t *rq)
#endif
last = NULL;
for (size_t i = 0; i < run_count; i++)
for (i = 0; i < run_count; i++)
{
raqm_run_t *run = calloc (1, sizeof (raqm_run_t));
if (!run)
@ -1216,7 +1233,7 @@ _raqm_itemize (raqm_t *rq)
run->pos = runs[i].pos + runs[i].len - 1;
run->script = rq->text_info[run->pos].script;
run->font = _raqm_create_hb_font (rq, rq->text_info[run->pos].ftface);
for (int j = runs[i].len - 1; j >= 0; j--)
for (j = runs[i].len; j-- > 0; )
{
_raqm_text_info info = rq->text_info[runs[i].pos + j];
if (!_raqm_compare_text_info (rq->text_info[run->pos], info))
@ -1247,7 +1264,7 @@ _raqm_itemize (raqm_t *rq)
run->pos = runs[i].pos;
run->script = rq->text_info[run->pos].script;
run->font = _raqm_create_hb_font (rq, rq->text_info[run->pos].ftface);
for (size_t j = 0; j < runs[i].len; j++)
for (j = 0; j < runs[i].len; j++)
{
_raqm_text_info info = rq->text_info[runs[i].pos + j];
if (!_raqm_compare_text_info (rq->text_info[run->pos], info))
@ -1277,13 +1294,13 @@ _raqm_itemize (raqm_t *rq)
#ifdef RAQM_TESTING
run_count = 0;
for (raqm_run_t *run = rq->runs; run != NULL; run = run->next)
for (run = rq->runs; run != NULL; run = run->next)
run_count++;
RAQM_TEST ("Number of runs after script itemization: %zu\n\n", run_count);
run_count = 0;
RAQM_TEST ("Final Runs:\n");
for (raqm_run_t *run = rq->runs; run != NULL; run = run->next)
for (run = rq->runs; run != NULL; run = run->next)
{
SCRIPT_TO_STRING (run->script);
RAQM_TEST ("run[%zu]:\t start: %d\tlength: %d\tdirection: %s\tscript: %s\tfont: %s\n",
@ -1448,18 +1465,19 @@ _get_pair_index (const FriBidiChar ch)
static bool
_raqm_resolve_scripts (raqm_t *rq)
{
int last_script_index = -1;
int last_set_index = -1;
size_t i, j;
size_t next_script_index = 0;
size_t next_set_index = 0;
hb_script_t last_script = HB_SCRIPT_INVALID;
_raqm_stack_t *stack = NULL;
hb_unicode_funcs_t* unicode_funcs = hb_unicode_funcs_get_default ();
for (size_t i = 0; i < rq->text_len; ++i)
for (i = 0; i < rq->text_len; ++i)
rq->text_info[i].script = hb_unicode_script (unicode_funcs, rq->text[i]);
#ifdef RAQM_TESTING
RAQM_TEST ("Before script detection:\n");
for (size_t i = 0; i < rq->text_len; ++i)
for (i = 0; i < rq->text_len; ++i)
{
SCRIPT_TO_STRING (rq->text_info[i].script);
RAQM_TEST ("script for ch[%zu]\t%s\n", i, buff);
@ -1471,9 +1489,9 @@ _raqm_resolve_scripts (raqm_t *rq)
if (!stack)
return false;
for (int i = 0; i < (int) rq->text_len; i++)
for (i = 0; i < rq->text_len; i++)
{
if (rq->text_info[i].script == HB_SCRIPT_COMMON && last_script_index != -1)
if (rq->text_info[i].script == HB_SCRIPT_COMMON && next_script_index != 0)
{
int pair_index = _get_pair_index (rq->text[i]);
if (pair_index >= 0)
@ -1482,7 +1500,7 @@ _raqm_resolve_scripts (raqm_t *rq)
{
/* is a paired character */
rq->text_info[i].script = last_script;
last_set_index = i;
next_set_index = i + 1;
_raqm_stack_push (stack, rq->text_info[i].script, pair_index);
}
else
@ -1499,34 +1517,34 @@ _raqm_resolve_scripts (raqm_t *rq)
{
rq->text_info[i].script = _raqm_stack_top (stack);
last_script = rq->text_info[i].script;
last_set_index = i;
next_set_index = i + 1;
}
else
{
rq->text_info[i].script = last_script;
last_set_index = i;
next_set_index = i + 1;
}
}
}
else
{
rq->text_info[i].script = last_script;
last_set_index = i;
next_set_index = i + 1;
}
}
else if (rq->text_info[i].script == HB_SCRIPT_INHERITED &&
last_script_index != -1)
next_script_index != 0)
{
rq->text_info[i].script = last_script;
last_set_index = i;
next_set_index = i + 1;
}
else
{
for (int j = last_set_index + 1; j < i; ++j)
for (j = next_set_index; j < i; ++j)
rq->text_info[j].script = rq->text_info[i].script;
last_script = rq->text_info[i].script;
last_script_index = i;
last_set_index = i;
next_script_index = i + 1;
next_set_index = i + 1;
}
}
@ -1534,7 +1552,7 @@ _raqm_resolve_scripts (raqm_t *rq)
* take the script if the next character.
* https://github.com/HOST-Oman/libraqm/issues/95
*/
for (int i = rq->text_len - 2; i >= 0; --i)
for (i = rq->text_len - 1; i-- > 0; )
{
if (rq->text_info[i].script == HB_SCRIPT_INHERITED ||
rq->text_info[i].script == HB_SCRIPT_COMMON)
@ -1543,7 +1561,7 @@ _raqm_resolve_scripts (raqm_t *rq)
#ifdef RAQM_TESTING
RAQM_TEST ("After script detection:\n");
for (size_t i = 0; i < rq->text_len; ++i)
for (i = 0; i < rq->text_len; ++i)
{
SCRIPT_TO_STRING (rq->text_info[i].script);
RAQM_TEST ("script for ch[%zu]\t%s\n", i, buff);
@ -1559,6 +1577,7 @@ _raqm_resolve_scripts (raqm_t *rq)
static bool
_raqm_shape (raqm_t *rq)
{
raqm_run_t *run;
hb_buffer_flags_t hb_buffer_flags = HB_BUFFER_FLAG_BOT | HB_BUFFER_FLAG_EOT;
#if defined(HAVE_DECL_HB_BUFFER_FLAG_REMOVE_DEFAULT_IGNORABLES) && \
@ -1567,7 +1586,7 @@ _raqm_shape (raqm_t *rq)
hb_buffer_flags |= HB_BUFFER_FLAG_REMOVE_DEFAULT_IGNORABLES;
#endif
for (raqm_run_t *run = rq->runs; run != NULL; run = run->next)
for (run = rq->runs; run != NULL; run = run->next)
{
run->buffer = hb_buffer_create ();
@ -1653,6 +1672,8 @@ raqm_index_to_position (raqm_t *rq,
int *x,
int *y)
{
size_t i, j;
raqm_run_t *run;
/* We don't currently support multiline, so y is always 0 */
*y = 0;
*x = 0;
@ -1676,7 +1697,7 @@ raqm_index_to_position (raqm_t *rq,
++*index;
}
for (raqm_run_t *run = rq->runs; run != NULL; run = run->next)
for (run = rq->runs; run != NULL; run = run->next)
{
size_t len;
hb_glyph_info_t *info;
@ -1685,7 +1706,7 @@ raqm_index_to_position (raqm_t *rq,
info = hb_buffer_get_glyph_infos (run->buffer, NULL);
position = hb_buffer_get_glyph_positions (run->buffer, NULL);
for (size_t i = 0; i < len; i++)
for (i = 0; i < len; i++)
{
uint32_t curr_cluster = info[i].cluster;
uint32_t next_cluster = curr_cluster;
@ -1693,13 +1714,12 @@ raqm_index_to_position (raqm_t *rq,
if (run->direction == HB_DIRECTION_LTR)
{
for (size_t j = i + 1; j < len && next_cluster == curr_cluster; j++)
for (j = i + 1; j < len && next_cluster == curr_cluster; j++)
next_cluster = info[j].cluster;
}
else
{
for (int j = i - 1; i != 0 && j >= 0 && next_cluster == curr_cluster;
j--)
for (j = i; i != 0 && j-- > 0 && next_cluster == curr_cluster; )
next_cluster = info[j].cluster;
}
@ -1745,6 +1765,8 @@ raqm_position_to_index (raqm_t *rq,
int y,
size_t *index)
{
size_t i, j;
raqm_run_t *run;
int delta_x = 0, current_x = 0;
(void)y;
@ -1762,7 +1784,7 @@ raqm_position_to_index (raqm_t *rq,
RAQM_TEST ("\n");
for (raqm_run_t *run = rq->runs; run != NULL; run = run->next)
for (run = rq->runs; run != NULL; run = run->next)
{
size_t len;
hb_glyph_info_t *info;
@ -1771,7 +1793,7 @@ raqm_position_to_index (raqm_t *rq,
info = hb_buffer_get_glyph_infos (run->buffer, NULL);
position = hb_buffer_get_glyph_positions (run->buffer, NULL);
for (size_t i = 0; i < len; i++)
for (i = 0; i < len; i++)
{
delta_x = position[i].x_advance;
if (x < (current_x + delta_x))
@ -1789,11 +1811,10 @@ raqm_position_to_index (raqm_t *rq,
uint32_t curr_cluster = info[i].cluster;
uint32_t next_cluster = curr_cluster;
if (run->direction == HB_DIRECTION_LTR)
for (size_t j = i + 1; j < len && next_cluster == curr_cluster; j++)
for (j = i + 1; j < len && next_cluster == curr_cluster; j++)
next_cluster = info[j].cluster;
else
for (int j = i - 1; i != 0 && j >= 0 && next_cluster == curr_cluster;
j--)
for (j = i; i != 0 && j-- > 0 && next_cluster == curr_cluster; )
next_cluster = info[j].cluster;
if (next_cluster == curr_cluster)