/* =item i_tt_push_error(code) Push an error message and code onto the Imager error stack. =cut */ static void i_tt_push_error(TT_Error rc) { #ifdef FTXERR18 TT_String const *msg = TT_ErrToString18(rc); i_push_error(rc, msg); #else i_push_errorf(rc, "Error code 0x%04x", (unsigned)rc); #endif }
unsigned long imss_x11_open(char const *display_name) { XErrorHandler old_handler; Display *display; i_clear_error(); old_handler = XSetErrorHandler(my_handler); display = XOpenDisplay(display_name); if (!display) i_push_errorf(0, "Cannot connect to X server %s", XDisplayName(display_name)); XSetErrorHandler(old_handler); return (unsigned long)display; }
i_img* i_transform2(i_img_dim width, i_img_dim height, int channels, struct rm_op *ops, int ops_count, double *n_regs, int n_regs_count, i_color *c_regs, int c_regs_count, i_img **in_imgs, int in_imgs_count) { i_img *new_img; i_img_dim x, y; i_color val; int i; int need_images; i_clear_error(); /* since the number of images is variable and the image numbers for getp? are fixed, we can check them here instead of in the register machine - this will help performance */ need_images = 0; for (i = 0; i < ops_count; ++i) { switch (ops[i].code) { case rbc_getp1: case rbc_getp2: case rbc_getp3: if (ops[i].code - rbc_getp1 + 1 > need_images) { need_images = ops[i].code - rbc_getp1 + 1; } } } if (need_images > in_imgs_count) { i_push_errorf(0, "not enough images, code requires %d, %d supplied", need_images, in_imgs_count); return NULL; } new_img = i_img_empty_ch(NULL, width, height, channels); for (x = 0; x < width; ++x) { for (y = 0; y < height; ++y) { n_regs[0] = x; n_regs[1] = y; val = i_rm_run(ops, ops_count, n_regs, n_regs_count, c_regs, c_regs_count, in_imgs, in_imgs_count); i_ppix(new_img, x, y, &val); } } return new_img; }
size_t i_tt_glyph_name(TT_Fonthandle *handle, unsigned long ch, char *name_buf, size_t name_buf_size) { #ifdef FTXPOST TT_Error rc; TT_String *psname; TT_UShort index; i_clear_error(); if (!handle->loaded_names) { TT_Post post; mm_log((1, "Loading PS Names")); handle->load_cond = TT_Load_PS_Names(handle->face, &post); ++handle->loaded_names; } if (handle->load_cond) { i_push_errorf(handle->load_cond, "error loading names (%#x)", (unsigned)handle->load_cond); return 0; } index = TT_Char_Index(handle->char_map, ch); if (!index) { i_push_error(0, "no such character"); return 0; } rc = TT_Get_PS_Name(handle->face, index, &psname); if (rc) { i_push_error(rc, "error getting name"); return 0; } strncpy(name_buf, psname, name_buf_size); name_buf[name_buf_size-1] = '\0'; return strlen(psname) + 1; #else mm_log((1, "FTXPOST extension not enabled\n")); i_clear_error(); i_push_error(0, "Use of FTXPOST extension disabled"); return 0; #endif }
undef_int i_tt_bbox( TT_Fonthandle *handle, double points,const char *txt,size_t len,i_img_dim cords[6], int utf8) { int inst; i_clear_error(); mm_log((1,"i_tt_box(handle %p,points %f,txt '%.*s', len %ld, utf8 %d)\n", handle, points, (int)len, txt, (long)len, utf8)); if ( (inst=i_tt_get_instance(handle,points,-1)) < 0) { i_push_errorf(0, "i_tt_get_instance(%g)", points); mm_log((1,"i_tt_text: get instance failed\n")); return 0; } return i_tt_bbox_inst(handle, inst, txt, len, cords, utf8); }
i_img * imss_darwin(i_img_dim left, i_img_dim top, i_img_dim right, i_img_dim bottom) { CGDisplayCount count; CGDisplayErr err; CGRect rect; CGLPixelFormatObj pix; GLint npix; CGLContextObj ctx; i_img *im; CGDirectDisplayID disp; i_img_dim screen_width, screen_height; i_img_dim width, height; CGLPixelFormatAttribute pix_attrs[] = { kCGLPFADisplayMask, 0, /* filled in later */ kCGLPFAColorSize, 24, kCGLPFAAlphaSize, 0, kCGLPFAFullScreen, 0 }; i_clear_error(); disp = CGMainDisplayID(); if (!disp) { i_push_error(0, "No main display"); return NULL; } /* for now, only interested in the first display */ rect = CGDisplayBounds(disp); screen_width = rect.size.width; screen_height = rect.size.height; /* adjust negative/zero values to window size */ if (left < 0) left += screen_width; if (top < 0) top += screen_height; if (right <= 0) right += screen_width; if (bottom <= 0) bottom += screen_height; /* clamp */ if (left < 0) left = 0; if (right > screen_width) right = screen_width; if (top < 0) top = 0; if (bottom > screen_height) bottom = screen_height; /* validate */ if (right <= left || bottom <= top) { i_push_error(0, "image would be empty"); return NULL; } width = right - left; height = bottom - top; /* select a pixel format */ pix_attrs[1] = CGDisplayIDToOpenGLDisplayMask(disp); err = CGLChoosePixelFormat(pix_attrs, &pix, &npix); if (err) { i_push_errorf(err, "CGLChoosePixelFormat: %d", (int)err); return NULL; } if (!npix) { i_push_error(0, "No pixel format found - hidden display?"); return NULL; } /* make ourselves a context */ err = CGLCreateContext(pix, NULL, &ctx); CGLDestroyPixelFormat(pix); if (err) { i_push_errorf(err, "CGLCreateContext: %d", (int)err); return NULL; } err = CGLSetCurrentContext(ctx); if (err) { i_push_errorf(err, "CGLSetCurrentContext: %d", (int)err); return NULL; } err = CGLSetFullScreen(ctx); if (err) { i_push_errorf(err, "CGLSetFullScreen: %d", (int)err); return NULL; } /* capture */ im = i_img_8_new(width, height, 3); if (im) { size_t line_size = width * 4; size_t buf_size = line_size * height; unsigned char *buf = malloc(buf_size); i_img_dim y = height - 1; i_color *bufp = (i_color *)buf; /* hackish */ /* GL has the vertical axis going from bottom to top, so translate it */ glReadBuffer(GL_FRONT); glReadPixels(left, screen_height - top - height, width, height, GL_RGBA, GL_UNSIGNED_BYTE, buf); /* transfer */ while (y >= 0) { i_plin(im, 0, width, y, bufp); bufp += width; --y; } free(buf); i_tags_setn(&im->tags, "ss_window_width", width); i_tags_setn(&im->tags, "ss_window_height", height); i_tags_set(&im->tags, "ss_type", "Darwin", 6); i_tags_set(&im->tags, "ss_variant", "<11", 3); i_tags_setn(&im->tags, "ss_left", left); i_tags_setn(&im->tags, "ss_top", top); } /* clean up */ CGLSetCurrentContext(NULL); CGLDestroyContext(ctx); return im; }
static void t1_push_error(void) { #if T1LIB_VERSION > 5 || T1LIB_VERSION == 5 && T1LIB_VERSION >= 1 /* I don't know when T1_StrError() was introduced, be conservative */ i_push_error(T1_errno, T1_StrError(T1_errno)); #else switch (T1_errno) { case 0: i_push_error(0, "No error"); break; #ifdef T1ERR_SCAN_FONT_FORMAT case T1ERR_SCAN_FONT_FORMAT: i_push_error(T1ERR_SCAN_FONT_FORMAT, "Attempt to Load Multiple Master Font"); break; #endif #ifdef T1ERR_SCAN_FILE_OPEN_ERR case T1ERR_SCAN_FILE_OPEN_ERR: i_push_error(T1ERR_SCAN_FILE_OPEN_ERR, "Type 1 Font File Open Error"); break; #endif #ifdef T1ERR_SCAN_OUT_OF_MEMORY case T1ERR_SCAN_OUT_OF_MEMORY: i_push_error(T1ERR_SCAN_OUT_OF_MEMORY, "Virtual Memory Exceeded"); break; #endif #ifdef T1ERR_SCAN_ERROR case T1ERR_SCAN_ERROR: i_push_error(T1ERR_SCAN_ERROR, "Syntactical Error Scanning Font File"); break; #endif #ifdef T1ERR_SCAN_FILE_EOF case T1ERR_SCAN_FILE_EOF: i_push_error(T1ERR_SCAN_FILE_EOF, "Premature End of Font File Encountered"); break; #endif #ifdef T1ERR_PATH_ERROR case T1ERR_PATH_ERROR: i_push_error(T1ERR_PATH_ERROR, "Path Construction Error"); break; #endif #ifdef T1ERR_PARSE_ERROR case T1ERR_PARSE_ERROR: i_push_error(T1ERR_PARSE_ERROR, "Font is Corrupt"); break; #endif #ifdef T1ERR_TYPE1_ABORT case T1ERR_TYPE1_ABORT: i_push_error(T1ERR_TYPE1_ABORT, "Rasterization Aborted"); break; #endif #ifdef T1ERR_INVALID_FONTID case T1ERR_INVALID_FONTID: i_push_error(T1ERR_INVALID_FONTID, "Font ID Invalid in this Context"); break; #endif #ifdef T1ERR_INVALID_PARAMETER case T1ERR_INVALID_PARAMETER: i_push_error(T1ERR_INVALID_PARAMETER, "Invalid Argument in Function Call"); break; #endif #ifdef T1ERR_OP_NOT_PERMITTED case T1ERR_OP_NOT_PERMITTED: i_push_error(T1ERR_OP_NOT_PERMITTED, "Operation not Permitted"); break; #endif #ifdef T1ERR_ALLOC_MEM case T1ERR_ALLOC_MEM: i_push_error(T1ERR_ALLOC_MEM, "Memory Allocation Error"); break; #endif #ifdef T1ERR_FILE_OPEN_ERR case T1ERR_FILE_OPEN_ERR: i_push_error(T1ERR_FILE_OPEN_ERR, "Error Opening File"); break; #endif #ifdef T1ERR_UNSPECIFIED case T1ERR_UNSPECIFIED: i_push_error(T1ERR_UNSPECIFIED, "Unspecified T1Lib Error"); break; #endif #ifdef T1ERR_NO_AFM_DATA case T1ERR_NO_AFM_DATA: i_push_error(T1ERR_NO_AFM_DATA, "Missing AFM Data"); break; #endif #ifdef T1ERR_X11 case T1ERR_X11: i_push_error(T1ERR_X11, "X11 Interface Error"); break; #endif #ifdef T1ERR_COMPOSITE_CHAR case T1ERR_COMPOSITE_CHAR: i_push_error(T1ERR_COMPOSITE_CHAR, "Missing Component of Composite Character"); break; #endif #ifdef T1ERR_SCAN_ENCODING case T1ERR_SCAN_ENCODING: i_push_error(T1ERR_SCAN_ENCODING, "Error Scanning Encoding File"); break; #endif default: i_push_errorf(T1_errno, "unknown error %d", (int)T1_errno); } #endif }