0024911: Avoid using virtual functions in NCollection classes
[occt.git] / src / Font / Font_SystemFont.cxx
CommitLineData
b311480e 1// Created on: 2008-01-20
2// Created by: Alexander A. BORODIN
973c2be1 3// Copyright (c) 2008-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
7fd59977 15
7fd59977 16// Updated:
17
eeaaaefb 18#include <Font_SystemFont.ixx>
7fd59977 19#include <OSD_Path.hxx>
20#include <TCollection_HAsciiString.hxx>
21
22
eeaaaefb 23Font_SystemFont::Font_SystemFont():
7fd59977 24MyFontName(),
eeaaaefb 25MyFontAspect(Font_FA_Undefined),
7fd59977 26MyFaceSize(-1),
27MyVerification(Standard_False)
28{
29}
30
eeaaaefb 31Font_SystemFont::Font_SystemFont( const Handle(TCollection_HAsciiString)& FontName,
32 const Font_FontAspect FontAspect,
7fd59977 33 const Handle(TCollection_HAsciiString)& FilePath ):
34MyFontName(FontName),
35MyFontAspect(FontAspect),
7fd59977 36MyFaceSize(-1),
a174a3c5 37MyFilePath(FilePath),
7fd59977 38MyVerification(Standard_True)
39{
40
41}
42
aff395a3 43Font_SystemFont::Font_SystemFont (const Handle(TCollection_HAsciiString)& theXLFD,
44 const Handle(TCollection_HAsciiString)& theFilePath) :
a174a3c5 45MyFontAspect(Font_FA_Regular),
46MyFaceSize(-1),
47MyFilePath(theFilePath)
7fd59977 48{
49 MyVerification = Standard_True;
aff395a3 50 if (theXLFD.IsNull())
7fd59977 51 {
aff395a3 52 MyVerification = Standard_False; // empty font description handler
7fd59977 53 }
aff395a3 54 if (theXLFD->IsEmpty())
7fd59977 55 {
aff395a3 56 MyVerification = Standard_False; // empty font description
7fd59977 57 }
58
aff395a3 59 if (MyVerification)
7fd59977 60 {
aff395a3 61 MyFontName = theXLFD->Token ("-", 2);
62 TCollection_AsciiString aXLFD (theXLFD->ToCString());
7fd59977 63
aff395a3 64 // Getting font size for fixed size fonts
65 if (aXLFD.Search ("-0-0-0-0-") >= 0)
66 MyFaceSize = -1; // Scalable font
7fd59977 67 else
68 //TODO catch exeption
aff395a3 69 MyFaceSize = aXLFD.Token ("-", 7).IntegerValue();
7fd59977 70
aff395a3 71 // Detect font aspect
a174a3c5 72 if (aXLFD.Token ("-", 3).IsEqual ("bold") &&
aff395a3 73 (aXLFD.Token ("-", 4).IsEqual ("i") || aXLFD.Token ("-", 4).IsEqual ("o")))
74 {
75 MyFontAspect = Font_FA_BoldItalic;
76 }
77 else if (aXLFD.Token ("-", 3).IsEqual ("bold"))
78 {
eeaaaefb 79 MyFontAspect = Font_FA_Bold;
aff395a3 80 }
81 else if (aXLFD.Token ("-", 4).IsEqual ("i") || aXLFD.Token ("-", 4).IsEqual ("o"))
7fd59977 82 {
aff395a3 83 MyFontAspect = Font_FA_Italic;
7fd59977 84 }
85 }
86}
87
eeaaaefb 88Standard_Boolean Font_SystemFont::IsValid() const{
7fd59977 89 if ( !MyVerification)
90 return Standard_False;
91
eeaaaefb 92 if ( MyFontAspect == Font_FA_Undefined )
7fd59977 93 return Standard_False;
94
95 if ( MyFontName->IsEmpty() || !MyFontName->IsAscii() )
96 return Standard_False;
97
a174a3c5 98 OSD_Path path;
7fd59977 99 return path.IsValid( MyFilePath->String() );
100}
101
eeaaaefb 102Handle(TCollection_HAsciiString) Font_SystemFont::FontPath() const{
7fd59977 103 return MyFilePath;
104}
105
eeaaaefb 106Handle(TCollection_HAsciiString) Font_SystemFont::FontName() const{
7fd59977 107 return MyFontName;
108}
109
eeaaaefb 110Font_FontAspect Font_SystemFont::FontAspect() const{
7fd59977 111 return MyFontAspect;
112}
113
eeaaaefb 114Standard_Integer Font_SystemFont::FontHeight() const {
7fd59977 115 return MyFaceSize;
116}
aff395a3 117
118Standard_Boolean Font_SystemFont::IsEqual(const Handle(Font_SystemFont)& theOtherFont) const
119{
120 if (!MyFontName->IsSameString (theOtherFont->FontName(), Standard_False))
121 {
122 return Standard_False;
123 }
124
125 if (MyFontAspect != theOtherFont->FontAspect())
126 {
127 return Standard_False;
128 }
129
130 if (MyFaceSize != theOtherFont->FontHeight())
131 {
132 return Standard_False;
133 }
134
135 return Standard_True;
136}