summaryrefslogtreecommitdiff
path: root/src/WNT/WNT_TextManager.cxx
blob: 8f8db01b070b79eea9e69045522d05de56446879 (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
// File:        WNT_TextManager.cxx
// Created:     Feb 1998
// Author:      CHABROVSKY Dmitry
// Copyright:   Matra Datavision 1998

// include windows.h first to have all definitions available
#include <windows.h>

#define  MFT

#include <WNT_TextManager.ixx>
#include <WNT_MFTDraw.hxx>
#include <Aspect_Units.hxx>

#define CHAR_DESC_LEN 30000
#define MY_HDC (HDC)myDevContext
#define U2P(v) LONG( (v)/myPixelToUnit + 0.5 )
#define TRANSFORM(X,Y)                                           \
        { Standard_Real x = X,y = Y;                             \
          X = Standard_ShortReal(x*theCosAngle - y*theSinAngle); \
          Y = Standard_ShortReal(x*theSinAngle + y*theCosAngle); \
        }

enum TypeOfPoint {
  TOP_MOVETO, TOP_LINETO, TOP_CURVETO
};

static Standard_Integer   thePaintType;
static Standard_Integer   theTextColor;
static Aspect_TypeOfText  theTypeOfText;
static Standard_ShortReal theUnderlinePosition;
static Standard_ShortReal theXmin,theXmax;
static Standard_Integer   theNchar;
static Standard_Real      theSinAngle,theCosAngle;
static Standard_Real      theOrientation;
//////////////// Character description ///////////////
static int                myStrLen  = 0;
static POINT              myStrDesc [CHAR_DESC_LEN];
static TypeOfPoint        myStrInfo [CHAR_DESC_LEN];
static double             myBX, myBY;
static double             myCX, myCY;
static int                myCharWidth;
static int                myCharHeight;
static BOOL               myCharInside;

#define ADD_POINT(X,Y,aType)                                                         \
  myStrDesc[myStrLen].x = U2P( (X)+myBX );                                           \
  myStrDesc[myStrLen].y = ( myWin95 ? myDevHeight - U2P((Y)+myBY) : U2P((Y)+myBY) ); \
  myStrInfo[myStrLen]   = aType; myStrLen++;

#define CHECK_INSIDE(x,y)                                                 \
  if (!myCharInside)                                                      \
    if (myWin95) {                                                        \
      if ((x > -myCharWidth  && x < (myDevWidth  /*+ myCharWidth*/ )) &&  \
          (y > -myCharHeight && y < (myDevHeight + myCharHeight)))        \
        myCharInside = TRUE;                                              \
    } else {                                                              \
      if ((x > -myCharWidth  && x < (myDevWidth  /*+ myCharWidth */)) &&  \
          (y > -myCharHeight && y < (myDevHeight /*+ myCharHeight*/)))    \
        myCharInside = TRUE;                                              \
    }

#define CUR_X() myStrDesc[myStrLen-1].x
#define CUR_Y() myStrDesc[myStrLen-1].y

/*==================================================================*/
WNT_TextManager::WNT_TextManager(const Standard_Real aPixelToUnit)
{
  myPixelToUnit = aPixelToUnit;
  myDevContext  = 0;
  myDevHeight   = 0;
  // Clear the memory for STRING description
  ZeroMemory (myStrDesc, sizeof(myStrDesc));
  ZeroMemory (myStrInfo, sizeof(myStrInfo));
  myStrLen = 0;
}

/*==================================================================*/
void WNT_TextManager::BeginString(const Quantity_Length X,
                                  const Quantity_Length Y,
                                  const Quantity_PlaneAngle anOrientation,
                                  const Quantity_Length aWidth,
                                  const Quantity_Length aHeight,
                                  const Quantity_PlaneAngle aSlant,
                                  const Standard_Integer aPaintType)
{
  myStrLen       = 0;
  myCharWidth    = U2P(aWidth );
  myCharHeight   = U2P(aHeight);

  thePaintType   = aPaintType;
  theOrientation = anOrientation;
  myBX           = X;
  myBY           = Y;
  theNchar       = 0;
  theXmin        = theXmax = 0.F;
  if (!thePaintType) {
    if ((aHeight < (6. MILLIMETER)) || 
		    (theTypeOfText == Aspect_TOT_OUTLINE))
      thePaintType = 2;
  }
}

/*==================================================================*/
Standard_Boolean WNT_TextManager::BeginChar(const Standard_Integer aCharCode,
                                            const Standard_Real X,
                                            const Standard_Real Y)
{
  myCharInside = FALSE;
  return Standard_True;
}

/*==================================================================*/
Standard_Boolean WNT_TextManager::SetCharBoundingBox(const Quantity_Length X1,
                                                     const Quantity_Length Y1,
                                                     const Quantity_Length X2,
                                                     const Quantity_Length Y2,
                                                     const Quantity_Length X3,
                                                     const Quantity_Length Y3,
                                                     const Quantity_Length X4,
                                                     const Quantity_Length Y4)
{
  if (theUnderlinePosition > 0.) {
    if (!theNchar)
      theXmin = Standard_ShortReal (X1);
    theXmax   = Standard_ShortReal (Sqrt(X2*X2 + Y2*Y2));
  }
  return Standard_True;
}

/*==================================================================*/
Standard_Boolean WNT_TextManager::SetCharEncoding(const Standard_CString anEncoding)
{
  return Standard_True;
}

/*==================================================================*/
Standard_Boolean WNT_TextManager::Moveto(const Standard_Real X,
                                         const Standard_Real Y)
{
  ADD_POINT (X,Y,TOP_MOVETO);
  myCX = X; myCY = Y;
  CHECK_INSIDE (CUR_X(),CUR_Y());
  if (!myCharInside)
    myStrLen--;
  return myCharInside;
}

/*==================================================================*/
Standard_Boolean WNT_TextManager::Lineto(const Standard_Real X,
                                         const Standard_Real Y)
{
  ADD_POINT (X,Y,TOP_LINETO);
  CHECK_INSIDE (CUR_X(),CUR_Y());
  if (!myCharInside)
    myStrLen--;
  return myCharInside;
}

/*==================================================================*/
Standard_Boolean WNT_TextManager::Curveto(const Quantity_Length X1,
                                          const Quantity_Length Y1,
                                          const Quantity_Length X2,
                                          const Quantity_Length Y2,
                                          const Quantity_Length X3,
                                          const Quantity_Length Y3,
                                          const Quantity_Length X4,
                                          const Quantity_Length Y4)
{
  ADD_POINT (X2,Y2,TOP_CURVETO);
  ADD_POINT (X3,Y3,TOP_CURVETO);
  ADD_POINT (X4,Y4,TOP_CURVETO);
  return Standard_True;
}

/*==================================================================*/
void WNT_TextManager::ClosePath()
{
  ADD_POINT (myCX,myCY,TOP_LINETO);
  CHECK_INSIDE (CUR_X(),CUR_Y());
  if (!myCharInside)
    myStrLen--;
}

/*==================================================================*/
Standard_Boolean WNT_TextManager::EndChar(const Standard_Real X,
                                          const Standard_Real Y)
{
  theNchar++;
  return Standard_True;
}

/*==================================================================*/
void WNT_TextManager::EndString()
{
  static int i, j;

  // Draw text string
  i = 0;
  BeginPath (MY_HDC);
  do {
    switch (myStrInfo[i]) {
      case TOP_MOVETO:
        MoveToEx     (MY_HDC, myStrDesc[i].x, myStrDesc[i].y, NULL);
        break;
      case TOP_LINETO:
        j = i+1;
        while ((myStrInfo[j] == TOP_LINETO) && (j < myStrLen))
          j++;
        PolylineTo   (MY_HDC, &myStrDesc[i], j-i);
        i = j-1;
        break;
      case TOP_CURVETO:
        PolyBezierTo (MY_HDC, &myStrDesc[i], 3);
        i += 2;
        break;
      default:
        break;
    }
  } while (++i < myStrLen);
  EndPath (MY_HDC);
  if (thePaintType == 0 && !myMonoBuf) FillPath   (MY_HDC);
  else                                 StrokePath (MY_HDC);

  // Draw underline if necessary
  if (theUnderlinePosition > 0.) {
    Standard_ShortReal theX1 = theXmin;
    Standard_ShortReal theY1 = -theUnderlinePosition;
    Standard_ShortReal theX2 = theXmax;
    Standard_ShortReal theY2 = theY1;
    theSinAngle = Sin (theOrientation);
    theCosAngle = Cos (theOrientation);
    TRANSFORM (theX1, theY1);
    TRANSFORM (theX2, theY2);
    // Draw UNDERLINE
    if (myWin95) {
      MoveToEx     (MY_HDC, U2P(theX1 + myBX), myDevHeight - U2P(theY1 + myBY), NULL);
      LineTo       (MY_HDC, U2P(theX2 + myBX), myDevHeight - U2P(theY2 + myBY)      );
    } else {
      MoveToEx     (MY_HDC, U2P(theX1 + myBX), U2P(theY1 + myBY), NULL);
      LineTo       (MY_HDC, U2P(theX2 + myBX), U2P(theY2 + myBY)      );
    }
  }
}

/*==================================================================*/
void WNT_TextManager::SetTextAttribs(const Standard_Integer aTextColor,
                                     const Aspect_TypeOfText aTypeOfText,
                                     const Quantity_Length anUnderlinePosition)
{
  theTextColor         = aTextColor;
  theTypeOfText        = aTypeOfText;
  theUnderlinePosition = (Standard_ShortReal)anUnderlinePosition;
}

/*==================================================================*/
void WNT_TextManager::SetDrawAttribs(const Standard_Address aDrawData)
{
  PMFT_TEXTMAN_DATA aData = (PMFT_TEXTMAN_DATA)aDrawData;
  myDevContext = (int)aData->theHDC;
  myWin95      =      aData->theWin95;
  myDevWidth   =      aData->theDevWidth;
  myDevHeight  =      aData->theDevHeight;
  myUWidth     =      aData->theUWidth;
  myMonoBuf    =      aData->theMonoBuffer;
}