Example #1
0
// --------------------------------------------------
status_t 
DrawShape::IterateLineTo(int32 lineCount, BPoint *linePoints)
{
	REPORT(kDebug, 0, "IterateLineTo %d", (int)lineCount);
	BPoint *p = linePoints;
	for (int32 i = 0; i < lineCount; i++) {
		REPORT(kDebug, 0, "(%f, %f) ", p->x, p->y);

		if (TransformPath()) {
			fSubPath.AddPoint(*p);
		} else {
			PDF_lineto(Pdf(), tx(p->x), ty(p->y));
		}
		fCurrentPoint = *p;
		p++;
	}
	return B_OK;
}
Example #2
0
static int mkline(gfxline_t*line, PDF*p, double mx, double my, double scale, char fill)
{
    double x=0,y=0;
    char first = 1;
    int ret = 0;
    gfxline_t*free_line = 0;
    if(fill) {
	line = gfxline_restitch(gfxline_clone(line));
	free_line = line;
    }
    while(line) {
	if(line->type == gfx_moveTo && (x!=line->x || y!=line->y || first)) {
	    first = 0;
	    PDF_moveto(p, line->x*scale+mx, line->y*scale+my);
	} else if(line->type == gfx_lineTo) {
	    PDF_lineto(p, line->x*scale+mx, line->y*scale+my);
	    ret = 1;
	} else {
	    /* when converting a quadratic bezier to a cubic bezier, the
	       two new control points are both 2/3 the way from the
	       endpoints to the old control point */
	    double c1x = (x + line->sx*2)/3;
	    double c1y = (y + line->sy*2)/3;
	    double c2x = (line->x + line->sx*2)/3;
	    double c2y = (line->y + line->sy*2)/3;
	    PDF_curveto(p, c1x*scale+mx, c1y*scale+my, 
		           c2x*scale+mx, c2y*scale+my, 
			   line->x*scale+mx, line->y*scale+my);
	    ret = 1;
	}
	x = line->x;
	y = line->y;
	line = line->next;
    }
    if(free_line)
	gfxline_free(free_line);
    return ret;
}
Example #3
0
int
main(void)
{
    /* This is where the data files are. Adjust as necessary.*/
    const char * searchpath = "../data";
    const char *targetname = "x5target.pdf";

    PDF *p;
    char optlist[1024];

    int font, proxy;
    double linewidth=2;
    double width, height;

    /* create a new PDFlib object */
    if ((p = PDF_new()) == (PDF *) 0) {
        printf("Couldn't create PDFlib object (out of memory)!\n");
        return(2);
    }

    PDF_TRY(p) {
        /* This means we must check return values of load_font() etc. */
        PDF_set_parameter(p, "errorpolicy", "return");

        PDF_set_parameter(p, "SearchPath", searchpath);

        if (PDF_begin_document(p, "starter_pdfx5g.pdf", 0, "pdfx=PDF/X-5g")
                == -1) {
            printf("Error: %s\n", PDF_get_errmsg(p));
            PDF_delete(p);
            return(2);
        }

        PDF_set_info(p, "Creator", "PDFlib starter sample");
        PDF_set_info(p, "Title", "starter_pdfx5g");

        /* Open the output intent profile */
        if (PDF_load_iccprofile(p, "ISOcoated.icc", 0,
                "usage=outputintent") == -1)
        {
            printf("Error: %s\n", PDF_get_errmsg(p));
            printf("Please install the ICC profile package from "
                   "www.pdflib.com to run the PDF/X-5g starter sample.\n");
            PDF_delete(p);
            return(2);
        }

        /* Font embedding is required for PDF/X */
        font = PDF_load_font(p, "LuciduxSans-Oblique", 0,
                "winansi", "embedding");

        if (font == -1) {
            printf("Error: %s\n", PDF_get_errmsg(p));
            PDF_delete(p);
            return(2);
        }

        /* Create a template which will serve as proxy. The referenced
         * page (the target) is attached to the proxy.
	 * The template width and height will be determined automatically,
	 * so we don't have to supply them.
         */
        sprintf(optlist, "reference={filename=%s pagenumber=1}", targetname);
        proxy = PDF_begin_template_ext(p, 0, 0, optlist);

        if (proxy == -1)
        {
            printf("Error: %s\n", PDF_get_errmsg(p));
            PDF_delete(p);
            return(2);
        }

	width  = PDF_info_image(p, proxy, "imagewidth", "");
	height = PDF_info_image(p, proxy, "imageheight", "");

        /* Draw a crossed-out rectangle to visualize the proxy.
         * Attention: if we use the exact corner points, one half of the
         * linewidth would end up outside the template, and therefore be
         * clipped.
         */
        PDF_setlinewidth(p, linewidth);
        PDF_moveto(p, linewidth/2, linewidth/2);
        PDF_lineto(p, width-linewidth/2, linewidth/2);
        PDF_lineto(p, width-linewidth/2, height-linewidth/2);
        PDF_lineto(p, linewidth/2, height-linewidth/2);
        PDF_lineto(p, linewidth/2, linewidth/2);
        PDF_lineto(p, width-linewidth/2, height-linewidth/2);

        PDF_moveto(p, width-linewidth/2, linewidth/2);
        PDF_lineto(p, linewidth/2, height-linewidth/2);
        PDF_stroke(p);

        PDF_setfont(p, font, 24);

        sprintf(optlist, "fitmethod=auto position=center boxsize={%f %f}",
            width, height);
        PDF_fit_textline(p, "Proxy replaces target here", 0,
            0, 0, optlist);

	PDF_end_template_ext(p, 0, 0);


        /* Create the page */
        PDF_begin_page_ext(p, 595, 842, "");

        PDF_setfont(p, font, 18);

        PDF_fit_textline(p,
            "PDF/X-5 starter sample with reference to an external page", 0,
            50, 700, "");

        /* Place the proxy on the page */
        PDF_fit_image(p, proxy, 50, 50, "boxsize={500 500} fitmethod=meet");

        PDF_end_page_ext(p, "");
        PDF_end_document(p, "");
    }

    PDF_CATCH(p) {
        printf("PDFlib exception occurred:\n");
        printf("[%d] %s: %s\n",
            PDF_get_errnum(p), PDF_get_apiname(p), PDF_get_errmsg(p));
        PDF_delete(p);
        return(2);
    }

    PDF_delete(p);

    return 0;
}
Example #4
0
/*
** cg_cut_lines()
** Write the cut lines in a page.
*/
yerr_t cg_cut_lines(cg_t *carta, cg_deck_t *deck, cg_back_t back)
{
  int i;
  double color_luminance = 0;

  /* hidden-ditch */
  PDF_save(carta->p);
  if ((back == BACK_NO && deck->ditch_odd) ||
      (back != BACK_NO && deck->ditch_even))
    {
      unsigned int hex1, hex2, hex3;
      double col1, col2, col3;
      char *used_color = (back == BACK_NO) ? deck->ditch_odd : deck->ditch_even;

      sscanf(used_color, "#%02x%02x%02x", &hex1, &hex2, &hex3);
      col1 = (double)hex1 / 255;
      col2 = (double)hex2 / 255;
      col3 = (double)hex3 / 255;
      color_luminance = (col1 * LUMINANCE_RED) + (col2 * LUMINANCE_GREEN) +
	(col3 * LUMINANCE_BLUE);
      PDF_setcolor(carta->p, "fill", "rgb", col1, col2, col3, 0.0);
      PDF_rect(carta->p, YVAL2PT(deck->paper_margin_w) / 2.0,
	       YVAL2PT(deck->paper_margin_h) / 2.0,
	       YVAL2PT(deck->paper_width) - YVAL2PT(deck->paper_margin_w),
	       YVAL2PT(deck->paper_height) - YVAL2PT(deck->paper_margin_h));
      PDF_fill(carta->p);
    }
  PDF_restore(carta->p);

  /* external cut lines */
  PDF_save(carta->p);
  PDF_setcolor(carta->p, "fillstroke", "rgb", 0.0, 0.0, 0.0, 0.0);
  for (i = 0; i <= deck->cols; ++i)
    {
      double x, y;

      if (i == deck->cols && YVAL2PT(deck->space_width))
	break ;
      x = YVAL2PT(deck->paper_margin_w) + (i * YVAL2PT(deck->card_width)) +
	(i * YVAL2PT(deck->space_width));
      if (back == BACK_HEIGHT || back == BACK_WIDTH)
	x = YVAL2PT(deck->paper_width) - YVAL2PT(deck->paper_margin_w) -
	  (i * YVAL2PT(deck->card_width)) - (i * YVAL2PT(deck->space_width));
      y = 0.0;
      PDF_moveto(carta->p, x, y);
      y = YVAL2PT(deck->paper_margin_h) / 2.0;
      PDF_lineto(carta->p, x, y);
      y = YVAL2PT(deck->paper_height);
      PDF_moveto(carta->p, x, y);
      y = YVAL2PT(deck->paper_height) -
	(YVAL2PT(deck->paper_margin_h) / 2.0);
      PDF_lineto(carta->p, x, y);
      /* second cut line - space between cards */
      if (i < deck->cols && YVAL2PT(deck->space_width))
	{
	  if (back == BACK_HEIGHT || back == BACK_WIDTH)
	    x -= YVAL2PT(deck->card_width);
	  else
	    x += YVAL2PT(deck->card_width);
	  y = 0.0;
	  PDF_moveto(carta->p, x, y);
	  y = YVAL2PT(deck->paper_margin_h) / 2.0;
	  PDF_lineto(carta->p, x, y);
	  y = YVAL2PT(deck->paper_height);
	  PDF_moveto(carta->p, x, y);
	  y = YVAL2PT(deck->paper_height) -
	    (YVAL2PT(deck->paper_margin_h) / 2.0);
	  PDF_lineto(carta->p, x, y);
	}
    }
  for (i = 0; i <= deck->rows; ++i)
    {
      double x, y;

      if (i == deck->rows && YVAL2PT(deck->space_height))
	break ;
      x = 0.0;
      y = YVAL2PT(deck->paper_margin_h) + (i * YVAL2PT(deck->card_height)) +
	(i * YVAL2PT(deck->space_height));
      PDF_moveto(carta->p, x, y);
      x = YVAL2PT(deck->paper_margin_w) / 2.0;
      PDF_lineto(carta->p, x, y);
      x = YVAL2PT(deck->paper_width);
      PDF_moveto(carta->p, x, y);
      x = YVAL2PT(deck->paper_width) -
	(YVAL2PT(deck->paper_margin_w) / 2.0);
      PDF_lineto(carta->p, x, y);
      /* second cut line - space between cards */
      if (i < deck->rows && YVAL2PT(deck->space_height))
	{
	  x = 0.0;
	  y += YVAL2PT(deck->card_height);
	  PDF_moveto(carta->p, x, y);
	  x = YVAL2PT(deck->paper_margin_w) / 2.0;
	  PDF_lineto(carta->p, x, y);
	  x = YVAL2PT(deck->paper_width);
	  PDF_moveto(carta->p, x, y);
	  x = YVAL2PT(deck->paper_width) -
	    (YVAL2PT(deck->paper_margin_w) / 2.0);
	  PDF_lineto(carta->p, x, y);
	}
    }
  PDF_stroke(carta->p);
  PDF_restore(carta->p);

  /* internal cut lines */
  PDF_save(carta->p);
  if (color_luminance >= LUMINANCE_THRESHOLD)
    PDF_setcolor(carta->p, "fillstroke", "rgb", 0.0, 0.0, 0.0, 0.0);
  else
    PDF_setcolor(carta->p, "fillstroke", "rgb", 1.0, 1.0, 1.0, 0.0);
  for (i = 0; i <= deck->cols; ++i)
    {
      double x, y;

      if (i == deck->cols && YVAL2PT(deck->space_width))
	break ;
      x = YVAL2PT(deck->paper_margin_w) + (i * YVAL2PT(deck->card_width)) +
	(i * YVAL2PT(deck->space_width));
      if (back == BACK_HEIGHT || back == BACK_WIDTH)
	x = YVAL2PT(deck->paper_width) - YVAL2PT(deck->paper_margin_w) -
	  (i * YVAL2PT(deck->card_width)) - (i * YVAL2PT(deck->space_width));
      y = YVAL2PT(deck->paper_margin_h) / 2.0;
      PDF_moveto(carta->p, x, y);
      y = YVAL2PT(deck->paper_margin_h) * 2.0 / 3.0;
      PDF_lineto(carta->p, x, y);
      y = YVAL2PT(deck->paper_height) -
	(YVAL2PT(deck->paper_margin_h) / 2.0);
      PDF_moveto(carta->p, x, y);
      y = YVAL2PT(deck->paper_height) -
	(YVAL2PT(deck->paper_margin_h) * 2.0 / 3.0);
      PDF_lineto(carta->p, x, y);
      /* second cut line - space between cards */
      if (i < deck->cols && YVAL2PT(deck->space_width))
	{
	  if (back == BACK_HEIGHT || back == BACK_WIDTH)
	    x -= YVAL2PT(deck->card_width);
	  else
	    x += YVAL2PT(deck->card_width);
	  y = YVAL2PT(deck->paper_margin_h) / 2.0;
	  PDF_moveto(carta->p, x, y);
	  y = YVAL2PT(deck->paper_margin_h) * 2.0 / 3.0;
	  PDF_lineto(carta->p, x, y);
	  y = YVAL2PT(deck->paper_height) -
	    (YVAL2PT(deck->paper_margin_h) / 2.0);
	  PDF_moveto(carta->p, x, y);
	  y = YVAL2PT(deck->paper_height) -
	    (YVAL2PT(deck->paper_margin_h) * 2.0 / 3.0);
	  PDF_lineto(carta->p, x, y);
	}
    }
  for (i = 0; i <= deck->rows; ++i)
    {
      double x, y;

      if (i == deck->rows && YVAL2PT(deck->space_height))
	break ;
      x = YVAL2PT(deck->paper_margin_w) / 2.0;
      y = YVAL2PT(deck->paper_margin_h) + (i * YVAL2PT(deck->card_height)) +
	(i * YVAL2PT(deck->space_height));
      PDF_moveto(carta->p, x, y);
      x = YVAL2PT(deck->paper_margin_w) * 2.0 / 3.0;
      PDF_lineto(carta->p, x, y);
      x = YVAL2PT(deck->paper_width) - (YVAL2PT(deck->paper_margin_w) / 2.0);
      PDF_moveto(carta->p, x, y);
      x = YVAL2PT(deck->paper_width) -
	(YVAL2PT(deck->paper_margin_w) * 2.0 / 3.0);
      PDF_lineto(carta->p, x, y);
      /* second cut line - space between cards */
      if (i < deck->rows && YVAL2PT(deck->space_height))
	{
	  x = YVAL2PT(deck->paper_margin_w) / 2.0;
	  y += YVAL2PT(deck->card_height);
	  PDF_moveto(carta->p, x, y);
	  x = YVAL2PT(deck->paper_margin_w) * 2.0 / 3.0;
	  PDF_lineto(carta->p, x, y);
	  x = YVAL2PT(deck->paper_width) -
	    (YVAL2PT(deck->paper_margin_w) / 2.0);
	  PDF_moveto(carta->p, x, y);
	  x = YVAL2PT(deck->paper_width) -
	    (YVAL2PT(deck->paper_margin_w) * 2.0 / 3.0);
	  PDF_lineto(carta->p, x, y);
	}
    }
  PDF_stroke(carta->p);
  PDF_restore(carta->p);
  return (YENOERR);
}
Example #5
0
int
main(void)
{
    PDF		*p;
    float	alpha;
    time_t	timer;
    struct tm	ltime;

    /* create a new PDFlib object */
    if ((p = PDF_new()) == (PDF *) 0)
    {
        printf("Couldn't create PDFlib object (out of memory)!\n");
        return(2);
    }

    PDF_TRY(p) {
	/* open new PDF file */
	if (PDF_open_file(p, "pdfclock.pdf") == -1) {
	    printf("Error: %s\n", PDF_get_errmsg(p));
	    return(2);
	}

	/* This line is required to avoid problems on Japanese systems */
	PDF_set_parameter(p, "hypertextencoding", "host");

	PDF_set_info(p, "Creator", "pdfclock.c");
	PDF_set_info(p, "Author", "Thomas Merz");
	PDF_set_info(p, "Title", "PDF clock (C)");

	PDF_begin_page(p, (float) (2 * (RADIUS + MARGIN)),
			  (float) (2 * (RADIUS + MARGIN)));
	
	PDF_translate(p, RADIUS + MARGIN, RADIUS + MARGIN);
	PDF_setcolor(p, "fillstroke", "rgb", 0, 0, 1, 0);
	PDF_save(p);

	/* minute strokes */
	PDF_setlinewidth(p, 2);
	for (alpha = 0; alpha < 360; alpha += 6)
	{
	    PDF_rotate(p, 6);
	    PDF_moveto(p, RADIUS, 0);
	    PDF_lineto(p, (float) (RADIUS-MARGIN/3), 0);
	    PDF_stroke(p);
	}

	PDF_restore(p);
	PDF_save(p);

	/* 5 minute strokes */
	PDF_setlinewidth(p, 3);
	for (alpha = 0; alpha < 360; alpha += 30)
	{
	    PDF_rotate(p, 30);
	    PDF_moveto(p, RADIUS, 0);
	    PDF_lineto(p, RADIUS-MARGIN, 0);
	    PDF_stroke(p);
	}

	time(&timer);
	ltime = *localtime(&timer);

	/* draw hour hand */
	PDF_save(p);
	PDF_rotate(p, 
		(float)(-((ltime.tm_min/60.0) + ltime.tm_hour - 3.0) * 30.0));
	PDF_moveto(p, -RADIUS/10, -RADIUS/20);
	PDF_lineto(p, RADIUS/2, 0);
	PDF_lineto(p, -RADIUS/10, RADIUS/20);
	PDF_closepath(p);
	PDF_fill(p);
	PDF_restore(p);

	/* draw minute hand */
	PDF_save(p);
	PDF_rotate(p,
		(float) (-((ltime.tm_sec/60.0) + ltime.tm_min - 15.0) * 6.0));
	PDF_moveto(p, -RADIUS/10, -RADIUS/20);
	PDF_lineto(p, RADIUS * 0.8f, 0);
	PDF_lineto(p, -RADIUS/10, RADIUS/20);
	PDF_closepath(p);
	PDF_fill(p);
	PDF_restore(p);

	/* draw second hand */
	PDF_setcolor(p, "fillstroke", "rgb", 1, 0, 0, 0);
	PDF_setlinewidth(p, 2);
	PDF_save(p);
	PDF_rotate(p, (float) -((ltime.tm_sec - 15.0) * 6.0));
	PDF_moveto(p, -RADIUS/5, 0);
	PDF_lineto(p, RADIUS, 0);
	PDF_stroke(p);
	PDF_restore(p);

	/* draw little circle at center */
	PDF_circle(p, 0, 0, (float) RADIUS/30);
	PDF_fill(p);

	PDF_restore(p);

	PDF_end_page(p);

	PDF_close(p);
    }

    PDF_CATCH(p) {
        printf("PDFlib exception occurred in pdfclock sample:\n");
        printf("[%d] %s: %s\n",
	    PDF_get_errnum(p), PDF_get_apiname(p), PDF_get_errmsg(p));
        PDF_delete(p);
        return(2);
    }

    PDF_delete(p);				/* delete the PDFlib object */

    return 0;
}
Example #6
0
int
main(void)
{

    /* This is where the data files are. Adjust as necessary. */
    const char* searchpath = "../data";

    PDF * p;
    const char* imagefile = "nesrin.jpg";
    char* optlist;
    int font, image;

    /* create a new PDFlib object */
    if ((p = PDF_new()) == (PDF *) 0) {
        printf("Couldn't create PDFlib object (out of memory)!\n");
        return(2);
    }

    PDF_TRY(p) {
        /* This means we must check return values of load_font() etc. */
        PDF_set_parameter(p, "errorpolicy", "return");

        PDF_set_parameter(p, "SearchPath", searchpath);

        if (PDF_begin_document(p, "starter_basic.pdf", 0, "") == -1) {
            printf("Error: %s\n", PDF_get_errmsg(p));
            PDF_delete(p);
            return(2);
        }

        PDF_set_info(p, "Creator", "PDFlib starter sample");
        PDF_set_info(p, "Title", "starter_basic");

        /* We load the image before the first page, and use it
         * on all pages
         */
        image = PDF_load_image(p, "auto", imagefile, 0, "");

        if (image == -1) {
            printf("Error: %s\n", PDF_get_errmsg(p));
            PDF_delete(p);
            return(2);
        }

        /* Page 1 */
        PDF_begin_page_ext(p, 595, 842, "");

        font = PDF_load_font(p, "Helvetica-Bold", 0, "winansi", "");

        if (font == -1) {
            printf("Error: %s\n", PDF_get_errmsg(p));
            PDF_delete(p);
            return(2);
        }

        PDF_setfont(p, font, 24);

        PDF_set_text_pos(p, 50, 700);
        PDF_show(p, "Hello world!");

        PDF_fit_image(p, image, (float) 0.0, (float) 0.0, "scale=0.25");

        PDF_end_page_ext(p, "");

        /* Page 2 */
        PDF_begin_page_ext(p, 595, 842, "");

        /* red rectangle */
        PDF_setcolor(p, "fill", "rgb", 1.0, 0.0, 0.0, 0.0);
        PDF_rect(p, 200, 200, 250, 150);
        PDF_fill(p);

        /* blue circle */
        PDF_setcolor(p, "fill", "rgb", 0.0, 0.0, 1.0, 0.0);
        PDF_arc(p, 400, 600, 100, 0, 360);
        PDF_fill(p);

        /* thick gray line */
        PDF_setcolor(p, "stroke", "gray", 0.5, 0.0, 0.0, 0.0);
        PDF_setlinewidth(p, 10);
        PDF_moveto(p, 100, 500);
        PDF_lineto(p, 300, 700);
        PDF_stroke(p);

        /* Using the same image handle means the data will be copied
         * to the PDF only once, which saves space.
         */
        PDF_fit_image(p, image, 150.0, 25.0, "scale=0.25");
        PDF_end_page_ext(p, "");

        /* Page 3 */
        PDF_begin_page_ext(p, 595, 842, "");

        /* Fit the image to a box of predefined size (without distortion) */
        optlist =
        "boxsize={400 400} position={center} fitmethod=meet";

        PDF_fit_image(p, image, 100, 200, optlist);

        PDF_end_page_ext(p, "");

        PDF_close_image(p, image);
        PDF_end_document(p, "");
    }

    PDF_CATCH(p) {
        printf("PDFlib exception occurred:\n");
        printf("[%d] %s: %s\n",
            PDF_get_errnum(p), PDF_get_apiname(p), PDF_get_errmsg(p));
        PDF_delete(p);
        return(2);
    }

    PDF_delete(p);

    return 0;
}