1 // Copyright (c) 1996-1999 Matra Datavision
2 // Copyright (c) 1999-2012 OPEN CASCADE SAS
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.
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.
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.
19 #include <WNT_FontMapEntry.ixx>
21 #include <InterfaceGraphic_WNT.hxx>
26 // character for field separator
28 // character for default value
31 WNT_FontMapEntry :: WNT_FontMapEntry ( const Standard_CString aFontName )
36 char* fName = new char[ strlen ( aFontName ) + 1 ];
38 strcpy ( fName, aFontName );
39 ZeroMemory ( &myLogFont, sizeof ( WNT_LogFont ) );
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;
47 p = strtok ( fName, FS );
48 if ( p && strcmp ( p, DV ) )
49 myLogFont.lfHeight = atol ( p );
51 p = strtok ( NULL, FS );
52 if ( p && strcmp ( p, DV ) )
53 myLogFont.lfWidth = atol ( p );
55 p = strtok ( NULL, FS );
56 if ( p && strcmp ( p, DV ) )
57 myLogFont.lfEscapement = atol ( p );
59 p = strtok ( NULL, FS );
60 if ( p && strcmp ( p, DV ) )
61 myLogFont.lfOrientation = atol ( p );
63 p = strtok ( NULL, FS );
64 if ( p && strcmp ( p, DV ) )
65 myLogFont.lfWeight = atol ( p );
67 p = strtok ( NULL, FS );
68 if ( p && strcmp ( p, DV ) )
69 myLogFont.lfItalic = ( BYTE )atoi ( p );
71 p = strtok ( NULL, FS );
72 if ( p && strcmp ( p, DV ) )
73 myLogFont.lfUnderline = ( BYTE )atoi ( p );
75 p = strtok ( NULL, FS );
76 if ( p && strcmp ( p, DV ) )
77 myLogFont.lfStrikeOut = ( BYTE )atoi ( p );
79 p = strtok ( NULL, FS );
80 if ( p && strcmp ( p, DV ) )
81 myLogFont.lfCharSet = ( BYTE )atoi ( p );
83 p = strtok ( NULL, FS );
84 if ( p && strcmp ( p, DV ) )
85 myLogFont.lfOutPrecision = ( BYTE )atoi ( p );
87 p = strtok ( NULL, FS );
88 if ( p && strcmp ( p, DV ) )
89 myLogFont.lfClipPrecision = ( BYTE )atoi ( p );
91 p = strtok ( NULL, FS );
92 if ( p && strcmp ( p, DV ) )
93 myLogFont.lfQuality = ( BYTE )atoi ( p );
95 p = strtok ( NULL, FS );
96 if ( p && strcmp ( p, DV ) )
97 myLogFont.lfPitchAndFamily = ( BYTE )atoi ( p );
99 p = strtok ( NULL, FS );
100 if ( p && strcmp ( p, DV ) ) {
102 strncpy ( myLogFont.lfFaceName, p, ( i < LF_FACESIZE ) ? i : LF_FACESIZE );
105 myLogFont.lfOutPrecision |= OUT_TT_ONLY_PRECIS;
106 myHandle = CreateFontIndirect ( &myLogFont );
109 WNT_FontMapEntryDefinitionError :: Raise ( "Unable to load font" );
112 void WNT_FontMapEntry :: Destroy () {
114 DeleteObject ( myHandle );
116 } // end WNT_FontMapEntry :: Destroy
118 Aspect_Handle WNT_FontMapEntry :: HFont () const {
122 } // WNT_FontMapEntry :: HFont
124 Aspect_Handle WNT_FontMapEntry :: SetAttrib (
125 const WNT_Dword& aFlags,
126 const Standard_Address aData,
127 const Standard_Boolean aRepl
131 LOGFONT lf = myLogFont;
132 FONT_DATA* fd = ( FONT_DATA* )aData;
134 if ( aFlags & faUnderlined )
136 lf.lfUnderline = fd -> fdUnderlined;
138 if ( aFlags & faItalic )
140 lf.lfItalic = fd -> fdItalic;
142 if ( aFlags & faStrikeOut )
144 lf.lfStrikeOut = fd -> fdStrikeOut;
146 if ( aFlags & faBold )
148 lf.lfWeight = fd -> fdBold;
150 if ( aFlags & faHeight )
152 lf.lfHeight = fd -> fdHeight;
154 if ( aFlags & faAngle ) {
156 lf.lfEscapement = fd -> fdOrientation;
157 lf.lfOrientation = fd -> fdOrientation;
161 if ( aFlags & faWidth )
163 lf.lfWidth = fd -> fdWidth;
165 if ( aFlags & faSlant )
167 lf.lfOrientation -= ( fd -> fdSlant * 10 );
169 hFont = CreateFontIndirect ( &lf );
171 if ( hFont != NULL && aRepl ) {
173 DeleteObject ( myHandle );
181 } // WNT_FontMapEntry :: SetAttrib