Print Page | Close Window

DrawCapturedPageMatrix - Matrix HOWTO ?

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: I need help - I can help
Forum Description: Problems and solutions while programming with the Debenu Quick PDF Library and Debenu PDF Viewer SDK
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=2932
Printed Date: 28 Apr 24 at 10:21AM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: DrawCapturedPageMatrix - Matrix HOWTO ?
Posted By: mLipok
Subject: DrawCapturedPageMatrix - Matrix HOWTO ?
Date Posted: 11 Jul 14 at 11:09AM
If I Capture A4 Page
How to draw it using DrawCapturedPageMatrix 

Can somebody make an example which explain following parameteres:

M11 Matrix component
M12 Matrix component
M21 Matrix component
M22 Matrix component
MDX Matrix component
MDY Matrix component



-------------
Here you can find description how to test my examples:
http://www.quickpdf.org/forum/forum_posts.asp?TID=2932&PID=12600&title=drawcapturedpagematrix-matrix-howto#12600



Replies:
Posted By: AndrewC
Date Posted: 13 Jul 14 at 3:17PM

Michael,
M11 Matrix component  = xscale
M12 Matrix component  = shear
M21 Matrix component  = shear
M22 Matrix component  = yscale
MDX Matrix component  = xoffset
MDY Matrix component  = y offset

http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/pdf_reference_1-7.pdf

Read the section on coordinate systems.  Page 199 to 209.  If you are keen to learn the PDF spec then you can read the whole PDF :-)



Here is a link for more of the Mathematics.

http://mrl.nyu.edu/~dzorin/ig06/lecture05/lecture05.pdf

Andrew.


Posted By: mLipok
Date Posted: 08 Jun 15 at 12:35AM
After long time I just have time to study:
http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/pdf_reference_1-7.pdf

For me: the most important description was on page 205 near Figure 4.5
inside "4.2.2 Common Transformations".

I will do some functions and after using them, I will share in a future to the "Sample code" in this forum.

Cheers,
mLipok


-------------
Here you can find description how to test my examples:
http://www.quickpdf.org/forum/forum_posts.asp?TID=2932&PID=12600&title=drawcapturedpagematrix-matrix-howto#12600


Posted By: tfrost
Date Posted: 09 Jun 15 at 12:17PM
I look forward to your examples!  Although I studied mathematics and matrices at school and university, it was a long time ago and some practical guidance on using them in PDF rendering would be most useful.


Posted By: jpbro
Date Posted: 15 Jun 15 at 12:06AM
I look forward to your examples too!


Posted By: mLipok
Date Posted: 15 Jun 15 at 10:26AM
Here you go:

#AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7
#Tidy_Parameters=/sort_funcs /reel
;~ #AutoIt3Wrapper_Run_Debug_Mode=Y

#Region Include
#include-once
#include "QuickPDF.au3"
#EndRegion Include

; SET YOUR LICENSE KEY in your main script using _QPDF_SetLicenseKey()
; If you not set $__sLicenseKey_QPDF then DebenuPDFLibraryLite1114.dll will be used (Lite version) BUT THIS EXAMPLE REQUIRES COMMERCIAL LICENSE.
_QPDF_SetLicenseKey('ENTER YOUR KEY HERE')

; I (mLipok) use MyLicenseKey.txt file to prevent accidentally placed my license key in a public forum.
If FileExists(@ScriptDir & '\MyLicenseKey.txt') Then _QPDF_SetLicenseKey(FileRead(@ScriptDir & '\MyLicenseKey.txt'))

_QPDF_Example_DrawHTMLTextMatrix('ABCDE')

Func _Matrix_Create()
Local $aMatrixTable[6] = [1, 0, 0, 1, 0, 0]
Return $aMatrixTable
EndFunc   ;==>_Matrix_Create

Func _Matrix_Move(ByRef $aMatrixTable, $iTx, $iTy)
$aMatrixTable[0] *= 1 ; do not change
$aMatrixTable[1] *= 1 ; do not change
$aMatrixTable[2] *= 1 ; do not change
$aMatrixTable[3] *= 1 ; do not change
$aMatrixTable[4] = $iTx
$aMatrixTable[5] = $iTy
EndFunc   ;==>_Matrix_Move

Func _Matrix_Rotate(ByRef $aMatrixTable, $iAngle, $bAsDegree = True, $bAppendMode = False)
Local Const $PI = 3.141592653589793
Local $iRadian = 0

; conversion Degree to Radian
If $bAsDegree Then
; 1° = pi / 180 radians.
; http://www.purplemath.com/modules/radians.htm
$iRadian = ($iAngle * $PI) / 180
Else
$iRadian = $iAngle
EndIf

; Matrix changing
If $bAppendMode Then
$aMatrixTable[0] *= Cos($iRadian)
$aMatrixTable[1] *= Sin($iRadian)
$aMatrixTable[2] *= -Sin($iRadian)
$aMatrixTable[3] *= Cos($iRadian)
Else
$aMatrixTable[0] = Cos($iRadian)
$aMatrixTable[1] = Sin($iRadian)
$aMatrixTable[2] = -Sin($iRadian)
$aMatrixTable[3] = Cos($iRadian)
EndIf
$aMatrixTable[4] *= 1 ; do not change
$aMatrixTable[5] *= 1 ; do not change

EndFunc   ;==>_Matrix_Rotate

Func _Matrix_Skew(ByRef $aMatrixTable, $iAngleAlpha, $iAngleBetha, $bAsDegree = True, $bAppendMode = False)
Local Const $PI = 3.141592653589793
Local $iRadianAlpha = 0
Local $iRadianBetha = 0

; conversion Degree to Radian
If $bAsDegree Then
; 1° = pi / 180 radians.
; http://www.purplemath.com/modules/radians.htm
$iRadianAlpha = ($iAngleAlpha * $PI) / 180
$iRadianBetha = ($iAngleBetha * $PI) / 180
Else
$iRadianAlpha = $iAngleAlpha
$iRadianBetha = $iAngleBetha
EndIf

; Matrix changing
$aMatrixTable[0] *= 1 ; do not change
If $bAppendMode Then
$aMatrixTable[1] *= Tan($iRadianAlpha)
$aMatrixTable[2] *= Tan($iRadianBetha)
Else
$aMatrixTable[1] = Tan($iRadianAlpha)
$aMatrixTable[2] = Tan($iRadianBetha)
EndIf
$aMatrixTable[3] *= 1 ; do not change
$aMatrixTable[4] *= 1 ; do not change
$aMatrixTable[5] *= 1 ; do not change

EndFunc   ;==>_Matrix_Skew

Func _Matrix_Zoom(ByRef $aMatrixTable, $iSx, $iSy)
$aMatrixTable[0] = $iSx
$aMatrixTable[1] *= 1 ; do not change
$aMatrixTable[2] *= 1 ; do not change
$aMatrixTable[3] = $iSy
$aMatrixTable[4] *= 1 ; do not change
$aMatrixTable[5] *= 1 ; do not change
EndFunc   ;==>_Matrix_Zoom

Func _QPDF_DrawHTMLTextMatrix($oQP, $sHTML_Text, $aMatrixTable)
$oQP.DrawHTMLTextMatrix(100, $sHTML_Text, _
$aMatrixTable[0], _
$aMatrixTable[1], _
$aMatrixTable[2], _
$aMatrixTable[3], _
$aMatrixTable[4], _
$aMatrixTable[5])
EndFunc   ;==>_QPDF_DrawHTMLTextMatrix

Func _QPDF_Example_DrawHTMLTextMatrix($sHTML_Text)
Local $oQP
If _QPDF_CreateObjectAndUnlock($oQP) = 1 Then
Local $sFileName = @ScriptDir & "\Example_DrawHTMLTextMatrix.pdf"

$oQP.SetOrigin($__eQPDF_SORIGIN_TopLeft);
$oQP.SetMeasurementUnits($__eQPDF_MUNITS_Milimeters)
$sHTML_Text = '<font size="20">' & $sHTML_Text & '</font>'
Local $sHTML_Temp = $sHTML_Text

; normal drawn HTML text
$sHTML_Text = '1. ' & $sHTML_Temp
$oQP.DrawHTMLText(20, 20, 100, $sHTML_Text)

Local $aMatrixTable = _Matrix_Create()
; HTML text drawn with
; moved matrix
$sHTML_Text = '2. ' & $sHTML_Temp
_Matrix_Move($aMatrixTable, 20, 100)
_QPDF_DrawHTMLTextMatrix($oQP, $sHTML_Text, $aMatrixTable)

; HTML text drawn with
; moved zoomed
$sHTML_Text = '3. ' & $sHTML_Temp
_Matrix_Move($aMatrixTable, 40, 200)
_Matrix_Zoom($aMatrixTable, 1.5, 1.5)
_QPDF_DrawHTMLTextMatrix($oQP, $sHTML_Text, $aMatrixTable)

; HTML text drawn with
; moved zoomed
; Rotated 15°
$sHTML_Text = '4. ' & $sHTML_Temp
_Matrix_Move($aMatrixTable, 150, 300)
_Matrix_Zoom($aMatrixTable, 2, 2)
_Matrix_Rotate($aMatrixTable, 15)
_QPDF_DrawHTMLTextMatrix($oQP, $sHTML_Text, $aMatrixTable)

; HTML text drawn with
; moved zoomed
; Rotated 45°
; Skewing 15° for X-axis and -35° for Y-axis
$sHTML_Text = '5. ' & $sHTML_Temp
_Matrix_Move($aMatrixTable, 150, 400)
_Matrix_Zoom($aMatrixTable, 2, 2)
_Matrix_Rotate($aMatrixTable, 45)
_Matrix_Skew($aMatrixTable, 15, -35, True, True)
_QPDF_DrawHTMLTextMatrix($oQP, $sHTML_Text, $aMatrixTable)

; HTML text drawn with
; moved zoomed
; Skewing 0° for X-axis and 45° for Y-axis
_Matrix_Move($aMatrixTable, 150, 550)
_Matrix_Zoom($aMatrixTable, 2, 2)
_Matrix_Skew($aMatrixTable, 0, 45, True, True)
$sHTML_Text = '6. ' & $sHTML_Temp
_QPDF_DrawHTMLTextMatrix($oQP, $sHTML_Text, $aMatrixTable)

; Save PDF to file
$oQP.SaveToFile($sFileName)
While _WinAPI_FileInUse($sFileName)
Sleep(10)
WEnd

; Open PDF
ShellExecuteWait($sFileName)

EndIf
$oQP = 0 ; CleanUp - destroy object
EndFunc   ;==>_QPDF_Example_DrawHTMLTextMatrix



-------------
Here you can find description how to test my examples:
http://www.quickpdf.org/forum/forum_posts.asp?TID=2932&PID=12600&title=drawcapturedpagematrix-matrix-howto#12600


Posted By: mLipok
Date Posted: 02 Jul 15 at 5:47PM
@tfrost  ,  @jpbro 

Any comments ?
I wonder if you have any constructive ideas.

Best regards,
mLipok



-------------
Here you can find description how to test my examples:
http://www.quickpdf.org/forum/forum_posts.asp?TID=2932&PID=12600&title=drawcapturedpagematrix-matrix-howto#12600


Posted By: tfrost
Date Posted: 03 Jul 15 at 5:15PM
Sorry, I looked at it, but have been too busy to experiment!


Posted By: mLipok
Date Posted: 03 Jul 15 at 6:14PM
So I'll be here waiting patiently for your comment.
Cheers,

mLipok


-------------
Here you can find description how to test my examples:
http://www.quickpdf.org/forum/forum_posts.asp?TID=2932&PID=12600&title=drawcapturedpagematrix-matrix-howto#12600


Posted By: jpbro
Date Posted: 09 Jul 15 at 10:41PM
Hi mLipok,

Sorry I've had a very busy few weeks (plus vacation). I'll take a look at your sample tomorrow, thanks a lot for posting it!


Posted By: jpbro
Date Posted: 10 Jul 15 at 1:18PM
Very nice mLipok - the part I wasn't understanding before was the need for radians/cos/tan/etc... to determine the matrix values.

I haven't had a chance to run the code yet because I have to convert it to VB first, but I appreciate the work you've done. Thanks again for posting it!


Posted By: mLipok
Date Posted: 10 Jul 15 at 7:11PM
You can use it very easy.

First download and install AutoIt 3.3.14.0
https://www.autoitscript.com/site/autoit/downloads/

second step:
download and install "AutoIt Script Editor" 
https://www.autoitscript.com/site/autoit-script-editor/downloads/

Now open SciTE, and paste my script to this Editor.
Save it as "Example.au3"

Download my UDF
https://www.autoitscript.com/forum/files/file/342-debenu-quick-pdf-library-udf/

unpack and place QuickPDF.au3 in the same directory when you save "Example.au3"

now go to opened "Example.au3" document in SciTE and run it or compile, by using function from menu "Tools".





-------------
Here you can find description how to test my examples:
http://www.quickpdf.org/forum/forum_posts.asp?TID=2932&PID=12600&title=drawcapturedpagematrix-matrix-howto#12600


Posted By: mLipok
Date Posted: 10 Jul 15 at 7:37PM
Originally posted by jpbro jpbro wrote:

Very nice mLipok
Thanks

Originally posted by jpbro jpbro wrote:

the part I wasn't understanding before was the need for radians/cos/tan/etc... to determine the matrix values.

You can read this here:
http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/pdf_reference_1-7.pdf

Page #205


Rotations are produced by [ cos θ sin θ −sin θ cos θ 0 0 ], which has the effect of rotating the coordinate system axes by an angle θ counterclockwise.
•Skew is specified by [ 1 tan α tan β 1 0 0 ], which skews the x axis by an angle α and the y axis by an angle β.




-------------
Here you can find description how to test my examples:
http://www.quickpdf.org/forum/forum_posts.asp?TID=2932&PID=12600&title=drawcapturedpagematrix-matrix-howto#12600


Posted By: mLipok
Date Posted: 23 Oct 17 at 12:47PM
Originally posted by tfrost tfrost wrote:

I look forward to your examples!  Although I studied mathematics and matrices at school and university, it was a long time ago and some practical guidance on using them in PDF rendering would be most useful.

Did you look at this ?
Could you check this with your mathematical eye ?



-------------
Here you can find description how to test my examples:
http://www.quickpdf.org/forum/forum_posts.asp?TID=2932&PID=12600&title=drawcapturedpagematrix-matrix-howto#12600


Posted By: mLipok
Date Posted: 28 Oct 17 at 12:16AM
Interesting link:
http://www.planetpdf.com/forumarchive/69809.asp



-------------
Here you can find description how to test my examples:
http://www.quickpdf.org/forum/forum_posts.asp?TID=2932&PID=12600&title=drawcapturedpagematrix-matrix-howto#12600



Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.01 - http://www.webwizforums.com
Copyright ©2001-2014 Web Wiz Ltd. - http://www.webwiz.co.uk