2
* ptext.c -- $Id: ptext.c 685 2003-03-08 15:26:51Z travo $
3
* p_text for MS Windows
5
* Copyright (c) 1999. See accompanying LEGAL file for details.
12
p_text(p_win *w, int x0, int y0, const char *text, int n)
14
HDC dc = w_getdc(w, 1);
17
if (n <= 0) n = 16350;
18
for (i=0 ; i<n ; i++) if (!text[i]) break;
21
TextOut(dc, x0, y0, text, n);
23
/* only do this with opaque background,
24
* since only 8x8 patterned brushes supported under Win95
25
* (could read screen, rotate, TextOut, rotate back) */
28
if (n>0 && GetTextMetrics(dc, &tm) &&
29
GetTextExtentPoint32(dc, text, n, &sz) &&
32
int height = tm.tmHeight + 1;
33
int base = tm.tmAscent;
34
int scandx = ((width-1)/(8*sizeof(DWORD)) + 1)*(8*sizeof(DWORD));
35
int scandy = ((height-1)/(8*sizeof(DWORD)) + 1)*(8*sizeof(DWORD));
36
HDC offdc = CreateCompatibleDC(dc);
37
HBITMAP offbm = CreateCompatibleBitmap(dc, scandx, scandy);
38
HFONT font = GetCurrentObject(dc, OBJ_FONT);
39
void *monodat = p_malloc(scandx*scandy/4);
40
void *monorot = (char *)monodat + (scandx*scandy/8);
42
BITMAPINFOHEADER bmiHeader;
45
mono.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
46
mono.bmiHeader.biWidth = scandx;
47
mono.bmiHeader.biHeight = -scandy;
48
mono.bmiHeader.biPlanes = 1;
49
mono.bmiHeader.biBitCount = 1;
50
mono.bmiHeader.biCompression = BI_RGB;
51
mono.bmiHeader.biSizeImage = 0;
52
mono.bmiHeader.biXPelsPerMeter = 0;
53
mono.bmiHeader.biYPelsPerMeter = 0;
54
mono.bmiHeader.biClrUsed = 0;
55
mono.bmiHeader.biClrImportant = 0;
56
/* apparently, bmiColors ignored on read
57
* -white bits are set, black bits reset no matter what */
58
mono.bmiColors[0] = RGB(0,0,0);
59
mono.bmiColors[1] = RGB(255,255,255);
60
if (offdc && offbm && font && monodat) {
62
SelectObject(offdc, offbm);
63
SelectObject(offdc, font);
64
SetBkMode(offdc, TRANSPARENT);
65
SetTextColor(offdc, RGB(255,255,255));
66
SetTextAlign(offdc, TA_LEFT | TA_BASELINE | TA_NOUPDATECP);
70
FillRect(offdc, &r, GetStockObject(BLACK_BRUSH));
72
TextOut(offdc, scandx-width, base, text, n);
73
} else if (w->orient == 1) {
74
TextOut(offdc, scandx-width, base, text, n);
76
TextOut(offdc, 0, scandy-height+base, text, n);
78
GetDIBits(offdc, offbm, 0, scandy, monodat,
79
(BITMAPINFO *)&mono, DIB_RGB_COLORS);
81
if (offdc) DeleteDC(offdc);
82
if (offbm) DeleteObject(offbm);
85
COLORREF bg = w_color(w,w->bg);
86
COLORREF fg = w_color(w,w->color);
88
p_mrot180(monodat, monorot, scandx, height);
90
y0 -= (height-base)-1;
91
scandx = width, width = height, height = scandx;
92
} else if (w->orient == 1) {
93
p_mrot090(monodat, monorot, scandx, scandy);
97
p_mrot270(monodat, monorot, scandx, scandy);
98
x0 -= (height-base)-1;
100
mono.bmiColors[0] = W_SWAPRGB(bg);
101
mono.bmiColors[1] = W_SWAPRGB(fg);
102
mono.bmiHeader.biWidth = height;
103
mono.bmiHeader.biHeight = -width;
104
/* prefer this to SetDIBitsToDevice? */
105
StretchDIBits(dc, x0, y0,
107
0, 0, height, width, monorot,
108
(BITMAPINFO *)&mono, DIB_RGB_COLORS, SRCCOPY);