void pdf_place_rule(PDF pdf,halfword q,scaledpos size,int callback_id) { pdfpos dim; pdfstructure*p= pdf->pstruct; scaledpos pos= pdf->posstruct->pos; if(subtype(q)==box_rule){ pdf_place_form(pdf,q); }else if(subtype(q)==image_rule){ pdf_place_image(pdf,q); }else if(subtype(q)==empty_rule){ }else if(subtype(q)==user_rule){ if(callback_id!=0){ pdf_goto_pagemode(pdf); pdf_puts(pdf,"q\n"); pdf_set_pos_temp(pdf,pos); run_callback(callback_id,"Ndd->",q,size.h,size.v); pdf_puts(pdf,"\nQ\n"); } }else{ pdf_goto_pagemode(pdf); dim.h.m= i64round(size.h*p->k1); dim.h.e= p->pdf.h.e; dim.v.m= i64round(size.v*p->k1); dim.v.e= p->pdf.v.e; pdf_puts(pdf,"q\n"); if(size.v<=one_bp){ pos.v+= i64round(0.5*size.v); pdf_set_pos_temp(pdf,pos); pdf_puts(pdf,"[]0 d 0 J "); print_pdffloat(pdf,dim.v); pdf_puts(pdf," w 0 0 m "); print_pdffloat(pdf,dim.h); pdf_puts(pdf," 0 l S\n"); }else if(size.h<=one_bp){ pos.h+= i64round(0.5*size.h); pdf_set_pos_temp(pdf,pos); pdf_puts(pdf,"[]0 d 0 J "); print_pdffloat(pdf,dim.h); pdf_puts(pdf," w 0 0 m 0 "); print_pdffloat(pdf,dim.v); pdf_puts(pdf," l S\n"); }else{ pdf_set_pos_temp(pdf,pos); pdf_puts(pdf,"0 0 "); print_pdffloat(pdf,dim.h); pdf_out(pdf,' '); print_pdffloat(pdf,dim.v); pdf_puts(pdf," re f\n"); } pdf_puts(pdf,"Q\n"); } }/*:2*/
static int luapdfprint(lua_State * L) { int n; const_lstring st, modestr; ctm_transform_modes literal_mode; st.s = modestr.s = NULL; n = lua_gettop(L); if (!lua_isstring(L, -1)) { luaL_error(L, "no string to print"); } literal_mode = set_origin; if (n == 2) { if (!lua_isstring(L, -2)) { luaL_error(L, "invalid argument for print literal mode"); } else { modestr.s = lua_tolstring(L, -2, &modestr.l); if (modestr.l == 6 && strncmp(modestr.s, "direct", 6) == 0) literal_mode = direct_always; else if (modestr.l == 4 && strncmp(modestr.s, "page", 4) == 0) literal_mode = direct_page; else { luaL_error(L, "invalid argument for print literal mode"); } } } else { if (n != 1) { luaL_error(L, "invalid number of arguments"); } } check_o_mode(static_pdf, "pdf.print()", 1 << OMODE_PDF, true); switch (literal_mode) { case (set_origin): pdf_goto_pagemode(static_pdf); pdf_set_pos(static_pdf, static_pdf->posstruct->pos); (void) calc_pdfpos(static_pdf->pstruct, static_pdf->posstruct->pos); break; case (direct_page): pdf_goto_pagemode(static_pdf); (void) calc_pdfpos(static_pdf->pstruct, static_pdf->posstruct->pos); break; case (direct_always): pdf_end_string_nl(static_pdf); break; default: assert(0); } st.s = lua_tolstring(L, n, &st.l); pdf_out_block(static_pdf, st.s, st.l); return 0; }
static int luapdfprint(lua_State * L) { int n; const_lstring st; const char *modestr_s; ctm_transform_modes literal_mode; st.s = modestr_s = NULL; n = lua_gettop(L); if (!lua_isstring(L, -1)) { /* or number */ luaL_error(L, "no string to print"); } literal_mode = set_origin; if (n == 2) { if (lua_type(L,-2) != LUA_TSTRING) { luaL_error(L, "invalid first argument for print literal mode"); } else { modestr_s = lua_tostring(L, -2); if (lua_key_eq(modestr_s,direct)) literal_mode = direct_always; else if (lua_key_eq(modestr_s,page)) literal_mode = direct_page; else { luaL_error(L, "invalid first argument for print literal mode"); } } } else if (n != 1) { luaL_error(L, "invalid number of arguments"); } check_o_mode(static_pdf, "pdf.print()", 1 << OMODE_PDF, true); switch (literal_mode) { case (set_origin): pdf_goto_pagemode(static_pdf); pdf_set_pos(static_pdf, static_pdf->posstruct->pos); (void) calc_pdfpos(static_pdf->pstruct, static_pdf->posstruct->pos); break; case (direct_page): pdf_goto_pagemode(static_pdf); (void) calc_pdfpos(static_pdf->pstruct, static_pdf->posstruct->pos); break; case (direct_always): pdf_end_string_nl(static_pdf); break; default: assert(0); } st.s = lua_tolstring(L, n, &st.l); pdf_out_block(static_pdf, st.s, st.l); return 0; }
void place_img(PDF pdf, image_dict * idict, scaled_whd dim, int transform) { /*tex A transformation matrix: */ double a[6]; double xoff, yoff, tmp; pdfstructure *p = pdf->pstruct; scaledpos pos = pdf->posstruct->pos; /*tex The number of digits after the decimal point: */ int r; int k; scaledpos tmppos; pdffloat cm[6]; int groupref; a[0] = a[3] = 1.0e6; a[1] = a[2] = 0; if (img_type(idict) == IMG_TYPE_PDF || img_type(idict) == IMG_TYPE_PDFMEMSTREAM || img_type(idict) == IMG_TYPE_PDFSTREAM) { a[0] /= (double) img_xsize(idict); a[3] /= (double) img_ysize(idict); xoff = (double) img_xorig(idict) / (double) img_xsize(idict); yoff = (double) img_yorig(idict) / (double) img_ysize(idict); r = 6; } else { if (img_type(idict) == IMG_TYPE_PNG) { groupref = img_group_ref(idict); if ((groupref > 0) && (pdf->img_page_group_val == 0)) pdf->img_page_group_val = groupref; } a[0] /= (double) one_hundred_bp; a[3] = a[0]; xoff = yoff = 0; r = 4; } if ((transform & 7) > 3) { /*tex Mirror cases: */ a[0] *= -1; xoff *= -1; } switch ((transform + img_rotation(idict)) & 3) { case 0: /*tex No transform. */ break; case 1: /*tex rotation over 90 degrees (counterclockwise) */ a[1] = a[0]; a[2] = -a[3]; a[3] = a[0] = 0; tmp = yoff; yoff = xoff; xoff = -tmp; break; case 2: /*tex rotation over 180 degrees (counterclockwise) */ a[0] *= -1; a[3] *= -1; xoff *= -1; yoff *= -1; break; case 3: /*tex rotation over 270 degrees (counterclockwise) */ a[1] = -a[0]; a[2] = a[3]; a[3] = a[0] = 0; tmp = yoff; yoff = -xoff; xoff = tmp; break; default:; } xoff *= (double) dim.wd; yoff *= (double) (dim.ht + dim.dp); a[0] *= (double) dim.wd; a[1] *= (double) (dim.ht + dim.dp); a[2] *= (double) dim.wd; a[3] *= (double) (dim.ht + dim.dp); a[4] = (double) pos.h - xoff; a[5] = (double) pos.v - yoff; k = transform + img_rotation(idict); if ((transform & 7) > 3) k++; switch (k & 3) { case 0: /*tex No transform */ break; case 1: /*tex rotation over 90 degrees (counterclockwise) */ a[4] += (double) dim.wd; break; case 2: /*tex rotation over 180 degrees (counterclockwise) */ a[4] += (double) dim.wd; a[5] += (double) (dim.ht + dim.dp); break; case 3: /*tex rotation over 270 degrees (counterclockwise) */ a[5] += (double) (dim.ht + dim.dp); break; default:; } setpdffloat(cm[0], i64round(a[0]), r); setpdffloat(cm[1], i64round(a[1]), r); setpdffloat(cm[2], i64round(a[2]), r); setpdffloat(cm[3], i64round(a[3]), r); tmppos.h = round(a[4]); tmppos.v = round(a[5]); pdf_goto_pagemode(pdf); (void) calc_pdfpos(p, tmppos); cm[4] = p->cm[4]; cm[5] = p->cm[5]; if (pdf->img_page_group_val == 0) pdf->img_page_group_val = img_group_ref(idict); pdf_puts(pdf, "q\n"); pdf_print_cm(pdf, cm); pdf_puts(pdf, "/Im"); pdf_print_int(pdf, img_index(idict)); pdf_print_resname_prefix(pdf); pdf_puts(pdf, " Do\nQ\n"); addto_page_resources(pdf, obj_type_ximage, img_objnum(idict)); if (img_state(idict) < DICT_OUTIMG) img_state(idict) = DICT_OUTIMG; }