5 Copyright (c) 2002 OpenBeOS.
10 Permission is hereby granted, free of charge, to any person obtaining a copy of
11 this software and associated documentation files (the "Software"), to deal in
12 the Software without restriction, including without limitation the rights to
13 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
14 of the Software, and to permit persons to whom the Software is furnished to do
15 so, subject to the following conditions:
17 The above copyright notice and this permission notice shall be included in all
18 copies or substantial portions of the Software.
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
32 #include "PicturePrinter.h"
34 PicturePrinter::PicturePrinter(int indent
)
39 void PicturePrinter::Print(const char* text
) {
43 void PicturePrinter::Print(BPoint
* p
) {
44 printf("point (%f, %f) ", p
->x
, p
->y
);
47 void PicturePrinter::Print(BRect
* r
) {
48 printf("rect [l: %f, t: %f, r: %f, b: %f] ", r
->left
, r
->top
, r
->right
, r
->bottom
);
51 void PicturePrinter::Print(int numPoints
, BPoint
* points
) {
52 for (int i
= 0; i
< numPoints
; i
++) {
53 Indent(1); printf("%d ", i
); Print(&points
[i
]); Cr();
57 void PicturePrinter::Print(int numRects
, BRect
* rects
) {
58 for (int i
= 0; i
< numRects
; i
++) {
59 Indent(1); printf("%d ", i
); Print(&rects
[i
]); Cr();
63 void PicturePrinter::Print(BShape
* shape
) {
64 printf("Shape %p\n", shape
);
65 ShapePrinter
printer(this);
66 printer
.Iterate(shape
);
69 void PicturePrinter::Print(const char* text
, float f
) {
70 printf("%s %f ", text
, f
);
73 void PicturePrinter::Print(const char* text
, BPoint
* point
) {
74 Print(text
); Print(point
);
77 void PicturePrinter::Print(rgb_color color
) {
78 printf("color r: %d g: %d b: %d", color
.red
, color
.green
, color
.blue
);
81 void PicturePrinter::Print(float f
) {
85 void PicturePrinter::Cr() {
89 void PicturePrinter::Indent(int inc
) {
90 for (int i
= fIndent
+ inc
; i
> 0; i
--) printf(" ");
93 void PicturePrinter::IncIndent() {
97 void PicturePrinter::DecIndent() {
101 void PicturePrinter::Op(int number
) {
102 Indent(); printf("Unknown operator %d\n", number
); Cr();
106 void PicturePrinter::MovePenBy(BPoint delta
) {
107 Indent(); Print("MovePenBy"); Print(&delta
); Cr();
111 void PicturePrinter::StrokeLine(BPoint start
, BPoint end
) {
112 Indent(); Print("StrokeLine"); Print(&start
); Print(&end
); Cr();
116 void PicturePrinter::StrokeRect(BRect rect
) {
117 Indent(); Print("StrokeRect"); Print(&rect
); Cr();
121 void PicturePrinter::FillRect(BRect rect
) {
122 Indent(); Print("FillRect"); Print(&rect
); Cr();
126 void PicturePrinter::StrokeRoundRect(BRect rect
, BPoint radii
) {
127 Indent(); Print("StrokeRoundRect"); Print(&rect
); Print("radii", &radii
); Cr();
131 void PicturePrinter::FillRoundRect(BRect rect
, BPoint radii
) {
132 Indent(); Print("FillRoundRect"); Print(&rect
); Print("radii", &radii
); Cr();
136 void PicturePrinter::StrokeBezier(BPoint
*control
) {
137 Indent(); Print("StrokeBezier"); Print(4, control
); Cr();
141 void PicturePrinter::FillBezier(BPoint
*control
) {
142 Indent(); Print("FillBezier"); Print(4, control
); Cr();
146 void PicturePrinter::StrokeArc(BPoint center
, BPoint radii
, float startTheta
, float arcTheta
) {
147 Indent(); Print("StrokeArc center="); Print(¢er
); Print("radii="); Print(&radii
); Print("arcTheta=", arcTheta
); Cr();
151 void PicturePrinter::FillArc(BPoint center
, BPoint radii
, float startTheta
, float arcTheta
) {
152 Indent(); Print("FillArc center="); Print(¢er
); Print("radii="); Print(&radii
); Print("arcTheta=", arcTheta
); Cr();
156 void PicturePrinter::StrokeEllipse(BPoint center
, BPoint radii
) {
157 Indent(); Print("StrokeEllipse center="); Print(¢er
); Print("radii="); Print(&radii
); Cr();
161 void PicturePrinter::FillEllipse(BPoint center
, BPoint radii
) {
162 Indent(); Print("FillEllipse center="); Print(¢er
); Print("radii="); Print(&radii
); Cr();
166 void PicturePrinter::StrokePolygon(int32 numPoints
, BPoint
*points
, bool isClosed
) {
167 Indent(); Print("StrokePolygon");
168 printf("%s ", isClosed
? "closed" : "open"); Cr();
169 Print(numPoints
, points
);
173 void PicturePrinter::FillPolygon(int32 numPoints
, BPoint
*points
, bool isClosed
) {
174 Indent(); Print("FillPolygon");
175 printf("%s ", isClosed
? "closed" : "open"); Cr();
176 Print(numPoints
, points
);
180 void PicturePrinter::StrokeShape(BShape
*shape
) {
181 Indent(); Print("StrokeShape"); Print(shape
); Cr();
185 void PicturePrinter::FillShape(BShape
*shape
) {
186 Indent(); Print("FillShape"); Print(shape
); Cr();
190 void PicturePrinter::DrawString(char *string
, float escapement_nospace
, float escapement_space
) {
191 Indent(); Print("DrawString");
192 Print("escapement_nospace", escapement_nospace
);
193 Print("escapement_space", escapement_space
);
194 Print("text:"); Print(string
); Cr();
198 void PicturePrinter::DrawPixels(BRect src
, BRect dest
, int32 width
, int32 height
, int32 bytesPerRow
, int32 pixelFormat
, int32 flags
, void *data
) {
199 Indent(); Print("DrawPixels"); Cr();
203 void PicturePrinter::SetClippingRects(BRect
*rects
, uint32 numRects
) {
204 Indent(); Print("SetClippingRects");
205 if (numRects
== 0) Print("none");
207 Print(numRects
, rects
);
211 void PicturePrinter::ClipToPicture(BPicture
*picture
, BPoint point
, bool clip_to_inverse_picture
) {
213 Print(clip_to_inverse_picture
? "ClipToInversePicture" : "ClipToPicture");
214 Print("point=", &point
); Cr();
215 PicturePrinter
printer(fIndent
+1);
216 printer
.Iterate(picture
);
220 void PicturePrinter::PushState() {
221 Indent(); Print("PushState"); Cr();
226 void PicturePrinter::PopState() {
228 Indent(); Print("PopState"); Cr();
232 void PicturePrinter::EnterStateChange() {
233 Indent(); Print("EnterStateChange"); Cr();
237 void PicturePrinter::ExitStateChange() {
238 Indent(); Print("ExitStateChange"); Cr();
242 void PicturePrinter::EnterFontState() {
243 Indent(); Print("EnterFontState"); Cr();
247 void PicturePrinter::ExitFontState() {
248 Indent(); Print("ExitFontState"); Cr();
252 void PicturePrinter::SetOrigin(BPoint pt
) {
253 Indent(); Print("SetOrigin"); Print(&pt
); Cr();
257 void PicturePrinter::SetPenLocation(BPoint pt
) {
258 Indent(); Print("SetPenLocation"); Print(&pt
); Cr();
262 void PicturePrinter::SetDrawingMode(drawing_mode mode
) {
263 Indent(); Print("SetDrawingMode");
265 case B_OP_COPY
: Print("B_OP_COPY"); break;
266 case B_OP_OVER
: Print("B_OP_OVER"); break;
267 case B_OP_ERASE
: Print("B_OP_ERASE"); break;
268 case B_OP_INVERT
: Print("B_OP_INVERT"); break;
269 case B_OP_SELECT
: Print("B_OP_SELECT"); break;
270 case B_OP_ALPHA
: Print("B_OP_ALPHA"); break;
271 case B_OP_MIN
: Print("B_OP_MIN"); break;
272 case B_OP_MAX
: Print("B_OP_MAX"); break;
273 case B_OP_ADD
: Print("B_OP_ADD"); break;
274 case B_OP_SUBTRACT
: Print("B_OP_SUBTRACT"); break;
275 case B_OP_BLEND
: Print("B_OP_BLEND"); break;
276 default: Print("Unknown mode: ", (float)mode
);
282 void PicturePrinter::SetLineMode(cap_mode capMode
, join_mode joinMode
, float miterLimit
) {
283 Indent(); Print("SetLineMode");
285 case B_BUTT_CAP
: Print("B_BUTT_CAP"); break;
286 case B_ROUND_CAP
: Print("B_ROUND_CAP"); break;
287 case B_SQUARE_CAP
: Print("B_SQUARE_CAP"); break;
290 case B_MITER_JOIN
: Print("B_MITER_JOIN"); break;
291 case B_ROUND_JOIN
: Print("B_ROUND_JOIN"); break;
292 case B_BUTT_JOIN
: Print("B_BUTT_JOIN"); break;
293 case B_SQUARE_JOIN
: Print("B_SQUARE_JOIN"); break;
294 case B_BEVEL_JOIN
: Print("B_BEVEL_JOIN"); break;
296 Print("miterLimit", miterLimit
);
301 void PicturePrinter::SetPenSize(float size
) {
302 Indent(); Print("SetPenSize", size
); Cr();
306 void PicturePrinter::SetForeColor(rgb_color color
) {
307 Indent(); Print("SetForeColor"); Print(color
); Cr();
311 void PicturePrinter::SetBackColor(rgb_color color
) {
312 Indent(); Print("SetBackColor"); Print(color
); Cr();
315 static bool compare(pattern a
, pattern b
) {
316 for (int i
= 0; i
< 8; i
++) {
317 if (a
.data
[i
] != b
.data
[i
]) return false;
322 void PicturePrinter::SetStipplePattern(pattern p
) {
323 Indent(); Print("SetStipplePattern");
324 if (compare(p
, B_SOLID_HIGH
)) Print("B_SOLID_HIGH");
325 else if (compare(p
, B_SOLID_LOW
)) Print("B_SOLID_LOW");
326 else if (compare(p
, B_MIXED_COLORS
)) Print("B_MIXED_COLORS");
328 for (int i
= 0; i
< 8; i
++) {
329 printf("%2.2x ", (unsigned int)p
.data
[i
]);
336 void PicturePrinter::SetScale(float scale
) {
337 Indent(); Print("SetScale", scale
); Cr();
341 void PicturePrinter::SetFontFamily(char *family
) {
342 Indent(); Print("SetFontFamily"); Print(family
); Cr();
346 void PicturePrinter::SetFontStyle(char *style
) {
347 Indent(); Print("SetFontStyle"); Print(style
); Cr();
351 void PicturePrinter::SetFontSpacing(int32 spacing
) {
352 Indent(); Print("SetFontSpacing");
354 case B_CHAR_SPACING
: Print("B_CHAR_SPACING"); break;
355 case B_STRING_SPACING
: Print("B_STRING_SPACING"); break;
356 case B_BITMAP_SPACING
: Print("B_BITMAP_SPACING"); break;
357 case B_FIXED_SPACING
: Print("B_FIXED_SPACING"); break;
358 default: Print("Unknown: ", (float)spacing
);
364 void PicturePrinter::SetFontSize(float size
) {
365 Indent(); Print("SetFontSize", size
); Cr();
369 void PicturePrinter::SetFontRotate(float rotation
) {
370 Indent(); Print("SetFontRotation", rotation
); Cr();
374 void PicturePrinter::SetFontEncoding(int32 encoding
) {
375 Indent(); Print("SetFontEncoding");
377 case B_UNICODE_UTF8
: Print("B_UNICODE_UTF8"); break;
378 case B_ISO_8859_1
: Print("B_ISO_8859_1"); break;
379 case B_ISO_8859_2
: Print("B_ISO_8859_2"); break;
380 case B_ISO_8859_3
: Print("B_ISO_8859_3"); break;
381 case B_ISO_8859_4
: Print("B_ISO_8859_4"); break;
382 case B_ISO_8859_5
: Print("B_ISO_8859_5"); break;
383 case B_ISO_8859_6
: Print("B_ISO_8859_6"); break;
384 case B_ISO_8859_7
: Print("B_ISO_8859_7"); break;
385 case B_ISO_8859_8
: Print("B_ISO_8859_8"); break;
386 case B_ISO_8859_9
: Print("B_ISO_8859_9"); break;
387 case B_ISO_8859_10
: Print("B_ISO_8859_10"); break;
388 case B_MACINTOSH_ROMAN
: Print("B_MACINTOSH_ROMAN"); break;
389 default: Print("Unknown:", (float)encoding
);
394 #define PRINT_FLAG(flag) \
395 if (flags & flag) { f |= flag; Print(#flag); }
397 void PicturePrinter::SetFontFlags(int32 flags
) {
398 Indent(); Print("SetFontFlags");
400 if (flags
== 0) Print("none set");
401 PRINT_FLAG(B_DISABLE_ANTIALIASING
);
402 PRINT_FLAG(B_FORCE_ANTIALIASING
);
403 if (flags
!= f
) printf("Unknown Additional Flags %" B_PRId32
"", flags
& ~f
);
408 void PicturePrinter::SetFontShear(float shear
) {
409 Indent(); Print("SetFontShear", shear
); Cr();
413 void PicturePrinter::SetFontFace(int32 flags
) {
414 Indent(); Print("SetFontFace");
416 if (flags
== 0) Print("none set");
417 PRINT_FLAG(B_REGULAR_FACE
);
418 PRINT_FLAG(B_BOLD_FACE
);
419 PRINT_FLAG(B_ITALIC_FACE
);
420 PRINT_FLAG(B_NEGATIVE_FACE
);
421 PRINT_FLAG(B_OUTLINED_FACE
);
422 PRINT_FLAG(B_UNDERSCORE_FACE
);
423 PRINT_FLAG(B_STRIKEOUT_FACE
);
424 if (flags
!= f
) printf("Unknown Additional Flags %" B_PRId32
"", flags
& ~f
);
429 // Implementation of ShapePrinter
430 ShapePrinter::ShapePrinter(PicturePrinter
* printer
)
433 fPrinter
->IncIndent();
436 ShapePrinter::~ShapePrinter() {
437 fPrinter
->DecIndent();
441 ShapePrinter::IterateBezierTo(int32 bezierCount
, BPoint
*control
)
443 fPrinter
->Indent(); fPrinter
->Print("BezierTo"); fPrinter
->Cr();
444 for (int32 i
= 0; i
< bezierCount
; i
++, control
+= 3) {
446 fPrinter
->Print(i
/ 3.0);
447 fPrinter
->Print(&control
[0]);
448 fPrinter
->Print(&control
[1]);
449 fPrinter
->Print(&control
[2]);
456 ShapePrinter::IterateClose(void)
458 fPrinter
->Indent(); fPrinter
->Print("Close"); fPrinter
->Cr();
463 ShapePrinter::IterateLineTo(int32 lineCount
, BPoint
*linePoints
)
465 fPrinter
->Indent(); fPrinter
->Print("LineTo"); fPrinter
->Cr();
466 BPoint
*p
= linePoints
;
467 for (int32 i
= 0; i
< lineCount
; i
++) {
468 fPrinter
->Indent(1); fPrinter
->Print(p
); fPrinter
->Cr();
475 ShapePrinter::IterateMoveTo(BPoint
*point
)
477 fPrinter
->Indent(); fPrinter
->Print("MoveTo", point
); fPrinter
->Cr();