/Mac/Modules/fm/_Fmmodule.c

http://unladen-swallow.googlecode.com/ · C · 368 lines · 321 code · 40 blank · 7 comment · 21 complexity · 37d277ae90ab4c27a7c2c2e50e9ae3e9 MD5 · raw file

  1. /* =========================== Module _Fm =========================== */
  2. #include "Python.h"
  3. #ifndef __LP64__
  4. #include "pymactoolbox.h"
  5. /* Macro to test whether a weak-loaded CFM function exists */
  6. #define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
  7. PyErr_SetString(PyExc_NotImplementedError, \
  8. "Not available in this shared library/OS version"); \
  9. return NULL; \
  10. }} while(0)
  11. #include <Carbon/Carbon.h>
  12. /*
  13. ** Parse/generate ComponentDescriptor records
  14. */
  15. static PyObject *
  16. FMRec_New(FMetricRec *itself)
  17. {
  18. return Py_BuildValue("O&O&O&O&O&",
  19. PyMac_BuildFixed, itself->ascent,
  20. PyMac_BuildFixed, itself->descent,
  21. PyMac_BuildFixed, itself->leading,
  22. PyMac_BuildFixed, itself->widMax,
  23. ResObj_New, itself->wTabHandle);
  24. }
  25. #if 0
  26. /* Not needed... */
  27. static int
  28. FMRec_Convert(PyObject *v, FMetricRec *p_itself)
  29. {
  30. return PyArg_ParseTuple(v, "O&O&O&O&O&",
  31. PyMac_GetFixed, &itself->ascent,
  32. PyMac_GetFixed, &itself->descent,
  33. PyMac_GetFixed, &itself->leading,
  34. PyMac_GetFixed, &itself->widMax,
  35. ResObj_Convert, &itself->wTabHandle);
  36. }
  37. #endif
  38. static PyObject *Fm_Error;
  39. static PyObject *Fm_GetFontName(PyObject *_self, PyObject *_args)
  40. {
  41. PyObject *_res = NULL;
  42. short familyID;
  43. Str255 name;
  44. #ifndef GetFontName
  45. PyMac_PRECHECK(GetFontName);
  46. #endif
  47. if (!PyArg_ParseTuple(_args, "h",
  48. &familyID))
  49. return NULL;
  50. GetFontName(familyID,
  51. name);
  52. _res = Py_BuildValue("O&",
  53. PyMac_BuildStr255, name);
  54. return _res;
  55. }
  56. static PyObject *Fm_GetFNum(PyObject *_self, PyObject *_args)
  57. {
  58. PyObject *_res = NULL;
  59. Str255 name;
  60. short familyID;
  61. #ifndef GetFNum
  62. PyMac_PRECHECK(GetFNum);
  63. #endif
  64. if (!PyArg_ParseTuple(_args, "O&",
  65. PyMac_GetStr255, name))
  66. return NULL;
  67. GetFNum(name,
  68. &familyID);
  69. _res = Py_BuildValue("h",
  70. familyID);
  71. return _res;
  72. }
  73. static PyObject *Fm_RealFont(PyObject *_self, PyObject *_args)
  74. {
  75. PyObject *_res = NULL;
  76. Boolean _rv;
  77. short fontNum;
  78. short size;
  79. #ifndef RealFont
  80. PyMac_PRECHECK(RealFont);
  81. #endif
  82. if (!PyArg_ParseTuple(_args, "hh",
  83. &fontNum,
  84. &size))
  85. return NULL;
  86. _rv = RealFont(fontNum,
  87. size);
  88. _res = Py_BuildValue("b",
  89. _rv);
  90. return _res;
  91. }
  92. static PyObject *Fm_SetFScaleDisable(PyObject *_self, PyObject *_args)
  93. {
  94. PyObject *_res = NULL;
  95. Boolean fscaleDisable;
  96. #ifndef SetFScaleDisable
  97. PyMac_PRECHECK(SetFScaleDisable);
  98. #endif
  99. if (!PyArg_ParseTuple(_args, "b",
  100. &fscaleDisable))
  101. return NULL;
  102. SetFScaleDisable(fscaleDisable);
  103. Py_INCREF(Py_None);
  104. _res = Py_None;
  105. return _res;
  106. }
  107. static PyObject *Fm_FontMetrics(PyObject *_self, PyObject *_args)
  108. {
  109. PyObject *_res = NULL;
  110. FMetricRec theMetrics;
  111. #ifndef FontMetrics
  112. PyMac_PRECHECK(FontMetrics);
  113. #endif
  114. if (!PyArg_ParseTuple(_args, ""))
  115. return NULL;
  116. FontMetrics(&theMetrics);
  117. _res = Py_BuildValue("O&",
  118. FMRec_New, &theMetrics);
  119. return _res;
  120. }
  121. static PyObject *Fm_SetFractEnable(PyObject *_self, PyObject *_args)
  122. {
  123. PyObject *_res = NULL;
  124. Boolean fractEnable;
  125. #ifndef SetFractEnable
  126. PyMac_PRECHECK(SetFractEnable);
  127. #endif
  128. if (!PyArg_ParseTuple(_args, "b",
  129. &fractEnable))
  130. return NULL;
  131. SetFractEnable(fractEnable);
  132. Py_INCREF(Py_None);
  133. _res = Py_None;
  134. return _res;
  135. }
  136. static PyObject *Fm_GetDefFontSize(PyObject *_self, PyObject *_args)
  137. {
  138. PyObject *_res = NULL;
  139. short _rv;
  140. #ifndef GetDefFontSize
  141. PyMac_PRECHECK(GetDefFontSize);
  142. #endif
  143. if (!PyArg_ParseTuple(_args, ""))
  144. return NULL;
  145. _rv = GetDefFontSize();
  146. _res = Py_BuildValue("h",
  147. _rv);
  148. return _res;
  149. }
  150. static PyObject *Fm_IsOutline(PyObject *_self, PyObject *_args)
  151. {
  152. PyObject *_res = NULL;
  153. Boolean _rv;
  154. Point numer;
  155. Point denom;
  156. #ifndef IsOutline
  157. PyMac_PRECHECK(IsOutline);
  158. #endif
  159. if (!PyArg_ParseTuple(_args, "O&O&",
  160. PyMac_GetPoint, &numer,
  161. PyMac_GetPoint, &denom))
  162. return NULL;
  163. _rv = IsOutline(numer,
  164. denom);
  165. _res = Py_BuildValue("b",
  166. _rv);
  167. return _res;
  168. }
  169. static PyObject *Fm_SetOutlinePreferred(PyObject *_self, PyObject *_args)
  170. {
  171. PyObject *_res = NULL;
  172. Boolean outlinePreferred;
  173. #ifndef SetOutlinePreferred
  174. PyMac_PRECHECK(SetOutlinePreferred);
  175. #endif
  176. if (!PyArg_ParseTuple(_args, "b",
  177. &outlinePreferred))
  178. return NULL;
  179. SetOutlinePreferred(outlinePreferred);
  180. Py_INCREF(Py_None);
  181. _res = Py_None;
  182. return _res;
  183. }
  184. static PyObject *Fm_GetOutlinePreferred(PyObject *_self, PyObject *_args)
  185. {
  186. PyObject *_res = NULL;
  187. Boolean _rv;
  188. #ifndef GetOutlinePreferred
  189. PyMac_PRECHECK(GetOutlinePreferred);
  190. #endif
  191. if (!PyArg_ParseTuple(_args, ""))
  192. return NULL;
  193. _rv = GetOutlinePreferred();
  194. _res = Py_BuildValue("b",
  195. _rv);
  196. return _res;
  197. }
  198. static PyObject *Fm_SetPreserveGlyph(PyObject *_self, PyObject *_args)
  199. {
  200. PyObject *_res = NULL;
  201. Boolean preserveGlyph;
  202. #ifndef SetPreserveGlyph
  203. PyMac_PRECHECK(SetPreserveGlyph);
  204. #endif
  205. if (!PyArg_ParseTuple(_args, "b",
  206. &preserveGlyph))
  207. return NULL;
  208. SetPreserveGlyph(preserveGlyph);
  209. Py_INCREF(Py_None);
  210. _res = Py_None;
  211. return _res;
  212. }
  213. static PyObject *Fm_GetPreserveGlyph(PyObject *_self, PyObject *_args)
  214. {
  215. PyObject *_res = NULL;
  216. Boolean _rv;
  217. #ifndef GetPreserveGlyph
  218. PyMac_PRECHECK(GetPreserveGlyph);
  219. #endif
  220. if (!PyArg_ParseTuple(_args, ""))
  221. return NULL;
  222. _rv = GetPreserveGlyph();
  223. _res = Py_BuildValue("b",
  224. _rv);
  225. return _res;
  226. }
  227. static PyObject *Fm_GetSysFont(PyObject *_self, PyObject *_args)
  228. {
  229. PyObject *_res = NULL;
  230. short _rv;
  231. #ifndef GetSysFont
  232. PyMac_PRECHECK(GetSysFont);
  233. #endif
  234. if (!PyArg_ParseTuple(_args, ""))
  235. return NULL;
  236. _rv = GetSysFont();
  237. _res = Py_BuildValue("h",
  238. _rv);
  239. return _res;
  240. }
  241. static PyObject *Fm_GetAppFont(PyObject *_self, PyObject *_args)
  242. {
  243. PyObject *_res = NULL;
  244. short _rv;
  245. #ifndef GetAppFont
  246. PyMac_PRECHECK(GetAppFont);
  247. #endif
  248. if (!PyArg_ParseTuple(_args, ""))
  249. return NULL;
  250. _rv = GetAppFont();
  251. _res = Py_BuildValue("h",
  252. _rv);
  253. return _res;
  254. }
  255. static PyObject *Fm_QDTextBounds(PyObject *_self, PyObject *_args)
  256. {
  257. PyObject *_res = NULL;
  258. char *inText__in__;
  259. int inText__len__;
  260. int inText__in_len__;
  261. Rect bounds;
  262. #ifndef QDTextBounds
  263. PyMac_PRECHECK(QDTextBounds);
  264. #endif
  265. if (!PyArg_ParseTuple(_args, "s#",
  266. &inText__in__, &inText__in_len__))
  267. return NULL;
  268. inText__len__ = inText__in_len__;
  269. QDTextBounds(inText__len__, inText__in__,
  270. &bounds);
  271. _res = Py_BuildValue("O&",
  272. PyMac_BuildRect, &bounds);
  273. return _res;
  274. }
  275. static PyMethodDef Fm_methods[] = {
  276. {"GetFontName", (PyCFunction)Fm_GetFontName, 1,
  277. PyDoc_STR("(short familyID) -> (Str255 name)")},
  278. {"GetFNum", (PyCFunction)Fm_GetFNum, 1,
  279. PyDoc_STR("(Str255 name) -> (short familyID)")},
  280. {"RealFont", (PyCFunction)Fm_RealFont, 1,
  281. PyDoc_STR("(short fontNum, short size) -> (Boolean _rv)")},
  282. {"SetFScaleDisable", (PyCFunction)Fm_SetFScaleDisable, 1,
  283. PyDoc_STR("(Boolean fscaleDisable) -> None")},
  284. {"FontMetrics", (PyCFunction)Fm_FontMetrics, 1,
  285. PyDoc_STR("() -> (FMetricRec theMetrics)")},
  286. {"SetFractEnable", (PyCFunction)Fm_SetFractEnable, 1,
  287. PyDoc_STR("(Boolean fractEnable) -> None")},
  288. {"GetDefFontSize", (PyCFunction)Fm_GetDefFontSize, 1,
  289. PyDoc_STR("() -> (short _rv)")},
  290. {"IsOutline", (PyCFunction)Fm_IsOutline, 1,
  291. PyDoc_STR("(Point numer, Point denom) -> (Boolean _rv)")},
  292. {"SetOutlinePreferred", (PyCFunction)Fm_SetOutlinePreferred, 1,
  293. PyDoc_STR("(Boolean outlinePreferred) -> None")},
  294. {"GetOutlinePreferred", (PyCFunction)Fm_GetOutlinePreferred, 1,
  295. PyDoc_STR("() -> (Boolean _rv)")},
  296. {"SetPreserveGlyph", (PyCFunction)Fm_SetPreserveGlyph, 1,
  297. PyDoc_STR("(Boolean preserveGlyph) -> None")},
  298. {"GetPreserveGlyph", (PyCFunction)Fm_GetPreserveGlyph, 1,
  299. PyDoc_STR("() -> (Boolean _rv)")},
  300. {"GetSysFont", (PyCFunction)Fm_GetSysFont, 1,
  301. PyDoc_STR("() -> (short _rv)")},
  302. {"GetAppFont", (PyCFunction)Fm_GetAppFont, 1,
  303. PyDoc_STR("() -> (short _rv)")},
  304. {"QDTextBounds", (PyCFunction)Fm_QDTextBounds, 1,
  305. PyDoc_STR("(Buffer inText) -> (Rect bounds)")},
  306. {NULL, NULL, 0}
  307. };
  308. #else /* __LP64__ */
  309. static PyMethodDef Fm_methods[] = {
  310. {NULL, NULL, 0}
  311. };
  312. #endif /* __LP64__ */
  313. void init_Fm(void)
  314. {
  315. PyObject *m;
  316. #ifndef __LP64__
  317. PyObject *d;
  318. #endif /* __LP64__ */
  319. m = Py_InitModule("_Fm", Fm_methods);
  320. #ifndef __LP64__
  321. d = PyModule_GetDict(m);
  322. Fm_Error = PyMac_GetOSErrException();
  323. if (Fm_Error == NULL ||
  324. PyDict_SetItemString(d, "Error", Fm_Error) != 0)
  325. return;
  326. #endif /* __LP64__ */
  327. }
  328. /* ========================= End module _Fm ========================= */