1 /**
2 ** drawstrg.c ---- low level character string output
3 **
4 ** Copyright (c) 1998 Hartmut Schirmer
5 ** Copyright (c) 1995 Csaba Biegl, 820 Stirrup Dr, Nashville, TN 37221
6 ** [e-mail: csaba@vuse.vanderbilt.edu]
7 **
8 ** This file is part of the GRX graphics library.
9 **
10 ** The GRX graphics library is free software; you can redistribute it
11 ** and/or modify it under some conditions; see the "copying.grx" file
12 ** for details.
13 **
14 ** This library is distributed in the hope that it will be useful,
15 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17 **
18 **/
19
20 #include "libgrx.h"
21 #include "clipping.h"
22 #include "text/text.h"
23
24 int _GR_textattrintensevideo = 0;
25
_GrDrawString(const void * text,int length,int x,int y,const GrTextOption * opt,GrPattern * p,TextDrawBitmapFunc dbm)26 void _GrDrawString(const void *text,int length,int x,int y,
27 const GrTextOption *opt, GrPattern *p, TextDrawBitmapFunc dbm)
28 {
29 GrFont *f;
30 int x1;
31 GRX_ENTER();
32
33 if ( ((f = opt->txo_font) != NULL)
34 && (x1= GrFontStringWidth(f,text,length,opt->txo_chrtype))!=0 ) {
35 GrColorTableP fgcp = opt->txo_fgcolor.p;
36 GrColorTableP bgcp = opt->txo_bgcolor.p;
37 GrColor fgcv = opt->txo_fgcolor.v;
38 GrColor bgcv = opt->txo_bgcolor.v;
39 int undl = (fgcv & GR_UNDERLINE_TEXT) ? 1 : 0;
40 int rotat = GR_TEXT_IS_VERTICAL(opt->txo_direct) ? ~0 : 0;
41 int dxpre = 0;
42 int dypre = 0;
43 int dxpost= 0;
44 int dypost= 0;
45 int oldx = x;
46 int oldy = y;
47 int y1 = f->h.height;
48 int ww = (x1 & ~rotat) | (y1 & rotat);
49 int hh = (x1 & rotat) | (y1 & ~rotat);
50 int type, step, x2, y2;
51 switch(opt->txo_xalign) {
52 case GR_ALIGN_RIGHT:
53 x -= ww - 1;
54 break;
55 case GR_ALIGN_CENTER:
56 x -= (ww >> 1);
57 break;
58 }
59 switch(opt->txo_yalign) {
60 case GR_ALIGN_BASELINE:
61 if(opt->txo_direct == GR_TEXT_DEFAULT) y -= f->h.baseline;
62 break;
63 case GR_ALIGN_BOTTOM:
64 y -= hh - 1;
65 break;
66 case GR_ALIGN_CENTER:
67 y -= (hh >> 1);
68 break;
69 }
70 mouse_block(CURC,x,y,(x + ww - 1),(y + hh - 1));
71 switch(opt->txo_direct) {
72 case GR_TEXT_DOWN:
73 dypost = ~0;
74 break;
75 case GR_TEXT_LEFT:
76 dxpre = ~0;
77 x += ww;
78 break;
79 case GR_TEXT_UP:
80 dypre = ~0;
81 y += hh;
82 break;
83 default:
84 dxpost = ~0;
85 break;
86 }
87 type = opt->txo_chrtype;
88 step = GR_TEXTCHR_SIZE(type);
89 while(--length >= 0) {
90 int chr = GR_TEXTSTR_CODE(text,type);
91 int attr,xx,yy,cw,ch;
92 char far *bmp;
93 if(type == GR_ATTR_TEXT) {
94 attr = GR_TEXTSTR_ATTR(text,GR_ATTR_TEXT);
95 fgcv = GR_CTABLE_COLOR(fgcp,GR_ATTR_FGCOLOR(attr));
96 bgcv = GR_CTABLE_COLOR(bgcp,GR_ATTR_BGCOLOR(attr));
97 undl = GR_ATTR_UNDERLINE(attr);
98 }
99 text = (void *)((char *)(text) + step);
100 x1 = GrFontCharWidth(f,chr);
101 y1 = f->h.height;
102 cw = (x1 & ~rotat) | (y1 & rotat);
103 ch = (x1 & rotat) | (y1 & ~rotat);
104 x1 = (x -= (cw & dxpre));
105 y1 = (y -= (ch & dypre));
106 x2 = (xx = x1) + cw - 1;
107 y2 = (yy = y1) + ch - 1;
108 x += (cw & dxpost);
109 y += (ch & dypost);
110 clip_ordbox_(CURC,x1,y1,x2,y2,continue,CLIP_EMPTY_MACRO_ARG);
111 bmp = GrFontCharAuxBmp(f,chr,opt->txo_direct,undl);
112 if(bmp) (*dbm)(
113 (x1 + CURC->gc_xoffset),
114 (y1 + CURC->gc_yoffset),
115 (x2 - x1 + 1),
116 (y2 - y1 + 1),
117 oldx, oldy,
118 bmp,
119 ((cw + 7) >> 3),
120 ((x1 - xx) + ((y1 - yy) * ((cw + 7) & ~7))),
121 fgcv,bgcv,
122 p
123 );
124 else (*FDRV->drawblock)(
125 (x1 + CURC->gc_xoffset),
126 (y1 + CURC->gc_yoffset),
127 (x2 - x1 + 1),
128 (y2 - y1 + 1),
129 bgcv
130 );
131 }
132 mouse_unblock();
133 }
134 GRX_LEAVE();
135 }
136