File: bdftogd.c

package info (click to toggle)
scilab 4.0-12
  • links: PTS
  • area: non-free
  • in suites: etch, etch-m68k
  • size: 100,640 kB
  • ctags: 57,333
  • sloc: ansic: 377,889; fortran: 242,862; xml: 179,819; tcl: 42,062; sh: 10,593; ml: 9,441; makefile: 4,377; cpp: 1,354; java: 621; csh: 260; yacc: 247; perl: 130; lex: 126; asm: 72; lisp: 30
file content (149 lines) | stat: -rw-r--r-- 3,141 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#define MAXCHARS 256
#define MAXLINE 80
#include "gd.h"
#include <string.h>
#include <stdlib.h>

#ifdef WIN32
#include "../os_specific/win_mem_alloc.h" /* MALLOC */
#else
#include "../os_specific/sci_mem_alloc.h" /* MALLOC */
#endif

#define BITN(x,n) ( (x>>n) & 0x1 ) 
#define Max(x,y)	(((x)>(y))?(x):(y))

/* extern gdFontPtr FontPtr;*/

int GetTag(s,tag)
     char *s, *tag;
{
  int i;
  i=0;
  while (*s) {
    tag[i++] = *s++;
    if (*s == ' ' || *s == '\t' || *s == '\n') {
      tag[i] = '\0';
      return i++;
    }
  }
  return i; /* Correction warning missing return statement at end of non-void function */
}

void dispchar(C,height,width)
     char *C;
     int height,width;
{
  int i,j,k;
  k=0;
  for (i=0;i<height;i++) {
    for (j=0;j<width;j++) {
      printf("%d",C[k]);
      k++;
    }
    printf("\n");
  }
  printf("\n");
}

int ReadbdfFont(f,FontPtr,FontName)
     FILE *f;
     gdFontPtr FontPtr;
     char *FontName;

{
  char s[MAXLINE],hex[3],Spacing[4];
  char tag[MAXLINE];
  int curptr, curptrs, curcharptr;
  int  bottom, width, currentchar, globalleft, globaltop, left;
  int height,hei,wid, gobitmap, bot;
  char *Data, *data;
  int i, j, nrow, nbytes,k ;
  int c;

  FontPtr->fixed =0;
  gobitmap =0;
  hex[2]=0;

  while (fgets(s,MAXLINE,f)) 
    {
      GetTag(s,tag); 
      if (!strcmp(tag,"ENCODING")){
	sscanf(s,"%s %d",tag,&currentchar);
      }
      else if (!strcmp(tag,"FONT")){
	sscanf(s,"%s %s",tag,FontName);
      }
      else if (!strcmp(tag,"SPACING")){
	char buff[256];
	int nbchar = sprintf(buff,"%%%ds %%3s",MAXLINE-4);
	buff[nbchar+1]='\0';

	sscanf(s,buff,tag,Spacing);
	if (Spacing[1]=='M') FontPtr->fixed=1;
      }
      else if (!strcmp(tag,"FONTBOUNDINGBOX")){
	sscanf(s,"%s %d %d %d %d",tag,&width,&height,&globalleft,&globaltop);
	Data = (char *)CALLOC(256*width*height,sizeof(char));
	if (Data == 0) return 1;
	data = (char *)CALLOC(width*height+8,sizeof(char));
	if (Data == 0) {
	  FREE(Data);
	  return 1;
	}
	FontPtr->nchars = 256;
	FontPtr->offset = 0; /* ? */
	FontPtr->w = width;
	FontPtr->h = height;
	FontPtr->data = Data;
	for (i=0;i<256*width*height;i++) Data[i]=0;
      }
      else if (!strcmp(tag,"BBX")){
	sscanf(s,"%s %d %d %d %d",tag,&wid,&hei,&left,&bottom);
      }
      else if (!strcmp(tag,"BITMAP")){
	if (currentchar>=0) {
	  gobitmap = 1;
	  nrow = 0;
	  curcharptr = width*height*currentchar;
	  for (i=0; i<width*height; i++) data[i]=0;
	}
	curptrs = 0;
      }

      else if (!strcmp(tag,"ENDCHAR")){
	gobitmap = 0;
	if (currentchar>=0) {
	  bot = globaltop - bottom;
	  if (bot <= 0) {
	    k=curcharptr+(height-nrow+bot)*width;
	    for (i=0; i<nrow*width; i++)
	      Data[k + i]=data[i];
	  }
	}
      }
      else if (gobitmap) {
	curptr = Max(curptrs+left,0); /** Max added : jpc Jul 99 **/
	
	nbytes=strlen(s)/2;
	for (j=0 ; j<nbytes ; j++) {
	  hex[0]=s[2*j];
	  hex[1]=s[2*j+1];
	  sscanf(hex,"%x",&c);
	  for (i=7 ; i>=0 ; i--) {
	    data[curptr++] = (char)(BITN(c,i) != 0);
	  }
	}

	/* ?????? */
        if (curptrs >0)
	  data[curptrs-1]=0;
	
        curptrs = curptrs + width;
	nrow++;
      }
    }
  FREE(data);
  return 0;
}