Added argument --pictures to print contents of unflattened pictures in

spool file.
Clean up.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20087 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Michael Pfeiffer 2007-02-06 20:52:48 +00:00
parent 2e7b1dcdb9
commit 91b6c45560

View File

@ -1,31 +1,10 @@
/* /*
* Copyright 2002-2007, Haiku.
DumpPrintJob * Distributed under the terms of the MIT License.
*
Copyright (c) 2002 OpenBeOS. * Authors:
* Michael Pfeiffer
Author: */
Michael Pfeiffer
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <stdio.h> #include <stdio.h>
#include <PrintJob.h> #include <PrintJob.h>
@ -33,92 +12,71 @@ THE SOFTWARE.
#include "PicturePrinter.h" #include "PicturePrinter.h"
#include "PrintJobReader.h" #include "PrintJobReader.h"
void print(char* s) { void printArguments(const char* application) {
fprintf(stderr, s); printf("Usage: %s [--pictures] files\n", application);
} printf("Prints the contents of the specified spool files to stdout.\n"
"Arguments:\n"
void print(char* argv[]) { " --pictures print contents of pictures\n");
fprintf(stderr, "%s: ", argv[0]);
}
status_t dump_page(BFile* jobFile) {
int32 pictureCount;
status_t rc = B_OK;
jobFile->Read(&pictureCount, sizeof(pictureCount));
printf("Pictures %ld\n", pictureCount);
for (int i = 0; rc == B_OK && i < pictureCount; i ++) {
BPoint p; BRect r;
off_t v;
jobFile->Read(&v, sizeof(v));
printf("next picture %Lx %Lx %Lx\n", jobFile->Position(), v, v + jobFile->Position());
jobFile->Seek(40, SEEK_CUR);
jobFile->Read(&p, sizeof(p));
jobFile->Read(&r, sizeof(r));
BPicture picture;
rc = picture.Unflatten(jobFile);
if (rc == B_OK) {
PicturePrinter printer;
printf("Picture point (%f, %f) rect [l: %f t: %f r: %f b: %f]\n",
p.x, p.y,
r.left, r.top, r.right, r.bottom);
// printer.Iterate(&picture);
printf("==========================\n");
} else {
fprintf(stderr, "Error unflattening picture\n");
}
}
return rc;
} }
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
BApplication app("application/x-vnd.obos.dump-print-job"); BApplication app("application/x-vnd.Haiku.dump-print-job");
bool printPicture = false;
bool hasFiles = false;
for (int i = 1; i < argc; i ++) { for (int i = 1; i < argc; i ++) {
BFile jobFile(argv[i], B_READ_WRITE); const char* arg = argv[i];
if (jobFile.InitCheck() == B_OK) { if (strcmp(arg, "--pictures") == 0) {
PrintJobReader reader(&jobFile); printPicture = true;
if (reader.InitCheck() == B_OK) { continue;
printf("%s: JobMessage\n", argv[0]); }
reader.JobSettings()->PrintToStream();
int32 pages = reader.NumberOfPages(); hasFiles = true;
for (int page = 0; page < pages; page ++) { BFile jobFile(arg, B_READ_WRITE);
printf("Page %d\n", page+1); if (jobFile.InitCheck() != B_OK) {
PrintJobPage pjp; fprintf(stderr, "Error opening file %s!\n", arg);
if (reader.GetPage(page, pjp) == B_OK) { continue;
BPicture picture; BPoint p; BRect r; }
printf("Number of pictures %ld\n", pjp.NumberOfPictures());
while (pjp.NextPicture(picture, p, r) == B_OK) { PrintJobReader reader(&jobFile);
printf("Picture point (%f, %f) rect [l: %f t: %f r: %f b: %f]\n", if (reader.InitCheck() != B_OK) {
p.x, p.y, fprintf(stderr, "Error reading spool file %s!", arg);
r.left, r.top, r.right, r.bottom); continue;
}
printf("Spool file: %s\n", arg);
printf("Job settings message:\n");
reader.JobSettings()->PrintToStream();
int32 pages = reader.NumberOfPages();
printf("Number of pages: %d\n", (int)pages);
for (int page = 0; page < pages; page ++) {
printf("Page: %d\n", page+1);
PrintJobPage pjp;
if (reader.GetPage(page, pjp) != B_OK) {
fprintf(stderr, "Error reading page!\n");
break;
}
PicturePrinter printer; BPicture picture;
printer.Iterate(&picture); BPoint pos;
} BRect rect;
} printf("Number of pictures: %ld\n", pjp.NumberOfPictures());
} while (pjp.NextPicture(picture, pos, rect) == B_OK) {
} printf("Picture position = (%f, %f) bounds = [l: %f t: %f r: %f b: %f]\n",
/* pos.x, pos.y,
print_file_header header; rect.left, rect.top, rect.right, rect.bottom);
if (jobFile.Read(&header, sizeof(header)) == sizeof(header)) {
BMessage jobMsg; if (printPicture) {
if (jobMsg.Unflatten(&jobFile) == B_OK) { printf("Picture:\n");
printf("%s: JobMessage\n", argv[0]); PicturePrinter printer;
jobMsg.PrintToStream(); printer.Iterate(&picture);
int32 pages = header.page_count;
for (int page = 0; page < pages; page ++) {
printf("Page %d offset %lx\n", page+1, jobFile.Position());
if (dump_page(&jobFile) != B_OK) break;
}
} else {
print(argv); print("Could not unflatten job message\n");
} }
} else {
print(argv); print("Could not read print_job_header\n");
} }
*/
} else {
print(argv); print("Error opening file!\n");
} }
} }
if (!hasFiles)
printArguments(argv[0]);
} }