Knowledge Base and examples

Knowledge Base - How to make page corners rounded?

If you want to have a rounded page corners effect, you need to do the following:

(Note: the below code has a problem when the gap between pages is small, we are working on it, the article will be updated as soon as it’s solved)

RDPDFReader module:

You need to add the following method to PDFLayout class

protected void drawRoundedCorners(Canvas canvas, int scrollX, int scrollY, float radius, int pageno, Region.Op op) {

   if(m_pages == null || pageno < 0 || pageno >= m_pages.length || m_pages[pageno] == null)

      return;

   Path mClipPath = new Path();

   Paint paint = new Paint();

   paint.setColor(m_back_color);

   paint.setAntiAlias(true);

   VPage vpage = m_pages[pageno];

   int x = vpage.GetX() - scrollX, y =  vpage.GetY() - scrollY, width = x + vpage.GetWidth()

         , height = y + vpage.GetHeight();

   //top-left

   mClipPath.addCircle(x + radius,y + radius, radius, Path.Direction.CW);

   canvas.clipPath(mClipPath, op);

   canvas.drawCircle(x, y, radius, paint);

   //top-right

   mClipPath.addCircle(width - radius, y + radius, radius, Path.Direction.CW);

   canvas.clipPath(mClipPath, op);

   canvas.drawCircle(width, y, radius, paint);

   //bottom-left

   mClipPath.addCircle(x + radius, height - radius, radius, Path.Direction.CW);

   canvas.clipPath(mClipPath, op);

   canvas.drawCircle(x, height, radius, paint);

   //bottom-right

   mClipPath.addCircle(width - radius, height - radius, radius, Path.Direction.CW);

   canvas.clipPath(mClipPath, op);

   canvas.drawCircle(width, height, radius, paint);

Then call it from vDrawNormal as follows: 

drawRoundedCorners(canvas, x, y, radius, m_pageno, Region.Op.DIFFERENCE);

drawRoundedCorners(canvas, x, y, radius, m_pageno + 1, Region.Op.DIFFERENCE);

After: 

canvas.drawBitmap(m_bmp, 0, 0, null); 

For dual view mode, you need to override the method in PDFLayoutDual

protected void drawRoundedCorners(Canvas canvas, int scrollX, int scrollY, float radius, int pageno, Region.Op op) {

   if(m_pages == null || pageno < 0 || pageno >= m_pages.length || m_pages[pageno] == null)

      return;

 

   Path mClipPath = new Path();

   Paint paint = new Paint();

   paint.setColor(m_back_color);

   paint.setAntiAlias(true);

   VPage vpage = m_pages[pageno];

   int x = vpage.GetX() - scrollX, y =  vpage.GetY() - scrollY, width = x + vpage.GetWidth()

         , height = y + vpage.GetHeight();

 

   int ccur = 0;

   while( ccur < m_cells.length ) {

      if( pageno == m_cells[ccur].page_left || pageno == m_cells[ccur].page_right )

         break;

      ccur++;

   }

 

   if(pageno == m_cells[ccur].page_left) { //top-left

      mClipPath.addCircle(x + radius, y + radius, radius, Path.Direction.CW);

      canvas.clipPath(mClipPath, op);

      canvas.drawCircle(x, y, radius, paint);

 

      //bottom - left

      mClipPath.addCircle(x + radius, height - radius, radius, Path.Direction.CW);

      canvas.clipPath(mClipPath, op);

      canvas.drawCircle(x, height, radius, paint);

   }

 

   if(pageno == m_cells[ccur].page_right || m_cells[ccur].page_right == -1) { //top-right

      mClipPath.addCircle(width - radius, y + radius, radius, Path.Direction.CW);

      canvas.clipPath(mClipPath, op);

      canvas.drawCircle(width, y, radius, paint);

 

      //bottom-right

      mClipPath.addCircle(width - radius, height - radius, radius, Path.Direction.CW);

      canvas.clipPath(mClipPath, op);

      canvas.drawCircle(width, height, radius, paint);

   }

}


 

PDFReader module:

You need to add the following method to PDFView class

protected void drawRoundedCorners(Canvas canvas, int scrollX, int scrollY, float radius, int pageno, Region.Op op) {

   if(m_pages == null || pageno < 0 || pageno >= m_pages.length || m_pages[pageno] == null)

      return;

 

   Path mClipPath = new Path();

   Paint paint = new Paint();

   paint.setColor(m_back);

   paint.setAntiAlias(true);

   PDFVPage vpage = m_pages[pageno];

   int x = vpage.GetX() - scrollX, y =  vpage.GetY() - scrollY, width = x + vpage.GetWidth()

         , height = y + vpage.GetHeight();

 

   //top-left

   mClipPath.addCircle(x + radius,y + radius, radius, Path.Direction.CW);

   canvas.clipPath(mClipPath, op);

   canvas.drawCircle(x, y, radius, paint);

 

   //top-right

   mClipPath.addCircle(width - radius, y + radius, radius, Path.Direction.CW);

   canvas.clipPath(mClipPath, op);

   canvas.drawCircle(width, y, radius, paint);

 

   //bottom-left

   mClipPath.addCircle(x + radius, height - radius, radius, Path.Direction.CW);

   canvas.clipPath(mClipPath, op);

   canvas.drawCircle(x, height, radius, paint);

 

   //bottom-right

   mClipPath.addCircle(width - radius, height - radius, radius, Path.Direction.CW);

   canvas.clipPath(mClipPath, op);

   canvas.drawCircle(width, height, radius, paint);

}

Then call it from vDraw as follows: 

drawRoundedCorners(canvas, left, top, radius, m_pageno, Region.Op.DIFFERENCE);

drawRoundedCorners(canvas, left, top, radius, m_pageno + 1, Region.Op.DIFFERENCE);

After:

if( Global.dark_mode ) m_draw_bmp.Invert();

m_draw_bmp.Free(m_bmp);

canvas.drawBitmap(m_bmp, 0, 0, null);

For dual view mode, you need to override the method in PDFViewDual:

protected void drawRoundedCorners(Canvas canvas, int scrollX, int scrollY, float radius, int pageno, Region.Op op) {

   if(m_pages == null || pageno < 0 || pageno >= m_pages.length || m_pages[pageno] == null)

      return;

 

   Path mClipPath = new Path();

   Paint paint = new Paint();

   paint.setColor(m_back);

   paint.setAntiAlias(true);

   PDFVPage vpage = m_pages[pageno];

   int x = vpage.GetX() - scrollX, y =  vpage.GetY() - scrollY, width = x + vpage.GetWidth()

         , height = y + vpage.GetHeight();

 

   int ccur = 0;

   while( ccur < m_cells.length ) {

      if( pageno == m_cells[ccur].page_left || pageno == m_cells[ccur].page_right )

         break;

      ccur++;

   }

 

   if(pageno == m_cells[ccur].page_left) { //top-left

      mClipPath.addCircle(x + radius, y + radius, radius, Path.Direction.CW);

      canvas.clipPath(mClipPath, op);

      canvas.drawCircle(x, y, radius, paint);

 

      //bottom - left

      mClipPath.addCircle(x + radius, height - radius, radius, Path.Direction.CW);

      canvas.clipPath(mClipPath, op);

      canvas.drawCircle(x, height, radius, paint);

   }

 

   if(pageno == m_cells[ccur].page_right || m_cells[ccur].page_right == -1) { //top-right

      mClipPath.addCircle(width - radius, y + radius, radius, Path.Direction.CW);

      canvas.clipPath(mClipPath, op);

      canvas.drawCircle(width, y, radius, paint);

 

      //bottom-right

      mClipPath.addCircle(width - radius, height - radius, radius, Path.Direction.CW);

      canvas.clipPath(mClipPath, op);

      canvas.drawCircle(width, height, radius, paint);

   }

}

Applies To

RadaeePDF SDK for Android

Details

Created : 2016-09-20 10:28:43, Last Modified : 2016-09-20 11:13:49