Skip to content

Commit

Permalink
1.14
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitriychunikhin committed Oct 4, 2024
1 parent 8ba604b commit f02b319
Show file tree
Hide file tree
Showing 45 changed files with 1,189 additions and 629 deletions.
2 changes: 1 addition & 1 deletion .github/Tests/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion .github/Tests/out.coverage-summary.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"coverage": 34}
{"coverage": 58}
810 changes: 486 additions & 324 deletions .github/Tests/out.jacoco.xml

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Build/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
buildlog.txt
!build.fxp
!build_i18n.fxp

!/Packages/**
Binary file added Build/Packages/FoxConsole/FoxConsole.FXP
Binary file not shown.
239 changes: 239 additions & 0 deletions Build/Packages/FoxConsole/foxconsole.prg
Original file line number Diff line number Diff line change
@@ -0,0 +1,239 @@
lparameters tnSubsystem

* tnSubsystem: .F. | 0 - WINDOWS (GUI), 1 - CONSOLE (CUI)

if type('_vfp.cli') != 'O'
addproperty(_vfp, 'cli', .null.)
endif
_vfp.cli = createobject("Console", m.tnSubsystem)


* ================================= *
* Console class
* ================================= *
#define STD_INPUT_HANDLE -10
#define STD_OUTPUT_HANDLE -11
#define STD_ERROR_HANDLE -12
#define ATTACH_PARENT_PROCESS -1
#define INVALID_HANDLE_VALUE -1
#define FILE_TYPE_DISK 0x0001
#define FILE_TYPE_CHAR 0x0002
#define FILE_TYPE_PIPE 0x0003

define class console as custom
StdOut = 0
StdErr = 0
StdIn = 0
IsConsoleOut = .F.
IsConsoleIn = .F.

hidden StdOut, StdErr, StdIn, IsConsoleOut, IsConsoleIn

* Returns .T. if StdOut is a console and .F. if StdOut is a pipe or a file
function GetIsConsoleOut()
return this.IsConsoleOut
endfunc

* Returns .T. if StdIn is a console and .F. if StdIn is a pipe or a file
function GetIsConsoleIn()
return this.IsConsoleIn
endfunc

function init
lparameters tnSubsystem

this.loadLibraries()

do case
case empty(m.tnSubsystem) or _vfp.StartMode = 0
if AllocConsole() = 0
return .f.
endif

case cast(m.tnSubsystem as i) = 1
if inlist(GetStdHandle(STD_OUTPUT_HANDLE), 0, INVALID_HANDLE_VALUE)
if AttachConsole(ATTACH_PARENT_PROCESS) = 0
if AllocConsole() = 0
return .f.
endif
endif
endif

otherwise
return .f.
endcase

this.StdOut = GetStdHandle(STD_OUTPUT_HANDLE)
if inlist(this.StdOut, 0, INVALID_HANDLE_VALUE)
return .f.
endif

this.StdErr = GetStdHandle(STD_ERROR_HANDLE)
this.StdIn = GetStdHandle(STD_INPUT_HANDLE)

this.IsConsoleOut = inlist(GetFileType(this.StdOut), FILE_TYPE_CHAR)
this.IsConsoleIn = inlist(GetFileType(this.StdIn), FILE_TYPE_CHAR)


if this.IsConsoleOut
=SetConsoleTextAttribute(this.StdOut, 0x07)
=SetConsoleTitle(_screen.caption)
endif
endfunc


function print(cOutput, lStdErr)
local nBytesWritten
if vartype(cOutput) <> "C"
cOutput=iif(!empty(cOutput), alltrim(transform(cOutput)), "")
endif

nBytesWritten=0

if WriteFile(IIF(m.lStdErr, this.StdErr, this.StdOut), @cOutput, len(cOutput), @nBytesWritten, 0) = 0
=GetLastError()
endif

return nBytesWritten
endfunc

function PrintLn(cOutput, lStdErr)
this.print(cOutput, m.lStdErr)
this.print(chr(13)+chr(10), m.lStdErr)
endfunc


function input(tcTitle)
if empty(tcTitle)
tcTitle = ""
endif
this.print(tcTitle)
return this.ReadLn()
endfunc


function ReadLn(nBufsize)
local cBuffer, nBytesRead, lcResult
if vartype(nBufsize) <> "N"
nBufsize=1024
endif
cBuffer = replicate(chr(0), nBufsize)
nBytesRead=0

if ReadFile(this.StdIn, @cBuffer, nBufsize, @nBytesRead, 0) = 0
=GetLastError()
return ""
endif

lcResult = substr(cBuffer, 1, nBytesRead)
return strtran(alltrim(lcResult), chr(13) + chr(10), "")
endfunc


function readkey
return this.ReadLn()
endfunc

hidden function loadLibraries
declare integer GetLastError in kernel32 as GetLastError
declare integer GetStdHandle in kernel32 as GetStdHandle long nStdHandle
declare integer AttachConsole in kernel32 as AttachConsole LONG dwProcessId
declare integer AllocConsole in kernel32 as AllocConsole
declare integer FreeConsole in kernel32 as FreeConsole
declare integer CloseHandle in kernel32 as CloseHandle integer hObject
declare integer SetConsoleTitle in kernel32 as SetConsoleTitle string lpConsoleTitle

declare integer GetFileType IN kernel32 AS GetFileType integer hFile

declare integer WriteFile IN kernel32 as WriteFile ;
integer hFile, string @lpBuffer, ;
integer nNumberOfBytesToWrite, ;
integer @lpNumberOfBytesWritten, ;
integer lpOverlapped

declare integer ReadFile IN kernel32 AS ReadFile ;
integer hFile, string @lpBuffer, ;
integer nNumberOfBytesToRead, ;
integer @lpNumberOfBytesRead, ;
integer lpOverlapped

declare integer WriteConsole in kernel32 as WriteConsole ;
integer hConsoleOutput, string @lpBuffer,;
integer nNumberOfCharsToWrite,;
integer @lpNumberOfCharsWritten,;
integer lpReserved

declare integer ReadConsole in kernel32 as ReadConsole ;
integer hConsoleInput, string @lpBuffer,;
integer nNumberOfCharsToRead,;
integer @lpNumberOfCharsRead, integer lpReserved

declare integer SetConsoleTextAttribute in kernel32 as SetConsoleTextAttribute ;
integer hConsoleOutput, SHORT wAttributes

declare short ExitProcess in WIN32API as ExitProcess integer uExitCode
endfunc

function destroy
=FreeConsole()
=CloseHandle(this.StdOut)
=CloseHandle(this.StdErr)
=CloseHandle(this.StdIn)
endfunc

function exit(tnReturnValue)
FLUSH FORCE
=ExitProcess(tnReturnValue)
endfunc


enddefine

* ================================= *
* ConsoleTools class
* ================================= *

define class ConsoleTools as custom

* Make exe file a console application by setting IMAGE_SUBSYSTEM_WINDOWS_CUI flag in PE header of exe file
* in the same way as "editbin /SUBSYSTEM:CONSOLE appname.exe"
* https://github.com/MicrosoftDocs/cpp-docs/blob/main/docs/build/reference/editbin-reference.md
* https://learn.microsoft.com/ru-ru/cpp/build/reference/editbin-reference?view=msvc-170
* https://github.com/tpn/pdfs/blob/master/Microsoft%20Portable%20Executable%20and%20Common%20Object%20File%20Format%20Specification%20-%20Revision%208.3%20(6th%20Feb%2C%202013).pdf
*
function makeConsoleApp
lparameters tcExeFile

lcFileName = EVL(m.tcExeFile,"")

if file(lcFileName,1) = .F.
ERROR 'File '+lcFileName+ ' is not found'
return .f.
endif


local lnFileHandle
lnFileHandle = fopen(lcFileName, 2)

if lnFileHandle = -1
ERROR 'FOPEN("'+lcFileName+ '", 2) returned -1'
return .f.
endif

*!* fseek(lnFileHandle, 0x148,0)
*!* fwrite(lnFileHandle, 0hFA,1)

*!* fseek(lnFileHandle, 0x149,0)
*!* fwrite(lnFileHandle, 0hE8,1)

fseek(lnFileHandle, 0x14C,0)
fwrite(lnFileHandle, 0h03,1)

fflush(lnFileHandle,.T.)
fclose(lnFileHandle)

return .t.

endfunc

enddefine
Binary file modified Build/build.FXP
Binary file not shown.
17 changes: 16 additions & 1 deletion Build/build.prg
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,28 @@ ON ERROR buildError()
PUBLIC glBuildError
glBuildError = .F.

DO build_i18n.prg

******************************************
DO (lcPath + "/build_i18n.prg")
******************************************

******************************************
buildProject(lcPath+"/../Source/PdfiumReport.pjx", "app", lcPath+"/../Release/PdfiumReport.app")
buildProject(lcPath+"/../Sample/sample.pjx", "exe")
buildProject(lcPath+"/../Tests/tests_run.pjx", "exe")
******************************************

******************************************
COPY FILE lcPath+"/../Source/pdfium-vfp.vcx" TO lcPath+"/../Release/pdfium-vfp.vcx"
COPY FILE lcPath+"/../Source/pdfium-vfp.vct" TO lcPath+"/../Release/pdfium-vfp.vct"
******************************************

******************************************
LOCAL loConsoleTools
loConsoleTools = NEWOBJECT("ConsoleTools", lcPath+"/Packages/FoxConsole/FoxConsole.prg")
loConsoleTools.makeconsoleapp(lcPath+"/../Tests/tests_run.exe")
******************************************


? TEXTMERGE("Build completed <<IIF(glBuildError, 'with error', 'succesfully')>>")

Expand Down
33 changes: 33 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,36 @@
1.14
- Removed redundant images compression:
- PdfiumViewer: removed rendering cache contained page images in png format. Rendering has become a bit faster and less blurry on small scaling
- PdfiumReport: removed pictures downscaling when original size of the image is greater than size of the picture control. Now images are stored in the output pdf in their original size that results in a better quality of image rendering when pdf is viewed.

- PdfiumReport: Improved quality of rendering text as an image (text in symbol fonts, rotated text).

- PdfiumReport: Retrieving pictures embedded in application executable.

Added property `PdfiumReport.Ext_Func_GetFileData`
```
* Basic usage
**********************************************************************************************
_REPORTOUTPUT = "pdfiumreport.app"
DO (_REPORTOUTPUT)
...
* Sample function to retrieve pictures embedded in application executable
SET PROCEDURE TO sample_getfiledata.prg ADDITIVE
_PdfiumReport.Ext_Func_GetFileData = "sample_getfiledata"
**********************************************************************************************
* sample_getfiledata.prg
**********************************************************************************************
LPARAMETERS lcFileName
RETURN FILETOSTR(m.lcFileName)
**********************************************************************************************
```

- Increased test coverage


1.13
- Folder structure reorganization
- All binaries were moved to the Release folder
Expand Down
Binary file modified Release/pdfium-vfp.vct
Binary file not shown.
Binary file modified Release/pdfium-vfp.vcx
Binary file not shown.
Binary file modified Release/pdfiumreport.app
Binary file not shown.
Binary file modified Sample/report1.frx
Binary file not shown.
Binary file modified Sample/report2.frx
Binary file not shown.
Binary file modified Sample/sample.exe
Binary file not shown.
1 change: 1 addition & 0 deletions Sample/sample.pj2
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ WITH loProject.FILES
.ADD('report2.frx') && *< FileMetadata: Type="R" Cpid="0" Timestamp="0" ID="0" ObjRev="0" User="" />
.ADD('sample.prg') && *< FileMetadata: Type="P" Cpid="1251" Timestamp="0" ID="0" ObjRev="544" User="" />
.ADD('sample.scx') && *< FileMetadata: Type="K" Cpid="1251" Timestamp="0" ID="0" ObjRev="544" User="" />
.ADD('sample_getfiledata.prg') && *< FileMetadata: Type="P" Cpid="1251" Timestamp="0" ID="0" ObjRev="544" User="" />
*</BuildProj>

.ITEM('__newproject.f2b').Remove()
Expand Down
Binary file modified Sample/sample.pjt
Binary file not shown.
Binary file modified Sample/sample.pjx
Binary file not shown.
8 changes: 7 additions & 1 deletion Sample/sample.sc2
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ DEFINE CLASS sample AS form
Height = 741
Left = 0
MinWidth = 1235
Name = "sample"
Name = "SAMPLE"
ScrollBars = 2
ShowWindow = 0
Top = 0
Expand Down Expand Up @@ -797,6 +797,12 @@ DEFINE CLASS sample AS form
_PdfiumReport.SaveAs_PDFMeta.Permit_Edit = .T. && Allow to make annotations and fill forms
**********************************************************************************************

**********************************************************************************************
* Sample function to retrieve pictures embedded in application executable
SET PROCEDURE TO sample_getfiledata.prg ADDITIVE
_PdfiumReport.Ext_Func_GetFileData = "sample_getfiledata"
**********************************************************************************************

REPORT FORM Report1.frx NOPAGEEJECT
REPORT FORM Report2.frx PREVIEW

Expand Down
Binary file modified Sample/sample.sct
Binary file not shown.
Binary file modified Sample/sample.scx
Binary file not shown.
3 changes: 3 additions & 0 deletions Sample/sample_getfiledata.prg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
LPARAMETERS lcFileName

RETURN FILETOSTR(m.lcFileName)
Binary file modified Source/PdfiumReport.PJT
Binary file not shown.
Binary file modified Source/PdfiumReport.pjx
Binary file not shown.
Loading

0 comments on commit f02b319

Please sign in to comment.