Knowledge Base and examples

Knowledge Base - Maintain the proportions of a stamp.

This article shows how to maintain the proportions of a stamp during the drawing (onTouchStamp) . 

You have to use this edited method in stead of the original one of PDFReader class.

private boolean onTouchStamp(MotionEvent event)
{
if( m_status == STA_STAMP )
{
int len = 0;
if( m_rects != null ) len = m_rects.length;
int cur = 0;

int prop = m_icon.getWidth() / m_icon.getHeight();

switch(event.getActionMasked())
{
case MotionEvent.ACTION_DOWN:
float rects[] = new float[len + 4];
for( cur = 0; cur < len; cur++ )
rects[cur] = m_rects[cur];
len += 4;
rects[cur + 0] = event.getX();
rects[cur + 1] = event.getY();
rects[cur + 2] = event.getX();
rects[cur + 3] = event.getY();
m_rects = rects;
break;
case MotionEvent.ACTION_MOVE:
float deltaMoveX = event.getX() - m_rects[len - 2];
float deltaMoveY = event.getY() - m_rects[len - 1];
m_rects[len - 2] = (deltaMoveX > deltaMoveY) ? event.getX() : m_rects[len - 2] + deltaMoveY * prop;
m_rects[len - 1] = (deltaMoveX < deltaMoveY) ? event.getY() : m_rects[len - 1] + deltaMoveX / prop;
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
float deltaCancelX = event.getX() - m_rects[len - 2];
float deltaCancelY = event.getY() - m_rects[len - 1];

m_rects[len - 2] = (deltaCancelX > deltaCancelY) ? event.getX() : m_rects[len - 2] + deltaCancelY * prop;
m_rects[len - 1] = (deltaCancelX < deltaCancelY) ? event.getY() : m_rects[len - 1] + deltaCancelX / prop;
break;
}
invalidate();
return true;
}
return false;
}
Applies To

RadaeePDF SDK for Android

Details

Created : 2015-08-07 09:34:38, Last Modified : 2015-09-23 16:33:56