PageRenderTime 67ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 1ms

/nx-3.5.0/nx-X11/lib/dpstk/FontCreato.c

#
C | 1610 lines | 1272 code | 254 blank | 84 comment | 271 complexity | c41dc89d21ca1e0c4e1e64089bf08671 MD5 | raw file
Possible License(s): BSD-3-Clause, GPL-2.0, LGPL-2.0
  1. /*
  2. * FontCreato.c
  3. *
  4. * (c) Copyright 1992-1994 Adobe Systems Incorporated.
  5. * All rights reserved.
  6. *
  7. * Permission to use, copy, modify, distribute, and sublicense this software
  8. * and its documentation for any purpose and without fee is hereby granted,
  9. * provided that the above copyright notices appear in all copies and that
  10. * both those copyright notices and this permission notice appear in
  11. * supporting documentation and that the name of Adobe Systems Incorporated
  12. * not be used in advertising or publicity pertaining to distribution of the
  13. * software without specific, written prior permission. No trademark license
  14. * to use the Adobe trademarks is hereby granted. If the Adobe trademark
  15. * "Display PostScript"(tm) is used to describe this software, its
  16. * functionality or for any other purpose, such use shall be limited to a
  17. * statement that this software works in conjunction with the Display
  18. * PostScript system. Proper trademark attribution to reflect Adobe's
  19. * ownership of the trademark shall be given whenever any such reference to
  20. * the Display PostScript system is made.
  21. *
  22. * ADOBE MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF THE SOFTWARE FOR
  23. * ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
  24. * ADOBE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  25. * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. * NON- INFRINGEMENT OF THIRD PARTY RIGHTS. IN NO EVENT SHALL ADOBE BE LIABLE
  27. * TO YOU OR ANY OTHER PARTY FOR ANY SPECIAL, INDIRECT, OR CONSEQUENTIAL
  28. * DAMAGES OR ANY DAMAGES WHATSOEVER WHETHER IN AN ACTION OF CONTRACT,
  29. * NEGLIGENCE, STRICT LIABILITY OR ANY OTHER ACTION ARISING OUT OF OR IN
  30. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ADOBE WILL NOT
  31. * PROVIDE ANY TRAINING OR OTHER SUPPORT FOR THE SOFTWARE.
  32. *
  33. * Adobe, PostScript, and Display PostScript are trademarks of Adobe Systems
  34. * Incorporated which may be registered in certain jurisdictions
  35. *
  36. * Author: Adobe Systems Incorporated
  37. */
  38. /* $XFree86$ */
  39. #include <stdio.h>
  40. #include <ctype.h>
  41. #include <X11/IntrinsicP.h>
  42. #include <X11/StringDefs.h>
  43. #include <X11/ShellP.h>
  44. #include <Xm/Xm.h>
  45. /* There are no words to describe how I feel about having to do this */
  46. #if XmVersion > 1001
  47. #include <Xm/ManagerP.h>
  48. #else
  49. #include <Xm/XmP.h>
  50. #endif
  51. #include <Xm/Form.h>
  52. #include <Xm/LabelG.h>
  53. #include <Xm/PushBG.h>
  54. #include <Xm/DrawingA.h>
  55. #include <Xm/Scale.h>
  56. #include <Xm/MessageB.h>
  57. #include <Xm/TextF.h>
  58. #include <Xm/PanedW.h>
  59. #include <Xm/List.h>
  60. #include <Xm/SeparatoG.h>
  61. #include <Xm/ToggleBG.h>
  62. #include <Xm/RowColumn.h>
  63. #include <DPS/dpsXclient.h>
  64. #include <DPS/dpsXshare.h>
  65. #include <DPS/FontSBP.h>
  66. #include <DPS/FontCreatP.h>
  67. #include <stdlib.h>
  68. #include <math.h>
  69. #include "FontSBI.h"
  70. #include "FSBwraps.h"
  71. /* Turn a string into a compound string */
  72. #define UnsharedCS(str) XmStringCreate(str, XmSTRING_DEFAULT_CHARSET)
  73. #define CS(str, w) _FSBCreateSharedCS(str, w)
  74. static XmString CSempty;
  75. static char *opticalSize = NULL;
  76. #define Canonical(str) XrmQuarkToString(XrmStringToQuark(str))
  77. static float defaultSizeList[] = {
  78. #ifndef CREATOR_DEFAULT_SIZE_LIST
  79. 8, 10, 12, 14, 16, 18, 24, 36, 48, 72
  80. #else
  81. CREATOR_DEFAULT_SIZE_LIST
  82. #endif /* CREATOR_DEFAULT_SIZE_LIST */
  83. };
  84. #ifndef CREATOR_DEFAULT_SIZE_LIST_COUNT
  85. #define CREATOR_DEFAULT_SIZE_LIST_COUNT 10
  86. #endif /* CREATOR_DEFAULT_SIZE_LIST_COUNT */
  87. #define Offset(field) XtOffsetOf(FontCreatorRec, creator.field)
  88. static XtResource resources[] = {
  89. {XtNsizes, XtCSizes, XtRFloatList, sizeof(float*),
  90. Offset(sizes), XtRImmediate, (XtPointer) defaultSizeList},
  91. {XtNsizeCount, XtCSizeCount, XtRInt, sizeof(int),
  92. Offset(size_count), XtRImmediate,
  93. (XtPointer) CREATOR_DEFAULT_SIZE_LIST_COUNT},
  94. {XtNdismissCallback, XtCCallback, XtRCallback, sizeof(XtCallbackList),
  95. Offset(dismiss_callback), XtRCallback, (XtPointer) NULL},
  96. {XtNfontSelectionBox, XtCReadOnly, XtRWidget, sizeof(Widget),
  97. Offset(fsb), XtRWidget, (XtPointer) NULL},
  98. };
  99. /* Forward declarations */
  100. static Boolean SetValues(Widget old, Widget req, Widget new, ArgList args, Cardinal *num_args);
  101. static XtGeometryResult GeometryManager(Widget w, XtWidgetGeometry *desired, XtWidgetGeometry *allowed);
  102. static void ChangeManaged(Widget w);
  103. static void ClassInitialize(void);
  104. static void Destroy(Widget widget);
  105. static void Initialize(Widget request, Widget new, ArgList args, Cardinal *num_args);
  106. static void Resize(Widget widget);
  107. FontCreatorClassRec fontCreatorClassRec = {
  108. /* Core class part */
  109. {
  110. /* superclass */ (WidgetClass) &xmManagerClassRec,
  111. /* class_name */ "FontCreator",
  112. /* widget_size */ sizeof(FontCreatorRec),
  113. /* class_initialize */ ClassInitialize,
  114. /* class_part_initialize */ NULL,
  115. /* class_inited */ FALSE,
  116. /* initialize */ Initialize,
  117. /* initialize_hook */ NULL,
  118. /* realize */ XtInheritRealize,
  119. /* actions */ NULL,
  120. /* num_actions */ 0,
  121. /* resources */ resources,
  122. /* num_resources */ XtNumber(resources),
  123. /* xrm_class */ NULLQUARK,
  124. /* compress_motion */ TRUE,
  125. /* compress_exposure */ XtExposeCompressMultiple,
  126. /* compress_enterleave */ TRUE,
  127. /* visible_interest */ FALSE,
  128. /* destroy */ Destroy,
  129. /* resize */ Resize,
  130. /* expose */ NULL,
  131. /* set_values */ SetValues,
  132. /* set_values_hook */ NULL,
  133. /* set_values_almost */ XtInheritSetValuesAlmost,
  134. /* get_values_hook */ NULL,
  135. /* accept_focus */ NULL,
  136. /* version */ XtVersion,
  137. /* callback offsets */ NULL,
  138. /* tm_table */ NULL,
  139. /* query_geometry */ XtInheritQueryGeometry,
  140. /* display_accelerator */ NULL,
  141. /* extension */ NULL,
  142. },
  143. /* Composite class part */
  144. {
  145. /* geometry_manager */ GeometryManager,
  146. /* change_managed */ ChangeManaged,
  147. /* insert_child */ XtInheritInsertChild,
  148. /* delete_child */ XtInheritDeleteChild,
  149. /* extension */ NULL,
  150. },
  151. /* Constraint class part */
  152. {
  153. /* resources */ NULL,
  154. /* num_resources */ 0,
  155. /* constraint_size */ 0,
  156. /* initialize */ NULL,
  157. /* destroy */ NULL,
  158. /* set_values */ NULL,
  159. /* extension */ NULL,
  160. },
  161. /* Manager class part */
  162. {
  163. /* translations */ XtInheritTranslations,
  164. /* syn_resources */ NULL,
  165. /* num_syn_resources */ 0,
  166. /* syn_constraint_resources */ NULL,
  167. /* num_syn_constraint_resources */ 0,
  168. /* parent_process */ XmInheritParentProcess,
  169. /* extension */ NULL,
  170. },
  171. /* FontCreator class part */
  172. {
  173. /* extension */ NULL,
  174. }
  175. };
  176. WidgetClass fontCreatorWidgetClass =
  177. (WidgetClass) &fontCreatorClassRec;
  178. static void ClassInitialize(void)
  179. {
  180. XtInitializeWidgetClass(fontSelectionBoxWidgetClass);
  181. CSempty = UnsharedCS("");
  182. opticalSize = Canonical("OpticalSize");
  183. }
  184. /* ARGSUSED */
  185. static void ResizePreview(
  186. Widget widget,
  187. XtPointer clientData, XtPointer callData)
  188. {
  189. Dimension height;
  190. Cardinal depth;
  191. FontCreatorWidget fc = (FontCreatorWidget) clientData;
  192. if (!XtIsRealized(widget) || fc->creator.gstate == 0) return;
  193. XtVaGetValues(widget, XmNheight, &height,
  194. XmNdepth, &depth, NULL);
  195. XDPSSetContextGState(fc->creator.fsb->fsb.context, fc->creator.gstate);
  196. XDPSSetContextParameters(fc->creator.fsb->fsb.context, XtScreen(widget),
  197. depth, XtWindow(widget), height,
  198. (XDPSStandardColormap *) NULL,
  199. (XDPSStandardColormap *) NULL,
  200. XDPSContextScreenDepth | XDPSContextDrawable);
  201. _DPSFReclip(fc->creator.fsb->fsb.context);
  202. XDPSUpdateContextGState(fc->creator.fsb->fsb.context, fc->creator.gstate);
  203. }
  204. static void DrawMM(FontCreatorWidget fc)
  205. {
  206. int i, j;
  207. String str;
  208. float p[MAX_AXES];
  209. float b[MAX_BLENDS];
  210. int val;
  211. float size;
  212. char *chSize;
  213. DPSContext context;
  214. Dimension hgt;
  215. BlendDataRec *bd = fc->creator.font->blend_data;
  216. float total;
  217. int bogusFont;
  218. str = XmTextFieldGetString(fc->creator.display_text_child);
  219. for (i = 0; i < bd->num_axes; i++) {
  220. XtVaGetValues(fc->creator.axis_scale_child[i], XmNvalue, &val, NULL);
  221. p[i] = _FSBNormalize(val, bd, i);
  222. }
  223. XtVaGetValues(fc->creator.preview_child, XtNheight, &hgt, NULL);
  224. context = fc->creator.fsb->fsb.context;
  225. if (fc->creator.gstate == 0) {
  226. XDPSSetContextDrawable(context,
  227. XtWindow(fc->creator.preview_child), hgt);
  228. XDPSCaptureContextGState(context, &fc->creator.gstate);
  229. } else XDPSSetContextGState(context, fc->creator.gstate);
  230. /* Force b[0] to be 1 - total(b[1..n]) to avoid round-off error */
  231. total = 0.0;
  232. for (i = 1; i < bd->num_designs; i++) {
  233. b[i] = 1.0;
  234. for (j = 0; j < bd->num_axes; j++) {
  235. if (bd->design_positions[i*bd->num_axes + j] == 1.0) b[i] *= p[j];
  236. else b[i] *= 1.0 - p[j];
  237. }
  238. total += b[i];
  239. }
  240. b[0] = 1.0 - total;
  241. XtVaGetValues(fc->creator.size_text_field_child,
  242. XmNvalue, &chSize, NULL);
  243. if (chSize == NULL || *chSize == '\0') return;
  244. size = atof(chSize);
  245. _DPSFSetUpMM(context, fc->creator.font->font_name,
  246. str, size, hgt, b, bd->num_designs, &bogusFont);
  247. DPSWaitContext(context);
  248. XClearWindow(XtDisplay(fc->creator.preview_child),
  249. XtWindow(fc->creator.preview_child));
  250. _DPSFDrawMM(context, str, hgt);
  251. }
  252. /* ARGSUSED */
  253. static void DrawMMCallback(
  254. Widget widget,
  255. XtPointer clientData, XtPointer callData)
  256. {
  257. FontCreatorWidget fc = (FontCreatorWidget) clientData;
  258. DrawMM(fc);
  259. }
  260. /* ARGSUSED */
  261. static void ExposeCallback(
  262. Widget widget,
  263. XtPointer clientData, XtPointer callData)
  264. {
  265. FontCreatorWidget fc = (FontCreatorWidget) clientData;
  266. XmDrawingAreaCallbackStruct *dac =
  267. (XmDrawingAreaCallbackStruct *) callData;
  268. if (!fc->creator.preview_fixed) {
  269. XSetWindowAttributes att;
  270. att.bit_gravity = ForgetGravity;
  271. XChangeWindowAttributes(XtDisplay(fc),
  272. XtWindow(fc->creator.preview_child),
  273. CWBitGravity, &att);
  274. fc->creator.preview_fixed = TRUE;
  275. }
  276. if (dac != NULL && dac->event->type == Expose &&
  277. dac->event->xexpose.count != 0) return;
  278. DrawMM(fc);
  279. }
  280. static void SetUpBlendList(FontCreatorWidget fc)
  281. {
  282. XmString *CSblends;
  283. int count, i;
  284. BlendRec *b;
  285. char buf[256];
  286. FontRec *f = fc->creator.font;
  287. sprintf(buf, "%s Blends", f->face_name);
  288. XtVaSetValues(fc->creator.blend_label_child,
  289. XtVaTypedArg, XmNlabelString, XtRString,
  290. buf, strlen(buf)+1,
  291. NULL);
  292. if (f->blend_count == 0) {
  293. count = 1;
  294. CSblends = &CSempty;
  295. } else {
  296. count = f->blend_count;
  297. CSblends = (XmString *) XtCalloc(count, sizeof(XmString));
  298. for (i = 0, b = f->blend_data->blends; i < f->blend_count;
  299. i++, b = b->next) {
  300. CSblends[i] = b->CS_blend_name;
  301. }
  302. }
  303. XtVaSetValues(fc->creator.blend_scrolled_list_child, XmNitemCount, count,
  304. XmNitems, CSblends, NULL);
  305. if (f->blend_count != 0) XtFree((XtPointer) CSblends);
  306. }
  307. static void CalcCarryValues(FontCreatorWidget fc, FontRec *oldf, int *carry_values)
  308. {
  309. FontRec *f = fc->creator.font;
  310. BlendDataRec *bd = f->blend_data, *oldbd = oldf->blend_data;
  311. int i, j;
  312. for (i = 0; i < bd->num_axes; i++) {
  313. carry_values[i] = -1;
  314. for (j = 0; j < oldbd->num_axes; j++) {
  315. if (bd->name[i] == oldbd->name[j]) {
  316. XmScaleGetValue(fc->creator.axis_scale_child[j],
  317. carry_values+i);
  318. break;
  319. }
  320. }
  321. }
  322. }
  323. static void SetUpAxisLabels(FontCreatorWidget fc, FontRec *oldf, int *carry_values)
  324. {
  325. int i;
  326. char buf[20];
  327. XmString cs;
  328. BlendDataRec *bd = fc->creator.font->blend_data, *oldbd = 0;
  329. char *value;
  330. if (oldf != NULL) oldbd = oldf->blend_data;
  331. for (i = 0; i < bd->num_axes; i++) {
  332. if (oldf == NULL || i >= oldbd->num_axes ||
  333. oldbd->name[i] != bd->name[i]) {
  334. cs = UnsharedCS(bd->name[i]);
  335. XtVaSetValues(fc->creator.axis_label_child[i],
  336. XmNlabelString, cs, NULL);
  337. XmStringFree(cs);
  338. }
  339. if (oldf == NULL || i >= oldbd->num_axes ||
  340. oldbd->min[i] != bd->min[i]) {
  341. sprintf(buf, "%d", bd->min[i]);
  342. cs = UnsharedCS(buf);
  343. XtVaSetValues(fc->creator.axis_min_label_child[i],
  344. XmNlabelString, cs, NULL);
  345. XmStringFree(cs);
  346. }
  347. if (oldf == NULL || i >= oldbd->num_axes ||
  348. oldbd->max[i] != bd->max[i]) {
  349. sprintf(buf, "%d", bd->max[i]);
  350. cs = UnsharedCS(buf);
  351. XtVaSetValues(fc->creator.axis_max_label_child[i],
  352. XmNlabelString, cs, NULL);
  353. XmStringFree(cs);
  354. }
  355. if (oldf == NULL || carry_values[i] == -1) {
  356. if (bd->name[i] == opticalSize &&
  357. XmToggleButtonGadgetGetState(
  358. fc->creator.follow_size_toggle_child)) {
  359. XtVaGetValues(fc->creator.fsb->fsb.size_text_field_child,
  360. XmNvalue, &value, NULL);
  361. if (value == NULL || *value == '\0') {
  362. carry_values[i] = bd->min[i];
  363. } else carry_values[i] = atof(value) + 0.5;
  364. } else carry_values[i] = bd->min[i];
  365. }
  366. if (carry_values[i] < bd->min[i]) carry_values[i] = bd->min[i];
  367. else if (carry_values[i] > bd->max[i]) carry_values[i] = bd->max[i];
  368. XtVaSetValues(fc->creator.axis_scale_child[i],
  369. XmNminimum, bd->min[i], XmNmaximum, bd->max[i],
  370. XmNvalue, carry_values[i], NULL);
  371. }
  372. }
  373. static void ManageAxes(FontCreatorWidget fc)
  374. {
  375. Widget w[5*MAX_AXES];
  376. int i, j;
  377. int diff;
  378. diff = fc->creator.managed_axes - fc->creator.font->blend_data->num_axes;
  379. if (diff == 0) return;
  380. if (diff < 0) {
  381. for (i = fc->creator.managed_axes, j=0; j < -diff * 5; i++, j+=5) {
  382. w[j] = fc->creator.axis_label_child[i];
  383. w[j+1] = fc->creator.axis_scale_child[i];
  384. w[j+2] = fc->creator.axis_value_text_child[i];
  385. w[j+3] = fc->creator.axis_min_label_child[i];
  386. w[j+4] = fc->creator.axis_max_label_child[i];
  387. }
  388. XtManageChildren(w, -diff * 5);
  389. } else {
  390. for (i = fc->creator.font->blend_data->num_axes, j=0; j < diff * 5;
  391. i++, j+=5) {
  392. w[j] = fc->creator.axis_label_child[i];
  393. w[j+1] = fc->creator.axis_scale_child[i];
  394. w[j+2] = fc->creator.axis_value_text_child[i];
  395. w[j+3] = fc->creator.axis_min_label_child[i];
  396. w[j+4] = fc->creator.axis_max_label_child[i];
  397. }
  398. XtUnmanageChildren(w, diff * 5);
  399. }
  400. fc->creator.managed_axes = fc->creator.font->blend_data->num_axes;
  401. }
  402. static void SetScaleValues(FontCreatorWidget fc)
  403. {
  404. int val;
  405. char buf[32];
  406. int i, axes;
  407. axes = fc->creator.font->blend_data->num_axes;
  408. for (i = 0; i < axes; i++) {
  409. XmScaleGetValue(fc->creator.axis_scale_child[i], &val);
  410. sprintf(buf, "%d", val);
  411. XmTextFieldSetString(fc->creator.axis_value_text_child[i], buf);
  412. }
  413. }
  414. static void SetUpAxes(FontCreatorWidget fc, FontRec *oldf)
  415. {
  416. int carry_values[MAX_AXES];
  417. if (oldf != NULL) CalcCarryValues(fc, oldf, carry_values);
  418. SetUpAxisLabels(fc, oldf, carry_values);
  419. SetScaleValues(fc);
  420. ManageAxes(fc);
  421. }
  422. /* ARGSUSED */
  423. static void FaceSelect(
  424. Widget widget,
  425. XtPointer clientData, XtPointer callData)
  426. {
  427. XmListCallbackStruct *listCB = (XmListCallbackStruct *) callData;
  428. FontCreatorWidget fc = (FontCreatorWidget) clientData;
  429. FontRec *f, *oldf = fc->creator.font;
  430. int i;
  431. i = 0;
  432. f = fc->creator.family->fonts;
  433. while (f != NULL) {
  434. if (f->blend_data != NULL) i++;
  435. if (i == listCB->item_position) break;
  436. f = f->next;
  437. }
  438. if (f == NULL) return;
  439. if (!_FSBDownloadFontIfNecessary(f, fc->creator.fsb)) {
  440. _FSBFlushFont(fc->creator.fsb, f);
  441. return;
  442. }
  443. if (fc->creator.font != NULL) fc->creator.font->in_font_creator = False;
  444. fc->creator.font = f;
  445. f->in_font_creator = True;
  446. SetUpBlendList(fc);
  447. SetUpAxes(fc, oldf);
  448. DrawMM(fc);
  449. }
  450. static void HandleSelectedBlend(FontCreatorWidget fc, int n)
  451. {
  452. BlendDataRec *bd = fc->creator.font->blend_data;
  453. BlendRec *b;
  454. int i;
  455. int value;
  456. char buf[32];
  457. b = bd->blends;
  458. /* List uses 1-based addressing!! */
  459. for (i = 1; i < n; i++) b = b->next;
  460. XmTextFieldSetString(fc->creator.name_text_child, b->blend_name);
  461. for (i = 0; i < bd->num_axes; i++) {
  462. value = _FSBUnnormalize(b->data[i], bd, i);
  463. XmScaleSetValue(fc->creator.axis_scale_child[i], value);
  464. sprintf(buf, "%d", value);
  465. XmTextFieldSetString(fc->creator.axis_value_text_child[i], buf);
  466. }
  467. }
  468. /* ARGSUSED */
  469. static void BlendSelect(
  470. Widget widget,
  471. XtPointer clientData, XtPointer callData)
  472. {
  473. XmListCallbackStruct *listCB = (XmListCallbackStruct *) callData;
  474. FontCreatorWidget fc = (FontCreatorWidget) clientData;
  475. if (fc->creator.font->blend_count == 0) return;
  476. HandleSelectedBlend(fc, listCB->item_position);
  477. DrawMM(fc);
  478. }
  479. /* ARGSUSED */
  480. static void SetValue(
  481. Widget widget,
  482. XtPointer clientData, XtPointer callData)
  483. {
  484. XmScaleCallbackStruct *scaleData = (XmScaleCallbackStruct *) callData;
  485. Widget text = (Widget) clientData;
  486. char buf[32];
  487. sprintf(buf, "%d", scaleData->value);
  488. XmTextFieldSetString(text, buf);
  489. }
  490. /* ARGSUSED */
  491. static void SetScale(
  492. Widget widget,
  493. XtPointer clientData, XtPointer callData)
  494. {
  495. Widget scale = (Widget) clientData;
  496. char *value;
  497. int val, min, max;
  498. char buf[32];
  499. value = XmTextFieldGetString(widget);
  500. val = atoi(value);
  501. XtVaGetValues(scale, XmNminimum, &min, XmNmaximum, &max, NULL);
  502. if (val < min) val = min;
  503. if (val > max) val = max;
  504. XmScaleSetValue(scale, val);
  505. /* Handle range and illegal characters this way...*/
  506. sprintf(buf, "%d", val);
  507. XmTextFieldSetString(widget, buf);
  508. }
  509. /* ARGSUSED */
  510. static void DeleteMessage(
  511. Widget widget,
  512. XtPointer clientData, XtPointer callData)
  513. {
  514. XtDestroyWidget(widget);
  515. }
  516. static void PutUpDialog(FontCreatorWidget fc, char *name)
  517. {
  518. Widget message, w;
  519. message = XmCreateInformationDialog((Widget) fc, name, (ArgList) NULL, 0);
  520. w = XmMessageBoxGetChild(message, XmDIALOG_CANCEL_BUTTON);
  521. XtUnmanageChild(w);
  522. w = XmMessageBoxGetChild(message, XmDIALOG_HELP_BUTTON);
  523. XtUnmanageChild(w);
  524. XtAddCallback(message, XmNokCallback, DeleteMessage, (XtPointer) NULL);
  525. XtManageChild(message);
  526. }
  527. static void NoName(FontCreatorWidget fc)
  528. {
  529. PutUpDialog(fc, "noNameMessage");
  530. }
  531. static void UsedName(FontCreatorWidget fc)
  532. {
  533. PutUpDialog(fc, "usedNameMessage");
  534. }
  535. static void SomeUsedName(FontCreatorWidget fc)
  536. {
  537. PutUpDialog(fc, "someUsedNameMessage");
  538. }
  539. static void NoSuchName(FontCreatorWidget fc)
  540. {
  541. PutUpDialog(fc, "noSuchNameMessage");
  542. }
  543. static Boolean DoAdd(FontCreatorWidget fc, FontRec *f, String name)
  544. {
  545. char *spaceName;
  546. BlendRec *b, *newb, **last;
  547. BlendDataRec *bd = f->blend_data;
  548. int val[MAX_AXES], i;
  549. for (b = bd->blends; b != NULL; b = b->next) {
  550. if (strcmp(name, b->blend_name) == 0) return True;
  551. }
  552. newb = (BlendRec *) XtMalloc(sizeof(BlendRec));
  553. newb->blend_name = Canonical(name);
  554. newb->CS_blend_name = CS(newb->blend_name, (Widget) fc);
  555. spaceName = (char *) XtMalloc(strlen(name) + 4);
  556. spaceName[0] = spaceName[1] = spaceName[2] = ' ';
  557. strcpy(spaceName+3, name);
  558. newb->CS_space_blend_name = CS(spaceName, (Widget) fc);
  559. XtFree((XtPointer) spaceName);
  560. for (i = 0; i < bd->num_axes; i++) {
  561. XtVaGetValues(fc->creator.axis_scale_child[i],
  562. XmNvalue, val+i, NULL);
  563. newb->data[i] = _FSBNormalize(val[i], bd, i);
  564. }
  565. for (/**/; i < MAX_AXES; i++) newb->data[i] = 0.0;
  566. newb->font_name = _FSBGenFontName(f->font_name, val, bd);
  567. f->blend_count++;
  568. fc->creator.family->blend_count++;
  569. last = &bd->blends;
  570. for (b = bd->blends; b != NULL; b = b->next) {
  571. if (strcmp(name, b->blend_name) < 0) break;
  572. last = &b->next;
  573. }
  574. newb->next = b;
  575. *last = newb;
  576. SetUpBlendList(fc);
  577. _FSBSetUpFaceList(fc->creator.fsb, False);
  578. return False;
  579. }
  580. /* ARGSUSED */
  581. static void AddCallback(
  582. Widget widget,
  583. XtPointer clientData, XtPointer callData)
  584. {
  585. FontCreatorWidget fc = (FontCreatorWidget) clientData;
  586. char *value;
  587. FontRec *f;
  588. Boolean failures = False;
  589. BlendDataRec *bd = fc->creator.font->blend_data;
  590. int i;
  591. value = XmTextFieldGetString(fc->creator.name_text_child);
  592. if (value == NULL || *value == '\0') {
  593. NoName(fc);
  594. return;
  595. }
  596. if (XmToggleButtonGadgetGetState(fc->creator.do_all_toggle_child)) {
  597. for (f = fc->creator.family->fonts; f != NULL; f = f->next) {
  598. if (f->blend_data != NULL &&
  599. f->blend_data->num_axes == bd->num_axes) {
  600. for (i = 0; i < bd->num_axes; i++) {
  601. if (f->blend_data->name[i] != bd->name[i]) break;
  602. }
  603. if (i == bd->num_axes) failures |= DoAdd(fc, f, value);
  604. }
  605. }
  606. if (failures) SomeUsedName(fc);
  607. } else if (DoAdd(fc, fc->creator.font, value)) UsedName(fc);
  608. }
  609. static Boolean DoReplace(FontCreatorWidget fc, FontRec *f, String name)
  610. {
  611. BlendDataRec *bd = f->blend_data;
  612. BlendRec *b;
  613. int val[MAX_AXES], i;
  614. name = Canonical(name);
  615. for (b = bd->blends; b != NULL; b = b->next) {
  616. if (name == b->blend_name) {
  617. for (i = 0; i < bd->num_axes; i++) {
  618. XtVaGetValues(fc->creator.axis_scale_child[i],
  619. XmNvalue, val+i, NULL);
  620. b->data[i] = _FSBNormalize(val[i], bd, i);
  621. }
  622. b->font_name = _FSBGenFontName(f->font_name, val, bd);
  623. if (fc->creator.fsb->fsb.currently_selected_blend == b) {
  624. _FSBSetUpFaceList(fc->creator.fsb, True);
  625. }
  626. return False;
  627. }
  628. }
  629. return True;
  630. }
  631. /* ARGSUSED */
  632. static void ReplaceCallback(
  633. Widget widget,
  634. XtPointer clientData, XtPointer callData)
  635. {
  636. FontCreatorWidget fc = (FontCreatorWidget) clientData;
  637. char *value;
  638. FontRec *f;
  639. Boolean failures = True;
  640. BlendDataRec *bd = fc->creator.font->blend_data;
  641. int i;
  642. value = XmTextFieldGetString(fc->creator.name_text_child);
  643. if (value == NULL || *value == '\0') {
  644. NoName(fc);
  645. return;
  646. }
  647. if (XmToggleButtonGadgetGetState(fc->creator.do_all_toggle_child)) {
  648. for (f = fc->creator.family->fonts; f != NULL; f = f->next) {
  649. if (f->blend_data != NULL &&
  650. f->blend_data->num_axes == bd->num_axes) {
  651. for (i = 0; i < bd->num_axes; i++) {
  652. if (f->blend_data->name[i] != bd->name[i]) break;
  653. }
  654. if (i == bd->num_axes) failures &= DoReplace(fc, f, value);
  655. }
  656. }
  657. if (failures) NoSuchName(fc);
  658. } else if (DoReplace(fc, fc->creator.font, value)) NoSuchName(fc);
  659. }
  660. static Boolean DoDelete(FontCreatorWidget fc, FontRec *f, String name)
  661. {
  662. BlendDataRec *bd = f->blend_data;
  663. BlendRec *b, *oldb;
  664. Boolean current = FALSE;
  665. name = Canonical(name);
  666. for (b = bd->blends, oldb = NULL; b != NULL; oldb = b, b = b->next) {
  667. if (name == b->blend_name) {
  668. if (oldb == NULL) bd->blends = b->next;
  669. else oldb->next = b->next;
  670. if (fc->creator.fsb->fsb.currently_selected_blend == b) {
  671. fc->creator.fsb->fsb.currently_selected_blend = NULL;
  672. current = TRUE;
  673. }
  674. XtFree((XtPointer) b);
  675. f->blend_count--;
  676. fc->creator.family->blend_count--;
  677. SetUpBlendList(fc);
  678. _FSBSetUpFaceList(fc->creator.fsb, current);
  679. return False;
  680. }
  681. }
  682. return True;
  683. }
  684. /* ARGSUSED */
  685. static void DeleteCallback(
  686. Widget widget,
  687. XtPointer clientData, XtPointer callData)
  688. {
  689. FontCreatorWidget fc = (FontCreatorWidget) clientData;
  690. char *value;
  691. FontRec *f;
  692. Boolean failures = True;
  693. value = XmTextFieldGetString(fc->creator.name_text_child);
  694. if (value == NULL || *value == '\0') {
  695. NoName(fc);
  696. return;
  697. }
  698. if (XmToggleButtonGadgetGetState(fc->creator.do_all_toggle_child)) {
  699. for (f = fc->creator.family->fonts; f != NULL; f = f->next) {
  700. if (f->blend_data != NULL) {
  701. failures &= DoDelete(fc, f, value);
  702. }
  703. }
  704. if (failures) NoSuchName(fc);
  705. } else if (DoDelete(fc, fc->creator.font, value)) NoSuchName(fc);
  706. }
  707. /* ARGSUSED */
  708. static void UnmanageOptions(
  709. Widget widget,
  710. XtPointer clientData, XtPointer callData)
  711. {
  712. FontCreatorWidget fc = (FontCreatorWidget) clientData;
  713. XtUnmanageChild(fc->creator.option_box);
  714. }
  715. /* ARGSUSED */
  716. static void ShowOptions(
  717. Widget widget,
  718. XtPointer clientData, XtPointer callData)
  719. {
  720. FontCreatorWidget fc = (FontCreatorWidget) clientData;
  721. XtManageChild(fc->creator.option_box);
  722. }
  723. /* ARGSUSED */
  724. static void GenerateCallback(
  725. Widget widget,
  726. XtPointer clientData, XtPointer callData)
  727. {
  728. FontCreatorWidget fc = (FontCreatorWidget) clientData;
  729. BlendDataRec *bd = fc->creator.font->blend_data;
  730. int i, val[MAX_AXES];
  731. char nameBuf[256];
  732. char *ch;
  733. for (i = 0; i < bd->num_axes; i++) {
  734. XtVaGetValues(fc->creator.axis_scale_child[i],
  735. XmNvalue, val+i, NULL);
  736. }
  737. ch = nameBuf;
  738. for (i = 0; i < bd->num_axes - 1; i++) {
  739. sprintf(ch, "%d ", val[i]);
  740. ch = ch + strlen(ch);
  741. }
  742. sprintf(ch, "%d", val[bd->num_axes - 1]);
  743. XmTextFieldSetString(fc->creator.name_text_child, nameBuf);
  744. }
  745. /* ARGSUSED */
  746. static void DismissCallback(
  747. Widget widget,
  748. XtPointer clientData, XtPointer callData)
  749. {
  750. FontCreatorWidget fc = (FontCreatorWidget) clientData;
  751. if (XtIsShell(XtParent(fc))) XtPopdown(XtParent(fc));
  752. XtCallCallbackList(widget, fc->creator.dismiss_callback, (XtPointer) NULL);
  753. }
  754. /* ARGSUSED */
  755. static void SizeChanged(
  756. Widget widget,
  757. XtPointer clientData, XtPointer callData)
  758. {
  759. String value;
  760. FontCreatorWidget fc = (FontCreatorWidget) clientData;
  761. int size;
  762. FontRec *f = fc->creator.font;
  763. BlendDataRec *bd;
  764. int i;
  765. char buf[32];
  766. if (f == NULL || f->blend_data == NULL) return;
  767. /* See if we have an optical size scale */
  768. bd = f->blend_data;
  769. for (i = 0; i < bd->num_axes; i++) {
  770. if (bd->name[i] == opticalSize) break;
  771. }
  772. if (i == bd->num_axes) return;
  773. if (!XmToggleButtonGadgetGetState(fc->creator.follow_size_toggle_child)) {
  774. return;
  775. }
  776. XtVaGetValues(widget, XmNvalue, &value, NULL);
  777. if (value == NULL || *value == '\0') return;
  778. size = atof(value) + 0.5;
  779. sprintf(buf, "%d", size);
  780. XmTextFieldSetString(fc->creator.axis_value_text_child[i], buf);
  781. SetScale(fc->creator.axis_value_text_child[i],
  782. (XtPointer) fc->creator.axis_scale_child[i], (XtPointer) NULL);
  783. DrawMM(fc);
  784. }
  785. /* There's a problem; sometimes the change has already been made in the field,
  786. and sometimes it hasn't. The times when it has seem to correspond to
  787. making changes with the size option menu, so we use this disgusting
  788. global flag to notice when this happens. We also use this to tell whether
  789. or not the change is coming from internal to the widget or as a result
  790. of user interaction. */
  791. static Boolean changingSize = False;
  792. /* ARGSUSED */
  793. static void SizeSelect(
  794. Widget widget,
  795. XtPointer clientData, XtPointer callData)
  796. {
  797. String value;
  798. Widget option;
  799. FontCreatorWidget fc = (FontCreatorWidget) clientData;
  800. char *ch;
  801. XtVaGetValues(widget, XmNvalue, &value, NULL);
  802. if (value == NULL) option = fc->creator.other_size;
  803. else {
  804. for (ch = value; *ch != '\0'; ch++) if (*ch == '.') *ch = '-';
  805. option = XtNameToWidget(fc->creator.size_menu, value);
  806. if (option == NULL) option = fc->creator.other_size;
  807. }
  808. XtVaSetValues(fc->creator.size_option_menu_child,
  809. XmNmenuHistory, option, NULL);
  810. }
  811. /* ARGSUSED */
  812. static void TextVerify(
  813. Widget widget,
  814. XtPointer clientData, XtPointer callData)
  815. {
  816. XmTextVerifyPtr v = (XmTextVerifyPtr) callData;
  817. char ch, *cp;
  818. int decimalPoints = 0;
  819. int i;
  820. if (changingSize) return; /* We know what we're doing; allow it */
  821. /* Should probably look at format field, but seems to contain garbage */
  822. if (v->text->length == 0) return;
  823. for (i = 0; i < v->text->length; i++) {
  824. ch = v->text->ptr[i];
  825. if (ch == '.') decimalPoints++;
  826. else if (!isdigit(ch)) {
  827. v->doit = False;
  828. return;
  829. }
  830. }
  831. if (decimalPoints > 1) {
  832. v->doit = False;
  833. return;
  834. }
  835. XtVaGetValues(widget, XmNvalue, &cp, NULL);
  836. for (/**/; *cp != '\0'; cp++) {
  837. if (*cp == '.') decimalPoints++;
  838. }
  839. if (decimalPoints > 1) v->doit = False;
  840. }
  841. /* ARGSUSED */
  842. static void SetSize(
  843. Widget widget,
  844. XtPointer clientData, XtPointer callData)
  845. {
  846. char buf[20];
  847. char *ch;
  848. FontCreatorWidget fc = (FontCreatorWidget) clientData;
  849. strcpy(buf, XtName(widget));
  850. for (ch = buf; *ch != '\0'; ch++) if (*ch == '-') *ch++ = '.';
  851. changingSize = True;
  852. XtVaSetValues(fc->creator.size_text_field_child, XmNvalue, buf, NULL);
  853. changingSize = False;
  854. }
  855. /* This makes sure the selected item is visible */
  856. static void ListSelectPos(Widget w, int pos, Boolean notify)
  857. {
  858. int topPos, items, visible;
  859. XmListSelectPos(w, pos, notify);
  860. XtVaGetValues(w, XmNtopItemPosition, &topPos,
  861. XmNvisibleItemCount, &visible,
  862. XmNitemCount, &items, NULL);
  863. if (pos >= topPos && pos < topPos + visible) return;
  864. topPos = pos - (visible-1)/2;
  865. if (topPos + visible > items) topPos = items - visible + 1;
  866. if (topPos < 1) topPos = 1;
  867. XtVaSetValues(w, XmNtopItemPosition, topPos, NULL);
  868. }
  869. static void CreateSizeMenu(
  870. FontCreatorWidget fc,
  871. Boolean destroyOldChildren)
  872. {
  873. Arg args[20];
  874. int i, j;
  875. Widget *sizes;
  876. char buf[20];
  877. Widget *children;
  878. Cardinal num_children;
  879. XmString csName;
  880. char *ch;
  881. if (destroyOldChildren) {
  882. XtVaGetValues(fc->creator.size_menu, XtNchildren, &children,
  883. XtNnumChildren, &num_children, NULL);
  884. /* Don't destroy first child ("other") */
  885. for (j = 1; (Cardinal)j < num_children; j++) XtDestroyWidget(children[j]);
  886. sizes = (Widget *) XtMalloc((fc->creator.size_count+1) *
  887. sizeof(Widget));
  888. sizes[0] = children[0];
  889. } else {
  890. sizes = (Widget *) XtMalloc((fc->creator.size_count+1) *
  891. sizeof(Widget));
  892. i = 0;
  893. fc->creator.other_size = sizes[0] =
  894. XtCreateManagedWidget("other", xmPushButtonGadgetClass,
  895. fc->creator.size_menu, args, i);
  896. }
  897. for (j = 0; j < fc->creator.size_count; j++) {
  898. (void) sprintf(buf, "%g", fc->creator.sizes[j]);
  899. csName = UnsharedCS(buf);
  900. for (ch = buf; *ch != '\0'; ch++) if (*ch == '.') *ch = '-';
  901. i = 0;
  902. XtSetArg(args[i], XmNlabelString, csName); i++;
  903. sizes[j+1] =
  904. XmCreatePushButtonGadget(fc->creator.size_menu, buf, args, i);
  905. XmStringFree(csName);
  906. XtAddCallback(sizes[j+1], XmNactivateCallback,
  907. SetSize, (XtPointer) fc);
  908. XtAddCallback(sizes[j+1], XmNactivateCallback,
  909. DrawMMCallback, (XtPointer) fc);
  910. }
  911. XtManageChildren(sizes, j+1);
  912. XtFree((char *) sizes);
  913. }
  914. static void CreateChildren(FontCreatorWidget fc)
  915. {
  916. Arg args[20];
  917. int i, j;
  918. Widget form, prev, w, label, sep, button;
  919. char buf[20];
  920. i = 0;
  921. fc->creator.pane_child =
  922. XtCreateManagedWidget("pane", xmPanedWindowWidgetClass,
  923. (Widget) fc, args, i);
  924. i = 0;
  925. fc->creator.preview_child =
  926. XtCreateManagedWidget("preview", xmDrawingAreaWidgetClass,
  927. fc->creator.pane_child, args, i);
  928. XtAddCallback(fc->creator.preview_child, XmNexposeCallback,
  929. ExposeCallback, (XtPointer) fc);
  930. XtAddCallback(fc->creator.preview_child, XmNresizeCallback,
  931. ResizePreview, (XtPointer) fc);
  932. i = 0;
  933. form = XtCreateManagedWidget("panel", xmFormWidgetClass,
  934. fc->creator.pane_child, args, i);
  935. i = 0;
  936. XtSetArg(args[i], XmNrightAttachment, XmATTACH_FORM); i++;
  937. XtSetArg(args[i], XmNbottomAttachment, XmATTACH_FORM); i++;
  938. button = XtCreateManagedWidget("deleteButton", xmPushButtonGadgetClass,
  939. form, args, i);
  940. XtAddCallback(button, XmNactivateCallback, DeleteCallback, (XtPointer) fc);
  941. i = 0;
  942. XtSetArg(args[i], XmNrightAttachment, XmATTACH_WIDGET); i++;
  943. XtSetArg(args[i], XmNrightWidget, button); i++;
  944. XtSetArg(args[i], XmNbottomAttachment, XmATTACH_FORM); i++;
  945. button = XtCreateManagedWidget("replaceButton", xmPushButtonGadgetClass,
  946. form, args, i);
  947. XtAddCallback(button, XmNactivateCallback,
  948. ReplaceCallback, (XtPointer) fc);
  949. i = 0;
  950. XtSetArg(args[i], XmNrightAttachment, XmATTACH_WIDGET); i++;
  951. XtSetArg(args[i], XmNrightWidget, button); i++;
  952. XtSetArg(args[i], XmNbottomAttachment, XmATTACH_FORM); i++;
  953. button = XtCreateManagedWidget("addButton", xmPushButtonGadgetClass,
  954. form, args, i);
  955. XtAddCallback(button, XmNactivateCallback, AddCallback, (XtPointer) fc);
  956. i = 0;
  957. XtSetArg(args[i], XmNrightAttachment, XmATTACH_WIDGET); i++;
  958. XtSetArg(args[i], XmNrightWidget, button); i++;
  959. XtSetArg(args[i], XmNbottomAttachment, XmATTACH_FORM); i++;
  960. fc->creator.generate_button_child =
  961. XtCreateManagedWidget("generateButton", xmPushButtonGadgetClass,
  962. form, args, i);
  963. XtAddCallback(fc->creator.generate_button_child, XmNactivateCallback,
  964. GenerateCallback, (XtPointer) fc);
  965. i = 0;
  966. XtSetArg(args[i], XmNrightAttachment, XmATTACH_WIDGET); i++;
  967. XtSetArg(args[i], XmNrightWidget, fc->creator.generate_button_child);i++;
  968. XtSetArg(args[i], XmNbottomAttachment, XmATTACH_FORM); i++;
  969. button = XtCreateManagedWidget("optionsButton", xmPushButtonGadgetClass,
  970. form, args, i);
  971. XtAddCallback(button, XmNactivateCallback, ShowOptions, (XtPointer) fc);
  972. i = 0;
  973. XtSetArg(args[i], XmNleftAttachment, XmATTACH_FORM); i++;
  974. XtSetArg(args[i], XmNbottomAttachment, XmATTACH_FORM); i++;
  975. button = XtCreateManagedWidget("dismissButton", xmPushButtonGadgetClass,
  976. form, args, i);
  977. XtAddCallback(button, XmNactivateCallback,
  978. DismissCallback, (XtPointer) fc);
  979. i = 0;
  980. XtSetArg(args[i], XmNleftAttachment, XmATTACH_FORM); i++;
  981. XtSetArg(args[i], XmNrightAttachment, XmATTACH_FORM); i++;
  982. XtSetArg(args[i], XmNbottomAttachment, XmATTACH_WIDGET); i++;
  983. XtSetArg(args[i], XmNbottomWidget, button); i++;
  984. sep = XtCreateManagedWidget("separator", xmSeparatorGadgetClass,
  985. form, args, i);
  986. i = 0;
  987. XtSetArg(args[i], XmNrightAttachment, XmATTACH_POSITION); i++;
  988. XtSetArg(args[i], XmNbottomAttachment, XmATTACH_WIDGET); i++;
  989. XtSetArg(args[i], XmNbottomWidget, sep); i++;
  990. label = XtCreateManagedWidget("sizeLabel", xmLabelGadgetClass,
  991. form, args, i);
  992. i = 0;
  993. XtSetArg(args[i], XmNleftAttachment, XmATTACH_POSITION); i++;
  994. XtSetArg(args[i], XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET); i++;
  995. XtSetArg(args[i], XmNbottomWidget, label); i++;
  996. fc->creator.size_text_field_child =
  997. XtCreateManagedWidget("sizeTextField", xmTextFieldWidgetClass,
  998. form, args, i);
  999. XtAddCallback(fc->creator.size_text_field_child, XmNvalueChangedCallback,
  1000. SizeSelect, (XtPointer) fc);
  1001. XtAddCallback(fc->creator.size_text_field_child, XmNmodifyVerifyCallback,
  1002. TextVerify, (XtPointer) fc);
  1003. XtAddCallback(fc->creator.size_text_field_child, XmNactivateCallback,
  1004. DrawMMCallback, (XtPointer) fc);
  1005. i = 0;
  1006. fc->creator.size_menu = XmCreatePulldownMenu(form, "sizeMenu", args, i);
  1007. CreateSizeMenu(fc, FALSE);
  1008. i = 0;
  1009. XtSetArg(args[i], XmNleftAttachment, XmATTACH_WIDGET); i++;
  1010. XtSetArg(args[i], XmNleftWidget, fc->creator.size_text_field_child);i++;
  1011. XtSetArg(args[i], XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET); i++;
  1012. XtSetArg(args[i], XmNbottomWidget, label); i++;
  1013. XtSetArg(args[i], XmNsubMenuId, fc->creator.size_menu); i++;
  1014. fc->creator.size_option_menu_child =
  1015. XmCreateOptionMenu(form, "sizeOptionMenu", args, i);
  1016. XtManageChild(fc->creator.size_option_menu_child);
  1017. SizeSelect(fc->creator.size_text_field_child, (XtPointer) fc,
  1018. (XtPointer) NULL);
  1019. i = 0;
  1020. XtSetArg(args[i], XmNbottomAttachment, XmATTACH_WIDGET); i++;
  1021. XtSetArg(args[i], XmNbottomWidget, sep); i++;
  1022. XtSetArg(args[i], XmNrightAttachment, XmATTACH_FORM); i++;
  1023. XtSetArg(args[i], XmNleftAttachment, XmATTACH_POSITION); i++;
  1024. fc->creator.name_text_child =
  1025. XtCreateManagedWidget("nameText", xmTextFieldWidgetClass,
  1026. form, args, i);
  1027. XtAddCallback(fc->creator.name_text_child, XmNactivateCallback,
  1028. AddCallback, (XtPointer) fc);
  1029. i = 0;
  1030. XtSetArg(args[i], XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET); i++;
  1031. XtSetArg(args[i], XmNbottomWidget, fc->creator.name_text_child); i++;
  1032. XtSetArg(args[i], XmNrightAttachment, XmATTACH_POSITION); i++;
  1033. label = XtCreateManagedWidget("nameLabel", xmLabelGadgetClass,
  1034. form, args, i);
  1035. i = 0;
  1036. XtSetArg(args[i], XmNtopAttachment, XmATTACH_FORM); i++;
  1037. XtSetArg(args[i], XmNleftAttachment, XmATTACH_POSITION); i++;
  1038. XtSetArg(args[i], XmNrightAttachment, XmATTACH_FORM); i++;
  1039. label = XtCreateManagedWidget("faceLabel",xmLabelGadgetClass,
  1040. form, args, i);
  1041. i = 0;
  1042. XtSetArg(args[i], XmNitemCount, 1); i++;
  1043. XtSetArg(args[i], XmNitems, &CSempty); i++;
  1044. fc->creator.face_scrolled_list_child =
  1045. XmCreateScrolledList(form, "faceList", args, i);
  1046. XtAddCallback(fc->creator.face_scrolled_list_child,
  1047. XmNbrowseSelectionCallback, FaceSelect, (XtPointer) fc);
  1048. i = 0;
  1049. XtSetArg(args[i], XmNtopAttachment, XmATTACH_WIDGET); i++;
  1050. XtSetArg(args[i], XmNtopWidget, label); i++;
  1051. XtSetArg(args[i], XmNleftAttachment, XmATTACH_POSITION); i++;
  1052. XtSetArg(args[i], XmNrightAttachment, XmATTACH_FORM); i++;
  1053. XtSetArg(args[i], XmNbottomAttachment, XmATTACH_POSITION); i++;
  1054. XtSetValues(XtParent(fc->creator.face_scrolled_list_child), args, i);
  1055. XtManageChild(fc->creator.face_scrolled_list_child);
  1056. i = 0;
  1057. XtSetArg(args[i], XmNtopAttachment, XmATTACH_POSITION); i++;
  1058. XtSetArg(args[i], XmNleftAttachment, XmATTACH_POSITION); i++;
  1059. XtSetArg(args[i], XmNrightAttachment, XmATTACH_FORM); i++;
  1060. fc->creator.blend_label_child =
  1061. XtCreateManagedWidget("blendLabel",xmLabelGadgetClass,
  1062. form, args, i);
  1063. i = 0;
  1064. XtSetArg(args[i], XmNitemCount, 1); i++;
  1065. XtSetArg(args[i], XmNitems, &CSempty); i++;
  1066. fc->creator.blend_scrolled_list_child =
  1067. XmCreateScrolledList(form, "blendList", args, i);
  1068. XtAddCallback(fc->creator.blend_scrolled_list_child,
  1069. XmNbrowseSelectionCallback, BlendSelect, (XtPointer) fc);
  1070. i = 0;
  1071. XtSetArg(args[i], XmNtopAttachment, XmATTACH_WIDGET); i++;
  1072. XtSetArg(args[i], XmNtopWidget, fc->creator.blend_label_child); i++;
  1073. XtSetArg(args[i], XmNleftAttachment, XmATTACH_POSITION); i++;
  1074. XtSetArg(args[i], XmNrightAttachment, XmATTACH_FORM); i++;
  1075. XtSetArg(args[i], XmNbottomAttachment, XmATTACH_WIDGET); i++;
  1076. XtSetArg(args[i], XmNbottomWidget, fc->creator.name_text_child); i++;
  1077. XtSetValues(XtParent(fc->creator.blend_scrolled_list_child), args, i);
  1078. XtManageChild(fc->creator.blend_scrolled_list_child);
  1079. i = 0;
  1080. XtSetArg(args[i], XmNleftAttachment, XmATTACH_POSITION); i++;
  1081. XtSetArg(args[i], XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET); i++;
  1082. XtSetArg(args[i], XmNtopWidget,
  1083. XtParent(fc->creator.face_scrolled_list_child)); i++;
  1084. XtSetArg(args[i], XmNrightAttachment, XmATTACH_POSITION); i++;
  1085. fc->creator.display_text_child =
  1086. XtCreateManagedWidget("displayText", xmTextFieldWidgetClass,
  1087. form, args, i);
  1088. XtAddCallback(fc->creator.display_text_child, XmNactivateCallback,
  1089. DrawMMCallback, (XtPointer) fc);
  1090. i = 0;
  1091. XtSetArg(args[i], XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET); i++;
  1092. XtSetArg(args[i], XmNtopWidget, fc->creator.display_text_child); i++;
  1093. XtSetArg(args[i], XmNrightAttachment, XmATTACH_POSITION); i++;
  1094. label = XtCreateManagedWidget("displayTextLabel", xmLabelGadgetClass,
  1095. form, args, i);
  1096. prev = fc->creator.display_text_child;
  1097. for (j = 0; j < 4; j++) {
  1098. i = 0;
  1099. XtSetArg(args[i], XmNrightAttachment, XmATTACH_POSITION); i++;
  1100. XtSetArg(args[i], XmNtopAttachment, XmATTACH_WIDGET); i++;
  1101. XtSetArg(args[i], XmNtopWidget, prev); i++;
  1102. sprintf(buf, "axisValue%d", j+1);
  1103. fc->creator.axis_value_text_child[j] =
  1104. XtCreateWidget(buf, xmTextFieldWidgetClass, form, args, i);
  1105. i = 0;
  1106. XtSetArg(args[i], XmNleftAttachment, XmATTACH_POSITION); i++;
  1107. XtSetArg(args[i], XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET); i++;
  1108. XtSetArg(args[i], XmNtopWidget,
  1109. fc->creator.axis_value_text_child[j]); i++;
  1110. XtSetArg(args[i], XmNrightAttachment, XmATTACH_WIDGET); i++;
  1111. XtSetArg(args[i], XmNrightWidget,
  1112. fc->creator.axis_value_text_child[j]); i++;
  1113. sprintf(buf, "axisScale%d", j+1);
  1114. fc->creator.axis_scale_child[j] =
  1115. XtCreateWidget(buf, xmScaleWidgetClass, form, args, i);
  1116. XtAddCallback(fc->creator.axis_scale_child[j],
  1117. XmNvalueChangedCallback, DrawMMCallback, (XtPointer) fc);
  1118. XtAddCallback(fc->creator.axis_scale_child[j],
  1119. XmNdragCallback, DrawMMCallback, (XtPointer) fc);
  1120. XtAddCallback(fc->creator.axis_scale_child[j],
  1121. XmNvalueChangedCallback, SetValue,
  1122. (XtPointer) fc->creator.axis_value_text_child[j]);
  1123. XtAddCallback(fc->creator.axis_scale_child[j],
  1124. XmNdragCallback, SetValue,
  1125. (XtPointer) fc->creator.axis_value_text_child[j]);
  1126. XtAddCallback(fc->creator.axis_value_text_child[j],
  1127. XmNactivateCallback, SetScale,
  1128. (XtPointer) fc->creator.axis_scale_child[j]);
  1129. i = 0;
  1130. XtSetArg(args[i], XmNtopAttachment, XmATTACH_WIDGET); i++;
  1131. XtSetArg(args[i], XmNtopWidget,
  1132. fc->creator.axis_scale_child[j]); i++;
  1133. XtSetArg(args[i], XmNrightAttachment, XmATTACH_OPPOSITE_WIDGET);i++;
  1134. XtSetArg(args[i], XmNrightWidget,
  1135. fc->creator.axis_scale_child[j]); i++;
  1136. sprintf(buf, "axisMax%d", j+1);
  1137. fc->creator.axis_max_label_child[j] =
  1138. XtCreateWidget(buf, xmLabelGadgetClass, form, args, i);
  1139. i = 0;
  1140. XtSetArg(args[i], XmNtopAttachment, XmATTACH_WIDGET); i++;
  1141. XtSetArg(args[i], XmNtopWidget,
  1142. fc->creator.axis_scale_child[j]); i++;
  1143. XtSetArg(args[i], XmNleftAttachment, XmATTACH_OPPOSITE_WIDGET); i++;
  1144. XtSetArg(args[i], XmNleftWidget,
  1145. fc->creator.axis_scale_child[j]); i++;
  1146. sprintf(buf, "axisMin%d", j+1);
  1147. fc->creator.axis_min_label_child[j] =
  1148. XtCreateWidget(buf, xmLabelGadgetClass, form, args, i);
  1149. i = 0;
  1150. XtSetArg(args[i], XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET); i++;
  1151. XtSetArg(args[i], XmNtopWidget,
  1152. fc->creator.axis_value_text_child[j]); i++;
  1153. XtSetArg(args[i], XmNrightAttachment, XmATTACH_POSITION); i++;
  1154. sprintf(buf, "axisLabel%d", j+1);
  1155. fc->creator.axis_label_child[j] =
  1156. XtCreateWidget(buf, xmLabelGadgetClass, form, args, i);
  1157. prev = fc->creator.axis_value_text_child[j];
  1158. }
  1159. /* Create the options box so we have the toggles */
  1160. fc->creator.option_box = XmCreateFormDialog((Widget) fc, "optionBox",
  1161. (Arg *) NULL, 0);
  1162. w = XtCreateManagedWidget("filterBox", xmRowColumnWidgetClass,
  1163. fc->creator.option_box, (Arg *) NULL, 0);
  1164. fc->creator.do_all_toggle_child =
  1165. XtCreateManagedWidget("doAllToggle", xmToggleButtonGadgetClass,
  1166. w, (Arg *) NULL, 0);
  1167. fc->creator.follow_size_toggle_child =
  1168. XtCreateManagedWidget("followSizeToggle",
  1169. xmToggleButtonGadgetClass,
  1170. w, (Arg *) NULL, 0);
  1171. button = XtCreateManagedWidget("dismissOptionButton",
  1172. xmPushButtonGadgetClass,
  1173. w, (Arg *) NULL, 0);
  1174. XtAddCallback(button, XmNactivateCallback,
  1175. UnmanageOptions, (XtPointer) fc);
  1176. }
  1177. /* ARGSUSED */
  1178. static void Initialize(
  1179. Widget request, Widget new,
  1180. ArgList args,
  1181. Cardinal *num_args)
  1182. {
  1183. FontCreatorWidget fc = (FontCreatorWidget) new;
  1184. /* Must have a fsb */
  1185. if (fc->creator.fsb == NULL) {
  1186. XtAppErrorMsg(XtWidgetToApplicationContext(new),
  1187. "initializeFontCreator", "noFontSelectionBox",
  1188. "FontSelectionBoxError",
  1189. "No font selection box given to font creator",
  1190. (String *) NULL, (Cardinal *) NULL);
  1191. }
  1192. /* Verify size list */
  1193. if (fc->creator.size_count > 0 && fc->creator.sizes == NULL) {
  1194. XtAppWarningMsg(XtWidgetToApplicationContext(new),
  1195. "initializeFontCreator", "sizeMismatch",
  1196. "FontSelectionBoxError",
  1197. "Size count specified but no sizes present",
  1198. (String *) NULL, (Cardinal *) NULL);
  1199. fc->creator.size_count = 0;
  1200. }
  1201. if (fc->creator.size_count < 0) {
  1202. XtAppWarningMsg(XtWidgetToApplicationContext(new),
  1203. "initializeFontCreator", "negativeSize",
  1204. "FontSelectionBoxError",
  1205. "Size count should not be negative",
  1206. (String *) NULL, (Cardinal *) NULL);
  1207. fc->creator.size_count = 0;
  1208. }
  1209. fc->creator.gstate = 0;
  1210. fc->creator.family = NULL;
  1211. fc->creator.font = NULL;
  1212. fc->creator.managed_axes = 0;
  1213. fc->creator.preview_fixed = False;
  1214. fc->creator.option_box = NULL;
  1215. CreateChildren(fc);
  1216. XtAddCallback(fc->creator.fsb->fsb.size_text_field_child,
  1217. XmNvalueChangedCallback, SizeChanged, (XtPointer) fc);
  1218. }
  1219. static void SelectBlend(FontCreatorWidget fc, BlendRec *cur_b)
  1220. {
  1221. int i, cur = 0;
  1222. BlendRec *b;
  1223. int *selectList, selectCount;
  1224. if (cur_b == NULL) {
  1225. if (!XmListGetSelectedPos(fc->creator.blend_scrolled_list_child,
  1226. &selectList, &selectCount)) return;
  1227. if (selectCount == 0 || *selectList < 1) return;
  1228. cur = *selectList;
  1229. XtFree((XtPointer) selectList);
  1230. } else {
  1231. for (i = 0, b = fc->creator.font->blend_data->blends;
  1232. i < fc->creator.font->blend_count; i++, b = b->next) {
  1233. if (b == cur_b) {
  1234. cur = i+1;
  1235. break;
  1236. }
  1237. }
  1238. }
  1239. ListSelectPos(fc->creator.blend_scrolled_list_child, cur, FALSE);
  1240. HandleSelectedBlend(fc, cur);
  1241. }
  1242. void _FSBSetCreatorFamily(Widget w, FontFamilyRec *ff)
  1243. {
  1244. FontCreatorWidget fc = (FontCreatorWidget) w;
  1245. int i, count = 0, cur = 1;
  1246. FontRec *newf = NULL, *f, *oldf = fc->creator.font;
  1247. XmString *CSfaces;
  1248. if (ff != fc->creator.family) {
  1249. fc->creator.family = ff;
  1250. CSfaces = (XmString *) XtCalloc(ff->font_count, sizeof(XmString));
  1251. for (i = 0, f = ff->fonts; i < ff->font_count; i++, f = f->next) {
  1252. if (f->blend_data == NULL) continue;
  1253. if (newf == NULL) newf = f;
  1254. CSfaces[count] = f->CS_face_name;
  1255. count++;
  1256. if (f == fc->creator.fsb->fsb.currently_selected_face) {
  1257. cur = count;
  1258. newf = f;
  1259. }
  1260. }
  1261. XtVaSetValues(fc->creator.face_scrolled_list_child,
  1262. XmNitemCount, count, XmNitems, CSfaces, NULL);
  1263. XtFree((XtPointer) CSfaces);
  1264. } else {
  1265. for (i = 0, f = ff->fonts; i < ff->font_count; i++, f = f->next) {
  1266. if (f->blend_data == NULL) continue;
  1267. count++;
  1268. if (newf == NULL) newf = f;
  1269. if (f == fc->creator.fsb->fsb.currently_selected_face) {
  1270. cur = count;
  1271. newf = f;
  1272. break;
  1273. }
  1274. }
  1275. }
  1276. if (fc->creator.font != NULL) fc->creator.font->in_font_creator = False;
  1277. fc->creator.font = newf;
  1278. newf->in_font_creator = True;
  1279. ListSelectPos(fc->creator.face_scrolled_list_child, cur, FALSE);
  1280. SetUpBlendList(fc);
  1281. SetUpAxes(fc, oldf);
  1282. if (fc->creator.fsb->fsb.currently_selected_blend != 0) {
  1283. SelectBlend(fc, fc->creator.fsb->fsb.currently_selected_blend);
  1284. } else {
  1285. SelectBlend(fc, NULL);
  1286. }
  1287. SetScaleValues(fc);
  1288. XmTextFieldSetString(fc->creator.display_text_child, ff->family_name);
  1289. DrawMM(fc);
  1290. }
  1291. static void Destroy(Widget widget)
  1292. {
  1293. FontCreatorWidget fc = (FontCreatorWidget) widget;
  1294. if (fc->creator.gstate != 0) {
  1295. XDPSFreeContextGState(fc->creator.fsb->fsb.context,
  1296. fc->creator.gstate);
  1297. }
  1298. }
  1299. static void Resize(Widget widget)
  1300. {
  1301. FontCreatorWidget fc = (FontCreatorWidget) widget;
  1302. XtResizeWidget(fc->creator.pane_child, fc->core.width, fc->core.height, 0);
  1303. }
  1304. /* ARGSUSED */
  1305. static Boolean SetValues(
  1306. Widget old, Widget req, Widget new,
  1307. ArgList args,
  1308. Cardinal *num_args)
  1309. {
  1310. FontCreatorWidget oldfc = (FontCreatorWidget) old;
  1311. FontCreatorWidget newfc = (FontCreatorWidget) new;
  1312. #define NE(field) newfc->creator.field != oldfc->creator.field
  1313. if (NE(fsb)) newfc->creator.fsb = oldfc->creator.fsb;
  1314. if (newfc->creator.size_count > 0 && newfc->creator.sizes == NULL) {
  1315. XtAppWarningMsg(XtWidgetToApplicationContext(new),
  1316. "setValuesFontCreator", "sizeMismatch",
  1317. "FontSelectionBoxError",
  1318. "Size count specified but no sizes present",
  1319. (String *) NULL, (Cardinal *) NULL);
  1320. newfc->creator.size_count = 0;
  1321. }
  1322. if (newfc->creator.size_count < 0) {
  1323. XtAppWarningMsg(XtWidgetToApplicationContext(new),
  1324. "setValuesFontCreator", "negativeSize",
  1325. "FontSelectionBoxError",
  1326. "Size count should not be negative",
  1327. (String *) NULL, (Cardinal *) NULL);
  1328. newfc->creator.size_count = 0;
  1329. }
  1330. if (NE(sizes)) CreateSizeMenu(newfc, TRUE);
  1331. #undef NE
  1332. return False;
  1333. }
  1334. /* ARGSUSED */
  1335. static XtGeometryResult GeometryManager(
  1336. Widget w,
  1337. XtWidgetGeometry *desired, XtWidgetGeometry *allowed)
  1338. {
  1339. #define WANTS(flag) (desired->request_mode & flag)
  1340. if (WANTS(XtCWQueryOnly)) return XtGeometryYes;
  1341. if (WANTS(CWWidth)) w->core.width = desired->width;
  1342. if (WANTS(CWHeight)) w->core.height = desired->height;
  1343. if (WANTS(CWX)) w->core.x = desired->x;
  1344. if (WANTS(CWY)) w->core.y = desired->y;
  1345. if (WANTS(CWBorderWidth)) {
  1346. w->core.border_width = desired->border_width;
  1347. }
  1348. return XtGeometryYes;
  1349. #undef WANTS
  1350. }
  1351. static void ChangeManaged(Widget w)
  1352. {
  1353. FontCreatorWidget fc = (FontCreatorWidget) w;
  1354. w->core.width = fc->composite.children[0]->core.width;
  1355. w->core.height = fc->composite.children[0]->core.height;
  1356. }