示例#1
0
    void GraphAggRenderer::fillPolygon(Point *points, int pointCount,
            Color *color)
    {
        //qDebug() << QString("%1").arg(__PRETTY_FUNCTION__);

        agg::path_storage &ps = m_data->ps;
        unsigned idx = ps.start_new_path();

        ps.move_to(points[0].x(), points[0].y());
        for (int i = 1; i < pointCount; ++i) {
            ps.line_to(points[i].x(), points[i].y());
        }
        ps.end_poly(agg::path_flags_close);


        // 保存属性
        push_attr();
        m_data->as.add(path_attributes(cur_attr(), idx));

        //保存idx值
        path_attributes attr = cur_attr();
        attr.stroke_flag = false;
        attr.fill_flag = true;
        attr.fill_color = agg::rgba8(color->red(), 
                color->green(), color->blue(), color->alpha());
        attr.index = idx;
        m_data->as[m_data->as.size() -1] = attr;
        pop_attr();

        updateBbox();
    }
示例#2
0
    void GraphAggRenderer::fillEllipse(Point *center, 
            float width, float height, 
            Color *color)
    {
        //qDebug() << QString("%1").arg(__PRETTY_FUNCTION__);

        agg::ellipse e1;
        e1.init(center->x(), center->y(),
                width, height, 100);

        agg::path_storage &ps = m_data->ps;
        unsigned idx = ps.start_new_path();
        ps.concat_path(e1);

        // 保存属性
        push_attr();
        m_data->as.add(path_attributes(cur_attr(), idx));

        //保存idx值
        path_attributes attr = cur_attr();
        attr.stroke_flag = false;
        attr.fill_flag = true;
        attr.fill_color = agg::rgba8(color->red(), 
                color->green(), color->blue(), color->alpha());
        attr.index = idx;
        m_data->as[m_data->as.size() -1] = attr;
        pop_attr();

        updateBbox();
    }
示例#3
0
    void GraphAggRenderer::fillRect(Point *ulCorner, Point *lrCorner, 
            Color *color)
    {
        //qDebug() << QString("%1").arg(__PRETTY_FUNCTION__);
        agg::path_storage &ps = m_data->ps;
        unsigned idx = ps.start_new_path();

        ps.move_to(ulCorner->x(), ulCorner->y());
        ps.line_to(lrCorner->x(), ulCorner->y());
        ps.line_to(lrCorner->x(), lrCorner->y());
        ps.line_to(ulCorner->x(), lrCorner->y());
        ps.line_to(ulCorner->x(), ulCorner->y());
        ps.end_poly();


        // 保存属性
        push_attr();
        m_data->as.add(path_attributes(cur_attr(), idx));

        //保存idx值
        path_attributes attr = cur_attr();
        attr.stroke_flag = false;
        attr.fill_flag = true;
        attr.fill_color = agg::rgba8(color->red(), 
                color->green(), color->blue(), color->alpha());
        attr.index = idx;
        m_data->as[m_data->as.size() -1] = attr;
        pop_attr();

        updateBbox();
    }
//------------------------------------------------------------------------
void path_renderer::begin_path()
{
    push_attr();
    unsigned idx = m_storage.start_new_path();
    m_attr_storage.add(path_attributes(cur_attr(), idx));
}
示例#5
0
 void begin_path()
 {
     push_attr();
     unsigned idx = source_.start_new_path();
     attributes_.add(path_attributes(cur_attr(), idx));
 }
示例#6
0
    void GraphAggRenderer::drawString(const QString &text, 
            Point *pos,
            int alignment, 
            Color *color)
    {
        if (text.isEmpty())
            return;
        //qDebug() << QString("%1").arg(__PRETTY_FUNCTION__);

        agg::path_storage &ps = m_data->ps;
        unsigned idx = ps.start_new_path();


        // 绘制文本
        font_manager_type *fman = get_fman();

        double x = pos->x();
        double y = pos->y();

        wchar_t *buffer = new wchar_t[text.size() + 1];
        text.toWCharArray(buffer);
        buffer[text.size()] = NULL;
        //qDebug() << text;
        const wchar_t *p = buffer;//L"this is a deom.";
        while (*p) {
            //qDebug() << QString(*p);

            const agg::glyph_cache* glyph = fman->glyph(*p);
            if (glyph) {
                //qDebug() << QString("good");
                fman->init_embedded_adaptors(glyph, x, y);
                ps.concat_path(fman->path_adaptor());
                /*
                cc_pa_type ccpath(fman->path_adaptor());
                cs_cc_pa_type csccpath(ccpath);
                //ct_cs_cc_pa_type ctpath(csccpath, transform);

                //ras.add_path(ctpath);
                ps.concat_path(csccpath);
                */

                x += glyph->advance_x;
                y += glyph->advance_y;
                //qDebug() << QString("%1,%2").arg(x).arg(y);
            } else {
                //qDebug() << QString("bad");
            }
            ++p;
        }
        delete []buffer;


        // 保存属性
        push_attr();
        m_data->as.add(path_attributes(cur_attr(), idx));

        //保存idx值
        path_attributes attr = cur_attr();
        attr.stroke_flag = true;
        attr.fill_flag = false;
        attr.fill_color = agg::rgba8(color->red(), 
                color->green(), color->blue(), color->alpha());
        attr.index = idx;
        m_data->as[m_data->as.size() -1] = attr;
        pop_attr();

        updateBbox();
    }
示例#7
0
int funTar (DataSource *src, int action, int arg, int argc,
            char **argv, TarCallbackFun cb, void *data)
{
  union  tar_buffer buffer;
  int    len;
  int    err;
  int    getheader = 1;
  int    remaining = 0;
  FILE   *outfile = NULL;
  char   fname[BLOCKSIZE];
  int    tarmode;
  time_t tartime;
  struct attr_item *attributes = NULL;
  int    ctr = 0;
  int extracting = 0;


  while (1)
    {
      ctr++;
      len = src->read(src->data, &buffer, BLOCKSIZE, src);
      if (len < 0)
	  error(src->throwError(src->data, &err, src));
      /*
       * Always expect complete blocks to process
       * the tar information.
       */
      if (len != BLOCKSIZE)
        {
          action = TGZ_INVALID; /* force error exit */
          remaining = 0;        /* force I/O cleanup */
        }

      /*
       * If we have to get a tar header
       */
      if (getheader >= 1)
        {
          /*
           * if we met the end of the tar
           * or the end-of-tar block,
           * we are done
           */
          if (len == 0 || buffer.header.name[0] == 0)
            break;

          tarmode = getoct(buffer.header.mode,8);
          tartime = (time_t)getoct(buffer.header.mtime,12);
          if (tarmode == -1 || tartime == (time_t)-1)
            {
              buffer.header.name[0] = 0;
              action = TGZ_INVALID;
            }

          if (getheader == 1)
            {
              strncpy(fname,buffer.header.name,SHORTNAMESIZE);
   	      extracting = 0;
              if (fname[SHORTNAMESIZE-1] != 0)
                  fname[SHORTNAMESIZE] = 0;
            }
          else
            {
              /*
               * The file name is longer than SHORTNAMESIZE
               */
              if (strncmp(fname,buffer.header.name,SHORTNAMESIZE-1) != 0)
                  error("bad long name");
              getheader = 1;
            }

          /*
           * Act according to the type flag
           */
          switch (buffer.header.typeflag)
            {
            case DIRTYPE:
               if (action == TGZ_LIST) {
                 cb(ctr, DIRTYPE, tartime, fname, remaining, data);
                  /* printf(" %s     <dir> %s\n",strtime(&tartime),fname); */
               }
               else if (action == TGZ_EXTRACT)
                {
		    /* makedir(fname); */
 	   	  extracting = 0;
                  push_attr(&attributes,fname,tarmode,tartime);
                }
              break;
            case REGTYPE:
            case AREGTYPE:
              remaining = getoct(buffer.header.size,12);
              if (remaining == -1)
                {
                  action = TGZ_INVALID;
                  break;
                }
              if (action == TGZ_LIST) {
                  cb(ctr, buffer.header.typeflag, tartime, fname, remaining, data);
                 /* printf(" %s %9d %s\n",strtime(&tartime),remaining,fname); */
              }
              else if (action == TGZ_EXTRACT)
                {
		    extracting = matchname(arg,argc,argv,fname);
                }
              getheader = 0;
              break;
            case GNUTYPE_LONGLINK:
            case GNUTYPE_LONGNAME:
              remaining = getoct(buffer.header.size,12);
              if (remaining < 0 || remaining >= BLOCKSIZE)
                {
                  action = TGZ_INVALID;
                  break;
                }
              len = src->read(src->data, fname, BLOCKSIZE, src);
              if (len < 0)
		  error(src->throwError(src->data, &err, src));
              if (fname[BLOCKSIZE-1] != 0 || (int)strlen(fname) > remaining)
                {
                  action = TGZ_INVALID;
                  break;
                }
              getheader = 2;
              break;
            default:
                if (action == TGZ_LIST) {
                    cb(ctr, '\0', tartime, fname, remaining, data);
                    /* printf(" %s     <---> %s\n",strtime(&tartime),fname); */
                }
              break;
            }
        }
      else
        {
          unsigned int bytes = (remaining > BLOCKSIZE) ? BLOCKSIZE : remaining;

	  if(extracting && action == TGZ_EXTRACT)
	      ((TarExtractCallbackFun ) cb)(fname, buffer.buffer, bytes, remaining, data);
          remaining -= bytes;
        }

      if (remaining == 0)
        {
          getheader = 1;
          if(extracting && action == TGZ_EXTRACT) /* Close this file. */
	      ((TarExtractCallbackFun ) cb)(fname, NULL, 0, remaining, data);
	  if (action != TGZ_INVALID)
                push_attr(&attributes,fname,tarmode,tartime);
        }

      /*
       * Abandon if errors are found
       */
      if (action == TGZ_INVALID)
        {
          error("broken archive");
          break;
        }
    }

  /*
   * Restore file modes and time stamps
   */
  restore_attr(&attributes);

  return 0;
}