int pdf_imagebbox(lua_State *L) { const char* filename = luaL_checkstring(L, 1); double llx = 0; double lly = 0; double urx = 0; double ury = 0; FILE* f = MFOPEN(filename, FOPEN_RBIN_MODE); if (!f) { return luaL_error(L, "Image file not found %s", filename); } if ( get_image_bbox(f, &llx, &lly, &urx, &ury) < 0 ) { MFCLOSE(f); return luaL_error(L, "Invalid image file %s", filename); } MFCLOSE(f); lua_pushnumber(L, llx); lua_pushnumber(L, lly); lua_pushnumber(L, urx); lua_pushnumber(L, ury); return 4; }
int pdf_font_open_pkfont (pdf_font *font) { char *ident; double point_size; int encoding_id; unsigned dpi; FILE *fp; ident = pdf_font_get_ident(font); point_size = pdf_font_get_param(font, PDF_FONT_PARAM_POINT_SIZE); encoding_id = pdf_font_get_encoding(font); if (!ident || point_size <= 0.0) return -1; { char *fontfile = pdf_font_get_fontfile (font); char *tfmfile = pdf_font_get_tfmfile (font); if (fontfile) fp = MFOPEN(fontfile, FOPEN_RBIN_MODE); else fp = dpx_open_pk_font_at(ident, dpi); if (tfmfile) dpi = truedpi(tfmfile, point_size, base_dpi); else dpi = base_dpi; } if (!fp) return -1; MFCLOSE(fp); /* Type 3 fonts doesn't have FontName. * FontFamily is recommended for PDF 1.5. */ pdf_font_set_fontname(font, ident); if (encoding_id >= 0) { pdf_encoding_used_by_type3(encoding_id); WARN("PK font is found for font \"%s\" but non built-in encoding \"%s\" is specified.", ident, pdf_encoding_get_name(encoding_id)); #if ENABLE_GLYPHENC WARN(">> Assuming this is for glyph name assignment."); #else WARN(">> I can't reencode PK font. (not enough information available)"); WARN(">> Maybe you need to install pfb/opentype/truetype font."); #endif } return 0; }
static unsigned truedpi (const char *ident, double point_size, unsigned bdpi) { unsigned dpi = bdpi; double design_size; int tfm_id; tfm_id = MFOPEN(ident, FOPEN_RBIN_MODE); if (tfm_id < 0) return dpi; design_size = tfm_get_design_size(tfm_id); MFCLOSE(tfm_id); if (design_size <= 0.0) WARN("DESGIN_SIZE <= 0.0? (TFM=\"%s\")", ident); else { dpi = (unsigned) ROUND(base_dpi * point_size / design_size, 1.0); } return dpi; }