Menu

#6 A Couple Of changes - Pixels per Metre

open
nobody
None
5
2006-07-18
2006-07-18
LeslieM
No

Here are a couple of changes I have made to my (old)
copy of libharu.

1. Provide the ability to set the Creation Date
Property.

2. Provide the ability to determine the Pixels Per
Metre for PNG images.
This important change allows us to scale the image
correctly so that it not only appears correctly on the
screen, but importantly when printing out the PDF file
the image retains its original size.

// Liharuc.h

The following definitions have been added.....

/*-----------------------------------------------------
----------------------*/
/*----- PdfInfo class ---------------------------------
----------------------*/

int pdf_info_set_creation_date(pdf_info info, pdf_date
date);

/*-----------------------------------------------------
-----------------------*/
/*----- PdfImage class --------------------------------
-----------------------*/

unsigned int pdf_image_get_pixels_per_meter(pdf_image
image);

//Libharu.h

/*-----------------------------------------------------
-----------------------*/
/*----- PdfImage class --------------------------------
-----------------------*/

The following elements were added to the class - no
other changes here.

class PdfImage : public PdfXObject
{
public:
unsigned int PixelsPerMeter() { return
fPixelsPerMeter; }
protected:
unsigned int fPixelsPerMeter;

};

//Libharuc.cc

The following C interface functions were added.

/*-----------------------------------------------------
----------------------*/
/*----- pdf_info --------------------------------------
----------------------*/

int pdf_info_set_creation_date(pdf_info info, pdf_date
date)
{
PDF_INFO_SAFE_CALL(info, SetCreationDate, (date));
}

/*-----------------------------------------------------
----------------------*/
/*----- pdf_image -------------------------------------
----------------------*/

unsigned int pdf_image_get_pixels_per_meter(pdf_image
image)
{
if (image == NULL)
return 0;

PdfImage* image_obj = (PdfImage*)image;
return image_obj->PixelsPerMeter();
}

// PdfPngImage.cc

/*-----------------------------------------------------
-----------------------*/
/*----- PdfPngImage class -----------------------------
-----------------------*/

The following element was added......

PdfPngImage::PdfPngImage(PdfDoc* doc)
PdfImage(doc)
{

fPixelsPerMeter = 0;
}

The following changes were made to this function....

void
PdfPngImage::LoadFromFile(const char* filename)
{
.
.
.

FILE* infile = NULL;

// This variable was added directly after the infile
declaration.

png_uint_32 ppm = 0;

.
.
.
.
.
.

try {

/* io setting */
infile = OpenImageFile(filename);
.
.
.
.
.
.

png_uint_32 len = png_get_rowbytes(png_ptr,
info_ptr);

// **** This next line ONLY was added directly after
ther above line. *****

ppm = png_get_pixels_per_meter(png_ptr, info_ptr);

.
.
.
.
.
.

}

/* setting the info of the image. */
fWidth = (unsigned int)info_ptr->width;
fHeight = (unsigned int)info_ptr->height;
fBitsPerComponent = (unsigned int)info_ptr-
>bit_depth;

// **** This next line ONLY was added directly after
the above line. *****

fPixelsPerMeter = (unsigned int)ppm;

.
.
.
.
.
.

fHasImage = true;
return;
}

Discussion


Log in to post a comment.