pdfSetTouchZoomCbk
Set a callback function for touch zoom.
void pdfSetTouchZoomCbk(PDFViewerHandle viewer, void (*cbk)(void *data, int status, int winX, int winY, int distance), void *data)
This function sets a callback function which is called when the user
performs a touch zoom, i.e., a two-finger "pinch" gesture.
The status
argument is:
- 0 for the first touch zoom event, when the user first touches the screen with two fingers
- 1 for intermediate events, when the user moves their fingers
- 2 for the last event, when the user lifts their fingers
The winX
, winY
arguments are the coordinates
of one of the touch points, in window coordinates.
The distance
argument is the distance between the two
touch points.
This callback is only called if pdfEnableTouchZoom
has been called
with true.
IMPORTANT: Calling pdfEnableTouchZoom
with true only
enables the callbacks; it does not perform any zooming.
The pdfSetTouchZoomCbk
callback must be implemented to
handle zooming.
The purpose is to allow the application code to update the user interface (e.g., a "current zoom" display), limit the minimum/maximum zoom level, etc. The standard approach is to zoom based on the ratio of the current distance to the previous distance. See the sample code below.
C:
int touchZoomPrevDist;
...
pdfEnableTouchZoom(viewer, TRUE);
pdfSetTouchZoomCbk(viewer, &touchZoomCbk, NULL);
...
void touchZoomCbk(void *data, int status, int winX, int winY,
int distance) {
double z;
/* on the first touch zoom event (status = 0), just save the distance
* for use in subsequent events */
if (status != 0) {
/* compute the new zoom level */
z = (pdfGetZoomPercent(viewer) * distance) / touchZoomPrevDist;
/* don't go below 10% or above 800% */
if (z < 10) {
z = 10;
} else if (z > 800) {
z = 800;
}
/* set the new zoom level */
pdfZoomCentered(viewer, z);
}
/* save the distance - this will be used in the next touchZoom event */
touchZoomPrevDist = distance;
}