示例#1
0
void print(int s)
{
if(s>=str_ptr){
normal_warning("print","bad string pointer");
return;
}else if(s<STRING_OFFSET){
if(s<0){
normal_warning("print","bad string offset");
}else{

if((false)&&(selector> pseudo)){

print_char(s);
return;
}
if(s==new_line_char_par){
if(selector<pseudo){
print_ln();
return;
}
}
if(s<=0x7F){
print_char(s);
}else if(s<=0x7FF){
print_char(0xC0+(s/0x40));
print_char(0x80+(s%0x40));
}else if(s<=0xFFFF){
print_char(0xE0+(s/0x1000));
print_char(0x80+((s%0x1000)/0x40));
print_char(0x80+((s%0x1000)%0x40));
}else if(s>=0x110000){
int c= s-0x110000;
if(c>=256){
formatted_warning("print","bad raw byte to print (c=%d), skipped",c);
}else{
print_char(c);
}
}else{
print_char(0xF0+(s/0x40000));
print_char(0x80+((s%0x40000)/0x1000));
print_char(0x80+(((s%0x40000)%0x1000)/0x40));
print_char(0x80+(((s%0x40000)%0x1000)%0x40));
}
}
return;
}
if(selector==new_string){
append_string(str_string(s),(unsigned)str_length(s));
return;
}
lprint(&str_lstring(s));
}
示例#2
0
static void read_scale_img(image * a)
{
    image_dict *ad;
    if (a == NULL) {
        luaL_error(Luas, "the image scaler needs a valid image");
    } else {
        ad = img_dict(a);
        if (a == NULL) {
            luaL_error(Luas, "the image scaler needs a valid dictionary");
        } else {
            if (img_state(ad) == DICT_NEW) {
                if (img_type(ad) == IMG_TYPE_PDFSTREAM)
                    check_pdfstream_dict(ad);
                else {
                    read_img(ad);
                }
            }
            if ((img_type(ad) == IMG_TYPE_NONE) || (img_state(ad) == DICT_NEW)) {
                normal_warning("image","don't rely on the image data to be okay");
                img_width(a) = 0;
                img_height(a) = 0;
                img_depth(a) = 0;
            } else if (is_wd_running(a) || is_ht_running(a) || is_dp_running(a)) {
                img_dimen(a) = scale_img(ad, img_dimen(a), img_transform(a));
            }
        }
    }
}
示例#3
0
static void checkpdfrestore(scaledpos pos)
{
scaledpos diff;
if(pos_stack_used==0){
normal_warning("pdf backend","'restore' is missing a 'save'");
return;
}
pos_stack_used--;
diff.h= pos.h-pos_stack[pos_stack_used].pos.h;
diff.v= pos.v-pos_stack[pos_stack_used].pos.v;
if(diff.h!=0||diff.v!=0){
formatted_warning("pdf backend","misplaced 'restore' by (%dsp, %dsp)",(int)diff.h,(int)diff.v);
}
if(global_shipping_mode==SHIPPING_PAGE){
matrix_stack_used= pos_stack[pos_stack_used].matrix_stack;
}
}
示例#4
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);
    }
}
示例#5
0
scaled_whd scale_img(image_dict * idict, scaled_whd alt_rule, int transform)
{
    /*tex size and resolution of image */
    int x, y, xr, yr, tmp;
    /*tex natural size corresponding to image resolution */
    scaled_whd nat;
    int default_res;
    nat.dp = 0;
    nat.wd = 0;
    nat.ht = 0;
    if (img_nobbox(idict)) {
        if (img_is_bbox(idict)) {
            x = img_xsize(idict) = img_bbox(idict)[2] - img_bbox(idict)[0];
            y = img_ysize(idict) = img_bbox(idict)[3] - img_bbox(idict)[1];
            img_xorig(idict) = img_bbox(idict)[0];
            img_yorig(idict) = img_bbox(idict)[1];
            nat.wd = x;
            nat.ht = y;
        } else {
            normal_error("pdf backend","use boundingbox to pass dimensions");
        }
    } else {
        if ((img_type(idict) == IMG_TYPE_PDF || img_type(idict) == IMG_TYPE_PDFMEMSTREAM
             || img_type(idict) == IMG_TYPE_PDFSTREAM) && img_is_bbox(idict)) {
            /*tex dimensions from image.bbox */
            x = img_xsize(idict) = img_bbox(idict)[2] - img_bbox(idict)[0];
            y = img_ysize(idict) = img_bbox(idict)[3] - img_bbox(idict)[1];
            img_xorig(idict) = img_bbox(idict)[0];
            img_yorig(idict) = img_bbox(idict)[1];
        } else {
            /*tex dimensions, resolutions from image file */
            x = img_xsize(idict);
            y = img_ysize(idict);
        }
        xr = img_xres(idict);
        yr = img_yres(idict);
        if (x <= 0 || y <= 0 || xr < 0 || yr < 0)
            normal_error("pdf backend","invalid image dimensions");
        if (xr > 65535 || yr > 65535) {
            xr = 0;
            yr = 0;
            normal_warning("pdf backend","too large image resolution ignored");
        }
        if (((transform - img_rotation(idict)) & 1) == 1) {
            tmp = x;
            x = y;
            y = tmp;
            tmp = xr;
            xr = yr;
            yr = tmp;
        }
        /*tex always for images */
        if (img_type(idict) == IMG_TYPE_PDF || img_type(idict) == IMG_TYPE_PDFMEMSTREAM
            || img_type(idict) == IMG_TYPE_PDFSTREAM) {
            nat.wd = x;
            nat.ht = y;
        } else {
            default_res = fix_int(pdf_image_resolution, 0, 65535);
            if (default_res > 0 && (xr == 0 || yr == 0)) {
                xr = default_res;
                yr = default_res;
            }
            if (xr > 0 && yr > 0) {
                nat.wd = ext_xn_over_d(one_hundred_inch, x, 100 * xr);
                nat.ht = ext_xn_over_d(one_hundred_inch, y, 100 * yr);
            } else {
                nat.wd = ext_xn_over_d(one_hundred_inch, x, 7200);
                nat.ht = ext_xn_over_d(one_hundred_inch, y, 7200);
            }
        }
    }
    return tex_scale(nat, alt_rule);
}
示例#6
0
void scan_pdfximage(PDF pdf)
{
    scaled_whd alt_rule;
    image_dict *idict;
    int transform = 0, page = 1, pagebox, colorspace = 0;
    char *named = NULL, *attr = NULL, *file_name = NULL, *user = NULL, *owner = NULL, *visible = NULL;
    alt_rule = scan_alt_rule();
    if (scan_keyword("attr")) {
        scan_toks(false, true);
        attr = tokenlist_to_cstring(def_ref, true, NULL);
        delete_token_ref(def_ref);
    }
    if (scan_keyword("named")) {
        scan_toks(false, true);
        if (0) {
            named = tokenlist_to_cstring(def_ref, true, NULL);
            page = 0;
        } else {
            normal_warning("pdf backend","named pages are not supported, using page 1");
            page = 1;
        }
        delete_token_ref(def_ref);
    } else if (scan_keyword("page")) {
        scan_int();
        page = cur_val;
    }
    if (scan_keyword("userpassword")) {
        scan_toks(false, true);
        user = tokenlist_to_cstring(def_ref, true, NULL);
        delete_token_ref(def_ref);
    }
    if (scan_keyword("ownerpassword")) {
        scan_toks(false, true);
        owner = tokenlist_to_cstring(def_ref, true, NULL);
        delete_token_ref(def_ref);
    }
    if (scan_keyword("visiblefilename")) {
        scan_toks(false, true);
        visible = tokenlist_to_cstring(def_ref, true, NULL);
        delete_token_ref(def_ref);
    }
    if (scan_keyword("colorspace")) {
        scan_int();
        colorspace = cur_val;
    }
    pagebox = scan_pdf_box_spec();
    if (pagebox == PDF_BOX_SPEC_NONE) {
        pagebox = pdf_pagebox;
        if (pagebox == PDF_BOX_SPEC_NONE)
            pagebox = PDF_BOX_SPEC_CROP;
    }
    scan_toks(false, true);
    file_name = tokenlist_to_cstring(def_ref, true, NULL);
    if (file_name == NULL) {
        normal_error("pdf backend","no image filename given");
    }
    delete_token_ref(def_ref);
    idict = read_image(file_name, page, named, colorspace, pagebox, user, owner, visible);
    img_attr(idict) = attr;
    img_dimen(idict) = alt_rule;
    img_transform(idict) = transform;
    last_saved_image_index = img_objnum(idict);
    last_saved_image_pages = img_totalpages(idict);
}
示例#7
0
void read_img(image_dict * idict)
{
    char *filepath = NULL;
    int callback_id;
    if (img_filename(idict) == NULL) {
        normal_error("pdf backend","image file name missing");
    }
    callback_id = callback_defined(find_image_file_callback);
    if (img_filepath(idict) == NULL) {
        if (callback_id > 0) {
            /*tex We always callback, also for a mem stream. */
            if (run_callback(callback_id, "S->S", img_filename(idict),&filepath)) {
                if (filepath && (strlen(filepath) > 0)) {
                    img_filepath(idict) = strdup(filepath);
                }
            }
        }
        if (img_filepath(idict) == NULL && (strstr(img_filename(idict),"data:application/pdf,") != NULL)) {
            /*tex We need to check here for a pdf memstream. */
            img_filepath(idict) = strdup(img_filename(idict));
        } else if (callback_id == 0) {
            /*tex Otherwise we use kpse but only when we don't callback. */
            img_filepath(idict) = kpse_find_file(img_filename(idict), kpse_tex_format, true);
        }
        if (img_filepath(idict) == NULL) {
            /*tex In any case we need a name. */
            formatted_error("pdf backend","cannot find image file '%s'", img_filename(idict));
        }
    }
    recorder_record_input(img_filepath(idict));
    /*tex A few type checks. */
    check_type_by_header(idict);
    check_type_by_extension(idict);
    /*tex Now we're ready to read the image. */
    switch (img_type(idict)) {
        case IMG_TYPE_PDFMEMSTREAM:
        case IMG_TYPE_PDF:
            read_pdf_info(idict);
            break;
        case IMG_TYPE_PNG:
            read_png_info(idict);
            break;
        case IMG_TYPE_JPG:
            read_jpg_info(idict);
            break;
        case IMG_TYPE_JP2:
            read_jp2_info(idict);
            break;
        case IMG_TYPE_JBIG2:
            read_jbig2_info(idict);
            break;
        default:
            img_type(idict) = IMG_TYPE_NONE;
            if (pdf_ignore_unknown_images) {
                normal_warning("pdf backend","internal error: ignoring unknown image type");
            } else {
                normal_error("pdf backend","internal error: unknown image type");
            }
            break;
    }
    cur_file_name = NULL;
    if (img_type(idict) == IMG_TYPE_NONE) {
        img_state(idict) = DICT_NEW;
    } else if (img_state(idict) < DICT_FILESCANNED) {
        img_state(idict) = DICT_FILESCANNED;
    }
}