Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 128107 | Differences between
and this patch

Collapse All | Expand All

(-)dia-0.94/plug-ins/xfig/xfig-import.c.orig (-34 / +53 lines)
Lines 441-451 Link Here
441
static Color
441
static Color
442
fig_color(int color_index) 
442
fig_color(int color_index) 
443
{
443
{
444
    if (color_index == -1) 
444
    if (color_index <= -1) 
445
        return color_black; /* Default color */
445
        return color_black; /* Default color */
446
    if (color_index < FIG_MAX_DEFAULT_COLORS) 
446
    else if (color_index < FIG_MAX_DEFAULT_COLORS) 
447
        return fig_default_colors[color_index];
447
        return fig_default_colors[color_index];
448
    else return fig_colors[color_index-FIG_MAX_DEFAULT_COLORS];
448
    else if (color_index < FIG_MAX_USER_COLORS) 
449
	return fig_colors[color_index-FIG_MAX_DEFAULT_COLORS];
450
    else {
451
	message_error(_("Color index %d too high, only 512 colors allowed. Using black instead."),
452
		      color_index);
453
	return color_black;
454
    }
449
}
455
}
450
456
451
static Color
457
static Color
Lines 563-585 Link Here
563
static int
569
static int
564
fig_read_n_points(FILE *file, int n, Point **points) {
570
fig_read_n_points(FILE *file, int n, Point **points) {
565
    int i;
571
    int i;
566
    Point *new_points;
572
    GArray *points_list = g_array_sized_new(FALSE, FALSE, sizeof(Point), n);
567
568
    new_points = (Point*)g_malloc(sizeof(Point)*n);
569
573
570
    for (i = 0; i < n; i++) {
574
    for (i = 0; i < n; i++) {
571
	int x,y;
575
	int x,y;
576
	Point p;
572
	if (fscanf(file, " %d %d ", &x, &y) != 2) {
577
	if (fscanf(file, " %d %d ", &x, &y) != 2) {
573
	    message_error(_("Error while reading %dth of %d points: %s\n"),
578
	    message_error(_("Error while reading %dth of %d points: %s\n"),
574
			  i, n, strerror(errno));
579
			  i, n, strerror(errno));
575
	    free(new_points);
580
	    g_array_free(points_list, TRUE);
576
	    return FALSE;
581
	    return FALSE;
577
	}
582
	}
578
	new_points[i].x = x/FIG_UNIT;
583
	p.x = x/FIG_UNIT;
579
	new_points[i].y = y/FIG_UNIT;
584
	p.y = y/FIG_UNIT;
585
	g_array_append_val(points_list, p);
580
    }
586
    }
581
    fscanf(file, "\n");
587
    fscanf(file, "\n");
582
    *points = new_points;
588
    
589
    *points = (Point *)points_list->data;
590
    g_array_free(points_list, FALSE);
583
    return TRUE;
591
    return TRUE;
584
}
592
}
585
593
Lines 683-689 Link Here
683
    return text_buf;
691
    return text_buf;
684
}
692
}
685
693
686
static GList *depths[1000];
694
static GList *depths[FIG_MAX_DEPTHS];
687
695
688
/* If there's something in the compound stack, we ignore the depth field,
696
/* If there's something in the compound stack, we ignore the depth field,
689
   as it will be determined by the group anyway */
697
   as it will be determined by the group anyway */
Lines 693-698 Link Here
693
   level.  Best we can do now. */
701
   level.  Best we can do now. */
694
static int compound_depth;
702
static int compound_depth;
695
703
704
/** Add an object at a given depth.  This function checks for depth limits
705
 * and updates the compound depth if needed.
706
 *
707
 * @param newobj An object to add.  If we're inside a compound, this
708
 * doesn't really add the object.
709
 * @param depth A depth as in the Fig format, max 999
710
 */
711
static void
712
add_at_depth(DiaObject *newobj, int depth) {
713
    if (depth < 0 || depth >= FIG_MAX_DEPTHS) {
714
	message_error(_("Depth %d of of range, only 0-%d allowed.\n"),
715
		      depth, FIG_MAX_DEPTHS-1);
716
	depth = FIG_MAX_DEPTHS - 1;
717
    }
718
    if (compound_stack == NULL) 
719
	depths[depth] = g_list_append(depths[depth], newobj);
720
    else 
721
	if (compound_depth > depth) compound_depth = depth;
722
}
723
696
static DiaObject *
724
static DiaObject *
697
fig_read_ellipse(FILE *file, DiagramData *dia) {
725
fig_read_ellipse(FILE *file, DiagramData *dia) {
698
    int sub_type;
726
    int sub_type;
Lines 749-758 Link Here
749
    /* Angle -- can't rotate yet */
777
    /* Angle -- can't rotate yet */
750
778
751
    /* Depth field */
779
    /* Depth field */
752
    if (compound_stack == NULL)
780
    add_at_depth(newobj, depth);
753
	depths[depth] = g_list_append(depths[depth], newobj);
754
    else
755
	if (compound_depth > depth) compound_depth = depth;
756
781
757
    return newobj;
782
    return newobj;
758
}
783
}
Lines 885-894 Link Here
885
    /* Cap style */
910
    /* Cap style */
886
     
911
     
887
    /* Depth field */
912
    /* Depth field */
888
    if (compound_stack == NULL)
913
    add_at_depth(newobj, depth);
889
	depths[depth] = g_list_append(depths[depth], newobj);
890
    else
891
	if (compound_depth > depth) compound_depth = depth;
892
 exit:
914
 exit:
893
    prop_list_free(props);
915
    prop_list_free(props);
894
    g_free(forward_arrow_info);
916
    g_free(forward_arrow_info);
Lines 1111-1120 Link Here
1111
    /* Cap style */
1133
    /* Cap style */
1112
     
1134
     
1113
    /* Depth field */
1135
    /* Depth field */
1114
    if (compound_stack == NULL)
1136
    add_at_depth(newobj, depth);
1115
	depths[depth] = g_list_append(depths[depth], newobj);
1116
    else
1117
	if (compound_depth > depth) compound_depth = depth;
1118
 exit:
1137
 exit:
1119
    prop_list_free(props);
1138
    prop_list_free(props);
1120
    g_free(forward_arrow_info);
1139
    g_free(forward_arrow_info);
Lines 1202-1211 Link Here
1202
    /* Cap style */
1221
    /* Cap style */
1203
     
1222
     
1204
    /* Depth field */
1223
    /* Depth field */
1205
    if (compound_stack == NULL)
1224
    add_at_depth(newobj, depth);
1206
	depths[depth] = g_list_append(depths[depth], newobj);
1207
    else
1208
	if (compound_depth > depth) compound_depth = depth;
1209
1225
1210
 exit:
1226
 exit:
1211
    g_free(forward_arrow_info);
1227
    g_free(forward_arrow_info);
Lines 1298-1307 Link Here
1298
    newobj->ops->set_props(newobj, props);
1314
    newobj->ops->set_props(newobj, props);
1299
    
1315
    
1300
    /* Depth field */
1316
    /* Depth field */
1301
    if (compound_stack == NULL)
1317
    add_at_depth(newobj, depth);
1302
	depths[depth] = g_list_append(depths[depth], newobj);
1303
    else
1304
	if (compound_depth > depth) compound_depth = depth;
1305
1318
1306
 exit:
1319
 exit:
1307
    if (text_buf != NULL) free(text_buf);
1320
    if (text_buf != NULL) free(text_buf);
Lines 1347-1352 Link Here
1347
	    return FALSE;
1360
	    return FALSE;
1348
	}
1361
	}
1349
1362
1363
	if (colornumber < 32 || colornumber > FIG_MAX_USER_COLORS) {
1364
	    message_error(_("Color number %d out of range 0..%d.  Discarding color.\n"),
1365
			  colornumber, FIG_MAX_USER_COLORS);
1366
	    return FALSE;
1367
	}
1368
1350
	color.red = ((colorvalues & 0x00ff0000)>>16) / 255.0;
1369
	color.red = ((colorvalues & 0x00ff0000)>>16) / 255.0;
1351
	color.green = ((colorvalues & 0x0000ff00)>>8) / 255.0;
1370
	color.green = ((colorvalues & 0x0000ff00)>>8) / 255.0;
1352
	color.blue = (colorvalues & 0x000000ff) / 255.0;
1371
	color.blue = (colorvalues & 0x000000ff) / 255.0;
Lines 1393-1399 Link Here
1393
	}
1412
	}
1394
	/* Group extends don't really matter */
1413
	/* Group extends don't really matter */
1395
	if (compound_stack == NULL)
1414
	if (compound_stack == NULL)
1396
	    compound_depth = 999;
1415
	    compound_depth = FIG_MAX_DEPTHS - 1;
1397
	compound_stack = g_slist_append(compound_stack, NULL);
1416
	compound_stack = g_slist_append(compound_stack, NULL);
1398
	return TRUE;
1417
	return TRUE;
1399
	break;
1418
	break;
Lines 1551-1557 Link Here
1551
    for (i = 0; i < FIG_MAX_USER_COLORS; i++) {
1570
    for (i = 0; i < FIG_MAX_USER_COLORS; i++) {
1552
	fig_colors[i] = color_black;
1571
	fig_colors[i] = color_black;
1553
    }
1572
    }
1554
    for (i = 0; i < 1000; i++) {
1573
    for (i = 0; i < FIG_MAX_DEPTHS; i++) {
1555
	depths[i] = NULL;
1574
	depths[i] = NULL;
1556
    }
1575
    }
1557
1576
Lines 1606-1612 Link Here
1606
    } while (TRUE);
1625
    } while (TRUE);
1607
1626
1608
    /* Now we can reorder for the depth fields */
1627
    /* Now we can reorder for the depth fields */
1609
    for (i = 0; i < 1000; i++) {
1628
    for (i = 0; i < FIG_MAX_DEPTHS; i++) {
1610
	if (depths[i] != NULL)
1629
	if (depths[i] != NULL)
1611
	    layer_add_objects_first(dia->active_layer, depths[i]);
1630
	    layer_add_objects_first(dia->active_layer, depths[i]);
1612
    }
1631
    }

Return to bug 128107