void _create_tiled_line(Line * line) { int flag, sign = 1; Eina_List *list = NULL, *l, *lo; Evas *e; Evas_Object *o; Drawing *d; float x, y, dx, dy, len; double x1, y1, x2, y2; XY *xy; d = drawing; dx = line->x2 - line->x1; if (dx == 0) dx = 1e-40; /* ok for 1200 dpi? */ sign = fabs(dx) / dx; dy = line->y2 - line->y1; len = hypot(dx, dy); flag = linestyle_get_odd(); list = linestyle_get_points(len, line->line_scale); ENGY_ASSERT(list); trans_rotate(list, atan(-dy / dx) + M_PI * (sign - 1) / 2); trans_move(list, line->x1, line->y1); e = shell->evas; lo = line->list; for (l = list->next; l; l = l->next) { XY *a, *b; a = (XY *) l->prev->data; b = (XY *) l->data; flag = !flag; if (flag) { if (!lo || !lo->data) { o = _line_item(e, line->thickness * shell->context.show_thickness * d->scale); evas_object_layer_set(o, 10); evas_object_pass_events_set(o, 1); line->list = eina_list_append(line->list, o); lo = eina_list_last(line->list); } o = lo->data; lo = lo->next; x1 = w2s_x(a->x); y1 = w2s_y(a->y); x2 = w2s_x(b->x); y2 = w2s_y(b->y); if (line->flags & FLAG_VISIBLE) { evas_object_color_set(o, line->color.red*line->color.alpha/255, line->color.green*line->color.alpha/255, line->color.blue*line->color.alpha/255, line->color.alpha); } else { evas_object_color_set(o, 0, 0, 0, 0); } if (line->flags & FLAG_SELECTED) evas_object_color_set(o, ALPHA5, ALPHA5/5, ALPHA5/5, ALPHA5); if (line->flags & FLAG_DELETED) evas_object_color_set(o, 0, 0, 0, 0); _line_item_xy(e, o, x1, y1, x2, y2, line->thickness * shell->context.show_thickness * d->scale); evas_object_show(o); } } for (l = list; l; l = l->next) FREE(l->data); list = eina_list_free(list); }
/* determine the dimensions of the output based on command line and image dimensions, and optionally, based on the actual image outline. */ static void calc_dimensions(imginfo_t *imginfo, potrace_path_t *plist) { double dim_def; double maxwidth, maxheight, sc; int default_scaling = 0; /* we take care of a special case: if one of the image dimensions is 0, we change it to 1. Such an image is empty anyway, so there will be 0 paths in it. Changing the dimensions avoids division by 0 error in calculating scaling factors, bounding boxes and such. This doesn't quite do the right thing in all cases, but it is better than causing overflow errors or "nan" output in backends. Human users don't tend to process images of size 0 anyway; they might occur in some pipelines. */ if (imginfo->pixwidth == 0) { imginfo->pixwidth = 1; } if (imginfo->pixheight == 0) { imginfo->pixheight = 1; } /* set the default dimension for width, height, margins */ if (info.backend->pixel) { dim_def = DIM_PT; } else { dim_def = DEFAULT_DIM; } /* apply default dimension to width, height, margins */ imginfo->width = info.width_d.x == UNDEF ? UNDEF : double_of_dim(info.width_d, dim_def); imginfo->height = info.height_d.x == UNDEF ? UNDEF : double_of_dim(info.height_d, dim_def); imginfo->lmar = info.lmar_d.x == UNDEF ? UNDEF : double_of_dim(info.lmar_d, dim_def); imginfo->rmar = info.rmar_d.x == UNDEF ? UNDEF : double_of_dim(info.rmar_d, dim_def); imginfo->tmar = info.tmar_d.x == UNDEF ? UNDEF : double_of_dim(info.tmar_d, dim_def); imginfo->bmar = info.bmar_d.x == UNDEF ? UNDEF : double_of_dim(info.bmar_d, dim_def); /* start with a standard rectangle */ trans_from_rect(&imginfo->trans, imginfo->pixwidth, imginfo->pixheight); /* if info.tight is set, tighten the bounding box */ if (info.tight) { trans_tighten(&imginfo->trans, plist); } /* sx/rx is just an alternate way to specify width; sy/ry is just an alternate way to specify height. */ if (info.backend->pixel) { if (imginfo->width == UNDEF && info.sx != UNDEF) { imginfo->width = imginfo->trans.bb[0] * info.sx; } if (imginfo->height == UNDEF && info.sy != UNDEF) { imginfo->height = imginfo->trans.bb[1] * info.sy; } } else { if (imginfo->width == UNDEF && info.rx != UNDEF) { imginfo->width = imginfo->trans.bb[0] / info.rx * 72; } if (imginfo->height == UNDEF && info.ry != UNDEF) { imginfo->height = imginfo->trans.bb[1] / info.ry * 72; } } /* if one of width/height is specified, use stretch to determine the other */ if (imginfo->width == UNDEF && imginfo->height != UNDEF) { imginfo->width = imginfo->height / imginfo->trans.bb[1] * imginfo->trans.bb[0] / info.stretch; } else if (imginfo->width != UNDEF && imginfo->height == UNDEF) { imginfo->height = imginfo->width / imginfo->trans.bb[0] * imginfo->trans.bb[1] * info.stretch; } /* if width and height are still variable, tenatively use the default scaling factor of 72dpi (for dimension-based backends) or 1 (for pixel-based backends). For fixed-size backends, this will be adjusted later to fit the page. */ if (imginfo->width == UNDEF && imginfo->height == UNDEF) { imginfo->width = imginfo->trans.bb[0]; imginfo->height = imginfo->trans.bb[1] * info.stretch; default_scaling = 1; } /* apply scaling */ trans_scale_to_size(&imginfo->trans, imginfo->width, imginfo->height); /* apply rotation, and tighten the bounding box again, if necessary */ if (info.angle != 0.0) { trans_rotate(&imginfo->trans, info.angle); if (info.tight) { trans_tighten(&imginfo->trans, plist); } } /* for fixed-size backends, if default scaling was in effect, further adjust the scaling to be the "best fit" for the given page size and margins. */ if (default_scaling && info.backend->fixed) { /* try to squeeze it between margins */ maxwidth = UNDEF; maxheight = UNDEF; if (imginfo->lmar != UNDEF && imginfo->rmar != UNDEF) { maxwidth = info.paperwidth - imginfo->lmar - imginfo->rmar; } if (imginfo->bmar != UNDEF && imginfo->tmar != UNDEF) { maxheight = info.paperheight - imginfo->bmar - imginfo->tmar; } if (maxwidth == UNDEF && maxheight == UNDEF) { maxwidth = max(info.paperwidth - 144, info.paperwidth * 0.75); maxheight = max(info.paperheight - 144, info.paperheight * 0.75); } if (maxwidth == UNDEF) { sc = maxheight / imginfo->trans.bb[1]; } else if (maxheight == UNDEF) { sc = maxwidth / imginfo->trans.bb[0]; } else { sc = min(maxwidth / imginfo->trans.bb[0], maxheight / imginfo->trans.bb[1]); } /* re-scale coordinate system */ imginfo->width *= sc; imginfo->height *= sc; trans_rescale(&imginfo->trans, sc); } /* adjust margins */ if (info.backend->fixed) { if (imginfo->lmar == UNDEF && imginfo->rmar == UNDEF) { imginfo->lmar = (info.paperwidth-imginfo->trans.bb[0])/2; } else if (imginfo->lmar == UNDEF) { imginfo->lmar = (info.paperwidth-imginfo->trans.bb[0]-imginfo->rmar); } else if (imginfo->lmar != UNDEF && imginfo->rmar != UNDEF) { imginfo->lmar += (info.paperwidth-imginfo->trans.bb[0]-imginfo->lmar-imginfo->rmar)/2; } if (imginfo->bmar == UNDEF && imginfo->tmar == UNDEF) { imginfo->bmar = (info.paperheight-imginfo->trans.bb[1])/2; } else if (imginfo->bmar == UNDEF) { imginfo->bmar = (info.paperheight-imginfo->trans.bb[1]-imginfo->tmar); } else if (imginfo->bmar != UNDEF && imginfo->tmar != UNDEF) { imginfo->bmar += (info.paperheight-imginfo->trans.bb[1]-imginfo->bmar-imginfo->tmar)/2; } } else { if (imginfo->lmar == UNDEF) { imginfo->lmar = 0; } if (imginfo->rmar == UNDEF) { imginfo->rmar = 0; } if (imginfo->bmar == UNDEF) { imginfo->bmar = 0; } if (imginfo->tmar == UNDEF) { imginfo->tmar = 0; } } }
void hatch_create(void) { Eina_List *list, *l; XY *a, *b; int i, num, res, res1; int flag = 0; Evas *e; char buf[4096]; char *s, *st; Eina_List *poly; double dx, dy, g, g2; e = shell->evas; hs_set(shell->context.hatch_style); poly = hatch_get_poly(); serv_set_hint(DUP(_("enter hatch angle: "))); s = serv_get_string(); g = atof(s); FREE(s); num = hs_get_num(); for (i = 0; i < num; i++) { int flag = 0, cnt = 0; double y, yr, ystep, scale; g2 = g + hs_get_angle(i); scale = hs_get_scale(i); ystep = hs_get_ystep(i); dy = hs_get_yoffset(i); dx = hs_get_xoffset(i); st = hs_get_line_style(i); trans_rotate(poly, g2 / 180 * M_PI); for (y = drawing->h * (-2); y < drawing->h * 3; y += ystep) { cnt++; yr = y + dy; list = find_points(poly, -210.0, yr, 420.0, yr); if (!list) continue; if (!list->next) continue; trans_rotate(list, -g2 / 180 * M_PI); flag = 0; for (l = list; l->next; l = l->next) { flag = !flag; a = (XY *) l->data; b = (XY *) l->next->data; if (flag) { _hatch_create_line(a->x, a->y, b->x, b->y, DUP(st), scale, shell-> context.thickness, dx * cnt); } } } trans_rotate(poly, -g2 / 180 * M_PI); FREE(st); } }