S32 UmService::get_list( gs_srv_um_list_type_enum list_type, gs_srv_um_box_identity_struct msg_box, gs_srv_um_list_filter_struct *filter, gs_srv_um_get_msg_list_cb cb_func, S32 user_data) { /*----------------------------------------------------------------*/ /* Local Variables */ /*----------------------------------------------------------------*/ S32 result; S32 new_data; srv_um_box_identity_struct box_id_struct; /*----------------------------------------------------------------*/ /* Code Body */ /*----------------------------------------------------------------*/ //MMI_PRINT(MOD_MRE, TRACE_GROUP_1, "[MRE] UmService::get_list"); #ifndef __SRV_UM_THREAD_MESSAGE_SUPPORT__ if (GS_SRV_UM_LIST_TYPE_THREAD == list_type) { return GS_SRV_UM_RESULT_NOT_SUPPORT; } #endif tans_box_id_struct(&box_id_struct,msg_box); UM_COMMON_CALLBACK_BEGIN(&new_data,cb_func,user_data); result = srv_um_get_list((srv_um_list_type_enum)list_type,box_id_struct,(srv_um_list_filter_struct*)filter,(srv_um_get_msg_list_cb)common_callback,new_data); if (result < 0) { gs_free((void*)new_data); } return result; }
S32 UmService::get_msg_info ( gs_srv_um_box_identity_struct msg_box, gs_srv_um_msg_node_struct msg_list[], U16 msg_number, gs_srv_um_get_msg_info_cb cb_func, S32 user_data) { /*----------------------------------------------------------------*/ /* Local Variables */ /*----------------------------------------------------------------*/ S32 result; S32 new_data; srv_um_box_identity_struct box_id_struct; /*----------------------------------------------------------------*/ /* Code Body */ /*----------------------------------------------------------------*/ //MMI_PRINT(MOD_MRE, TRACE_GROUP_1, "[MRE] UmService::get_msg_info"); tans_box_id_struct(&box_id_struct,msg_box); UM_COMMON_CALLBACK_BEGIN(&new_data,cb_func,user_data); result = srv_um_get_msg_info(box_id_struct,(srv_um_msg_node_struct*)msg_list,msg_number,(srv_um_get_msg_info_cb)common_callback,new_data); if (result < 0) { gs_free((void*)new_data); } return result; }
S32 UmService::delete_folder( gs_srv_um_box_identity_struct msg_box, gs_srv_um_delete_folder_cb cb_func, S32 user_data) { /*----------------------------------------------------------------*/ /* Local Variables */ /*----------------------------------------------------------------*/ S32 result; S32 new_data; srv_um_box_identity_struct box_id_struct; /*----------------------------------------------------------------*/ /* Code Body */ /*----------------------------------------------------------------*/ //MMI_PRINT(MOD_MRE, TRACE_GROUP_1, "[MRE] UmService::delete_folder"); tans_box_id_struct(&box_id_struct,msg_box); UM_COMMON_CALLBACK_BEGIN(&new_data,cb_func,user_data); result = srv_um_delete_folder(box_id_struct, (srv_um_delete_folder_cb)common_callback, new_data); if (result < 0) { gs_free((void*)new_data); } return result; }
S32 UmService::get_thread_info ( gs_srv_um_box_identity_struct msg_box, gs_srv_um_thread_id_struct thread_list[], U16 thread_number, gs_srv_um_get_thread_info_cb cb_func, S32 user_data) { #ifndef __SRV_UM_THREAD_MESSAGE_SUPPORT__ return GS_SRV_UM_RESULT_NOT_SUPPORT; #else /*----------------------------------------------------------------*/ /* Local Variables */ /*----------------------------------------------------------------*/ S32 result; S32 new_data; srv_um_box_identity_struct box_id_struct; /*----------------------------------------------------------------*/ /* Code Body */ /*----------------------------------------------------------------*/ //MMI_PRINT(MOD_MRE, TRACE_GROUP_1, "[MRE] UmService::get_thread_info"); tans_box_id_struct(&box_id_struct,msg_box); UM_COMMON_CALLBACK_BEGIN(&new_data,cb_func,user_data); result = srv_um_get_thread_info(box_id_struct, (srv_um_thread_id_struct*)thread_list, thread_number, (srv_um_get_thread_info_cb)common_callback, new_data); if (result < 0) { gs_free((void*)new_data); } return result; #endif }
static int lp2000_print_page_copies(gx_device_printer * pdev, FILE * fp, int num_coipes) { gx_device_lprn *const lprn = (gx_device_lprn *) pdev; int code = 0; int bpl = gdev_mem_bytes_per_scan_line(pdev); int maxY = lprn->BlockLine / lprn->nBh * lprn->nBh; /* printer initialize */ if (pdev->PageCount == 0) escpage_printer_initialize(pdev, fp, num_coipes); if (!(lprn->CompBuf = gs_malloc(pdev->memory->non_gc_memory, bpl * 3 / 2 + 1, maxY, "lp2000_print_page_copies(CompBuf)"))) return_error(gs_error_VMerror); if (lprn->NegativePrint) { fprintf(fp, "%c1dmG", GS); fprintf(fp, "%c0;0;%d;%d;0rG", GS, pdev->width, pdev->height); fprintf(fp, "%c2owE", GS); } code = lprn_print_image(pdev, fp); if (code < 0) return code; gs_free(pdev->memory->non_gc_memory, lprn->CompBuf, bpl * 3 / 2 + 1, maxY, "lp2000_print_page_copies(CompBuf)"); if (pdev->Duplex) fprintf(fp, "%c0dpsE", GS); else fprintf(fp, "\014"); /* eject page */ return code; }
int eprn_output_page(gx_device *dev, int num_copies, int flush) { eprn_Eprn *eprn = &((eprn_Device *)dev)->eprn; int rc; #ifdef EPRN_TRACE clock_t start_time = clock(); if_debug0(EPRN_TRACE_CHAR, "! eprn_output_page()...\n"); #endif /* Initialize eprn_get_planes() data */ eprn->next_y = 0; if (eprn->intensity_rendering == eprn_IR_FloydSteinberg) { /* Fetch the first line and store it in 'next_scan_line'. */ if (eprn_fetch_scan_line((eprn_Device *)dev, &eprn->next_scan_line) == 0) eprn->next_y++; } /* Ship out */ rc = gdev_prn_output_page(dev, num_copies, flush); /* CUPS page accounting message. The CUPS documentation is not perfectly clear on whether one should generate this message before printing a page or after printing has been successful. The rasterto* filters generate it before sending the page, but as the scheduler uses these messages for accounting, this seems unfair. */ if (rc == 0 && eprn->CUPS_accounting) eprintf2("PAGE: %ld %d\n", dev->ShowpageCount, num_copies); /* The arguments are the number of the page, starting at 1, and the number of copies of that page. */ #ifndef EPRN_NO_PAGECOUNTFILE /* On success, record the number of pages printed */ if (rc == 0 && eprn->pagecount_file != NULL) { assert(num_copies > 0); /* because of signed/unsigned */ if (pcf_inccount(eprn->pagecount_file, num_copies) != 0) { /* pcf_inccount() has issued an error message. */ eprintf( " No further attempts will be made to access the page count file.\n"); gs_free(dev->memory->non_gc_memory, eprn->pagecount_file, strlen(eprn->pagecount_file) + 1, sizeof(char), "eprn_output_page"); eprn->pagecount_file = NULL; } } #endif /* !EPRN_NO_PAGECOUNTFILE */ /* If soft tumble has been demanded, ensure the get_initial_matrix procedure is consulted for the next page */ if (eprn->soft_tumble) eprn_forget_defaultmatrix(dev->memory->non_gc_memory); #ifdef EPRN_TRACE if_debug1(EPRN_TRACE_CHAR, "! eprn_output_page() terminates after %f s.\n", ((float)(clock() - start_time))/CLOCKS_PER_SEC); #endif return rc; }
static void BoundImage(gx_device_printer *pDev, struct bounding *pBox) { int x, y, flag; int LineSize = gdev_mem_bytes_per_scan_line((gx_device *)pDev); int Xsize, Ysize, Pt, Pb, Pl, Pr; int Xres = (int)pDev->x_pixels_per_inch, Yres = (int)pDev->y_pixels_per_inch, height = pDev->height; byte *Buf; enum Paper paper; /* ----==== Check parameters ====---- */ paper = height*10/Yres < 82 ? postcard :\ height*10/Yres < 98 ? a5 :\ height*10/Yres < 109 ? b5 :\ height*10/Yres < 116 ? letter : a4; Xsize = Xres * mm_to_inch(PaperInfo[paper].w-100) / 160; Ysize = Yres * mm_to_inch(PaperInfo[paper].h-100) / 10; /* ----==== Allocate momory ====---- */ if (LineSize < Xsize*2+1) { LineSize = Xsize*2+1; } Buf = (byte *)gs_malloc(gs_lib_ctx_get_non_gc_memory_t(), 1, LineSize, "LineBuffer"); /* ----==== bounding image ====---- */ Pt = Pb = Pl = Pr = -1; for(y=0 ; y<height && y<Ysize ; y++){ flag = 0; gdev_prn_copy_scan_lines(pDev, y, Buf, LineSize); for (x=0 ; x<min(LineSize/2, Xsize) ; x++) { if (*(Buf+x*2) || *(Buf+x*2+1)) { if (Pl == -1 || Pl > x) { Pl = x; } if (Pr < x) { Pr = x; } flag = 1; } } if (flag) { if (Pt == -1) { Pt = y; } Pb = y; } } pBox->paper = paper; pBox->Top = Pt; pBox->Bottom = Pb; pBox->Left = Pl; pBox->Right = Pr; gs_free(gs_lib_ctx_get_non_gc_memory_t(), Buf, 1, LineSize, "LineBuffer"); }
int eprn_close_device(gx_device *device) { eprn_Eprn *eprn = &((eprn_Device *)device)->eprn; #ifdef EPRN_TRACE if_debug0(EPRN_TRACE_CHAR, "! eprn_close_device()...\n"); #endif if (eprn->scan_line.str != NULL) { gs_free(device->memory->non_gc_memory, eprn->scan_line.str, eprn->octets_per_line, sizeof(eprn_Octet), "eprn_close_device"); eprn->scan_line.str = NULL; } if (eprn->next_scan_line.str != NULL) { gs_free(device->memory->non_gc_memory, eprn->next_scan_line.str, eprn->octets_per_line, sizeof(eprn_Octet), "eprn_close_device"); eprn->next_scan_line.str = NULL; } return gdev_prn_close(device); }
S32 UmService::check_list( gs_srv_um_list_type_enum list_type, gs_srv_um_box_identity_struct msg_box, gs_srv_um_list_filter_struct *filter, gs_srv_um_notify_list_handler cb_func, S32 user_data, gs_srv_um_list_cntx_struct **list_cntx) { /*----------------------------------------------------------------*/ /* Local Variables */ /*----------------------------------------------------------------*/ S32 ret; S32 new_data; srv_um_box_identity_struct box_id_struct; srv_um_list_cntx_struct* list_cntx_tmp; /*----------------------------------------------------------------*/ /* Code Body */ /*----------------------------------------------------------------*/ //MMI_PRINT(MOD_MRE, TRACE_GROUP_1, "[MRE] UmService::check_list"); if(NULL == list_cntx) { return GS_SRV_UM_RESULT_INVALID_PARA; } #ifndef __SRV_UM_THREAD_MESSAGE_SUPPORT__ if (GS_SRV_UM_LIST_TYPE_THREAD == list_type) { return GS_SRV_UM_RESULT_NOT_SUPPORT; } #endif UM_COMMON_CALLBACK_BEGIN(&new_data,cb_func,user_data) tans_box_id_struct(&box_id_struct,msg_box); ret = srv_um_check_list((srv_um_list_type_enum)list_type, box_id_struct, (srv_um_list_filter_struct*)filter, (srv_um_notify_list_handler)notify_cb, new_data, &list_cntx_tmp); if (ret < 0) { gs_free((void*)new_data); return ret; } *list_cntx = (gs_srv_um_list_cntx_struct*)(&list_cntx_tmp->list); return ret; }
/* Put parameters */ int gdev_pdf_put_params(gx_device * dev, gs_param_list * plist) { int code; gx_device_pdf *pdev = (gx_device_pdf *) dev; gs_memory_t *mem = gs_memory_stable(pdev->memory); gx_device_pdf *save_dev = gs_malloc(mem, sizeof(gx_device_pdf), 1, "saved gx_device_pdf"); if (!save_dev) return_error(gs_error_VMerror); memcpy(save_dev, pdev, sizeof(gx_device_pdf)); code = gdev_pdf_put_params_impl(dev, save_dev, plist); gs_free(mem, save_dev, sizeof(gx_device_pdf), 1, "saved gx_device_pdf"); return code; }
void notify_cb(S32 event, S32 list_cid, S32 user_data) { callback_data* data = (callback_data*)user_data; //MMI_PRINT(MOD_MRE, TRACE_GROUP_1, "[MRE] notify_cb"); if (VM_PMNG_OP_OK == vm_pmng_set_ctx(data->handle)) { if (data->cb) { (*(gs_srv_um_notify_list_handler)data->cb)(event,list_cid,data->user_data); } gs_free(data); vm_pmng_reset_ctx(); } }
/* Close the win_ddb driver */ static int win_ddb_close(gx_device * dev) { /* Free resources */ win_destroytools(wdev); DeleteDC(wdev->hdcmono); win_ddb_free_bitmap((gx_device_win *) dev); DeleteObject(wdev->hpalette); DeleteObject(wdev->hbmmono); gs_free((char *)(wdev->lpalette), 1, sizeof(LOGPALETTE) + (1 << (wdev->color_info.depth)) * sizeof(PALETTEENTRY), "win_ddb_close"); return win_close(dev); }
S32 common_callback(S32 pid, void* rsp, S32 user_data) { S32 res = 0; callback_data* data = (callback_data*)user_data; //MMI_PRINT(MOD_MRE, TRACE_GROUP_1, "[MRE] common_callback"); if (VM_PMNG_OP_OK == vm_pmng_set_ctx(data->handle)) { if (data->cb) { res = (*data->cb)(pid,rsp,data->user_data); } gs_free(data); vm_pmng_reset_ctx(); } return res; }
void eprn_init_device(eprn_Device *dev, const eprn_PrinterDescription *desc) { eprn_Eprn *eprn = &dev->eprn; int j; float hres, vres; if (dev->is_open) gs_closedevice((gx_device *)dev); assert(desc != NULL); eprn->cap = desc; eprn_set_media_data(dev, NULL, 0); /* The media flags are retained because they have not been prescribed by the user directly in contact with eprn but are completely under the control of the derived device. */ eprn->code = ms_none; eprn->leading_edge_set = false; eprn->right_shift = 0; eprn->down_shift = 0; eprn->keep_margins = false; eprn->soft_tumble = false; for (j = 0; j < 4; j++) dev->HWMargins[j] = 0; /* Set to default colour state, ignoring request failures */ eprn->colour_model = eprn_DeviceGray; eprn->black_levels = 2; eprn->non_black_levels = 0; eprn->intensity_rendering = eprn_IR_halftones; hres = dev->HWResolution[0]; vres = dev->HWResolution[1]; eprn_check_colour_info(desc->colour_info, &eprn->colour_model, &hres, &vres, &eprn->black_levels, &eprn->non_black_levels); if (eprn->pagecount_file != NULL) { gs_free(dev->memory->non_gc_memory, eprn->pagecount_file, strlen(eprn->pagecount_file) + 1, sizeof(char), "eprn_init_device"); eprn->pagecount_file = NULL; } eprn->media_position_set = false; return; }
S32 UmService::mark_several_thread_op( gs_srv_um_box_identity_struct msg_box, gs_srv_um_thread_id_struct thread_list[], U16 thread_list_size, U32 mark_status[], gs_srv_um_mark_several_op_action_enum action_type, gs_srv_um_mark_several_thread_op_cb cb_func, S32 user_data) { //MMI_PRINT(MOD_MRE, TRACE_GROUP_1, "[MRE] UmService::mark_several_thread_op"); #ifndef __SRV_UM_THREAD_MESSAGE_SUPPORT__ return GS_SRV_UM_RESULT_NOT_SUPPORT; #else /*----------------------------------------------------------------*/ /* Local Variables */ /*----------------------------------------------------------------*/ S32 result; S32 new_data; srv_um_box_identity_struct box_id_struct; /*----------------------------------------------------------------*/ /* Code Body */ /*----------------------------------------------------------------*/ tans_box_id_struct(&box_id_struct,msg_box); UM_COMMON_CALLBACK_BEGIN(&new_data,cb_func,user_data); result = srv_um_mark_several_thread_op(box_id_struct, (srv_um_thread_id_struct*)thread_list, thread_list_size,mark_status, (srv_um_mark_several_op_action_enum)action_type, (srv_um_mark_several_thread_op_cb)common_callback, new_data); if (result < 0) { gs_free((void*)new_data); } return result; #endif }
S32 UmService::get_msg_num( gs_srv_um_msg_enum msg_type, gs_srv_um_sim_enum sim_id, gs_srv_um_get_msg_num_cb cb_func, S32 user_data) { /*----------------------------------------------------------------*/ /* Local Variables */ /*----------------------------------------------------------------*/ S32 new_data; S32 result; /*----------------------------------------------------------------*/ /* Code Body */ /*----------------------------------------------------------------*/ //MMI_PRINT(MOD_MRE, TRACE_GROUP_1, "[MRE] UmService::get_msg_num"); UM_COMMON_CALLBACK_BEGIN(&new_data,cb_func,user_data); result = srv_um_get_msg_num((srv_um_msg_enum)msg_type,(srv_um_sim_enum)sim_id,(srv_um_get_msg_num_cb)common_callback,new_data); if (result < 0) { gs_free((void*)new_data); } return result; }
/* Send the page to the printer. */ static int m8510_print_page(gx_device_printer *pdev, FILE *prn_stream) { int line_size = gdev_mem_bytes_per_scan_line((gx_device *)pdev); byte *in1 = (byte *) gs_malloc(pdev->memory, 8, line_size, "m8510_print_page(in1)"); byte *in2 = (byte *) gs_malloc(pdev->memory, 8, line_size, "m8510_print_page(in2)"); byte *out = (byte *) gs_malloc(pdev->memory, 8, line_size, "m8510_print_page(out)"); int lnum = 0; int code = 0; byte *inp, *in_end, *outp; int i; if (in1 == 0 || in2 == 0 || out == 0) { code = gs_note_error(gs_error_VMerror); goto out; } /* * Initialize the printer. * NLQ mode, proportional print (160x144 dpi). * and 16/144" linefeeds. */ fwrite("\033m2\033P\033T16", 1, 9, prn_stream); /* Transfer pixels to printer */ while ( lnum < pdev->height ) { /* get a raster */ for (i = 7; i >= 0; i--) { gdev_prn_copy_scan_lines(pdev, lnum, &in1[i*line_size], line_size); lnum++; gdev_prn_copy_scan_lines(pdev, lnum, &in2[i*line_size], line_size); lnum++; } /* Transpose the 1st pass of data. */ in_end = in1 + line_size; for (inp = in1, outp = out; inp < in_end; inp++, outp += 8) gdev_prn_transpose_8x8(inp, line_size, outp, 1); /* send the 1st line */ m8510_output_run(pdev, out, 0, prn_stream); /* Transpose the 2nd pass of data. */ in_end = in2 + line_size; for (inp = in2, outp = out; inp < in_end; inp++, outp += 8) gdev_prn_transpose_8x8(inp, line_size, outp, 1); /* send the 2nd line */ m8510_output_run(pdev, out, 1, prn_stream); } /* reset the printer. */ fwrite("\033c1", 1, 3, prn_stream); fflush(prn_stream); out:; if (out) gs_free(pdev->memory, (char *) out, 8, line_size, "m8510_print_page(out)"); if (in2) gs_free(pdev->memory, (char *) in2, 8, line_size, "m8510_print_page(in2)"); if (in1) gs_free(pdev->memory, (char *) in1, 8, line_size, "m8510_print_page(in1)"); return code; }
static int sparc_print_page(gx_device_printer *pdev, FILE *prn) { struct lpvi_page lpvipage; struct lpvi_err lpvierr; char *out_buf; int out_size; if (ioctl(fileno(prn),LPVIIOC_GETPAGE,&lpvipage)!=0) { errprintf(pdev->memory, "sparc_print_page: LPVIIOC_GETPAGE failed\n"); return -1; } lpvipage.bitmap_width=gdev_mem_bytes_per_scan_line((gx_device *)pdev); lpvipage.page_width=lpvipage.bitmap_width*8; lpvipage.page_length=pdev->height; lpvipage.resolution = (pdev->x_pixels_per_inch == 300 ? DPI300 : DPI400); if (ioctl(fileno(prn),LPVIIOC_SETPAGE,&lpvipage)!=0) { errprintf(pdev->memory, "sparc_print_page: LPVIIOC_SETPAGE failed\n"); return -1; } out_size=lpvipage.bitmap_width*lpvipage.page_length; out_buf=gs_malloc(pdev->memory, out_size,1,"sparc_print_page: out_buf"); gdev_prn_copy_scan_lines(pdev,0,out_buf,out_size); while (write(fileno(prn),out_buf,out_size)!=out_size) { if (ioctl(fileno(prn),LPVIIOC_GETERR,&lpvierr)!=0) { errprintf(pdev->memory, "sparc_print_page: LPVIIOC_GETERR failed\n"); return -1; } switch (lpvierr.err_type) { case 0: if (warning==0) { errprintf(pdev->memory, "sparc_print_page: Printer Problem with unknown reason..."); dmflush(pdev->memory); warning=1; } sleep(5); break; case ENGWARN: errprintf(pdev->memory, "sparc_print_page: Printer-Warning: %s...", err_code_string(lpvierr.err_code)); dmflush(pdev->memory); warning=1; sleep(5); break; case ENGFATL: errprintf(pdev->memory, "sparc_print_page: Printer-Fatal: %s\n", err_code_string(lpvierr.err_code)); return -1; case EDRVR: errprintf(pdev->memory, "sparc_print_page: Interface/driver error: %s\n", err_code_string(lpvierr.err_code)); return -1; default: errprintf(pdev->memory, "sparc_print_page: Unknown err_type=%d(err_code=%d)\n", lpvierr.err_type,lpvierr.err_code); return -1; } } if (warning==1) { errprintf(pdev->memory, "OK.\n"); warning=0; } gs_free(pdev->memory, out_buf,out_size,1,"sparc_print_page: out_buf"); return 0; }
/* Send the page to the printer. */ static int dmp_print_page(gx_device_printer *pdev, FILE *prn_stream) { int dev_type; int line_size = gdev_mem_bytes_per_scan_line((gx_device *)pdev); /* Note that in_size is a multiple of 8. */ int in_size = line_size * 8; byte *buf1 = (byte *)gs_malloc(pdev->memory, in_size, 1, "dmp_print_page(buf1)"); byte *buf2 = (byte *)gs_malloc(pdev->memory, in_size, 1, "dmp_print_page(buf2)"); byte *prn = (byte *)gs_malloc(pdev->memory, 3*in_size, 1, "dmp_print_page(prn)"); byte *in = buf1; byte *out = buf2; int lnum = 0; /* Check allocations */ if ( buf1 == 0 || buf2 == 0 || prn == 0 ) { if ( buf1 ) gs_free(pdev->memory, (char *)buf1, in_size, 1, "dmp_print_page(buf1)"); if ( buf2 ) gs_free(pdev->memory, (char *)buf2, in_size, 1, "dmp_print_page(buf2)"); if ( prn ) gs_free(pdev->memory, (char *)prn, in_size, 1, "dmp_print_page(prn)"); return_error(gs_error_VMerror); } if ( pdev->y_pixels_per_inch == 216 ) dev_type = IWLQ; else if ( pdev->y_pixels_per_inch == 144 ) dev_type = IWHI; else if ( pdev->x_pixels_per_inch == 160 ) dev_type = IWLO; else dev_type = DMP; /* Initialize the printer and reset the margins. */ fputs("\r\n\033>\033T16", prn_stream); switch(dev_type) { case IWLQ: fputs("\033P\033a3", prn_stream); break; case IWHI: case IWLO: fputs("\033P", prn_stream); break; case DMP: default: fputs("\033q", prn_stream); break; } /* Print lines of graphics */ while ( lnum < pdev->height ) { byte *inp; byte *in_end; byte *out_end; int lcnt,ltmp; int count, passes; byte *prn_blk, *prn_end, *prn_tmp; /* The apple DMP printer seems to be odd in that the bit order on * each line is reverse what might be expected. Meaning, an * underscore would be done as a series of 0x80, while on overscore * would be done as a series of 0x01. So we get each * scan line in reverse order. */ switch (dev_type) { case IWLQ: passes = 3; break; case IWHI: passes = 2; break; case IWLO: case DMP: default: passes = 1; break; } for (count = 0; count < passes; count++) { for (lcnt=0; lcnt<8; lcnt++) { switch(dev_type) { case IWLQ: ltmp = lcnt + 8*count; break; case IWHI: ltmp = 2*lcnt + count; break; case IWLO: case DMP: default: ltmp = lcnt; break; } if ((lnum+ltmp)>pdev->height) memset(in+lcnt*line_size,0,line_size); else gdev_prn_copy_scan_lines(pdev, lnum+ltmp, in + line_size*(7 - lcnt), line_size); } out_end = out; inp = in; in_end = inp + line_size; for ( ; inp < in_end; inp++, out_end += 8 ) { gdev_prn_transpose_8x8(inp, line_size, out_end, 1); } out_end = out; switch (dev_type) { case IWLQ: prn_end = prn + count; break; case IWHI: prn_end = prn + in_size*count; break; case IWLO: case DMP: default: prn_end = prn; break; } while ( (int)(out_end-out) < in_size) { *prn_end = *(out_end++); if ((dev_type) == IWLQ) prn_end += 3; else prn_end++; } } switch (dev_type) { case IWLQ: prn_blk = prn; prn_end = prn_blk + in_size * 3; while (prn_end > prn && prn_end[-1] == 0 && prn_end[-2] == 0 && prn_end[-3] == 0) { prn_end -= 3; } while (prn_blk < prn_end && prn_blk[0] == 0 && prn_blk[1] == 0 && prn_blk[2] == 0) { prn_blk += 3; } if (prn_end != prn_blk) { if ((prn_blk - prn) > 7) fprintf(prn_stream,"\033U%04d%c%c%c", (int)((prn_blk - prn)/3), 0, 0, 0); else prn_blk = prn; fprintf(prn_stream,"\033C%04d", (int)((prn_end - prn_blk)/3)); fwrite(prn_blk, 1, (int)(prn_end - prn_blk), prn_stream); } break; case IWHI: for (count = 0; count < 2; count++) { prn_blk = prn_tmp = prn + in_size*count; prn_end = prn_blk + in_size; while (prn_end > prn_blk && prn_end[-1] == 0) prn_end--; while (prn_blk < prn_end && prn_blk[0] == 0) prn_blk++; if (prn_end != prn_blk) { if ((prn_blk - prn_tmp) > 7) fprintf(prn_stream, "\033V%04d%c", (int)(prn_blk-prn_tmp), 0); else prn_blk = prn_tmp; fprintf(prn_stream,"\033G%04d", (int)(prn_end - prn_blk)); fwrite(prn_blk, 1, (int)(prn_end - prn_blk), prn_stream); } if (!count) fputs("\033T01\r\n",prn_stream); } fputs("\033T15",prn_stream); break; case IWLO: case DMP: default: prn_blk = prn; prn_end = prn_blk + in_size; while (prn_end > prn_blk && prn_end[-1] == 0) prn_end--; while (prn_blk < prn_end && prn_blk[0] == 0) prn_blk++; if (prn_end != prn_blk) { if ((prn_blk - prn) > 7) fprintf(prn_stream,"\033V%04d%c", (int)(prn_blk - prn), 0); else prn_blk = prn; fprintf(prn_stream,"\033G%04d", (int)(prn_end - prn_blk)); fwrite(prn_blk, 1, (int)(prn_end - prn_blk), prn_stream); } break; } fputs("\r\n",prn_stream); switch (dev_type) { case IWLQ: lnum += 24 ; break; case IWHI: lnum += 16 ; break; case IWLO: case DMP: default: lnum += 8 ; break; } } /* ImageWriter will skip a whole page if too close to end */ /* so skip back more than an inch */ if ( !(dev_type == DMP) ) fputs("\033T99\n\n\033r\n\n\n\n\033f", prn_stream); /* Formfeed and Reset printer */ fputs("\033T16\f\033<\033B\033E", prn_stream); fflush(prn_stream); gs_free(pdev->memory, (char *)prn, in_size, 1, "dmp_print_page(prn)"); gs_free(pdev->memory, (char *)buf2, in_size, 1, "dmp_print_page(buf2)"); gs_free(pdev->memory, (char *)buf1, in_size, 1, "dmp_print_page(buf1)"); return 0; }
/* .getnativefonts [ [<name> <path>] ... ] */ static int z_fontenum(i_ctx_t *i_ctx_p) { os_ptr op = osp; void *enum_state; int code = 0; int e,elements; char *fontname, *path; fontenum_t *r, *results; ref array; uint length; byte *string; enum_state = gp_enumerate_fonts_init(imemory); if (enum_state == NULL) { /* put false on the stack and return */ push(1); make_bool(op, false); return code; } r = results = gs_malloc(imemory->non_gc_memory, 1, sizeof(fontenum_t), "fontenum list"); elements = 0; while((code = gp_enumerate_fonts_next(enum_state, &fontname, &path )) > 0) { if (fontname == NULL || path == NULL) { gp_enumerate_fonts_free(enum_state); return_error(e_ioerror); } length = strlen(fontname) + 1; r->fontname = gs_malloc(imemory->non_gc_memory, length, 1, "native font name"); memcpy(r->fontname, fontname, length); length = strlen(path) + 1; r->path = gs_malloc(imemory->non_gc_memory, length, 1, "native font path"); memcpy(r->path, path, length); r->next = gs_malloc(imemory->non_gc_memory, 1, sizeof(fontenum_t), "fontenum list"); r = r->next; elements += 1; } gp_enumerate_fonts_free(enum_state); code = ialloc_ref_array(&array, a_all | icurrent_space, elements, "native fontmap"); r = results; for (e = 0; e < elements; e++) { ref mapping; code = ialloc_ref_array(&mapping, a_all | icurrent_space, 2, "native font mapping"); length = strlen(r->fontname); string = ialloc_string(length, "native font name"); if (string == NULL) return_error(e_VMerror); memcpy(string, r->fontname, length); make_string(&(mapping.value.refs[0]), a_all | icurrent_space, length, string); length = strlen(r->path); string = ialloc_string(length, "native font path"); if (string == NULL) return_error(e_VMerror); memcpy(string, r->path, length); make_string(&(mapping.value.refs[1]), a_all | icurrent_space, length, string); ref_assign(&(array.value.refs[e]), &mapping); results = r; r = r->next; gs_free(imemory->non_gc_memory, results->fontname, strlen(results->fontname) + 1, 1, "native font name"); gs_free(imemory->non_gc_memory, results->path, strlen(results->path) + 1, 1, "native font path"); gs_free(imemory->non_gc_memory, results, 1, sizeof(fontenum_t), "fontenum list"); } push(2); ref_assign(op-1, &array); make_bool(op, true); return code; }
/* Get Device Context for printer */ static int win_pr2_getdc(gx_device_win_pr2 * wdev) { char *device; char *devices; char *p; char driverbuf[512]; char *driver; char *output; char *devcap; int devcapsize; int devmode_size; int i, n; POINT *pp; int paperindex; int paperwidth, paperheight; int orientation; int papersize; char papername[64]; LPDEVMODE podevmode, pidevmode; HANDLE hprinter; /* first try to derive the printer name from -sOutputFile= */ /* is printer if name prefixed by \\spool\ or by %printer% */ if (is_spool(wdev->fname)) { device = wdev->fname + 8; /* skip over \\spool\ */ wdev->use_old_spool_name = true; } else if (strncmp("%printer%",wdev->fname,9) == 0) { device = wdev->fname + 9; /* skip over %printer% */ wdev->use_old_spool_name = false; } else { return FALSE; } /* now try to match the printer name against the [Devices] section */ if ((devices = gs_malloc(wdev->memory, 4096, 1, "win_pr2_getdc")) == (char *)NULL) return FALSE; GetProfileString("Devices", NULL, "", devices, 4096); p = devices; while (*p) { if (stricmp(p, device) == 0) break; p += strlen(p) + 1; } if (*p == '\0') p = NULL; gs_free(wdev->memory, devices, 4096, 1, "win_pr2_getdc"); if (p == NULL) return FALSE; /* doesn't match an available printer */ /* the printer exists, get the remaining information from win.ini */ GetProfileString("Devices", device, "", driverbuf, sizeof(driverbuf)); driver = strtok(driverbuf, ","); output = strtok(NULL, ","); if (!OpenPrinter(device, &hprinter, NULL)) return FALSE; devmode_size = DocumentProperties(NULL, hprinter, device, NULL, NULL, 0); if ((podevmode = gs_malloc(wdev->memory, devmode_size, 1, "win_pr2_getdc")) == (LPDEVMODE) NULL) { ClosePrinter(hprinter); return FALSE; } if ((pidevmode = gs_malloc(wdev->memory, devmode_size, 1, "win_pr2_getdc")) == (LPDEVMODE) NULL) { gs_free(wdev->memory, podevmode, devmode_size, 1, "win_pr2_getdc"); ClosePrinter(hprinter); return FALSE; } DocumentProperties(NULL, hprinter, device, podevmode, NULL, DM_OUT_BUFFER); /* now find out what paper sizes are available */ devcapsize = DeviceCapabilities(device, output, DC_PAPERSIZE, NULL, NULL); devcapsize *= sizeof(POINT); if ((devcap = gs_malloc(wdev->memory, devcapsize, 1, "win_pr2_getdc")) == (LPBYTE) NULL) return FALSE; n = DeviceCapabilities(device, output, DC_PAPERSIZE, devcap, NULL); paperwidth = (int)(wdev->MediaSize[0] * 254 / 72); paperheight = (int)(wdev->MediaSize[1] * 254 / 72); papername[0] = '\0'; papersize = 0; paperindex = -1; orientation = 0; pp = (POINT *) devcap; for (i = 0; i < n; i++, pp++) { if ((pp->x < paperwidth + 20) && (pp->x > paperwidth - 20) && (pp->y < paperheight + 20) && (pp->y > paperheight - 20)) { paperindex = i; paperwidth = pp->x; paperheight = pp->y; orientation = DMORIENT_PORTRAIT; break; } } if (paperindex < 0) { /* try again in landscape */ pp = (POINT *) devcap; for (i = 0; i < n; i++, pp++) { if ((pp->x < paperheight + 20) && (pp->x > paperheight - 20) && (pp->y < paperwidth + 20) && (pp->y > paperwidth - 20)) { paperindex = i; paperwidth = pp->x; paperheight = pp->y; orientation = DMORIENT_LANDSCAPE; break; } } } gs_free(wdev->memory, devcap, devcapsize, 1, "win_pr2_getdc"); /* get the dmPaperSize */ devcapsize = DeviceCapabilities(device, output, DC_PAPERS, NULL, NULL); devcapsize *= sizeof(WORD); if ((devcap = gs_malloc(wdev->memory, devcapsize, 1, "win_pr2_getdc")) == (LPBYTE) NULL) return FALSE; n = DeviceCapabilities(device, output, DC_PAPERS, devcap, NULL); if ((paperindex >= 0) && (paperindex < n)) papersize = ((WORD *) devcap)[paperindex]; gs_free(wdev->memory, devcap, devcapsize, 1, "win_pr2_getdc"); /* get the paper name */ devcapsize = DeviceCapabilities(device, output, DC_PAPERNAMES, NULL, NULL); devcapsize *= 64; if ((devcap = gs_malloc(wdev->memory, devcapsize, 1, "win_pr2_getdc")) == (LPBYTE) NULL) return FALSE; n = DeviceCapabilities(device, output, DC_PAPERNAMES, devcap, NULL); if ((paperindex >= 0) && (paperindex < n)) strcpy(papername, devcap + paperindex * 64); gs_free(wdev->memory, devcap, devcapsize, 1, "win_pr2_getdc"); memcpy(pidevmode, podevmode, devmode_size); pidevmode->dmFields = 0; wdev->paper_name[0] = 0; if ( (wdev->user_paper) && (wdev->user_paper != papersize) ) { papersize = wdev->user_paper; paperheight = 0; paperwidth = 0; papername[0] = 0; } if (wdev->user_orient) { orientation = wdev->user_orient; } pidevmode->dmFields &= ~(DM_PAPERSIZE | DM_ORIENTATION | DM_COLOR | DM_PAPERLENGTH | DM_PAPERWIDTH | DM_DUPLEX); pidevmode->dmFields |= DM_DEFAULTSOURCE; pidevmode->dmDefaultSource = 0; if (orientation) { wdev->user_orient = orientation; } if (papersize) { wdev->user_paper = papersize; strcpy (wdev->paper_name, papername); } if (paperheight && paperwidth) { pidevmode->dmFields |= (DM_PAPERLENGTH | DM_PAPERWIDTH); pidevmode->dmPaperWidth = paperwidth; pidevmode->dmPaperLength = paperheight; wdev->user_media_size[0] = paperwidth / 254.0 * 72.0; wdev->user_media_size[1] = paperheight / 254.0 * 72.0; } if (DeviceCapabilities(device, output, DC_DUPLEX, NULL, NULL)) { wdev->Duplex_set = 1; } win_pr2_update_win(wdev, pidevmode); /* merge the entries */ DocumentProperties(NULL, hprinter, device, podevmode, pidevmode, DM_IN_BUFFER | DM_OUT_BUFFER); ClosePrinter(hprinter); /* now get a DC */ wdev->hdcprn = CreateDC(driver, device, NULL, podevmode); if (wdev->win32_hdevmode == NULL) wdev->win32_hdevmode = GlobalAlloc(0, devmode_size); if (wdev->win32_hdevmode) { LPDEVMODE pdevmode = (LPDEVMODE) GlobalLock(wdev->win32_hdevmode); if (pdevmode) { memcpy(pdevmode, podevmode, devmode_size); GlobalUnlock(wdev->win32_hdevmode); } } gs_free(wdev->memory, pidevmode, devmode_size, 1, "win_pr2_getdc"); gs_free(wdev->memory, podevmode, devmode_size, 1, "win_pr2_getdc"); if (wdev->hdcprn != (HDC) NULL) return TRUE; /* success */ /* fall back to prompting user */ return FALSE; }
/* Send the page to the printer. */ static int jj100_print_page(gx_device_printer *pdev, FILE *prn_stream) { int line_size = gdev_prn_raster(pdev); int height = pdev->height; int bits_per_column = 48; int bytes_per_column = bits_per_column / 8; int chunk_size = bits_per_column * line_size; byte *in, *out; int lnum, skip; char prn_buf[16]; in = (byte *) gs_malloc(gs_lib_ctx_get_non_gc_memory_t(), bits_per_column, line_size, "jj100_print_page(in)"); out = (byte *) gs_malloc(gs_lib_ctx_get_non_gc_memory_t(), bits_per_column, line_size, "jj100_print_page(out)"); if(in == 0 || out == 0) return -1; /* Initialize printer */ fputs("\033P", pdev->file); /* Proportional Mode */ fputs("\033G", pdev->file); /* 1/180 inch per line */ fputs("\033T16", pdev->file); /* 16/180 inch per line */ /* Send Data to printer */ lnum = 0; skip = 0; while(lnum < height) { byte *inp, *outp, *out_beg, *out_end; int x, y, num_lines, size, mod; /* Copy scan lines */ if(gdev_prn_copy_scan_lines(pdev, lnum, in, chunk_size) < 0) break; /* The number of lines to process */ if((num_lines = height - lnum) > bits_per_column) num_lines = bits_per_column; /* Test for all zero */ size = line_size * num_lines; if(in[0] == 0 && !memcmp((char *)in, (char *)in + 1, size - 1)) { lnum += bits_per_column; skip ++; continue; } /* Fill zero */ if(num_lines < bits_per_column) { size = line_size * (bits_per_column - num_lines); memset(in + line_size * num_lines, 0, size); } lnum += bits_per_column; /* Vertical tab to the appropriate position. */ while(skip > 15) { sprintf(prn_buf, "\037%c", 16 + 15); fputs(prn_buf, pdev->file); skip -= 15; } if(skip > 0) { sprintf(prn_buf, "\037%c", 16 + skip); fputs(prn_buf, pdev->file); } /* Transpose in blocks of 8 scan lines. */ for(y = 0; y < bytes_per_column; y ++) { inp = in + line_size * 8 * y; outp = out + y; for(x = 0; x < line_size; x ++) { jj100_transpose_8x8(inp, line_size, outp, bytes_per_column); inp ++; outp += bits_per_column; } } /* Remove trailing 0s. */ out_end = out + chunk_size - 1; while(out_end >= out) { if(*out_end) break; out_end --; } size = (out_end - out) + 1; if((mod = size % bytes_per_column) != 0) out_end += bytes_per_column - mod; /* Remove leading 0s. */ out_beg = out; while(out_beg <= out_end) { if(*out_beg) break; out_beg ++; } out_beg -= (out_beg - out) % (bytes_per_column * 2); /* Dot addressing */ sprintf(prn_buf, "\033F%04d", (out_beg - out) / bytes_per_column / 2); fputs(prn_buf, pdev->file); /* Dot graphics */ size = out_end - out_beg + 1; sprintf(prn_buf, "\034bP,48,%04d.", size / bytes_per_column); fputs(prn_buf, pdev->file); fwrite(out_beg, 1, size, pdev->file); /* Carriage Return */ fputc('\r', pdev->file); skip = 1; } /* Form Feed */ fputc('\f', pdev->file); fflush(pdev->file); gs_free(gs_lib_ctx_get_non_gc_memory_t(), (char *)out, bits_per_column, line_size, "jj100_print_page(out)"); gs_free(gs_lib_ctx_get_non_gc_memory_t(), (char *)in, bits_per_column, line_size, "jj100_print_page(in)"); return 0; }
static void gs_x_free(gs_memory_t *mem, void *obj, client_name_t cname) { gs_free(mem, obj, 0 /*ignored*/, 0 /*ignored*/, cname); }
/* Render a character. */ static int x_render_char(gx_xfont * xf, gx_xglyph xg, gx_device * dev, int xo, int yo, gx_color_index color, int required) { x_xfont *xxf = (x_xfont *) xf; char chr = (char)xg; gs_point wxy; gs_int_rect bbox; int x, y, w, h; int code; if (dev->dname == gs_x11_device.dname && !((gx_device_X *)dev)->is_buffered) { gx_device_X *xdev = (gx_device_X *)dev; code = (*xf->common.procs->char_metrics) (xf, xg, 0, &wxy, &bbox); if (code < 0) return code; /* Buffer text for more efficient X interaction. */ if (xdev->text.item_count == MAX_TEXT_ITEMS || xdev->text.char_count == MAX_TEXT_CHARS || (IN_TEXT(xdev) && (yo != xdev->text.origin.y || color != xdev->fore_color || xxf->font->fid != xdev->fid)) ) { DRAW_TEXT(xdev); xdev->text.item_count = xdev->text.char_count = 0; } if (xdev->text.item_count == 0) { X_SET_FILL_STYLE(xdev, FillSolid); X_SET_FORE_COLOR(xdev, color); X_SET_FUNCTION(xdev, GXcopy); xdev->text.origin.x = xdev->text.x = xo; xdev->text.origin.y = yo; xdev->text.items[0].font = xdev->fid = xxf->font->fid; } /* * The following is wrong for rotated text, but it doesn't matter, * because the next call of x_render_char will have a different Y. */ { int index = xdev->text.item_count; XTextItem *item = &xdev->text.items[index]; char *pchar = &xdev->text.chars[xdev->text.char_count++]; int delta = xo - xdev->text.x; *pchar = chr; if (index > 0 && delta == 0) { /* Continue the same item. */ item[-1].nchars++; } else { /* Start a new item. */ item->chars = pchar; item->nchars = 1; item->delta = delta; if (index > 0) item->font = None; xdev->text.item_count++; } xdev->text.x = xo + wxy.x; } if (xdev->bpixmap != (Pixmap) 0) { x = xo + bbox.p.x; y = yo + bbox.p.y; w = bbox.q.x - bbox.p.x; h = bbox.q.y - bbox.p.y; fit_fill(dev, x, y, w, h); x_update_add(xdev, x, y, w, h); } return 0; } else if (!required) return -1; /* too hard */ else { /* Display on an intermediate bitmap, then copy the bits. */ gx_device_X *xdev = xxf->xdev; int wbm, raster; int i; XImage *xim; Pixmap xpm; GC fgc; byte *bits; dev_proc_copy_mono((*copy_mono)) = dev_proc(dev, copy_mono); code = (*xf->common.procs->char_metrics) (xf, xg, 0, &wxy, &bbox); if (code < 0) return code; w = bbox.q.x - bbox.p.x; h = bbox.q.y - bbox.p.y; wbm = ROUND_UP(w, align_bitmap_mod * 8); raster = wbm >> 3; bits = (byte *) gs_malloc(xdev->memory, h, raster, "x_render_char"); if (bits == 0) return gs_error_limitcheck; xpm = XCreatePixmap(xdev->dpy, xdev->win, w, h, 1); fgc = XCreateGC(xdev->dpy, xpm, None, NULL); XSetForeground(xdev->dpy, fgc, 0); XFillRectangle(xdev->dpy, xpm, fgc, 0, 0, w, h); XSetForeground(xdev->dpy, fgc, 1); XSetFont(xdev->dpy, fgc, xxf->font->fid); XDrawString(xdev->dpy, xpm, fgc, -bbox.p.x, -bbox.p.y, &chr, 1); xim = XGetImage(xdev->dpy, xpm, 0, 0, w, h, 1, ZPixmap); i = 0; for (y = 0; y < h; y++) { char b = 0; for (x = 0; x < wbm; x++) { b = b << 1; if (x < w) b += XGetPixel(xim, x, y); if ((x & 7) == 7) bits[i++] = b; } } code = (*copy_mono) (dev, bits, 0, raster, gx_no_bitmap_id, xo + bbox.p.x, yo + bbox.p.y, w, h, gx_no_color_index, color); gs_free(xdev->memory, (char *)bits, h, raster, "x_render_char"); XFreePixmap(xdev->dpy, xpm); XFreeGC(xdev->dpy, fgc); XDestroyImage(xim); return (code < 0 ? code : 0); } }
/* Send the page to the printer. */ static int fmlbp_print_page(gx_device_printer *pdev, FILE *prn_stream) { int line_size = gdev_mem_bytes_per_scan_line((gx_device *)pdev); #ifdef FMLBP_NOPAPERSIZE char data[LINE_SIZE*2]; #else byte *data = (byte *)gs_malloc(gs_lib_ctx_get_non_gc_memory_t(), 1, line_size, "fmlpr_print_page(data)"); if(data == NULL) return_error(gs_error_VMerror); #endif/*FMLBP_NOPAPERSIZE*/ /* initialize */ fwrite(can_inits, sizeof(can_inits), 1, prn_stream); fprintf(prn_stream, "%c%c%d!I", PU1, 0); /* 100% */ #ifndef OLD_FMLBP_400DPI fprintf(prn_stream, "%c%c%d!A", PU1, (int)(pdev->x_pixels_per_inch)); /* 240dpi or 400dpi */ #endif/*!OLD_FMLBP_400DPI*/ #ifndef FMLBP_NOPAPERSIZE fprintf(prn_stream, "%c%c%s!F", PU1, gdev_fmlbp_paper_size(pdev)); /* Paper size */ #endif/*!FMLBP_NOPAPERSIZE*/ /* Send each scan line in turn */ { int lnum; byte rmask = (byte)(0xff << (-pdev->width & 7)); for ( lnum = 0; lnum < pdev->height; lnum++ ) { byte *end_data = data + line_size; int s = gdev_prn_copy_scan_lines(pdev, lnum, (byte *)data, line_size); if(s < 0) return_error(s); /* Mask off 1-bits beyond the line width. */ end_data[-1] &= rmask; /* Remove trailing 0s. */ while ( end_data > data && end_data[-1] == 0 ) end_data--; if ( end_data != data ) { int num_cols = 0; int out_count = 0; byte *out_data = data; while(out_data < end_data && *out_data == 0) { num_cols += 8; out_data++; } out_count = end_data - out_data; /* move down */ /* move across */ goto_xy(prn_stream, num_cols, lnum); /* transfer raster graphics */ fprintf(prn_stream, "%c%c%d;%d;0!a", PU1, out_count, out_count*8 ); /* send the row */ fwrite(out_data, sizeof(byte), out_count, prn_stream); } } } /* eject page */ fputc(0x0c,prn_stream); fflush(prn_stream); #ifndef FMLBP_NOPAPERSIZE gs_free(gs_lib_ctx_get_non_gc_memory_t(), (char *)data, line_size, sizeof(byte), "fmlbp_print_page(data)"); #endif/*!FMLBP_NOPAPERSIZE*/ return 0; }
int eprn_open_device(gx_device *device) { eprn_Eprn *eprn = &((eprn_Device *)device)->eprn; const char *epref = eprn->CUPS_messages? CUPS_ERRPREF: ""; int rc; #ifdef EPRN_TRACE if_debug0(EPRN_TRACE_CHAR, "! eprn_open_device()...\n"); #endif /* Checks on page size and determination of derived values */ if (eprn_set_page_layout((eprn_Device *)device) != 0) return_error(gs_error_rangecheck); /* Check the rendering parameters */ if (eprn_check_colour_info(eprn->cap->colour_info, &eprn->colour_model, &device->HWResolution[0], &device->HWResolution[1], &eprn->black_levels, &eprn->non_black_levels) != 0) { gs_param_string str; eprintf1("%s" ERRPREF "The requested combination of colour model (", epref); str.size = 0; if (eprn_get_string(eprn->colour_model, eprn_colour_model_list, &str) != 0) assert(0); /* Bug. No harm on NDEBUG because I've just set the size. */ errwrite(device->memory, (const char *)str.data, str.size * sizeof(str.data[0])); eprintf7("),\n" "%s resolution (%gx%g ppi) and intensity levels (%d, %d) is\n" "%s not supported by the %s.\n", epref, device->HWResolution[0], device->HWResolution[1], eprn->black_levels, eprn->non_black_levels, epref, eprn->cap->name); return_error(gs_error_rangecheck); } /* Initialization for colour rendering */ if (device->color_info.num_components == 4) { /* Native colour space is 'DeviceCMYK' */ set_dev_proc(device, map_rgb_color, NULL); if (eprn->intensity_rendering == eprn_IR_FloydSteinberg) set_dev_proc(device, map_cmyk_color, &eprn_map_cmyk_color_max); else if (device->color_info.max_gray > 1 || device->color_info.max_color > 1) set_dev_proc(device, map_cmyk_color, &eprn_map_cmyk_color_flex); else set_dev_proc(device, map_cmyk_color, &eprn_map_cmyk_color); if (eprn->intensity_rendering == eprn_IR_FloydSteinberg) set_dev_proc(device, map_rgb_color, &eprn_map_rgb_color_for_CMY_or_K_max); else if (device->color_info.max_gray > 1 || device->color_info.max_color > 1) set_dev_proc(device, map_rgb_color, &eprn_map_rgb_color_for_CMY_or_K_flex); else set_dev_proc(device, map_rgb_color, &eprn_map_rgb_color_for_CMY_or_K); } else { set_dev_proc(device, map_cmyk_color, NULL); if (eprn->colour_model == eprn_DeviceRGB) { if (eprn->intensity_rendering == eprn_IR_FloydSteinberg) set_dev_proc(device, map_rgb_color, &eprn_map_rgb_color_for_RGB_max); else if (device->color_info.max_color > 1) set_dev_proc(device, map_rgb_color, &eprn_map_rgb_color_for_RGB_flex); else set_dev_proc(device, map_rgb_color, &eprn_map_rgb_color_for_RGB); } else { if (eprn->intensity_rendering == eprn_IR_FloydSteinberg) set_dev_proc(device, map_rgb_color, &eprn_map_rgb_color_for_CMY_or_K_max); else if (device->color_info.max_gray > 1 || device->color_info.max_color > 1) set_dev_proc(device, map_rgb_color, &eprn_map_rgb_color_for_CMY_or_K_flex); else set_dev_proc(device, map_rgb_color, &eprn_map_rgb_color_for_CMY_or_K); } } eprn->output_planes = eprn_bits_for_levels(eprn->black_levels) + 3 * eprn_bits_for_levels(eprn->non_black_levels); #if !defined(GS_REVISION) || GS_REVISION >= 600 /* According to my understanding, the following call should be superfluous (because the colour mapping functions may not be called while the device is closed) and I am also not aware of any situation where it does make a difference. It shouldn't do any harm, though, and I feel safer with it :-) */ gx_device_decache_colors(device); #endif #ifndef EPRN_NO_PAGECOUNTFILE /* Read the page count value */ if (eprn->pagecount_file != NULL) { unsigned long count; if (pcf_getcount(eprn->pagecount_file, &count) == 0) device->PageCount = count; /* unsigned to signed. The C standard permits an implementation to generate an overflow indication if the value is too large. I consider this to mean that the type of 'PageCount' is inappropriate :-). Note that eprn does not use 'PageCount' for updating the file. */ else { /* pcf_getcount() has issued an error message. */ eprintf( " No further attempts will be made to access the page count file.\n"); gs_free(device->memory->non_gc_memory, eprn->pagecount_file, strlen(eprn->pagecount_file) + 1, sizeof(char), "eprn_open_device"); eprn->pagecount_file = NULL; } } #endif /* !EPRN_NO_PAGECOUNTFILE */ /* Open the "prn" device part */ if ((rc = gdev_prn_open(device)) != 0) return rc; /* Just in case a previous open call failed in a derived device (note that 'octets_per_line' is still the same as then): */ if (eprn->scan_line.str != NULL) gs_free(device->memory->non_gc_memory, eprn->scan_line.str, eprn->octets_per_line, sizeof(eprn_Octet), "eprn_open_device"); if (eprn->next_scan_line.str != NULL) { gs_free(device->memory->non_gc_memory, eprn->next_scan_line.str, eprn->octets_per_line, sizeof(eprn_Octet), "eprn_open_device"); eprn->next_scan_line.str = NULL; } /* Calls which might depend on prn having been initialized */ eprn->octets_per_line = gdev_prn_raster((gx_device_printer *)device); eprn->scan_line.str = (eprn_Octet *) gs_malloc(device->memory->non_gc_memory, eprn->octets_per_line, sizeof(eprn_Octet), "eprn_open_device"); if (eprn->intensity_rendering == eprn_IR_FloydSteinberg) { eprn->next_scan_line.str = (eprn_Octet *) gs_malloc(device->memory->non_gc_memory, eprn->octets_per_line, sizeof(eprn_Octet), "eprn_open_device"); if (eprn->next_scan_line.str == NULL && eprn->scan_line.str != NULL) { gs_free(device->memory->non_gc_memory, eprn->scan_line.str, eprn->octets_per_line, sizeof(eprn_Octet), "eprn_open_device"); eprn->scan_line.str = NULL; } } if (eprn->scan_line.str == NULL) { eprintf1("%s" ERRPREF "Memory allocation failure from gs_malloc() in eprn_open_device().\n", epref); return_error(gs_error_VMerror); } return rc; }
int gs_display(char *file, gs_t * gs) { int32 i; int32 code_id; int32 m_id, s_id, c_id; float32 tmp; bitvec_t *bv; E_INFO("Reading gaussian selector map: %s\n", file); gs = (gs_t *) ckd_calloc(1, sizeof(gs_t)); if ((gs->fp = fopen(file, "rb")) == NULL) E_FATAL("fopen(%s,rb) failed\n", file); gs->n_mgau = gs_fread_int32(gs); E_INFO("The number of mixtures of gaussian: %d\n", gs->n_mgau); gs->n_feat = gs_fread_int32(gs); E_INFO("The number of features stream: %d\n", gs->n_feat); gs->n_density = gs_fread_int32(gs); E_INFO("The number of density: %d\n", gs->n_density); gs->n_code = gs_fread_int32(gs); E_INFO("The number of code word: %d\n", gs->n_code); gs->n_featlen = gs_fread_int32(gs); E_INFO("The feature length: %d\n", gs->n_featlen); gs->n_mbyte = bitvec_size(gs->n_density) * sizeof(bitvec_t); E_INFO("The number of byte to read: %d\n", gs->n_mbyte); /* allocate the bit vector here */ bv = bitvec_alloc(gs->n_density); /* for(i=0;i<gs->n_code;i++) */ for (code_id = 0; code_id < gs->n_code; code_id++) { printf("Code idx: %d\n", code_id); for (c_id = 0; c_id < gs->n_featlen; c_id++) { tmp = gs_fread_float32(gs); printf("%f ", tmp); } printf("\n"); for (m_id = 0; m_id < gs->n_mgau; m_id++) { for (s_id = 0; s_id < gs->n_feat; s_id++) { /*The writer currently doesn't support the byte order */ gs_fread_bitvec_t(bv, gs); printf("%d %d ", m_id, s_id); for (i = 0; i < gs->n_density; i++) { if (bitvec_is_set(bv, i)) { printf("%d ", i); } } printf("\n"); } } } printf("\n"); /* bitvec_free(bv); */ /* destroy the bit vector here */ gs_free(gs); return 1; }
/* * Release group iter. */ void nc_free_giter(ncgiter_t *iterp) { gs_free(iterp); }
/* Send the page to the printer. For speed, compress each scan line, since computer-to-printer communication time is often a bottleneck. */ static int npdl_print_page_copies(gx_device_printer * pdev, FILE * prn_stream, int num_copies) { gx_device_lprn *const lprn = (gx_device_lprn *) pdev; int line_size = gdev_prn_raster(pdev); int x_dpi = (int)(pdev->x_pixels_per_inch); char paper_command[5]; int code; int maxY = lprn->BlockLine / lprn->nBh * lprn->nBh; if (!(lprn->CompBuf = gs_malloc(pdev->memory->non_gc_memory, line_size * maxY, sizeof(byte), "npdl_print_page_copies(CompBuf)"))) return_error(gs_error_VMerror); /* Initialize printer */ if (pdev->PageCount == 0) { /* Initialize printer */ fputs("\033c1", prn_stream); /* Software Reset */ fputs("\034d240.", prn_stream); /* Page Printer Mode */ /* Check paper size */ switch (npdl_get_paper_size((gx_device *) pdev)) { case PAPER_SIZE_POSTCARD: gs_sprintf(paper_command, "PC"); break; case PAPER_SIZE_A5: gs_sprintf(paper_command, "A5"); break; case PAPER_SIZE_A4: gs_sprintf(paper_command, "A4"); break; case PAPER_SIZE_A3: gs_sprintf(paper_command, "A3"); break; case PAPER_SIZE_B5: gs_sprintf(paper_command, "B5"); break; case PAPER_SIZE_B4: gs_sprintf(paper_command, "B4"); break; case PAPER_SIZE_LETTER: gs_sprintf(paper_command, "LT"); break; case PAPER_SIZE_ENV4: gs_sprintf(paper_command, "ENV4"); break; case PAPER_SIZE_BPOSTCARD: gs_sprintf(paper_command, "UPPC"); break; } if (lprn->ManualFeed) { fprintf(prn_stream, "\034f%cM0.", (pdev->MediaSize[0] > pdev->MediaSize[1]) ? 'L' : 'P'); /* Page Orientation P: Portrait, L: Landscape */ } else { fprintf(prn_stream, "\034f%c%s.", (pdev->MediaSize[0] > pdev->MediaSize[1]) ? 'L' : 'P', /* Page Orientation P: Portrait, L: Landscape */ paper_command); /* Paper Size */ } fprintf(prn_stream, "\034<1/%d,i.", x_dpi); /* Image Resolution */ /* Duplex Setting */ if (pdev->Duplex_set > 0) { if (pdev->Duplex) { if (lprn->Tumble == 0) fprintf(prn_stream, "\034'B,,1,0."); else fprintf(prn_stream, "\034'B,,2,0."); } else fprintf(prn_stream, "\034'S,,,0."); } } if (num_copies > 99) num_copies = 99; fprintf(prn_stream, "\034x%d.", num_copies); lprn->initialized = false; if (lprn->NegativePrint) { fprintf(prn_stream, "\034e0,0."); /* move to (0, 0) */ fprintf(prn_stream, "\034Y"); /* goto figure mode */ fprintf(prn_stream, "SU1,%d,0;", (int)pdev->x_pixels_per_inch); /* Setting Printer Unit */ fprintf(prn_stream, "SG0,0;"); /* select black color */ fprintf(prn_stream, "NP;"); /* begin path */ fprintf(prn_stream, "PA%d,0,%d,%d,0,%d;", pdev->width, pdev->width, pdev->height, pdev->height); /* draw rectangle */ fprintf(prn_stream, "CP"); /* close path */ fprintf(prn_stream, "EP;"); /* end path */ fprintf(prn_stream, "FL0;"); /* fill path */ fprintf(prn_stream, "\034Z"); /* end of figure mode */ fprintf(prn_stream, "\034\"R."); /* `R'eplace Mode */ } code = lprn_print_image(pdev, prn_stream); if (code < 0) return code; /* Form Feed */ fputs("\014", prn_stream); gs_free(pdev->memory->non_gc_memory, lprn->CompBuf, line_size * maxY, sizeof(byte), "npdl_print_page_copies(CompBuf)"); return 0; }