示例#1
0
static void setup_image(PDF pdf, image * a, wrtype_e writetype)
{
    image_dict *ad;
    if (a == NULL)
        luaL_error(Luas, "no valid image passed"); /* todo, also check in caller */
    ad = img_dict(a);
    check_o_mode(pdf, wrtype_s[writetype], 1 << OMODE_PDF, false);
    read_scale_img(a);
    if (img_objnum(ad) == 0) { /* latest needed just before out_img() */
        pdf->ximage_count++;
        img_objnum(ad) = pdf_create_obj(pdf, obj_type_ximage, pdf->ximage_count);
        img_index(ad) = pdf->ximage_count;
        idict_to_array(ad); /* from now on ad is read-only */
        obj_data_ptr(pdf, pdf->obj_ptr) = img_index(ad);
    }
}
示例#2
0
static void setup_image(PDF pdf, image * a, wrtype_e writetype)
{
    image_dict *ad;
    assert(a != NULL);
    ad = img_dict(a);
    check_o_mode(pdf, wrtype_s[writetype], 1 << OMODE_PDF, false);
    /* flush_str(last_tex_string); *//* ?? */
    read_scale_img(a);
    if (img_objnum(ad) == 0) {  /* latest needed just before out_img() */
        pdf->ximage_count++;
        img_objnum(ad) =
            pdf_create_obj(pdf, obj_type_ximage, pdf->ximage_count);
        img_index(ad) = pdf->ximage_count;
        idict_to_array(ad);     /* now ad is read-only */
        obj_data_ptr(pdf, pdf->obj_ptr) = img_index(ad);
    }
}
示例#3
0
static image_dict *read_image(char *file_name, int page_num, char *page_name, int colorspace, int page_box, char *user_password, char *owner_password, char *visible_filename)
{
    image *a = new_image();
    image_dict *idict = img_dict(a) = new_image_dict();
    static_pdf->ximage_count++;
    img_objnum(idict) = pdf_create_obj(static_pdf, obj_type_ximage, static_pdf->ximage_count);
    img_index(idict) = static_pdf->ximage_count;
    set_obj_data_ptr(static_pdf, img_objnum(idict), img_index(idict));
    idict_to_array(idict);
    img_colorspace(idict) = colorspace;
    img_pagenum(idict) = page_num;
    img_pagename(idict) = page_name;
    img_userpassword(idict) = user_password;
    img_ownerpassword(idict) = owner_password;
    img_visiblefilename(idict) = visible_filename;
    if (file_name == NULL) {
        normal_error("pdf backend","no image filename given");
    }
    cur_file_name = file_name;
    img_filename(idict) = file_name;
    img_pagebox(idict) = page_box;
    read_img(idict);
    return idict;
}
示例#4
0
static halfword img_to_node(image * a)
{
    image_dict *ad;
    halfword n;
    assert(a != NULL);
    ad = img_dict(a);
    assert(ad != NULL);
    assert(img_objnum(ad) != 0);
    n = new_node(whatsit_node, pdf_refximage_node);
    pdf_ximage_index(n) = img_index(ad);
    width(n) = img_width(a);
    height(n) = img_height(a);
    depth(n) = img_depth(a);
    pdf_ximage_transform(n) = img_transform(a);
    return n;
}
示例#5
0
void scan_pdfrefximage(PDF pdf)
{
    /*tex One could scan transform as well. */
    int transform = 0;
    /*tex Begin of experiment. */
    int open = 0;
    /*tex End of experiment. */
    image_dict *idict;
    /*tex This scans |<rule spec>| to |alt_rule|. */
    scaled_whd alt_rule, dim;
    alt_rule = scan_alt_rule();
    /*tex Begin of experiment. */
    if (scan_keyword("keepopen")) {
        open = 1;
    }
    /*tex End of experiment. */
    scan_int();
    check_obj_type(pdf, obj_type_ximage, cur_val);
    tail_append(new_rule(image_rule));
    idict = idict_array[obj_data_ptr(pdf, cur_val)];
    /*tex Begin of experiment, */
    if (open) {
        /*tex So we keep the original value when no close is given. */
        idict->keepopen = 1;
    }
    /*tex End of experiment. */
    if (img_state(idict) == DICT_NEW) {
        normal_warning("image","don't rely on the image data to be okay");
        width(tail_par) = 0;
        height(tail_par) = 0;
        depth(tail_par) = 0;
    } else {
        if (alt_rule.wd != null_flag || alt_rule.ht != null_flag || alt_rule.dp != null_flag) {
            dim = scale_img(idict, alt_rule, transform);
        } else {
            dim = scale_img(idict, img_dimen(idict), img_transform(idict));
        }
        width(tail_par) = dim.wd;
        height(tail_par) = dim.ht;
        depth(tail_par) = dim.dp;
        rule_transform(tail_par) = transform;
        rule_index(tail_par) = img_index(idict);
    }
}
示例#6
0
static halfword img_to_node(lua_State * L, image * a)
{
    image_dict *ad;
    halfword n = null;
    if (a == NULL) {
        luaL_error(L, "img.tonode needs a valid image");
    } else {
        ad = img_dict(a);
        if (a == NULL) {
            luaL_error(L, "img.tonode image has no dictionary");
        } else if (img_objnum(ad) == 0) {
            luaL_error(L, "img.tonode got image without object number");
        } else {
            n = new_rule(image_rule);
            rule_index(n) = img_index(ad);
            width(n) = img_width(a);
            height(n) = img_height(a);
            depth(n) = img_depth(a);
            rule_transform(n) = img_transform(a);
        }
    }
    return n;
}
示例#7
0
image_dict *new_image_dict(void)
{
    image_dict *p = xtalloc(1, image_dict);
    memset(p, 0, sizeof(image_dict));
    set_wd_running(p);
    set_ht_running(p);
    set_dp_running(p);
    img_transform(p) = 0;
    img_pagenum(p) = 1;
    img_type(p) = IMG_TYPE_NONE;
    img_pagebox(p) = PDF_BOX_SPEC_MEDIA;
    img_unset_bbox(p);
    img_unset_group(p);
    img_state(p) = DICT_NEW;
    /*tex A value of -1 means unused while the used counts from 0 */
    img_index(p) = -1;
    img_luaref(p) = 0;
    img_errorlevel(p) = pdf_inclusion_errorlevel;
    fix_pdf_version(static_pdf);
    img_pdfmajorversion(p) = pdf_major_version;
    img_pdfminorversion(p) = pdf_minor_version;
    return p;
}
示例#8
0
static void image_to_lua(lua_State * L, image * a)
{                               /* key user ... */
    int i, j;
    image_dict *d = img_dict(a);
    assert(d != NULL);
    lua_pushstring(L, IMG_ENV); /* s k u ... */
    lua_gettable(L, LUA_REGISTRYINDEX); /* t k u ... */
    lua_pushvalue(L, -2);       /* k t k u ... */
    lua_gettable(L, -2);        /* i? t k u ... */
    if (!lua_isnumber(L, -1))   /* !i t k u ... */
        luaL_error(L, "image_to_lua(): %s is not a valid image key",
                   lua_tostring(L, -3));
    i = (int) lua_tointeger(L, -1);     /* i t k u ... */
    lua_pop(L, 3);              /* u ... */
    switch (i) {
    case P_WIDTH:
        if (is_wd_running(a))
            lua_pushnil(L);
        else
            lua_pushinteger(L, img_width(a));
        break;
    case P_HEIGHT:
        if (is_ht_running(a))
            lua_pushnil(L);
        else
            lua_pushinteger(L, img_height(a));
        break;
    case P_DEPTH:
        if (is_dp_running(a))
            lua_pushnil(L);
        else
            lua_pushinteger(L, img_depth(a));
        break;
    case P_TRANSFORM:
        lua_pushinteger(L, img_transform(a));
        break;
        /* now follow all image_dict entries */
    case P_FILENAME:
        if (img_filename(d) == NULL || strlen(img_filename(d)) == 0)
            lua_pushnil(L);
        else
            lua_pushstring(L, img_filename(d));
        break;
    case P_VISIBLEFILENAME:
        if (img_visiblefilename(d) == NULL
            || strlen(img_visiblefilename(d)) == 0)
            lua_pushnil(L);
        else
            lua_pushstring(L, img_visiblefilename(d));
        break;
    case P_FILEPATH:
        if (img_filepath(d) == NULL || strlen(img_filepath(d)) == 0)
            lua_pushnil(L);
        else
            lua_pushstring(L, img_filepath(d));
        break;
    case P_ATTR:
        if (img_attr(d) == NULL || strlen(img_attr(d)) == 0)
            lua_pushnil(L);
        else
            lua_pushstring(L, img_attr(d));
        break;
    case P_PAGE:
        if (img_pagename(d) != NULL && strlen(img_pagename(d)) != 0)
            lua_pushstring(L, img_pagename(d));
        else
            lua_pushinteger(L, img_pagenum(d));
        break;
    case P_TOTALPAGES:
        lua_pushinteger(L, img_totalpages(d));
        break;
    case P_XSIZE:              /* Modify by /Rotate only for output */
        if ((img_rotation(d) & 1) == 0)
            lua_pushinteger(L, img_xsize(d));
        else
            lua_pushinteger(L, img_ysize(d));
        break;
    case P_YSIZE:              /* Modify by /Rotate only for output */
        if ((img_rotation(d) & 1) == 0)
            lua_pushinteger(L, img_ysize(d));
        else
            lua_pushinteger(L, img_xsize(d));
        break;
    case P_XRES:
        lua_pushinteger(L, img_xres(d));
        break;
    case P_YRES:
        lua_pushinteger(L, img_yres(d));
        break;
    case P_ROTATION:
        lua_pushinteger(L, img_rotation(d));
        break;
    case P_COLORSPACE:
        if (img_colorspace(d) == 0)
            lua_pushnil(L);
        else
            lua_pushinteger(L, img_colorspace(d));
        break;
    case P_COLORDEPTH:
        if (img_colordepth(d) == 0)
            lua_pushnil(L);
        else
            lua_pushinteger(L, img_colordepth(d));
        break;
    case P_IMAGETYPE:
        j = img_type(d);
        if (j >= 0 && j <= imgtype_max) {
            if (j == IMG_TYPE_NONE)
                lua_pushnil(L);
            else
                lua_pushstring(L, imgtype_s[j]);
        } else
            assert(0);
        break;
    case P_PAGEBOX:
        j = img_pagebox(d);
        if (j >= 0 && j <= pagebox_max) {
            if (j == PDF_BOX_SPEC_NONE)
                lua_pushnil(L);
            else
                lua_pushstring(L, pdfboxspec_s[j]);
        } else
            assert(0);
        break;
    case P_BBOX:
        if (!img_is_bbox(d)) {
            img_bbox(d)[0] = img_xorig(d);
            img_bbox(d)[1] = img_yorig(d);
            img_bbox(d)[2] = img_xorig(d) + img_xsize(d);
            img_bbox(d)[3] = img_yorig(d) + img_ysize(d);
        }
        lua_newtable(L);
        lua_pushinteger(L, 1);
        lua_pushinteger(L, img_bbox(d)[0]);
        lua_settable(L, -3);
        lua_pushinteger(L, 2);
        lua_pushinteger(L, img_bbox(d)[1]);
        lua_settable(L, -3);
        lua_pushinteger(L, 3);
        lua_pushinteger(L, img_bbox(d)[2]);
        lua_settable(L, -3);
        lua_pushinteger(L, 4);
        lua_pushinteger(L, img_bbox(d)[3]);
        lua_settable(L, -3);
        break;
    case P_OBJNUM:
        if (img_objnum(d) == 0)
            lua_pushnil(L);
        else
            lua_pushinteger(L, img_objnum(d));
        break;
    case P_INDEX:
        if (img_index(d) == 0)
            lua_pushnil(L);
        else
            lua_pushinteger(L, img_index(d));
        break;
    case P_STREAM:
        if (img_type(d) != IMG_TYPE_PDFSTREAM || img_pdfstream_ptr(d) == NULL
            || img_pdfstream_stream(d) == NULL
            || strlen(img_pdfstream_stream(d)) == 0)
            lua_pushnil(L);
        else
            lua_pushstring(L, img_pdfstream_stream(d));
        break;
    default:
        assert(0);
    }                           /* v u ... */
}
示例#9
0
static int m_img_get(lua_State * L)
{
    int j;
    const char *s;
    image **a = (image **) luaL_checkudata(L, 1, TYPE_IMG); /* k u */
    image_dict *d = img_dict(*a);
    if (d == NULL) {
        luaL_error(L, "invalid image dictionary");
    }
    s = lua_tostring(L, 2);
    if (lua_key_eq(s,width)) {
        if (is_wd_running(*a)) {
            lua_pushnil(L);
        } else {
            lua_pushinteger(L, img_width(*a));
        }
    } else if (lua_key_eq(s,height)) {
        if (is_ht_running(*a)) {
            lua_pushnil(L);
        } else {
            lua_pushinteger(L, img_height(*a));
        }
    } else if (lua_key_eq(s,depth)) {
        if (is_dp_running(*a)) {
            lua_pushnil(L);
        } else {
            lua_pushinteger(L, img_depth(*a));
        }
    } else if (lua_key_eq(s,transform)) {
        lua_pushinteger(L, img_transform(*a));
    } else if (lua_key_eq(s,filename)) {
        if (img_filename(d) == NULL || strlen(img_filename(d)) == 0) {
            lua_pushnil(L);
        } else {
            lua_pushstring(L, img_filename(d));
        }
    } else if (lua_key_eq(s,visiblefilename)) {
        if (img_visiblefilename(d) == NULL || strlen(img_visiblefilename(d)) == 0) {
            lua_pushnil(L);
        } else {
            lua_pushstring(L, img_visiblefilename(d));
        }
    } else if (lua_key_eq(s,keepopen)) {
        lua_pushboolean(L, img_keepopen(d));
    } else if (lua_key_eq(s,filepath)) {
        if (img_filepath(d) == NULL || strlen(img_filepath(d)) == 0) {
            lua_pushnil(L);
        } else {
            lua_pushstring(L, img_filepath(d));
        }
    } else if (lua_key_eq(s,attr)) {
        if (img_attr(d) == NULL || strlen(img_attr(d)) == 0) {
            lua_pushnil(L);
        } else {
            lua_pushstring(L, img_attr(d));
        }
    } else if (lua_key_eq(s,page)) {
        if (img_pagename(d) != NULL && strlen(img_pagename(d)) != 0) {
            lua_pushstring(L, img_pagename(d));
        } else {
            lua_pushinteger(L, img_pagenum(d));
        }
    } else if (lua_key_eq(s,pages)) {
        lua_pushinteger(L, img_totalpages(d));
    } else if (lua_key_eq(s,xsize)) {
        if ((img_rotation(d) & 1) == 0) {
            lua_pushinteger(L, img_xsize(d));
        } else {
            lua_pushinteger(L, img_ysize(d));
        }
    } else if (lua_key_eq(s,ysize)) {
        if ((img_rotation(d) & 1) == 0) {
            lua_pushinteger(L, img_ysize(d));
        } else {
            lua_pushinteger(L, img_xsize(d));
        }
    } else if (lua_key_eq(s,xres)) {
        lua_pushinteger(L, img_xres(d));
    } else if (lua_key_eq(s,yres)) {
        lua_pushinteger(L, img_yres(d));
    } else if (lua_key_eq(s,rotation)) {
        lua_pushinteger(L, img_rotation(d));
    } else if (lua_key_eq(s,colorspace)) {
        if (img_colorspace(d) == 0) {
            lua_pushnil(L);
        } else {
            lua_pushinteger(L, img_colorspace(d));
        }
    } else if (lua_key_eq(s,colordepth)) {
        if (img_colordepth(d) == 0) {
            lua_pushnil(L);
        } else {
            lua_pushinteger(L, img_colordepth(d));
        }
    } else if (lua_key_eq(s,imagetype)) {
        j = img_type(d);
        if (j >= 0 && j <= img_types_max) {
            if (j == IMG_TYPE_NONE) {
                lua_pushnil(L);
            } else {
                lua_pushstring(L, img_types[j]);
            }
        } else {
            lua_pushnil(L);
        }
    } else if (lua_key_eq(s,pagebox)) {
        j = img_pagebox(d);
        if (j < 0 || j >= img_pageboxes_max) {
            j = 0;
        }
        lua_push_img_pagebox(L, j);
    } else if (lua_key_eq(s,bbox)) {
        if (!img_is_bbox(d)) {
            img_bbox(d)[0] = img_xorig(d);
            img_bbox(d)[1] = img_yorig(d);
            img_bbox(d)[2] = img_xorig(d) + img_xsize(d);
            img_bbox(d)[3] = img_yorig(d) + img_ysize(d);
        }
        lua_newtable(L);
        lua_pushinteger(L, 1);
        lua_pushinteger(L, img_bbox(d)[0]);
        lua_settable(L, -3);
        lua_pushinteger(L, 2);
        lua_pushinteger(L, img_bbox(d)[1]);
        lua_settable(L, -3);
        lua_pushinteger(L, 3);
        lua_pushinteger(L, img_bbox(d)[2]);
        lua_settable(L, -3);
        lua_pushinteger(L, 4);
        lua_pushinteger(L, img_bbox(d)[3]);
        lua_settable(L, -3);
    } else if (lua_key_eq(s,objnum)) {
        if (img_objnum(d) == 0) {
            lua_pushnil(L);
        } else {
            lua_pushinteger(L, img_objnum(d));
        }
    } else if (lua_key_eq(s,index)) {
        if (img_index(d) == 0) {
            lua_pushnil(L);
        } else {
            lua_pushinteger(L, img_index(d));
        }
    } else if (lua_key_eq(s,stream)) {
        if (img_type(d) != IMG_TYPE_PDFSTREAM
                || img_pdfstream_ptr(d) == NULL
                || img_pdfstream_stream(d) == NULL
                || strlen(img_pdfstream_stream(d)) == 0) {
            lua_pushnil(L);
        } else {
            lua_pushstring(L, img_pdfstream_stream(d));
        }
    } else if (lua_key_eq(s,ref_count)) {
        lua_pushinteger(L, img_luaref(d));
    } else {
        lua_pushnil(L);
    }
    return 1;
}
示例#10
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;
}