Pencil Tool problem

PDF-XChange Viewer SDK for Developer's
(ActiveX and Simple DLL Versions)

Moderators: TrackerSupp-Daniel, Tracker Support, Vasyl-Tracker Dev Team, Sean - Tracker, Chris - Tracker Supp, Tracker Supp-Stefan, Ivan - Tracker Software

Post Reply
patient chart manager, llc
User
Posts: 29
Joined: Thu Jan 03, 2013 7:43 pm

Pencil Tool problem

Post by patient chart manager, llc » Wed Apr 10, 2013 3:45 am

Hi, I've read all the posts on Pencil Search topics, and nothing seen regarding this issue:

Problem is, the tool does nothing when you simply "click" the mouse on the screen, so not possible to "dot an i".... I set the pen width usually around 2, and end users calling quite upset that when they use the pencil tool with tablet PC, or Android RDP with stylus, or just the mouse, trying to use printing instead of cursive, and this is very annoying. Please let me know if there is some way to just detect the click perhaps with pencil tool active and if just a mouse down and mouse up occurs, to draw a pixel annotation entry programatically or something? try to use a tablet with a stylus and write the word "this" and you will see the issue. I use the viewer for handwriting in a medical records application, and it is the only solution out there that lets you ink over remote desktop because of the nice curve fitting/anti aliasing which I love, but please, this needs fix.

Thanks

Nico - Tracker Supp
User
Posts: 220
Joined: Fri May 18, 2012 8:41 pm

Re: Pencil Tool problem

Post by Nico - Tracker Supp » Wed Apr 10, 2013 11:28 pm

Hi patient chart manager,

Thank you for your post.
Regarding your questons:
Problem is, the tool does nothing when you simply "click" the mouse on the screen, so not possible to "dot an i"
If you are using the Pencil tool and want to draw a dot, you need to draw a circle on the screen. If you just click on the page, nothing will be drawn because the way this tool works is by holding the mouse left button while moving the mouse from its initial position.
Please let me know if there is some way to just detect the click perhaps with pencil tool active and if just a mouse down and mouse up occurs, to draw a pixel annotation entry programatically or something?
It is possible to detect the WM_LBUTTONDOWN event by registering the OnEvent() handler and then find out if the pencil tool is active. For example:

Code: Select all

....
// Register mouse notifications
CComBSTR bsPropName (L"Notifications.Mouse.Filter");	
ComVariant vDataIn (L"All");
HRESULT hr = m_spView->SetProperty(bsPropName, vDataIn, 0);
if (FAILED(hr))
	return hr;
....

void OnEvent(LONG Type, BSTR Name, VARIANT DataIn, VARIANT* DataOut, LONG Flags)
{	
	CComBSTR bsPropName;	
	CComVariant vDataIn, CComVariant vDataOut;
	HRESULT hr;	
	CComBSTR bsName(Name);	
	if((Type == PXCVA_OnNamedNotify) && (bsName ==  L"Notifications.Mouse"))
	 {
		// Get mouse event message
		bsPropName = L"Notifications.Mouse.msg";		 
		hr = m_spView->GetProperty(bsPropName, &vDataOut, 0);
		if (FAILED(hr))
			return;
			
		// Left button down ?
		if (vDataOut.lVal == WM_LBUTTONDOWN)		
		{ 
			// Get active tool
			bsPropName = L"Tools.Active";
			hr = m_spView->GetProperty(bsPropName, &vDataOut, 0);
			if (FAILED(hr))
				return;
			// Pencil Tool Selected?	
			if(vDataOut.lVal != 33129)
				return;
			// Click on Page ?
			bsPropName = L"Notifications.Mouse.TargetName";	
			hr = m_spView->GetProperty(bsPropName, &vDataOut, 0);
			if (FAILED(hr))
				return;			
			CString sOut;
			sOut = vDataOut.bstrVal;
			if(sOut.Compare(L"Pages") == 0)
			{
				// Your code here
				MessageBox(L"Left Mouse Button Click on a Page with Pencil Tool Selected");
			}			
		}
	 }
}
Thanks.
Sincerely,

patient chart manager, llc
User
Posts: 29
Joined: Thu Jan 03, 2013 7:43 pm

Re: Pencil Tool problem

Post by patient chart manager, llc » Thu Apr 11, 2013 3:41 am

Well, I put the exclusive mode active so pencil tool can't even be used to select something, so control should know in that case that user is clicking with an active pencil, and should add a dot the width of the pencil tool in my opinion, just as does the ink tools pdfFill etc use with no problem.

Would the geniuses at Tracker also add a code sample to the helpful code you just sent to draw this circle for me, to "dot the i", with some parameter for the radius to be the current pen width?

Thanks

Nico - Tracker Supp
User
Posts: 220
Joined: Fri May 18, 2012 8:41 pm

Re: Pencil Tool problem

Post by Nico - Tracker Supp » Thu Apr 11, 2013 7:01 pm

Hi patient chart manager,

Thank you for your post.
Regarding your request, this is not a specific question related to the Viewer SDK, therefore we are not able to help you.
What you can do is to move the mouse and draw a circle when keeping the left button down, you may find many examples on the Web.
Thanks.

Sincerely,

patient chart manager, llc
User
Posts: 29
Joined: Thu Jan 03, 2013 7:43 pm

Re: Pencil Tool problem

Post by patient chart manager, llc » Fri Apr 12, 2013 12:39 am

Ok, this kind of thing works, so hopefully, I can make an i dotted doing this, will followup this post on when I get it done

this.addAnnot(
{
type: "Circle",
page: 0,
rect: [200,200,400,300],
author: "A. C. Robat",
name: "myCircle",
popupOpen: true,
popupRect: [200,100,400,200],
contents: "Hi World!",
strokeColor: color.red,
fillColor: ["RGB",1,1,.855]
});

User avatar
Tracker Supp-Stefan
Site Admin
Posts: 14037
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Pencil Tool problem

Post by Tracker Supp-Stefan » Fri Apr 12, 2013 11:59 am

Looking forward to how it went patient chart manager, llc!

Cheers,
Stefan

patient chart manager, llc
User
Posts: 29
Joined: Thu Jan 03, 2013 7:43 pm

Re: Pencil Tool problem

Post by patient chart manager, llc » Sun Apr 14, 2013 1:22 am

Hi please help with the rest of this, as the TranslateScreenPoint function, "***** below, fails every time, but the Javascript to draw a new circle works fine, it's just that I need to know where to draw it.

Static Xdown As Integer
Static Ydown As Integer
Static Xup As Integer
Static Yup As Integer
Static ToolNo As Variant
Dim JS as String
Dim ResString as String
Dim PgNo As Variant
Dim DocId As Variant
Call Me.PDFX1.GetProperty("Notifications.Mouse.msg", vDataIn, 0)
If vDataIn = WM_LBUTTONDOWN Then
Call Me.PDFX1.GetProperty("Notifications.Mouse.X", vDataIn, 0)
Xdown = vDataIn
Call Me.PDFX1.GetProperty("Notifications.Mouse.Y", vDataIn, 0)
Ydown = vDataIn
Call Me.PDFX1.GetProperty("Tools.Active", vDataIn, 0)
ToolNo = vDataIn
ElseIf vDataIn = WM_LBUTTONUP Then
Call Me.PDFX1.GetProperty("Notifications.Mouse.X", vDataIn, 0)
Xup = vDataIn
Call Me.PDFX1.GetProperty("Notifications.Mouse.Y", vDataIn, 0)
Yup = vDataIn
Call Me.PDFX1.GetProperty("Notifications.Mouse.Document", vDataIn, 0)
DocId = vDataIn
Call Me.PDFX1.GetProperty("Notifications.Mouse.Page", vDataIn, 0)
PgNo = vDataIn
Call Me.PDFX1.GetProperty("Tools.Active", vDataIn, 0)
If DocId <> -1 And PgNo <> -1 And vDataIn = 33129 And vDataIn = ToolNo Then 'pencil tool for both mousedown and up,
If Xdown = Xup And Ydown = Yup And Xdown <> 0 And Ydown <> 0 Then 'and is just a click, no mouse moved

Dim PenWidth As Variant
Call PDFX1.GetProperty("Commenting.Pencil.Styles[0].Border.Width", PenWidth, 0)
'translate the screen coordinate to page coordinate
Dim args As PDFXCviewAxLibCtl.IPDFXCargs
Dim datIn, datOut As Variant
Call Me.PDFX1.DoVerb("", ".ARGS", datIn, datOut, 0)
Set args = datOut
args.Init (2)
args(0) = Xup
args(1) = Yup
Dim args2 As Object '(note, I have also tried dimming as PDFXCviewAxLibCtl.IPDFXCargs) still won't work
'**********this statement fails**************
Call Me.PDFX1.DoVerb("Documents[" & DocId & "].pages[" & PgNo & "]", "TranslateScreenPoint", args, args2, PXCVA_OutArgs)
'I want to see if the new coordinates are returned, and reset my Xup and Yup to that
Xup = args2(0)
Yup = args2(1)
JS = "this.addAnnot({type: ""Circle"",page:" & Me.PdfCurrentPage & ",rect: [" & Xup & "," & Yup & "," & Xup + CInt(PenWidth) & "," & Yup + CInt(PenWidth) & "],author: """", name: """", strokeColor: color.black, fillColor: color.black});"
Me.PDFX1.RunJavaScript JS, ResString
End If
End If
End If

Nico - Tracker Supp
User
Posts: 220
Joined: Fri May 18, 2012 8:41 pm

Re: Pencil Tool problem

Post by Nico - Tracker Supp » Mon Apr 15, 2013 7:37 pm

Hi patient chart manager, llc,

Thank you for your post.
Please try one of the following alternatives:

Code: Select all

// Code - C++
/////////////////////////////////////////////
// Common intialization to both alternatives
////////////////////////////////////////////
// Get Document ID string
long lID;
hr = m_spView->GetDocumentID(0, &lID);
WCHAR sID[10];
memset((void*)sID, 0, sizeof(sID)/sizeof(WCHAR));
wsprintf(sID, L"%ld", lID);
// Prepare input mouse coordinates x and y
CComSafeArray<VARIANT> args(2);				
CComVariant arg1(x);
CComVariant arg2(y);		
args.SetAt(0, arg1);
args.SetAt(1, arg2);
CComVariant vDataIn, vDataOut;
vDataIn = (SAFEARRAY*) args;				
CComBSTR bsObjectName = L"Documents[#";
bsObjectName += sID;
bsObjectName += L"].pages[0]";
CComBSTR bsOperName(L"TranslateScreenPoint");

Code: Select all

//////////////////////////////////////
// Alternative 1
//////////////////////////////////////
// Translate Units
hr = m_spView->DoVerb(bsObjectName, bsOperName, vDataIn, &vDataOut, PXCVA_OutArgs);
if (FAILED(hr))
{
	DisplayErrorMessage(m_spView, hr, 0, 0);
	return;
}
// Get Output Args
CComPtr<IPDFXCargs> spArgs;			
long nCnt;
spArgs = static_cast<IPDFXCargs*>(vDataOut.punkVal);
spArgs->get_Count(&nCnt);
if(nCnt > 0)
{
	CComVariant v1, v2;
	spArgs->get_Item(0, &v1);
	spArgs->get_Item(1, &v2);
	// Get data
	double px = v1.dblVal;
	double py = v2.dblVal;
}

Code: Select all

////////////////////////////////////
// Alternative 2
/////////////////////////////////////
hr = m_spView->DoVerb(bsObjectName, bsOperName, vDataIn, &vDataOut, 0);
if (FAILED(hr))
{
	DisplayErrorMessage(m_spView, hr, 0, 0);
	return;
}
CComSafeArray<double> res(vDataOut.parray);
double px = res.GetAt(0);
double py = res.GetAt(1);
Thanks.
Sincerely,

patient chart manager, llc
User
Posts: 29
Joined: Thu Jan 03, 2013 7:43 pm

Re: Pencil Tool problem

Post by patient chart manager, llc » Tue Apr 16, 2013 1:18 am

Hi, I hate to have to ask this, but can you please post response for code sample in the same programming language as given? I believe though in VB I have tried the two options given and thus, If the code to TranslateScreenPoint does not work then can you tell me how to calculate that number, in other words a function where I can just pass the screen x,y and return document x,y to draw this annotation, as the code is done for what I want to do except for the translation.

Thanks

Nico - Tracker Supp
User
Posts: 220
Joined: Fri May 18, 2012 8:41 pm

Re: Pencil Tool problem

Post by Nico - Tracker Supp » Tue Apr 16, 2013 7:20 pm

Hi patient chart manager,llc,

Thank you for your post.
Here it is the Visual Basic version:

Code: Select all

If (e.type = PDFXCviewAxLib.PXCVA_EventTypes.PXCVA_OnNamedNotify) And (e.name = "Notifications.Mouse") Then
            AxCoPDFXCview1.GetProperty("Notifications.Mouse.msg", vDataIn)
            If vDataIn = WM_LBUTTONDOWN Then
                AxCoPDFXCview1.GetProperty("Notifications.Mouse.X", vDataIn)
                Xdown = vDataIn
                AxCoPDFXCview1.GetProperty("Notifications.Mouse.Y", vDataIn)
                Ydown = vDataIn
                AxCoPDFXCview1.GetProperty("Tools.Active", vDataIn)
                ToolNo = vDataIn
            ElseIf vDataIn = WM_LBUTTONUP Then
                AxCoPDFXCview1.GetProperty("Notifications.Mouse.X", vDataIn, 0)
                Xup = vDataIn
                AxCoPDFXCview1.GetProperty("Notifications.Mouse.Y", vDataIn, 0)
                Yup = vDataIn
                AxCoPDFXCview1.GetProperty("Notifications.Mouse.Document", vDataIn, 0)
                DocId = vDataIn
                AxCoPDFXCview1.GetProperty("Notifications.Mouse.Page", vDataIn, 0)
                PgNo = vDataIn
                AxCoPDFXCview1.GetProperty("Tools.Active", vDataIn, 0)
                If DocId <> -1 And PgNo <> -1 And vDataIn = 33129 And vDataIn = ToolNo Then 'pencil tool for both mousedown and up,
                    If Xdown = Xup And Ydown = Yup And Xdown <> 0 And Ydown <> 0 Then 'and is just a click, no mouse moved
                        Dim PenWidth As Object = 0
                        AxCoPDFXCview1.GetProperty("Commenting.Pencil.Styles[0].Border.Width", PenWidth, 0)
                        Dim args As Object
                        Dim arr(2) As Object
                        arr(0) = Xup
                        arr(1) = Yup
                        args = arr
                        Dim args2 As Object = Nothing
                        Dim ObjName As String = "Documents[#" + DocId.ToString + "].pages[" + PgNo.ToString + "]"
                        Dim OperName As String = "TranslateScreenPoint"
                        Try
                            AxCoPDFXCview1.DoVerb(ObjName, OperName, args, args2, 0)
                        Catch ex As Exception
                            ShowErrorMessage(System.Runtime.InteropServices.Marshal.GetHRForException(ex))
                        End Try
                        Xup = args2(0)
                        Yup = args2(1)
                        JS = "this.addAnnot({type: ""Circle"",page:" & PdfCurrentPage & ",rect: [" & Xup & "," & Yup & "," & Xup + CInt(PenWidth) & "," & Yup + CInt(PenWidth) & "],author: """", name: """", strokeColor: color.black, fillColor: color.black});"
                        AxCoPDFXCview1.RunJavaScript(JS)
                    End If
                End If
            End If
End If
Please note that you have to specify the '#' character when indexing the array of Documents by document ID. Also args gets initialized indirectly by copying its values from an array which already contains the position values.
Thanks.
Sincerely,

patient chart manager, llc
User
Posts: 29
Joined: Thu Jan 03, 2013 7:43 pm

Re: Pencil Tool problem

Post by patient chart manager, llc » Thu Apr 18, 2013 9:10 pm

Hi, ok, now here is the complete code for VB 6, had to translate from what was posted in vb.net, anyway, this works great, users can now "dot the i" See the bottom of the listing to figure out how to get the RGB color in use for the pen.. ColourLongToRGB function

Code: Select all

        If Name = "Notifications.Mouse" Then

            Static Xdown As Integer
            Static Ydown As Integer
            Static Xup As Integer
            Static Yup As Integer
            Static ToolNo As Variant
            Dim PgNo As Variant
            Dim DocId As Variant
            Call Me.PDFX1.GetProperty("Notifications.Mouse.msg", vDataIn, 0)
            If vDataIn = WM_LBUTTONDOWN Then
                Call Me.PDFX1.GetProperty("Notifications.Mouse.X", vDataIn, 0)
                Xdown = vDataIn
                Call Me.PDFX1.GetProperty("Notifications.Mouse.Y", vDataIn, 0)
                Ydown = vDataIn
                Call Me.PDFX1.GetProperty("Tools.Active", vDataIn, 0)
                ToolNo = vDataIn
            ElseIf vDataIn = WM_LBUTTONUP Then
                Call Me.PDFX1.GetProperty("Notifications.Mouse.X", vDataIn, 0)
                Xup = vDataIn
                Call Me.PDFX1.GetProperty("Notifications.Mouse.Y", vDataIn, 0)
                Yup = vDataIn
                Call Me.PDFX1.GetProperty("Notifications.Mouse.Document", vDataIn, 0)
                DocId = vDataIn
                Call Me.PDFX1.GetProperty("Notifications.Mouse.Page", vDataIn, 0)
                PgNo = vDataIn
                Call Me.PDFX1.GetProperty("Tools.Active", vDataIn, 0)
                If DocId <> -1 And PgNo <> -1 And vDataIn = 33129 And vDataIn = ToolNo Then 'pencil tool for both mousedown and up
                    'when user writes with pen, assume a movement of the mouse < 5 pixels is just attemp to add the dot.
                    If Abs(Xdown - Xup) < 5 And Abs(Ydown - Yup) < 5 And Xdown <> 0 And Ydown <> 0 Then
                        Dim Color As Variant
                        Call frmPdfEdit.PDFX1.GetProperty("Commenting.Pencil.Styles[#61953].SColor", Color, 0)
                        Dim PenWidth As Variant
                        Call PDFX1.GetProperty("Commenting.Pencil.Styles[0].Border.Width", PenWidth, 0)
                        'translate the screen coordinate to page coordinate
                        Dim args(1) As Variant
                        Dim args2 As Variant
                        args(0) = Xup
                        args(1) = Yup

                        Dim ObjName As String
                        ObjName = "Documents[#" + CStr(DocId) + "].pages[" + CStr(PgNo) + "]"
                        Dim OperName As String
                        OperName = "TranslateScreenPoint"
                        Call Me.PDFX1.DoVerb(ObjName, OperName, args, args2, 0)
                        Xup = args2(0)
                        Yup = args2(1)

                        Dim RGBColor As String
                        RGBColor = ColourLongToRGB(val(Color))  'return ["RGB",0,0,0] for black, or whatever is selected
                        'because using a dot, add an extra pixel width so it is more visible
                        JS = "this.addAnnot({type: ""Circle"",page:" & Me.PdfCurrentPage & ",rect: [" & Xup & "," & Yup & "," & Xup + CInt(PenWidth) + 1 & "," & Yup + CInt(PenWidth) + 1 & "],author: """", name: """", strokeColor: [" & RGBColor & "], fillColor: [" & RGBColor & "]});"

                        Me.PDFX1.RunJavaScript JS, ResString
                        Xdown = 0
                        Ydown = 0
                        Xup = 0
                        Yup = 0
                    End If
                End If
            Else 'like mouse move
                Xdown = 0
                Ydown = 0
                Xup = 0
                Yup = 0
            End If
            Exit Sub
        End If

Code: Select all

Function ColourLongToRGB(ByVal lColour As Long) As String
  lColour = lColour And &HFFFFFF

    'convert to separate RGB values
  Dim iRed As Integer, iGreen As Integer, iBlue As Integer
  iRed = lColour And &HFF
  iGreen = (lColour \ &H100) And &HFF
  iBlue = lColour \ &H10000
  ColourLongToRGB = """RGB""" + "," + CStr(iRed) + "," + CStr(iGreen) + "," + CStr(iBlue)
  
  
End Function

Nico - Tracker Supp
User
Posts: 220
Joined: Fri May 18, 2012 8:41 pm

Re: Pencil Tool problem

Post by Nico - Tracker Supp » Thu Apr 18, 2013 9:57 pm

Hi patient chart manager, llc,

Thank you for posting the example.
If you have any questions please feel free to come back.
Thanks.

Sincerely,

Post Reply