File: displayfont.c

package info (click to toggle)
chdrv 1.0.13-0.1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 1,204 kB
  • ctags: 1,069
  • sloc: ansic: 8,972; perl: 412; asm: 234; makefile: 195; sh: 36
file content (103 lines) | stat: -rw-r--r-- 1,923 bytes parent folder | download
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
#include <stdio.h>
#include <stdlib.h>
#include "vga.h"
#include "chinese.h"

int headlen,offset,isch,maplen;
FILE *infile;
char chbuf[32*1000];
SYSCFG sys_config;

displayEnglish()
{
  int i,x,y;

  if (headlen)
    fseek(infile,headlen,SEEK_SET);
  fseek(infile,offset*maplen*2,SEEK_CUR);
  fread(chbuf,maplen*2,256,infile);
  for(i=0;i<256;i++)
    {
      x = (i % 80);
      y = (i / 80)*maplen*2;
      vga1_drawtext(x,y,&chbuf[i*maplen]);
    }
  vga1_getch();
}

displayChinese()
{
  int i,x,y;
  char buf[32];

  if (headlen)
    fseek(infile,headlen,SEEK_SET);
  fseek(infile,offset*maplen*2,SEEK_CUR);
  fread(chbuf,maplen*2,500,infile);
  for(i=0;i<500;i++)
    {
      x = (i % 40)*2;
      y = (i / 40)*maplen+1;
      memset(buf,0,32);
      memcpy(buf,&chbuf[i*maplen*2],maplen*2);
      vga1_drawctext(x,y,buf);
    }
  vga1_getch();
}
main(int argc,char **argv)
{

  headlen = offset = isch = 0;
  sys_config.ttyfd=0;
  headlen = offset = 0;
  while(argv[1][0] == '-')
    {
      switch(argv[1][1])
	{
	case 's':
	  headlen = atoi(argv[1]+2);
	  break;
	case 'l':
	  offset = atoi(argv[1]+2);
	  break;
	case 'd':
	  isch = 1;
	  break;
	case 'm':
	  maplen = atoi(argv[1]+2);
	  break;
	default:
	  printf("Error arg %s",argv[1]);
	}
      argv++;
      argc--;
    }
  if (argc < 2)
    {
      printf("Usage : displayfont [-s <offset>] [-l <offset>] [-m <len>] [-d] <file>\n");
      exit(1);
    }
  
  infile = fopen(argv[1],"r");
  if (infile == NULL)
    {
      printf("Can't open %s\n",argv[1]);
      exit(1);
    }
  printf("Load font %s Head length= %d offset is %d\n",argv[1],headlen,offset);
  printf("FONT SIZE is %d ",maplen);
  if (isch)
    printf("STYLE is Chinese\n");
  else
    printf("STYLE is English\n");
  vga1_setmode(G640x480x16);
  vga1_setcolor(15);
  if (isch)
    displayChinese();
  else
    displayEnglish();
  fclose(infile);
  getc(stdin);
  vga1_setmode(TEXT);
}