Fossil SCM

Pikchr-generated SVG uses "viewbox" instead of "width" and "height" in an effort to be more mobile-friendly.

drh 2020-09-11 17:43 trunk
Commit 2defbdb3f47ba339ed8905c51741a24953ed8029cca784c0e5975fb253b6225f
--- src/markdown_html.c
+++ src/markdown_html.c
@@ -339,35 +339,39 @@
339339
char *zIn = fossil_strndup(zSrc, nSrc);
340340
char *zOut = pikchr(zIn, "pikchr", 0, &w, &h);
341341
fossil_free(zIn);
342342
if( w>0 && h>0 ){
343343
const char *zNonce = safe_html_nonce(1);
344
- char *zCss = 0;
344
+ Blob css;
345
+ blob_init(&css,0,0);
346
+ blob_appendf(&css,"max-width:%dpx;",w);
345347
blob_append(ob, zNonce, -1);
346348
blob_append_char(ob, '\n');
347
- while( nArg>0 && zCss==0 ){
349
+ while( nArg>0 ){
348350
int i;
349351
for(i=0; i<nArg && !fossil_isspace(zArg[i]); i++){}
350352
if( i==6 && strncmp(zArg, "center", 6)==0 ){
351
- zCss = mprintf("display:block;margin:auto;width:%dpx;", w);
353
+ blob_appendf(&css, "display:block;margin:auto;");
354
+ break;
352355
}else if( i==6 && strncmp(zArg, "indent", 6)==0 ){
353
- zCss = fossil_strdup("margin-left:4em;");
356
+ blob_appendf(&css, "margin-left:4em;");
357
+ break;
354358
}else if( i==10 && strncmp(zArg, "float-left", 10)==0 ){
355
- zCss = mprintf("float:left;width:%d;padding=4em;",w);
359
+ blob_appendf(&css, "float:left;padding=4em;");
360
+ break;
356361
}else if( i==11 && strncmp(zArg, "float-right", 11)==0 ){
357
- zCss = mprintf("float:right;width:%d;padding=4em;",w);
362
+ blob_appendf(&css, "float:right;padding=4em;");
363
+ break;
358364
}
359365
while( i<nArg && fossil_isspace(zArg[i]) ){ i++; }
360366
zArg += i;
361367
nArg -= i;
362368
}
363
- if( zCss ) blob_appendf(ob, "<div style='%s'>\n", zCss);
369
+ blob_appendf(ob, "<div style='%s'>\n", blob_str(&css));
364370
blob_append(ob, zOut, -1);
365
- if( zCss ){
366
- blob_appendf(ob, "</div>\n");
367
- fossil_free(zCss);
368
- }
371
+ blob_appendf(ob, "</div>\n");
372
+ blob_reset(&css);
369373
blob_appendf(ob, "%s\n", zNonce);
370374
}else{
371375
blob_appendf(ob, "<pre>\n%s\n</pre>\n", zOut);
372376
}
373377
free(zOut);
374378
--- src/markdown_html.c
+++ src/markdown_html.c
@@ -339,35 +339,39 @@
339 char *zIn = fossil_strndup(zSrc, nSrc);
340 char *zOut = pikchr(zIn, "pikchr", 0, &w, &h);
341 fossil_free(zIn);
342 if( w>0 && h>0 ){
343 const char *zNonce = safe_html_nonce(1);
344 char *zCss = 0;
 
 
345 blob_append(ob, zNonce, -1);
346 blob_append_char(ob, '\n');
347 while( nArg>0 && zCss==0 ){
348 int i;
349 for(i=0; i<nArg && !fossil_isspace(zArg[i]); i++){}
350 if( i==6 && strncmp(zArg, "center", 6)==0 ){
351 zCss = mprintf("display:block;margin:auto;width:%dpx;", w);
 
352 }else if( i==6 && strncmp(zArg, "indent", 6)==0 ){
353 zCss = fossil_strdup("margin-left:4em;");
 
354 }else if( i==10 && strncmp(zArg, "float-left", 10)==0 ){
355 zCss = mprintf("float:left;width:%d;padding=4em;",w);
 
356 }else if( i==11 && strncmp(zArg, "float-right", 11)==0 ){
357 zCss = mprintf("float:right;width:%d;padding=4em;",w);
 
358 }
359 while( i<nArg && fossil_isspace(zArg[i]) ){ i++; }
360 zArg += i;
361 nArg -= i;
362 }
363 if( zCss ) blob_appendf(ob, "<div style='%s'>\n", zCss);
364 blob_append(ob, zOut, -1);
365 if( zCss ){
366 blob_appendf(ob, "</div>\n");
367 fossil_free(zCss);
368 }
369 blob_appendf(ob, "%s\n", zNonce);
370 }else{
371 blob_appendf(ob, "<pre>\n%s\n</pre>\n", zOut);
372 }
373 free(zOut);
374
--- src/markdown_html.c
+++ src/markdown_html.c
@@ -339,35 +339,39 @@
339 char *zIn = fossil_strndup(zSrc, nSrc);
340 char *zOut = pikchr(zIn, "pikchr", 0, &w, &h);
341 fossil_free(zIn);
342 if( w>0 && h>0 ){
343 const char *zNonce = safe_html_nonce(1);
344 Blob css;
345 blob_init(&css,0,0);
346 blob_appendf(&css,"max-width:%dpx;",w);
347 blob_append(ob, zNonce, -1);
348 blob_append_char(ob, '\n');
349 while( nArg>0 ){
350 int i;
351 for(i=0; i<nArg && !fossil_isspace(zArg[i]); i++){}
352 if( i==6 && strncmp(zArg, "center", 6)==0 ){
353 blob_appendf(&css, "display:block;margin:auto;");
354 break;
355 }else if( i==6 && strncmp(zArg, "indent", 6)==0 ){
356 blob_appendf(&css, "margin-left:4em;");
357 break;
358 }else if( i==10 && strncmp(zArg, "float-left", 10)==0 ){
359 blob_appendf(&css, "float:left;padding=4em;");
360 break;
361 }else if( i==11 && strncmp(zArg, "float-right", 11)==0 ){
362 blob_appendf(&css, "float:right;padding=4em;");
363 break;
364 }
365 while( i<nArg && fossil_isspace(zArg[i]) ){ i++; }
366 zArg += i;
367 nArg -= i;
368 }
369 blob_appendf(ob, "<div style='%s'>\n", blob_str(&css));
370 blob_append(ob, zOut, -1);
371 blob_appendf(ob, "</div>\n");
372 blob_reset(&css);
 
 
373 blob_appendf(ob, "%s\n", zNonce);
374 }else{
375 blob_appendf(ob, "<pre>\n%s\n</pre>\n", zOut);
376 }
377 free(zOut);
378
+5 -4
--- src/pikchr.c
+++ src/pikchr.c
@@ -5904,12 +5904,12 @@
59045904
}
59055905
w = p->bbox.ne.x - p->bbox.sw.x;
59065906
h = p->bbox.ne.y - p->bbox.sw.y;
59075907
p->wSVG = (int)(p->rScale*w);
59085908
p->hSVG = (int)(p->rScale*h);
5909
- pik_append_dis(p, " width=\"", w, "\"");
5910
- pik_append_dis(p, " height=\"",h,"\">\n");
5909
+ pik_append_dis(p, " viewBox=\"0 0 ",w,"");
5910
+ pik_append_dis(p, " ",h,"\">\n");
59115911
pik_elist_render(p, pEList);
59125912
pik_append(p,"</svg>\n", -1);
59135913
}else{
59145914
p->wSVG = -1;
59155915
p->hSVG = -1;
@@ -6475,15 +6475,16 @@
64756475
if( w<0 ){
64766476
printf("<p>ERROR:</p>\n");
64776477
}else{
64786478
printf("<p>Output size: %d by %d</p>\n", w, h);
64796479
}
6480
- printf("<div style='border:2px solid gray;'>\n%s</div>\n", zOut);
6480
+ printf("<div style='border:2px solid gray;max-width:%dpx'>\n%s</div>\n",
6481
+ w, zOut);
64816482
free(zOut);
64826483
}
64836484
}
64846485
printf("</body></html>\n");
64856486
return 0;
64866487
}
64876488
#endif /* PIKCHR_SHELL */
64886489
6489
-#line 6514 "pikchr.c"
6490
+#line 6515 "pikchr.c"
64906491
--- src/pikchr.c
+++ src/pikchr.c
@@ -5904,12 +5904,12 @@
5904 }
5905 w = p->bbox.ne.x - p->bbox.sw.x;
5906 h = p->bbox.ne.y - p->bbox.sw.y;
5907 p->wSVG = (int)(p->rScale*w);
5908 p->hSVG = (int)(p->rScale*h);
5909 pik_append_dis(p, " width=\"", w, "\"");
5910 pik_append_dis(p, " height=\"",h,"\">\n");
5911 pik_elist_render(p, pEList);
5912 pik_append(p,"</svg>\n", -1);
5913 }else{
5914 p->wSVG = -1;
5915 p->hSVG = -1;
@@ -6475,15 +6475,16 @@
6475 if( w<0 ){
6476 printf("<p>ERROR:</p>\n");
6477 }else{
6478 printf("<p>Output size: %d by %d</p>\n", w, h);
6479 }
6480 printf("<div style='border:2px solid gray;'>\n%s</div>\n", zOut);
 
6481 free(zOut);
6482 }
6483 }
6484 printf("</body></html>\n");
6485 return 0;
6486 }
6487 #endif /* PIKCHR_SHELL */
6488
6489 #line 6514 "pikchr.c"
6490
--- src/pikchr.c
+++ src/pikchr.c
@@ -5904,12 +5904,12 @@
5904 }
5905 w = p->bbox.ne.x - p->bbox.sw.x;
5906 h = p->bbox.ne.y - p->bbox.sw.y;
5907 p->wSVG = (int)(p->rScale*w);
5908 p->hSVG = (int)(p->rScale*h);
5909 pik_append_dis(p, " viewBox=\"0 0 ",w,"");
5910 pik_append_dis(p, " ",h,"\">\n");
5911 pik_elist_render(p, pEList);
5912 pik_append(p,"</svg>\n", -1);
5913 }else{
5914 p->wSVG = -1;
5915 p->hSVG = -1;
@@ -6475,15 +6475,16 @@
6475 if( w<0 ){
6476 printf("<p>ERROR:</p>\n");
6477 }else{
6478 printf("<p>Output size: %d by %d</p>\n", w, h);
6479 }
6480 printf("<div style='border:2px solid gray;max-width:%dpx'>\n%s</div>\n",
6481 w, zOut);
6482 free(zOut);
6483 }
6484 }
6485 printf("</body></html>\n");
6486 return 0;
6487 }
6488 #endif /* PIKCHR_SHELL */
6489
6490 #line 6515 "pikchr.c"
6491
--- src/pikchrshow.c
+++ src/pikchrshow.c
@@ -27,11 +27,11 @@
2727
** WEBPAGE: pikchrshow
2828
**
2929
** A basic pikchr code editor and renderer, allowing users with write-
3030
** or wiki-write permissions to experiment with pikchr code.
3131
*/
32
-void pikchrshow_cmd(void){
32
+void pikchrshow_page(void){
3333
const char *zContent = 0;
3434
int isDark, flipColors;
3535
3636
login_check_credentials();
3737
if( !g.perm.RdWiki && !g.perm.Read && !g.perm.RdForum ){
@@ -44,11 +44,12 @@
4444
if(zContent && *zContent){
4545
int w = 0, h = 0;
4646
char *zOut = pikchr(zContent, "pikchr", 0, &w, &h);
4747
if( w>0 && h>0 ){
4848
const char *zNonce = safe_html_nonce(1);
49
- CX("%s\n%s%s", zNonce, zOut, zNonce);
49
+ CX("%s<div style='max-width:%dpx;'>\n%s</div>%s",
50
+ zNonce, w, zOut, zNonce);
5051
}else{
5152
cgi_printf_header("x-pikchrshow-is-error: 1\r\n");
5253
CX("<pre>\n%s\n</pre>\n", zOut);
5354
}
5455
fossil_free(zOut);
@@ -127,11 +128,12 @@
127128
if(*zContent){
128129
int w = 0, h = 0;
129130
char *zOut = pikchr(zContent, "pikchr", 0, &w, &h);
130131
if( w>0 && h>0 ){
131132
const char *zNonce = safe_html_nonce(1);
132
- CX("%s\n%s%s", zNonce, zOut, zNonce);
133
+ CX("%s<div style='max-width:%dpx;'>\n%s</div>%s",
134
+ zNonce, w, zOut, zNonce);
133135
}else{
134136
CX("<pre>\n%s\n</pre>\n", zOut);
135137
}
136138
fossil_free(zOut);
137139
}
@@ -143,6 +145,5 @@
143145
}
144146
builtin_emit_fossil_js_apis("page.pikchrshow", 0);
145147
builtin_fulfill_js_requests();
146148
style_footer();
147149
}
148
-
149150
--- src/pikchrshow.c
+++ src/pikchrshow.c
@@ -27,11 +27,11 @@
27 ** WEBPAGE: pikchrshow
28 **
29 ** A basic pikchr code editor and renderer, allowing users with write-
30 ** or wiki-write permissions to experiment with pikchr code.
31 */
32 void pikchrshow_cmd(void){
33 const char *zContent = 0;
34 int isDark, flipColors;
35
36 login_check_credentials();
37 if( !g.perm.RdWiki && !g.perm.Read && !g.perm.RdForum ){
@@ -44,11 +44,12 @@
44 if(zContent && *zContent){
45 int w = 0, h = 0;
46 char *zOut = pikchr(zContent, "pikchr", 0, &w, &h);
47 if( w>0 && h>0 ){
48 const char *zNonce = safe_html_nonce(1);
49 CX("%s\n%s%s", zNonce, zOut, zNonce);
 
50 }else{
51 cgi_printf_header("x-pikchrshow-is-error: 1\r\n");
52 CX("<pre>\n%s\n</pre>\n", zOut);
53 }
54 fossil_free(zOut);
@@ -127,11 +128,12 @@
127 if(*zContent){
128 int w = 0, h = 0;
129 char *zOut = pikchr(zContent, "pikchr", 0, &w, &h);
130 if( w>0 && h>0 ){
131 const char *zNonce = safe_html_nonce(1);
132 CX("%s\n%s%s", zNonce, zOut, zNonce);
 
133 }else{
134 CX("<pre>\n%s\n</pre>\n", zOut);
135 }
136 fossil_free(zOut);
137 }
@@ -143,6 +145,5 @@
143 }
144 builtin_emit_fossil_js_apis("page.pikchrshow", 0);
145 builtin_fulfill_js_requests();
146 style_footer();
147 }
148
149
--- src/pikchrshow.c
+++ src/pikchrshow.c
@@ -27,11 +27,11 @@
27 ** WEBPAGE: pikchrshow
28 **
29 ** A basic pikchr code editor and renderer, allowing users with write-
30 ** or wiki-write permissions to experiment with pikchr code.
31 */
32 void pikchrshow_page(void){
33 const char *zContent = 0;
34 int isDark, flipColors;
35
36 login_check_credentials();
37 if( !g.perm.RdWiki && !g.perm.Read && !g.perm.RdForum ){
@@ -44,11 +44,12 @@
44 if(zContent && *zContent){
45 int w = 0, h = 0;
46 char *zOut = pikchr(zContent, "pikchr", 0, &w, &h);
47 if( w>0 && h>0 ){
48 const char *zNonce = safe_html_nonce(1);
49 CX("%s<div style='max-width:%dpx;'>\n%s</div>%s",
50 zNonce, w, zOut, zNonce);
51 }else{
52 cgi_printf_header("x-pikchrshow-is-error: 1\r\n");
53 CX("<pre>\n%s\n</pre>\n", zOut);
54 }
55 fossil_free(zOut);
@@ -127,11 +128,12 @@
128 if(*zContent){
129 int w = 0, h = 0;
130 char *zOut = pikchr(zContent, "pikchr", 0, &w, &h);
131 if( w>0 && h>0 ){
132 const char *zNonce = safe_html_nonce(1);
133 CX("%s<div style='max-width:%dpx;'>\n%s</div>%s",
134 zNonce, w, zOut, zNonce);
135 }else{
136 CX("<pre>\n%s\n</pre>\n", zOut);
137 }
138 fossil_free(zOut);
139 }
@@ -143,6 +145,5 @@
145 }
146 builtin_emit_fossil_js_apis("page.pikchrshow", 0);
147 builtin_fulfill_js_requests();
148 style_footer();
149 }
 
150

Keyboard Shortcuts

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