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 @@
/*
DumpPrintJob
Copyright (c) 2002 OpenBeOS.
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.
*/
* Copyright 2002-2007, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* Michael Pfeiffer
*/
#include <stdio.h>
#include <PrintJob.h>
@ -33,92 +12,71 @@ THE SOFTWARE.
#include "PicturePrinter.h"
#include "PrintJobReader.h"
void print(char* s) {
fprintf(stderr, s);
}
void print(char* argv[]) {
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;
void printArguments(const char* application) {
printf("Usage: %s [--pictures] files\n", application);
printf("Prints the contents of the specified spool files to stdout.\n"
"Arguments:\n"
" --pictures print contents of pictures\n");
}
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 ++) {
BFile jobFile(argv[i], B_READ_WRITE);
if (jobFile.InitCheck() == B_OK) {
PrintJobReader reader(&jobFile);
if (reader.InitCheck() == B_OK) {
printf("%s: JobMessage\n", argv[0]);
reader.JobSettings()->PrintToStream();
int32 pages = reader.NumberOfPages();
for (int page = 0; page < pages; page ++) {
printf("Page %d\n", page+1);
PrintJobPage pjp;
if (reader.GetPage(page, pjp) == B_OK) {
BPicture picture; BPoint p; BRect r;
printf("Number of pictures %ld\n", pjp.NumberOfPictures());
while (pjp.NextPicture(picture, p, r) == B_OK) {
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);
const char* arg = argv[i];
if (strcmp(arg, "--pictures") == 0) {
printPicture = true;
continue;
}
hasFiles = true;
BFile jobFile(arg, B_READ_WRITE);
if (jobFile.InitCheck() != B_OK) {
fprintf(stderr, "Error opening file %s!\n", arg);
continue;
}
PrintJobReader reader(&jobFile);
if (reader.InitCheck() != B_OK) {
fprintf(stderr, "Error reading spool file %s!", arg);
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;
printer.Iterate(&picture);
}
}
}
}
/*
print_file_header header;
if (jobFile.Read(&header, sizeof(header)) == sizeof(header)) {
BMessage jobMsg;
if (jobMsg.Unflatten(&jobFile) == B_OK) {
printf("%s: JobMessage\n", argv[0]);
jobMsg.PrintToStream();
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");
BPicture 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,
rect.left, rect.top, rect.right, rect.bottom);
if (printPicture) {
printf("Picture:\n");
PicturePrinter printer;
printer.Iterate(&picture);
}
} else {
print(argv); print("Could not read print_job_header\n");
}
*/
} else {
print(argv); print("Error opening file!\n");
}
}
if (!hasFiles)
printArguments(argv[0]);
}