Ejemplo n.º 1
0
void bf_ReduceAllGlyph(bf_t *bf)
{
  int i;
  bg_t *bg;
  int red_x, red_y;
  
  bf_Log(bf, "Reduce: Start");
  
  for( i = 0; i < bf->glyph_cnt; i++ )
  {
    bg = bf->glyph_list[i];
    if ( bg->map_to >= 0 )
    {
      bg_ReduceGlyph(bg);
      //bg_ShowBitmap(bg, &(bg->bbx));
      red_x = bg->bitmap_width - bg->bbx.w;
      red_y = bg->bitmap_height - bg->bbx.h;
      if ( red_x > 0 || red_y > 0 )
      {
	//bf_Log(bf, "Reduce: Encoding %ld, x by %d, y by %d", bg->encoding, red_x, red_y);
      }
    }
  }
  bf_Log(bf, "Reduce: End");

}
Ejemplo n.º 2
0
void bf_CalculateMaxBBX(bf_t *bf)
{
  int i;
  int is_first = 1;
  int enc_idx;
  bg_t *bg;
  
  
  for( i = 0; i < bf->glyph_cnt; i++ )
  {
    bg = bf->glyph_list[i];
    if ( bg->map_to >= 0 )
    {
      if ( is_first != 0 )
      {
	bf->max = bg->bbx;
	bf->enc_x = bg->encoding;
	bf->enc_y = bg->encoding;
	bf->enc_w = bg->encoding;
	bf->enc_h = bg->encoding;
	is_first = 0;
      }
      else
      {
	enc_idx = bg_Max(bg, &(bf->max));
	switch(enc_idx)
	{
	  case 1:
	    bf->enc_w = bg->encoding;
	    break;
	  case 2:
	    bf->enc_h = bg->encoding;
	    break;
	  case 3:
	    bf->enc_x = bg->encoding;
	    break;
	  case 4:
	    bf->enc_y = bg->encoding;
	    break;
	}
      }
    }
  }
  
  if ( bf->bbx_mode == BDF_BBX_MODE_M8 )
  {
    bf->max.w = ( bf->max.w + 7 ) & ~7;
    bf->max.h = ( bf->max.h + 7 ) & ~7;
  }

  
  bf_Log(bf, "CalculateMaxBBX: x=%ld, y=%ld, w=%ld, h=%ld", bf->max.x, bf->max.y, bf->max.w, bf->max.h);
  bf_Log(bf, "CalculateMaxBBX: Encodings x=%ld, y=%ld, w=%ld, h=%ld", bf->enc_x, bf->enc_y, bf->enc_w, bf->enc_h);
}
Ejemplo n.º 3
0
void bf_Map(bf_t *bf, const char *map_cmd_list)
{
  bf_Log(bf, "Map: map_cmd_list='%s'", map_cmd_list);
  bf_map_list(bf, &map_cmd_list);
  
  
}
Ejemplo n.º 4
0
void bf_map_cmd(bf_t *bf, const char **s)
{
  int i;
  bg_t *bg;
  map_cmd(s);
  
  bf_Log(bf, "Map: exclude=%d from=%ld to=%ld map=%ld", is_exclude, range_from, range_to, map_to);
  
  for( i = 0; i < bf->glyph_cnt; i++ )
  {
    bg = bf->glyph_list[i];
    if ( bg->encoding >= range_from && bg->encoding <= range_to )
    {
      if ( is_exclude != 0 )
      {
	bg->map_to = -1;
      }
      else
      {
	bg->map_to = bg->encoding - range_from + map_to;
      }
    }
  }
  
}
Ejemplo n.º 5
0
int bf_WriteU8G2CByFilename(bf_t *bf, const char *filename, const char *fontname, const char *indent)
{
  FILE *fp;
  fp = fopen(filename, "wb");
  if ( fp == NULL )
  {
    bf_Log(bf, "bf_WriteU8G2CByFilename: Open error '%s'", filename);
    return 0;
  }
  
  bf_WriteU8G2CByFP(bf, fp, fontname, indent);
  bf_Log(bf, "bf_WriteU8G2CByFilename: Write file '%s'", filename);
  
  fclose(fp);
  return 1;
}
Ejemplo n.º 6
0
void bf_CalculateMinMaxDWidth(bf_t *bf)
{
  int i;
  bg_t *bg;
  
  bf->dx_min = 0x07fff;
  bf->dx_max = -0x07fff;
  
  bf->x_min = 0x07fff;
  bf->x_max = -0x07fff;
  
  for( i = 0; i < bf->glyph_cnt; i++ )
  {
    bg = bf->glyph_list[i];
    if ( bg->map_to >= 0 )
    {
      if ( bf->dx_min > bg->dwidth_x )
	bf->dx_min = bg->dwidth_x;
      if ( bf->dx_max < bg->dwidth_x )
	bf->dx_max = bg->dwidth_x;

      if ( bf->x_min > bg->bbx.x )
	bf->x_min = bg->bbx.x;
      if ( bf->x_max < bg->bbx.x )
	bf->x_max = bg->bbx.x;
      
    }
  }
  bf_Log(bf, "bf_CalculateMinMaxDWidth: dx_min=%ld, dx_max=%ld", bf->dx_min, bf->dx_max);
  bf_Log(bf, "bf_CalculateMinMaxDWidth: x_min=%ld, x_max=%ld", bf->x_min, bf->x_max);
  if ( bf->dx_min == bf->dx_max && bf->x_min >= 0 )
  {
    bf_Log(bf, "bf_CalculateMinMaxDWidth: Monospaced font.");	/* not sufficient: also bbx.x must be >= 0 for all glyphs */
    /* for a monospaced font, dx must be identical to bbx.w */
  }
}
Ejemplo n.º 7
0
void bf_ShowMonospaceStatistics(bf_t *bf)
{
  int i;
  bg_t *bg;
  long cnt = 0;
  long max = 0;
  long sum = 0;
  for( i = 0; i < bf->glyph_cnt; i++ )
  {
    bg = bf->glyph_list[i];
    if ( bg->map_to >= 0 )
    {
      if ( max < bg->width_deviation )
	max = bg->width_deviation;
      sum += bg->width_deviation;
      cnt++;
    }
  }
  if ( cnt == 0 )
    cnt++;
  bf_Log(bf, "Monospace Statistics: Max width extention %ld, average width extention %ld.%ld", max, sum/cnt, (sum*10/cnt) % 10 );
  /*
    Monospaced font: average width extention does not differ much between -b 1 and --b 2
    Variable width font: big difference for the average width extention between modes 1 and 2.
  
    Examples:
  
      ./bdfconv -b 1 -v ../bdf/profont12.bdf
	Monospace Statistics: Max width extention 6, average width extention 1.7
      ./bdfconv -b 2 -v ../bdf/profont12.bdf
	Monospace Statistics: Max width extention 6, average width extention 1.7
      --> profont12.bdf is a monospaced font  
  
      ./bdfconv -b 1 -v ../bdf/helvR12.bdf
	Monospace Statistics: Max width extention 6, average width extention 1.9
      ./bdfconv -b 2 -v ../bdf/helvR12.bdf
	Monospace Statistics: Max width extention 15, average width extention 8.0
      --> helvR12.bdf is not a monospaced font  
  
  */
}
Ejemplo n.º 8
0
int main(int argc, char **argv)
{
  bf_t *bf_desc_font;
  bf_t *bf;
  char *bdf_filename = NULL;
  int is_verbose = 0;
  char *map_str ="*";
  char *desc_font_str = "";
  unsigned y;
  
  argv++;
  /*
  if ( *argv == NULL )
  {
    help();
    exit(1);
  }
  */
  for(;;)
  {
    if ( *argv == NULL )
      break;
    if ( is_arg(&argv, 'h') != 0 )
    {
      help();
      exit(1);
    }
    else if ( is_arg(&argv, 'v') != 0 )
    {
      is_verbose = 1;
    }
    else if ( is_arg(&argv, 'a') != 0 )
    {
      font_picture_extra_info = 1;
    }
    else if ( is_arg(&argv, 't') != 0 )
    {
      font_picture_test_string = 1;
    }
    else if ( is_arg(&argv, 'r') != 0 )
    {
      runtime_test = 1;
    }
    else if ( get_num_arg(&argv, 'b', &build_bbx_mode) != 0 )
    {
    }
    else if ( get_num_arg(&argv, 'f', &font_format) != 0 )
    {
    }
    else if ( get_num_arg(&argv, 'l', &left_margin) != 0 )
    {
    }
    else if ( get_str_arg(&argv, 'd', &desc_font_str) != 0 )
    {      
    }
    else if ( get_str_arg(&argv, 'o', &c_filename) != 0 )
    {      
    }
    else if ( get_str_arg(&argv, 'n', &target_fontname) != 0 )
    {      
    }
    else if ( get_str_arg(&argv, 'm', &map_str) != 0 )
    {      
    }
    else
    {
      bdf_filename = *argv;
      argv++;
    }
  }
  
  if ( bdf_filename  == NULL )
  {
    help();
    exit(1);
  }

  bf_desc_font = NULL;
  if ( desc_font_str[0] != '\0' )
  {
    bf_desc_font = bf_OpenFromFile(desc_font_str, 0, BDF_BBX_MODE_MINIMAL, "*", 0);	/* assume format 0 for description */
    if ( bf_desc_font == NULL )
    {
      exit(1);
    }
  }

  if ( font_format == 1 )
  {
    build_bbx_mode = BDF_BBX_MODE_M8;
    /* issue the following log message later, when there is a valid bf object */
    /* bf_Log(bf, "Font mode 1: BBX mode set to 3"); */
  }
  
  bf = bf_OpenFromFile(bdf_filename, is_verbose, build_bbx_mode, map_str, font_format);
  
  if ( bf == NULL )
  {
    exit(1);
  }

  if ( font_format == 1 )
  {
    /* now generate the log message */
    bf_Log(bf, "Note: For font format 1 BBX mode has been set to 3");
  }

  if ( bf_desc_font != NULL )
  {
    tga_init(1024, 600);
    y = tga_draw_font(0, bdf_filename, bf_desc_font, bf);
    
    if ( runtime_test != 0 )
    {
      long i;
      clock_t c = clock();
      fd_t fd;
      fd_init(&fd);
      fd_set_font(&fd, bf->target_data);
      for( i = 0; i < 10000; i++ )
	fd_draw_string(&fd, left_margin, y, "Woven silk pyjamas exchanged for blue quartz.");
      bf_Log(bf, "Runtime test: %.2lf sec", (double)(clock()-c)/(double)CLOCKS_PER_SEC);
    }
    
    tga_save("bdf.tga");
  }
  
  
  if ( c_filename != NULL )
  {
    /* write the encoded data in bf->target_data */
    if ( font_format == 0 )
    {
      bf_WriteUCGCByFilename(bf, c_filename, target_fontname, "  ");
    }
    else
    {
      bf_WriteU8G2CByFilename(bf, c_filename, target_fontname, "  ");
    }
  }

  
  bf_Close(bf);
  return 0;
}
Ejemplo n.º 9
0
void bf_CalculateMaxBitFieldSize(bf_t *bf)
{
  int i;
  bg_t *bg;
  int bs;
  bbx_t local_bbx;
  bf->bbx_x_max_bit_size = 0;
  bf->bbx_y_max_bit_size = 0;
  bf->bbx_w_max_bit_size = 0;
  bf->bbx_h_max_bit_size = 0;
  bf->dx_max_bit_size = 0;
  for( i = 0; i < bf->glyph_cnt; i++ )
  {
    bg = bf->glyph_list[i];
    if ( bg->map_to >= 0 )
    {
      
      bf_copy_bbx_and_update_shift(bf, &local_bbx, bg);
#ifdef OLD_CLODE      
      /* modifing the following code requires update ind bdf_rle.c also */
      if ( bf->bbx_mode == BDF_BBX_MODE_MINIMAL )
      {
	local_bbx = bg->bbx;	
      }
      else if ( bf->bbx_mode == BDF_BBX_MODE_MAX )
      {
	local_bbx = bf->max;	
	local_bbx.x = 0;
	if ( bg->bbx.x < 0 )
	  bg->shift_x = bg->bbx.x;
	if ( local_bbx.w < bg->dwidth_x )
	  local_bbx.w = bg->dwidth_x;
      }
      else if ( bf->bbx_mode == BDF_BBX_MODE_M8 )
      {
	local_bbx.w = bf->max.w;
	if ( local_bbx.w < bg->dwidth_x )
	  local_bbx.w = bg->dwidth_x;
	local_bbx.w = (local_bbx.w+7) & ~7;
	local_bbx.h = (bf->max.h+7) & ~7;
	local_bbx.x = bf->max.x;
	local_bbx.y = bf->max.y;
	local_bbx.x = 0;
	if ( bg->bbx.x < 0 )
	  bg->shift_x = bg->bbx.x;
      }
      else
      {

	local_bbx = bf->max;
	local_bbx.w = bg->bbx.w;	
	local_bbx.x = bg->bbx.x;	
	local_bbx.x = 0;
	if ( bg->bbx.x < 0 )
	{
	  /* e.g. "j" */
	  local_bbx.w -= bg->bbx.x;
	  bg->shift_x = bg->bbx.x;
	}
	else
	{
	  /* e.g. "B" */
	  local_bbx.w += bg->bbx.x;
	  //bg->shift_x = bg->bbx.x;
	}
	if ( local_bbx.w < bg->dwidth_x )
	  local_bbx.w = bg->dwidth_x;
      }
#endif
      bs = get_unsigned_bit_size(local_bbx.w);
      if ( bf->bbx_w_max_bit_size < bs )
	bf->bbx_w_max_bit_size = bs;
      
      bs = get_unsigned_bit_size(local_bbx.h);
      if ( bf->bbx_h_max_bit_size < bs )
	bf->bbx_h_max_bit_size = bs;
      
      //printf("%ld ", local_bbx.x);
      bs = get_signed_bit_size(local_bbx.x);
      if ( bf->bbx_x_max_bit_size < bs )
	bf->bbx_x_max_bit_size = bs;
      //printf("%d:%d ",(int)local_bbx->x, (int)bs);

      bs = get_signed_bit_size(local_bbx.y);
      if ( bf->bbx_y_max_bit_size < bs )
	bf->bbx_y_max_bit_size = bs;

      if ( bf->bbx_mode == BDF_BBX_MODE_MINIMAL )
      {
	bs = get_signed_bit_size(bg->dwidth_x);
      }
      else if ( bf->bbx_mode == BDF_BBX_MODE_MAX )
      {
	bs = get_signed_bit_size(local_bbx.w);
      }
      else
      {
	bs = get_signed_bit_size(local_bbx.w);
      }
      if ( bf->dx_max_bit_size < bs )
	bf->dx_max_bit_size = bs;
      
    }
  }
  bf_Log(bf, "bf_CalculateMaxBitFieldSize: bbx.x=%d, bbx.y=%d, bbx.w=%d, bbx.h=%d, dwidth=%d", 
      bf->bbx_x_max_bit_size, bf->bbx_y_max_bit_size, bf->bbx_w_max_bit_size, bf->bbx_h_max_bit_size, bf->dx_max_bit_size);
  
}