Fossil SCM

Update the built-in pikchr.c to include the latest enhancements and fixes.

drh 2020-09-26 11:24 trunk
Commit 1347e990ac744d7d5539524787ff1819c9882173e0f147695560302360df348d
1 file changed +41 -8
+41 -8
--- src/pikchr.c
+++ src/pikchr.c
@@ -370,11 +370,11 @@
370370
const char *zName; /* Name of class */
371371
char isLine; /* True if a line class */
372372
char eJust; /* Use box-style text justification */
373373
void (*xInit)(Pik*,PElem*); /* Initializer */
374374
void (*xNumProp)(Pik*,PElem*,PToken*); /* Value change notification */
375
- void (*xCheck)(Pik*,PElem*); /* Checks to after parsing */
375
+ void (*xCheck)(Pik*,PElem*); /* Checks to do after parsing */
376376
PPoint (*xChop)(Pik*,PElem*,PPoint*); /* Chopper */
377377
PPoint (*xOffset)(Pik*,PElem*,int); /* Offset from .c to edge point */
378378
void (*xFit)(Pik*,PElem*,PNum w,PNum h); /* Size to fit text */
379379
void (*xRender)(Pik*,PElem*); /* Render */
380380
};
@@ -4424,11 +4424,11 @@
44244424
}
44254425
44264426
/*
44274427
** Append text to zOut with HTML characters escaped.
44284428
**
4429
-** * The space character is changed into non-breaking space (U+0080)
4429
+** * The space character is changed into non-breaking space (U+00a0)
44304430
** if mFlags has the 0x01 bit set. This is needed when outputting
44314431
** text to preserve leading and trailing whitespace. Turns out we
44324432
** cannot use   as that is an HTML-ism and is not valid in XML.
44334433
**
44344434
** * The "&" character is changed into "&" if mFlags has the
@@ -4790,12 +4790,17 @@
47904790
pik_append_xy(p, " ", x, orig_y);
47914791
pik_append(p,")\"",2);
47924792
}
47934793
}
47944794
pik_append(p," dominant-baseline=\"central\">",-1);
4795
- z = t->z+1;
4796
- nz = t->n-2;
4795
+ if( t->n>=2 && t->z[0]=='"' ){
4796
+ z = t->z+1;
4797
+ nz = t->n-2;
4798
+ }else{
4799
+ z = t->z;
4800
+ nz = t->n;
4801
+ }
47974802
while( nz>0 ){
47984803
int j;
47994804
for(j=0; j<nz && z[j]!='\\'; j++){}
48004805
if( j ) pik_append_text(p, z, j, 1);
48014806
nz -= j+1;
@@ -5915,11 +5920,11 @@
59155920
/*
59165921
** Look up a color-name. Unlike other names in this program, the
59175922
** color-names are not case sensitive. So "DarkBlue" and "darkblue"
59185923
** and "DARKBLUE" all find the same value (139).
59195924
**
5920
-** If not found, return -1.0. Also post an error if p!=NULL.
5925
+** If not found, return -99.0. Also post an error if p!=NULL.
59215926
**
59225927
** Special color names "None" and "Off" return -1.0 without causing
59235928
** an error.
59245929
*/
59255930
static PNum pik_lookup_color(Pik *p, PToken *pId){
@@ -5947,11 +5952,11 @@
59475952
}else{
59485953
last = mid-1;
59495954
}
59505955
}
59515956
if( p ) pik_error(p, pId, "not a known color name");
5952
- return -1.0;
5957
+ return -99.0;
59535958
}
59545959
59555960
/* Get the value of a variable.
59565961
**
59575962
** Search in order:
@@ -5965,11 +5970,11 @@
59655970
static PNum pik_get_var(Pik *p, PToken *pId){
59665971
int miss = 0;
59675972
PNum v = pik_value(p, pId->z, pId->n, &miss);
59685973
if( miss==0 ) return v;
59695974
v = pik_lookup_color(0, pId);
5970
- if( v>=0.0 ) return v;
5975
+ if( v>-90.0 ) return v;
59715976
pik_error(p,pId,"no such variable");
59725977
return 0.0;
59735978
}
59745979
59755980
/* Convert a T_NTH token (ex: "2nd", "5th"} into a numeric value and
@@ -6471,11 +6476,13 @@
64716476
void pik_elist_render(Pik *p, PEList *pEList){
64726477
int i;
64736478
int iNextLayer = 0;
64746479
int iThisLayer;
64756480
int bMoreToDo;
6481
+ int miss = 0;
64766482
int mDebug = (int)pik_value(p, "debug", 5, 0);
6483
+ PNum colorLabel;
64776484
do{
64786485
bMoreToDo = 0;
64796486
iThisLayer = iNextLayer;
64806487
iNextLayer = 0x7fffffff;
64816488
for(i=0; i<pEList->n; i++){
@@ -6496,10 +6503,33 @@
64966503
if( pElem->pSublist ){
64976504
pik_elist_render(p, pElem->pSublist);
64986505
}
64996506
}
65006507
}while( bMoreToDo );
6508
+
6509
+ /* If the color_debug_label value is defined, then go through
6510
+ ** and paint a dot at every label location */
6511
+ colorLabel = pik_value(p, "debug_label_color", 17, &miss);
6512
+ if( miss==0 && colorLabel>=0.0 ){
6513
+ PElem dot;
6514
+ memset(&dot, 0, sizeof(dot));
6515
+ dot.type = &noopClass;
6516
+ dot.rad = 0.015;
6517
+ dot.sw = 0.015;
6518
+ dot.fill = colorLabel;
6519
+ dot.color = colorLabel;
6520
+ dot.nTxt = 1;
6521
+ dot.aTxt[0].eCode = TP_ABOVE;
6522
+ for(i=0; i<pEList->n; i++){
6523
+ PElem *pElem = pEList->a[i];
6524
+ if( pElem->zName==0 ) continue;
6525
+ dot.ptAt = pElem->ptAt;
6526
+ dot.aTxt[0].z = pElem->zName;
6527
+ dot.aTxt[0].n = (int)strlen(pElem->zName);
6528
+ dotRender(p, &dot);
6529
+ }
6530
+ }
65016531
}
65026532
65036533
/* Add all elements of the list pEList to the bounding box
65046534
*/
65056535
static void pik_bbox_add_elist(Pik *p, PEList *pEList, PNum wArrow){
@@ -7109,10 +7139,13 @@
71097139
memset(&token,0,sizeof(token));
71107140
token.z = zText;
71117141
pik_parser(&sParse, 0, token);
71127142
}
71137143
pik_parserFinalize(&sParse);
7144
+ if( s.zOut==0 && s.nErr==0 ){
7145
+ pik_append(&s, "<!-- empty pikchr diagram -->\n", -1);
7146
+ }
71147147
while( s.pVar ){
71157148
PVar *pNext = s.pVar->pNext;
71167149
free(s.pVar);
71177150
s.pVar = pNext;
71187151
}
@@ -7284,6 +7317,6 @@
72847317
}
72857318
return 0;
72867319
}
72877320
#endif /* PIKCHR_SHELL */
72887321
7289
-#line 7314 "pikchr.c"
7322
+#line 7347 "pikchr.c"
72907323
--- src/pikchr.c
+++ src/pikchr.c
@@ -370,11 +370,11 @@
370 const char *zName; /* Name of class */
371 char isLine; /* True if a line class */
372 char eJust; /* Use box-style text justification */
373 void (*xInit)(Pik*,PElem*); /* Initializer */
374 void (*xNumProp)(Pik*,PElem*,PToken*); /* Value change notification */
375 void (*xCheck)(Pik*,PElem*); /* Checks to after parsing */
376 PPoint (*xChop)(Pik*,PElem*,PPoint*); /* Chopper */
377 PPoint (*xOffset)(Pik*,PElem*,int); /* Offset from .c to edge point */
378 void (*xFit)(Pik*,PElem*,PNum w,PNum h); /* Size to fit text */
379 void (*xRender)(Pik*,PElem*); /* Render */
380 };
@@ -4424,11 +4424,11 @@
4424 }
4425
4426 /*
4427 ** Append text to zOut with HTML characters escaped.
4428 **
4429 ** * The space character is changed into non-breaking space (U+0080)
4430 ** if mFlags has the 0x01 bit set. This is needed when outputting
4431 ** text to preserve leading and trailing whitespace. Turns out we
4432 ** cannot use &nbsp; as that is an HTML-ism and is not valid in XML.
4433 **
4434 ** * The "&" character is changed into "&amp;" if mFlags has the
@@ -4790,12 +4790,17 @@
4790 pik_append_xy(p, " ", x, orig_y);
4791 pik_append(p,")\"",2);
4792 }
4793 }
4794 pik_append(p," dominant-baseline=\"central\">",-1);
4795 z = t->z+1;
4796 nz = t->n-2;
 
 
 
 
 
4797 while( nz>0 ){
4798 int j;
4799 for(j=0; j<nz && z[j]!='\\'; j++){}
4800 if( j ) pik_append_text(p, z, j, 1);
4801 nz -= j+1;
@@ -5915,11 +5920,11 @@
5915 /*
5916 ** Look up a color-name. Unlike other names in this program, the
5917 ** color-names are not case sensitive. So "DarkBlue" and "darkblue"
5918 ** and "DARKBLUE" all find the same value (139).
5919 **
5920 ** If not found, return -1.0. Also post an error if p!=NULL.
5921 **
5922 ** Special color names "None" and "Off" return -1.0 without causing
5923 ** an error.
5924 */
5925 static PNum pik_lookup_color(Pik *p, PToken *pId){
@@ -5947,11 +5952,11 @@
5947 }else{
5948 last = mid-1;
5949 }
5950 }
5951 if( p ) pik_error(p, pId, "not a known color name");
5952 return -1.0;
5953 }
5954
5955 /* Get the value of a variable.
5956 **
5957 ** Search in order:
@@ -5965,11 +5970,11 @@
5965 static PNum pik_get_var(Pik *p, PToken *pId){
5966 int miss = 0;
5967 PNum v = pik_value(p, pId->z, pId->n, &miss);
5968 if( miss==0 ) return v;
5969 v = pik_lookup_color(0, pId);
5970 if( v>=0.0 ) return v;
5971 pik_error(p,pId,"no such variable");
5972 return 0.0;
5973 }
5974
5975 /* Convert a T_NTH token (ex: "2nd", "5th"} into a numeric value and
@@ -6471,11 +6476,13 @@
6471 void pik_elist_render(Pik *p, PEList *pEList){
6472 int i;
6473 int iNextLayer = 0;
6474 int iThisLayer;
6475 int bMoreToDo;
 
6476 int mDebug = (int)pik_value(p, "debug", 5, 0);
 
6477 do{
6478 bMoreToDo = 0;
6479 iThisLayer = iNextLayer;
6480 iNextLayer = 0x7fffffff;
6481 for(i=0; i<pEList->n; i++){
@@ -6496,10 +6503,33 @@
6496 if( pElem->pSublist ){
6497 pik_elist_render(p, pElem->pSublist);
6498 }
6499 }
6500 }while( bMoreToDo );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6501 }
6502
6503 /* Add all elements of the list pEList to the bounding box
6504 */
6505 static void pik_bbox_add_elist(Pik *p, PEList *pEList, PNum wArrow){
@@ -7109,10 +7139,13 @@
7109 memset(&token,0,sizeof(token));
7110 token.z = zText;
7111 pik_parser(&sParse, 0, token);
7112 }
7113 pik_parserFinalize(&sParse);
 
 
 
7114 while( s.pVar ){
7115 PVar *pNext = s.pVar->pNext;
7116 free(s.pVar);
7117 s.pVar = pNext;
7118 }
@@ -7284,6 +7317,6 @@
7284 }
7285 return 0;
7286 }
7287 #endif /* PIKCHR_SHELL */
7288
7289 #line 7314 "pikchr.c"
7290
--- src/pikchr.c
+++ src/pikchr.c
@@ -370,11 +370,11 @@
370 const char *zName; /* Name of class */
371 char isLine; /* True if a line class */
372 char eJust; /* Use box-style text justification */
373 void (*xInit)(Pik*,PElem*); /* Initializer */
374 void (*xNumProp)(Pik*,PElem*,PToken*); /* Value change notification */
375 void (*xCheck)(Pik*,PElem*); /* Checks to do after parsing */
376 PPoint (*xChop)(Pik*,PElem*,PPoint*); /* Chopper */
377 PPoint (*xOffset)(Pik*,PElem*,int); /* Offset from .c to edge point */
378 void (*xFit)(Pik*,PElem*,PNum w,PNum h); /* Size to fit text */
379 void (*xRender)(Pik*,PElem*); /* Render */
380 };
@@ -4424,11 +4424,11 @@
4424 }
4425
4426 /*
4427 ** Append text to zOut with HTML characters escaped.
4428 **
4429 ** * The space character is changed into non-breaking space (U+00a0)
4430 ** if mFlags has the 0x01 bit set. This is needed when outputting
4431 ** text to preserve leading and trailing whitespace. Turns out we
4432 ** cannot use &nbsp; as that is an HTML-ism and is not valid in XML.
4433 **
4434 ** * The "&" character is changed into "&amp;" if mFlags has the
@@ -4790,12 +4790,17 @@
4790 pik_append_xy(p, " ", x, orig_y);
4791 pik_append(p,")\"",2);
4792 }
4793 }
4794 pik_append(p," dominant-baseline=\"central\">",-1);
4795 if( t->n>=2 && t->z[0]=='"' ){
4796 z = t->z+1;
4797 nz = t->n-2;
4798 }else{
4799 z = t->z;
4800 nz = t->n;
4801 }
4802 while( nz>0 ){
4803 int j;
4804 for(j=0; j<nz && z[j]!='\\'; j++){}
4805 if( j ) pik_append_text(p, z, j, 1);
4806 nz -= j+1;
@@ -5915,11 +5920,11 @@
5920 /*
5921 ** Look up a color-name. Unlike other names in this program, the
5922 ** color-names are not case sensitive. So "DarkBlue" and "darkblue"
5923 ** and "DARKBLUE" all find the same value (139).
5924 **
5925 ** If not found, return -99.0. Also post an error if p!=NULL.
5926 **
5927 ** Special color names "None" and "Off" return -1.0 without causing
5928 ** an error.
5929 */
5930 static PNum pik_lookup_color(Pik *p, PToken *pId){
@@ -5947,11 +5952,11 @@
5952 }else{
5953 last = mid-1;
5954 }
5955 }
5956 if( p ) pik_error(p, pId, "not a known color name");
5957 return -99.0;
5958 }
5959
5960 /* Get the value of a variable.
5961 **
5962 ** Search in order:
@@ -5965,11 +5970,11 @@
5970 static PNum pik_get_var(Pik *p, PToken *pId){
5971 int miss = 0;
5972 PNum v = pik_value(p, pId->z, pId->n, &miss);
5973 if( miss==0 ) return v;
5974 v = pik_lookup_color(0, pId);
5975 if( v>-90.0 ) return v;
5976 pik_error(p,pId,"no such variable");
5977 return 0.0;
5978 }
5979
5980 /* Convert a T_NTH token (ex: "2nd", "5th"} into a numeric value and
@@ -6471,11 +6476,13 @@
6476 void pik_elist_render(Pik *p, PEList *pEList){
6477 int i;
6478 int iNextLayer = 0;
6479 int iThisLayer;
6480 int bMoreToDo;
6481 int miss = 0;
6482 int mDebug = (int)pik_value(p, "debug", 5, 0);
6483 PNum colorLabel;
6484 do{
6485 bMoreToDo = 0;
6486 iThisLayer = iNextLayer;
6487 iNextLayer = 0x7fffffff;
6488 for(i=0; i<pEList->n; i++){
@@ -6496,10 +6503,33 @@
6503 if( pElem->pSublist ){
6504 pik_elist_render(p, pElem->pSublist);
6505 }
6506 }
6507 }while( bMoreToDo );
6508
6509 /* If the color_debug_label value is defined, then go through
6510 ** and paint a dot at every label location */
6511 colorLabel = pik_value(p, "debug_label_color", 17, &miss);
6512 if( miss==0 && colorLabel>=0.0 ){
6513 PElem dot;
6514 memset(&dot, 0, sizeof(dot));
6515 dot.type = &noopClass;
6516 dot.rad = 0.015;
6517 dot.sw = 0.015;
6518 dot.fill = colorLabel;
6519 dot.color = colorLabel;
6520 dot.nTxt = 1;
6521 dot.aTxt[0].eCode = TP_ABOVE;
6522 for(i=0; i<pEList->n; i++){
6523 PElem *pElem = pEList->a[i];
6524 if( pElem->zName==0 ) continue;
6525 dot.ptAt = pElem->ptAt;
6526 dot.aTxt[0].z = pElem->zName;
6527 dot.aTxt[0].n = (int)strlen(pElem->zName);
6528 dotRender(p, &dot);
6529 }
6530 }
6531 }
6532
6533 /* Add all elements of the list pEList to the bounding box
6534 */
6535 static void pik_bbox_add_elist(Pik *p, PEList *pEList, PNum wArrow){
@@ -7109,10 +7139,13 @@
7139 memset(&token,0,sizeof(token));
7140 token.z = zText;
7141 pik_parser(&sParse, 0, token);
7142 }
7143 pik_parserFinalize(&sParse);
7144 if( s.zOut==0 && s.nErr==0 ){
7145 pik_append(&s, "<!-- empty pikchr diagram -->\n", -1);
7146 }
7147 while( s.pVar ){
7148 PVar *pNext = s.pVar->pNext;
7149 free(s.pVar);
7150 s.pVar = pNext;
7151 }
@@ -7284,6 +7317,6 @@
7317 }
7318 return 0;
7319 }
7320 #endif /* PIKCHR_SHELL */
7321
7322 #line 7347 "pikchr.c"
7323

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button