summaryrefslogtreecommitdiff
path: root/src/WNT/WNT_FontMapEntry.cxx
blob: 00157f5d903c4f0bbf819b6694b7a02478a8250d (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
#include <WNT_FontMapEntry.ixx>

#include <InterfaceGraphic_WNT.hxx>

#include <stdlib.h>
#include <string.h>						 

// character for field separator
#define FS "-"
// character for default value
#define DV "*"

WNT_FontMapEntry :: WNT_FontMapEntry ( const Standard_CString aFontName )
{
  int   i;
  char* p;

  char* fName = new char[ strlen ( aFontName ) + 1 ];

  strcpy ( fName, aFontName );
  ZeroMemory (  &myLogFont, sizeof ( WNT_LogFont )  );

  myLogFont.lfCharSet        = DEFAULT_CHARSET;
  myLogFont.lfOutPrecision   = OUT_DEFAULT_PRECIS;
  myLogFont.lfClipPrecision  = CLIP_DEFAULT_PRECIS;
  myLogFont.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
  myLogFont.lfQuality        = PROOF_QUALITY;

  p = strtok ( fName, FS );
  if (  p && strcmp ( p, DV )  )
    myLogFont.lfHeight = atol ( p );

  p = strtok ( NULL, FS );
  if (  p && strcmp ( p, DV )  )
    myLogFont.lfWidth = atol ( p );

  p = strtok ( NULL, FS );
  if (  p && strcmp ( p, DV )  )
    myLogFont.lfEscapement = atol ( p );

  p = strtok ( NULL, FS );
  if (  p && strcmp ( p, DV )  )
    myLogFont.lfOrientation = atol ( p );

  p = strtok ( NULL, FS );
  if (  p && strcmp ( p, DV )  )
    myLogFont.lfWeight = atol ( p );

  p = strtok ( NULL, FS );
  if (  p && strcmp ( p, DV )  )
    myLogFont.lfItalic = ( BYTE )atoi ( p );

  p = strtok ( NULL, FS );
  if (  p && strcmp ( p, DV )  )
    myLogFont.lfUnderline = ( BYTE )atoi ( p );

  p = strtok ( NULL, FS );
  if (  p && strcmp ( p, DV )  )
    myLogFont.lfStrikeOut = ( BYTE )atoi ( p );

  p = strtok ( NULL, FS );
  if (  p && strcmp ( p, DV )  )
    myLogFont.lfCharSet = ( BYTE )atoi ( p );

  p = strtok ( NULL, FS );
  if (  p && strcmp ( p, DV )  )
    myLogFont.lfOutPrecision = ( BYTE )atoi ( p );

  p = strtok ( NULL, FS );
  if (  p && strcmp ( p, DV )  )
    myLogFont.lfClipPrecision = ( BYTE )atoi ( p );

  p = strtok ( NULL, FS );
  if (  p && strcmp ( p, DV )  )
    myLogFont.lfQuality = ( BYTE )atoi ( p );

  p = strtok ( NULL, FS );
  if (  p && strcmp ( p, DV )  )
    myLogFont.lfPitchAndFamily = ( BYTE )atoi ( p );

  p = strtok ( NULL, FS );
  if (  p && strcmp ( p, DV )  ) {
    i = strlen ( p );
    strncpy (  myLogFont.lfFaceName, p, ( i < LF_FACESIZE ) ? i : LF_FACESIZE  );
  }  // end if

  myLogFont.lfOutPrecision |= OUT_TT_ONLY_PRECIS;
  myHandle = CreateFontIndirect ( &myLogFont );
  delete [] fName;
  if ( !myHandle )
    WNT_FontMapEntryDefinitionError :: Raise ( "Unable to load font" );
}  // end constructor

void WNT_FontMapEntry :: Destroy () {

 DeleteObject ( myHandle );

}  // end WNT_FontMapEntry :: Destroy 

Aspect_Handle WNT_FontMapEntry :: HFont () const {

 return myHandle;

}  // WNT_FontMapEntry :: HFont

Aspect_Handle WNT_FontMapEntry :: SetAttrib (
                                const WNT_Dword& aFlags,
                                const Standard_Address aData,
                                const Standard_Boolean aRepl
                               ) {

 HFONT      hFont;
 LOGFONT    lf = myLogFont;
 FONT_DATA* fd = ( FONT_DATA* )aData;

 if ( aFlags & faUnderlined )

  lf.lfUnderline = BYTE(fd -> fdUnderlined);

 if ( aFlags & faItalic )

  lf.lfItalic = BYTE(fd -> fdItalic);

 if ( aFlags & faStrikeOut )

  lf.lfStrikeOut = BYTE(fd -> fdStrikeOut);

 if ( aFlags & faBold )

  lf.lfWeight = fd -> fdBold;

 if ( aFlags & faHeight )

  lf.lfHeight = fd -> fdHeight;

 if ( aFlags & faAngle ) {

  lf.lfEscapement  = fd -> fdOrientation;
  lf.lfOrientation = fd -> fdOrientation;

 }  // end if

 if ( aFlags & faWidth )

  lf.lfWidth = fd -> fdWidth;

 if ( aFlags & faSlant )

  lf.lfOrientation -= ( fd -> fdSlant * 10 );

 hFont = CreateFontIndirect ( &lf );

 if ( hFont != NULL && aRepl ) {
 
  DeleteObject ( myHandle );
  myHandle  = hFont;
  myLogFont = lf;

 }  // end if

 return hFont;

}  // WNT_FontMapEntry :: SetAttrib