diff --git a/src/tests/kits/interface/picture/DumpPrintJob.cpp b/src/tests/kits/interface/picture/DumpPrintJob.cpp new file mode 100644 index 0000000000..24afa896d2 --- /dev/null +++ b/src/tests/kits/interface/picture/DumpPrintJob.cpp @@ -0,0 +1,124 @@ +/* + +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. + +*/ + +#include +#include + +#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 %d\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[]) { + BApplication app("application/x-vnd.obos.dump-print-job"); + 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 %d\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); + + 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"); + } + } else { + print(argv); print("Could not read print_job_header\n"); + } + */ + } else { + print(argv); print("Error opening file!\n"); + } + } +} diff --git a/src/tests/kits/interface/picture/Jamfile b/src/tests/kits/interface/picture/Jamfile new file mode 100644 index 0000000000..9e05aae1f7 --- /dev/null +++ b/src/tests/kits/interface/picture/Jamfile @@ -0,0 +1,54 @@ +SubDir OBOS_TOP src tests kits interface picture ; + +UsePrivateHeaders interface ; + +SimpleTest + TestPictureApp + : + PictureTestApp.cpp + PictureTestView.cpp + TestView.cpp + PictureTestWindow.cpp + PictureIterator.cpp + PicturePrinter.cpp + ; + +LinkSharedOSLibs + TestPictureApp + : + be + root + ; + + +SimpleTest + DumpPrintJob + : + DumpPrintJob.cpp + PictureIterator.cpp + PicturePrinter.cpp + PrintJobReader.cpp + ; + +LinkSharedOSLibs + DumpPrintJob + : + be + root + ; + +SimpleTest + Preview + : + Preview.cpp + PictureIterator.cpp + PicturePrinter.cpp + PrintJobReader.cpp + ; + +LinkSharedOSLibs + Preview + : + be + root + ; diff --git a/src/tests/kits/interface/picture/PictureIterator.cpp b/src/tests/kits/interface/picture/PictureIterator.cpp new file mode 100644 index 0000000000..b89825c46a --- /dev/null +++ b/src/tests/kits/interface/picture/PictureIterator.cpp @@ -0,0 +1,151 @@ +/* + +PictureIterator + +Copyright (c) 2001, 2002 OpenBeOS. + +Authors: + Philippe Houdoin + Simon Gauvin + 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 "PictureIterator.h" + +// BPicture playback handlers class instance redirectors +static void _MovePenBy(void *p, BPoint delta) { return ((PictureIterator *) p)->MovePenBy(delta); } +static void _StrokeLine(void *p, BPoint start, BPoint end) { return ((PictureIterator *) p)->StrokeLine(start, end); } +static void _StrokeRect(void *p, BRect rect) { return ((PictureIterator *) p)->StrokeRect(rect); } +static void _FillRect(void *p, BRect rect) { return ((PictureIterator *) p)->FillRect(rect); } +static void _StrokeRoundRect(void *p, BRect rect, BPoint radii) { return ((PictureIterator *) p)->StrokeRoundRect(rect, radii); } +static void _FillRoundRect(void *p, BRect rect, BPoint radii) { return ((PictureIterator *) p)->FillRoundRect(rect, radii); } +static void _StrokeBezier(void *p, BPoint *control) { return ((PictureIterator *) p)->StrokeBezier(control); } +static void _FillBezier(void *p, BPoint *control) { return ((PictureIterator *) p)->FillBezier(control); } +static void _StrokeArc(void *p, BPoint center, BPoint radii, float startTheta, float arcTheta) { return ((PictureIterator *) p)->StrokeArc(center, radii, startTheta, arcTheta); } +static void _FillArc(void *p, BPoint center, BPoint radii, float startTheta, float arcTheta) { return ((PictureIterator *) p)->FillArc(center, radii, startTheta, arcTheta); } +static void _StrokeEllipse(void *p, BPoint center, BPoint radii) { return ((PictureIterator *) p)->StrokeEllipse(center, radii); } +static void _FillEllipse(void *p, BPoint center, BPoint radii) { return ((PictureIterator *) p)->FillEllipse(center, radii); } +static void _StrokePolygon(void *p, int32 numPoints, BPoint *points, bool isClosed) { return ((PictureIterator *) p)->StrokePolygon(numPoints, points, isClosed); } +static void _FillPolygon(void *p, int32 numPoints, BPoint *points, bool isClosed) { return ((PictureIterator *) p)->FillPolygon(numPoints, points, isClosed); } +static void _StrokeShape(void * p, BShape *shape) { return ((PictureIterator *) p)->StrokeShape(shape); } +static void _FillShape(void * p, BShape *shape) { return ((PictureIterator *) p)->FillShape(shape); } +static void _DrawString(void *p, char *string, float deltax, float deltay) { return ((PictureIterator *) p)->DrawString(string, deltax, deltay); } +static void _DrawPixels(void *p, BRect src, BRect dest, int32 width, int32 height, int32 bytesPerRow, int32 pixelFormat, int32 flags, void *data) + { return ((PictureIterator *) p)->DrawPixels(src, dest, width, height, bytesPerRow, pixelFormat, flags, data); } +static void _SetClippingRects(void *p, BRect *rects, uint32 numRects) { return ((PictureIterator *) p)->SetClippingRects(rects, numRects); } +static void _ClipToPicture(void * p, BPicture *picture, BPoint point, bool clip_to_inverse_picture) { return ((PictureIterator *) p)->ClipToPicture(picture, point, clip_to_inverse_picture); } +static void _PushState(void *p) { return ((PictureIterator *) p)->PushState(); } +static void _PopState(void *p) { return ((PictureIterator *) p)->PopState(); } +static void _EnterStateChange(void *p) { return ((PictureIterator *) p)->EnterStateChange(); } +static void _ExitStateChange(void *p) { return ((PictureIterator *) p)->ExitStateChange(); } +static void _EnterFontState(void *p) { return ((PictureIterator *) p)->EnterFontState(); } +static void _ExitFontState(void *p) { return ((PictureIterator *) p)->ExitFontState(); } +static void _SetOrigin(void *p, BPoint pt) { return ((PictureIterator *) p)->SetOrigin(pt); } +static void _SetPenLocation(void *p, BPoint pt) { return ((PictureIterator *) p)->SetPenLocation(pt); } +static void _SetDrawingMode(void *p, drawing_mode mode) { return ((PictureIterator *) p)->SetDrawingMode(mode); } +static void _SetLineMode(void *p, cap_mode capMode, join_mode joinMode, float miterLimit) { return ((PictureIterator *) p)->SetLineMode(capMode, joinMode, miterLimit); } +static void _SetPenSize(void *p, float size) { return ((PictureIterator *) p)->SetPenSize(size); } +static void _SetForeColor(void *p, rgb_color color) { return ((PictureIterator *) p)->SetForeColor(color); } +static void _SetBackColor(void *p, rgb_color color) { return ((PictureIterator *) p)->SetBackColor(color); } +static void _SetStipplePattern(void *p, pattern pat) { return ((PictureIterator *) p)->SetStipplePattern(pat); } +static void _SetScale(void *p, float scale) { return ((PictureIterator *) p)->SetScale(scale); } +static void _SetFontFamily(void *p, char *family) { return ((PictureIterator *) p)->SetFontFamily(family); } +static void _SetFontStyle(void *p, char *style) { return ((PictureIterator *) p)->SetFontStyle(style); } +static void _SetFontSpacing(void *p, int32 spacing) { return ((PictureIterator *) p)->SetFontSpacing(spacing); } +static void _SetFontSize(void *p, float size) { return ((PictureIterator *) p)->SetFontSize(size); } +static void _SetFontRotate(void *p, float rotation) { return ((PictureIterator *) p)->SetFontRotate(rotation); } +static void _SetFontEncoding(void *p, int32 encoding) { return ((PictureIterator *) p)->SetFontEncoding(encoding); } +static void _SetFontFlags(void *p, int32 flags) { return ((PictureIterator *) p)->SetFontFlags(flags); } +static void _SetFontShear(void *p, float shear) { return ((PictureIterator *) p)->SetFontShear(shear); } +static void _SetFontFace(void * p, int32 flags) { return ((PictureIterator *) p)->SetFontFace(flags); } + +// undefined or undocumented operation handlers... +static void _op0(void * p) { return ((PictureIterator *) p)->Op(0); } +static void _op19(void * p) { return ((PictureIterator *) p)->Op(19); } +static void _op45(void * p) { return ((PictureIterator *) p)->Op(45); } +static void _op47(void * p) { return ((PictureIterator *) p)->Op(47); } +static void _op48(void * p) { return ((PictureIterator *) p)->Op(48); } +static void _op49(void * p) { return ((PictureIterator *) p)->Op(49); } + +// Private Variables +// ----------------- + +static void * +playbackHandlers[] = { + _op0, // 0 no operation + _MovePenBy, // 1 MovePenBy(void *user, BPoint delta) + _StrokeLine, // 2 StrokeLine(void *user, BPoint start, BPoint end) + _StrokeRect, // 3 StrokeRect(void *user, BRect rect) + _FillRect, // 4 FillRect(void *user, BRect rect) + _StrokeRoundRect, // 5 StrokeRoundRect(void *user, BRect rect, BPoint radii) + _FillRoundRect, // 6 FillRoundRect(void *user, BRect rect, BPoint radii) + _StrokeBezier, // 7 StrokeBezier(void *user, BPoint *control) + _FillBezier, // 8 FillBezier(void *user, BPoint *control) + _StrokeArc, // 9 StrokeArc(void *user, BPoint center, BPoint radii, float startTheta, float arcTheta) + _FillArc, // 10 FillArc(void *user, BPoint center, BPoint radii, float startTheta, float arcTheta) + _StrokeEllipse, // 11 StrokeEllipse(void *user, BPoint center, BPoint radii) + _FillEllipse, // 12 FillEllipse(void *user, BPoint center, BPoint radii) + _StrokePolygon, // 13 StrokePolygon(void *user, int32 numPoints, BPoint *points, bool isClosed) + _FillPolygon, // 14 FillPolygon(void *user, int32 numPoints, BPoint *points, bool isClosed) + _StrokeShape, // 15 StrokeShape(void *user, BShape *shape) + _FillShape, // 16 FillShape(void *user, BShape *shape) + _DrawString, // 17 DrawString(void *user, char *string, float deltax, float deltay) + _DrawPixels, // 18 DrawPixels(void *user, BRect src, BRect dest, int32 width, int32 height, int32 bytesPerRow, int32 pixelFormat, int32 flags, void *data) + _op19, // 19 *reserved* + _SetClippingRects, // 20 SetClippingRects(void *user, BRect *rects, uint32 numRects) + _ClipToPicture, // 21 ClipToPicture(void *user, BPicture *picture, BPoint pt, bool clip_to_inverse_picture) + _PushState, // 22 PushState(void *user) + _PopState, // 23 PopState(void *user) + _EnterStateChange, // 24 EnterStateChange(void *user) + _ExitStateChange, // 25 ExitStateChange(void *user) + _EnterFontState, // 26 EnterFontState(void *user) + _ExitFontState, // 27 ExitFontState(void *user) + _SetOrigin, // 28 SetOrigin(void *user, BPoint pt) + _SetPenLocation, // 29 SetPenLocation(void *user, BPoint pt) + _SetDrawingMode, // 30 SetDrawingMode(void *user, drawing_mode mode) + _SetLineMode, // 31 SetLineMode(void *user, cap_mode capMode, join_mode joinMode, float miterLimit) + _SetPenSize, // 32 SetPenSize(void *user, float size) + _SetForeColor, // 33 SetForeColor(void *user, rgb_color color) + _SetBackColor, // 34 SetBackColor(void *user, rgb_color color) + _SetStipplePattern, // 35 SetStipplePattern(void *user, pattern p) + _SetScale, // 36 SetScale(void *user, float scale) + _SetFontFamily, // 37 SetFontFamily(void *user, char *family) + _SetFontStyle, // 38 SetFontStyle(void *user, char *style) + _SetFontSpacing, // 39 SetFontSpacing(void *user, int32 spacing) + _SetFontSize, // 40 SetFontSize(void *user, float size) + _SetFontRotate, // 41 SetFontRotate(void *user, float rotation) + _SetFontEncoding, // 42 SetFontEncoding(void *user, int32 encoding) + _SetFontFlags, // 43 SetFontFlags(void *user, int32 flags) + _SetFontShear, // 44 SetFontShear(void *user, float shear) + _op45, // 45 *reserved* + _SetFontFace, // 46 SetFontFace(void *user, int32 flags) + _op47, + _op48, + _op49, + + NULL + }; + +void +PictureIterator::Iterate(BPicture* picture) { + picture->Play(playbackHandlers, 50, this); +} diff --git a/src/tests/kits/interface/picture/PictureIterator.h b/src/tests/kits/interface/picture/PictureIterator.h new file mode 100644 index 0000000000..98cd2fe588 --- /dev/null +++ b/src/tests/kits/interface/picture/PictureIterator.h @@ -0,0 +1,93 @@ +/* + +PictureIterator. + +Copyright (c) 2001, 2002 OpenBeOS. + +Authors: + Philippe Houdoin + Simon Gauvin + 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. + +*/ + +#ifndef _PICTURE_ITERATOR_H +#define _PICTURE_TIERATOR_H + +#include +#include + +class PictureIterator +{ +public: + virtual ~PictureIterator() { } + + // BPicture playback handlers + virtual void Op(int number) { } + virtual void MovePenBy(BPoint delta) { } + virtual void StrokeLine(BPoint start, BPoint end) { } + virtual void StrokeRect(BRect rect) { } + virtual void FillRect(BRect rect) { } + virtual void StrokeRoundRect(BRect rect, BPoint radii) { } + virtual void FillRoundRect(BRect rect, BPoint radii) { } + virtual void StrokeBezier(BPoint *control) { } + virtual void FillBezier(BPoint *control) { } + virtual void StrokeArc(BPoint center, BPoint radii, float startTheta, float arcTheta) { } + virtual void FillArc(BPoint center, BPoint radii, float startTheta, float arcTheta) { } + virtual void StrokeEllipse(BPoint center, BPoint radii) { } + virtual void FillEllipse(BPoint center, BPoint radii) { } + virtual void StrokePolygon(int32 numPoints, BPoint *points, bool isClosed) { } + virtual void FillPolygon(int32 numPoints, BPoint *points, bool isClosed) { } + virtual void StrokeShape(BShape *shape) { } + virtual void FillShape(BShape *shape) { } + virtual void DrawString(char *string, float escapement_nospace, float escapement_space) { } + virtual void DrawPixels(BRect src, BRect dest, int32 width, int32 height, int32 bytesPerRow, int32 pixelFormat, int32 flags, void *data) { } + virtual void SetClippingRects(BRect *rects, uint32 numRects) { } + virtual void ClipToPicture(BPicture *picture, BPoint point, bool clip_to_inverse_picture) { } + virtual void PushState() { } + virtual void PopState() { } + virtual void EnterStateChange() { } + virtual void ExitStateChange() { } + virtual void EnterFontState() { } + virtual void ExitFontState() { } + virtual void SetOrigin(BPoint pt) { } + virtual void SetPenLocation(BPoint pt) { } + virtual void SetDrawingMode(drawing_mode mode) { } + virtual void SetLineMode(cap_mode capMode, join_mode joinMode, float miterLimit) { } + virtual void SetPenSize(float size) { } + virtual void SetForeColor(rgb_color color) { } + virtual void SetBackColor(rgb_color color) { } + virtual void SetStipplePattern(pattern p) { } + virtual void SetScale(float scale) { } + virtual void SetFontFamily(char *family) { } + virtual void SetFontStyle(char *style) { } + virtual void SetFontSpacing(int32 spacing) { } + virtual void SetFontSize(float size) { } + virtual void SetFontRotate(float rotation) { } + virtual void SetFontEncoding(int32 encoding) { } + virtual void SetFontFlags(int32 flags) { } + virtual void SetFontShear(float shear) { } + virtual void SetFontFace(int32 flags) { } + + virtual void Iterate(BPicture* picture); +}; + +#endif _PICTURE_ITERATOR_H diff --git a/src/tests/kits/interface/picture/PicturePrinter.cpp b/src/tests/kits/interface/picture/PicturePrinter.cpp new file mode 100644 index 0000000000..30d47dbd2d --- /dev/null +++ b/src/tests/kits/interface/picture/PicturePrinter.cpp @@ -0,0 +1,479 @@ +/* + +PicturePrinter + +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. + +*/ + +#include + +#include "PicturePrinter.h" + +PicturePrinter::PicturePrinter(int indent) + : fIndent(indent) + { + } + +void PicturePrinter::Print(const char* text) { + printf("%s ", text); +} + +void PicturePrinter::Print(BPoint* p) { + printf("point (%f, %f) ", p->x, p->y); +} + +void PicturePrinter::Print(BRect* r) { + printf("rect [l: %f, t: %f, r: %f, b: %f] ", r->left, r->top, r->right, r->bottom); +} + +void PicturePrinter::Print(int numPoints, BPoint* points) { + for (int i = 0; i < numPoints; i ++) { + Indent(1); printf("%d ", i); Print(&points[i]); Cr(); + } +} + +void PicturePrinter::Print(int numRects, BRect* rects) { + for (int i = 0; i < numRects; i ++) { + Indent(1); printf("%d ", i); Print(&rects[i]); Cr(); + } +} + +void PicturePrinter::Print(BShape* shape) { + printf("Shape %p\n", shape); + ShapePrinter printer(this); + printer.Iterate(shape); +} + +void PicturePrinter::Print(const char* text, float f) { + printf("%s %f ", text, f); +} + +void PicturePrinter::Print(const char* text, BPoint* point) { + Print(text); Print(point); +} + +void PicturePrinter::Print(rgb_color color) { + printf("color r: %d g: %d b: %d", color.red, color.green, color.blue); +} + +void PicturePrinter::Print(float f) { + printf("%f ", f); +} + +void PicturePrinter::Cr() { + printf("\n"); +} + +void PicturePrinter::Indent(int inc) { + for (int i = fIndent + inc; i > 0; i --) printf(" "); +} + +void PicturePrinter::IncIndent() { + fIndent ++; +} + +void PicturePrinter::DecIndent() { + fIndent --; +} + +void PicturePrinter::Op(int number) { + Indent(); printf("Unknown operator %d\n", number); Cr(); +} + + +void PicturePrinter::MovePenBy(BPoint delta) { + Indent(); Print("MovePenBy"); Print(&delta); Cr(); +} + + +void PicturePrinter::StrokeLine(BPoint start, BPoint end) { + Indent(); Print("StrokeLine"); Print(&start); Print(&end); Cr(); +} + + +void PicturePrinter::StrokeRect(BRect rect) { + Indent(); Print("StrokeRect"); Print(&rect); Cr(); +} + + +void PicturePrinter::FillRect(BRect rect) { + Indent(); Print("FillRect"); Print(&rect); Cr(); +} + + +void PicturePrinter::StrokeRoundRect(BRect rect, BPoint radii) { + Indent(); Print("StrokeRoundRect"); Print(&rect); Print("radii", &radii); Cr(); +} + + +void PicturePrinter::FillRoundRect(BRect rect, BPoint radii) { + Indent(); Print("FillRoundRect"); Print(&rect); Print("radii", &radii); Cr(); +} + + +void PicturePrinter::StrokeBezier(BPoint *control) { + Indent(); Print("StrokeBezier"); Print(4, control); Cr(); +} + + +void PicturePrinter::FillBezier(BPoint *control) { + Indent(); Print("FillBezier"); Print(4, control); Cr(); +} + + +void PicturePrinter::StrokeArc(BPoint center, BPoint radii, float startTheta, float arcTheta) { + Indent(); Print("StrokeArc center="); Print(¢er); Print("radii="); Print(&radii); Print("arcTheta=", arcTheta); Cr(); +} + + +void PicturePrinter::FillArc(BPoint center, BPoint radii, float startTheta, float arcTheta) { + Indent(); Print("FillArc center="); Print(¢er); Print("radii="); Print(&radii); Print("arcTheta=", arcTheta); Cr(); +} + + +void PicturePrinter::StrokeEllipse(BPoint center, BPoint radii) { + Indent(); Print("StrokeEllipse center="); Print(¢er); Print("radii="); Print(&radii); Cr(); +} + + +void PicturePrinter::FillEllipse(BPoint center, BPoint radii) { + Indent(); Print("FillEllipse center="); Print(¢er); Print("radii="); Print(&radii); Cr(); +} + + +void PicturePrinter::StrokePolygon(int32 numPoints, BPoint *points, bool isClosed) { + Indent(); Print("StrokePolygon"); + printf("%s ", isClosed ? "closed" : "open"); Cr(); + Print(numPoints, points); +} + + +void PicturePrinter::FillPolygon(int32 numPoints, BPoint *points, bool isClosed) { + Indent(); Print("FillPolygon"); + printf("%s ", isClosed ? "closed" : "open"); Cr(); + Print(numPoints, points); +} + + +void PicturePrinter::StrokeShape(BShape *shape) { + Indent(); Print("StrokeShape"); Print(shape); Cr(); +} + + +void PicturePrinter::FillShape(BShape *shape) { + Indent(); Print("FillShape"); Print(shape); Cr(); +} + + +void PicturePrinter::DrawString(char *string, float escapement_nospace, float escapement_space) { + Indent(); Print("DrawString"); + Print("escapement_nospace", escapement_nospace); + Print("escapement_space", escapement_space); + Print("text:"); Print(string); Cr(); +} + + +void PicturePrinter::DrawPixels(BRect src, BRect dest, int32 width, int32 height, int32 bytesPerRow, int32 pixelFormat, int32 flags, void *data) { + Indent(); Print("DrawPixels"); Cr(); +} + + +void PicturePrinter::SetClippingRects(BRect *rects, uint32 numRects) { + Indent(); Print("SetClippingRects"); + if (numRects == 0) Print("none"); Cr(); + Print(numRects, rects); +} + + +void PicturePrinter::ClipToPicture(BPicture *picture, BPoint point, bool clip_to_inverse_picture) { + Indent(); + Print(clip_to_inverse_picture ? "ClipToInversePicture" : "ClipToPicture"); + Print("point=", &point); Cr(); + PicturePrinter printer(fIndent+1); + printer.Iterate(picture); +} + + +void PicturePrinter::PushState() { + Indent(); Print("PushState"); Cr(); + IncIndent(); +} + + +void PicturePrinter::PopState() { + DecIndent(); + Indent(); Print("PopState"); Cr(); +} + + +void PicturePrinter::EnterStateChange() { + Indent(); Print("EnterStateChange"); Cr(); +} + + +void PicturePrinter::ExitStateChange() { + Indent(); Print("ExitStateChange"); Cr(); +} + + +void PicturePrinter::EnterFontState() { + Indent(); Print("EnterFontState"); Cr(); +} + + +void PicturePrinter::ExitFontState() { + Indent(); Print("ExitFontState"); Cr(); +} + + +void PicturePrinter::SetOrigin(BPoint pt) { + Indent(); Print("SetOrigin"); Print(&pt); Cr(); +} + + +void PicturePrinter::SetPenLocation(BPoint pt) { + Indent(); Print("SetPenLocation"); Print(&pt); Cr(); +} + + +void PicturePrinter::SetDrawingMode(drawing_mode mode) { + Indent(); Print("SetDrawingMode"); + switch (mode) { + case B_OP_COPY: Print("B_OP_COPY"); break; + case B_OP_OVER: Print("B_OP_OVER"); break; + case B_OP_ERASE: Print("B_OP_ERASE"); break; + case B_OP_INVERT: Print("B_OP_INVERT"); break; + case B_OP_SELECT: Print("B_OP_SELECT"); break; + case B_OP_ALPHA: Print("B_OP_ALPHA"); break; + case B_OP_MIN: Print("B_OP_MIN"); break; + case B_OP_MAX: Print("B_OP_MAX"); break; + case B_OP_ADD: Print("B_OP_ADD"); break; + case B_OP_SUBTRACT: Print("B_OP_SUBTRACT"); break; + case B_OP_BLEND: Print("B_OP_BLEND"); break; + default: Print("Unknown mode: ", (float)mode); + } + Cr(); +} + + +void PicturePrinter::SetLineMode(cap_mode capMode, join_mode joinMode, float miterLimit) { + Indent(); Print("SetLineMode"); + switch (capMode) { + case B_BUTT_CAP: Print("B_BUTT_CAP"); break; + case B_ROUND_CAP: Print("B_ROUND_CAP"); break; + case B_SQUARE_CAP: Print("B_SQUARE_CAP"); break; + } + switch (joinMode) { + case B_MITER_JOIN: Print("B_MITER_JOIN"); break; + case B_ROUND_JOIN: Print("B_ROUND_JOIN"); break; + case B_BUTT_JOIN: Print("B_BUTT_JOIN"); break; + case B_SQUARE_JOIN: Print("B_SQUARE_JOIN"); break; + case B_BEVEL_JOIN: Print("B_BEVEL_JOIN"); break; + } + Print("miterLimit", miterLimit); + Cr(); +} + + +void PicturePrinter::SetPenSize(float size) { + Indent(); Print("SetPenSize", size); Cr(); +} + + +void PicturePrinter::SetForeColor(rgb_color color) { + Indent(); Print("SetForeColor"); Print(color); Cr(); +} + + +void PicturePrinter::SetBackColor(rgb_color color) { + Indent(); Print("SetBackColor"); Print(color); Cr(); +} + +static bool compare(pattern a, pattern b) { + for (int i = 0; i < 8; i ++) { + if (a.data[i] != b.data[i]) return false; + } + return true; +} + +void PicturePrinter::SetStipplePattern(pattern p) { + Indent(); Print("SetStipplePattern"); + if (compare(p, B_SOLID_HIGH)) Print("B_SOLID_HIGH"); + else if (compare(p, B_SOLID_LOW)) Print("B_SOLID_LOW"); + else if (compare(p, B_MIXED_COLORS)) Print("B_MIXED_COLORS"); + else { + for (int i = 0; i < 8; i++) { + printf("%2.2x ", (unsigned int)p.data[i]); + } + } + Cr(); +} + + +void PicturePrinter::SetScale(float scale) { + Indent(); Print("SetScale", scale); Cr(); +} + + +void PicturePrinter::SetFontFamily(char *family) { + Indent(); Print("SetFontFamily"); Print(family); Cr(); +} + + +void PicturePrinter::SetFontStyle(char *style) { + Indent(); Print("SetFontStyle"); Print(style); Cr(); +} + + +void PicturePrinter::SetFontSpacing(int32 spacing) { + Indent(); Print("SetFontSpacing"); + switch(spacing) { + case B_CHAR_SPACING: Print("B_CHAR_SPACING"); break; + case B_STRING_SPACING: Print("B_STRING_SPACING"); break; + case B_BITMAP_SPACING: Print("B_BITMAP_SPACING"); break; + case B_FIXED_SPACING: Print("B_FIXED_SPACING"); break; + default: Print("Unknown: ", (float)spacing); + } + Cr(); +} + + +void PicturePrinter::SetFontSize(float size) { + Indent(); Print("SetFontSize", size); Cr(); +} + + +void PicturePrinter::SetFontRotate(float rotation) { + Indent(); Print("SetFontRotation", rotation); Cr(); +} + + +void PicturePrinter::SetFontEncoding(int32 encoding) { + Indent(); Print("SetFontEncoding"); + switch (encoding) { + case B_UNICODE_UTF8: Print("B_UNICODE_UTF8"); break; + case B_ISO_8859_1: Print("B_ISO_8859_1"); break; + case B_ISO_8859_2: Print("B_ISO_8859_2"); break; + case B_ISO_8859_3: Print("B_ISO_8859_3"); break; + case B_ISO_8859_4: Print("B_ISO_8859_4"); break; + case B_ISO_8859_5: Print("B_ISO_8859_5"); break; + case B_ISO_8859_6: Print("B_ISO_8859_6"); break; + case B_ISO_8859_7: Print("B_ISO_8859_7"); break; + case B_ISO_8859_8: Print("B_ISO_8859_8"); break; + case B_ISO_8859_9: Print("B_ISO_8859_9"); break; + case B_ISO_8859_10: Print("B_ISO_8859_10"); break; + case B_MACINTOSH_ROMAN: Print("B_MACINTOSH_ROMAN"); break; + default: Print("Unknown:", (float)encoding); + } + Cr(); +} + +#define PRINT_FLAG(flag) \ + if (flags & flag) { f |= flag; Print(##flag); } + +void PicturePrinter::SetFontFlags(int32 flags) { + Indent(); Print("SetFontFlags"); + int f = 0; + if (flags == 0) Print("none set"); + PRINT_FLAG(B_DISABLE_ANTIALIASING); + PRINT_FLAG(B_FORCE_ANTIALIASING); + if (flags != f) printf("Unknown Additional Flags %d", flags & ~f); + Cr(); +} + + +void PicturePrinter::SetFontShear(float shear) { + Indent(); Print("SetFontShear", shear); Cr(); +} + + +void PicturePrinter::SetFontFace(int32 flags) { + Indent(); Print("SetFontFace"); + int32 f = 0; + if (flags == 0) Print("none set"); + PRINT_FLAG(B_REGULAR_FACE); + PRINT_FLAG(B_BOLD_FACE); + PRINT_FLAG(B_ITALIC_FACE); + PRINT_FLAG(B_NEGATIVE_FACE); + PRINT_FLAG(B_OUTLINED_FACE); + PRINT_FLAG(B_UNDERSCORE_FACE); + PRINT_FLAG(B_STRIKEOUT_FACE); + if (flags != f) printf("Unknown Additional Flags %d", flags & ~f); + Cr(); +} + + +// Implementation of ShapePrinter +ShapePrinter::ShapePrinter(PicturePrinter* printer) + : fPrinter(printer) +{ + fPrinter->IncIndent(); +} + +ShapePrinter::~ShapePrinter() { + fPrinter->DecIndent(); +} + +status_t +ShapePrinter::IterateBezierTo(int32 bezierCount, BPoint *control) +{ + fPrinter->Indent(); fPrinter->Print("BezierTo"); fPrinter->Cr(); + for (int32 i = 0; i < bezierCount; i++, control += 3) { + fPrinter->Indent(1); + fPrinter->Print(i / 3.0); + fPrinter->Print(&control[0]); + fPrinter->Print(&control[1]); + fPrinter->Print(&control[2]); + fPrinter->Cr(); + } + return B_OK; +} + +status_t +ShapePrinter::IterateClose(void) +{ + fPrinter->Indent(); fPrinter->Print("Close"); fPrinter->Cr(); + return B_OK; +} + +status_t +ShapePrinter::IterateLineTo(int32 lineCount, BPoint *linePoints) +{ + fPrinter->Indent(); fPrinter->Print("LineTo"); fPrinter->Cr(); + BPoint *p = linePoints; + for (int32 i = 0; i < lineCount; i++) { + fPrinter->Indent(1); fPrinter->Print(p); fPrinter->Cr(); + p++; + } + return B_OK; +} + +status_t +ShapePrinter::IterateMoveTo(BPoint *point) +{ + fPrinter->Indent(); fPrinter->Print("MoveTo", point); fPrinter->Cr(); + return B_OK; +} + diff --git a/src/tests/kits/interface/picture/PicturePrinter.h b/src/tests/kits/interface/picture/PicturePrinter.h new file mode 100644 index 0000000000..b539f13275 --- /dev/null +++ b/src/tests/kits/interface/picture/PicturePrinter.h @@ -0,0 +1,124 @@ +/* + +PicturePrinter + +Copyright (c) 2001, 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. + +*/ + +#ifndef _PICTURE_PRINTER_H +#define _PICTURE_PRINTER_H + +#include "PictureIterator.h" + +#include + +class PicturePrinter : public PictureIterator +{ +public: + PicturePrinter(int indent = 0); + + // BPicture playback handlers + virtual void Op(int number); + virtual void MovePenBy(BPoint delta); + virtual void StrokeLine(BPoint start, BPoint end); + virtual void StrokeRect(BRect rect); + virtual void FillRect(BRect rect); + virtual void StrokeRoundRect(BRect rect, BPoint radii); + virtual void FillRoundRect(BRect rect, BPoint radii); + virtual void StrokeBezier(BPoint *control); + virtual void FillBezier(BPoint *control); + virtual void StrokeArc(BPoint center, BPoint radii, float startTheta, float arcTheta); + virtual void FillArc(BPoint center, BPoint radii, float startTheta, float arcTheta); + virtual void StrokeEllipse(BPoint center, BPoint radii); + virtual void FillEllipse(BPoint center, BPoint radii); + virtual void StrokePolygon(int32 numPoints, BPoint *points, bool isClosed); + virtual void FillPolygon(int32 numPoints, BPoint *points, bool isClosed); + virtual void StrokeShape(BShape *shape); + virtual void FillShape(BShape *shape); + virtual void DrawString(char *string, float escapement_nospace, float escapement_space); + virtual void DrawPixels(BRect src, BRect dest, int32 width, int32 height, int32 bytesPerRow, int32 pixelFormat, int32 flags, void *data); + virtual void SetClippingRects(BRect *rects, uint32 numRects); + virtual void ClipToPicture(BPicture *picture, BPoint point, bool clip_to_inverse_picture); + virtual void PushState(); + virtual void PopState(); + virtual void EnterStateChange(); + virtual void ExitStateChange(); + virtual void EnterFontState(); + virtual void ExitFontState(); + virtual void SetOrigin(BPoint pt); + virtual void SetPenLocation(BPoint pt); + virtual void SetDrawingMode(drawing_mode mode); + virtual void SetLineMode(cap_mode capMode, join_mode joinMode, float miterLimit); + virtual void SetPenSize(float size); + virtual void SetForeColor(rgb_color color); + virtual void SetBackColor(rgb_color color); + virtual void SetStipplePattern(pattern p); + virtual void SetScale(float scale); + virtual void SetFontFamily(char *family); + virtual void SetFontStyle(char *style); + virtual void SetFontSpacing(int32 spacing); + virtual void SetFontSize(float size); + virtual void SetFontRotate(float rotation); + virtual void SetFontEncoding(int32 encoding); + virtual void SetFontFlags(int32 flags); + virtual void SetFontShear(float shear); + virtual void SetFontFace(int32 flags); + +private: + int fIndent; + + void Print(const char* text); + void Print(BPoint* point); + void Print(BRect* rect); + void Print(int numPoints, BPoint* points); + void Print(int numRects, BRect* rects); + void Print(BShape* shape); + void Print(const char* label, float f); + void Print(const char* label, BPoint *point); + void Print(rgb_color color); + void Print(float f); + void Cr(); + void Indent(int inc = 0); + void IncIndent(); + void DecIndent(); + + friend class ShapePrinter; +}; + +class ShapePrinter : public BShapeIterator { +public: + ShapePrinter(PicturePrinter* printer); + ~ShapePrinter(); + + status_t IterateBezierTo(int32 bezierCount, BPoint *bezierPoints); + status_t IterateClose(void); + status_t IterateLineTo(int32 lineCount, BPoint *linePoints); + status_t IterateMoveTo(BPoint *point); + +private: + PicturePrinter* fPrinter; +}; + +#endif _PICTURE_PRINTER_H diff --git a/src/tests/kits/interface/picture/PictureTestApp.cpp b/src/tests/kits/interface/picture/PictureTestApp.cpp new file mode 100644 index 0000000000..cb97508f52 --- /dev/null +++ b/src/tests/kits/interface/picture/PictureTestApp.cpp @@ -0,0 +1,52 @@ +/* + +PictureTestApp + +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. + +*/ + +#include "PictureTestApp.hpp" +#include "PictureTestWindow.hpp" +#include "PictureTestView.hpp" + +int main() +{ + new PictureTestApp; + be_app->Run(); + delete be_app; + + return 0; +} + +PictureTestApp::PictureTestApp() + : Inherited(PRINTTEST_SIGNATURE) +{ +} + +void PictureTestApp::ReadyToRun() +{ + (new PictureTestWindow)->Show(); +} + diff --git a/src/tests/kits/interface/picture/PictureTestApp.hpp b/src/tests/kits/interface/picture/PictureTestApp.hpp new file mode 100644 index 0000000000..fe37bd9271 --- /dev/null +++ b/src/tests/kits/interface/picture/PictureTestApp.hpp @@ -0,0 +1,51 @@ +/* + +PictureTestApp + +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. + +*/ + +#ifndef PICTURETESTAPP_HPP +#define PICTURETESTAPP_HPP + +class PictureTestApp; + +#include +#include + +#define PRINTTEST_SIGNATURE "application/x-vnd.OpenBeOS-picturetest" + +class PictureTestApp : public BApplication +{ + typedef BApplication Inherited; +public: + PictureTestApp(); + + void ReadyToRun(); +private: + void DoPictureTest(); +}; + +#endif diff --git a/src/tests/kits/interface/picture/PictureTestView.cpp b/src/tests/kits/interface/picture/PictureTestView.cpp new file mode 100644 index 0000000000..8fe8e98a0e --- /dev/null +++ b/src/tests/kits/interface/picture/PictureTestView.cpp @@ -0,0 +1,47 @@ +/* + +PictureTestView + +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. + +*/ + +#include "PictureTestView.hpp" + +PictureTestView::PictureTestView(BRect frame) + : Inherited(frame, "", B_FOLLOW_ALL, B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE) +{ +} + +void PictureTestView::Draw(BRect updateRect) +{ + StrokeRoundRect(Bounds().InsetByCopy(20,20), 10, 10); + BFont font(be_bold_font); + font.SetSize(Bounds().Height()/10); + font.SetShear(Bounds().Height()/10); + font.SetRotation(Bounds().Width()/10); + SetFont(&font, B_FONT_ALL); + DrawString("OpenBeOS", 8, BPoint(Bounds().Width()/2,Bounds().Height()/2)); +} + diff --git a/src/tests/kits/interface/picture/PictureTestView.hpp b/src/tests/kits/interface/picture/PictureTestView.hpp new file mode 100644 index 0000000000..d962aa11f4 --- /dev/null +++ b/src/tests/kits/interface/picture/PictureTestView.hpp @@ -0,0 +1,47 @@ +/* + +PictureTestView + +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. + +*/ + +#ifndef PICTURETESTVIEW_HPP +#define PICTURETESTVIEW_HPP + +#include + +class PictureTestView; + +#include + +class PictureTestView : public BView +{ + typedef BView Inherited; +public: + PictureTestView(BRect frame); + void Draw(BRect updateRect); +}; + +#endif diff --git a/src/tests/kits/interface/picture/PictureTestWindow.cpp b/src/tests/kits/interface/picture/PictureTestWindow.cpp new file mode 100644 index 0000000000..6767b115b8 --- /dev/null +++ b/src/tests/kits/interface/picture/PictureTestWindow.cpp @@ -0,0 +1,137 @@ +/* + +PictureTestWindow + +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. + +*/ + +#include "PictureTestWindow.hpp" + +#include "PictureTestView.hpp" +#include "TestView.hpp" +#include "PicturePrinter.h" + +#include + +#include +#include +#include +#include + +PictureTestWindow::PictureTestWindow() + : Inherited(BRect(100,100,500,300), "OpenBeOS Picture Test App", B_DOCUMENT_WINDOW, 0) +{ + BuildGUI(); +} + +bool PictureTestWindow::QuitRequested() +{ + bool isOk = Inherited::QuitRequested(); + if (isOk) { + be_app->PostMessage(B_QUIT_REQUESTED); + } + + return isOk; +} + + +void PictureTestWindow::BuildGUI() +{ + BView* backdrop = new BView(Bounds(), "backdrop", B_FOLLOW_ALL, B_WILL_DRAW); + backdrop->SetViewColor(::ui_color(B_PANEL_BACKGROUND_COLOR)); + AddChild(backdrop); + + BMenuBar* mb = new BMenuBar(Bounds(), "menubar"); + BMenu* m = new BMenu("File"); + m->AddItem(new BMenuItem("Picture"B_UTF8_ELLIPSIS, new BMessage('Pict'), 'P')); + m->AddSeparatorItem(); + m->AddItem(new BMenuItem("Quit", new BMessage(B_QUIT_REQUESTED), 'Q')); + mb->AddItem(m); + + backdrop->AddChild(mb); + + BRect b = Bounds(); + b.top = mb->Bounds().bottom +1; + backdrop->AddChild(new PictureTestView(b)); +} + +void PictureTestWindow::MessageReceived(BMessage* msg) +{ + switch(msg->what) { + case 'Pict': + DoPictureTest(); + break; + } +} + +void PictureTestWindow::DoPictureTest() { + fView = new TestView(BRect(0, 0, 10000, 10000)); + AddChild(fView); + bool continue_test = true; + for (int i = 0; continue_test; i++) { + Begin(); + continue_test = fView->Test(i, fName); + End(continue_test); + } + RemoveChild(fView); + delete fView; +} + +void PictureTestWindow::Begin() { + fView->BeginPicture(new BPicture()); +} + +void PictureTestWindow::End(bool write) { + fView->Sync(); + if (!write) return; + BPicture* picture = fView->EndPicture(); + printf("\n%s\n", fName.String()); + if (picture) { + bool saved = false; + { + BFile file(fName.String(), B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE); + if (file.InitCheck() == B_OK) { + if (picture->Flatten(&file) != B_OK) + fprintf(stderr, "Error %s could not flatten BPicture\n", fName.String()); + else saved = true; + } else fprintf(stderr, "Error %s could not create file\n", fName.String()); + delete picture; + } + if (saved) { + BFile file(fName.String(), B_READ_ONLY); + if (file.InitCheck() == B_OK) { + BPicture p; + if (p.Unflatten(&file) == B_OK) { + PicturePrinter printer; + printer.Iterate(&p); + } else { + fprintf(stderr, "Error %s could not unflatten BPicture\n", fName.String()); + } + } else { + fprintf(stderr, "Error %s could not open file\n", fName.String()); + } + } + } +} diff --git a/src/tests/kits/interface/picture/PictureTestWindow.hpp b/src/tests/kits/interface/picture/PictureTestWindow.hpp new file mode 100644 index 0000000000..34840bc9f8 --- /dev/null +++ b/src/tests/kits/interface/picture/PictureTestWindow.hpp @@ -0,0 +1,58 @@ +/* + +PictureTestWindow + +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. + +*/ + +#ifndef PICTURETESTWINDOW_HPP +#define PICTURETESTWINDOW_HPP + +class TestView; + +#include +#include +#include +#include + +class PictureTestWindow : public BWindow +{ + typedef BWindow Inherited; +public: + void MessageReceived(BMessage* m); + PictureTestWindow(); + bool QuitRequested(); +private: + void BuildGUI(); + void DoPictureTest(); + void Begin(); + void End(bool write); + + TestView* fView; + BString fName; + BPicture fPicture; +}; + +#endif diff --git a/src/tests/kits/interface/picture/Preview.cpp b/src/tests/kits/interface/picture/Preview.cpp new file mode 100644 index 0000000000..bf240ec482 --- /dev/null +++ b/src/tests/kits/interface/picture/Preview.cpp @@ -0,0 +1,300 @@ +/* + +Preview + +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. + +*/ + +#include + +#include "Preview.h" + +// Implementation of PreviewPage +PreviewPage::PreviewPage(int32 page, PrintJobPage* pjp) + : fPage(page) + , fPictures(NULL) + , fPoints(NULL) + , fRects(NULL) +{ + fNumberOfPictures = pjp->NumberOfPictures(); + fPictures = new BPicture[fNumberOfPictures]; + fPoints = new BPoint[fNumberOfPictures]; + fRects = new BRect[fNumberOfPictures]; + status_t rc = B_ERROR; + for (int32 i = 0; i < fNumberOfPictures && + (rc = pjp->NextPicture(fPictures[i], fPoints[i], fRects[i])) == B_OK; i ++); + fStatus = rc; +} + +PreviewPage::~PreviewPage() { + delete []fPictures; + delete []fPoints; + delete []fRects; +} + +status_t PreviewPage::InitCheck() const { + return fStatus; +} + +void PreviewPage::Draw(BView* view) { + ASSERT(fStatus == B_OK); + for (int32 i = 0; i < fNumberOfPictures; i ++) { + view->DrawPicture(&fPictures[i], fPoints[i]); + view->SetHighColor(255, 0, 0); + view->StrokeRect(fRects[i]); + } +} + +// Implementation of PreviewView + +PreviewView::PreviewView(BFile* jobFile, BRect rect) + : BView(rect, "PreviewView", B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS) + , fPage(0) + , fZoom(0) + , fReader(jobFile) + , fCachedPage(NULL) +{ +} + +PreviewView::~PreviewView() { + delete fCachedPage; +} + +// returns 2 ^ fZoom +float PreviewView::ZoomFactor() const { + const int32 b = 4; + int32 zoom; + if (fZoom > 0) zoom = (1 << b) << fZoom; + else zoom = (1 << b) >> -fZoom; + return zoom / (float)(1 << b); +} + +BRect PreviewView::PageRect() const { + float f = ZoomFactor(); + BRect r = fReader.PaperRect(); + r.left *= f; r.right *= f; r.top *= f; r.bottom *= f; + return r; +} + +status_t PreviewView::InitCheck() const { + return fReader.InitCheck(); +} + +void PreviewView::Draw(BRect rect) { + if (fReader.InitCheck() == B_OK) { + // set zoom factor + SetScale(ZoomFactor()); + // render picture(s) of current page + if (fCachedPage == NULL || fCachedPage->Page() != fPage) { + delete fCachedPage; fCachedPage = NULL; + PrintJobPage page; + if (fReader.GetPage(fPage, page) == B_OK) + fCachedPage = new PreviewPage(fPage, &page); + } + if (fCachedPage && fCachedPage->InitCheck() == B_OK) + fCachedPage->Draw(this); + } +} + +void PreviewView::FrameResized(float width, float height) { + FixScrollbars(); +} + +bool PreviewView::ShowsFirstPage() const { + return fPage == 0; +} + +bool PreviewView::ShowsLastPage() const { + return fPage == NumberOfPages() - 1; +} + +int PreviewView::NumberOfPages() const { + return fReader.NumberOfPages(); +} + +void PreviewView::ShowNextPage() { + if (!ShowsLastPage()) { + fPage ++; Invalidate(); + } +} + +void PreviewView::ShowPrevPage() { + if (!ShowsFirstPage()) { + fPage --; Invalidate(); + } +} + +bool PreviewView::CanZoomIn() const { + return fZoom < 4; +} + +bool PreviewView::CanZoomOut() const { + return fZoom > -2; +} + +void PreviewView::ZoomIn() { + if (CanZoomIn()) { + fZoom ++; FixScrollbars(); Invalidate(); + } +} + +void PreviewView::ZoomOut() { + if (CanZoomOut()) { + fZoom --; FixScrollbars(); Invalidate(); + } +} + +void PreviewView::FixScrollbars() { + BRect frame = Bounds(); + BScrollBar * scroll; + float x, y; + float bigStep, smallStep; + float width = PageRect().Width(); + float height = PageRect().Height(); + x = width - frame.Width(); + if (x < 0.0) { + x = 0.0; + } + y = height - frame.Height(); + if (y < 0.0) { + y = 0.0; + } + + scroll = ScrollBar (B_HORIZONTAL); + scroll->SetRange (0.0, x); + scroll->SetProportion ((width - x) / width); + bigStep = frame.Width() - 2; + smallStep = bigStep / 10.; + scroll->SetSteps (smallStep, bigStep); + + scroll = ScrollBar (B_VERTICAL); + scroll->SetRange (0.0, y); + scroll->SetProportion ((height - y) / height); + bigStep = frame.Height() - 2; + smallStep = bigStep / 10.; + scroll->SetSteps (smallStep, bigStep); +} + +// Implementation of PreviewWindow + +PreviewWindow::PreviewWindow(BFile* jobFile) + : BWindow(BRect(20, 20, 400, 600), "Preview", B_DOCUMENT_WINDOW, 0) +{ + float top = 0; + float left = 10; + + BRect r = Frame(); + r.right = r.IntegerWidth() - B_V_SCROLL_BAR_WIDTH; r.left = 0; + r.bottom = r.IntegerHeight() - B_H_SCROLL_BAR_HEIGHT; r.top = 0; + + // add navigation and zoom buttons + fNext = new BButton(BRect(left, top, left+10, top+10), "Next", "Next Page", new BMessage(MSG_NEXT_PAGE)); + AddChild(fNext); + fNext->ResizeToPreferred(); + left = fNext->Frame().right + 10; + + fPrev = new BButton(BRect(left, top, left+10, top+10), "Prev", "Previous Page", new BMessage(MSG_PREV_PAGE)); + AddChild(fPrev); + fPrev->ResizeToPreferred(); + left = fPrev->Frame().right + 10; + + fZoomIn = new BButton(BRect(left, top, left+10, top+10), "ZoomIn", "Zoom In", new BMessage(MSG_ZOOM_IN)); + AddChild(fZoomIn); + fZoomIn->ResizeToPreferred(); + left = fZoomIn->Frame().right + 10; + + fZoomOut = new BButton(BRect(left, top, left+10, top+10), "ZoomOut", "Zoom Out", new BMessage(MSG_ZOOM_OUT)); + AddChild(fZoomOut); + fZoomOut->ResizeToPreferred(); + left = fZoomOut->Frame().right + 10; + + top = fZoomOut->Frame().bottom + 5; + + // add preview view + r.top = top; + fPreview = new PreviewView(jobFile, r); + fPreviewScroller = new BScrollView("PreviewScroller", fPreview, B_FOLLOW_ALL, 0, true, true, B_FANCY_BORDER); + fPreviewScroller->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + AddChild(fPreviewScroller); + + if (fPreview->InitCheck() == B_OK) { + fPreview->FixScrollbars(); + UpdateControls(); + Show(); + } else { + Quit(); + } +} + +void PreviewWindow::UpdateControls() { + fPrev->SetEnabled(!fPreview->ShowsFirstPage()); + fNext->SetEnabled(!fPreview->ShowsLastPage()); + fZoomIn->SetEnabled(fPreview->CanZoomIn()); + fZoomOut->SetEnabled(fPreview->CanZoomOut()); +} + +void PreviewWindow::MessageReceived(BMessage* m) { + switch (m->what) { + case MSG_NEXT_PAGE: fPreview->ShowNextPage(); + break; + case MSG_PREV_PAGE: fPreview->ShowPrevPage(); + break; + case MSG_ZOOM_IN: fPreview->ZoomIn(); + break; + case MSG_ZOOM_OUT: fPreview->ZoomOut(); + break; + default: + inherited::MessageReceived(m); return; + } + UpdateControls(); +} + +#if 1 + +// Standalone test preview application +// Note to quit application press Command+Q + +#include + +class PreviewApp : public BApplication { +public: + PreviewApp(const char* sig) : BApplication(sig) { } + void ArgvReceived(int32 argc, char* argv[]); +}; + +void PreviewApp::ArgvReceived(int32 argc, char* argv[]) { + for (int32 i = 1; i < argc; i ++) { + BFile jobFile(argv[i], B_READ_WRITE); + if (jobFile.InitCheck() == B_OK) { + new PreviewWindow(&jobFile); + } + } +} + +int main(int argc, char* argv[]) { + PreviewApp app("application/x-vnd.obos.preview"); + app.Run(); +} +#endif diff --git a/src/tests/kits/interface/picture/Preview.h b/src/tests/kits/interface/picture/Preview.h new file mode 100644 index 0000000000..bb88e45cda --- /dev/null +++ b/src/tests/kits/interface/picture/Preview.h @@ -0,0 +1,101 @@ +/* + +Preview + +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. + +*/ + +#include +#include "PrintJobReader.h" + +class PreviewPage { + int32 fPage; + int32 fNumberOfPictures; + BPicture* fPictures; + BPoint* fPoints; + BRect* fRects; + status_t fStatus; + +public: + PreviewPage(int32 page, PrintJobPage* pjp); + ~PreviewPage(); + status_t InitCheck() const; + + int32 Page() const { return fPage; } + void Draw(BView* view); +}; + +class PreviewView : public BView { + int32 fPage; + int32 fZoom; + PrintJobReader fReader; + PreviewPage* fCachedPage; + + float ZoomFactor() const; + BRect PageRect() const; + +public: + PreviewView(BFile* jobFile, BRect rect); + ~PreviewView(); + status_t InitCheck() const; + + void Draw(BRect r); + void FrameResized(float width, float height); + + void FixScrollbars(); + + bool ShowsFirstPage() const; + bool ShowsLastPage() const; + int NumberOfPages() const; + void ShowNextPage(); + void ShowPrevPage(); + + bool CanZoomIn() const; + bool CanZoomOut() const; + void ZoomIn(); + void ZoomOut(); +}; + +class PreviewWindow : public BWindow { + BButton *fNext, *fPrev, *fZoomIn, *fZoomOut; + PreviewView* fPreview; + BScrollView* fPreviewScroller; + + enum { + MSG_NEXT_PAGE = 'pwnp', + MSG_PREV_PAGE = 'pwpp', + MSG_ZOOM_IN = 'pwzi', + MSG_ZOOM_OUT = 'pwzo' + }; + + void UpdateControls(); + + typedef BWindow inherited; + +public: + PreviewWindow(BFile* jobFile); + ~PreviewWindow() {}; + void MessageReceived(BMessage* m); +}; diff --git a/src/tests/kits/interface/picture/PrintJobReader.cpp b/src/tests/kits/interface/picture/PrintJobReader.cpp new file mode 100644 index 0000000000..9a37d4d53f --- /dev/null +++ b/src/tests/kits/interface/picture/PrintJobReader.cpp @@ -0,0 +1,169 @@ +/* + +PrintJobReader + +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. + +*/ + +#include +#include +#include "PrintJobReader.h" + +// Implementation of PrintJobPage + +PrintJobPage::PrintJobPage() + : fNextPicture(-1) + , fNumberOfPictures(0) + , fPicture(0) + , fStatus(B_ERROR) +{ +} + +PrintJobPage::PrintJobPage(const PrintJobPage& copy) + : fJobFile(copy.fJobFile) + , fNextPicture(copy.fNextPicture) + , fNumberOfPictures(copy.fNumberOfPictures) + , fPicture(copy.fPicture) + , fStatus(copy.fStatus) +{ +} + +PrintJobPage& PrintJobPage::operator=(const PrintJobPage& copy) { + if (this != ©) { + fJobFile = copy.fJobFile; + fNextPicture = copy.fNextPicture; + fNumberOfPictures = copy.fNumberOfPictures; + fPicture = copy.fPicture; + fStatus = copy.fStatus; + } +} + +PrintJobPage::PrintJobPage(BFile* jobFile, off_t start) + : fJobFile(*jobFile) + , fPicture(0) + , fStatus(B_ERROR) +{ + off_t size; + if (fJobFile.GetSize(&size) != B_OK || start > size) return; + if (fJobFile.Seek(start, SEEK_SET) != start) return; + if (fJobFile.Read(&fNumberOfPictures, sizeof(fNumberOfPictures)) == sizeof(fNumberOfPictures)) { + fJobFile.Seek(40 + sizeof(off_t), SEEK_CUR); + fNextPicture = fJobFile.Position(); + fStatus = B_OK; + } +} + +status_t PrintJobPage::InitCheck() const { + return fStatus; +} + +status_t PrintJobPage::NextPicture(BPicture& picture, BPoint& point, BRect& rect) { + if (fPicture >= fNumberOfPictures) return B_ERROR; + fPicture ++; + + fJobFile.Seek(fNextPicture, SEEK_SET); + fJobFile.Read(&point, sizeof(point)); + fJobFile.Read(&rect, sizeof(rect)); + status_t rc = picture.Unflatten(&fJobFile); + fNextPicture = fJobFile.Position(); + if (rc != B_OK) { + fPicture = fNumberOfPictures; + } + return rc; +} + + +// Implementation of PrintJobReader + +PrintJobReader::PrintJobReader(BFile* jobFile) + : fJobFile(*jobFile) + , fNumberOfPages(-1) + , fPageIndex(NULL) +{ + print_file_header header; + fJobFile.Seek(0, SEEK_SET); + if (fJobFile.Read(&header, sizeof(header)) == sizeof(header) && + fJobSettings.Unflatten(&fJobFile) == B_OK) { + fNumberOfPages = header.page_count; + fFirstPage = header.first_page; + BuildPageIndex(); + } +} + +PrintJobReader::~PrintJobReader() { + delete[] fPageIndex; +} + +status_t PrintJobReader::InitCheck() const { + return fNumberOfPages > 0 ? B_OK : B_ERROR; +} + +void PrintJobReader::BuildPageIndex() { + fPageIndex = new off_t[fNumberOfPages]; + + for (int page = 0; page < fNumberOfPages; page ++) { + int32 pictures; + off_t next_page; + // add position to page index + fPageIndex[page] = fJobFile.Position(); + + // determine start position of next page + if (fJobFile.Read(&pictures, sizeof(pictures)) == sizeof(pictures) && + fJobFile.Read(&next_page, sizeof(next_page)) == sizeof(next_page) && + fPageIndex[page] < next_page) { + fJobFile.Seek(next_page, SEEK_SET); + } else { + fNumberOfPages = 0; delete fPageIndex; fPageIndex = NULL; + } + } +} + +status_t PrintJobReader::GetPage(int page, PrintJobPage& pjp) { + if (0 <= page && page < fNumberOfPages) { + PrintJobPage p(&fJobFile, fPageIndex[page]); + if (p.InitCheck() == B_OK) { + pjp = p; return B_OK; + } + } + return B_ERROR; +} + +BRect PrintJobReader::PaperRect() const { + BRect r; + fJobSettings.FindRect("paper_rect", &r); + return r; +} + +BRect PrintJobReader::PrintableRect() const { + BRect r; + fJobSettings.FindRect("printable_rect", &r); + return r; +} + +void PrintJobReader::GetResolution(int32 *xdpi, int32 *ydpi) const { + fJobSettings.FindInt32("xres", xdpi); + fJobSettings.FindInt32("yres", ydpi); +} + diff --git a/src/tests/kits/interface/picture/PrintJobReader.h b/src/tests/kits/interface/picture/PrintJobReader.h new file mode 100644 index 0000000000..d656805078 --- /dev/null +++ b/src/tests/kits/interface/picture/PrintJobReader.h @@ -0,0 +1,81 @@ +/* + +PrintJobReader + +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. + +*/ + +#include +#include + +class PrintJobPage { + BFile fJobFile; // the job file + off_t fNextPicture; // offset to first picture + int32 fNumberOfPictures; // of this page + int32 fPicture; // the picture returned by NextPicture() + status_t fStatus; + +public: + PrintJobPage(); + PrintJobPage(const PrintJobPage& copy); + PrintJobPage(BFile* jobFile, off_t start); + status_t InitCheck() const; + + int32 NumberOfPictures() const { return fNumberOfPictures; } + + status_t NextPicture(BPicture& picture, BPoint& p, BRect& r); + + PrintJobPage& operator=(const PrintJobPage& copy); +}; + +class PrintJobReader { + BFile fJobFile; // the job file + int32 fNumberOfPages; // the number of pages in the job file + int32 fFirstPage; // the page number of the first page + BMessage fJobSettings; // the settings extracted from the job file + off_t* fPageIndex; // start positions of pages in the job file + + void BuildPageIndex(); + +public: + PrintJobReader(BFile* jobFile); + virtual ~PrintJobReader(); + + // test after construction if this is a valid job file + status_t InitCheck() const; + + // accessors to informations from job file + int32 NumberOfPages() const { return fNumberOfPages; } + int32 FirstPage() const { return fFirstPage; } + int32 LastPage() const { return fFirstPage + fNumberOfPages - 1; } + const BMessage* JobSettings() const { return &fJobSettings; } + BRect PaperRect() const; + BRect PrintableRect() const; + void GetResolution(int32 *xdpi, int32 *ydpi) const; + + // retrieve page + status_t GetPage(int no, PrintJobPage& pjp); +}; + diff --git a/src/tests/kits/interface/picture/Template.cpp b/src/tests/kits/interface/picture/Template.cpp new file mode 100644 index 0000000000..74c328f9d0 --- /dev/null +++ b/src/tests/kits/interface/picture/Template.cpp @@ -0,0 +1,212 @@ +/* + +Template + +Copyright (c) 2002 OpenBeOS. + +Author: + + +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 "Template.h" + +virtual void Template::Op(int number) { +} + + +virtual void Template::MovePenBy(BPoint delta) { +} + + +virtual void Template::StrokeLine(BPoint start, BPoint end) { +} + + +virtual void Template::StrokeRect(BRect rect) { +} + + +virtual void Template::FillRect(BRect rect) { +} + + +virtual void Template::StrokeRoundRect(BRect rect, BPoint radii) { +} + + +virtual void Template::FillRoundRect(BRect rect, BPoint radii) { +} + + +virtual void Template::StrokeBezier(BPoint *control) { +} + + +virtual void Template::FillBezier(BPoint *control) { +} + + +virtual void Template::StrokeArc(BPoint center, BPoint radii, float startTheta, float arcTheta) { +} + + +virtual void Template::FillArc(BPoint center, BPoint radii, float startTheta, float arcTheta) { +} + + +virtual void Template::StrokeEllipse(BPoint center, BPoint radii) { +} + + +virtual void Template::FillEllipse(BPoint center, BPoint radii) { +} + + +virtual void Template::StrokePolygon(int32 numPoints, BPoint *points, bool isClosed) { +} + + +virtual void Template::FillPolygon(int32 numPoints, BPoint *points, bool isClosed) { +} + + +virtual void Template::StrokeShape(BShape *shape) { +} + + +virtual void Template::FillShape(BShape *shape) { +} + + +virtual void Template::DrawString(char *string, float escapement_nospace, float escapement_space) { +} + + +virtual void Template::DrawPixels(BRect src, BRect dest, int32 width, int32 height, int32 bytesPerRow, int32 pixelFormat, int32 flags, void *data) { +} + + +virtual void Template::SetClippingRects(BRect *rects, uint32 numRects) { +} + + +virtual void Template::ClipToPicture(BPicture *picture, BPoint point, bool clip_to_inverse_picture) { +} + + +virtual void Template::PushState() { +} + + +virtual void Template::PopState() { +} + + +virtual void Template::EnterStateChange() { +} + + +virtual void Template::ExitStateChange() { +} + + +virtual void Template::EnterFontState() { +} + + +virtual void Template::ExitFontState() { +} + + +virtual void Template::SetOrigin(BPoint pt) { +} + + +virtual void Template::SetPenLocation(BPoint pt) { +} + + +virtual void Template::SetDrawingMode(drawing_mode mode) { +} + + +virtual void Template::SetLineMode(cap_mode capMode, join_mode joinMode, float miterLimit) { +} + + +virtual void Template::SetPenSize(float size) { +} + + +virtual void Template::SetForeColor(rgb_color color) { +} + + +virtual void Template::SetBackColor(rgb_color color) { +} + + +virtual void Template::SetStipplePattern(pattern p) { +} + + +virtual void Template::SetScale(float scale) { +} + + +virtual void Template::SetFontFamily(char *family) { +} + + +virtual void Template::SetFontStyle(char *style) { +} + + +virtual void Template::SetFontSpacing(int32 spacing) { +} + + +virtual void Template::SetFontSize(float size) { +} + + +virtual void Template::SetFontRotate(float rotation) { +} + + +virtual void Template::SetFontEncoding(int32 encoding) { +} + + +virtual void Template::SetFontFlags(int32 flags) { +} + + +virtual void Template::SetFontShear(float shear) { +} + + +virtual void Template::SetFontFace(int32 flags) { +} + + + diff --git a/src/tests/kits/interface/picture/Template.h b/src/tests/kits/interface/picture/Template.h new file mode 100644 index 0000000000..d135d1e782 --- /dev/null +++ b/src/tests/kits/interface/picture/Template.h @@ -0,0 +1,85 @@ +/* + +Copyright (c) 2001, 2002 OpenBeOS. + +Author: + + +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. + +*/ + +#ifndef _TEMPLATE_H +#define _TEMPLATE_H + +#include "PictureIterator.h" + +class Template : public PictureIterator +{ +public: + + // BPicture playback handlers + virtual void Op(int number); + virtual void MovePenBy(BPoint delta); + virtual void StrokeLine(BPoint start, BPoint end); + virtual void StrokeRect(BRect rect); + virtual void FillRect(BRect rect); + virtual void StrokeRoundRect(BRect rect, BPoint radii); + virtual void FillRoundRect(BRect rect, BPoint radii); + virtual void StrokeBezier(BPoint *control); + virtual void FillBezier(BPoint *control); + virtual void StrokeArc(BPoint center, BPoint radii, float startTheta, float arcTheta); + virtual void FillArc(BPoint center, BPoint radii, float startTheta, float arcTheta); + virtual void StrokeEllipse(BPoint center, BPoint radii); + virtual void FillEllipse(BPoint center, BPoint radii); + virtual void StrokePolygon(int32 numPoints, BPoint *points, bool isClosed); + virtual void FillPolygon(int32 numPoints, BPoint *points, bool isClosed); + virtual void StrokeShape(BShape *shape); + virtual void FillShape(BShape *shape); + virtual void DrawString(char *string, float escapement_nospace, float escapement_space); + virtual void DrawPixels(BRect src, BRect dest, int32 width, int32 height, int32 bytesPerRow, int32 pixelFormat, int32 flags, void *data); + virtual void SetClippingRects(BRect *rects, uint32 numRects); + virtual void ClipToPicture(BPicture *picture, BPoint point, bool clip_to_inverse_picture); + virtual void PushState(); + virtual void PopState(); + virtual void EnterStateChange(); + virtual void ExitStateChange(); + virtual void EnterFontState(); + virtual void ExitFontState(); + virtual void SetOrigin(BPoint pt); + virtual void SetPenLocation(BPoint pt); + virtual void SetDrawingMode(drawing_mode mode); + virtual void SetLineMode(cap_mode capMode, join_mode joinMode, float miterLimit); + virtual void SetPenSize(float size); + virtual void SetForeColor(rgb_color color); + virtual void SetBackColor(rgb_color color); + virtual void SetStipplePattern(pattern p); + virtual void SetScale(float scale); + virtual void SetFontFamily(char *family); + virtual void SetFontStyle(char *style); + virtual void SetFontSpacing(int32 spacing); + virtual void SetFontSize(float size); + virtual void SetFontRotate(float rotation); + virtual void SetFontEncoding(int32 encoding); + virtual void SetFontFlags(int32 flags); + virtual void SetFontShear(float shear); + virtual void SetFontFace(int32 flags); +}; + +#endif _TEMPLATE_H diff --git a/src/tests/kits/interface/picture/TestView.cpp b/src/tests/kits/interface/picture/TestView.cpp new file mode 100644 index 0000000000..73b045a956 --- /dev/null +++ b/src/tests/kits/interface/picture/TestView.cpp @@ -0,0 +1,76 @@ +/* + +TestView + +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. + +*/ + +#include "TestView.hpp" + +static BPoint NextPoint() { + return BPoint(NextNum(), NextNum()); +} + +static BRect NextRect() { + return BRect(NextNum(), NextNum(), NextNum(), NextNum()); +} + +bool TestView::Test(int no, BString& name) { + switch (no) { + case 0: name = "MoveTo"; MoveTo(NextPoint()); break; + case 1: name = "StrokeLine"; StrokeLine(NextPoint(), NextPoint()); break; + case 2: name = "StrokeRect"; StrokeRect(NextRect()); break; + case 3: name = "FillRect"; FillRect(NextRect()); break; + case 4: name = "DrawChar"; MoveTo(NextPoint()); DrawChar('O'); DrawChar('B'); DrawChar('O'); DrawChar('S'); break; + case 5: name = "DrawString"; DrawString("OpenBeOS", NextPoint()); break; + case 6: name = "BlendingMode"; + SetBlendingMode(B_CONSTANT_ALPHA, B_ALPHA_OVERLAY); + StrokeRect(NextRect()); + break; +// case 7: name = ""; break; +/* + case 6: name = "StrokeEllipse"; break; + case 7: name = "FillEllipse"; break; + case 8: name = "StrokeBezier"; break; + case 9: name = "FillBezier"; break; + case 10: name = "StrokePolygone"; break; + case 11: name = "FillPolygone"; break; + case 12: name = "FillRegion"; break; + case 13: name = "StrokeTriangle"; break; + case 14: name = "FillTriangle"; break; + case 15: name = ""; break; + case 16: name = ""; break; + case 17: name = ""; break; + case 18: name = ""; break; + case 19: name = ""; break; + case 20: name = ""; break; + case 21: name = ""; break; + case 22: name = ""; break; +*/ + default: return false; + } + return true; +} + diff --git a/src/tests/kits/interface/picture/TestView.hpp b/src/tests/kits/interface/picture/TestView.hpp new file mode 100644 index 0000000000..7365acb59f --- /dev/null +++ b/src/tests/kits/interface/picture/TestView.hpp @@ -0,0 +1,52 @@ +/* + +TestView + +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. + +*/ + + +#ifndef TESTVIEW_HPP +#define TESTVIEW_HPP + +#include + +#include + +class TestView : public BView +{ + typedef BView Inherited; +public: + TestView(BRect frame) : BView(frame, "", B_FOLLOW_NONE, 0) { } + void Draw(BRect updateRect) { }; + bool Test(int no, BString& name); +}; + +static int NextNum() { + static int n = 0; + return n ++; +} + +#endif