Exemplo n.º 1
0
int pdf_destination(lua_State *L) {
  pdf_obj* array = texpdf_new_array();
  const char* name = luaL_checkstring(L, 1);
  double x = luaL_checknumber(L, 2);
  double y = luaL_checknumber(L, 3);
  
  texpdf_add_array(array, texpdf_doc_this_page_ref(p));
  texpdf_add_array(array, texpdf_new_name("XYZ"));
  texpdf_add_array(array, texpdf_new_number(x));
  texpdf_add_array(array, texpdf_new_number(y));
  texpdf_add_array(array, texpdf_new_null());
  texpdf_doc_add_names(p, "Dests",
                    name,
                    strlen(name),
                    array);
  return 0;
}
Exemplo n.º 2
0
int pdf_push_array(lua_State *L) {
  pdf_obj* array = lua_touserdata(L, 1);
  if (!PDF_OBJ_ARRAYTYPE(array)) {
    return luaL_error(L, "push_array called on non-array");
  }
  pdf_obj* val = lua_touserdata(L, 2);
  texpdf_add_array(array, val);
  return 0;
}
Exemplo n.º 3
0
int
jpeg_include_image (pdf_ximage *ximage, FILE *fp)
{
  pdf_obj         *stream;
  pdf_obj         *stream_dict;
  pdf_obj         *colorspace;
  int              colortype;
  ximage_info      info;
  struct JPEG_info j_info;

  if (!texpdf_check_for_jpeg(fp)) {
    WARN("%s: Not a JPEG file?", JPEG_DEBUG_STR);
    rewind(fp);
    return -1;
  }
  /* File position is 2 here... */

  texpdf_ximage_init_image_info(&info);

  JPEG_info_init(&j_info);

  if (JPEG_scan_file(&j_info, fp) < 0) {
    WARN("%s: Not a JPEG file?", JPEG_DEBUG_STR);
    JPEG_info_clear(&j_info);
    return -1;
  }

  switch (j_info.num_components) {
  case 1:
    colortype = PDF_COLORSPACE_TYPE_GRAY;
    break;
  case 3:
    colortype = PDF_COLORSPACE_TYPE_RGB;
    break;
  case 4:
    colortype = PDF_COLORSPACE_TYPE_CMYK;
    break;
  default:
    WARN("%s: Unknown color space (num components: %d)", JPEG_DEBUG_STR, info.num_components);
    JPEG_info_clear(&j_info);
    return -1;
  }

  /* JPEG image use DCTDecode. */
  stream      = texpdf_new_stream (0);
  stream_dict = texpdf_stream_dict(stream);
  texpdf_add_dict(stream_dict,
	       texpdf_new_name("Filter"), texpdf_new_name("DCTDecode"));

  /* XMP Metadata */
  if (texpdf_get_version() >= 4) {
    if (j_info.flags & HAVE_APPn_XMP) {
      pdf_obj *XMP_stream;

      XMP_stream = JPEG_get_XMP(&j_info);
      texpdf_add_dict(stream_dict,
                   texpdf_new_name("Metadata"), texpdf_ref_obj(XMP_stream));
      texpdf_release_obj(XMP_stream);
    }
  }

  /* Check embedded ICC Profile */
  colorspace  = NULL;
  if (j_info.flags & HAVE_APPn_ICC) {
    pdf_obj *icc_stream, *intent;
    int      cspc_id;

    icc_stream = JPEG_get_iccp(&j_info);
    if (!icc_stream)
      colorspace = NULL;
    else {
      if (iccp_check_colorspace(colortype,
          pdf_stream_dataptr(icc_stream), pdf_stream_length (icc_stream)) < 0)
        colorspace = NULL;
      else {
        cspc_id = iccp_load_profile(NULL, /* noname */
                                    pdf_stream_dataptr(icc_stream),
                                    pdf_stream_length (icc_stream));
        if (cspc_id < 0)
          colorspace = NULL;
        else {
          colorspace = texpdf_get_colorspace_reference(cspc_id);
          intent     = iccp_get_rendering_intent(pdf_stream_dataptr(icc_stream),
                                                 pdf_stream_length (icc_stream));
          if (intent)
            texpdf_add_dict(stream_dict, texpdf_new_name("Intent"), intent);
        }
      }
      texpdf_release_obj(icc_stream);
    }
  }
  /* No ICC or invalid ICC profile. */
  if (!colorspace) {
    switch (colortype) {
    case PDF_COLORSPACE_TYPE_GRAY:
      colorspace = texpdf_new_name("DeviceGray");
      break;
    case PDF_COLORSPACE_TYPE_RGB:
      colorspace = texpdf_new_name("DeviceRGB");
      break;
    case PDF_COLORSPACE_TYPE_CMYK:
      colorspace = texpdf_new_name("DeviceCMYK");
      break;
    }
  }
  texpdf_add_dict(stream_dict, texpdf_new_name("ColorSpace"), colorspace);

#define IS_ADOBE_CMYK(j) (((j).flags & HAVE_APPn_ADOBE) && (j).num_components == 4)
  if (IS_ADOBE_CMYK(j_info)) {
    pdf_obj *decode;
    int      i;

    WARN("Adobe CMYK JPEG: Inverted color assumed.");
    decode = texpdf_new_array();
    for (i = 0; i < j_info.num_components; i++) {
      texpdf_add_array(decode, texpdf_new_number(1.0));
      texpdf_add_array(decode, texpdf_new_number(0.0));
    }
    texpdf_add_dict(stream_dict, texpdf_new_name("Decode"), decode);
  }

  /* Copy file */
  JPEG_copy_stream(&j_info, stream, fp);

  info.width              = j_info.width;
  info.height             = j_info.height;
  info.bits_per_component = j_info.bits_per_component;
  info.num_components     = j_info.num_components;

  jpeg_get_density(&j_info, &info.xdensity, &info.ydensity);

  texpdf_ximage_set_image(ximage, &info, stream);
  JPEG_info_clear(&j_info);

  return 0;
}