source: Sophya/trunk/SophyaPI/PI/pifontmac.cc@ 369

Last change on this file since 369 was 369, checked in by ercodmgr, 26 years ago

pour le mac

File size: 3.3 KB
Line 
1// Module PI : Peida Interactive PIFontMac
2// Gestion de fontes - Implementation Mac
3// DAPNIA/SPP E. Aubourg 1999
4
5#include <stdio.h>
6
7#include "pisysdep.h"
8#include "pifontmac.h"
9#include PIWDG_H
10
11#include "UDrawingState.h"
12
13/* --Methode-- */
14PIFontMac::PIFontMac(PIFontName fn)
15 : PIFontGen(fn)
16{
17 SelectFont(fn, PI_RomanFont, PI_NormalSizeFont);
18}
19
20/* --Methode-- */
21PIFontMac::PIFontMac(int npt, PIFontName fn, PIFontAtt fa)
22 : PIFontGen(npt, fn, fa)
23{
24 SelectFontPt(fn, fa, npt);
25}
26
27/* --Methode-- */
28PIFontMac::PIFontMac(PIFontMac const & fnt)
29 : PIFontGen(fnt.mFName)
30{
31 SelectFontPt(fnt.mFName, fnt.mFAtt, fnt.mFSize);
32}
33
34/* --Methode-- */
35PIFontMac::~PIFontMac()
36{
37}
38
39/* --Methode-- */
40PIFontMac & PIFontMac::operator = (PIFontMac const & fnt)
41{
42 SelectFontPt(fnt.mFName, fnt.mFAtt, fnt.mFSize);
43 return(*this);
44}
45
46/* --Methode-- */
47bool PIFontMac::operator == (PIFontMac const & fnt)
48{
49 if ((fnt.mFName == mFName) && (fnt.mFAtt == mFAtt) && (fnt.mFSize == mFSize))
50 return(true);
51 else
52 return(false);
53}
54
55/* --Methode-- */
56void PIFontMac::SetFont(PIFontName fn)
57{
58 SelectFontPt(fn, mFAtt, mFSize);
59}
60
61/* --Methode-- */
62void PIFontMac::SetFontAtt(PIFontAtt fa)
63{
64 SelectFontPt(mFName, fa, mFSize);
65}
66
67/* --Methode-- */
68void PIFontMac::SetFontSz(PIFontSize fs)
69{
70 SelectFont(mFName, mFAtt, fs);
71}
72
73/* --Methode-- */
74void PIFontMac::SetFontSzPt(int npt)
75{
76 SelectFontPt(mFName, mFAtt, npt);
77}
78
79/* --Methode-- */
80PIFontName PIFontMac::GetFontName()
81{
82 return(mFName);
83}
84
85/* --Methode-- */
86PIFontAtt PIFontMac::GetFontAtt()
87{
88 return(mFAtt);
89}
90
91/* --Methode-- */
92int PIFontMac::GetFontSize()
93{
94 return(mFSize);
95}
96
97/* --Methode-- */
98void PIFontMac::Apply()
99{
100 ::TextFont(mFNum);
101 ::TextSize(mFSize);
102 ::TextFace(mFStyle);
103}
104
105/* --Methode-- */
106int PIFontMac::GetFontHeight(int& asc, int& desc)
107{
108 StTextState saver;
109 Apply();
110 ::FontInfo finfo;
111 GetFontInfo(&finfo);
112 asc = finfo.ascent;
113 desc = finfo.descent;
114 return(asc+desc);
115}
116
117/* --Methode-- */
118int PIFontMac::GetStringWidth(char const* s)
119{
120 StTextState saver;
121 Apply();
122 return(::TextWidth(s, 0, strlen(s)));
123}
124
125
126#define NMAXFONTSZ 7
127#define NMAXFONTATT 3
128#define NMAXFONTTYP 5
129
130/* Variables globales pour la gestion des fontes */
131static const int fontSizes[4] = {8,12,18,24};
132
133/* --Methode-- */
134void PIFontMac::SelectFont(PIFontName fn, PIFontAtt fa, PIFontSize fs)
135{
136 if (fs < 0 || fs >=4) fs = PI_NormalSizeFont;
137 int isz = fontSizes[fs];
138 SelectFontPt(fn, fa, isz);
139}
140
141/* --Methode-- */
142void PIFontMac::SelectFontPt(PIFontName fn, PIFontAtt fa, int npt)
143{
144 if ((fn == mFName) && (fa == mFAtt) && (npt == mFSize)) return;
145 mFName = fn;
146 mFAtt = fa;
147 mFSize = npt;
148
149 switch (fa) {
150 case PI_RomanFont :
151 mFStyle = 0;
152 break;
153 case PI_BoldFont :
154 mFStyle = bold;
155 break;
156 case PI_ItalicFont :
157 mFStyle = italic;
158 break;
159 default :
160 mFStyle = 0;
161 break;
162 }
163
164 switch (fn) {
165 case PI_DefaultFont :
166 mFNum = 0;
167 break;
168 case PI_CourierFont :
169 GetFNum("\pCourier", &mFNum);
170 break;
171 case PI_HelveticaFont :
172 GetFNum("\pHelvetica", &mFNum);
173 break;
174 case PI_TimesFont :
175 GetFNum("\pTimes", &mFNum);
176 break;
177 case PI_SymbolFont :
178 GetFNum("\pSymbol", &mFNum);
179 break;
180 default :
181 mFNum = 0;
182 break;
183 }
184}
185
Note: See TracBrowser for help on using the repository browser.