Exemplo n.º 1
0
Arquivo: font.c Projeto: 0xPIT/UltiDMM
// -----------------------------------------------------------------------------
// Calculate the pointer to the requested character inside the Flash ROM
//
PGM_P font_get_char_position(FONT_P font, char character) 
{
  uint16_t ret         = 0;
  int16_t  charnum_ret = font_get_char_number(font, character);
  uint8_t  charnum     = charnum_ret;
  PGM_P    base        = font_widthtable(font);
  
  if (charnum_ret < 0) { // char not found
    return 0;
  }
  
  if (base == 0) { // fixed width
    return font_data(font) + (uint16_t)charnum / (uint8_t)(font_get_height_bytes(font) / font_get_char_width(font,character));
  }
  
  if (charnum) { // proportional width
    while (charnum--) {
      ret += pgm_read_byte(base++);
    }
  }
  
  return (font_data(font)) + ret * font_get_height_bytes(font);
}
Exemplo n.º 2
0
int main ()
{
  printf ("Results of open_benchmark:\n");

  try
  {
    FT_Library library;

    if (FT_Init_FreeType (&library))
      throw xtl::format_operation_exception ("::FT_Init_FreeType", "Can't init freetype library\n");

    {
      common::InputFile font_file (FILE_NAME);

      xtl::uninitialized_storage<char> font_data (font_file.Size ());

      font_file.Read (font_data.data (), font_data.size ());

      size_t start_time = common::milliseconds ();

      for (size_t i = 0; i < MEMORY_ITERATIONS_COUNT; i++)
      {
        FT_Face face;

        if (FT_New_Memory_Face (library, (const FT_Byte*)font_data.data (), font_data.size (), 0, &face))
          throw xtl::format_operation_exception ("FontFace::FontFace", "Can't create font face\n");

        FT_Done_Face (face);
      }

      printf ("FreeType font creation speed from memory is %f/s\n", MEMORY_ITERATIONS_COUNT / ((common::milliseconds () - start_time) / 1000.f));
    }

    {
      size_t start_time = common::milliseconds ();

      for (size_t i = 0; i < FILE_ITERATIONS_COUNT; i++)
      {
        common::InputFile font_file (FILE_NAME);

        xtl::uninitialized_storage<char> font_data (font_file.Size ());

        font_file.Read (font_data.data (), font_data.size ());

        FT_Face face;

        if (FT_New_Memory_Face (library, (const FT_Byte*)font_data.data (), font_data.size (), 0, &face))
          throw xtl::format_operation_exception ("FontFace::FontFace", "Can't create font face\n");

        FT_Done_Face (face);
      }

      printf ("FreeType font creation speed from file is %f/s\n", FILE_ITERATIONS_COUNT / ((common::milliseconds () - start_time) / 1000.f));
    }

    FT_Done_FreeType (library);
  }
  catch (std::exception& exception)
  {                                               
    printf ("exception: %s\n",exception.what ());
  }                                               
  catch (...)
  {
    printf ("unknown exception\n");
  }

  return 0;
}