4 * Copyright 1993 Alexandre Julliard
7 static char Copyright[] = "Copyright Alexandre Julliard, 1993";
9 #include <X11/Intrinsic.h>
10 #include <X11/StringDefs.h>
12 #include <X11/Shell.h>
13 #include <X11/Xatom.h>
21 /***********************************************************************
24 int DrawText( HDC hdc, LPSTR str, int count, LPRECT rect, WORD flags )
26 int x = rect->left, y = rect->top;
27 if (flags & DT_CENTER) x = (rect->left + rect->right) / 2;
28 if (flags & DT_VCENTER) y = (rect->top + rect->bottom) / 2;
29 if (count == -1) count = strlen(str);
31 if (!TextOut( hdc, x, y, str, count )) return 0;
36 /***********************************************************************
39 BOOL TextOut( HDC hdc, short x, short y, LPSTR str, short count )
41 int dir, ascent, descent, i;
45 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
46 if (!dc) return FALSE;
47 if (!DC_SetupGCForText( dc )) return TRUE;
48 font = dc->u.x.font.fstruct;
50 if (dc->w.textAlign & TA_UPDATECP)
56 printf( "TextOut: %d,%d '%s'\n", x, y, str );
61 XTextExtents( font, str, count, &dir, &ascent, &descent, &info );
62 info.width += count*dc->w.charExtra + dc->w.breakExtra*dc->w.breakCount;
64 /* Compute starting position */
66 switch( dc->w.textAlign & (TA_LEFT | TA_RIGHT | TA_CENTER) )
69 if (dc->w.textAlign & TA_UPDATECP)
70 dc->w.CursPosX = XDPTOLP( dc, x + info.width );
74 if (dc->w.textAlign & TA_UPDATECP) dc->w.CursPosX = XDPTOLP( dc, x );
80 switch( dc->w.textAlign & (TA_TOP | TA_BOTTOM | TA_BASELINE) )
94 if (!dc->w.charExtra && !dc->w.breakExtra)
96 if (dc->w.backgroundMode == TRANSPARENT)
97 XDrawString( XT_display, dc->u.x.drawable, dc->u.x.gc,
100 XDrawImageString( XT_display, dc->u.x.drawable, dc->u.x.gc,
107 for (i = 0; i < count; i++, p++)
109 XCharStruct * charStr;
110 unsigned char ch = *p;
113 if ((ch < font->min_char_or_byte2)||(ch > font->max_char_or_byte2))
114 ch = font->default_char;
115 if (!font->per_char) charStr = &font->min_bounds;
116 else charStr = font->per_char + ch - font->min_char_or_byte2;
118 extraWidth = dc->w.charExtra;
119 if (ch == dc->u.x.font.metrics.tmBreakChar)
120 extraWidth += dc->w.breakExtra;
122 if (dc->w.backgroundMode == TRANSPARENT)
123 XDrawString( XT_display, dc->u.x.drawable, dc->u.x.gc,
127 XDrawImageString( XT_display, dc->u.x.drawable, dc->u.x.gc,
129 XSetForeground( XT_display, dc->u.x.gc, dc->w.backgroundPixel);
130 XFillRectangle( XT_display, dc->u.x.drawable, dc->u.x.gc,
131 xchar + charStr->width, y - font->ascent,
132 extraWidth, font->ascent + font->descent );
133 XSetForeground( XT_display, dc->u.x.gc, dc->w.textPixel );
135 xchar += charStr->width + extraWidth;
139 /* Draw underline and strike-out if needed */
141 if (dc->u.x.font.metrics.tmUnderlined)
143 long linePos, lineWidth;
144 if (!XGetFontProperty( font, XA_UNDERLINE_POSITION, &linePos ))
145 linePos = font->descent-1;
146 if (!XGetFontProperty( font, XA_UNDERLINE_THICKNESS, &lineWidth ))
148 else if (lineWidth == 1) lineWidth = 0;
149 XSetLineAttributes( XT_display, dc->u.x.gc, lineWidth,
150 LineSolid, CapRound, JoinBevel );
151 XDrawLine( XT_display, dc->u.x.drawable, dc->u.x.gc,
152 x, y + linePos, x + info.width, y + linePos );
154 if (dc->u.x.font.metrics.tmStruckOut)
156 long lineAscent, lineDescent;
157 if (!XGetFontProperty( font, XA_STRIKEOUT_ASCENT, &lineAscent ))
158 lineAscent = font->ascent / 3;
159 if (!XGetFontProperty( font, XA_STRIKEOUT_DESCENT, &lineDescent ))
160 lineDescent = -lineAscent;
161 XSetLineAttributes( XT_display, dc->u.x.gc, lineAscent + lineDescent,
162 LineSolid, CapRound, JoinBevel );
163 XDrawLine( XT_display, dc->u.x.drawable, dc->u.x.gc,
164 x, y - lineAscent, x + info.width, y - lineAscent );