FriBidiRun *
new_run (
  void
)
{
  register FriBidiRun *run;

#if USE_SIMPLE_MALLOC+0
  run = fribidi_malloc (sizeof (FriBidiRun));
#else /* !USE_SIMPLE_MALLOC */
  if (free_runs)
    {
      run = free_runs;
      free_runs = run->next;
    }
  else
    {
      static FriBidiMemChunk *run_mem_chunk = NULL;

      if UNLIKELY
	(!run_mem_chunk)
	 run_mem_chunk = fribidi_chunk_new_for_type (FriBidiRun);

      if LIKELY
	(run_mem_chunk)
	run = fribidi_chunk_new (FriBidiRun, run_mem_chunk);
      else
	run = NULL;
    }
Beispiel #2
0
static char *
my_fribidi_strdup (
  char *s
)
{
  char *m;

  m = fribidi_malloc (strlen (s) + 1);
  if (!m)
    return NULL;

  strcpy (m, s);

  return m;
}
fribidi_boolean
fribidi_char_set_enter_cap_rtl (void)
{
  if (!caprtl_to_unicode)
    {
      int request[FRIBIDI_TYPES_COUNT + 1];
      int i, count;

      caprtl_to_unicode =
	(FriBidiChar *) fribidi_malloc (NULL,
					CAPRTL_CHARS *
					sizeof caprtl_to_unicode[0]);
      for (i = 0; i < FRIBIDI_TYPES_COUNT; i++)
	request[i] = 0;
      for (i = 0; i < CAPRTL_CHARS; i++)
	if (fribidi_get_mirror_char (NULL, i, NULL))
	  caprtl_to_unicode[i] = i;
      for (count = 0, i = 0; i < CAPRTL_CHARS; i++)
	if (caprtl_to_unicode[i] == 0)
	  {
	    request[(unsigned char) CapRTLCharTypes[i]]++;
	    count++;
	  }
      for (i = 1; i < 0x10000 && count; i++)	/* Assign BMP chars to CapRTL entries */
	if (!fribidi_get_mirror_char (NULL, i, NULL))
	  {
	    int j, k;
	    for (j = 0; j < FRIBIDI_TYPES_COUNT; j++)
	      if (fribidi_prop_to_type[j] == fribidi_get_type_internal (i))
		break;
	    if (!request[j])	/* Do not need this type */
	      continue;
	    for (k = 0; k < CAPRTL_CHARS; k++)
	      if (!caprtl_to_unicode[k] && j == CapRTLCharTypes[k])
		break;
	    if (k < CAPRTL_CHARS)
	      {
		request[j]--;
		count--;
		caprtl_to_unicode[k] = i;
	      }
	  }
    }

  return FRIBIDI_TRUE;
}
char *
fribidi_char_set_desc_cap_rtl (void)
{
  static char *s = 0;
  int l, i, j;

  if (s)
    return s;

  l = 4000;
  s = (char *) fribidi_malloc (NULL, l);
  i = 0;
  i += snprintf (s + i, l - i,
		 "CapRTL is a character set for testing with the reference\n"
		 "implementation, with explicit marks escape strings, and\n"
		 "the property that contains all unicode character types in\n"
		 "ASCII range 1-127.\n"
		 "\n"
		 "Warning: CapRTL character types are subject to change.\n"
		 "\n" "CapRTL's character types:\n");
  for (j = 0; j < CAPRTL_CHARS; j++)
    {
      if (j % 4 == 0)
	s[i++] = '\n';
      i += snprintf (s + i, l - i, "  * 0x%02x %c%c %-3s ", j,
		     j < 0x20 ? '^' : ' ',
		     j < 0x20 ? j + '@' : j < 0x7f ? j : ' ',
		     fribidi_type_name (fribidi_prop_to_type
					[(unsigned char)
					 CapRTLCharTypes[j]]));
    }
  i += snprintf (s + i, l - i,
		 "\n\n"
		 "Escape sequences:\n"
		 "  Character `_' is used to escape explicit marks. The list is:\n"
		 "    * _>  LRM\n"
		 "    * _<  RLM\n"
		 "    * _l  LRE\n"
		 "    * _r  RLE\n"
		 "    * _L  LRO\n"
		 "    * _R  RLO\n" "    * _o  PDF\n" "    * __  `_' itself\n"
		 "\n");
  return s;
}
Beispiel #5
0
static void
init_cap_rtl (
  void
)
{
  int request[_FRIBIDI_NUM_TYPES];
  FriBidiCharType to_type[_FRIBIDI_NUM_TYPES];
  int num_types = 0, count = 0;
  FriBidiCharType i;
  char mark[CAPRTL_CHARS];

  caprtl_to_unicode =
    (FriBidiChar *) fribidi_malloc (CAPRTL_CHARS *
				    sizeof caprtl_to_unicode[0]);
  for (i = 0; i < CAPRTL_CHARS; i++)
    if (CapRTLCharTypes[i] == fribidi_get_bidi_type (i))
      {
	caprtl_to_unicode[i] = i;
	mark[i] = 1;
      }
    else
      {
	int j;

	caprtl_to_unicode[i] = FRIBIDI_UNICODE_CHARS;
	mark[i] = 0;
	if (fribidi_get_mirror_char (i, NULL))
	  {
	    DBG ("warning: I could not map mirroring character map to itself in CapRTL");
	  }

	for (j = 0; j < num_types; j++)
	  if (to_type[j] == CapRTLCharTypes[i])
	    break;
	if (j == num_types)
	  {
	    num_types++;
	    to_type[j] = CapRTLCharTypes[i];
	    request[j] = 0;
	  }
	request[j]++;
	count++;
      }
  for (i = 0; i < 0x10000 && count; i++)	/* Assign BMP chars to CapRTL entries */
    if (!fribidi_get_mirror_char (i, NULL) && !(i < CAPRTL_CHARS && mark[i]))
      {
	int j, k;
	FriBidiCharType t = fribidi_get_bidi_type (i);
	for (j = 0; j < num_types; j++)
	  if (to_type[j] == t)
	    break;
	if (!request[j])	/* Do not need this type */
	  continue;
	for (k = 0; k < CAPRTL_CHARS; k++)
	  if (caprtl_to_unicode[k] == FRIBIDI_UNICODE_CHARS
	      && to_type[j] == CapRTLCharTypes[k])
	    {
	      request[j]--;
	      count--;
	      caprtl_to_unicode[k] = i;
	      break;
	    }
      }
  if (count)
    {
      int j;

      DBG ("warning: could not find a mapping for CapRTL to Unicode:");
      for (j = 0; j < num_types; j++)
	if (request[j])
	  {
	    DBG2 ("  need this type: %s", fribidi_get_bidi_type_name (to_type[j]));
	  }
    }
}