467
if (strcmp (*names, "x") == 0)
469
parse_svg_length (*values,
470
handler->width, parser->image->xresolution, &x);
472
else if (strcmp (*names, "y") == 0)
474
parse_svg_length (*values,
475
handler->height, parser->image->yresolution, &y);
477
else if (strcmp (*names, "width") == 0)
479
parse_svg_length (*values,
480
handler->width, parser->image->xresolution, &w);
482
else if (strcmp (*names, "height") == 0)
484
parse_svg_length (*values,
485
handler->height, parser->image->yresolution, &h);
487
else if (strcmp (*names, "viewBox") == 0)
479
if (strcmp (*names, "x") == 0)
480
parse_svg_length (*values,
481
handler->width, parser->image->xresolution, &x);
485
if (strcmp (*names, "y") == 0)
486
parse_svg_length (*values,
487
handler->height, parser->image->yresolution, &y);
491
if (strcmp (*names, "width") == 0)
492
parse_svg_length (*values,
493
handler->width, parser->image->xresolution, &w);
497
if (strcmp (*names, "height") == 0)
498
parse_svg_length (*values,
499
handler->height, parser->image->yresolution, &h);
503
if (strcmp (*names, "viewBox") == 0)
579
if (strcmp (*names, "id") == 0 && !path->id)
581
path->id = g_strdup (*values);
583
else if (strcmp (*names, "d") == 0 && !path->strokes)
585
path->strokes = parse_path_data (*values);
587
else if (strcmp (*names, "transform") == 0 && !handler->transform)
591
if (parse_svg_transform (*values, &matrix))
592
handler->transform = g_memdup (&matrix, sizeof (GimpMatrix3));
598
if (strcmp (*names, "id") == 0 && !path->id)
599
path->id = g_strdup (*values);
603
if (strcmp (*names, "d") == 0 && !path->strokes)
604
path->strokes = parse_path_data (*values);
608
if (strcmp (*names, "transform") == 0 && !handler->transform)
612
if (parse_svg_transform (*values, &matrix))
613
handler->transform = g_memdup (&matrix, sizeof (GimpMatrix3));
618
if (strcmp (*names, "id") == 0 && !path->id)
620
path->id = g_strdup (*values);
622
else if (strcmp (*names, "x") == 0)
624
parse_svg_length (*values,
625
handler->width, parser->image->xresolution,
628
else if (strcmp (*names, "y") == 0)
630
parse_svg_length (*values,
631
handler->height, parser->image->yresolution,
634
else if (strcmp (*names, "width") == 0)
636
parse_svg_length (*values,
637
handler->width, parser->image->xresolution,
640
else if (strcmp (*names, "height") == 0)
642
parse_svg_length (*values,
643
handler->height, parser->image->yresolution,
646
else if (strcmp (*names, "rx") == 0)
648
parse_svg_length (*values,
649
handler->width, parser->image->xresolution,
652
else if (strcmp (*names, "ry") == 0)
654
parse_svg_length (*values,
655
handler->height, parser->image->yresolution,
658
else if (strcmp (*names, "transform") == 0 && !handler->transform)
662
if (parse_svg_transform (*values, &matrix))
663
handler->transform = g_memdup (&matrix, sizeof (GimpMatrix3));
644
if (strcmp (*names, "id") == 0 && !path->id)
645
path->id = g_strdup (*values);
649
if (strcmp (*names, "x") == 0)
650
parse_svg_length (*values,
651
handler->width, parser->image->xresolution,
656
if (strcmp (*names, "y") == 0)
657
parse_svg_length (*values,
658
handler->height, parser->image->yresolution,
663
if (strcmp (*names, "width") == 0)
664
parse_svg_length (*values,
665
handler->width, parser->image->xresolution,
670
if (strcmp (*names, "height") == 0)
671
parse_svg_length (*values,
672
handler->height, parser->image->yresolution,
677
if (strcmp (*names, "rx") == 0)
678
parse_svg_length (*values,
679
handler->width, parser->image->xresolution,
681
else if (strcmp (*names, "ry") == 0)
682
parse_svg_length (*values,
683
handler->height, parser->image->yresolution,
688
if (strcmp (*names, "transform") == 0 && !handler->transform)
692
if (parse_svg_transform (*values, &matrix))
693
handler->transform = g_memdup (&matrix, sizeof (GimpMatrix3));
761
if (strcmp (*names, "id") == 0 && !path->id)
763
path->id = g_strdup (*values);
765
else if (strcmp (*names, "cx") == 0)
767
parse_svg_length (*values,
768
handler->width, parser->image->xresolution,
771
else if (strcmp (*names, "cy") == 0)
773
parse_svg_length (*values,
774
handler->height, parser->image->yresolution,
777
else if (strcmp (*names, "r") == 0)
779
parse_svg_length (*values,
780
handler->width, parser->image->xresolution,
782
parse_svg_length (*values,
783
handler->height, parser->image->yresolution,
786
else if (strcmp (*names, "rx") == 0)
788
parse_svg_length (*values,
789
handler->width, parser->image->xresolution,
792
else if (strcmp (*names, "ry") == 0)
794
parse_svg_length (*values,
795
handler->height, parser->image->yresolution,
798
else if (strcmp (*names, "transform") == 0 && !handler->transform)
802
if (parse_svg_transform (*values, &matrix))
803
handler->transform = g_memdup (&matrix, sizeof (GimpMatrix3));
796
if (strcmp (*names, "id") == 0 && !path->id)
797
path->id = g_strdup (*values);
801
if (strcmp (*names, "cx") == 0)
802
parse_svg_length (*values,
803
handler->width, parser->image->xresolution,
805
else if (strcmp (*names, "cy") == 0)
806
parse_svg_length (*values,
807
handler->height, parser->image->yresolution,
812
if (strcmp (*names, "r") == 0)
814
parse_svg_length (*values,
815
handler->width, parser->image->xresolution,
817
parse_svg_length (*values,
818
handler->height, parser->image->yresolution,
821
else if (strcmp (*names, "rx") == 0)
823
parse_svg_length (*values,
824
handler->width, parser->image->xresolution,
827
else if (strcmp (*names, "ry") == 0)
829
parse_svg_length (*values,
830
handler->height, parser->image->yresolution,
836
if (strcmp (*names, "transform") == 0 && !handler->transform)
840
if (parse_svg_transform (*values, &matrix))
841
handler->transform = g_memdup (&matrix, sizeof (GimpMatrix3));
831
if (strcmp (*names, "id") == 0 && !path->id)
833
path->id = g_strdup (*values);
835
else if (strcmp (*names, "x1") == 0)
837
parse_svg_length (*values,
838
handler->width, parser->image->xresolution,
841
else if (strcmp (*names, "y1") == 0)
843
parse_svg_length (*values,
844
handler->height, parser->image->yresolution,
847
else if (strcmp (*names, "x2") == 0)
849
parse_svg_length (*values,
850
handler->width, parser->image->xresolution,
853
else if (strcmp (*names, "y2") == 0)
855
parse_svg_length (*values,
856
handler->height, parser->image->yresolution,
859
else if (strcmp (*names, "transform") == 0 && !handler->transform)
863
if (parse_svg_transform (*values, &matrix))
864
handler->transform = g_memdup (&matrix, sizeof (GimpMatrix3));
875
if (strcmp (*names, "id") == 0 && !path->id)
876
path->id = g_strdup (*values);
880
if (strcmp (*names, "x1") == 0)
881
parse_svg_length (*values,
882
handler->width, parser->image->xresolution,
884
else if (strcmp (*names, "x2") == 0)
885
parse_svg_length (*values,
886
handler->width, parser->image->xresolution,
891
if (strcmp (*names, "y1") == 0)
892
parse_svg_length (*values,
893
handler->height, parser->image->yresolution,
895
else if (strcmp (*names, "y2") == 0)
896
parse_svg_length (*values,
897
handler->height, parser->image->yresolution,
902
if (strcmp (*names, "transform") == 0 && !handler->transform)
906
if (parse_svg_transform (*values, &matrix))
907
handler->transform = g_memdup (&matrix, sizeof (GimpMatrix3));
890
if (strcmp (*names, "id") == 0 && !path->id)
892
path->id = g_strdup (*values);
894
else if (strcmp (*names, "points") == 0 && !points)
896
const gchar *p = *values;
897
const gchar *m = NULL;
898
const gchar *l = NULL;
903
while (g_ascii_isspace (*p) || *p == ',')
916
while (*p && !g_ascii_isspace (*p) && *p != ',')
922
if ((n > 3) && (n % 2 == 0))
924
points = g_string_sized_new (p - *values + 8);
926
g_string_append_len (points, "M ", 2);
927
g_string_append_len (points, m, l - m);
929
g_string_append_len (points, "L ", 2);
930
g_string_append_len (points, l, p - l);
932
if (strcmp (handler->name, "polygon") == 0)
933
g_string_append_c (points, 'Z');
936
else if (strcmp (*names, "transform") == 0 && !handler->transform)
940
if (parse_svg_transform (*values, &matrix))
941
handler->transform = g_memdup (&matrix, sizeof (GimpMatrix3));
938
if (strcmp (*names, "id") == 0 && !path->id)
939
path->id = g_strdup (*values);
943
if (strcmp (*names, "points") == 0 && !points)
945
const gchar *p = *values;
946
const gchar *m = NULL;
947
const gchar *l = NULL;
952
while (g_ascii_isspace (*p) || *p == ',')
965
while (*p && !g_ascii_isspace (*p) && *p != ',')
971
if ((n > 3) && (n % 2 == 0))
973
points = g_string_sized_new (p - *values + 8);
975
g_string_append_len (points, "M ", 2);
976
g_string_append_len (points, m, l - m);
978
g_string_append_len (points, "L ", 2);
979
g_string_append_len (points, l, p - l);
981
if (strcmp (handler->name, "polygon") == 0)
982
g_string_append_c (points, 'Z');
988
if (strcmp (*names, "transform") == 0 && !handler->transform)
992
if (parse_svg_transform (*values, &matrix))
993
handler->transform = g_memdup (&matrix, sizeof (GimpMatrix3));
1307
1361
if (c >= '0' && c <= '9')
1314
exp = (exp * 10) + c - '0';
1315
exp_wait_sign = FALSE;
1318
val += (frac *= 0.1) * (c - '0');
1320
val = (val * 10) + c - '0';
1329
exp_wait_sign = FALSE;
1368
exp = (exp * 10) + c - '0';
1369
exp_wait_sign = FALSE;
1372
val += (frac *= 0.1) * (c - '0');
1374
val = (val * 10) + c - '0';
1383
exp_wait_sign = FALSE;
1334
1388
else if (c == '.')
1344
1398
else if ((c == 'E' || c == 'e') && in_num)
1347
exp_wait_sign = TRUE;
1401
exp_wait_sign = TRUE;
1351
1405
else if ((c == '+' || c == '-') && in_exp)
1353
exp_sign = c == '+' ? 1 : -1;
1407
exp_sign = c == '+' ? 1 : -1;
1355
1409
else if (in_num)
1359
val *= sign * pow (10, exp_sign * exp);
1362
/* Handle relative coordinates. This switch statement attempts
1363
to determine _what_ the coords are relative to. This is
1364
underspecified in the 12 Apr working draft. */
1373
/* rule: even-numbered params are x-relative, odd-numbered
1375
if ((ctx.param & 1) == 0)
1377
else if ((ctx.param & 1) == 1)
1382
/* rule: sixth and seventh are x and y, rest are not
1386
else if (ctx.param == 6)
1390
/* rule: x-relative */
1394
/* rule: y-relative */
1400
ctx.params[ctx.param++] = val;
1401
parse_path_do_cmd (&ctx, FALSE);
1413
val *= sign * pow (10, exp_sign * exp);
1416
/* Handle relative coordinates. This switch statement attempts
1417
to determine _what_ the coords are relative to. This is
1418
underspecified in the 12 Apr working draft. */
1427
/* rule: even-numbered params are x-relative, odd-numbered
1429
if ((ctx.param & 1) == 0)
1431
else if ((ctx.param & 1) == 1)
1436
/* rule: sixth and seventh are x and y, rest are not
1440
else if (ctx.param == 6)
1444
/* rule: x-relative */
1448
/* rule: y-relative */
1454
ctx.params[ctx.param++] = val;
1455
parse_path_do_cmd (&ctx, FALSE);
1407
1461
else if ((c == '+' || c == '-') && !exp_wait_sign)
1409
sign = c == '+' ? 1 : -1;
1416
exp_wait_sign = FALSE;
1463
sign = c == '+' ? 1 : -1;
1470
exp_wait_sign = FALSE;
1418
1472
else if (c == 'z' || c == 'Z')
1421
parse_path_do_cmd (&ctx, TRUE);
1475
parse_path_do_cmd (&ctx, TRUE);
1422
1476
if (ctx.stroke)
1423
1477
gimp_stroke_close (ctx.stroke);
1425
1479
else if (c >= 'A' && c <= 'Z' && c != 'E')
1428
parse_path_do_cmd (&ctx, TRUE);
1429
ctx.cmd = c + 'a' - 'A';
1482
parse_path_do_cmd (&ctx, TRUE);
1483
ctx.cmd = c + 'a' - 'A';
1432
1486
else if (c >= 'a' && c <= 'z' && c != 'e')
1435
parse_path_do_cmd (&ctx, TRUE);
1489
parse_path_do_cmd (&ctx, TRUE);
1439
1493
/* else c _should_ be whitespace or , */
1490
1544
ctx->stroke = gimp_bezier_stroke_new_moveto (&coords);
1491
1545
ctx->strokes = g_list_prepend (ctx->strokes, ctx->stroke);
1498
1553
if (ctx->param == 2 || final)
1500
parse_path_default_xy (ctx, 2);
1555
parse_path_default_xy (ctx, 2);
1502
1557
coords.x = ctx->cpx = ctx->rpx = ctx->params[0];
1503
1558
coords.y = ctx->cpy = ctx->rpy = ctx->params[1];
1505
1560
gimp_bezier_stroke_lineto (ctx->stroke, &coords);
1512
1568
if (ctx->param == 6 || final)
1514
1570
GimpCoords ctrl1 = { 0.0, 0.0, 1.0, 0.5, 0.5, 0.5 };
1515
1571
GimpCoords ctrl2 = { 0.0, 0.0, 1.0, 0.5, 0.5, 0.5 };
1517
parse_path_default_xy (ctx, 6);
1573
parse_path_default_xy (ctx, 6);
1519
ctrl1.x = ctx->params[0];
1520
ctrl1.y = ctx->params[1];
1521
ctrl2.x = ctx->rpx = ctx->params[2];
1522
ctrl2.y = ctx->rpy = ctx->params[3];
1523
coords.x = ctx->cpx = ctx->params[4];
1524
coords.y = ctx->cpy = ctx->params[5];
1575
ctrl1.x = ctx->params[0];
1576
ctrl1.y = ctx->params[1];
1577
ctrl2.x = ctx->rpx = ctx->params[2];
1578
ctrl2.y = ctx->rpy = ctx->params[3];
1579
coords.x = ctx->cpx = ctx->params[4];
1580
coords.y = ctx->cpy = ctx->params[5];
1526
1582
gimp_bezier_stroke_cubicto (ctx->stroke, &ctrl1, &ctrl2, &coords);
1532
1589
/* smooth curveto */
1533
1590
if (ctx->param == 4 || final)
1535
1592
GimpCoords ctrl1 = { 0.0, 0.0, 1.0, 0.5, 0.5, 0.5 };
1536
1593
GimpCoords ctrl2 = { 0.0, 0.0, 1.0, 0.5, 0.5, 0.5 };
1538
parse_path_default_xy (ctx, 4);
1595
parse_path_default_xy (ctx, 4);
1540
1597
ctrl1.x = 2 * ctx->cpx - ctx->rpx;
1541
ctrl1.y = 2 * ctx->cpy - ctx->rpy;
1598
ctrl1.y = 2 * ctx->cpy - ctx->rpy;
1542
1599
ctrl2.x = ctx->rpx = ctx->params[0];
1543
1600
ctrl2.y = ctx->rpy = ctx->params[1];
1544
coords.x = ctx->cpx = ctx->params[2];
1545
coords.y = ctx->cpy = ctx->params[3];
1601
coords.x = ctx->cpx = ctx->params[2];
1602
coords.y = ctx->cpy = ctx->params[3];
1547
1604
gimp_bezier_stroke_cubicto (ctx->stroke, &ctrl1, &ctrl2, &coords);
1553
1611
/* horizontal lineto */
1554
1612
if (ctx->param == 1)
1556
1614
coords.x = ctx->cpx = ctx->rpx = ctx->params[0];
1557
1615
coords.y = ctx->cpy;
1559
1617
gimp_bezier_stroke_lineto (ctx->stroke, &coords);
1565
1624
/* vertical lineto */
1566
1625
if (ctx->param == 1)
1568
1627
coords.x = ctx->cpx;
1569
1628
coords.y = ctx->cpy = ctx->rpy = ctx->params[0];
1571
1630
gimp_bezier_stroke_lineto (ctx->stroke, &coords);
1578
1637
/* quadratic bezier curveto */
1579
1638
if (ctx->param == 4 || final)
1581
1640
GimpCoords ctrl = { 0.0, 0.0, 1.0, 0.5, 0.5, 0.5 };
1583
parse_path_default_xy (ctx, 4);
1642
parse_path_default_xy (ctx, 4);
1585
ctrl.x = ctx->rpx = ctx->params[0];
1586
ctrl.y = ctx->rpy = ctx->params[1];
1587
coords.x = ctx->cpx = ctx->params[2];
1588
coords.y = ctx->cpy = ctx->params[3];
1644
ctrl.x = ctx->rpx = ctx->params[0];
1645
ctrl.y = ctx->rpy = ctx->params[1];
1646
coords.x = ctx->cpx = ctx->params[2];
1647
coords.y = ctx->cpy = ctx->params[3];
1590
1649
gimp_bezier_stroke_conicto (ctx->stroke, &ctrl, &coords);
1596
1656
/* truetype quadratic bezier curveto */
1597
1657
if (ctx->param == 2 || final)
1599
1659
GimpCoords ctrl = { 0.0, 0.0, 1.0, 0.5, 0.5, 0.5 };
1601
parse_path_default_xy (ctx, 2);
1661
parse_path_default_xy (ctx, 2);
1603
1663
ctrl.x = ctx->rpx = 2 * ctx->cpx - ctx->rpx;
1604
1664
ctrl.y = ctx->rpy = 2 * ctx->cpy - ctx->rpy;
1605
coords.x = ctx->cpx = ctx->params[0];
1606
coords.y = ctx->cpy = ctx->params[1];
1665
coords.x = ctx->cpx = ctx->params[0];
1666
coords.y = ctx->cpy = ctx->params[1];
1608
1668
gimp_bezier_stroke_conicto (ctx->stroke, &ctrl, &coords);
1612
1672
else if (final)
1616
1676
GimpCoords ctrl = { 0.0, 0.0, 1.0, 0.5, 0.5, 0.5 };
1618
parse_path_default_xy (ctx, 4);
1678
parse_path_default_xy (ctx, 4);
1620
1680
ctrl.x = ctx->rpx = ctx->params[0];
1621
1681
ctrl.y = ctx->rpy = ctx->params[1];