0023370: MSVC++ warnings issued during compilation for 64bits, WNT_FontMapEntry.cxx
[occt.git] / src / WNT / WNT_FontMapEntry.cxx
CommitLineData
b311480e 1// Copyright (c) 1996-1999 Matra Datavision
2// Copyright (c) 1999-2012 OPEN CASCADE SAS
3//
4// The content of this file is subject to the Open CASCADE Technology Public
5// License Version 6.5 (the "License"). You may not use the content of this file
6// except in compliance with the License. Please obtain a copy of the License
7// at http://www.opencascade.org and read it completely before using this file.
8//
9// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11//
12// The Original Code and all software distributed under the License is
13// distributed on an "AS IS" basis, without warranty of any kind, and the
14// Initial Developer hereby disclaims all such warranties, including without
15// limitation, any warranties of merchantability, fitness for a particular
16// purpose or non-infringement. Please see the License for the specific terms
17// and conditions governing the rights and limitations under the License.
18
7fd59977 19#include <WNT_FontMapEntry.ixx>
20
21#include <InterfaceGraphic_WNT.hxx>
22
23#include <stdlib.h>
24#include <string.h>
25
26// character for field separator
27#define FS "-"
28// character for default value
29#define DV "*"
30
31WNT_FontMapEntry :: WNT_FontMapEntry ( const Standard_CString aFontName )
32{
2ac09710 33 Standard_Size i;
7fd59977 34 char* p;
7fd59977 35
36 char* fName = new char[ strlen ( aFontName ) + 1 ];
37
38 strcpy ( fName, aFontName );
39 ZeroMemory ( &myLogFont, sizeof ( WNT_LogFont ) );
40
41 myLogFont.lfCharSet = DEFAULT_CHARSET;
42 myLogFont.lfOutPrecision = OUT_DEFAULT_PRECIS;
43 myLogFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
44 myLogFont.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
45 myLogFont.lfQuality = PROOF_QUALITY;
46
47 p = strtok ( fName, FS );
48 if ( p && strcmp ( p, DV ) )
49 myLogFont.lfHeight = atol ( p );
50
51 p = strtok ( NULL, FS );
52 if ( p && strcmp ( p, DV ) )
53 myLogFont.lfWidth = atol ( p );
54
55 p = strtok ( NULL, FS );
56 if ( p && strcmp ( p, DV ) )
57 myLogFont.lfEscapement = atol ( p );
58
59 p = strtok ( NULL, FS );
60 if ( p && strcmp ( p, DV ) )
61 myLogFont.lfOrientation = atol ( p );
62
63 p = strtok ( NULL, FS );
64 if ( p && strcmp ( p, DV ) )
65 myLogFont.lfWeight = atol ( p );
66
67 p = strtok ( NULL, FS );
68 if ( p && strcmp ( p, DV ) )
69 myLogFont.lfItalic = ( BYTE )atoi ( p );
70
71 p = strtok ( NULL, FS );
72 if ( p && strcmp ( p, DV ) )
73 myLogFont.lfUnderline = ( BYTE )atoi ( p );
74
75 p = strtok ( NULL, FS );
76 if ( p && strcmp ( p, DV ) )
77 myLogFont.lfStrikeOut = ( BYTE )atoi ( p );
78
79 p = strtok ( NULL, FS );
80 if ( p && strcmp ( p, DV ) )
81 myLogFont.lfCharSet = ( BYTE )atoi ( p );
82
83 p = strtok ( NULL, FS );
84 if ( p && strcmp ( p, DV ) )
85 myLogFont.lfOutPrecision = ( BYTE )atoi ( p );
86
87 p = strtok ( NULL, FS );
88 if ( p && strcmp ( p, DV ) )
89 myLogFont.lfClipPrecision = ( BYTE )atoi ( p );
90
91 p = strtok ( NULL, FS );
92 if ( p && strcmp ( p, DV ) )
93 myLogFont.lfQuality = ( BYTE )atoi ( p );
94
95 p = strtok ( NULL, FS );
96 if ( p && strcmp ( p, DV ) )
97 myLogFont.lfPitchAndFamily = ( BYTE )atoi ( p );
98
99 p = strtok ( NULL, FS );
100 if ( p && strcmp ( p, DV ) ) {
101 i = strlen ( p );
102 strncpy ( myLogFont.lfFaceName, p, ( i < LF_FACESIZE ) ? i : LF_FACESIZE );
103 } // end if
104
105 myLogFont.lfOutPrecision |= OUT_TT_ONLY_PRECIS;
106 myHandle = CreateFontIndirect ( &myLogFont );
107 delete [] fName;
108 if ( !myHandle )
109 WNT_FontMapEntryDefinitionError :: Raise ( "Unable to load font" );
110} // end constructor
111
112void WNT_FontMapEntry :: Destroy () {
113
114 DeleteObject ( myHandle );
115
116} // end WNT_FontMapEntry :: Destroy
117
118Aspect_Handle WNT_FontMapEntry :: HFont () const {
119
120 return myHandle;
121
122} // WNT_FontMapEntry :: HFont
123
124Aspect_Handle WNT_FontMapEntry :: SetAttrib (
125 const WNT_Dword& aFlags,
126 const Standard_Address aData,
127 const Standard_Boolean aRepl
128 ) {
129
130 HFONT hFont;
131 LOGFONT lf = myLogFont;
132 FONT_DATA* fd = ( FONT_DATA* )aData;
133
134 if ( aFlags & faUnderlined )
135
136 lf.lfUnderline = fd -> fdUnderlined;
137
138 if ( aFlags & faItalic )
139
140 lf.lfItalic = fd -> fdItalic;
141
142 if ( aFlags & faStrikeOut )
143
144 lf.lfStrikeOut = fd -> fdStrikeOut;
145
146 if ( aFlags & faBold )
147
148 lf.lfWeight = fd -> fdBold;
149
150 if ( aFlags & faHeight )
151
152 lf.lfHeight = fd -> fdHeight;
153
154 if ( aFlags & faAngle ) {
155
156 lf.lfEscapement = fd -> fdOrientation;
157 lf.lfOrientation = fd -> fdOrientation;
158
159 } // end if
160
161 if ( aFlags & faWidth )
162
163 lf.lfWidth = fd -> fdWidth;
164
165 if ( aFlags & faSlant )
166
167 lf.lfOrientation -= ( fd -> fdSlant * 10 );
168
169 hFont = CreateFontIndirect ( &lf );
170
171 if ( hFont != NULL && aRepl ) {
172
173 DeleteObject ( myHandle );
174 myHandle = hFont;
175 myLogFont = lf;
176
177 } // end if
178
179 return hFont;
180
181} // WNT_FontMapEntry :: SetAttrib