1 // Created on: 1993-09-14
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
21 //GG_040298 eliminer les variables statiques globales.
23 #define PRO5676 //GG_020197
24 // Donner la possibillite d'exprimer la taille
25 // par rapport a la hauteur totale du caractere ou par
26 // rapport a la hauteur "ascent" situee au dessus de la
30 //GG_160498 etude G1343 gerer les polices transformables pour
31 // l'utilisation de MFT_FontManager.
33 // =====================================================================
34 // DCB_120598 study S3553. Platform specific code has been deleted
35 // ("#ifdef WNT") to be able to use on WNT the same font descriptor
36 // string like on UNIX.
37 // =====================================================================
43 //-Design Declaration des variables specifiques aux Fontures de textes
45 //-Warning Un style est definie, soit par son type predefini TOF_...
46 // soit par sa description (Font string de type ADOBE)
54 #define PITCHSIZE (0.00028 METER);
57 #include <Aspect_FontStyle.ixx>
58 #include <Aspect_Units.hxx>
63 //-Global data definitions
65 // MyFontType : TypeOfFont from Aspect;
66 // MyStyle : AsciiString from TCollection
67 // MyFontName : AsciiCString from TCollection
68 // MyFontSize : Real from Standard
69 // MyFontSlant : Real from Standard
70 // MyCapsHeight : Boolean from Standard
78 Aspect_FontStyle::Aspect_FontStyle () {
80 SetPredefinedStyle(Aspect_TOF_DEFAULT,0.003 METER,0.,Standard_False) ;
83 Aspect_FontStyle::Aspect_FontStyle (const Aspect_TypeOfFont Type, const Quantity_Length Size, const Quantity_PlaneAngle Slant, const Standard_Boolean CapsHeight) {
85 SetPredefinedStyle(Type,Size,Slant,CapsHeight) ;
88 Aspect_FontStyle::Aspect_FontStyle (const Standard_CString style, const Quantity_Length Size, const Quantity_PlaneAngle Slant, const Standard_Boolean CapsHeight) {
90 MyFontType = Aspect_TOF_USERDEFINED ;
93 MyCapsHeight = CapsHeight;
95 MyFontName = Normalize(style,MyFontSize) ;
98 Aspect_FontStyle::Aspect_FontStyle (const Standard_CString style) {
100 MyFontType = Aspect_TOF_USERDEFINED ;
103 MyCapsHeight = Standard_False;
105 MyFontName = Normalize(style,MyFontSize) ;
108 Aspect_FontStyle& Aspect_FontStyle::Assign (const Aspect_FontStyle& Other) {
110 MyFontType = Other.Style() ;
111 MyFontSize = Other.Size() ;
112 MyFontSlant = Other.Slant() ;
113 MyStyle = Other.Value();
114 MyFontName = Other.FullName() ;
115 MyCapsHeight = Other.CapsHeight() ;
120 void Aspect_FontStyle::SetValues ( const Aspect_TypeOfFont Type, const Quantity_Length Size, const Quantity_PlaneAngle Slant, const Standard_Boolean CapsHeight) {
122 SetPredefinedStyle (Type,Size,Slant,CapsHeight);
125 void Aspect_FontStyle::SetValues ( const Standard_CString style, const Quantity_Length Size, const Quantity_PlaneAngle Slant, const Standard_Boolean CapsHeight) {
126 MyFontType = Aspect_TOF_USERDEFINED ;
129 MyCapsHeight = CapsHeight;
131 MyFontName = Normalize(style,MyFontSize) ;
134 void Aspect_FontStyle::SetValues ( const Standard_CString style) {
135 MyFontType = Aspect_TOF_USERDEFINED ;
138 MyCapsHeight = Standard_False;
140 MyFontName = Normalize(style,MyFontSize) ;
143 // ============================================================================
144 // ---Purpose: Sets the family of the font.
145 // ============================================================================
147 void Aspect_FontStyle::SetFamily(const Standard_CString aName) {
148 MyFontName = SetField(MyFontName,aName,2);
151 // ============================================================================
152 // ---Purpose: Sets the weight of the font.
153 // ============================================================================
155 void Aspect_FontStyle::SetWeight(const Standard_CString aName) {
156 MyFontName = SetField(MyFontName,aName,3);
159 // ============================================================================
160 // ---Purpose: Sets the Registry of the font.
161 // ============================================================================
163 void Aspect_FontStyle::SetRegistry(const Standard_CString aName) {
164 MyFontName = SetField(MyFontName,aName,13);
167 // ============================================================================
168 // ---Purpose: Sets the Encoding of the font.
169 // ============================================================================
171 void Aspect_FontStyle::SetEncoding(const Standard_CString aName) {
172 MyFontName = SetField(MyFontName,aName,14);
175 Aspect_TypeOfFont Aspect_FontStyle::Style () const {
180 Standard_Integer Aspect_FontStyle::Length () const {
182 return MyStyle.Length();
185 Standard_CString Aspect_FontStyle::Value () const
187 return MyStyle.ToCString();
190 Quantity_Length Aspect_FontStyle::Size () const {
194 Quantity_PlaneAngle Aspect_FontStyle::Slant () const {
196 return (MyFontSlant);
199 Standard_Boolean Aspect_FontStyle::CapsHeight () const {
201 return (MyCapsHeight);
204 // ============================================================================
205 // ---Purpose: Returns the alias font name.
206 // -- this is a shorter font name which identify the
207 // -- main characteristics of the fonts.
208 // ---Example: "helvetica-bold"
209 // ============================================================================
211 Standard_CString Aspect_FontStyle::AliasName() const
213 static TCollection_AsciiString aliasname;
215 TCollection_AsciiString family(Family());
216 if( family.Length() > 0 && family != "*" ) {
217 TCollection_AsciiString FAMILY = family; FAMILY.UpperCase();
218 family.SetValue(1,FAMILY.Value(1));
221 TCollection_AsciiString weight(Weight());
222 if( weight.Length() > 0 && weight != "*" ) {
223 TCollection_AsciiString WEIGHT = weight; WEIGHT.UpperCase();
224 if( WEIGHT == "NORMAL" ) {
227 weight.SetValue(1,WEIGHT.Value(1));
229 } else weight.Clear();
230 TCollection_AsciiString sslant(SSlant());
231 if( sslant.Length() > 0 && sslant != "*" ) {
232 if( sslant == "r" ) {
234 } else if( sslant == "i" ) {
237 } else if( sslant == "o" ) {
241 } else sslant.Clear();
242 if( weight.Length() > 0 ) {
243 aliasname += '-'; aliasname += weight;
245 if( sslant.Length() > 0 ) {
246 aliasname += '-'; aliasname += sslant;
248 TCollection_AsciiString swidth(SWidth());
249 if( swidth.Length() > 0 && swidth != "*" ) {
250 TCollection_AsciiString SWIDTH = swidth; SWIDTH.UpperCase();
251 if( SWIDTH == "NORMAL" ) {
253 if( !weight.Length() ) aliasname += '-';
254 aliasname += '-'; aliasname += swidth;
257 return aliasname.ToCString();
259 // ============================================================================
260 // ---Purpose: Returns the full normalized font name
261 // ============================================================================
263 Standard_CString Aspect_FontStyle::FullName () const {
265 return (MyFontName.ToCString());
268 // ============================================================================
269 // ---Purpose: Returns the foundry of the font.
270 // ---Example: "adobe"
271 // ============================================================================
273 Standard_CString Aspect_FontStyle::Foundry() const
275 return Field(MyFontName,1);
278 // ============================================================================
279 // ---Purpose: Returns the family of the font.
280 // ---Example: "helvetica"
281 // ============================================================================
283 Standard_CString Aspect_FontStyle::Family() const
285 return Field(MyFontName,2);
288 // ============================================================================
289 // ---Purpose: Returns the weight of the font.
290 // ---Example: "bold"
291 // ============================================================================
293 Standard_CString Aspect_FontStyle::Weight() const
295 return Field(MyFontName,3);
298 // ============================================================================
299 // ---Purpose: Returns the char set registry of the font.
300 // ---Example: "iso8859"
301 // ============================================================================
303 Standard_CString Aspect_FontStyle::Registry() const
305 return Field(MyFontName,13);
308 // ============================================================================
309 // ---Purpose: Returns the char set encoding of the font.
311 // ============================================================================
313 Standard_CString Aspect_FontStyle::Encoding() const
315 return Field(MyFontName,14);
318 // ============================================================================
319 // ---Purpose: Returns the slant of the font.
321 // ============================================================================
323 Standard_CString Aspect_FontStyle::SSlant() const
325 return Field(MyFontName,4);
328 // ============================================================================
329 // ---Purpose: Returns the width name of the font.
330 // ---Example: "normal"
331 // ============================================================================
333 Standard_CString Aspect_FontStyle::SWidth() const
335 return Field(MyFontName,5);
338 // ============================================================================
339 // ---Purpose: Returns the style name of the font.
340 // ---Example: "serif"
341 // ============================================================================
343 Standard_CString Aspect_FontStyle::SStyle() const
345 return Field(MyFontName,6);
348 // ============================================================================
349 // ---Purpose: Returns the pixel size of the font.
351 // ============================================================================
353 Standard_CString Aspect_FontStyle::SPixelSize() const
355 return Field(MyFontName,7);
358 // ============================================================================
359 // ---Purpose: Returns the point size of the font.
361 // ============================================================================
363 Standard_CString Aspect_FontStyle::SPointSize() const
365 return Field(MyFontName,8);
367 // ============================================================================
368 // ---Purpose: Returns the resolution X of the font.
370 // ============================================================================
372 Standard_CString Aspect_FontStyle::SResolutionX() const
374 return Field(MyFontName,9);
377 // ============================================================================
378 // ---Purpose: Returns the resolution Y of the font.
380 // ============================================================================
382 Standard_CString Aspect_FontStyle::SResolutionY() const
384 return Field(MyFontName,10);
387 // ============================================================================
388 // ---Purpose: Returns the spacing of the font.
390 // ============================================================================
392 Standard_CString Aspect_FontStyle::SSpacing() const
394 return Field(MyFontName,11);
397 // ============================================================================
398 // ---Purpose: Returns the average width of the font.
400 // ============================================================================
402 Standard_CString Aspect_FontStyle::SAverageWidth() const
404 return Field(MyFontName,12);
407 // ============================================================================
408 // ---Purpose: Dumps the font attributes.
409 // ============================================================================
411 void Aspect_FontStyle::Dump() const
413 cout << ".Aspect_FontStyle::Dump() :" << endl;
414 cout << "-----------------" << endl << endl;
415 cout << " style name is : '" << this->Value() << "'" << endl;
416 cout << " Normalized font name is : '" << this->FullName() << "'" << endl;
417 cout << " Alias font name is : '" << this->AliasName() << "'" << endl;
418 cout << " Foundry is : '" << this->Foundry() << "'" << endl;
419 cout << " Family is : '" << this->Family() << "'" << endl;
420 cout << " Weight is : '" << this->Weight() << "'" << endl;
421 cout << " Slant is : '" << this->SSlant() << "'" << endl;
422 cout << " Width is : '" << this->SWidth() << "'" << endl;
423 cout << " Style is : '" << this->SStyle() << "'" << endl;
424 cout << " PixelSize is : '" << this->SPixelSize() << "'" << endl;
425 cout << " PointSize is : '" << this->SPointSize() << "'" << endl;
426 cout << " ResolutionX is : '" << this->SResolutionX() << "'" << endl;
427 cout << " ResolutionY is : '" << this->SResolutionY() << "'" << endl;
428 cout << " Spacing is : '" << this->SSpacing() << "'" << endl;
429 cout << " AverageWidth is : '" << this->SAverageWidth() << "'" << endl;
430 cout << " Registry is : '" << this->Registry() << "'" << endl;
431 cout << " Encoding is : '" << this->Encoding() << "'" << endl << endl;
434 void Aspect_FontStyle::SetPredefinedStyle( const Aspect_TypeOfFont Type, const Quantity_Length Size, const Quantity_PlaneAngle Slant, const Standard_Boolean CapsHeight) {
437 Aspect_FontStyleDefinitionError::Raise ("Bad font Size");
441 MyFontSlant = Slant ;
442 MyCapsHeight = CapsHeight;
443 Standard_CString pstyle = "" ;
445 case Aspect_TOF_USERDEFINED :
446 Aspect_FontStyleDefinitionError::Raise ("Bad Font Type Style");
447 case Aspect_TOF_DEFAULT :
448 pstyle = "Defaultfont" ;
450 case Aspect_TOF_COURIER :
453 case Aspect_TOF_HELVETICA :
454 pstyle = "Helvetica" ;
456 case Aspect_TOF_TIMES :
461 MyFontName = Normalize(pstyle,MyFontSize);
464 Standard_Boolean Aspect_FontStyle::IsEqual(const Aspect_FontStyle& Other) const
467 (MyFontType == Other.MyFontType) &&
468 (MyFontName.Length() == Other.MyFontName.Length()) &&
469 (MyFontName == Other.MyFontName) &&
470 (MyFontSize == Other.MyFontSize) &&
471 (MyFontSlant == Other.MyFontSlant) &&
472 (MyCapsHeight == Other.MyCapsHeight)
477 Standard_Boolean Aspect_FontStyle::IsNotEqual(const Aspect_FontStyle& Other) const
479 return !IsEqual(Other);
482 // ============================================================================
483 // ---Purpose: Returns a normalized XLFD descriptor from the font name
485 // ============================================================================
487 Standard_CString Aspect_FontStyle::Normalize(const Standard_CString aFontName,Standard_Real& aSize)
489 Aspect_FontStyleDefinitionError_Raise_if(
490 !aFontName ,"NULL font descriptor");
492 static TCollection_AsciiString afontstring;
493 static TCollection_AsciiString astar("*");
494 static TCollection_AsciiString azero("0");
495 TCollection_AsciiString afield,afontname(aFontName);
496 Standard_CString pfontname = NULL;
497 Standard_Boolean xlfd = Standard_False;
498 Standard_Integer i,len = afontname.Length();
502 if( len <= 0 ) return pfontname;
504 if( afontname.Value(1) != '-' ) afontname.Prepend("-adobe-");
505 for( i=1 ; i<=MAXFIELDS ; i++ ) {
506 Standard_CString pfield = Field(afontname,i);
510 afield = pfield; afield.LowerCase();
511 {afontstring += '-'; afontstring += afield;}
513 afontstring += "-adobe";
518 afield = pfield; afield.LowerCase();
519 if( afield == astar ) {
520 if( aSize > 0. ) afontstring += "-*";
521 else {afontstring += "-0"; xlfd = Standard_True;}
522 } else if( afield == azero ) { afontstring += "-0"; xlfd = Standard_True;}
523 else {afontstring += '-'; afontstring += afield;}
525 if( aSize > 0. ) afontstring += "-*";
526 else { afontstring += "-0"; xlfd = Standard_True;}
534 } else if( pfield ) {
535 afield = pfield; afield.LowerCase();
536 afontstring += '-'; afontstring += afield;
543 afield = pfield; afield.LowerCase();
544 afontstring += '-'; afontstring += afield;
552 afontstring += '-'; afontstring += afield;
558 pfontname = afontstring.ToCString();
560 Standard_CString psize = Field(pfontname,7);
561 Standard_Integer isize;
562 if( sscanf(psize,"%d",&isize) == 1 ) {
563 aSize = isize*PITCHSIZE;
565 aSize = 2. MILLIMETER;
572 // ============================================================================
573 // ---Purpose: Returns the field at position <aRank>
574 // -- from the font name <aFontName>.
575 // ============================================================================
577 Standard_CString Aspect_FontStyle::Field(const TCollection_AsciiString& aFontName,const Standard_Integer aRank)
579 static TCollection_AsciiString afieldstring;
580 Standard_Integer length = aFontName.Length();
581 Standard_CString pfield = NULL;
583 if( length > 0 && aRank >= 1 && aRank <= MAXFIELDS ) {
584 Standard_Integer start = 1,end = 0;
585 start = aFontName.Location(aRank,'-',1,length);
586 end = aFontName.Location(aRank+1,'-',1,length);
588 if( start > 0 && end > 0 ) {
591 if( end >= start ) afieldstring = aFontName.SubString(start,end);
592 else afieldstring = "";
593 } else if( start > 0 ) {
596 if( end >= start ) afieldstring = aFontName.SubString(start,end);
597 else afieldstring = "";
602 pfield = afieldstring.ToCString();
607 // ============================================================================
608 // ---Purpose: Sets the field at position <aRank>
609 // -- of the font <aFontName>
610 // -- from the field <aField>.
611 // ============================================================================
613 Standard_CString Aspect_FontStyle::SetField(const TCollection_AsciiString& aFontName,const Standard_CString aField,const Standard_Integer aRank)
615 static TCollection_AsciiString afontstring;
616 Standard_Integer length = aFontName.Length();
617 Standard_CString pfontname = NULL;
619 if( length > 0 && aRank >= 1 && aRank <= MAXFIELDS ) {
620 Standard_Integer start = 1,end = 0;
621 start = aFontName.Location(aRank,'-',1,length);
622 end = aFontName.Location(aRank+1,'-',1,length);
623 TCollection_AsciiString lowername(""),uppername("");
624 if( start > 0 && end > 0 ) {
626 if( start > 1 ) lowername = aFontName.SubString(1,start);
627 uppername = aFontName.SubString(end,length);
629 } else if( start > 1 ) {
630 lowername = aFontName.SubString(1,start);
634 afontstring = lowername;
635 afontstring += aField; afontstring += uppername;
636 pfontname = afontstring.ToCString();