Signin/Signup with: 
Welcome, Guest
Username: Password: Remember me
Questions about Android development and PDF
  • Page:
  • 1
  • 2

TOPIC:

Add Handwriting Annotation 10 years 3 months ago #4932

  • sparklellama
  • sparklellama's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 34
  • Thank you received: 0
The following code is intended to insert an HWriting annotation into a PDF. The HWriting has been perviously successfully drawn. However, the code only causes the HWriting to vanish. It is not inserted into the PDF. I have used this code pattern successfully for other annotation types (Ink, Rects, Circles, Comments etc), but it does not work for HWriting. Any clues? Thanks if you can help.
// elsewhere mWw is defined as  new HWriting([view width], [view height], 1.0f, 3.0f, 0, 0, 0);

	@Override
	public void persist(PDFVPage vpage, int x, int y)
	{
		Page page = vpage.GetPage();
		if (page != null)
		{
			Matrix mat = vpage.CreateMatrix();
			Log.v(this.getClass().getName(), String.format("Persisting hWriting at: %d %d", -vpage.GetVX(x), -vpage.GetVY(y)));
			page.ObjsStart(); // Docs suggest that this might be a good idea, but doesn't seem to help
			page.AddAnnotHWriting(mat, mHw,-vpage.GetVX(x), -vpage.GetVY(y)); // TODO: NOT WORKING
			mat.Destroy();
		}
		
	}

Please Log in or Create an account to join the conversation.

Add Handwriting Annotation 10 years 3 months ago #4935

  • radaee
  • radaee's Avatar
  • Offline
  • Moderator
  • Moderator
  • Posts: 1123
  • Thank you received: 73
plz check this:
@Override
public void persist(PDFVPage vpage)
{
	Page page = vpage.GetPage();
	if (page != null)
	{
		Matrix mat = vpage.CreateMatrix();
		Log.v(this.getClass().getName(), String.format("Persisting hWriting at: %d %d", -vpage.GetVX(x), -vpage.GetVY(y)));
		page.ObjsStart(); // Docs suggest that this might be a good idea, but doesn't seem to help
		page.AddAnnotHWriting(mat, mHw,-vpage.GetVX(m_view.vGetX()), -vpage.GetVY(m_view.vGetY())); // TODO: NOT WORKING
		mat.Destroy();
	}
}

Please Log in or Create an account to join the conversation.

Add Handwriting Annotation 10 years 3 months ago #4936

  • sparklellama
  • sparklellama's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 34
  • Thank you received: 0
Thanks so much for the suggestion. Unfortunately this time, it didn't have any effect. Let me know if you have any more ideas… thanks so much.

Please Log in or Create an account to join the conversation.

Add Handwriting Annotation 10 years 3 months ago #4938

  • radaee
  • radaee's Avatar
  • Offline
  • Moderator
  • Moderator
  • Posts: 1123
  • Thank you received: 73
i tested it, and fixed some bugs for this method. plz wait.
and try these codes for next version:
Init:
	private HWriting m_writing = null;
	m_writing = new HWriting( getWidth(), getHeight(), 1, 5, 255, 0, 0 );

case onTouchDown:
	m_writing.OnDown(event.getX(), event.getY());
	PDFPos pos = m_view.vGetPos((int)event.getX(), (int)event.getY());
	PDFVPage vpage = m_view.vGetPage(pos.pageno);

case onTouchMove:
	m_writing.OnMove(event.getX(), event.getY());

case onTouchUp:
	m_writing.OnUp(event.getX(), event.getY());

Add to page:
	Page page = vpage.GetPage();
	Matrix mat = vpage.CreateMatrix();
	page.AddAnnotHWriting(mat, m_writing, -vpage.GetVX(m_view.vGetX()), -vpage.GetVY(m_view.vGetY()));
	mat.Destroy();
	m_view.vRender(vpage);
	m_writing.Destroy();
	m_writing = null;

Please Log in or Create an account to join the conversation.

Last edit: by .

Add Handwriting Annotation 10 years 3 months ago #4943

  • nermeen
  • nermeen's Avatar
  • Offline
  • Platinum Member
  • Platinum Member
  • Posts: 962
  • Thank you received: 87
A new version 2.9.7beta5 has been pubblished..
This contains a fix to HWriting annotation

Please Log in or Create an account to join the conversation.

Add Handwriting Annotation 10 years 3 months ago #4956

  • sparklellama
  • sparklellama's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 34
  • Thank you received: 0
Thank you for the new beta version of the library. Unfortunately there was no change upon upgrading to the new library. I have updated the code to more closely reflect your example, but no luck. Thanks if you have any more ideas.
create:

		mView = view;
		mAndroidView = aview;
		// width, height, min stroke width, max stroke width, 3x # = RGB col
		mHw = new HWriting(mAndroidView.getWidth(), mAndroidView.getHeight(),
				1.0f, 3.0f, 0, 0, 0);
		mBitmap = Bitmap.createBitmap(mAndroidView.getWidth(),
				mAndroidView.getHeight(), Bitmap.Config.ARGB_8888);		

draw:

		mBitmap.eraseColor(0);
		int hndl = Global.lockBitmap(mBitmap);
		mHw.OnDraw(hndl);
		Global.unlockBitmap(mBitmap, hndl);
		c.drawBitmap(mBitmap, 0, 0, null);	

touchDown:

		mHw.OnDown(x, y);
		PDFPos pos = mView.vGetPos((int)x, (int)y);
		aPage = mView.vGetPage(pos.pageno);
		
touchMove:

		mHw.OnMove(x, y);
		
touchUp:

		mHw.OnUp(x, y);

persist to page:

		Page page = aPage.GetPage();
		if (page != null)
		{
			Matrix mat = aPage.CreateMatrix();
			Log.v(this.getClass().getName(),
					String.format("Persisting hWriting at: %d %d",
							vpage.GetVX(mView.vGetX()),
							-vpage.GetVY(mView.vGetY())));
			page.ObjsStart(); // Docs suggest that this might be a good idea,
								// but doesn't seem to help
			page.AddAnnotHWriting(mat, mHw, -vpage.GetVX(mView.vGetX()),
					-vpage.GetVY(mView.vGetY())); // Not working
			mat.Destroy();
			mView.vRender(aPage);
			mHw.Destroy();
			mHw = null;

		}
		

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
  • 2
Powered by Kunena Forum