1 //GG_040298 eliminer les variables statiques globales.
3 #define PRO5676 //GG_020197
4 // Donner la possibillite d'exprimer la taille
5 // par rapport a la hauteur totale du caractere ou par
6 // rapport a la hauteur "ascent" situee au dessus de la
11 //GG_160498 etude G1343 gerer les polices transformables pour
12 // l'utilisation de MFT_FontManager.
14 // =====================================================================
15 // DCB_120598 study S3553. Platform specific code has been deleted
16 // ("#ifdef WNT") to be able to use on WNT the same font descriptor
17 // string like on UNIX.
18 // =====================================================================
20 // File Aspect_FontStyle.cxx
21 // Created Septembre 1993
24 //-Copyright MatraDatavision 1991,1992
28 //-Design Declaration des variables specifiques aux Fontures de textes
30 //-Warning Un style est definie, soit par son type predefini TOF_...
31 // soit par sa description (Font string de type ADOBE)
39 #define PITCHSIZE (0.00028 METER);
42 #include <Aspect_FontStyle.ixx>
43 #include <Aspect_Units.hxx>
48 //-Global data definitions
50 // MyFontType : TypeOfFont from Aspect;
51 // MyStyle : AsciiString from TCollection
52 // MyFontName : AsciiCString from TCollection
53 // MyFontSize : Real from Standard
54 // MyFontSlant : Real from Standard
55 // MyCapsHeight : Boolean from Standard
63 Aspect_FontStyle::Aspect_FontStyle () {
65 SetPredefinedStyle(Aspect_TOF_DEFAULT,0.003 METER,0.,Standard_False) ;
68 Aspect_FontStyle::Aspect_FontStyle (const Aspect_TypeOfFont Type, const Quantity_Length Size, const Quantity_PlaneAngle Slant, const Standard_Boolean CapsHeight) {
70 SetPredefinedStyle(Type,Size,Slant,CapsHeight) ;
73 Aspect_FontStyle::Aspect_FontStyle (const Standard_CString style, const Quantity_Length Size, const Quantity_PlaneAngle Slant, const Standard_Boolean CapsHeight) {
75 MyFontType = Aspect_TOF_USERDEFINED ;
78 MyCapsHeight = CapsHeight;
80 MyFontName = Normalize(style,MyFontSize) ;
83 Aspect_FontStyle::Aspect_FontStyle (const Standard_CString style) {
85 MyFontType = Aspect_TOF_USERDEFINED ;
88 MyCapsHeight = Standard_False;
90 MyFontName = Normalize(style,MyFontSize) ;
93 Aspect_FontStyle& Aspect_FontStyle::Assign (const Aspect_FontStyle& Other) {
95 MyFontType = Other.Style() ;
96 MyFontSize = Other.Size() ;
97 MyFontSlant = Other.Slant() ;
98 MyStyle = Other.Value();
99 MyFontName = Other.FullName() ;
100 MyCapsHeight = Other.CapsHeight() ;
105 void Aspect_FontStyle::SetValues ( const Aspect_TypeOfFont Type, const Quantity_Length Size, const Quantity_PlaneAngle Slant, const Standard_Boolean CapsHeight) {
107 SetPredefinedStyle (Type,Size,Slant,CapsHeight);
110 void Aspect_FontStyle::SetValues ( const Standard_CString style, const Quantity_Length Size, const Quantity_PlaneAngle Slant, const Standard_Boolean CapsHeight) {
111 MyFontType = Aspect_TOF_USERDEFINED ;
114 MyCapsHeight = CapsHeight;
116 MyFontName = Normalize(style,MyFontSize) ;
119 void Aspect_FontStyle::SetValues ( const Standard_CString style) {
120 MyFontType = Aspect_TOF_USERDEFINED ;
123 MyCapsHeight = Standard_False;
125 MyFontName = Normalize(style,MyFontSize) ;
128 // ============================================================================
129 // ---Purpose: Sets the family of the font.
130 // ============================================================================
132 void Aspect_FontStyle::SetFamily(const Standard_CString aName) {
133 MyFontName = SetField(MyFontName,aName,2);
136 // ============================================================================
137 // ---Purpose: Sets the weight of the font.
138 // ============================================================================
140 void Aspect_FontStyle::SetWeight(const Standard_CString aName) {
141 MyFontName = SetField(MyFontName,aName,3);
144 // ============================================================================
145 // ---Purpose: Sets the Registry of the font.
146 // ============================================================================
148 void Aspect_FontStyle::SetRegistry(const Standard_CString aName) {
149 MyFontName = SetField(MyFontName,aName,13);
152 // ============================================================================
153 // ---Purpose: Sets the Encoding of the font.
154 // ============================================================================
156 void Aspect_FontStyle::SetEncoding(const Standard_CString aName) {
157 MyFontName = SetField(MyFontName,aName,14);
160 Aspect_TypeOfFont Aspect_FontStyle::Style () const {
165 Standard_Integer Aspect_FontStyle::Length () const {
167 return MyStyle.Length();
170 Standard_CString Aspect_FontStyle::Value () const
172 return MyStyle.ToCString();
175 Quantity_Length Aspect_FontStyle::Size () const {
179 Quantity_PlaneAngle Aspect_FontStyle::Slant () const {
181 return (MyFontSlant);
184 Standard_Boolean Aspect_FontStyle::CapsHeight () const {
186 return (MyCapsHeight);
189 // ============================================================================
190 // ---Purpose: Returns the alias font name.
191 // -- this is a shorter font name which identify the
192 // -- main characteristics of the fonts.
193 // ---Example: "helvetica-bold"
194 // ============================================================================
196 Standard_CString Aspect_FontStyle::AliasName() const
198 static TCollection_AsciiString aliasname;
200 TCollection_AsciiString family(Family());
201 if( family.Length() > 0 && family != "*" ) {
202 TCollection_AsciiString FAMILY = family; FAMILY.UpperCase();
203 family.SetValue(1,FAMILY.Value(1));
206 TCollection_AsciiString weight(Weight());
207 if( weight.Length() > 0 && weight != "*" ) {
208 TCollection_AsciiString WEIGHT = weight; WEIGHT.UpperCase();
209 if( WEIGHT == "NORMAL" ) {
212 weight.SetValue(1,WEIGHT.Value(1));
214 } else weight.Clear();
215 TCollection_AsciiString sslant(SSlant());
216 if( sslant.Length() > 0 && sslant != "*" ) {
217 if( sslant == "r" ) {
219 } else if( sslant == "i" ) {
222 } else if( sslant == "o" ) {
226 } else sslant.Clear();
227 if( weight.Length() > 0 ) {
228 aliasname += '-'; aliasname += weight;
230 if( sslant.Length() > 0 ) {
231 aliasname += '-'; aliasname += sslant;
233 TCollection_AsciiString swidth(SWidth());
234 if( swidth.Length() > 0 && swidth != "*" ) {
235 TCollection_AsciiString SWIDTH = swidth; SWIDTH.UpperCase();
236 if( SWIDTH == "NORMAL" ) {
238 if( !weight.Length() ) aliasname += '-';
239 aliasname += '-'; aliasname += swidth;
242 return aliasname.ToCString();
244 // ============================================================================
245 // ---Purpose: Returns the full normalized font name
246 // ============================================================================
248 Standard_CString Aspect_FontStyle::FullName () const {
250 return (MyFontName.ToCString());
253 // ============================================================================
254 // ---Purpose: Returns the foundry of the font.
255 // ---Example: "adobe"
256 // ============================================================================
258 Standard_CString Aspect_FontStyle::Foundry() const
260 return Field(MyFontName,1);
263 // ============================================================================
264 // ---Purpose: Returns the family of the font.
265 // ---Example: "helvetica"
266 // ============================================================================
268 Standard_CString Aspect_FontStyle::Family() const
270 return Field(MyFontName,2);
273 // ============================================================================
274 // ---Purpose: Returns the weight of the font.
275 // ---Example: "bold"
276 // ============================================================================
278 Standard_CString Aspect_FontStyle::Weight() const
280 return Field(MyFontName,3);
283 // ============================================================================
284 // ---Purpose: Returns the char set registry of the font.
285 // ---Example: "iso8859"
286 // ============================================================================
288 Standard_CString Aspect_FontStyle::Registry() const
290 return Field(MyFontName,13);
293 // ============================================================================
294 // ---Purpose: Returns the char set encoding of the font.
296 // ============================================================================
298 Standard_CString Aspect_FontStyle::Encoding() const
300 return Field(MyFontName,14);
303 // ============================================================================
304 // ---Purpose: Returns the slant of the font.
306 // ============================================================================
308 Standard_CString Aspect_FontStyle::SSlant() const
310 return Field(MyFontName,4);
313 // ============================================================================
314 // ---Purpose: Returns the width name of the font.
315 // ---Example: "normal"
316 // ============================================================================
318 Standard_CString Aspect_FontStyle::SWidth() const
320 return Field(MyFontName,5);
323 // ============================================================================
324 // ---Purpose: Returns the style name of the font.
325 // ---Example: "serif"
326 // ============================================================================
328 Standard_CString Aspect_FontStyle::SStyle() const
330 return Field(MyFontName,6);
333 // ============================================================================
334 // ---Purpose: Returns the pixel size of the font.
336 // ============================================================================
338 Standard_CString Aspect_FontStyle::SPixelSize() const
340 return Field(MyFontName,7);
343 // ============================================================================
344 // ---Purpose: Returns the point size of the font.
346 // ============================================================================
348 Standard_CString Aspect_FontStyle::SPointSize() const
350 return Field(MyFontName,8);
352 // ============================================================================
353 // ---Purpose: Returns the resolution X of the font.
355 // ============================================================================
357 Standard_CString Aspect_FontStyle::SResolutionX() const
359 return Field(MyFontName,9);
362 // ============================================================================
363 // ---Purpose: Returns the resolution Y of the font.
365 // ============================================================================
367 Standard_CString Aspect_FontStyle::SResolutionY() const
369 return Field(MyFontName,10);
372 // ============================================================================
373 // ---Purpose: Returns the spacing of the font.
375 // ============================================================================
377 Standard_CString Aspect_FontStyle::SSpacing() const
379 return Field(MyFontName,11);
382 // ============================================================================
383 // ---Purpose: Returns the average width of the font.
385 // ============================================================================
387 Standard_CString Aspect_FontStyle::SAverageWidth() const
389 return Field(MyFontName,12);
392 // ============================================================================
393 // ---Purpose: Dumps the font attributes.
394 // ============================================================================
396 void Aspect_FontStyle::Dump() const
398 cout << ".Aspect_FontStyle::Dump() :" << endl;
399 cout << "-----------------" << endl << endl;
400 cout << " style name is : '" << this->Value() << "'" << endl;
401 cout << " Normalized font name is : '" << this->FullName() << "'" << endl;
402 cout << " Alias font name is : '" << this->AliasName() << "'" << endl;
403 cout << " Foundry is : '" << this->Foundry() << "'" << endl;
404 cout << " Family is : '" << this->Family() << "'" << endl;
405 cout << " Weight is : '" << this->Weight() << "'" << endl;
406 cout << " Slant is : '" << this->SSlant() << "'" << endl;
407 cout << " Width is : '" << this->SWidth() << "'" << endl;
408 cout << " Style is : '" << this->SStyle() << "'" << endl;
409 cout << " PixelSize is : '" << this->SPixelSize() << "'" << endl;
410 cout << " PointSize is : '" << this->SPointSize() << "'" << endl;
411 cout << " ResolutionX is : '" << this->SResolutionX() << "'" << endl;
412 cout << " ResolutionY is : '" << this->SResolutionY() << "'" << endl;
413 cout << " Spacing is : '" << this->SSpacing() << "'" << endl;
414 cout << " AverageWidth is : '" << this->SAverageWidth() << "'" << endl;
415 cout << " Registry is : '" << this->Registry() << "'" << endl;
416 cout << " Encoding is : '" << this->Encoding() << "'" << endl << endl;
419 void Aspect_FontStyle::SetPredefinedStyle( const Aspect_TypeOfFont Type, const Quantity_Length Size, const Quantity_PlaneAngle Slant, const Standard_Boolean CapsHeight) {
422 Aspect_FontStyleDefinitionError::Raise ("Bad font Size");
426 MyFontSlant = Slant ;
427 MyCapsHeight = CapsHeight;
428 Standard_CString pstyle = "" ;
430 case Aspect_TOF_USERDEFINED :
431 Aspect_FontStyleDefinitionError::Raise ("Bad Font Type Style");
432 case Aspect_TOF_DEFAULT :
433 pstyle = "Defaultfont" ;
435 case Aspect_TOF_COURIER :
438 case Aspect_TOF_HELVETICA :
439 pstyle = "Helvetica" ;
441 case Aspect_TOF_TIMES :
446 MyFontName = Normalize(pstyle,MyFontSize);
449 Standard_Boolean Aspect_FontStyle::IsEqual(const Aspect_FontStyle& Other) const
452 (MyFontType == Other.MyFontType) &&
453 (MyFontName.Length() == Other.MyFontName.Length()) &&
454 (MyFontName == Other.MyFontName) &&
455 (MyFontSize == Other.MyFontSize) &&
456 (MyFontSlant == Other.MyFontSlant) &&
457 (MyCapsHeight == Other.MyCapsHeight)
462 Standard_Boolean Aspect_FontStyle::IsNotEqual(const Aspect_FontStyle& Other) const
464 return !IsEqual(Other);
467 // ============================================================================
468 // ---Purpose: Returns a normalized XLFD descriptor from the font name
470 // ============================================================================
472 Standard_CString Aspect_FontStyle::Normalize(const Standard_CString aFontName,Standard_Real& aSize)
474 Aspect_FontStyleDefinitionError_Raise_if(
475 !aFontName ,"NULL font descriptor");
477 static TCollection_AsciiString afontstring;
478 static TCollection_AsciiString astar("*");
479 static TCollection_AsciiString azero("0");
480 TCollection_AsciiString afield,afontname(aFontName);
481 Standard_CString pfontname = NULL;
482 Standard_Boolean xlfd = Standard_False;
483 Standard_Integer i,len = afontname.Length();
487 if( len <= 0 ) return pfontname;
489 if( afontname.Value(1) != '-' ) afontname.Prepend("-adobe-");
490 for( i=1 ; i<=MAXFIELDS ; i++ ) {
491 Standard_CString pfield = Field(afontname,i);
495 afield = pfield; afield.LowerCase();
496 {afontstring += '-'; afontstring += afield;}
498 afontstring += "-adobe";
503 afield = pfield; afield.LowerCase();
504 if( afield == astar ) {
505 if( aSize > 0. ) afontstring += "-*";
506 else {afontstring += "-0"; xlfd = Standard_True;}
507 } else if( afield == azero ) { afontstring += "-0"; xlfd = Standard_True;}
508 else {afontstring += '-'; afontstring += afield;}
510 if( aSize > 0. ) afontstring += "-*";
511 else { afontstring += "-0"; xlfd = Standard_True;}
519 } else if( pfield ) {
520 afield = pfield; afield.LowerCase();
521 afontstring += '-'; afontstring += afield;
528 afield = pfield; afield.LowerCase();
529 afontstring += '-'; afontstring += afield;
537 afontstring += '-'; afontstring += afield;
543 pfontname = afontstring.ToCString();
545 Standard_CString psize = Field(pfontname,7);
546 Standard_Integer isize;
547 if( sscanf(psize,"%d",&isize) == 1 ) {
548 aSize = isize*PITCHSIZE;
550 aSize = 2. MILLIMETER;
557 // ============================================================================
558 // ---Purpose: Returns the field at position <aRank>
559 // -- from the font name <aFontName>.
560 // ============================================================================
562 Standard_CString Aspect_FontStyle::Field(const TCollection_AsciiString& aFontName,const Standard_Integer aRank)
564 static TCollection_AsciiString afieldstring;
565 Standard_Integer length = aFontName.Length();
566 Standard_CString pfield = NULL;
568 if( length > 0 && aRank >= 1 && aRank <= MAXFIELDS ) {
569 Standard_Integer start = 1,end = 0;
570 start = aFontName.Location(aRank,'-',1,length);
571 end = aFontName.Location(aRank+1,'-',1,length);
573 if( start > 0 && end > 0 ) {
576 if( end >= start ) afieldstring = aFontName.SubString(start,end);
577 else afieldstring = "";
578 } else if( start > 0 ) {
581 if( end >= start ) afieldstring = aFontName.SubString(start,end);
582 else afieldstring = "";
587 pfield = afieldstring.ToCString();
592 // ============================================================================
593 // ---Purpose: Sets the field at position <aRank>
594 // -- of the font <aFontName>
595 // -- from the field <aField>.
596 // ============================================================================
598 Standard_CString Aspect_FontStyle::SetField(const TCollection_AsciiString& aFontName,const Standard_CString aField,const Standard_Integer aRank)
600 static TCollection_AsciiString afontstring;
601 Standard_Integer length = aFontName.Length();
602 Standard_CString pfontname = NULL;
604 if( length > 0 && aRank >= 1 && aRank <= MAXFIELDS ) {
605 Standard_Integer start = 1,end = 0;
606 start = aFontName.Location(aRank,'-',1,length);
607 end = aFontName.Location(aRank+1,'-',1,length);
608 TCollection_AsciiString lowername(""),uppername("");
609 if( start > 0 && end > 0 ) {
611 if( start > 1 ) lowername = aFontName.SubString(1,start);
612 uppername = aFontName.SubString(end,length);
614 } else if( start > 1 ) {
615 lowername = aFontName.SubString(1,start);
619 afontstring = lowername;
620 afontstring += aField; afontstring += uppername;
621 pfontname = afontstring.ToCString();