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

Last change on this file since 2615 was 2615, checked in by cmv, 21 years ago

using namespace sophya enleve de machdefs.h, nouveau sopnamsp.h cmv 10/09/2004

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