summaryrefslogtreecommitdiff
path: root/Build/source/libs/t1lib/t1win32.c
blob: 2e1608b96fe1217646bb66b16ca59948ef32c5db (plain)
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
/*--------------------------------------------------------------------------
  ----- File:        t1win32.c 
  ----- Author:      Rainer Menzner (rmz@neuroinformatik.ruhr-uni-bochum.de)
                     modified for win32 by Fabrice Popineau (Fabrice.Popineau@supelec.fr)
  ----- Date:        1999-06-24
  ----- Description: This file is part of the t1-library. It contains
                     functions for generating glyphs with data in
		     Win32 dib format.
  ----- Copyright:   t1lib is copyrighted (c) Rainer Menzner, 1996-1998. 
                     As of version 0.5, t1lib is distributed under the
		     GNU General Public Library Lincense. The
		     conditions can be found in the files LICENSE and
		     LGPL, which should reside in the toplevel
		     directory of the distribution.  Please note that 
		     there are parts of t1lib that are subject to
		     other licenses:
		     The parseAFM-package is copyrighted by Adobe Systems
		     Inc.
		     The type1 rasterizer is copyrighted by IBM and the
		     X11-consortium.
  ----- Warranties:  Of course, there's NO WARRANTY OF ANY KIND :-)
  ----- Credits:     I want to thank IBM and the X11-consortium for making
                     their rasterizer freely available.
		     Also thanks to Piet Tutelaers for his ps2pk, from
		     which I took the rasterizer sources in a format
		     independent from X11.
                     Thanks to all people who make free software living!
--------------------------------------------------------------------------*/
  
#define T1WIN32_C


#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <math.h>

#include <windows.h>

#include "../type1/types.h"
#include "parseAFM.h" 
#include "../type1/objects.h" 
#include "../type1/spaces.h"  
#include "../type1/util.h" 
#include "../type1/fontfcn.h"
#include "../type1/regions.h"

#include "t1types.h"
#include "t1extern.h"
#include "t1set.h"
#include "t1aaset.h"
#include "t1load.h"
#include "t1finfo.h"
#include "t1misc.h"
#include "t1win32.h"
#include "t1base.h"



#define T1GCMASK GCForeground | GCBackground 

/* As a fall back */
#ifndef T1_AA_TYPE16 
#define T1_AA_TYPE16    short
#endif
#ifndef T1_AA_TYPE32 
#define T1_AA_TYPE32    int
#endif



/* The three important X11 parameters t1lib has to deal with: */
static HDC  *T1_display=NULL;  /* Must be accessible from t1delete.c */
static Colormap T1_colormap;
static unsigned int T1_depth;
static int T1_byte_order;
static int lastlevel=0;
static unsigned long oldfg_n=0, oldbg_n=0, oldfg_l=0, oldbg_l=0;
static unsigned long oldfg_h=0, oldbg_h=0, oldfg=0, oldbg=0;


extern int T1aa_SmartOn;        /* from t1aaset.c */
extern float T1aa_smartlimit1;
extern float T1aa_smartlimit2;



static XColor aacolors[AAMAXPLANES];
static unsigned long aapixels[AAMAXPLANES];


/* The following parameter determines whether t1lib will use logical
   positioning of chars and string (place the origin at specified
   destination-point) or absolute positioning with respect to the
   origin (upper left corner) of the generated bitmap/pixmap. */
static int T1_lposition=1;



/* T1_SetX11Params(): Set X11-parameters which t1lib has to know in order
   to properly generate pixmaps from characters */
int T1_SetWin32Params( HDC hDc,
		     unsigned int depth,
		     Colormap colormap)
{

  T1_display  =display;
  T1_visual   =visual;
  T1_depth    =depth;
  T1_colormap =colormap;

  if (T1_CheckEndian()==0)
    T1_byte_order=0;
  else
    T1_byte_order=1;

  /* For bug hunting: */
  if (ImageByteOrder( T1_display)==0)
    T1_PrintLog( "T1_SetX11Params()",
		 "X-Server uses Little Endian data representation",
		 T1LOG_DEBUG);
  else
    T1_PrintLog( "T1_SetX11Params()",
		 "X-Server uses Big Endian data representation",
		 T1LOG_DEBUG);
  
  return(0);
}



/* T1_SetCharX(): Generate an object of type GLYPH, i.e, a glyph with
   a pixmap ID instead of a pointer to a bitmap: */

GLYPH *T1_SetCharX( HDC hDc, int mode, int x_dest, int y_dest,
		    int FontID, char charcode,
		    float size, T1_TMATRIX *transform)
{
  GLYPH  *pglyph;
  static GLYPH xglyph={NULL,{0,0,0,0,0,0},NULL,0};
 
  int height, width;
  Pixmap clipmask=0;
  int opaque;
  

  xglyph.metrics.leftSideBearing=0;
  xglyph.metrics.rightSideBearing=0;
  xglyph.metrics.advanceX=0;
  xglyph.metrics.advanceY=0;
  xglyph.metrics.ascent=0;
  xglyph.metrics.descent=0;
  xglyph.pFontCacheInfo=NULL;
  

  opaque=mode;
  
  
  if ((pglyph=T1_SetChar( FontID, charcode, size, transform))==NULL){
    T1_PrintLog( "T1_SetCharX()",
		 "T1_SetChar() returned NULL-pointer!",
		 T1LOG_WARNING);
    return(NULL);
  }

  /* Check for empty bitmap */
  if (pglyph->bits==NULL) {
    xglyph=*pglyph;
    return( &xglyph);
  }
  
  width=pglyph->metrics.rightSideBearing-pglyph->metrics.leftSideBearing;
  height=pglyph->metrics.ascent-pglyph->metrics.descent;
  
  
  clipmask=XCreateBitmapFromData( T1_display,
				  d,
				  (char *)pglyph->bits,
				  PAD(width, pFontBase->bitmap_pad),  
				  height
				  );
				  
  /* Correct position */
  if (T1_lposition){
    x_dest += pglyph->metrics.leftSideBearing;
    y_dest -= pglyph->metrics.ascent;
  }

  if (opaque==0){
    XSetClipMask(T1_display, gc, clipmask);
    XSetClipOrigin(T1_display, gc, x_dest, y_dest);
  }
  
  XCopyPlane( T1_display, clipmask, d, gc, 0, 0,
	      width, height, x_dest, y_dest, 0x01);
  
  if (clipmask){
    XFreePixmap( T1_display, clipmask);
    clipmask=0;
    XSetClipMask(T1_display, gc, None);
    XSetClipOrigin(T1_display, gc, 0, 0);
  }
  
  pglyph->bits=NULL;    /* Since XDestroyImage() free's this also! */
  xglyph.metrics.leftSideBearing=pglyph->metrics.leftSideBearing;
  xglyph.metrics.rightSideBearing=pglyph->metrics.rightSideBearing;
  xglyph.metrics.advanceX=pglyph->metrics.advanceX;
  xglyph.metrics.advanceY=pglyph->metrics.advanceY;
  xglyph.metrics.ascent=pglyph->metrics.ascent;
  xglyph.metrics.descent=pglyph->metrics.descent;
  xglyph.bpp=pglyph->bpp;
  
  return( &xglyph);
  
  
}



/* T1_SetStringX(...): Draw a string of characters into an X11 drawable */
GLYPH *T1_SetStringX( HDC hDc, int mode, int x_dest, int y_dest,
		      int FontID, char *string, int len, 
		      long spaceoff, int modflag, float size,
		      T1_TMATRIX *transform)
{
  GLYPH  *pglyph;
  static GLYPH xglyph={NULL,{0,0,0,0,0,0},NULL,0};
 
  int height, width;
  Pixmap clipmask=0;
  int opaque;
  

  xglyph.metrics.leftSideBearing=0;
  xglyph.metrics.rightSideBearing=0;
  xglyph.metrics.advanceX=0;
  xglyph.metrics.advanceY=0;
  xglyph.metrics.ascent=0;
  xglyph.metrics.descent=0;
  xglyph.pFontCacheInfo=NULL;
  

  opaque=mode;
  

  if ((pglyph=T1_SetString( FontID, string, len, 
			    spaceoff, modflag, size,
			    transform))==NULL){
    T1_PrintLog( "T1_SetStringX()",
		 "T1_SetString() returned NULL-pointer!",
		 T1LOG_WARNING);
    return(NULL);
  }

  /* Check for empty bitmap */
  if (pglyph->bits==NULL) {
    xglyph=*pglyph;
    return( &xglyph);
  }

  width=pglyph->metrics.rightSideBearing-pglyph->metrics.leftSideBearing;
  height=pglyph->metrics.ascent-pglyph->metrics.descent;
  
  clipmask=XCreateBitmapFromData( T1_display,
				  d,
				  (char *)pglyph->bits,
				  PAD(width, pFontBase->bitmap_pad), /* width */
				  height
				  );
  
  /* Correct position */
  if (T1_lposition){
    x_dest += pglyph->metrics.leftSideBearing;
    y_dest -= pglyph->metrics.ascent;
  }

  if (opaque==0){
    XSetClipMask(T1_display, gc, clipmask);
    XSetClipOrigin(T1_display, gc, x_dest, y_dest);
  }
  
  XCopyPlane( T1_display, clipmask, d, gc, 0, 0,
	      width, height, x_dest, y_dest, 0x01);
  
  if (clipmask){
    XFreePixmap( T1_display, clipmask);
    clipmask=0;
    XSetClipMask(T1_display, gc, None);
    XSetClipOrigin(T1_display, gc, 0, 0);
  }
  
  pglyph->bits=NULL;    /* Since XDestroyImage() free's this also! */
  xglyph.metrics.leftSideBearing=pglyph->metrics.leftSideBearing;
  xglyph.metrics.rightSideBearing=pglyph->metrics.rightSideBearing;
  xglyph.metrics.advanceX=pglyph->metrics.advanceX;
  xglyph.metrics.advanceY=pglyph->metrics.advanceY;
  xglyph.metrics.ascent=pglyph->metrics.ascent;
  xglyph.metrics.descent=pglyph->metrics.descent;
  xglyph.bpp=pglyph->bpp;
  
  return( &xglyph);
  
  
}



/* T1_AASetCharX(): Generate an object of type GLYPH, i.e, a glyph with
   a pixmap ID instead of a pointer to a bitmap: */

GLYPH *T1_AASetCharX( HDC hDc, int mode, int x_dest, int y_dest,
		      int FontID, char charcode,
		      float size, T1_TMATRIX *transform)
{
  int j, k;

  GLYPH  *pglyph;
  XImage *ximage;

  static GLYPH xglyph={NULL,{0,0,0,0,0,0},NULL,0};
 
  int height, width, width_pad;
  
  XGCValues xgcvalues;
  static unsigned long fg, bg, oldfg=0, oldbg=0;
  static unsigned long oldfg_l=0, oldbg_l=0, oldfg_h=0, oldbg_h=0;

  Pixmap clipmask=0;
  int clipmask_h, clipmask_v, line_off;
  char *clipmask_ptr;
  
  int opaque;
  

	       
  xglyph.metrics.leftSideBearing=0;
  xglyph.metrics.rightSideBearing=0;
  xglyph.metrics.advanceX=0;
  xglyph.metrics.advanceY=0;
  xglyph.metrics.ascent=0;
  xglyph.metrics.descent=0;
  xglyph.pFontCacheInfo=NULL;
  

  opaque=mode;
  
  xglyph.bpp=T1_depth;
  
  /* In order to be able to contruct the pixmap we need to know
     foreground and background color as well the copy function */
  XGetGCValues( T1_display, gc, T1GCMASK, &xgcvalues);
  fg=xgcvalues.foreground;
  bg=xgcvalues.background;
  

  /* At this point we must compute the colors that are needed to do
     antialiasing between fore- and background. The following function
     fills the static aacolors */
  if (T1aa_SmartOn==0)
    j=T1_AAGetLevel();
  else if (size>=T1aa_smartlimit2)
    j=1;
  else if (size>=T1aa_smartlimit1)
    j=2;
  else
    j=4;
  if ( j!=lastlevel || fg!=oldfg || bg!=oldbg ){
    switch ( j){
    case 1:
      if ( fg!=oldfg_n || bg!=oldbg_n){
	oldfg_n=fg;
	oldbg_n=bg;
	/* computing colors is not necessary here */
	T1_AANSetGrayValues( bg, fg);
      }
      break;
    case 2:
      if ( fg!=oldfg_l || bg!=oldbg_l){
	oldfg_l=fg;
	oldbg_l=bg;
	T1_ComputeAAColorsX( fg, bg, AAMAXPLANES);
	T1_AASetGrayValues(aapixels[0],   /* white */
			   aapixels[4],
			   aapixels[8],
			   aapixels[12],
			   aapixels[16] ); /* black */
      }
      break;
    case 4:
      if ( fg!=oldfg_h || bg!=oldbg_h){
	oldfg_h=fg;
	oldbg_h=bg;
	T1_ComputeAAColorsX( fg, bg, AAMAXPLANES);
	T1_AAHSetGrayValues( aapixels); 
      }
      break;
    }
    lastlevel=j;
    oldfg=fg;
    oldbg=bg;
  }

  if ((pglyph=T1_AASetChar( FontID, charcode, size,
			    transform))==NULL){
    T1_PrintLog( "T1_AASetCharX()",
		 "T1_AASetChar() returned NULL-pointer!",
		 T1LOG_WARNING);
    return(NULL);
  }

  /* Check for empty bitmap */
  if (pglyph->bits==NULL) {
    xglyph=*pglyph;
    return( &xglyph);
  }

  width=pglyph->metrics.rightSideBearing-pglyph->metrics.leftSideBearing;
  height=pglyph->metrics.ascent-pglyph->metrics.descent;
  
	       
  /* Correct position */
  if (T1_lposition){
    x_dest += pglyph->metrics.leftSideBearing;
    y_dest -= pglyph->metrics.ascent;
  }

  if (opaque==0){
    clipmask_v=height;
    clipmask_h=width;
    width_pad=PAD(width*T1aa_bpp, pFontBase->bitmap_pad)/T1aa_bpp;
    clipmask_ptr=(char *)calloc((PAD(clipmask_h, 8)>>3) * clipmask_v, sizeof( char)); 
    if (clipmask_ptr==NULL){
      T1_errno=T1ERR_ALLOC_MEM;
      return(NULL);
    }
    /* Note: We pad the clipmask always to byte boundary */
    if (pglyph->bpp==8)
      for ( k=0; k<clipmask_v; k++){
	line_off=k*(PAD(clipmask_h, 8)>>3);
	for (j=0; j<clipmask_h; j++){
	  if (((char *)(pglyph->bits))[k*width_pad+j]!=bg)
	    clipmask_ptr[line_off+(j>>3)] |= (0x01<<(j%8));
	}
      }
    else if (pglyph->bpp==16)
      for ( k=0; k<clipmask_v; k++){
	line_off=k*(PAD(clipmask_h, 8)>>3);
	for (j=0; j<clipmask_h; j++){
	  if (((T1_AA_TYPE16 *)(pglyph->bits))[k*width_pad+j]!=(T1_AA_TYPE16)bg)
	    clipmask_ptr[line_off+(j>>3)] |= (0x01<<(j%8));
	}
      }
    else 
      for ( k=0; k<clipmask_v; k++){
	line_off=k*(PAD(clipmask_h, 8)>>3);
	for (j=0; j<clipmask_h; j++){
	  if (((T1_AA_TYPE32 *)(pglyph->bits))[k*width_pad+j]!=(T1_AA_TYPE32)bg)
	    clipmask_ptr[line_off+(j>>3)] |= (0x01<<(j%8));
	}
      }
    
    clipmask=XCreateBitmapFromData( T1_display,
				    d,
				    (char *)clipmask_ptr,
				    width,
				    height
				    );
    free( clipmask_ptr);
    XSetClipMask(T1_display, gc, clipmask);
    XSetClipOrigin(T1_display, gc, x_dest, y_dest);

  }
  ximage=XCreateImage( T1_display,
		       T1_visual,
		       T1_depth, 
		       ZPixmap, /* XYBitmap or XYPixmap */
		       0, /* No offset */
		       (char *)pglyph->bits,
		       width,
		       height,
		       pFontBase->bitmap_pad,  
		       0 /*PAD(width,8)/8*/  /* number of bytes per line */
		       );
  ximage->byte_order=T1_byte_order;
  XPutImage(T1_display,
	    d,
	    gc,
	    ximage,
	    0,  
	    0,  
	    x_dest,  
	    y_dest,  
	    width,
	    height
	    );
  XDestroyImage(ximage);
  if (clipmask){
    XFreePixmap( T1_display, clipmask);
    clipmask=0;
    XSetClipMask(T1_display, gc, None);
    XSetClipOrigin(T1_display, gc, 0, 0);
  }
  
  pglyph->bits=NULL;    /* Since XDestroyImage() free's this also! */
  xglyph.metrics.leftSideBearing=pglyph->metrics.leftSideBearing;
  xglyph.metrics.rightSideBearing=pglyph->metrics.rightSideBearing;
  xglyph.metrics.advanceX=pglyph->metrics.advanceX;
  xglyph.metrics.advanceY=pglyph->metrics.advanceY;
  xglyph.metrics.ascent=pglyph->metrics.ascent;
  xglyph.metrics.descent=pglyph->metrics.descent;
  xglyph.bpp=pglyph->bpp;
  
  return( &xglyph);
  
  
}



/* T1_AASetStringX(...): Draw a string of characters into an X11 drawable */
GLYPH *T1_AASetStringX( HDC hDc, int mode, int x_dest, int y_dest,
			int FontID, char *string, int len, 
			long spaceoff, int modflag, float size,
			T1_TMATRIX *transform)
{
  int  j, k;

  GLYPH  *pglyph;
  XImage *ximage;

  
  static GLYPH xglyph={NULL,{0,0,0,0,0,0},NULL,0};

  int height, width, width_pad;
  
  XGCValues xgcvalues;
  static unsigned long fg, bg;
  

  Pixmap clipmask=0;
  int clipmask_h, clipmask_v, line_off;
  char *clipmask_ptr;
  
  int opaque;
  

  xglyph.metrics.leftSideBearing=0;
  xglyph.metrics.rightSideBearing=0;
  xglyph.metrics.advanceX=0;
  xglyph.metrics.advanceY=0;
  xglyph.metrics.ascent=0;
  xglyph.metrics.descent=0;
  xglyph.pFontCacheInfo=NULL;
  

  opaque=mode;
  
  
  /* In order to be able to contruct the pixmap we need to know
     foreground and background color as well the copy function */
  XGetGCValues( T1_display, gc, T1GCMASK, &xgcvalues);
  fg=xgcvalues.foreground;
  bg=xgcvalues.background;
  
  xglyph.bpp=T1_depth;
  
  /* At this point we must compute the colors that are needed to do
     antialiasing between fore- and background. The following function
     fills the static aacolors */
  if (T1aa_SmartOn==0)
    j=T1_AAGetLevel();
  else if (size>=T1aa_smartlimit2)
    j=1;
  else if (size>=T1aa_smartlimit1)
    j=2;
  else
    j=4;
  if ( j!=lastlevel || fg!=oldfg || bg!=oldbg ){
    switch ( j){
    case 1:
      if ( fg!=oldfg_n || bg!=oldbg_n){
	oldfg_n=fg;
	oldbg_n=bg;
	/* computing colors is not necessary here */
	T1_AANSetGrayValues( bg, fg);
      }
      break;
    case 2:
      if ( fg!=oldfg_l || bg!=oldbg_l){
	oldfg_l=fg;
	oldbg_l=bg;
	T1_ComputeAAColorsX( fg, bg, AAMAXPLANES);
	T1_AASetGrayValues(aapixels[0],   /* white */
			   aapixels[4],
			   aapixels[8],
			   aapixels[12],
			   aapixels[16] ); /* black */
      }
      break;
    case 4:
      if ( fg!=oldfg_h || bg!=oldbg_h){
	oldfg_h=fg;
	oldbg_h=bg;
	T1_ComputeAAColorsX( fg, bg, AAMAXPLANES);
	T1_AAHSetGrayValues( aapixels); 
      }
      break;
    }
    lastlevel=j;
    oldfg=fg;
    oldbg=bg;
  }

  
  if ((pglyph=T1_AASetString( FontID, string, len, 
			      spaceoff, modflag, size,
			      transform))==NULL){
    T1_PrintLog( "T1_AASetStringX()",
		 "T1_AASetString() returned NULL-pointer!",
		 T1LOG_WARNING);
    return(NULL);
  }

  /* Check for empty bitmap */
  if (pglyph->bits==NULL) {
    xglyph=*pglyph;
    return( &xglyph);
  }

  width=pglyph->metrics.rightSideBearing-pglyph->metrics.leftSideBearing;
  height=pglyph->metrics.ascent-pglyph->metrics.descent;
  
  
  /* Correct position */
  if (T1_lposition){
    x_dest += pglyph->metrics.leftSideBearing;
    y_dest -= pglyph->metrics.ascent;
  }

  if (opaque==0){
    clipmask_v=height;
    clipmask_h=width;
    width_pad=PAD(width*T1aa_bpp, pFontBase->bitmap_pad)/T1aa_bpp;
    clipmask_ptr=(char *)calloc((PAD(clipmask_h, 8)>>3) * clipmask_v, sizeof( char));
    if (clipmask_ptr==NULL){
      T1_errno=T1ERR_ALLOC_MEM;
      return(NULL);
    }
    /* Note: We pad the clipmask always to byte boundary */
    if (pglyph->bpp==8)
      for ( k=0; k<clipmask_v; k++){
	line_off=k*(PAD(clipmask_h, 8)>>3);
	for (j=0; j<clipmask_h; j++){
	  if (((char *)(pglyph->bits))[k*width_pad+j]!=bg)
	    clipmask_ptr[line_off+(j>>3)] |= (0x01<<(j%8));
	}
      }
    else if (pglyph->bpp==16)
      for ( k=0; k<clipmask_v; k++){
	line_off=k*(PAD(clipmask_h, 8)>>3);
	for (j=0; j<clipmask_h; j++){
	  if (((T1_AA_TYPE16 *)(pglyph->bits))[k*width_pad+j]!=(T1_AA_TYPE16)bg)
	    clipmask_ptr[line_off+(j>>3)] |= (0x01<<(j%8));
	}
      }
    else 
      for ( k=0; k<clipmask_v; k++){
	line_off=k*(PAD(clipmask_h, 8)>>3);
	for (j=0; j<clipmask_h; j++){
	  if (((T1_AA_TYPE32 *)(pglyph->bits))[k*width_pad+j]!=(T1_AA_TYPE32)bg)
	    clipmask_ptr[line_off+(j>>3)] |= (0x01<<(j%8));
	}
      }
    
    clipmask=XCreateBitmapFromData( T1_display,
				    d,
				    (char *)clipmask_ptr,
				    width,
				    height
				    );
    free( clipmask_ptr);
    XSetClipMask(T1_display, gc, clipmask);
    XSetClipOrigin(T1_display, gc, x_dest, y_dest);

  }
  ximage=XCreateImage( T1_display,
		       T1_visual,
		       T1_depth, 
		       ZPixmap, /* XYBitmap or XYPixmap */
		       0, /* No offset */
		       (char *)pglyph->bits,
		       width,
		       height,
		       pFontBase->bitmap_pad,  /* lines padded to bytes */
		       0 /*PAD(width,8)/8*/  /* number of bytes per line */
		       );
  ximage->byte_order=T1_byte_order;
  XPutImage(T1_display,
	    d,
	    gc,
	    ximage,
	    0,  
	    0,  
	    x_dest,  
	    y_dest,  
	    width,
	    height
	    );
  XDestroyImage(ximage);
  if (clipmask){
    XFreePixmap( T1_display, clipmask);
    clipmask=0;
    XSetClipMask(T1_display, gc, None);
    XSetClipOrigin(T1_display, gc, 0, 0);
  }
  
  pglyph->bits=NULL;    /* Since XDestroyImage() free's this also! */
  xglyph.metrics.leftSideBearing=pglyph->metrics.leftSideBearing;
  xglyph.metrics.rightSideBearing=pglyph->metrics.rightSideBearing;
  xglyph.metrics.advanceX=pglyph->metrics.advanceX;
  xglyph.metrics.advanceY=pglyph->metrics.advanceY;
  xglyph.metrics.ascent=pglyph->metrics.ascent;
  xglyph.metrics.descent=pglyph->metrics.descent;
  xglyph.bpp=pglyph->bpp;
  
  return( &xglyph);
  
  
}



/* T1_ComputeAAColorsX(): Compute the antialiasing colors in dependency
   of foreground and background */
int T1_ComputeAAColorsX( unsigned long fg, unsigned long bg, int nolevels)
{

  static unsigned long last_fg;
  static unsigned long last_bg;
  unsigned long delta_red, delta_green, delta_blue;
  int i;
  int nocolors=0;
  
  
  aacolors[0].pixel=bg;
  aacolors[nolevels-1].pixel=fg;

  if ((fg==last_fg)&&(bg==last_bg))
    return(nocolors);
  
  /* Get RGB values for fore- and background */
  XQueryColor( T1_display, T1_colormap, &aacolors[0]);
  XQueryColor( T1_display, T1_colormap, &aacolors[nolevels-1]);
  delta_red   = (aacolors[nolevels-1].red - aacolors[0].red)/(nolevels-1);
  delta_green = (aacolors[nolevels-1].green - aacolors[0].green)/(nolevels-1);
  delta_blue  = (aacolors[nolevels-1].blue - aacolors[0].blue)/(nolevels-1);
  aapixels[0]=aacolors[0].pixel;
  aapixels[nolevels-1]=aacolors[nolevels-1].pixel;

  
  for (i=1; i<nolevels-1; i++){
    aacolors[i].red   = aacolors[i-1].red + delta_red;
    aacolors[i].green = aacolors[i-1].green + delta_green;
    aacolors[i].blue  = aacolors[i-1].blue + delta_blue;
    /* Allocate color in current palette */
    if (XAllocColor( T1_display, T1_colormap, &aacolors[i])!=0){
      aapixels[i]=aacolors[i].pixel;
      nocolors++;
    }
    
  }
  
  return(nocolors);

}



/* Set the positioning switch */
void T1_LogicalPositionX( int pos_switch)
{
  if (pos_switch)
    T1_lposition=1;
  else
    T1_lposition=0;
  return;
}