Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3a50f8a

Browse files
committed
- Added FontInfo support
- Added (read-)access to members of [C]GrafPort object
1 parent bf220a1 commit 3a50f8a

5 files changed

Lines changed: 178 additions & 37 deletions

File tree

Mac/Lib/toolbox/QuickDraw.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Generated from 'Sap:CodeWarrior7:Metrowerks CodeWarrior:MacOS Support:Headers:Universal Headers:QuickDraw.h'
1+
# Generated from 'flap:CodeWarrior:Metrowerks CodeWarrior:MacOS Support:Headers:Universal Headers:QuickDraw.h'
22

33
invalColReq = -1
44
srcCopy = 0
@@ -90,7 +90,7 @@
9090
kHorizontalConstraint = 2
9191
kCursorImageMajorVersion = 0x0001
9292
kCursorImageMinorVersion = 0x0000
93-
# Generated from 'Sap:CodeWarrior7:Metrowerks CodeWarrior:MacOS Support:Headers:Universal Headers:QuickDrawText.h'
93+
# Generated from 'flap:CodeWarrior:Metrowerks CodeWarrior:MacOS Support:Headers:Universal Headers:QuickDrawText.h'
9494

9595
leftCaret = 0
9696
rightCaret = -1

Mac/Modules/qd/Qdmodule.c

Lines changed: 91 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,19 @@ QdRGB_Convert(v, p_itself)
7474
return 1;
7575
}
7676

77+
/*
78+
** Generate FontInfo records
79+
*/
80+
static
81+
PyObject *QdFI_New(itself)
82+
FontInfo *itself;
83+
{
84+
85+
return Py_BuildValue("hhhh", itself->ascent, itself->descent,
86+
itself->widMax, itself->leading);
87+
}
88+
89+
7790

7891
static PyObject *Qd_Error;
7992

@@ -132,21 +145,70 @@ static PyObject *GrafObj_getattr(self, name)
132145
GrafPortObject *self;
133146
char *name;
134147
{
135-
if ( strcmp(name, "device") == 0 )
136-
return PyInt_FromLong((long)self->ob_itself->device);
137-
if ( strcmp(name, "portBits") == 0 ) {
138-
CGrafPtr itself_color = (CGrafPtr)self->ob_itself;
148+
149+
{ CGrafPtr itself_color = (CGrafPtr)self->ob_itself;
150+
151+
if ( strcmp(name, "data") == 0 )
152+
return PyString_FromStringAndSize((char *)self->ob_itself, sizeof(GrafPort));
153+
154+
if ( (itself_color->portVersion&0xc000) == 0xc000 ) {
155+
/* Color-only attributes */
139156

140-
if ( (itself_color->portVersion&0xc000) == 0xc000 )
141-
/* XXXX Do we need HLock() stuff here?? */
142-
return BMObj_New((BitMapPtr)*itself_color->portPixMap);
143-
else
144-
return BMObj_New(&self->ob_itself->portBits);
157+
if ( strcmp(name, "portBits") == 0 )
158+
/* XXXX Do we need HLock() stuff here?? */
159+
return BMObj_New((BitMapPtr)*itself_color->portPixMap);
160+
if ( strcmp(name, "grafVars") == 0 )
161+
return Py_BuildValue("O&", ResObj_New, (Handle)itself_color->visRgn);
162+
if ( strcmp(name, "chExtra") == 0 )
163+
return Py_BuildValue("h", itself_color->chExtra);
164+
if ( strcmp(name, "pnLocHFrac") == 0 )
165+
return Py_BuildValue("h", itself_color->pnLocHFrac);
166+
} else {
167+
/* Mono-only attributes */
168+
if ( strcmp(name, "portBits") == 0 )
169+
return BMObj_New(&self->ob_itself->portBits);
170+
}
171+
/*
172+
** Accessible for both color/mono windows.
173+
** portVersion is really color-only, but we put it here
174+
** for convenience
175+
*/
176+
if ( strcmp(name, "portVersion") == 0 )
177+
return Py_BuildValue("h", itself_color->portVersion);
178+
if ( strcmp(name, "device") == 0 )
179+
return PyInt_FromLong((long)self->ob_itself->device);
180+
if ( strcmp(name, "portRect") == 0 )
181+
return Py_BuildValue("O&", PyMac_BuildRect, &self->ob_itself->portRect);
182+
if ( strcmp(name, "visRgn") == 0 )
183+
return Py_BuildValue("O&", ResObj_New, (Handle)self->ob_itself->visRgn);
184+
if ( strcmp(name, "clipRgn") == 0 )
185+
return Py_BuildValue("O&", ResObj_New, (Handle)self->ob_itself->clipRgn);
186+
if ( strcmp(name, "bkPat") == 0 )
187+
return Py_BuildValue("s#", (char *)&self->ob_itself->bkPat, sizeof(Pattern));
188+
if ( strcmp(name, "fillPat") == 0 )
189+
return Py_BuildValue("s#", (char *)&self->ob_itself->fillPat, sizeof(Pattern));
190+
if ( strcmp(name, "pnLoc") == 0 )
191+
return Py_BuildValue("O&", PyMac_BuildPoint, self->ob_itself->pnLoc);
192+
if ( strcmp(name, "pnSize") == 0 )
193+
return Py_BuildValue("O&", PyMac_BuildPoint, self->ob_itself->pnSize);
194+
if ( strcmp(name, "pnMode") == 0 )
195+
return Py_BuildValue("h", self->ob_itself->pnMode);
196+
if ( strcmp(name, "pnPat") == 0 )
197+
return Py_BuildValue("s#", (char *)&self->ob_itself->pnPat, sizeof(Pattern));
198+
if ( strcmp(name, "pnVis") == 0 )
199+
return Py_BuildValue("h", self->ob_itself->pnVis);
200+
if ( strcmp(name, "txFont") == 0 )
201+
return Py_BuildValue("h", self->ob_itself->txFont);
202+
if ( strcmp(name, "txFace") == 0 )
203+
return Py_BuildValue("h", (short)self->ob_itself->txFace);
204+
if ( strcmp(name, "txMode") == 0 )
205+
return Py_BuildValue("h", self->ob_itself->txMode);
206+
if ( strcmp(name, "txSize") == 0 )
207+
return Py_BuildValue("h", self->ob_itself->txSize);
208+
if ( strcmp(name, "spExtra") == 0 )
209+
return Py_BuildValue("O&", PyMac_BuildFixed, self->ob_itself->spExtra);
210+
/* XXXX Add more, as needed */
145211
}
146-
if ( strcmp(name, "portRect") == 0 )
147-
return Py_BuildValue("O&", PyMac_BuildRect, &self->ob_itself->portRect);
148-
/* XXXX Add more, as needed */
149-
150212
return Py_FindMethodInChain(&GrafObj_chain, (PyObject *)self, name);
151213
}
152214

@@ -3323,6 +3385,20 @@ static PyObject *Qd_TextWidth(_self, _args)
33233385
return _res;
33243386
}
33253387

3388+
static PyObject *Qd_GetFontInfo(_self, _args)
3389+
PyObject *_self;
3390+
PyObject *_args;
3391+
{
3392+
PyObject *_res = NULL;
3393+
FontInfo info;
3394+
if (!PyArg_ParseTuple(_args, ""))
3395+
return NULL;
3396+
GetFontInfo(&info);
3397+
_res = Py_BuildValue("O&",
3398+
QdFI_New, &info);
3399+
return _res;
3400+
}
3401+
33263402
static PyObject *Qd_CharExtra(_self, _args)
33273403
PyObject *_self;
33283404
PyObject *_args;
@@ -3738,6 +3814,8 @@ static PyMethodDef Qd_methods[] = {
37383814
"(Str255 s) -> (short _rv)"},
37393815
{"TextWidth", (PyCFunction)Qd_TextWidth, 1,
37403816
"(Buffer textBuf, short firstByte, short byteCount) -> (short _rv)"},
3817+
{"GetFontInfo", (PyCFunction)Qd_GetFontInfo, 1,
3818+
"() -> (FontInfo info)"},
37413819
{"CharExtra", (PyCFunction)Qd_CharExtra, 1,
37423820
"(Fixed extra) -> None"},
37433821
{"BitMap", (PyCFunction)Qd_BitMap, 1,

Mac/Modules/qd/qdgen.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Generated from 'Sap:CodeWarrior7:Metrowerks CodeWarrior:MacOS Support:Headers:Universal Headers:QuickDraw.h'
1+
# Generated from 'flap:CodeWarrior:Metrowerks CodeWarrior:MacOS Support:Headers:Universal Headers:QuickDraw.h'
22

33
f = Function(void, 'SetPort',
44
(GrafPtr, 'port', InMode),
@@ -926,7 +926,7 @@
926926
)
927927
functions.append(f)
928928

929-
# Generated from 'Sap:CodeWarrior7:Metrowerks CodeWarrior:MacOS Support:Headers:Universal Headers:QuickDrawText.h'
929+
# Generated from 'flap:CodeWarrior:Metrowerks CodeWarrior:MacOS Support:Headers:Universal Headers:QuickDrawText.h'
930930

931931
f = Function(void, 'TextFont',
932932
(short, 'font', InMode),
@@ -987,6 +987,11 @@
987987
)
988988
functions.append(f)
989989

990+
f = Function(void, 'GetFontInfo',
991+
(FontInfo, 'info', OutMode),
992+
)
993+
functions.append(f)
994+
990995
f = Function(void, 'CharExtra',
991996
(Fixed, 'extra', InMode),
992997
)

Mac/Modules/qd/qdscan.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,12 @@ def makeblacklisttypes(self):
8585
'ColorSearchProcPtr',
8686
'ColorSearchUPP',
8787
'ConstPatternParam',
88-
## 'Pattern_ptr',
89-
## 'Pattern',
90-
## 'Cursor_ptr',
9188
'DeviceLoopDrawingProcPtr',
9289
'DeviceLoopFlags',
93-
'FontInfo',
90+
## 'FontInfo',
9491
'GDHandle',
9592
'GrafVerb',
9693
'OpenCPicParams_ptr',
97-
## 'PenState',
98-
## 'PenState_ptr',
9994
'Ptr',
10095
'QDProcs',
10196
'ReqListRec',

Mac/Modules/qd/qdsupport.py

Lines changed: 77 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ def getargsCheck(self, name):
4545
BitMap_ptr = OpaqueByValueType("BitMapPtr", "BMObj")
4646
RGBColor = OpaqueType('RGBColor', 'QdRGB')
4747
RGBColor_ptr = RGBColor
48+
FontInfo = OpaqueType('FontInfo', 'QdFI')
4849

4950
Cursor_ptr = StructInputBufferType('Cursor')
5051
Pattern = StructOutputBufferType('Pattern')
@@ -82,6 +83,19 @@ def getargsCheck(self, name):
8283
return 1;
8384
}
8485
86+
/*
87+
** Generate FontInfo records
88+
*/
89+
static
90+
PyObject *QdFI_New(itself)
91+
FontInfo *itself;
92+
{
93+
94+
return Py_BuildValue("hhhh", itself->ascent, itself->descent,
95+
itself->widMax, itself->leading);
96+
}
97+
98+
8599
"""
86100

87101
variablestuff = """
@@ -133,21 +147,70 @@ def outputCheckConvertArg(self):
133147
Output("return 1;")
134148
OutRbrace()
135149
def outputGetattrHook(self):
136-
Output("""if ( strcmp(name, "device") == 0 )
137-
return PyInt_FromLong((long)self->ob_itself->device);
138-
if ( strcmp(name, "portBits") == 0 ) {
139-
CGrafPtr itself_color = (CGrafPtr)self->ob_itself;
150+
Output("""
151+
{ CGrafPtr itself_color = (CGrafPtr)self->ob_itself;
152+
153+
if ( strcmp(name, "data") == 0 )
154+
return PyString_FromStringAndSize((char *)self->ob_itself, sizeof(GrafPort));
155+
156+
if ( (itself_color->portVersion&0xc000) == 0xc000 ) {
157+
/* Color-only attributes */
140158
141-
if ( (itself_color->portVersion&0xc000) == 0xc000 )
142-
/* XXXX Do we need HLock() stuff here?? */
143-
return BMObj_New((BitMapPtr)*itself_color->portPixMap);
144-
else
145-
return BMObj_New(&self->ob_itself->portBits);
146-
}
147-
if ( strcmp(name, "portRect") == 0 )
148-
return Py_BuildValue("O&", PyMac_BuildRect, &self->ob_itself->portRect);
149-
/* XXXX Add more, as needed */
150-
""")
159+
if ( strcmp(name, "portBits") == 0 )
160+
/* XXXX Do we need HLock() stuff here?? */
161+
return BMObj_New((BitMapPtr)*itself_color->portPixMap);
162+
if ( strcmp(name, "grafVars") == 0 )
163+
return Py_BuildValue("O&", ResObj_New, (Handle)itself_color->visRgn);
164+
if ( strcmp(name, "chExtra") == 0 )
165+
return Py_BuildValue("h", itself_color->chExtra);
166+
if ( strcmp(name, "pnLocHFrac") == 0 )
167+
return Py_BuildValue("h", itself_color->pnLocHFrac);
168+
} else {
169+
/* Mono-only attributes */
170+
if ( strcmp(name, "portBits") == 0 )
171+
return BMObj_New(&self->ob_itself->portBits);
172+
}
173+
/*
174+
** Accessible for both color/mono windows.
175+
** portVersion is really color-only, but we put it here
176+
** for convenience
177+
*/
178+
if ( strcmp(name, "portVersion") == 0 )
179+
return Py_BuildValue("h", itself_color->portVersion);
180+
if ( strcmp(name, "device") == 0 )
181+
return PyInt_FromLong((long)self->ob_itself->device);
182+
if ( strcmp(name, "portRect") == 0 )
183+
return Py_BuildValue("O&", PyMac_BuildRect, &self->ob_itself->portRect);
184+
if ( strcmp(name, "visRgn") == 0 )
185+
return Py_BuildValue("O&", ResObj_New, (Handle)self->ob_itself->visRgn);
186+
if ( strcmp(name, "clipRgn") == 0 )
187+
return Py_BuildValue("O&", ResObj_New, (Handle)self->ob_itself->clipRgn);
188+
if ( strcmp(name, "bkPat") == 0 )
189+
return Py_BuildValue("s#", (char *)&self->ob_itself->bkPat, sizeof(Pattern));
190+
if ( strcmp(name, "fillPat") == 0 )
191+
return Py_BuildValue("s#", (char *)&self->ob_itself->fillPat, sizeof(Pattern));
192+
if ( strcmp(name, "pnLoc") == 0 )
193+
return Py_BuildValue("O&", PyMac_BuildPoint, self->ob_itself->pnLoc);
194+
if ( strcmp(name, "pnSize") == 0 )
195+
return Py_BuildValue("O&", PyMac_BuildPoint, self->ob_itself->pnSize);
196+
if ( strcmp(name, "pnMode") == 0 )
197+
return Py_BuildValue("h", self->ob_itself->pnMode);
198+
if ( strcmp(name, "pnPat") == 0 )
199+
return Py_BuildValue("s#", (char *)&self->ob_itself->pnPat, sizeof(Pattern));
200+
if ( strcmp(name, "pnVis") == 0 )
201+
return Py_BuildValue("h", self->ob_itself->pnVis);
202+
if ( strcmp(name, "txFont") == 0 )
203+
return Py_BuildValue("h", self->ob_itself->txFont);
204+
if ( strcmp(name, "txFace") == 0 )
205+
return Py_BuildValue("h", (short)self->ob_itself->txFace);
206+
if ( strcmp(name, "txMode") == 0 )
207+
return Py_BuildValue("h", self->ob_itself->txMode);
208+
if ( strcmp(name, "txSize") == 0 )
209+
return Py_BuildValue("h", self->ob_itself->txSize);
210+
if ( strcmp(name, "spExtra") == 0 )
211+
return Py_BuildValue("O&", PyMac_BuildFixed, self->ob_itself->spExtra);
212+
/* XXXX Add more, as needed */
213+
}""")
151214

152215
class MyBMObjectDefinition(GlobalObjectDefinition):
153216
def outputCheckNewArg(self):

0 commit comments

Comments
 (0)