Example #1
0
int
addTextTableAlias (TextTableData *ttd, wchar_t from, wchar_t to) {
  if (ttd->alias.count == ttd->alias.size) {
    size_t newSize = ttd->alias.size? (ttd->alias.size << 1): 0X10;
    TextTableAliasEntry *newArray;

    if (!(newArray = realloc(ttd->alias.array, ARRAY_SIZE(newArray, newSize)))) {
      logMallocError();
      return 0;
    }

    ttd->alias.array = newArray;
    ttd->alias.size = newSize;
  }

  {
    unsigned int cellNumber = UNICODE_CELL_NUMBER(from);
    UnicodeRowEntry *row = getUnicodeRowEntry(ttd, from, 1);

    if (!row) return 0;
    BITMASK_SET(row->cellAliased, cellNumber);
  }

  {
    TextTableAliasEntry *alias = &ttd->alias.array[ttd->alias.count++];

    memset(alias, 0, sizeof(*alias));
    alias->from = from;
    alias->to = to;
  }

  return 1;
}
Example #2
0
const unsigned char *
getUnicodeCellEntry (TextTableData *ttd, wchar_t character) {
  const UnicodeRowEntry *row = getUnicodeRowEntry(ttd, character, 0);

  if (row) {
    unsigned int cellNumber = UNICODE_CELL_NUMBER(character);
    if (BITMASK_TEST(row->defined, cellNumber)) return &row->cells[cellNumber];
  }

  return NULL;
}
Example #3
0
void
unsetTextTableCharacter (TextTableData *ttd, wchar_t character) {
  UnicodeRowEntry *row = getUnicodeRowEntry(ttd, character, 0);

  if (row) {
    unsigned int cellNumber = UNICODE_CELL_NUMBER(character);

    if (BITMASK_TEST(row->defined, cellNumber)) {
      unsigned char *cell = &row->cells[cellNumber];

      resetTextTableDots(ttd, *cell, character);
      *cell = 0;
      BITMASK_CLEAR(row->defined, cellNumber);
    }
  }
}
Example #4
0
int
setTextTableGlyph (TextTableData *ttd, wchar_t character, unsigned char dots) {
  UnicodeRowEntry *row = getUnicodeRowEntry(ttd, character, 1);

  if (row) {
    unsigned int cellNumber = UNICODE_CELL_NUMBER(character);
    unsigned char *cell = &row->cells[cellNumber];

    if (!BITMASK_TEST(row->defined, cellNumber)) {
      BITMASK_SET(row->defined, cellNumber);
    } else if (*cell != dots) {
      resetTextTableDots(ttd, *cell, character);
    }

    *cell = dots;
    return 1;
  }

  return 0;
}
Example #5
0
unsigned char
convertCharacterToDots (TextTable *table, wchar_t character) {
  switch (character & ~UNICODE_CELL_MASK) {
    case UNICODE_BRAILLE_ROW:
      return character & UNICODE_CELL_MASK;

    case 0XF000: {
      wint_t wc = convertCharToWchar(character & UNICODE_CELL_MASK);

      if (wc == WEOF) break;
      character = wc;
    }

    default: {
      {
        unsigned int counter = 0;

        while (++counter < 0X10) {
          const UnicodeRowEntry *row = getUnicodeRowEntry(table, character);

          if (row) {
            unsigned int cellNumber = UNICODE_CELL_NUMBER(character);

            if (BITMASK_TEST(row->cellDefined, cellNumber)) {
              return row->cells[cellNumber];
            }

            if (BITMASK_TEST(row->cellAliased, cellNumber)) {
              const TextTableAliasEntry *alias = findTextTableAlias(table, character);

              if (alias) {
                character = alias->to;
                continue;
              }
            }
          }

          break;
        }
      }

      if (table->options.tryBaseCharacter) {
        SetBrailleRepresentationData sbr = {
          .table = table,
          .dots = 0
        };

        if (handleBestCharacter(character, setBrailleRepresentation, &sbr)) {
          return sbr.dots;
        }
      }

      break;
    }
  }

  {
    const unsigned char *cell;

    if ((cell = getUnicodeCellEntry(table, UNICODE_REPLACEMENT_CHARACTER))) return *cell;
    if ((cell = getUnicodeCellEntry(table, WC_C('?')))) return *cell;
  }

  return BRL_DOT_1 | BRL_DOT_2 | BRL_DOT_3 | BRL_DOT_4 | BRL_DOT_5 | BRL_DOT_6 | BRL_DOT_7 | BRL_DOT_8;
}