gpftobdf.c 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /* $XConsortium: gpftobdf.c /main/5 1996/11/08 02:04:24 cde-fuj $ */
  24. /*
  25. * (c) Copyright 1995 FUJITSU LIMITED
  26. * This is source code modified by FUJITSU LIMITED under the Joint
  27. * Development Agreement for the CDEnext PST.
  28. * This is unpublished proprietary source code of FUJITSU LIMITED
  29. */
  30. #include <stdio.h>
  31. #include <sys/types.h>
  32. #include <sys/stat.h>
  33. #include <string.h>
  34. #include <fcntl.h>
  35. #include <stdlib.h>
  36. #include <unistd.h>
  37. #include <X11/fonts/font.h>
  38. #include <X11/X.h>
  39. #include <X11/Xproto.h>
  40. #include <X11/Xmd.h>
  41. #include <X11/Intrinsic.h>
  42. #include <ctype.h>
  43. #include <errno.h>
  44. #include <X11/fonts/fontstruct.h>
  45. #include "snfstruct.h"
  46. #include <time.h>
  47. #include "bdftosnf.h"
  48. #include <memory.h>
  49. #if defined( SVR4 )
  50. #include <sys/mman.h>
  51. #endif
  52. #include "udccom.h"
  53. #include "udcutil.h"
  54. #define GLYPHPADOPTIONS 4
  55. #define SIZEOF_COMPRESSED_METRIC 5
  56. #include "gtobdf.h"
  57. #include "pcf.h"
  58. typedef struct pcf_tmp {
  59. FontInfoRec info;
  60. int ntables;
  61. PCFTablePtr tables;
  62. int nprops;
  63. FontPropPtr props;
  64. char *isStringProp;
  65. int str_length;
  66. char *string;
  67. int nbitmaps;
  68. CARD32 bmp_fmt; /* bitOrder ,byteOrder, glyph, scan */
  69. CARD32 *offsets;
  70. int sizebitmaps;
  71. char *bitmaps;
  72. CARD32 enc_fmt;
  73. CARD16 *encodingOffsets;
  74. size_t pcf_bufsz;
  75. caddr_t pcf_buffer;
  76. /* scale width */
  77. CARD32 swd_fmt ;
  78. int swd_num ;
  79. CARD32 *swidth ;
  80. /* glyph name */
  81. CARD32 glyph_fmt ;
  82. unsigned int glyphs ;
  83. int *glyph_offset ;
  84. char *glyph_name ;
  85. /* metrics */
  86. int compress ;
  87. CARD32 mtr_fmt ;
  88. int mtr_num ;
  89. xCharInfo *metrics;
  90. } PcfTmp;
  91. typedef struct prop_tmp {
  92. char *font_name;
  93. FontPropRec psize;
  94. FontPropRec resolution;
  95. } PropTmp;
  96. static char *readfontfile(char *fname);
  97. static void Anafprop(FontInfoRec *fip,
  98. FontPropRec *fpropPtr,
  99. char *fpropvnPtr,
  100. char **fontname,
  101. FontPropRec **fplistPtr,
  102. FontPropRec *ps,
  103. FontPropRec *res,
  104. unsigned int *fplistNum);
  105. static void pSIZE(FontPropRec *ps, FontPropRec *res);
  106. static void pPROPS(FontInfoRec *fip,
  107. FontPropRec *fplistPtr,
  108. unsigned int fplistNum);
  109. static void pCHARS(FontInfoRec *fip,
  110. CharInfoRec *cip,
  111. char *glyphPtr,
  112. unsigned int charNum,
  113. unsigned int glyphPad);
  114. static void pfixCHARS(FontInfoRec *fip,
  115. CharInfoRec *cip,
  116. char *glyphPtr,
  117. unsigned int charNum,
  118. unsigned int glyphPad);
  119. static int getarg(int argc,
  120. char *argv[],
  121. char *fname,
  122. int *bitorder,
  123. int *byteorder,
  124. int *scanunit,
  125. int *glyphPad,
  126. int *outLevel,
  127. int *fix);
  128. static Bool seekToType(PCFTablePtr tables,
  129. int ntables,
  130. CARD32 type,
  131. CARD32 *formatp,
  132. CARD32 *sizep,
  133. CARD32 *offsetp);
  134. static void getMetric(caddr_t buf, CARD32 format, xCharInfo *metric) ;
  135. static Bool getAccel(FontInfoPtr pFontInfo,
  136. xCharInfo *maxink,
  137. caddr_t buf_top,
  138. PCFTablePtr tables,
  139. int ntables,
  140. CARD32 type);
  141. static Bool getProperties(PcfTmp *pcf,
  142. caddr_t buf_top,
  143. PCFTablePtr tables,
  144. int ntables);
  145. static void putPtn(unsigned char *bits, int width, int height);
  146. static void ByteSwap(char *p, int scan);
  147. static void invertBits(char *src,
  148. CARD32 format,
  149. int width,
  150. int height,
  151. char *dest) ;
  152. static int getINT16(unsigned char *p, CARD32 format);
  153. static int getINT32(unsigned char *p, CARD32 format);
  154. static CARD32 getLSB32(unsigned char *p);
  155. static char *make_toptn(int width, int height);
  156. static void pSIZE_pcf(PropTmp *proptmp);
  157. static PcfTmp *openPcfFont(char *fontname);
  158. static void setProp(PcfTmp *pcf, PropTmp *proptmp);
  159. static void pPROPS_pcf(PcfTmp *pcf);
  160. static void pCHARS_pcf(PcfTmp *pcf, int fix);
  161. static void BitOrderInvert(unsigned char *buf, int nbytes);
  162. static char *bufp,buf[2048];
  163. extern int ChkPcfFontFile(char *filename);
  164. int main( int argc, char *argv[] )
  165. {
  166. int i,k;
  167. char *fp; /* font */
  168. FontInfoRec *fip; /* font information */
  169. CharInfoRec *cip, *wkcip; /* character information */
  170. unsigned int glyphstotal; /* glyph */
  171. unsigned int charInfoNum ; /* character information's number */
  172. unsigned int charNum; /* define character number */
  173. char *glyphPtr; /* glyph */
  174. FontPropRec *fpropPtr,*fplistPtr; /* font property list */
  175. FontPropRec psprop; /* point size property */
  176. FontPropRec resprop; /* resolution property */
  177. char *fpropvnPtr;
  178. unsigned int fplistNum; /* font property number */
  179. char *fontname; /* fontname */
  180. time_t clock;
  181. struct tm *tm;
  182. char tmbuf[80] ;
  183. char fname[1024]; /* snf filename */
  184. int bitorder; /* bitorder */
  185. int byteorder; /* byteorder */
  186. int scanunit; /* scanunit */
  187. int glyphPad ; /* glyph */
  188. int outLevel; /* output information level */
  189. int fix;
  190. int isPcf;
  191. PcfTmp *pcf;
  192. PropTmp proptmp;
  193. char *tmpfname;
  194. extern char *GetRealFileName();
  195. if (getarg(argc,argv,fname,&bitorder,&byteorder,&scanunit,&glyphPad,
  196. &outLevel,&fix) != 0) {
  197. exit( -1 );
  198. }
  199. /*
  200. * read to fontfile
  201. */
  202. if ( ( tmpfname = GetRealFileName( fname ) ) == NULL ) {
  203. USAGE("dtgpftobdf: cannot refer to substance file.\n" );
  204. exit( -1 );
  205. }
  206. if ( strcmp( tmpfname, fname ) != 0 ){
  207. strcpy( fname, tmpfname );
  208. }
  209. if ( ChkPcfFontFile( fname ) == 0 ){
  210. /* pcf font */
  211. isPcf = 1;
  212. if ( !( pcf = openPcfFont( fname ) ) ) {
  213. USAGE("dtgpftobdf: cannot open font\n" );
  214. exit( -1 );
  215. }
  216. } else {
  217. /* snf font */
  218. isPcf = 0;
  219. if ( ( fp = readfontfile( fname ) ) == (char *)-1 ) {
  220. exit( -1 );
  221. }
  222. }
  223. if ( !isPcf ) {
  224. /* SNF format */
  225. COMM_SNF_GETHEADER( fip, fp ) ;
  226. cip = (CharInfoRec *)((char *)fip + sizeof(FontInfoRec));
  227. charInfoNum = (fip->lastCol - fip->firstCol + 1)
  228. *(fip->lastRow - fip->firstRow + 1);
  229. glyphPtr = ((char *)cip) + ( charInfoNum * sizeof(CharInfoRec) );
  230. charNum = charInfoNum ;
  231. wkcip = cip ;
  232. glyphPad = (((fip->maxbounds.rightSideBearing
  233. - fip->maxbounds.leftSideBearing)+31)/32)*4;
  234. if ( fix == TRUE ) {
  235. for ( i = 0; i < charInfoNum; i++ ) {
  236. wkcip++;
  237. }
  238. } else {
  239. glyphstotal = 0 ;
  240. for ( i = 0; i < charInfoNum; i++ ) {
  241. glyphstotal += (wkcip->metrics.ascent
  242. + wkcip->metrics.descent) * glyphPad;
  243. wkcip++;
  244. }
  245. }
  246. fpropPtr = (FontPropRec *)(glyphPtr + glyphstotal);
  247. fpropvnPtr = ((char *)fpropPtr) + (fip->nprops) * sizeof(FontPropRec);
  248. }
  249. if ( isPcf ) {
  250. setProp( pcf, &proptmp );
  251. } else {
  252. fontname = (char *)0;
  253. Anafprop(
  254. fip, fpropPtr,
  255. fpropvnPtr, &fontname,
  256. &fplistPtr,
  257. &psprop, &resprop,
  258. &fplistNum
  259. );
  260. }
  261. /*
  262. *¡¡output to BDF information
  263. */
  264. bufp = buf;
  265. memcpy(bufp,"STARTFONT 2.1\n",14);
  266. bufp += 14;
  267. memcpy(bufp,"COMMENT\n",8);
  268. bufp += 8;
  269. memcpy(bufp,"COMMENT This BDF was created by dtgpftobdf.\n",45 );
  270. bufp += 45 ;
  271. memcpy(bufp,"COMMENT\n",8);
  272. bufp += 8;
  273. time(&clock);
  274. tm = localtime(&clock);
  275. snprintf( tmbuf, sizeof(tmbuf), "%s", asctime(tm) ) ;
  276. k = sprintf(bufp,"COMMENT Created date : %s\n",tmbuf );
  277. bufp += k-1;
  278. memcpy(bufp,"COMMENT\n",8);
  279. bufp += 8;
  280. if ( isPcf ) {
  281. k = sprintf(bufp,"FONT %s\n",proptmp.font_name);
  282. bufp += k;
  283. *bufp = '\0';
  284. fprintf( stdout,"%s",buf );
  285. pSIZE_pcf( &proptmp );
  286. fprintf( stdout,"FONTBOUNDINGBOX %d %d %d %d\n",
  287. pcf->info.maxbounds.rightSideBearing
  288. - pcf->info.maxbounds.leftSideBearing,
  289. pcf->info.maxbounds.ascent
  290. + pcf->info.maxbounds.descent,
  291. pcf->info.maxbounds.leftSideBearing,
  292. - ( pcf->info.maxbounds.descent )
  293. );
  294. pPROPS_pcf( pcf );
  295. if ( outLevel == FALSE ) {
  296. pCHARS_pcf( pcf, fix );
  297. }
  298. } else {
  299. k = sprintf( bufp,"FONT %s\n",fontname );
  300. bufp += k;
  301. *bufp = '\0';
  302. fprintf( stdout,"%s",buf );
  303. pSIZE( &psprop, &resprop );
  304. fprintf( stdout,"FONTBOUNDINGBOX %d %d %d %d\n",
  305. cip->metrics.rightSideBearing
  306. - cip->metrics.leftSideBearing,
  307. cip->metrics.ascent + cip->metrics.descent,
  308. cip->metrics.leftSideBearing,
  309. -(cip->metrics.descent)
  310. );
  311. pPROPS( fip,fplistPtr,fplistNum );
  312. if ( outLevel == FALSE ) {
  313. if ( fix == TRUE ) {
  314. pfixCHARS( fip,cip,glyphPtr,charNum, glyphPad );
  315. } else {
  316. pCHARS(fip,cip,glyphPtr,charNum,glyphPad);
  317. }
  318. }
  319. }
  320. fprintf( stdout,"ENDFONT\n" );
  321. exit( 0 );
  322. }
  323. /*
  324. * read to font file
  325. */
  326. static char *readfontfile( char *fname )
  327. {
  328. int fd;
  329. char *fp = NULL;
  330. struct stat stat;
  331. fd = open( fname,O_RDONLY );
  332. if ( fd < 0 ) {
  333. USAGE("dtgpftobdf: can't open file.\n" );
  334. return ( char * )-1;
  335. }
  336. #if defined( SVR4 )
  337. if ( fstat( fd,&stat ) == 0 ) {
  338. fp = (char *)mmap( 0, stat.st_size, PROT_READ, MAP_SHARED, fd, 0 );
  339. if ( fp == (char *)-1 ) {
  340. if ( ( fp = ( char * )malloc( stat.st_size ) ) == NULL ) {
  341. USAGE("dtgpftobdf: malloc error.\n" );
  342. close( fd );
  343. return ( char * )-1;
  344. }
  345. /* if ( read( fd, fp, stat.st_size ) < 0 ) {*/
  346. if ( read( fd, fp, stat.st_size ) != stat.st_size ) {
  347. USAGE("dtgpftobdf: can't read file.\n" );
  348. close( fd );
  349. return ( char * )-1;
  350. }
  351. }
  352. } else {
  353. USAGE("dtgpftobdf: can't read file\n" );
  354. close( fd );
  355. return ( char * )-1;
  356. }
  357. close( fd );
  358. #else /* pfa */
  359. if ( fstat(fd,&stat) == 0 ) {
  360. if ( ( fp = (char *)malloc(stat.st_size) ) == NULL ) {
  361. USAGE("dtgpftobdf: malloc error.\n" );
  362. close( fd );
  363. return ( char * )-1;
  364. }
  365. if ( read( fd, fp, stat.st_size ) < 0 ) {
  366. USAGE("dtgpftobdf: can't read file.\n" );
  367. close( fd );
  368. free(fp);
  369. return ( char * )-1;
  370. }
  371. } else {
  372. USAGE("dtgpftobdf: can't read file\n" );
  373. close( fd );
  374. return ( char * )-1;
  375. }
  376. close( fd );
  377. #endif /* pfa */
  378. return fp;
  379. }
  380. #define getINT8( p ) ( *p++ ) ;
  381. static CARD32
  382. getLSB32( unsigned char *p )
  383. {
  384. CARD32 c;
  385. c = *p++;
  386. c |= (CARD32)(*p++) << 8;
  387. c |= (CARD32)(*p++) << 16;
  388. c |= (CARD32)(*p) << 24;
  389. return c;
  390. }
  391. static int
  392. getINT32( unsigned char *p, CARD32 format )
  393. {
  394. CARD32 c;
  395. if ( PCF_BYTE_ORDER(format) == MSBFirst ) {
  396. c = (CARD32)(*p++) << 24;
  397. c |= (CARD32)(*p++) << 16;
  398. c |= (CARD32)(*p++) << 8;
  399. c |= (CARD32)(*p);
  400. } else {
  401. c = (CARD32)(*p++);
  402. c |= (CARD32)(*p++) << 8;
  403. c |= (CARD32)(*p++) << 16;
  404. c |= (CARD32)(*p) << 24;
  405. }
  406. return ( int )c;
  407. }
  408. static int
  409. getINT16( unsigned char *p, CARD32 format )
  410. {
  411. CARD32 c;
  412. if ( PCF_BYTE_ORDER(format) == MSBFirst ) {
  413. c = (CARD32)(*p++) << 8;
  414. c |= (CARD32)(*p);
  415. } else {
  416. c = (CARD32)(*p++);
  417. c |= (CARD32)(*p) << 8;
  418. }
  419. return ( int )c;
  420. }
  421. static Bool
  422. seekToType(
  423. PCFTablePtr tables,
  424. int ntables,
  425. CARD32 type,
  426. CARD32 *formatp,
  427. CARD32 *sizep,
  428. CARD32 *offsetp)
  429. {
  430. int i;
  431. for ( i = 0; i < ntables; i++ ) {
  432. if ( getLSB32( (unsigned char *)&tables[i].type) == type) {
  433. *formatp = getLSB32( (unsigned char *)&tables[i].format);
  434. *sizep = getLSB32( (unsigned char *)&tables[i].size);
  435. *offsetp = getLSB32( (unsigned char *)&tables[i].offset);
  436. return TRUE;
  437. }
  438. }
  439. return FALSE;
  440. }
  441. static void
  442. getMetric( caddr_t buf, CARD32 format, xCharInfo *metric)
  443. {
  444. metric->leftSideBearing = getINT16( (unsigned char *)buf, format);
  445. buf += 2;
  446. metric->rightSideBearing = getINT16( (unsigned char *)buf, format);
  447. buf += 2;
  448. metric->characterWidth = getINT16( (unsigned char *)buf, format);
  449. buf += 2;
  450. metric->ascent = getINT16( (unsigned char *)buf, format);
  451. buf += 2;
  452. metric->descent = getINT16( (unsigned char *)buf, format);
  453. buf += 2;
  454. metric->attributes = getINT16( (unsigned char *)buf, format);
  455. buf += 2;
  456. }
  457. static Bool
  458. getAccel(
  459. FontInfoPtr pFontInfo,
  460. xCharInfo *maxink,
  461. caddr_t buf_top,
  462. PCFTablePtr tables,
  463. int ntables,
  464. CARD32 type)
  465. {
  466. CARD32 format;
  467. CARD32 size;
  468. CARD32 offset;
  469. caddr_t buffer;
  470. if ( !seekToType( tables, ntables, type, &format, &size, &offset)) {
  471. return FALSE;
  472. }
  473. buffer = buf_top + offset;
  474. format = getLSB32( (unsigned char *)buffer);
  475. buffer += 4;
  476. if ( !PCF_FORMAT_MATCH( format, PCF_DEFAULT_FORMAT )
  477. && !PCF_FORMAT_MATCH( format, PCF_ACCEL_W_INKBOUNDS )
  478. ) {
  479. return FALSE;
  480. }
  481. pFontInfo->noOverlap = *buffer++;
  482. pFontInfo->constantMetrics = *buffer++;
  483. pFontInfo->terminalFont = *buffer++;
  484. pFontInfo->constantWidth = *buffer++;
  485. pFontInfo->inkInside = *buffer++;
  486. pFontInfo->inkMetrics = *buffer++;
  487. pFontInfo->drawDirection = *buffer++;
  488. /* natural alignment */
  489. buffer++;
  490. pFontInfo->fontAscent = getINT32( (unsigned char *)buffer, format);
  491. buffer += 4;
  492. pFontInfo->fontDescent = getINT32((unsigned char *)buffer, format);
  493. buffer +=4;
  494. buffer += 4;
  495. getMetric(buffer, format, &pFontInfo->minbounds);
  496. buffer += 12;
  497. getMetric(buffer, format, &pFontInfo->maxbounds);
  498. buffer += 12;
  499. if ( PCF_FORMAT_MATCH( format, PCF_ACCEL_W_INKBOUNDS ) ) {
  500. buffer += 12;
  501. getMetric( buffer, format, maxink);
  502. } else {
  503. *maxink = pFontInfo->maxbounds;
  504. }
  505. return TRUE;
  506. }
  507. static Bool
  508. getProperties(PcfTmp *pcf, caddr_t buf_top, PCFTablePtr tables, int ntables)
  509. {
  510. CARD32 format;
  511. CARD32 size;
  512. CARD32 offset;
  513. caddr_t buffer;
  514. int i;
  515. if ( !seekToType( tables, ntables, (CARD32)PCF_PROPERTIES, &format, &size, &offset ) ) {
  516. return FALSE;
  517. }
  518. buffer = buf_top + offset;
  519. format = getLSB32( (unsigned char *)buffer );
  520. buffer += 4;
  521. if ( !PCF_FORMAT_MATCH( format, PCF_DEFAULT_FORMAT ) ) {
  522. return FALSE;
  523. }
  524. pcf->nprops = getINT32((unsigned char *)buffer, format);
  525. buffer += 4;
  526. if ( !( pcf->props = ( FontPropPtr )malloc( pcf->nprops * sizeof( FontPropRec ) ) ) ) {
  527. return FALSE;
  528. }
  529. if ( !( pcf->isStringProp = ( char * )malloc(pcf->nprops * sizeof( char ) ) ) ) {
  530. return FALSE;
  531. }
  532. for ( i = 0; i < pcf->nprops; i++ ) {
  533. pcf->props[i].name = getINT32((unsigned char *)buffer, format);
  534. buffer += 4;
  535. pcf->isStringProp[i] = *buffer++;
  536. pcf->props[i].value = getINT32((unsigned char *)buffer, format);
  537. buffer += 4;
  538. }
  539. if ( pcf->nprops & 3 ) {
  540. i = 4 - (pcf->nprops & 3);
  541. buffer += i;
  542. }
  543. pcf->str_length = getINT32((unsigned char *)buffer, format);
  544. buffer += 4;
  545. pcf->string = (char *)buffer;
  546. return TRUE;
  547. }
  548. static PcfTmp *
  549. openPcfFont(char *fontname)
  550. {
  551. PcfTmp *pcf_tmp;
  552. CARD32 format;
  553. CARD32 size;
  554. CARD32 offset;
  555. CARD32 *bitmapSizes;
  556. xCharInfo maxink;
  557. caddr_t buffp;
  558. struct stat st;
  559. pcf_tmp = ( PcfTmp * )calloc( 1, sizeof( PcfTmp ) );
  560. while(1){
  561. if ( !pcf_tmp ) {
  562. USAGE("dtgpftobdf : calloc() error.\n" ) ;
  563. break;
  564. }
  565. if ( stat( fontname, &st ) ) {
  566. break;
  567. }
  568. if ( ( pcf_tmp->pcf_buffer = readfontfile( fontname)) == (char *)-1 ) {
  569. break;
  570. }
  571. pcf_tmp->pcf_bufsz = st.st_size;
  572. if ( (format = getLSB32( (unsigned char *)pcf_tmp->pcf_buffer )) != PCF_FILE_VERSION ) {
  573. USAGE1("dtgpftobdf : pcf file version(0x%x) error.\n", format ) ;
  574. break;
  575. }
  576. pcf_tmp->ntables = getLSB32( (unsigned char *)(pcf_tmp->pcf_buffer + 4) );
  577. pcf_tmp->tables = (PCFTablePtr)(pcf_tmp->pcf_buffer + 8 );
  578. if ( !getAccel(
  579. &pcf_tmp->info, &maxink, pcf_tmp->pcf_buffer,
  580. pcf_tmp->tables, pcf_tmp->ntables, (CARD32)PCF_BDF_ACCELERATORS
  581. )
  582. ) {
  583. if ( !getAccel(
  584. &pcf_tmp->info, &maxink, pcf_tmp->pcf_buffer,
  585. pcf_tmp->tables, pcf_tmp->ntables, (CARD32)PCF_ACCELERATORS
  586. )
  587. ) {
  588. USAGE("dtgpftobdf : Cannot get accelerators.\n" ) ;
  589. break;
  590. }
  591. }
  592. if ( !getProperties(
  593. pcf_tmp, pcf_tmp->pcf_buffer,
  594. pcf_tmp->tables, pcf_tmp->ntables
  595. )
  596. ) {
  597. USAGE("dtgpftobdf : getProperties error.\n" ) ;
  598. break;
  599. }
  600. if ( !seekToType(
  601. pcf_tmp->tables, pcf_tmp->ntables,
  602. (CARD32)PCF_BITMAPS, &format, &size, &offset
  603. )
  604. ) {
  605. USAGE("dtgpftobdf : PCF_BITMAPS error.\n" ) ;
  606. break;
  607. }
  608. buffp = pcf_tmp->pcf_buffer + offset;
  609. format = getLSB32( (unsigned char *)buffp);
  610. buffp += 4;
  611. if ( !PCF_FORMAT_MATCH( format, PCF_DEFAULT_FORMAT ) ) {
  612. USAGE("dtgpftobdf : error.!PCF_FORMAT_MATCH(PCF_BITMAPS)\n" ) ;
  613. break;
  614. }
  615. pcf_tmp->nbitmaps = getINT32( (unsigned char *)buffp, format);
  616. buffp += 4;
  617. pcf_tmp->offsets = (CARD32 *)buffp;
  618. buffp += sizeof( *pcf_tmp->offsets) * pcf_tmp->nbitmaps;
  619. bitmapSizes = (CARD32 *)buffp;
  620. pcf_tmp->sizebitmaps
  621. = getINT32( (unsigned char *)&bitmapSizes[PCF_GLYPH_PAD_INDEX(format)], format);
  622. pcf_tmp->bmp_fmt = format;
  623. buffp += sizeof( *bitmapSizes) * GLYPHPADOPTIONS;
  624. pcf_tmp->bitmaps = buffp;
  625. buffp += pcf_tmp->sizebitmaps;
  626. if ( !seekToType(
  627. pcf_tmp->tables, pcf_tmp->ntables,
  628. (CARD32)PCF_BDF_ENCODINGS, &format, &size, &offset
  629. )
  630. ) {
  631. USAGE("dtgpftobdf : error.(PCF_BDF_ENCODINGS)\n" ) ;
  632. break;
  633. }
  634. buffp = pcf_tmp->pcf_buffer + offset;
  635. format = getLSB32( (unsigned char *)buffp);
  636. buffp += 4;
  637. if ( !PCF_FORMAT_MATCH( format, PCF_DEFAULT_FORMAT ) ) {
  638. USAGE("dtgpftobdf : error.!PCF_FORMAT_MATCH(PCF_BDF_ENCODINGS)\n" ) ;
  639. break;
  640. }
  641. pcf_tmp->info.firstCol = getINT16( (unsigned char *)buffp, format);
  642. buffp += 2;
  643. pcf_tmp->info.lastCol = getINT16( (unsigned char *)buffp, format);
  644. buffp += 2;
  645. pcf_tmp->info.firstRow = getINT16( (unsigned char *)buffp, format);
  646. buffp += 2;
  647. pcf_tmp->info.lastRow = getINT16( (unsigned char *)buffp, format);
  648. buffp += 2;
  649. pcf_tmp->info.defaultCh = getINT16( (unsigned char *)buffp, format);
  650. buffp += 2;
  651. pcf_tmp->info.allExist = FALSE;
  652. pcf_tmp->enc_fmt = format;
  653. pcf_tmp->encodingOffsets = (CARD16 *)buffp;
  654. /*
  655. * get scale width infomations
  656. */
  657. if ( !seekToType(
  658. pcf_tmp->tables, pcf_tmp->ntables,
  659. (CARD32)PCF_SWIDTHS, &format, &size, &offset
  660. )
  661. ) {
  662. break;
  663. }
  664. buffp = pcf_tmp->pcf_buffer + offset;
  665. format = getLSB32( (unsigned char*)buffp);
  666. buffp += 4;
  667. if ( !PCF_FORMAT_MATCH( format, PCF_DEFAULT_FORMAT ) ) {
  668. break;
  669. }
  670. pcf_tmp->swd_fmt = (CARD32)format ;
  671. pcf_tmp->swd_num = getINT32( (unsigned char*)buffp, format ) ;
  672. buffp += 4;
  673. pcf_tmp->swidth = (CARD32 *)buffp ;
  674. /*
  675. * get glyph names
  676. */
  677. if ( !seekToType(
  678. pcf_tmp->tables, pcf_tmp->ntables,
  679. (CARD32)PCF_GLYPH_NAMES, &format, &size, &offset
  680. )
  681. ) {
  682. break;
  683. }
  684. buffp = pcf_tmp->pcf_buffer + offset;
  685. format = getLSB32( (unsigned char*)buffp);
  686. buffp += 4;
  687. if ( !PCF_FORMAT_MATCH( format, PCF_DEFAULT_FORMAT ) ) {
  688. break;
  689. }
  690. pcf_tmp->glyphs = getINT32( (unsigned char*)buffp, format ) ;
  691. buffp += 4;
  692. pcf_tmp->glyph_offset = (int *)buffp ;
  693. buffp += 4 * (pcf_tmp->glyphs + 1) ;
  694. pcf_tmp->glyph_name = (char *)buffp ;
  695. pcf_tmp->glyph_fmt = (CARD32)format ;
  696. /*
  697. * get metrics
  698. */
  699. if ( !seekToType(
  700. pcf_tmp->tables, pcf_tmp->ntables,
  701. (CARD32)PCF_METRICS, &format, &size, &offset
  702. )
  703. ) {
  704. break;
  705. }
  706. buffp = pcf_tmp->pcf_buffer + offset;
  707. format = getLSB32( (unsigned char*)buffp);
  708. buffp += 4;
  709. if ( PCF_FORMAT_MATCH( format, PCF_DEFAULT_FORMAT ) ) {
  710. pcf_tmp->compress = 0 ;
  711. pcf_tmp->mtr_num = getINT32( (unsigned char*)buffp, format ) ;
  712. buffp += 4;
  713. }else if ( PCF_FORMAT_MATCH( format, PCF_COMPRESSED_METRICS ) ) {
  714. pcf_tmp->compress = 1 ;
  715. pcf_tmp->mtr_num = (int)getINT16( (unsigned char*)buffp, format ) ;
  716. buffp += 2;
  717. }else{
  718. break;
  719. }
  720. pcf_tmp->metrics = (xCharInfo *)buffp ;
  721. pcf_tmp->mtr_fmt = (CARD32)format ;
  722. return pcf_tmp;
  723. }
  724. if ( pcf_tmp ) {
  725. free( pcf_tmp );
  726. }
  727. return NULL;
  728. }
  729. static void
  730. Anafprop(
  731. FontInfoRec *fip,
  732. FontPropRec *fpropPtr,
  733. char *fpropvnPtr,
  734. char **fontname,
  735. FontPropRec **fplistPtr,
  736. FontPropRec *ps,
  737. FontPropRec *res,
  738. unsigned int *fplistNum)
  739. {
  740. FontPropRec *wkp ,*wklp;
  741. int i, fpnL;
  742. char *fpnp;
  743. *fplistNum = fip->nprops - 1;
  744. *fplistPtr = (FontPropRec *)malloc(*fplistNum * sizeof(FontPropRec));
  745. wkp = fpropPtr;
  746. wklp = *fplistPtr;
  747. for (i = 0; i < fip->nprops; i++) {
  748. fpnp = fpropvnPtr + wkp->name;
  749. fpnL = strlen(fpnp);
  750. if ((fpnL == 4) && (strncmp(fpnp,"FONT",4) == 0)) {
  751. *fontname = fpropvnPtr + wkp->value;
  752. wkp++;
  753. continue;
  754. }
  755. if (fpnL == 10) {
  756. if (strncmp(fpnp,"POINT_SIZE",10) == 0) {
  757. ps->value = wkp->value;
  758. }
  759. if (strncmp(fpnp,"RESOLUTION",10) == 0) {
  760. res->value = wkp->value;
  761. }
  762. }
  763. wklp->name = (CARD32) (intptr_t) fpropvnPtr + wkp->name;
  764. wklp->value = wkp->value;
  765. wkp++;
  766. wklp++;
  767. }
  768. }
  769. static void
  770. setProp( PcfTmp *pcf, PropTmp *proptmp )
  771. {
  772. int i, fpnL;
  773. char *fpnp;
  774. for ( i = 0; i < pcf->nprops; i++ ) {
  775. fpnp = pcf->string + pcf->props[i].name;
  776. fpnL = strlen(fpnp);
  777. if ( ( fpnL == 4 ) && ( strncmp( fpnp,"FONT", 4 ) == 0 ) ) {
  778. proptmp->font_name = pcf->string + pcf->props[i].value;
  779. continue;
  780. }
  781. if ( fpnL == 10 ) {
  782. if ( strncmp( fpnp,"POINT_SIZE", 10 ) == 0 ) {
  783. proptmp->psize.value = pcf->props[i].value;
  784. } else if ( strncmp( fpnp, "RESOLUTION", 10 ) == 0 ) {
  785. proptmp->resolution.value = pcf->props[i].value;
  786. }
  787. }
  788. }
  789. }
  790. /*
  791. * output to SIZE (SIZE point resolutionX resolutionY)
  792. *
  793. */
  794. static void
  795. pSIZE( FontPropRec *ps, FontPropRec *res )
  796. {
  797. int k;
  798. float f;
  799. char buf1[16], buf2[16];
  800. f = ps->value / 10.0;
  801. if ( ( ps->value % 10 ) != 0 ) {
  802. sprintf( buf1, "%.1f", f );
  803. } else {
  804. sprintf( buf1, "%.0f", f );
  805. }
  806. k = ( ( res->value * 72.27 ) / 100.0 ) + 1;
  807. sprintf( buf2, "%d %d", k, k );
  808. fprintf( stdout, "SIZE %s %s\n", buf1, buf2 );
  809. return;
  810. }
  811. /* output to SIZE of pcf font */
  812. static void
  813. pSIZE_pcf( PropTmp *proptmp )
  814. {
  815. int k;
  816. float f;
  817. char buf1[16],buf2[16];
  818. f = proptmp->psize.value / 10.0;
  819. if ( ( proptmp->psize.value % 10 ) != 0 ) {
  820. snprintf( buf1, sizeof(buf1), "%.1f",f );
  821. } else {
  822. snprintf( buf1, sizeof(buf1), "%.0f",f);
  823. }
  824. k = ( ( proptmp->resolution.value * 72.27 ) / 100.0 ) + 1;
  825. snprintf( buf2, sizeof(buf2), "%d %d", k, k );
  826. fprintf( stdout,"SIZE %s %s\n", buf1, buf2 );
  827. return;
  828. }
  829. static void
  830. pPROPS( FontInfoRec *fip, FontPropRec *fplistPtr, unsigned int fplistNum )
  831. {
  832. FontPropRec *wkp;
  833. int i, k;
  834. bufp = buf;
  835. k = snprintf( bufp, sizeof(buf), "STARTPROPERTIES %d\n", fplistNum+3 );
  836. bufp += k;
  837. k = snprintf( bufp, sizeof(buf) - (bufp - buf), "FONT_ASCENT %d\n", fip->fontAscent );
  838. bufp += k;
  839. k = snprintf( bufp, sizeof(buf) - (bufp - buf), "FONT_DESCENT %d\n", fip->fontDescent );
  840. bufp += k;
  841. k = snprintf( bufp, sizeof(buf) - (bufp - buf), "DEFAULT_CHAR %d\n", fip->defaultCh );
  842. bufp += k;
  843. wkp = fplistPtr;
  844. for ( i = 0; i < fplistNum; i++ ) {
  845. k = snprintf( bufp, sizeof(buf) - (bufp - buf), "%s %ld\n", (char *) (intptr_t) wkp->name, wkp->value );
  846. bufp += k;
  847. wkp++;
  848. }
  849. k = snprintf( bufp, sizeof(buf) - (bufp - buf), "ENDPROPERTIES\n" );
  850. bufp += k;
  851. *bufp = '\0';
  852. fprintf( stdout, "%s", buf );
  853. return;
  854. }
  855. /* output to font property information of pcf fontpcf */
  856. static void
  857. pPROPS_pcf(PcfTmp *pcf)
  858. {
  859. FontPropPtr wkp;
  860. int i, k;
  861. bufp = buf;
  862. k = sprintf( bufp, "STARTPROPERTIES %d\n", pcf->nprops+3 );
  863. bufp += k;
  864. k = sprintf( bufp, "FONT_ASCENT %d\n",
  865. (pcf->info.fontAscent >= pcf->info.maxbounds.ascent)
  866. ? pcf->info.fontAscent : pcf->info.maxbounds.ascent
  867. );
  868. bufp += k;
  869. k = sprintf( bufp, "FONT_DESCENT %d\n",
  870. (pcf->info.fontDescent >= pcf->info.maxbounds.descent)
  871. ? pcf->info.fontDescent : pcf->info.maxbounds.descent
  872. );
  873. bufp += k;
  874. k = sprintf( bufp, "DEFAULT_CHAR %d\n", pcf->info.defaultCh );
  875. bufp += k;
  876. wkp = pcf->props;
  877. for ( i = 0; i < pcf->nprops; i++ ) {
  878. if ( pcf->isStringProp[i] ) {
  879. k = sprintf(bufp,"%s \"%s\"\n",
  880. pcf->string + wkp->name, pcf->string + wkp->value
  881. );
  882. bufp += k;
  883. } else {
  884. k = sprintf(bufp,"%s %ld\n",
  885. pcf->string + wkp->name, wkp->value
  886. );
  887. bufp += k;
  888. }
  889. wkp++;
  890. }
  891. k = sprintf( bufp, "ENDPROPERTIES\n" );
  892. bufp += k;
  893. *bufp = '\0';
  894. fprintf( stdout,"%s",buf );
  895. return;
  896. }
  897. /*
  898. * output to character information and patern
  899. */
  900. static void
  901. pCHARS(
  902. FontInfoRec *fip,
  903. CharInfoRec *cip,
  904. char *glyphPtr,
  905. unsigned int charNum,
  906. unsigned int glyphPad)
  907. {
  908. CharInfoRec *wkp;
  909. int i, j;
  910. unsigned int frow, lrow, row, fcol, lcol, col;
  911. unsigned int bbw, bbh;
  912. unsigned int bml;
  913. char *glyph;
  914. fprintf( stdout, "CHARS %d\n", charNum );
  915. frow = fip->firstRow;
  916. lrow = fip->lastRow;
  917. fcol = fip->firstCol;
  918. lcol = fip->lastCol;
  919. wkp = cip;
  920. glyph = glyphPtr;
  921. row = frow;
  922. for ( i = 0; i < 256; i++ ) {
  923. cvtp[i] = &cvt[i];
  924. }
  925. for ( row = frow; row <= lrow; row++ ) {
  926. for ( col = fcol; col <= lcol; col++ ) {
  927. fprintf( stdout, "STARTCHAR %.2x%.2x\n", row,col );
  928. fprintf( stdout, "ENCODING %d\n", (row << 8) + col );
  929. fprintf( stdout, "SWIDTH 256 0\nDWIDTH %d %d\n",
  930. wkp->metrics.characterWidth,0 );
  931. bbw = wkp->metrics.rightSideBearing
  932. - wkp->metrics.leftSideBearing;
  933. bbh = wkp->metrics.ascent + wkp->metrics.descent;
  934. fprintf( stdout, "BBX %d %d %d %d\nBITMAP\n", bbw, bbh,
  935. wkp->metrics.leftSideBearing,
  936. - ( wkp->metrics.descent ));
  937. bml = (bbw + 7) / 8;
  938. for ( i = 0; i < bbh; i++ ) {
  939. bufp = buf;
  940. for ( j = 0; j < bml; j++ ) {
  941. sprintf( bufp, "%s", (char *) cvtp[(unsigned char)glyph[j]] );
  942. bufp += 2;
  943. }
  944. fprintf( stdout, "%.*s\n", bml*2, buf );
  945. glyph += glyphPad;
  946. }
  947. fprintf( stdout,"ENDCHAR\n" );
  948. wkp++;
  949. }
  950. }
  951. return;
  952. }
  953. /*
  954. * output to character information and patern
  955. */
  956. static void
  957. pfixCHARS(
  958. FontInfoRec *fip,
  959. CharInfoRec *cip,
  960. char *glyphPtr,
  961. unsigned int charNum,
  962. unsigned int glyphPad)
  963. {
  964. CharInfoRec *wkp;
  965. int i, j, k;
  966. unsigned int frow,lrow,fcol,lcol;
  967. int row, col;
  968. unsigned int bbw, bbh, bbox, bboy;
  969. unsigned int xd, yd;
  970. unsigned int bml;
  971. char *glyph;
  972. char fixbuf[240], *fixbufp;
  973. int fixdl;
  974. fprintf( stdout,"CHARS %d\n",charNum );
  975. for ( i = 0; i < 256; i++ ) {
  976. cvtp[i] = &cvt[i];
  977. }
  978. frow = fip->firstRow;
  979. lrow = fip->lastRow;
  980. fcol = fip->firstCol;
  981. lcol = fip->lastCol;
  982. xd = cip->metrics.characterWidth;
  983. yd = 0;
  984. bbw = cip->metrics.rightSideBearing - cip->metrics.leftSideBearing;
  985. bbh = cip->metrics.ascent + cip->metrics.descent;
  986. bbox = cip->metrics.leftSideBearing;
  987. bboy = -(cip->metrics.descent);
  988. fixbufp = fixbuf;
  989. fixdl = sprintf( fixbufp, "SWIDTH 256 0\nDWIDTH %d %d\n", xd, yd );
  990. fixbufp += fixdl;
  991. k = sprintf(fixbufp,"BBX %d %d %d %d\nBITMAP\n",
  992. bbw, bbh, bbox, bboy
  993. );
  994. fixdl += k;
  995. bml = (bbw + 7) / 8;
  996. wkp = cip;
  997. glyph = glyphPtr;
  998. for ( row = frow; row <= lrow; row++ ) {
  999. for ( col = fcol; col <= lcol; col++ ) {
  1000. bufp = buf;
  1001. memcpy(bufp,"STARTCHAR ",10);
  1002. bufp += 10;
  1003. memcpy(bufp,cvtp[row],2);
  1004. bufp += 2;
  1005. memcpy(bufp,cvtp[col],3);
  1006. bufp += 3;
  1007. memcpy(bufp,"ENCODING ",9);
  1008. bufp += 9;
  1009. k = sprintf(bufp,"%d\n",(row << 8) + col);
  1010. bufp += k;
  1011. memcpy(bufp,fixbuf,fixdl);
  1012. bufp += fixdl;
  1013. for (i = 0; i < bbh; i++) {
  1014. for (j = 0; j < bml; j++) {
  1015. memcpy(bufp, cvtp[(unsigned char)glyph[j]],3);
  1016. bufp += 2;
  1017. }
  1018. bufp ++;
  1019. glyph += glyphPad;
  1020. }
  1021. memcpy( bufp, "ENDCHAR\n", 8 );
  1022. bufp += 8;
  1023. *bufp = '\0';
  1024. fprintf( stdout, "%s", buf );
  1025. wkp++;
  1026. }
  1027. }
  1028. return;
  1029. }
  1030. static void
  1031. putPtn(unsigned char *bits, /* 1 byte boundary , no byte swap data */
  1032. int width,
  1033. int height)
  1034. {
  1035. int bytewidth;
  1036. int i, j;
  1037. bytewidth = ( width + 7) / 8;
  1038. for ( i = height; i-- > 0;) {
  1039. for ( j = bytewidth; j-- > 0; bits++) {
  1040. fprintf(stdout, "%.2x", *bits);
  1041. }
  1042. fprintf(stdout, "\n");
  1043. }
  1044. }
  1045. static void
  1046. ByteSwap(char *p, int scan)
  1047. {
  1048. char w;
  1049. switch( scan) {
  1050. case 1:
  1051. break;
  1052. case 2:
  1053. w = *p;
  1054. *p = *(p + 1);
  1055. *(p + 1) = w;
  1056. break;
  1057. case 4:
  1058. w = *p;
  1059. *p = *(p + 3);
  1060. *(p + 3) = w;
  1061. w = *(p + 1);
  1062. *(p + 1) = *(p + 2);
  1063. *(p + 2) = w;
  1064. break;
  1065. }
  1066. }
  1067. static unsigned char _reverse_byte[0x100] = {
  1068. 0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0,
  1069. 0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0,
  1070. 0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8,
  1071. 0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8,
  1072. 0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4,
  1073. 0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4,
  1074. 0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec,
  1075. 0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc,
  1076. 0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2,
  1077. 0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2,
  1078. 0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea,
  1079. 0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa,
  1080. 0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6,
  1081. 0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6,
  1082. 0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee,
  1083. 0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe,
  1084. 0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1,
  1085. 0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1,
  1086. 0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9,
  1087. 0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9,
  1088. 0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5,
  1089. 0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5,
  1090. 0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed,
  1091. 0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd,
  1092. 0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3,
  1093. 0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3,
  1094. 0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb,
  1095. 0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb,
  1096. 0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7,
  1097. 0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7,
  1098. 0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef,
  1099. 0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff
  1100. };
  1101. static void
  1102. BitOrderInvert(unsigned char *buf, int nbytes)
  1103. {
  1104. unsigned char *rev = _reverse_byte;
  1105. for (; --nbytes >= 0; buf++)
  1106. *buf = rev[*buf];
  1107. }
  1108. static void
  1109. invertBits(char *src, CARD32 format, int width, int height, char *dest)
  1110. {
  1111. int bit, byte, glyph, scan;
  1112. int src_bytewidth, dest_bytewidth;
  1113. char work[8];
  1114. int i, j;
  1115. bit = PCF_BIT_ORDER( format);
  1116. byte = PCF_BYTE_ORDER( format);
  1117. glyph = PCF_GLYPH_PAD( format);
  1118. scan = PCF_SCAN_UNIT( format);
  1119. src_bytewidth = (( width + ( 8 * glyph ) - 1)/( 8 * glyph)) * glyph;
  1120. dest_bytewidth = ( width + 7) /8;
  1121. for ( i = 0; i < height; i++, src += src_bytewidth,
  1122. dest += dest_bytewidth) {
  1123. for ( j = 0; j < src_bytewidth; j += scan) {
  1124. memcpy( work, src + j, scan);
  1125. if ( bit == LSBFirst)
  1126. BitOrderInvert( (unsigned char *)work, scan);
  1127. if ( byte == LSBFirst)
  1128. ByteSwap( work, scan);
  1129. if (( j + scan) >= dest_bytewidth) {
  1130. memcpy( dest + j, work, dest_bytewidth - j);
  1131. break;
  1132. }
  1133. memcpy( dest + j, work, scan);
  1134. }
  1135. }
  1136. }
  1137. static void
  1138. pCHARS_pcf (PcfTmp *pcf, int fix)
  1139. {
  1140. char *bmp_ptn = NULL;
  1141. char *bitmap = NULL;
  1142. int ptn_width = 0, ptn_height = 0;
  1143. int bmp_width = 0, bmp_height = 0;
  1144. int cpy_height = 0;
  1145. int row, col;
  1146. int row_width;
  1147. int encoding;
  1148. int encodingOffset;
  1149. int nencoding;
  1150. int bmp_adj = 0, ptn_adj = 0;
  1151. int adj_hi;
  1152. int width_bytes;
  1153. INT16 bl, br, ba, bd, bdw ;
  1154. unsigned char cl, cr, ca, cd, cdw ;
  1155. unsigned char *comp ;
  1156. int bbw, bbh, bbx, bby, dwidth ;
  1157. fprintf(stdout,"CHARS %d\n",pcf->nbitmaps);
  1158. row_width = pcf->info.lastCol - pcf->info.firstCol + 1;
  1159. nencoding = row_width * (pcf->info.lastRow - pcf->info.firstRow + 1);
  1160. if( fix == TRUE ) {
  1161. bmp_width = pcf->info.maxbounds.leftSideBearing
  1162. + pcf->info.maxbounds.rightSideBearing ;
  1163. bmp_height = pcf->info.fontAscent + pcf->info.fontDescent ;
  1164. ptn_width = bmp_width ;
  1165. ptn_height = pcf->info.maxbounds.ascent +
  1166. pcf->info.maxbounds.descent;
  1167. if (!(bmp_ptn = make_toptn( ptn_width, ptn_height)))
  1168. return;
  1169. if ( ( adj_hi = pcf->info.fontAscent - pcf->info.maxbounds.ascent ) > 0) {
  1170. width_bytes = 8 * PCF_GLYPH_PAD( pcf->bmp_fmt);
  1171. width_bytes = (( width_bytes + bmp_width - 1)/width_bytes) * PCF_GLYPH_PAD( pcf->bmp_fmt);
  1172. bmp_adj = width_bytes * adj_hi;
  1173. ptn_adj = 0;
  1174. if (( cpy_height = bmp_height - adj_hi) > ptn_height)
  1175. cpy_height = ptn_height ;
  1176. } else if ( adj_hi < 0) {
  1177. adj_hi *= -1;
  1178. width_bytes = ( ptn_width + 7) / 8;
  1179. bmp_adj = 0;
  1180. ptn_adj = width_bytes * adj_hi;
  1181. if (( cpy_height = ptn_height - adj_hi) > bmp_height)
  1182. cpy_height = bmp_height ;
  1183. } else {
  1184. bmp_adj = 0;
  1185. ptn_adj = 0;
  1186. cpy_height = ptn_height ;
  1187. }
  1188. }
  1189. for ( encoding = 0; encoding < nencoding; encoding++) {
  1190. if(fix == TRUE) memset( bmp_ptn, '\0', (ptn_width + 7)/8 * ptn_height);
  1191. encodingOffset = getINT16( (unsigned char *)(pcf->encodingOffsets + encoding), pcf->enc_fmt);
  1192. if (encodingOffset == 0xFFFF) continue;
  1193. row = pcf->info.firstRow + encoding / row_width;
  1194. col = pcf->info.firstCol + encoding % row_width;
  1195. fprintf(stdout,"STARTCHAR %s\n",pcf->glyph_name +
  1196. getINT32( (unsigned char*)&pcf->glyph_offset[encodingOffset],
  1197. pcf->glyph_fmt) );
  1198. fprintf(stdout,"ENCODING %d\n",(row << 8) + col);
  1199. fprintf( stdout,"SWIDTH %d 0\n", getINT32( (unsigned char*)(pcf->swidth + encodingOffset), pcf->swd_fmt) );
  1200. if( pcf->compress ){
  1201. comp = (unsigned char*)pcf->metrics +
  1202. encodingOffset * SIZEOF_COMPRESSED_METRIC ;
  1203. cl = getINT8( comp ) ;
  1204. cr = getINT8( comp ) ;
  1205. cdw = getINT8( comp ) ;
  1206. ca = getINT8( comp ) ;
  1207. cd = getINT8( comp ) ;
  1208. dwidth = (int)(cdw - 0x80) ;
  1209. bbw = (int)((cr - 0x80) - (cl - 0x80)) ;
  1210. bbh = (int)((ca - 0x80) + (cd - 0x80)) ;
  1211. bbx = (int)(cl - 0x80) ;
  1212. bby = (int)( -(cd - 0x80) ) ;
  1213. }else{
  1214. bl = getINT16( (unsigned char *)&pcf->metrics[encodingOffset].leftSideBearing, pcf->mtr_fmt ) ;
  1215. br = getINT16( (unsigned char *)&pcf->metrics[encodingOffset].rightSideBearing, pcf->mtr_fmt ) ;
  1216. bdw = getINT16( (unsigned char *)&pcf->metrics[encodingOffset].characterWidth, pcf->mtr_fmt ) ;
  1217. ba = getINT16( (unsigned char *)&pcf->metrics[encodingOffset].ascent, pcf->mtr_fmt ) ;
  1218. bd = getINT16( (unsigned char *)&pcf->metrics[encodingOffset].descent, pcf->mtr_fmt ) ;
  1219. dwidth = bdw ;
  1220. bbw = br-bl ;
  1221. bbh = ba+bd ;
  1222. bbx = bl ;
  1223. bby = -bd ;
  1224. }
  1225. fprintf( stdout,"DWIDTH %d 0\n", dwidth ) ;
  1226. fprintf( stdout,"BBX %d %d %d %d\nBITMAP\n", bbw, bbh, bbx, bby ) ;
  1227. if( fix == FALSE ) {
  1228. bmp_width = pcf->info.maxbounds.leftSideBearing
  1229. + pcf->info.maxbounds.rightSideBearing ;
  1230. bmp_height = pcf->info.fontAscent + pcf->info.fontDescent ;
  1231. ptn_width = bbw ;
  1232. ptn_height = bbh ;
  1233. if (!(bmp_ptn = make_toptn( ptn_width, ptn_height)))
  1234. return;
  1235. if ( ( adj_hi = pcf->info.fontAscent - pcf->info.maxbounds.ascent ) > 0) {
  1236. width_bytes = 8 * PCF_GLYPH_PAD( pcf->bmp_fmt);
  1237. width_bytes = (( width_bytes + bmp_width - 1)/width_bytes) * PCF_GLYPH_PAD( pcf->bmp_fmt);
  1238. bmp_adj = width_bytes * adj_hi;
  1239. ptn_adj = 0;
  1240. if (( cpy_height = bmp_height - adj_hi) > ptn_height)
  1241. cpy_height = ptn_height ;
  1242. } else if ( adj_hi < 0) {
  1243. adj_hi *= -1;
  1244. width_bytes = ( ptn_width + 7) / 8;
  1245. bmp_adj = 0;
  1246. ptn_adj = width_bytes * adj_hi;
  1247. if (( cpy_height = ptn_height - adj_hi) > bmp_height)
  1248. cpy_height = bmp_height ;
  1249. } else {
  1250. bmp_adj = 0;
  1251. ptn_adj = 0;
  1252. cpy_height = ptn_height ;
  1253. }
  1254. memset( bmp_ptn, '\0', (ptn_width + 7)/8 * ptn_height);
  1255. }
  1256. bitmap = pcf->bitmaps + getINT32( (unsigned char *)(pcf->offsets + encodingOffset),
  1257. pcf->bmp_fmt);
  1258. /* Only do this if non-NULL... */
  1259. if (bmp_ptn)
  1260. {
  1261. invertBits( bitmap + bmp_adj, pcf->bmp_fmt,
  1262. ptn_width, cpy_height, bmp_ptn + ptn_adj);
  1263. putPtn( (unsigned char *)bmp_ptn, ptn_width, ptn_height );
  1264. }
  1265. else
  1266. {
  1267. fprintf(stderr, "%s: bmp_ptn is NULL", __FUNCTION__);
  1268. }
  1269. fprintf(stdout,"ENDCHAR\n");
  1270. if( fix == FALSE ) free(bmp_ptn);
  1271. }
  1272. if( fix == TRUE ) free(bmp_ptn);
  1273. return;
  1274. }
  1275. static char *
  1276. make_toptn(int width, int height)
  1277. {
  1278. int byte_width;
  1279. byte_width = (width + 7)/8;
  1280. return (char *)malloc( byte_width * height);
  1281. }
  1282. static int
  1283. getarg(
  1284. int argc,
  1285. char *argv[],
  1286. char *fname,
  1287. int *bitorder,
  1288. int *byteorder,
  1289. int *scanunit,
  1290. int *glyphPad,
  1291. int *outLevel,
  1292. int *fix)
  1293. {
  1294. int i;
  1295. int already;
  1296. char *arg;
  1297. char *usage="dtgpftobdf [-H] [-V] [-help] font_file_name";
  1298. *glyphPad = DEFAULTGLPAD;
  1299. *bitorder = DEFAULTBITORDER;
  1300. *scanunit = DEFAULTSCANUNIT;
  1301. *byteorder = DEFAULTBYTEORDER;
  1302. *outLevel = FALSE;
  1303. *fix = FALSE ;
  1304. already = 0 ;
  1305. for (i = 1; i < argc; i++ ) {
  1306. arg = argv[i];
  1307. if (*arg == '-') {
  1308. *arg++;
  1309. switch (*arg) {
  1310. case 'p' :
  1311. *glyphPad = atoi(arg+1) ;
  1312. if (*glyphPad != 1 &&
  1313. *glyphPad != 2 &&
  1314. *glyphPad != 4 &&
  1315. *glyphPad != 8 ) {
  1316. USAGE("dtgpftobdf : illegal padding number (1/2/4/8)\n");
  1317. return -1;
  1318. }
  1319. break;
  1320. case 'H' :
  1321. *outLevel = TRUE ;
  1322. break;
  1323. case 'h' :
  1324. USAGE1("usage: %s\n",usage);
  1325. return (-1);
  1326. case 'V' :
  1327. *fix = TRUE ;
  1328. break;
  1329. default :
  1330. USAGE1("dtgpftobdf : illegal option -- %s\n",arg);
  1331. USAGE1("usage: %s\n",usage);
  1332. return -1;
  1333. }
  1334. } else {
  1335. if (already == FALSE) {
  1336. strcpy(fname,arg);
  1337. already = TRUE;
  1338. } else {
  1339. USAGE1("dtgpftobdf : extra parameter --- %s\n",arg);
  1340. USAGE1("usage: %s\n", usage );
  1341. return -1;
  1342. }
  1343. }
  1344. }
  1345. if (already == FALSE) {
  1346. USAGE("dtgpftobdf : require file name\n");
  1347. USAGE1("usage: %s\n",usage);
  1348. return -1;
  1349. }
  1350. return 0;
  1351. }