Пример #1
0
int pdf_add_content(lua_State *L) {
  const char* input = luaL_checkstring(L, 1);
  int input_l = lua_rawlen(L, 1);
  texpdf_graphics_mode(p); /* Don't be mid-string! */
  texpdf_doc_add_page_content(p, " ", 1);
  texpdf_doc_add_page_content(p, input, input_l);
  texpdf_doc_add_page_content(p, " ", 1);
  return 0;
}
Пример #2
0
int pdf_transform(lua_State *L) {
  pdf_tmatrix matrix;
  double a = luaL_checknumber(L, 1);
  double b = luaL_checknumber(L, 2);
  double c = luaL_checknumber(L, 3);
  double d = luaL_checknumber(L, 4);
  double e = luaL_checknumber(L, 5);
  double f = luaL_checknumber(L, 6);
  texpdf_graphics_mode(p);
  pdf_setmatrix(&matrix, a,b,c,d,e,f);
  texpdf_dev_concat(p, &matrix);
  return 0;
}
Пример #3
0
/*
 * mask == 0 means stroking color, mask == 0x20 nonstroking color
 *
 * force == 1 means that operators will be generated even if
 *   the color is the same as the current graphics state color
 */
void
texpdf_dev_set_color (pdf_doc *p, const pdf_color *color, char mask, int force)
{
  int len;

  pdf_gstate *gs  = m_stack_top(&gs_stack);
  pdf_color *current = mask ? &gs->fillcolor : &gs->strokecolor;

  ASSERT(texpdf_color_is_valid(color));

  if (!(texpdf_dev_get_param(PDF_DEV_PARAM_COLORMODE) &&
	(force || texpdf_color_compare(color, current))))
    /* If "color" is already the current color, then do nothing
     * unless a color operator is forced
     */
    return;

  texpdf_graphics_mode(p);
  len = texpdf_color_to_string(color, fmt_buf, mask);
  fmt_buf[len++] = ' ';
  switch (texpdf_color_type(color)) {
  case  PDF_COLORSPACE_TYPE_RGB:
    fmt_buf[len++] = 'R' | mask;
    fmt_buf[len++] = 'G' | mask;
    break;
  case  PDF_COLORSPACE_TYPE_CMYK:
    fmt_buf[len++] = 'K' | mask;
    break;
  case  PDF_COLORSPACE_TYPE_GRAY:
    fmt_buf[len++] = 'G' | mask;
    break;
  default: /* already verified the given color */
    break;
  }
  texpdf_doc_add_page_content(p, fmt_buf, len);  /* op: RG K G rg k g etc. */

  texpdf_color_copycolor(current, color);
}
Пример #4
0
int pdf_grestore(lua_State *L) { texpdf_graphics_mode(p); texpdf_dev_grestore(p); return 0; }
Пример #5
0
/* FIXME */
static int
texpdf_dev__flushpath (pdf_doc *p, pdf_path  *pa,
                    char       opchr,
                    int        rule,
                    int        ignore_rule)
{
  pa_elem   *pe, *pe1;
  char      *b      = fmt_buf;
  long       b_len  = FORMAT_BUFF_LEN;
  pdf_rect   r; /* FIXME */
  pdf_coord *pt;
  int        n_pts, n_seg;
  int        len = 0;
  int        isclip = 0;
  int        isrect, i, j;

  ASSERT(pa && PT_OP_VALID(opchr));

  isclip = (opchr == 'W') ? 1 : 0;

  if (PA_LENGTH(pa) <= 0 && path_added == 0)
    return 0;

  path_added = 0;
  texpdf_graphics_mode(p);
  isrect = pdf_path__isarect(pa, ignore_rule); 
  if (isrect) {
    pe  = &(pa->path[0]);
    pe1 = &(pa->path[2]);

    r.llx = pe->p[0].x;
    r.lly = pe->p[0].y;
    r.urx = pe1->p[0].x - pe->p[0].x; /* width...  */
    r.ury = pe1->p[0].y - pe->p[0].y; /* height... */

    b[len++] = ' ';
    len += pdf_sprint_rect(b + len, &r);
    b[len++] = ' ';
    b[len++] = 'r';
    b[len++] = 'e';
    texpdf_doc_add_page_content(p, b, len);  /* op: re */
    len = 0;
  } else {
    n_seg = PA_LENGTH(pa);
    for (i = 0, len = 0, pe = &pa->path[0];
         i < n_seg; pe++, i++) {
      n_pts = PE_N_PTS(pe);
      for (j = 0, pt = &pe->p[0];
           j < n_pts; j++, pt++) {
        b[len++] = ' ';
        len += pdf_sprint_coord(b + len, pt);
      }
      b[len++] = ' ';
      b[len++] = PE_OPCHR(pe);
      if (len + 128 > b_len) {
        texpdf_doc_add_page_content(p, b, len);  /* op: m l c v y h */
	len = 0;
      }
    }
    if (len > 0) {
      texpdf_doc_add_page_content(p, b, len);  /* op: m l c v y h */
      len = 0;
    }
  }

  b[len++] = ' ';
  b[len++] = opchr;
  if (rule == PDF_FILL_RULE_EVENODD)
    b[len++] = '*';
  if (isclip) {
    b[len++] = ' '; b[len++] = 'n';
  }

  texpdf_doc_add_page_content(p, b, len);  /* op: f F s S b B W f* F* s* S* b* B* W* */

  return 0;
}
Пример #6
0
/* rectfill, rectstroke, rectclip, recteoclip
 *
 * Draw isolated rectangle without actually doing
 * gsave/grestore operation.
 * 
 * TODO:
 *  linestyle, fill-opacity, stroke-opacity,....
 *  As this routine draw a single graphics object
 *  each time, there should be options for specifying
 *  various drawing styles, which might inherite
 *  current graphcs state parameter.
 */ 
static int
texpdf_dev__rectshape (pdf_doc *doc, const pdf_rect    *r,
                    const pdf_tmatrix *M,
                    char               opchr
                   )
{
  char     *buf = fmt_buf;
  int       len = 0;
  int       isclip = 0;
  pdf_coord p;
  double    wd, ht;

  ASSERT(r && PT_OP_VALID(opchr));

  isclip = (opchr == 'W' || opchr == ' ') ? 1 : 0;

  /* disallow matrix for clipping.
   * q ... clip Q does nothing and
   * n M cm ... clip n alter CTM.
   */
  if (M && (isclip ||
            !INVERTIBLE_MATRIX(M)))
    return -1;

  texpdf_graphics_mode(doc);

  buf[len++] = ' ';
  if (!isclip) {
    buf[len++] = 'q';
    if (M) {
      buf[len++] = ' ';
      len += texpdf_sprint_matrix(buf + len, M);
      buf[len++] = ' ';
      buf[len++] = 'c'; buf[len++] = 'm';
    }
    buf[len++] = ' ';
  }
  buf[len++] = 'n';

  p.x = r->llx; p.y = r->lly;
  wd  = r->urx - r->llx;
  ht  = r->ury - r->lly;
  buf[len++] = ' ';
  len += pdf_sprint_coord (buf + len, &p);
  buf[len++] = ' ';
  len += pdf_sprint_length(buf + len, wd);
  buf[len++] = ' ';
  len += pdf_sprint_length(buf + len, ht);
  buf[len++] = ' ';
  buf[len++] = 'r'; buf[len++] = 'e';

  if (opchr != ' ') {
    buf[len++] = ' ';
    buf[len++] = opchr;

    buf[len++] = ' ';
    buf[len++] = isclip ? 'n' : 'Q';
  }

  texpdf_doc_add_page_content(doc, buf, len);  /* op: q cm n re Q */

  return 0;
}