Esempio n. 1
0
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;
}
Esempio n. 2
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;
}