Exemple #1
0
static void preset_fontmetrics(fd_entry * fd, internalfontnumber f)
{
    int i;
    fd->font_dim[ITALIC_ANGLE_CODE].val =
        dividescaled(-atan(getslant(f) / 65536.0) * (180 / M_PI),
                     pdffontsize[f], 3);
    fd->font_dim[ASCENT_CODE].val =
        dividescaled(getcharheight(f, 'h'), pdffontsize[f], 3);
    fd->font_dim[CAPHEIGHT_CODE].val =
        dividescaled(getcharheight(f, 'H'), pdffontsize[f], 3);
    i = -dividescaled(getchardepth(f, 'y'), pdffontsize[f], 3);
    fd->font_dim[DESCENT_CODE].val = i < 0 ? i : 0;
    fd->font_dim[STEMV_CODE].val =
        dividescaled(getcharwidth(f, '.') / 3, pdffontsize[f], 3);
    fd->font_dim[XHEIGHT_CODE].val =
        dividescaled(getxheight(f), pdffontsize[f], 3);
    fd->font_dim[FONTBBOX1_CODE].val = 0;
    fd->font_dim[FONTBBOX2_CODE].val = fd->font_dim[DESCENT_CODE].val;
    fd->font_dim[FONTBBOX3_CODE].val =
        dividescaled(getquad(f), pdffontsize[f], 3);
    fd->font_dim[FONTBBOX4_CODE].val =
        fd->font_dim[CAPHEIGHT_CODE].val > fd->font_dim[ASCENT_CODE].val ?
        fd->font_dim[CAPHEIGHT_CODE].val : fd->font_dim[ASCENT_CODE].val;
    for (i = 0; i < INT_KEYS_NUM; i++)
        fd->font_dim[i].set = true;
}
Exemple #2
0
int main(const int argc, const char *argv[])
{
   FILE *file;
   unsigned char *data;

   if (argc < 8) {
      fprintf(stderr, "Usage: %s <file.gray> width height xoff yoff charwidth charheight\n", argv[0]);
      return 1;
   }
   long width = atol(argv[2]);
   long height = atol(argv[3]);
   long xoff = atol(argv[4]);
   long yoff = atol(argv[5]);
   long charwidth = atol(argv[6]);
   long charheight = atol(argv[7]);
   if (  width <= 0 || height <= 0 || xoff < 0
         || yoff < 0 || charwidth <= 0 || charheight <= 0) {
      fprintf(stderr, "%s: Error: Parameter <= 0\n", argv[0]);
      return 1;
   }

   if (charwidth > 32) {
      fprintf(stderr, "%s: Error: charwidth > 32\n", argv[0]);
      return 1;
   }

   file = fopen(argv[1], "r+");
   if (!file) goto ONERR;
   if (fseek(file, 0, SEEK_END) != 0) goto ONERR;
   size_t file_size = (size_t) ftell(file);
   if (file_size != width * height) {
      fprintf(stderr, "%s: Error: file_size != %ld\n", argv[0], width*height);
      return 1;
   }
   if (fseek(file, 0, SEEK_SET) != 0) goto ONERR;

   data = malloc((size_t)file_size);
   if (!data) {
      fprintf(stderr, "%s: Error: Out of memory\n", argv[0]);
      return 1;
   }
   if (fread(data, 1, file_size, file) != file_size) goto ONERR;

   if (nrcolor(file_size, data) != 2) {
      fprintf(stderr, "%s: Error: Picture not black and white\n", argv[0]);
      return 1;
   }

   size_t yoff2 = getyoff((size_t) width, (size_t) height, data);
   size_t charheight2 = getcharheight((size_t) width, (size_t) height, yoff2, data) + yoff2 - (size_t) yoff;
   if (charheight2 != (size_t) charheight) {
      fprintf(stderr, "%s: Error: charheight != %ld (yoff2:%ld)\n", argv[0], (long)charheight2, (long)yoff2);
      return 1;
   }

   fonttable((size_t)width, (size_t)height, (size_t)xoff, (size_t)yoff, (size_t)charwidth, (size_t)charheight, data);

   fclose(file);
   return 0;
ONERR:
   if (file) {
      fprintf(stderr, "Read error in file '%s'\n", argv[1]);
      fclose(file);
   } else {
      fprintf(stderr, "Cannot open file '%s'\n", argv[1]);
   }
   return 1;
}