diff --git a/src/add-ons/print/Jamfile b/src/add-ons/print/Jamfile index f1c6dc1fd1..29d64f9de8 100644 --- a/src/add-ons/print/Jamfile +++ b/src/add-ons/print/Jamfile @@ -1,4 +1,5 @@ SubDir OBOS_TOP src add-ons print ; +SubInclude OBOS_TOP src add-ons print shared ; SubInclude OBOS_TOP src add-ons print drivers ; SubInclude OBOS_TOP src add-ons print transports ; diff --git a/src/add-ons/print/shared/Jamfile b/src/add-ons/print/shared/Jamfile new file mode 100644 index 0000000000..e4a7a1fd48 --- /dev/null +++ b/src/add-ons/print/shared/Jamfile @@ -0,0 +1,12 @@ +SubDir OBOS_TOP src add-ons print shared ; + +UsePrivateHeaders interface print ; + +StaticLibrary + print + : + PicturePrinter.cpp + PrintJobReader.cpp + PictureIterator.cpp + ; + diff --git a/src/add-ons/print/shared/PictureIterator.cpp b/src/add-ons/print/shared/PictureIterator.cpp new file mode 100644 index 0000000000..b89825c46a --- /dev/null +++ b/src/add-ons/print/shared/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/add-ons/print/shared/PicturePrinter.cpp b/src/add-ons/print/shared/PicturePrinter.cpp new file mode 100644 index 0000000000..30d47dbd2d --- /dev/null +++ b/src/add-ons/print/shared/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/add-ons/print/shared/PrintJobReader.cpp b/src/add-ons/print/shared/PrintJobReader.cpp new file mode 100644 index 0000000000..9a37d4d53f --- /dev/null +++ b/src/add-ons/print/shared/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/add-ons/print/shared/Template.cpp b/src/add-ons/print/shared/Template.cpp new file mode 100644 index 0000000000..74c328f9d0 --- /dev/null +++ b/src/add-ons/print/shared/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) { +} + + +