fd37e907589ae2840a8449a510a056a23b340601
[occt.git] / src / Font / Font_SystemFont.cxx
1 // Created on: 2008-01-20
2 // Created by: Alexander A. BORODIN
3 // Copyright (c) 2008-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
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
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.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #include <Font_SystemFont.hxx>
17
18 #include <Font_FontMgr.hxx>
19 #include <OSD_Path.hxx>
20
21 IMPLEMENT_STANDARD_RTTIEXT(Font_SystemFont, Standard_Transient)
22
23 // =======================================================================
24 // function : Font_SystemFont
25 // purpose  :
26 // =======================================================================
27 Font_SystemFont::Font_SystemFont (const TCollection_AsciiString& theFontName)
28 : myFontKey (theFontName),
29   myFontName (theFontName),
30   myIsSingleLine (Standard_False)
31 {
32   if (theFontName.IsEmpty()) { throw Standard_ProgramError ("Font_SystemFont constructor called with empty font name"); }
33   myFontKey.LowerCase();
34 }
35
36 // =======================================================================
37 // function : SetFontPath
38 // purpose  :
39 // =======================================================================
40 void Font_SystemFont::SetFontPath (Font_FontAspect theAspect,
41                                    const TCollection_AsciiString& thePath)
42 {
43   if (theAspect == Font_FontAspect_UNDEFINED) { throw Standard_ProgramError ("Font_SystemFont::SetFontPath() called with UNDEFINED aspect"); }
44   myFilePaths[theAspect] = thePath;
45 }
46
47 // =======================================================================
48 // function : IsEqual
49 // purpose  :
50 // =======================================================================
51 Standard_Boolean Font_SystemFont::IsEqual (const Handle(Font_SystemFont)& theOtherFont) const
52 {
53   return theOtherFont.get() == this
54       || myFontKey.IsEqual (theOtherFont->myFontKey);
55 }
56
57 // =======================================================================
58 // function : ToString
59 // purpose  :
60 // =======================================================================
61 TCollection_AsciiString Font_SystemFont::ToString() const
62 {
63   TCollection_AsciiString aDesc;
64   aDesc += TCollection_AsciiString() + "'" + myFontName + "'";
65
66   bool isFirstAspect = true;
67   aDesc += " [aspects: ";
68   for (int anAspectIter = 0; anAspectIter < Font_FontAspect_NB; ++anAspectIter)
69   {
70     if (!HasFontAspect ((Font_FontAspect )anAspectIter))
71     {
72       continue;
73     }
74
75     if (!isFirstAspect)
76     {
77       aDesc += ",";
78     }
79     else
80     {
81       isFirstAspect = false;
82     }
83     aDesc += Font_FontMgr::FontAspectToString ((Font_FontAspect )anAspectIter);
84   }
85   aDesc += "]";
86
87   isFirstAspect = true;
88   aDesc += " [paths: ";
89   for (int anAspectIter = 0; anAspectIter < Font_FontAspect_NB; ++anAspectIter)
90   {
91     if (!HasFontAspect ((Font_FontAspect )anAspectIter))
92     {
93       continue;
94     }
95
96     if (!isFirstAspect)
97     {
98       aDesc += ";";
99     }
100     else
101     {
102       isFirstAspect = false;
103     }
104     aDesc += FontPath ((Font_FontAspect )anAspectIter);
105   }
106   aDesc += "]";
107   return aDesc;
108 }