Fossil SCM
Update the built-in pikchr.c to include the latest enhancements and fixes.
Commit
1347e990ac744d7d5539524787ff1819c9882173e0f147695560302360df348d
Parent
1165ed88f3f60f1…
1 file changed
+41
-8
+41
-8
| --- src/pikchr.c | ||
| +++ src/pikchr.c | ||
| @@ -370,11 +370,11 @@ | ||
| 370 | 370 | const char *zName; /* Name of class */ |
| 371 | 371 | char isLine; /* True if a line class */ |
| 372 | 372 | char eJust; /* Use box-style text justification */ |
| 373 | 373 | void (*xInit)(Pik*,PElem*); /* Initializer */ |
| 374 | 374 | 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 */ | |
| 376 | 376 | PPoint (*xChop)(Pik*,PElem*,PPoint*); /* Chopper */ |
| 377 | 377 | PPoint (*xOffset)(Pik*,PElem*,int); /* Offset from .c to edge point */ |
| 378 | 378 | void (*xFit)(Pik*,PElem*,PNum w,PNum h); /* Size to fit text */ |
| 379 | 379 | void (*xRender)(Pik*,PElem*); /* Render */ |
| 380 | 380 | }; |
| @@ -4424,11 +4424,11 @@ | ||
| 4424 | 4424 | } |
| 4425 | 4425 | |
| 4426 | 4426 | /* |
| 4427 | 4427 | ** Append text to zOut with HTML characters escaped. |
| 4428 | 4428 | ** |
| 4429 | -** * The space character is changed into non-breaking space (U+0080) | |
| 4429 | +** * The space character is changed into non-breaking space (U+00a0) | |
| 4430 | 4430 | ** if mFlags has the 0x01 bit set. This is needed when outputting |
| 4431 | 4431 | ** text to preserve leading and trailing whitespace. Turns out we |
| 4432 | 4432 | ** cannot use as that is an HTML-ism and is not valid in XML. |
| 4433 | 4433 | ** |
| 4434 | 4434 | ** * The "&" character is changed into "&" if mFlags has the |
| @@ -4790,12 +4790,17 @@ | ||
| 4790 | 4790 | pik_append_xy(p, " ", x, orig_y); |
| 4791 | 4791 | pik_append(p,")\"",2); |
| 4792 | 4792 | } |
| 4793 | 4793 | } |
| 4794 | 4794 | 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 | + } | |
| 4797 | 4802 | while( nz>0 ){ |
| 4798 | 4803 | int j; |
| 4799 | 4804 | for(j=0; j<nz && z[j]!='\\'; j++){} |
| 4800 | 4805 | if( j ) pik_append_text(p, z, j, 1); |
| 4801 | 4806 | nz -= j+1; |
| @@ -5915,11 +5920,11 @@ | ||
| 5915 | 5920 | /* |
| 5916 | 5921 | ** Look up a color-name. Unlike other names in this program, the |
| 5917 | 5922 | ** color-names are not case sensitive. So "DarkBlue" and "darkblue" |
| 5918 | 5923 | ** and "DARKBLUE" all find the same value (139). |
| 5919 | 5924 | ** |
| 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. | |
| 5921 | 5926 | ** |
| 5922 | 5927 | ** Special color names "None" and "Off" return -1.0 without causing |
| 5923 | 5928 | ** an error. |
| 5924 | 5929 | */ |
| 5925 | 5930 | static PNum pik_lookup_color(Pik *p, PToken *pId){ |
| @@ -5947,11 +5952,11 @@ | ||
| 5947 | 5952 | }else{ |
| 5948 | 5953 | last = mid-1; |
| 5949 | 5954 | } |
| 5950 | 5955 | } |
| 5951 | 5956 | if( p ) pik_error(p, pId, "not a known color name"); |
| 5952 | - return -1.0; | |
| 5957 | + return -99.0; | |
| 5953 | 5958 | } |
| 5954 | 5959 | |
| 5955 | 5960 | /* Get the value of a variable. |
| 5956 | 5961 | ** |
| 5957 | 5962 | ** Search in order: |
| @@ -5965,11 +5970,11 @@ | ||
| 5965 | 5970 | static PNum pik_get_var(Pik *p, PToken *pId){ |
| 5966 | 5971 | int miss = 0; |
| 5967 | 5972 | PNum v = pik_value(p, pId->z, pId->n, &miss); |
| 5968 | 5973 | if( miss==0 ) return v; |
| 5969 | 5974 | v = pik_lookup_color(0, pId); |
| 5970 | - if( v>=0.0 ) return v; | |
| 5975 | + if( v>-90.0 ) return v; | |
| 5971 | 5976 | pik_error(p,pId,"no such variable"); |
| 5972 | 5977 | return 0.0; |
| 5973 | 5978 | } |
| 5974 | 5979 | |
| 5975 | 5980 | /* Convert a T_NTH token (ex: "2nd", "5th"} into a numeric value and |
| @@ -6471,11 +6476,13 @@ | ||
| 6471 | 6476 | void pik_elist_render(Pik *p, PEList *pEList){ |
| 6472 | 6477 | int i; |
| 6473 | 6478 | int iNextLayer = 0; |
| 6474 | 6479 | int iThisLayer; |
| 6475 | 6480 | int bMoreToDo; |
| 6481 | + int miss = 0; | |
| 6476 | 6482 | int mDebug = (int)pik_value(p, "debug", 5, 0); |
| 6483 | + PNum colorLabel; | |
| 6477 | 6484 | do{ |
| 6478 | 6485 | bMoreToDo = 0; |
| 6479 | 6486 | iThisLayer = iNextLayer; |
| 6480 | 6487 | iNextLayer = 0x7fffffff; |
| 6481 | 6488 | for(i=0; i<pEList->n; i++){ |
| @@ -6496,10 +6503,33 @@ | ||
| 6496 | 6503 | if( pElem->pSublist ){ |
| 6497 | 6504 | pik_elist_render(p, pElem->pSublist); |
| 6498 | 6505 | } |
| 6499 | 6506 | } |
| 6500 | 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 | + } | |
| 6501 | 6531 | } |
| 6502 | 6532 | |
| 6503 | 6533 | /* Add all elements of the list pEList to the bounding box |
| 6504 | 6534 | */ |
| 6505 | 6535 | static void pik_bbox_add_elist(Pik *p, PEList *pEList, PNum wArrow){ |
| @@ -7109,10 +7139,13 @@ | ||
| 7109 | 7139 | memset(&token,0,sizeof(token)); |
| 7110 | 7140 | token.z = zText; |
| 7111 | 7141 | pik_parser(&sParse, 0, token); |
| 7112 | 7142 | } |
| 7113 | 7143 | pik_parserFinalize(&sParse); |
| 7144 | + if( s.zOut==0 && s.nErr==0 ){ | |
| 7145 | + pik_append(&s, "<!-- empty pikchr diagram -->\n", -1); | |
| 7146 | + } | |
| 7114 | 7147 | while( s.pVar ){ |
| 7115 | 7148 | PVar *pNext = s.pVar->pNext; |
| 7116 | 7149 | free(s.pVar); |
| 7117 | 7150 | s.pVar = pNext; |
| 7118 | 7151 | } |
| @@ -7284,6 +7317,6 @@ | ||
| 7284 | 7317 | } |
| 7285 | 7318 | return 0; |
| 7286 | 7319 | } |
| 7287 | 7320 | #endif /* PIKCHR_SHELL */ |
| 7288 | 7321 | |
| 7289 | -#line 7314 "pikchr.c" | |
| 7322 | +#line 7347 "pikchr.c" | |
| 7290 | 7323 |
| --- 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 as that is an HTML-ism and is not valid in XML. |
| 4433 | ** |
| 4434 | ** * The "&" character is changed into "&" 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 as that is an HTML-ism and is not valid in XML. |
| 4433 | ** |
| 4434 | ** * The "&" character is changed into "&" 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 |