Capture further jobs to be printed on this device.
(self, arg)
| 628 | |
| 629 | # ------------------------[ capture <operation> ]--------------------- |
| 630 | def do_capture(self, arg): |
| 631 | "Capture further jobs to be printed on this device." |
| 632 | free = '5' # memory limit in megabytes that must at least be free to capture print jobs |
| 633 | # record future print jobs |
| 634 | if arg.startswith('start'): |
| 635 | output().psonly() |
| 636 | # PRET commands themself should not be capture if they're performed within ≤ 10s idle |
| 637 | ''' |
| 638 | ┌──────────┬───────────────────────────────┬───────────────┐ |
| 639 | │ hooking: │ BeginPage/EndPage │ overwrite all │ |
| 640 | ├──────────┼───────────────────────────────┼───────────────┤ |
| 641 | │ metadat: │ ✔ │ - │ |
| 642 | ├──────────┼───────────────────────────────┼───────┬───────┤ |
| 643 | │ globals: │ we are already global(?) │ need │ none │ |
| 644 | ├──────────┼───────────────┬───────────────┼───────┴───────┤ |
| 645 | │ capture: │ currentfile │ %lineedit │ currentfile │ |
| 646 | ├──────────┼───────┬───────┼───────┬───────┼───────┬───────┤ |
| 647 | │ storage: │ nfile │ vfile │ nfile │ array │ vfile │ nfile │ |
| 648 | ├──────────┼───────┼───────┼───────┼───────┼───────┼───────┤ |
| 649 | │ package: │ ✔ │ ? │ ✔ │ ? │ ? │ ✔ │ |
| 650 | ├──────────┼───────┼───────┼───────┼───────┼───────┼───────┤ |
| 651 | │ execute: │ ✔ │ ✔ │ ✔ │ - │ ✔ │ ✔ │ |
| 652 | └──────────┴───────┴───────┴───────┴───────┴───────┴───────┘ |
| 653 | ''' |
| 654 | str_send = 'true 0 startjob { \n'\ |
| 655 | '/setoldtime {/oldtime realtime def} def setoldtime \n'\ |
| 656 | '/threshold {realtime oldtime sub abs 10000 lt} def \n'\ |
| 657 | '/free {vmstatus exch pop exch pop 1048576 div '+free+' ge} def \n'\ |
| 658 | '%---------------------------------------------------------------------\n'\ |
| 659 | '%--------------[ get current document as file object ]----------------\n'\ |
| 660 | '%---------------------------------------------------------------------\n'\ |
| 661 | '/document {(%stdin) (r) file /ReusableStreamDecode filter} bind def \n'\ |
| 662 | '%---------------------------------------------------------------------\n'\ |
| 663 | '/capturehook {{ \n'\ |
| 664 | ' threshold {(Within threshold - will not capture\\n) print flush \n'\ |
| 665 | ' setoldtime \n'\ |
| 666 | '}{ \n'\ |
| 667 | ' setoldtime \n'\ |
| 668 | ' free not {(Out of memory\\n) print flush}{ \n'\ |
| 669 | ' % (This job will be captured in memory\\n) print flush \n'\ |
| 670 | ' setoldtime \n'\ |
| 671 | ' false echo % stop interpreter slowdown \n'\ |
| 672 | ' /timestamp realtime def % get time from interpreter \n'\ |
| 673 | ' userdict /capturedict known not % print jobs are saved here \n'\ |
| 674 | ' {/capturedict 50000 dict def} if % define capture dictionary \n'\ |
| 675 | ' %-------------------------------------------------------------------\n'\ |
| 676 | ' %--------------[ save document to dict and print it ]---------------\n'\ |
| 677 | ' %-------------------------------------------------------------------\n'\ |
| 678 | ' capturedict timestamp document put % store document in memory \n'\ |
| 679 | ' capturedict timestamp get cvx exec % print the actual document \n'\ |
| 680 | ' clear cleardictstack % restore original vm state \n'\ |
| 681 | ' %-------------------------------------------------------------------\n'\ |
| 682 | ' setoldtime \n'\ |
| 683 | ' } ifelse} ifelse} stopped} bind def \n'\ |
| 684 | '<< /BeginPage {capturehook} bind >> setpagedevice \n'\ |
| 685 | '(Future print jobs will be captured in memory!)} \n'\ |
| 686 | '{(Cannot capture - unlock me first)} ifelse print' |
| 687 | output().raw(self.cmd(str_send)) |
nothing calls this directly
no test coverage detected