Graphics-Potrace

 view release on metacpan or  search on metacpan

Potrace.xs  view on Meta::CPAN

}

SV *_make_pathnode(potrace_path_t *node) {
   HV *retval = newHV();
   AV *curve  = newAV();
   unsigned int i;
   int tag;
   potrace_dpoint_t *c = NULL;
   HV *segment = NULL;
   HV *first_segment = NULL;
   SV *last_endpoint = NULL;
   
   hv_store(retval, "area", 4, newSViv(node->area), FALSE);
   hv_store(retval, "sign", 4, newSVpvn((node->sign == '-' ? "-" : "+"), 1), FALSE);
   hv_store(retval, "curve", 5, newRV_noinc((SV *)curve), FALSE);
   
   for (i = 0; i < (node->curve).n; ++i) {
      tag = (node->curve).tag[i];
      c   = (node->curve).c[i];

      segment = newHV();
      if (first_segment == NULL)
         first_segment = segment;

      if (last_endpoint) {
         hv_store(segment, "begin", 5, last_endpoint, FALSE);
         last_endpoint = NULL;
      }

      hv_store(segment, "end", 3, _make_point(c+2), FALSE);
      last_endpoint = _make_point(c+2); /* "begin" of the next segment */

      if (tag == POTRACE_CORNER) {
         hv_store(segment, "type", 4, newSVpvn("corner", 6), FALSE);
         hv_store(segment, "corner", 6, _make_point(c+1), FALSE);
      }
      else if (tag == POTRACE_CURVETO) {
         hv_store(segment, "type", 4, newSVpvn("bezier", 6), FALSE);
         hv_store(segment, "u", 1, _make_point(c), FALSE);
         hv_store(segment, "w", 1, _make_point(c+1), FALSE);
      }
      else {
         warn("Unknown tag: %d", tag);
         hv_store(segment, "type", 4, newSVpvn("unknown", 7), FALSE);
         hv_store(segment, "tag", 3, newSViv(tag), FALSE);
         hv_store(segment, "p1", 2, _make_point(c), FALSE);
         hv_store(segment, "p2", 2, _make_point(c+1), FALSE);
      }
      av_push(curve, newRV_noinc((SV *)segment));
   }
   if (last_endpoint)
      hv_store(first_segment, "begin", 5, last_endpoint, FALSE);
   
   return newRV_noinc((SV *)retval);
}

SV *_make_listpath(potrace_path_t *plist) {
   AV *retval = newAV();
   SV *node = NULL;
   unsigned int n = 0;

   while (plist != NULL) {



( run in 1.339 second using v1.01-cache-2.11-cpan-beeb90c9504 )