~ubuntu-branches/ubuntu/saucy/python-scipy/saucy

« back to all changes in this revision

Viewing changes to Lib/sandbox/xplt/src/play/win/ptext.c

  • Committer: Bazaar Package Importer
  • Author(s): Ondrej Certik
  • Date: 2008-06-16 22:58:01 UTC
  • mfrom: (2.1.24 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080616225801-irdhrpcwiocfbcmt
Tags: 0.6.0-12
* The description updated to match the current SciPy (Closes: #489149).
* Standards-Version bumped to 3.8.0 (no action needed)
* Build-Depends: netcdf-dev changed to libnetcdf-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * ptext.c -- $Id: ptext.c 685 2003-03-08 15:26:51Z travo $
3
 
 * p_text for MS Windows
4
 
 *
5
 
 * Copyright (c) 1999.  See accompanying LEGAL file for details.
6
 
 */
7
 
 
8
 
#include "playw.h"
9
 
#include "pstdlib.h"
10
 
 
11
 
void
12
 
p_text(p_win *w, int x0, int y0, const char *text, int n)
13
 
{
14
 
  HDC dc = w_getdc(w, 1);
15
 
  if (dc) {
16
 
    int i;
17
 
    if (n <= 0) n = 16350;
18
 
    for (i=0 ; i<n ; i++) if (!text[i]) break;
19
 
    n = i;
20
 
    if (!w->orient) {
21
 
      TextOut(dc, x0, y0, text, n);
22
 
    } else {
23
 
      /* only do this with opaque background,
24
 
       * since only 8x8 patterned brushes supported under Win95
25
 
       * (could read screen, rotate, TextOut, rotate back) */
26
 
      TEXTMETRIC tm;
27
 
      SIZE sz;
28
 
      if (n>0 && GetTextMetrics(dc, &tm) &&
29
 
          GetTextExtentPoint32(dc, text, n, &sz) &&
30
 
          sz.cx>0) {
31
 
        int width = sz.cx;
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);
41
 
        struct {
42
 
          BITMAPINFOHEADER bmiHeader;
43
 
          DWORD bmiColors[2];
44
 
        } mono;
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) {
61
 
          RECT r;
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);
67
 
          r.left = r.top = 0;
68
 
          r.right = scandx;
69
 
          r.bottom = scandy;
70
 
          FillRect(offdc, &r, GetStockObject(BLACK_BRUSH));
71
 
          if (w->orient == 2) {
72
 
            TextOut(offdc, scandx-width, base, text, n);
73
 
          } else if (w->orient == 1) {
74
 
            TextOut(offdc, scandx-width, base, text, n);
75
 
          } else {
76
 
            TextOut(offdc, 0, scandy-height+base, text, n);
77
 
          }
78
 
          GetDIBits(offdc, offbm, 0, scandy, monodat,
79
 
                    (BITMAPINFO *)&mono, DIB_RGB_COLORS);
80
 
        }
81
 
        if (offdc) DeleteDC(offdc);
82
 
        if (offbm) DeleteObject(offbm);
83
 
 
84
 
        if (monodat) {
85
 
          COLORREF bg = w_color(w,w->bg);
86
 
          COLORREF fg = w_color(w,w->color);
87
 
          if (w->orient == 2) {
88
 
            p_mrot180(monodat, monorot, scandx, height);
89
 
            x0 -= width-1;
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);
94
 
            x0 -= base;
95
 
            y0 -= width-1;
96
 
          } else {
97
 
            p_mrot270(monodat, monorot, scandx, scandy);
98
 
            x0 -= (height-base)-1;
99
 
          }
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,
106
 
                        height, width,
107
 
                        0, 0, height, width, monorot,
108
 
                        (BITMAPINFO *)&mono, DIB_RGB_COLORS, SRCCOPY);
109
 
 
110
 
          p_free(monodat);
111
 
        }
112
 
      }
113
 
    }
114
 
  }
115
 
}