~ubuntu-branches/ubuntu/precise/xcircuit/precise

« back to all changes in this revision

Viewing changes to text.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Ablassmeier
  • Date: 2006-05-22 10:08:25 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20060522100825-mk2nt6epw2dvvfaa
Tags: 3.6.24-1
* QA Upload 
* New Upstream Version (Closes: #266080, #262321)
* Update debian/copyright
* debian/{menu, install}:
  + install pixmaps to /usr/share/pixmaps/xcircuit/
* Conforms with new Standards version 3.7.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
/*------------------------------------------------------------------------*/
34
34
 
35
35
extern Display *dpy;
36
 
extern Clientdata areastruct;
 
36
extern XCWindowData *areawin;
37
37
extern Globaldata xobjs;
38
38
extern short textpos, textend;
39
39
extern short fontcount;
40
40
extern fontinfo *fonts;
41
 
extern short eventmode;
42
41
extern int *appcolors;
43
42
extern colorindex *colorlist;
44
43
extern char _STR[150];
92
91
   int tpos;
93
92
   labelptr dest, source;
94
93
 
95
 
   if (areastruct.selects < 2) {
 
94
   if (areawin->selects < 2) {
96
95
      Wprintf("Not enough labels selected for joining");
97
96
      return;
98
97
   }
99
98
 
100
99
   XcSetFunction(GXcopy);
101
 
   XSetForeground(dpy, areastruct.gc, BACKGROUND);
 
100
   XSetForeground(dpy, areawin->gc, BACKGROUND);
102
101
 
103
 
   for (jl = areastruct.selectlist; jl < areastruct.selectlist +
104
 
                areastruct.selects; jl++) {
 
102
   for (jl = areawin->selectlist; jl < areawin->selectlist +
 
103
                areawin->selects; jl++) {
105
104
      if (SELECTTYPE(jl) == LABEL) {
106
105
         dest = SELTOLABEL(jl);
107
 
         UDrawString(dest, DOFORALL, areastruct.topinstance);
 
106
         UDrawString(dest, DOFORALL, areawin->topinstance);
108
107
         for (endpart = dest->string; endpart->nextpart != NULL; endpart =
109
108
                        endpart->nextpart);
110
109
         break;
111
110
      }
112
111
   }
113
112
      
114
 
   for (++jl; jl < areastruct.selectlist + areastruct.selects; jl++) {
 
113
   for (++jl; jl < areawin->selectlist + areawin->selects; jl++) {
115
114
      if (SELECTTYPE(jl) == LABEL) {
116
115
         source = SELTOLABEL(jl);
117
 
         UDrawString(source, DOFORALL, areastruct.topinstance);
 
116
         UDrawString(source, DOFORALL, areawin->topinstance);
118
117
         endpart->nextpart = source->string;
119
118
         for (; endpart->nextpart != NULL; endpart = endpart->nextpart);
120
119
         free(source);
121
120
         removep(jl, 0);
122
 
         reviseselect(areastruct.selectlist, areastruct.selects, jl);
 
121
         reviseselect(areawin->selectlist, areawin->selects, jl);
123
122
      }
124
123
   }
125
124
 
126
 
   XSetForeground(dpy, areastruct.gc, dest->color);
127
 
   UDrawString(dest, dest->color, areastruct.topinstance);
 
125
   XSetForeground(dpy, areawin->gc, dest->color);
 
126
   UDrawString(dest, dest->color, areawin->topinstance);
128
127
 
129
128
   incr_changes(topobject);
130
129
   clearselects();
147
146
   }
148
147
   else {                               /* otherwise */
149
148
      for(lastptr = *strhead; lastptr != NULL;) {
150
 
         nextptr = nextstringpart(lastptr, areastruct.topinstance);
 
149
         nextptr = nextstringpart(lastptr, areawin->topinstance);
151
150
         if (nextptr == before) {
152
151
            if (lastptr->type == PARAM_START) {
153
152
               oparamptr obs = NULL;
154
153
               char *key = lastptr->data.string;
155
 
               obs = find_param(areastruct.topinstance, key);
 
154
               obs = find_param(areawin->topinstance, key);
156
155
               if (obs == NULL) {
157
156
                  Wprintf("Error:  Bad parameter!");
158
157
                  return NULL;
204
203
/* Get the next string part, linking to a paramter if necessary         */
205
204
/*----------------------------------------------------------------------*/
206
205
 
207
 
stringpart *nextstringpart(stringpart *strptr, objinstptr thisinst)
 
206
stringpart *nextstringpartrecompute(stringpart *strptr, objinstptr thisinst)
208
207
{
209
208
   stringpart *nextptr = strptr->nextpart;
210
209
 
232
231
/* when encountered.  Use the previously generated result.              */
233
232
/*----------------------------------------------------------------------*/
234
233
 
235
 
stringpart *nextstringpartnorecompute(stringpart *strptr, objinstptr thisinst)
 
234
stringpart *nextstringpart(stringpart *strptr, objinstptr thisinst)
236
235
{
237
236
   stringpart *nextptr = strptr->nextpart;
238
237
 
305
304
      else
306
305
         strptr->nextpart = dstr->nextpart;
307
306
   }
308
 
   if (dstr->type == TEXT_STRING) free(dstr->data.string);
 
307
   if (dstr->type == TEXT_STRING)
 
308
      free(dstr->data.string);
309
309
   free(dstr);
310
310
 
311
311
   /* attempt to merge, if legal */
388
388
         tmpptr = makesegment(&promote, NULL);
389
389
         tmpptr->type = PARAM_END;
390
390
      }
391
 
      else
392
 
         free(promote->data.string);
 
391
      else {
 
392
         if (promote->data.string != NULL) {
 
393
            free(promote->data.string);
 
394
            promote->data.string = NULL;
 
395
         }
 
396
      }
393
397
 
394
398
      /* Promote numerical type to string */
395
399
      if (ops->type == XC_INT) {
407
411
         if (!compute_exprs && (ips = match_instance_param(localinst, key))
408
412
                != NULL && (ips->type == XC_STRING)) {
409
413
            nextptr = ips->parameter.string;
410
 
            /* This could probably be done better. . . hack to keep  */
411
 
            /* free() from operating twice on the same memory block. */
412
 
            promote->data.string = (char *)malloc(1);
 
414
            promote->data.string = NULL;
413
415
         }
414
416
         else {
415
417
            promote->data.string = evaluate_expr(ops, localinst);
416
 
            nextptr = promote;
 
418
            if (promote->data.string != NULL)
 
419
               nextptr = promote;
 
420
            else
 
421
               nextptr = NULL;
417
422
         }
418
423
      }
419
424
   }
520
525
        "Tab_Stop", "Tab_Forward", "Tab_Backward",
521
526
        "Halfspace", "Quarterspace", "<Return>",
522
527
        "Font", "Scale", "Color", "Kern", 
523
 
        "Parameter", ">", "Error"};
 
528
        "Parameter", ">", "Net_Name", "Error"};
524
529
 
525
530
/*----------------------------------------------------------------------*/
526
531
/* charprint():                                                         */
627
632
 
628
633
   newstr = xcstringtostring(strtop, localinst, True);
629
634
   if (subnet >= 0) {
630
 
      busptr = strchr(newstr, areastruct.buschar);
 
635
      busptr = strchr(newstr, areawin->buschar);
631
636
      if (busptr != NULL) {
632
637
         endptr = find_delimiter(busptr);
633
638
         if (endptr != NULL) {
648
653
         strcpy(substr, newstr);
649
654
         endptr = substr;
650
655
         while ((*endptr) != '\0') endptr++;
651
 
         sprintf(endptr, "%c%d%c", areastruct.buschar, subnet,
652
 
                standard_delimiter_end(areastruct.buschar));
 
656
         sprintf(endptr, "%c%d%c", areawin->buschar, subnet,
 
657
                standard_delimiter_end(areawin->buschar));
653
658
         free(newstr);
654
659
         return substr;
655
660
      }
679
684
   else {       /* just make a comma-separated list */
680
685
      newstr = (char *)malloc(strlen(prefix) + 20 + 3 * sublist->subnets);
681
686
      sbus = sublist->net.list;
682
 
      sprintf(newstr, "%s%d%c", prefix, sbus->netid, areastruct.buschar);
 
687
      sprintf(newstr, "%s%d%c", prefix, sbus->netid, areawin->buschar);
683
688
      for (i = 0; i < sublist->subnets; i++) {
684
689
         sbus = sublist->net.list + i;
685
690
         sptr = newstr + strlen(newstr);
688
693
         sprintf(sptr, "%d", sbus->subnetid);
689
694
      }
690
695
      sptr = newstr + strlen(newstr);
691
 
      sprintf(sptr, "%c", standard_delimiter_end(areastruct.buschar));
 
696
      sprintf(sptr, "%c", standard_delimiter_end(areawin->buschar));
692
697
   }
693
698
   return newstr;
694
699
}
823
828
   for (strptr = thislab->string; strptr != NULL; strptr =
824
829
                nextstringpart(strptr, thisinst)) {
825
830
      if (strptr->type == TEXT_STRING) {
826
 
         if ((busptr = strchr(strptr->data.string, areastruct.buschar)) != NULL) {
 
831
         if ((busptr = strchr(strptr->data.string, areawin->buschar)) != NULL) {
827
832
            if (sscanf(++busptr, "%d", &busidx) == 1)
828
833
               return busidx;
829
834
         }
853
858
   for (strptr = thislab->string; strptr != NULL; strptr =
854
859
                nextstringpart(strptr, thisinst)) {
855
860
      if (strptr->type == TEXT_STRING) {
856
 
         if ((busptr = strchr(strptr->data.string, areastruct.buschar)) != NULL) {
 
861
         if ((busptr = strchr(strptr->data.string, areawin->buschar)) != NULL) {
857
862
            if (isdigit(*(++busptr)))
858
863
               return TRUE;
859
864
            else
908
913
 
909
914
   tptr = textprint(blab->string, thisinst);
910
915
   tlen = strlen(tptr) + 1;
911
 
   buspos = strchr(tptr, areastruct.buschar);
 
916
   buspos = strchr(tptr, areawin->buschar);
912
917
 
913
918
   /* The notation "(...)" with NO TEXT preceding the opening bus       */
914
919
   /* delimiter, is assumed to represent a numerical pin range.  So     */
1037
1042
         switch (strptr1->type) {
1038
1043
            case TEXT_STRING:
1039
1044
               if (in_bus == 1) {
1040
 
                  char matchchar = areastruct.buschar;
1041
 
                  switch (areastruct.buschar) {
 
1045
                  char matchchar = areawin->buschar;
 
1046
                  switch (areawin->buschar) {
1042
1047
                     case '(': matchchar = ')'; break;
1043
1048
                     case '[': matchchar = ']'; break;
1044
1049
                     case '{': matchchar = '}'; break;
1067
1072
               /* except between the bus notation delimiters (default   */
1068
1073
               /* "()".                                                 */
1069
1074
                
1070
 
               buspos = strchr(strptr1->data.string, areastruct.buschar);
 
1075
               buspos = strchr(strptr1->data.string, areawin->buschar);
1071
1076
               if (buspos != NULL) {
1072
1077
 
1073
1078
                  bpos = (int)(buspos - (char *)(strptr1->data.string)) + 1;
1353
1358
   int    defaultcolor, curcolor, scolor;
1354
1359
   short  oldx, oldfont, oldstyle;
1355
1360
   float  tmpscale = 1.0, natscale = 1.0;
1356
 
   float  tmpthick = xobjs.pagelist[areastruct.page]->wirewidth;
 
1361
   float  tmpthick = xobjs.pagelist[areawin->page]->wirewidth;
1357
1362
   XPoint newpoint, bboxin[2], bboxout[2];
1358
1363
   u_char xm, ym;
1359
1364
   TextExtents tmpext;
1402
1407
   /* them from the circuit point to which they attach.  */
1403
1408
 
1404
1409
   if (drawlabel->pin) {
1405
 
      if (!areastruct.schemon)
1406
 
         goto enddraw;  /* Don't draw pins when schematic capture is off */
1407
 
      else
1408
 
         pinadjust(tmpjust, &(newpoint.x), &(newpoint.y), 1);
 
1410
      pinadjust(tmpjust, &(newpoint.x), &(newpoint.y), 1);
1409
1411
   }
1410
1412
 
1411
1413
   oldx = newpoint.x;
1421
1423
   xm = (bboxout[0].x < bboxout[1].x) ? 0 : 1;
1422
1424
   ym = (bboxout[0].y < bboxout[1].y) ? 0 : 1;
1423
1425
 
1424
 
   if (bboxout[xm].x < areastruct.width && bboxout[ym].y < areastruct.height &&
 
1426
   if (bboxout[xm].x < areawin->width && bboxout[ym].y < areawin->height &&
1425
1427
       bboxout[1 - xm].x > 0 && bboxout[1 - ym].y > 0) {
1426
1428
 
1427
1429
       pos = 0;
1428
1430
       for (strptr = drawlabel->string; strptr != NULL;
1429
 
                strptr = nextstringpartnorecompute(strptr, localinst)) {
 
1431
                strptr = nextstringpart(strptr, localinst)) {
1430
1432
 
1431
1433
          /* All segments other than text cancel any    */
1432
1434
          /* existing overline/underline in effect.     */
1447
1449
                
1448
1450
                /* simple boldface technique for derived fonts */
1449
1451
 
1450
 
                xobjs.pagelist[areastruct.page]->wirewidth =
 
1452
                xobjs.pagelist[areawin->page]->wirewidth =
1451
1453
                   ((fonts[ffont].flags & 0x21) == 0x21) ?  4.0 : 2.0;
1452
1454
                break;
1453
1455
 
1561
1563
                } break;
1562
1564
 
1563
1565
             case TEXT_STRING:
1564
 
                for (textptr = strptr->data.string; textptr && *textptr != '\0'; textptr++) {
 
1566
                for (textptr = strptr->data.string; textptr && *textptr != '\0';
 
1567
                        textptr++) {
1565
1568
                   pos++;
1566
1569
                   UPushCTM();
1567
1570
                   UPreMultCTM(DCTM, newpoint, tmpscale, 0);
1597
1600
 
1598
1601
   UPopCTM();
1599
1602
 
1600
 
   if (drawlabel->pin && areastruct.schemon) UDrawXDown(drawlabel);
 
1603
   if (drawlabel->pin) UDrawXDown(drawlabel);
1601
1604
 
1602
1605
   if ((defaultcolor != DOFORALL) && (passcolor != curcolor)) {
1603
1606
      XTopSetForeground(passcolor);
1604
1607
   }
1605
1608
 
1606
 
   xobjs.pagelist[areastruct.page]->wirewidth = tmpthick;
 
1609
   xobjs.pagelist[areawin->page]->wirewidth = tmpthick;
1607
1610
}
1608
1611
 
1609
1612
/*----------------------------------------------------------------------*/
1756
1759
 
1757
1760
void undrawtextsimple(labelptr settext)
1758
1761
{
1759
 
   SetFunction(dpy, areastruct.gc, GXcopy);
 
1762
   SetFunction(dpy, areawin->gc, GXcopy);
1760
1763
   XTopSetForeground(BACKGROUND);
1761
 
   UDrawString(settext, DOFORALL, areastruct.topinstance);
 
1764
   UDrawString(settext, DOFORALL, areawin->topinstance);
1762
1765
}
1763
1766
 
1764
1767
/*----------------------------------------------------------------------*/
1765
1768
 
1766
1769
void redrawtextsimple(labelptr settext)
1767
1770
{
1768
 
   UDrawString(settext, settext->color, areastruct.topinstance);
 
1771
   UDrawString(settext, settext->color, areawin->topinstance);
1769
1772
}
1770
1773
 
1771
1774
/*----------------------------------------------------------------------*/
1856
1859
   directory->parts = 0;
1857
1860
 
1858
1861
   /* 0.5 is the default vscale;  16 is no. characters per line */
1859
 
   del = min(areastruct.width, areastruct.height) / (0.5 * 16);
 
1862
   del = min(areawin->width, areawin->height) / (0.5 * 16);
1860
1863
   qdel = del >> 2;
1861
1864
 
1862
1865
   for (i = 0; i < 256; i++) {
1929
1932
 
1930
1933
   if (op != XCF_Cancel) {
1931
1934
 
1932
 
      window_to_user(x, y, &areastruct.save);
 
1935
      window_to_user(x, y, &areawin->save);
1933
1936
 
1934
 
      chy = -areastruct.save.y / del + 1;
1935
 
      chx = areastruct.save.x / del;
 
1937
      chy = -areawin->save.y / del + 1;
 
1938
      chx = areawin->save.x / del;
1936
1939
 
1937
1940
      chx = min(15, chx);
1938
1941
      chy = min(15, chy);