Tk Source Code

Check-in [ebc9fe82]
Login
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2019 Conference, Houston/TX, US, Nov 4-8
Send your abstracts to [email protected]
or submit via the online form by Sep 9.

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fix code style a bit, and comments
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | tip-545-svg-options
Files: files | file ages | folders
SHA3-256: ebc9fe82f9f6cc88b33c91170950d07c64a437ddcbe81b7565caabdeb93eb518
User & Date: fvogel 2019-06-10 12:22:23
Context
2019-06-12
22:23
Remove wrong forcing of image size to 1x1 when it was read from the data or disk to be 0x0 (which indicates the image could not be parsed in that format). Handling for images 0x0 in size must be kept because Tk bases its error detection for the format on this feature. check-in: c111a3ea user: fvogel tags: tip-545-svg-options
2019-06-10
12:22
Fix code style a bit, and comments check-in: ebc9fe82 user: fvogel tags: tip-545-svg-options
12:10
Update documentation to reflect content of TIP #545 check-in: 2057f970 user: fvogel tags: tip-545-svg-options
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to generic/tkImgSVGnano.c.

258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
...
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
...
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
...
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
     * Width and Height equal zero is an svgnano error case and must be errored
     * out. Valid png images give width and height 0 as result
     */
    if ((nsvgImage->width <= 0.0) || (nsvgImage->height <= 0.0)) {
	nsvgDelete(nsvgImage);
	return 0;
    }
    GetScaleFromParameters(
	    nsvgImage,
	    &ropts,
	    widthPtr,
	    heightPtr);
    if (!CacheSVG(interp, dataObj, formatObj, nsvgImage, &ropts)) {
	nsvgDelete(nsvgImage);
    }
    return 1;
}

/*
................................................................................
{
    int w, h, c;
    NSVGrasterizer *rast;
    unsigned char *imgData;
    Tk_PhotoImageBlock svgblock;
    double scale;

    scale = GetScaleFromParameters(
	    nsvgImage,
	    ropts,
	    &w,
	    &h);

    rast = nsvgCreateRasterizer();
    if (rast == NULL) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj("cannot initialize rasterizer", -1));
	Tcl_SetErrorCode(interp, "TK", "IMAGE", "SVG", "RASTERIZER_ERROR",
		NULL);
	goto cleanAST;
................................................................................
 *
 * GetScaleFromParameters --
 *
 *	Get the scale value from the already parsed parameters -scale,
 *	-scaletoheight and -scaletowidth.
 *
 *	The image width and height is also returned.
 *	Both are greater or equal to 1.
 *
 * Results:
 *	The evaluated or configured scale value or 0.0 on failure
 *
 * Side effects:
 *	height and width is set to heightPtr and widthPtr.
 *
 *----------------------------------------------------------------------
 */

static double
GetScaleFromParameters(
    NSVGimage *nsvgImage,
................................................................................
    int width, height;
    /*
     * nsvgImage->width  and nsvgImage->height are greater than 0.
     * Equal to 0 is an svgnano error case.
     */
    if (ropts->scaleToHeight > 0) {
	/*
	 * Fix height
	 */
	height = ropts->scaleToHeight;
	scale = height / nsvgImage->height;
	width = (int) ceil(nsvgImage->width * scale);
    } else if (ropts->scaleToWidth > 0) {
	/*
	 * Fix width
	 */
	width = ropts->scaleToWidth;
	scale = width / nsvgImage->width;
	height = (int) ceil(nsvgImage->height * scale);
    } else {
	/*
	 * Scale factor






|
<
<
<
<







 







|
<
<
<
<







 







|


|


|







 







|






|







258
259
260
261
262
263
264
265




266
267
268
269
270
271
272
...
523
524
525
526
527
528
529
530




531
532
533
534
535
536
537
...
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
...
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
     * Width and Height equal zero is an svgnano error case and must be errored
     * out. Valid png images give width and height 0 as result
     */
    if ((nsvgImage->width <= 0.0) || (nsvgImage->height <= 0.0)) {
	nsvgDelete(nsvgImage);
	return 0;
    }
    GetScaleFromParameters(nsvgImage, &ropts, widthPtr, heightPtr);




    if (!CacheSVG(interp, dataObj, formatObj, nsvgImage, &ropts)) {
	nsvgDelete(nsvgImage);
    }
    return 1;
}

/*
................................................................................
{
    int w, h, c;
    NSVGrasterizer *rast;
    unsigned char *imgData;
    Tk_PhotoImageBlock svgblock;
    double scale;

    scale = GetScaleFromParameters(nsvgImage, ropts, &w, &h);





    rast = nsvgCreateRasterizer();
    if (rast == NULL) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj("cannot initialize rasterizer", -1));
	Tcl_SetErrorCode(interp, "TK", "IMAGE", "SVG", "RASTERIZER_ERROR",
		NULL);
	goto cleanAST;
................................................................................
 *
 * GetScaleFromParameters --
 *
 *	Get the scale value from the already parsed parameters -scale,
 *	-scaletoheight and -scaletowidth.
 *
 *	The image width and height is also returned.
 *	Both are greater than or equal to 1.
 *
 * Results:
 *	The evaluated or configured scale value, or 0.0 on failure
 *
 * Side effects:
 *	heightPtr and widthPtr are set to height and width of the image.
 *
 *----------------------------------------------------------------------
 */

static double
GetScaleFromParameters(
    NSVGimage *nsvgImage,
................................................................................
    int width, height;
    /*
     * nsvgImage->width  and nsvgImage->height are greater than 0.
     * Equal to 0 is an svgnano error case.
     */
    if (ropts->scaleToHeight > 0) {
	/*
	 * Fixed height
	 */
	height = ropts->scaleToHeight;
	scale = height / nsvgImage->height;
	width = (int) ceil(nsvgImage->width * scale);
    } else if (ropts->scaleToWidth > 0) {
	/*
	 * Fixed width
	 */
	width = ropts->scaleToWidth;
	scale = width / nsvgImage->width;
	height = (int) ceil(nsvgImage->height * scale);
    } else {
	/*
	 * Scale factor