PictureDataWriter: Style fixes only
No functional change intended
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2006-2007, Haiku Inc.
|
* Copyright 2006-2007 Haiku, Inc. All rights reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
* Stefano Ceccherini ([email protected])
|
* Stefano Ceccherini, [email protected]
|
||||||
*/
|
*/
|
||||||
#ifndef _PICTURE_DATA_WRITER_H
|
#ifndef _PICTURE_DATA_WRITER_H
|
||||||
#define _PICTURE_DATA_WRITER_H
|
#define _PICTURE_DATA_WRITER_H
|
||||||
@@ -16,74 +16,93 @@
|
|||||||
|
|
||||||
#include <stack>
|
#include <stack>
|
||||||
|
|
||||||
|
|
||||||
class BPositionIO;
|
class BPositionIO;
|
||||||
class BRegion;
|
class BRegion;
|
||||||
|
|
||||||
|
|
||||||
class PictureDataWriter {
|
class PictureDataWriter {
|
||||||
public:
|
public:
|
||||||
PictureDataWriter();
|
PictureDataWriter();
|
||||||
PictureDataWriter(BPositionIO *data);
|
PictureDataWriter(BPositionIO* data);
|
||||||
virtual ~PictureDataWriter();
|
virtual ~PictureDataWriter();
|
||||||
|
|
||||||
status_t SetTo(BPositionIO *data);
|
status_t SetTo(BPositionIO* data);
|
||||||
|
|
||||||
status_t WriteSetHighColor(const rgb_color &color);
|
status_t WriteSetHighColor(const rgb_color& color);
|
||||||
status_t WriteSetLowColor(const rgb_color &color);
|
status_t WriteSetLowColor(const rgb_color& color);
|
||||||
status_t WriteSetOrigin(const BPoint &point);
|
status_t WriteSetOrigin(const BPoint& point);
|
||||||
status_t WriteSetDrawingMode(const drawing_mode &mode);
|
status_t WriteSetDrawingMode(const drawing_mode& mode);
|
||||||
status_t WriteSetPenLocation(const BPoint &point);
|
status_t WriteSetPenLocation(const BPoint& point);
|
||||||
status_t WriteSetPenSize(const float &penSize);
|
status_t WriteSetPenSize(const float& penSize);
|
||||||
status_t WriteSetLineMode(const cap_mode &cap, const join_mode &join, const float &miterLimit);
|
status_t WriteSetLineMode(const cap_mode& cap,
|
||||||
status_t WriteSetScale(const float &scale);
|
const join_mode& join,
|
||||||
status_t WriteSetTransform(BAffineTransform transform);
|
const float& miterLimit);
|
||||||
status_t WriteSetPattern(const pattern &pat);
|
status_t WriteSetScale(const float& scale);
|
||||||
status_t WriteSetClipping(const BRegion ®ion);
|
status_t WriteSetTransform(BAffineTransform transform);
|
||||||
status_t WriteClearClipping();
|
status_t WriteSetPattern(const ::pattern& pattern);
|
||||||
|
status_t WriteSetClipping(const BRegion& region);
|
||||||
|
status_t WriteClearClipping();
|
||||||
|
|
||||||
status_t WritePushState();
|
status_t WritePushState();
|
||||||
status_t WritePopState();
|
status_t WritePopState();
|
||||||
|
|
||||||
status_t WriteSetFontFamily(const font_family family);
|
|
||||||
status_t WriteSetFontStyle(const font_style style);
|
|
||||||
status_t WriteSetFontSpacing(const int32 &spacing);
|
|
||||||
status_t WriteSetFontSize(const float &size);
|
|
||||||
status_t WriteSetFontRotation(const float &rotation);
|
|
||||||
status_t WriteSetFontEncoding(const int32 &encoding);
|
|
||||||
status_t WriteSetFontFlags(const int32 &flags);
|
|
||||||
status_t WriteSetFontShear(const float &shear);
|
|
||||||
status_t WriteSetFontFace(const int32 &face);
|
|
||||||
|
|
||||||
status_t WriteStrokeLine(const BPoint &start, const BPoint &end);
|
status_t WriteSetFontFamily(const font_family family);
|
||||||
status_t WriteInvertRect(const BRect &rect);
|
status_t WriteSetFontStyle(const font_style style);
|
||||||
status_t WriteDrawRect(const BRect &rect, const bool &fill);
|
status_t WriteSetFontSpacing(const int32& spacing);
|
||||||
status_t WriteDrawRoundRect(const BRect &rect, const BPoint &radius, const bool &fill);
|
status_t WriteSetFontSize(const float& size);
|
||||||
status_t WriteDrawEllipse(const BRect &rect, const bool &fill);
|
status_t WriteSetFontRotation(const float& rotation);
|
||||||
status_t WriteDrawArc(const BPoint ¢er, const BPoint &radius,
|
status_t WriteSetFontEncoding(const int32& encoding);
|
||||||
const float &startTheta, const float &arcTheta, const bool &fill);
|
status_t WriteSetFontFlags(const int32& flags);
|
||||||
status_t WriteDrawPolygon(const int32 &numPoints, BPoint *points,
|
status_t WriteSetFontShear(const float& shear);
|
||||||
const bool &isClosed, const bool &fill);
|
status_t WriteSetFontFace(const int32& face);
|
||||||
status_t WriteDrawBezier(const BPoint points[4], const bool &fill);
|
|
||||||
status_t WriteDrawString(const BPoint &where, const char *string,
|
|
||||||
const int32 &length, const escapement_delta &delta);
|
|
||||||
status_t WriteDrawShape(const int32 &opCount, const void *opList,
|
|
||||||
const int32 &ptCount, const void *ptList, const bool &fill);
|
|
||||||
status_t WriteDrawBitmap(const BRect &srcRect, const BRect &dstRect, const int32 &width, const int32 &height,
|
|
||||||
const int32 &bytesPerRow, const int32 &colorSpace, const int32 &flags,
|
|
||||||
const void *data, const int32 &length);
|
|
||||||
|
|
||||||
status_t WriteDrawPicture(const BPoint &where, const int32 &token);
|
status_t WriteStrokeLine(const BPoint& start,
|
||||||
|
const BPoint& end);
|
||||||
|
status_t WriteInvertRect(const BRect& rect);
|
||||||
|
status_t WriteDrawRect(const BRect& rect,
|
||||||
|
const bool& fill);
|
||||||
|
status_t WriteDrawRoundRect(const BRect& rect,
|
||||||
|
const BPoint& radius, const bool& fill);
|
||||||
|
status_t WriteDrawEllipse(const BRect& rect,
|
||||||
|
const bool& fill);
|
||||||
|
status_t WriteDrawArc(const BPoint& center,
|
||||||
|
const BPoint& radius,
|
||||||
|
const float& startTheta,
|
||||||
|
const float& arcTheta, const bool& fill);
|
||||||
|
status_t WriteDrawPolygon(const int32& numPoints,
|
||||||
|
BPoint* points, const bool& isClosed,
|
||||||
|
const bool& fill);
|
||||||
|
status_t WriteDrawBezier(const BPoint points[4],
|
||||||
|
const bool& fill);
|
||||||
|
status_t WriteDrawString(const BPoint& where,
|
||||||
|
const char* string, const int32& length,
|
||||||
|
const escapement_delta& delta);
|
||||||
|
status_t WriteDrawShape(const int32& opCount,
|
||||||
|
const void* opList, const int32& ptCount,
|
||||||
|
const void* ptList, const bool& fill);
|
||||||
|
status_t WriteDrawBitmap(const BRect& srcRect,
|
||||||
|
const BRect& dstRect, const int32& width,
|
||||||
|
const int32& height,
|
||||||
|
const int32& bytesPerRow,
|
||||||
|
const int32& colorSpace,
|
||||||
|
const int32& flags,
|
||||||
|
const void* data, const int32& length);
|
||||||
|
|
||||||
|
status_t WriteDrawPicture(const BPoint& where,
|
||||||
|
const int32& token);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// throw a status_t on error
|
// throw a status_t on error
|
||||||
void BeginOp(const int16 &op);
|
void BeginOp(const int16& op);
|
||||||
void EndOp();
|
void EndOp();
|
||||||
void WriteData(const void *data, size_t size);
|
void WriteData(const void* data, size_t size);
|
||||||
template <typename T> void Write(const T &data) { WriteData(&data, sizeof(data)); }
|
template <typename T> void Write(const T& data)
|
||||||
|
{ WriteData(&data, sizeof(data)); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BPositionIO *fData;
|
BPositionIO* fData;
|
||||||
std::stack<off_t> fStack;
|
std::stack<off_t> fStack;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // _PICTURE_DATA_WRITER_H
|
#endif // _PICTURE_DATA_WRITER_H
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2006-2009, Haiku Inc.
|
* Copyright 2006-2009 Haiku, Inc. All rights reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
* Stefano Ceccherini ([email protected])
|
* Stefano Ceccherini, [email protected]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <PictureDataWriter.h>
|
#include <PictureDataWriter.h>
|
||||||
@@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
#define THROW_ERROR(error) throw (status_t)(error)
|
#define THROW_ERROR(error) throw (status_t)(error)
|
||||||
|
|
||||||
|
|
||||||
// TODO: Review writing of strings. AFAIK in the picture data format
|
// TODO: Review writing of strings. AFAIK in the picture data format
|
||||||
// They are not supposed to be NULL terminated
|
// They are not supposed to be NULL terminated
|
||||||
// (at least, it's not mandatory) so we should write their size too.
|
// (at least, it's not mandatory) so we should write their size too.
|
||||||
@@ -30,7 +31,7 @@ PictureDataWriter::PictureDataWriter()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PictureDataWriter::PictureDataWriter(BPositionIO *data)
|
PictureDataWriter::PictureDataWriter(BPositionIO* data)
|
||||||
:
|
:
|
||||||
fData(data)
|
fData(data)
|
||||||
{
|
{
|
||||||
@@ -43,92 +44,99 @@ PictureDataWriter::~PictureDataWriter()
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
PictureDataWriter::SetTo(BPositionIO *data)
|
PictureDataWriter::SetTo(BPositionIO* data)
|
||||||
{
|
{
|
||||||
if (data == NULL)
|
if (data == NULL)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
fData = data;
|
fData = data;
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
PictureDataWriter::WriteSetOrigin(const BPoint &point)
|
PictureDataWriter::WriteSetOrigin(const BPoint& point)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
BeginOp(B_PIC_SET_ORIGIN);
|
BeginOp(B_PIC_SET_ORIGIN);
|
||||||
Write<BPoint>(point);
|
Write<BPoint>(point);
|
||||||
EndOp();
|
EndOp();
|
||||||
} catch (status_t &status) {
|
} catch (status_t& status) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
PictureDataWriter::WriteInvertRect(const BRect &rect)
|
PictureDataWriter::WriteInvertRect(const BRect& rect)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
WriteSetDrawingMode(B_OP_INVERT);
|
WriteSetDrawingMode(B_OP_INVERT);
|
||||||
|
|
||||||
BeginOp(B_PIC_FILL_RECT);
|
BeginOp(B_PIC_FILL_RECT);
|
||||||
Write<BRect>(rect);
|
Write<BRect>(rect);
|
||||||
EndOp();
|
EndOp();
|
||||||
|
|
||||||
WriteSetDrawingMode(B_OP_COPY);
|
WriteSetDrawingMode(B_OP_COPY);
|
||||||
} catch (status_t &status) {
|
} catch (status_t& status) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
PictureDataWriter::WriteSetDrawingMode(const drawing_mode &mode)
|
PictureDataWriter::WriteSetDrawingMode(const drawing_mode& mode)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
BeginOp(B_PIC_SET_DRAWING_MODE);
|
BeginOp(B_PIC_SET_DRAWING_MODE);
|
||||||
Write<int16>((int16)mode);
|
Write<int16>((int16)mode);
|
||||||
EndOp();
|
EndOp();
|
||||||
} catch (status_t &status) {
|
} catch (status_t& status) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
PictureDataWriter::WriteSetPenLocation(const BPoint &point)
|
PictureDataWriter::WriteSetPenLocation(const BPoint& point)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
BeginOp(B_PIC_SET_PEN_LOCATION);
|
BeginOp(B_PIC_SET_PEN_LOCATION);
|
||||||
Write<BPoint>(point);
|
Write<BPoint>(point);
|
||||||
EndOp();
|
EndOp();
|
||||||
} catch (status_t &status) {
|
} catch (status_t& status) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
PictureDataWriter::WriteSetPenSize(const float &penSize)
|
PictureDataWriter::WriteSetPenSize(const float& penSize)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
BeginOp(B_PIC_SET_PEN_SIZE);
|
BeginOp(B_PIC_SET_PEN_SIZE);
|
||||||
Write<float>(penSize);
|
Write<float>(penSize);
|
||||||
EndOp();
|
EndOp();
|
||||||
} catch (status_t &status) {
|
} catch (status_t& status) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
PictureDataWriter::WriteSetLineMode(const cap_mode &cap,
|
PictureDataWriter::WriteSetLineMode(const cap_mode& cap, const join_mode& join,
|
||||||
const join_mode &join, const float &miterLimit)
|
const float& miterLimit)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
BeginOp(B_PIC_SET_LINE_MODE);
|
BeginOp(B_PIC_SET_LINE_MODE);
|
||||||
@@ -136,23 +144,25 @@ PictureDataWriter::WriteSetLineMode(const cap_mode &cap,
|
|||||||
Write<int16>((int16)join);
|
Write<int16>((int16)join);
|
||||||
Write<float>(miterLimit);
|
Write<float>(miterLimit);
|
||||||
EndOp();
|
EndOp();
|
||||||
} catch (status_t &status) {
|
} catch (status_t& status) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
PictureDataWriter::WriteSetScale(const float &scale)
|
PictureDataWriter::WriteSetScale(const float& scale)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
BeginOp(B_PIC_SET_SCALE);
|
BeginOp(B_PIC_SET_SCALE);
|
||||||
Write<float>(scale);
|
Write<float>(scale);
|
||||||
EndOp();
|
EndOp();
|
||||||
} catch (status_t &status) {
|
} catch (status_t& status) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,43 +174,45 @@ PictureDataWriter::WriteSetTransform(BAffineTransform transform)
|
|||||||
BeginOp(B_PIC_SET_TRANSFORM);
|
BeginOp(B_PIC_SET_TRANSFORM);
|
||||||
Write<BAffineTransform>(transform);
|
Write<BAffineTransform>(transform);
|
||||||
EndOp();
|
EndOp();
|
||||||
} catch (status_t &status) {
|
} catch (status_t& status) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
PictureDataWriter::WriteSetPattern(const pattern &pat)
|
PictureDataWriter::WriteSetPattern(const ::pattern& pattern)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
BeginOp(B_PIC_SET_STIPLE_PATTERN);
|
BeginOp(B_PIC_SET_STIPLE_PATTERN);
|
||||||
Write<pattern>(pat);
|
Write< ::pattern>(pattern);
|
||||||
EndOp();
|
EndOp();
|
||||||
} catch (status_t &status) {
|
} catch (status_t& status) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
PictureDataWriter::WriteSetClipping(const BRegion ®ion)
|
PictureDataWriter::WriteSetClipping(const BRegion& region)
|
||||||
{
|
{
|
||||||
// TODO: I don't know if it's compatible with R5's BPicture version
|
// TODO: I don't know if it's compatible with R5's BPicture version
|
||||||
try {
|
try {
|
||||||
const int32 numRects = region.CountRects();
|
const int32 numRects = region.CountRects();
|
||||||
if (numRects > 0 && region.Frame().IsValid()) {
|
if (numRects > 0 && region.Frame().IsValid()) {
|
||||||
BeginOp(B_PIC_SET_CLIPPING_RECTS);
|
BeginOp(B_PIC_SET_CLIPPING_RECTS);
|
||||||
Write<uint32>(numRects);
|
Write<uint32>(numRects);
|
||||||
for (int32 i = 0; i < numRects; i++) {
|
for (int32 i = 0; i < numRects; i++)
|
||||||
Write<BRect>(region.RectAt(i));
|
Write<BRect>(region.RectAt(i));
|
||||||
}
|
|
||||||
EndOp();
|
EndOp();
|
||||||
} else
|
} else
|
||||||
WriteClearClipping();
|
WriteClearClipping();
|
||||||
} catch (status_t &status) {
|
} catch (status_t& status) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -214,90 +226,94 @@ PictureDataWriter::WriteClearClipping()
|
|||||||
try {
|
try {
|
||||||
BeginOp(B_PIC_CLEAR_CLIPPING_RECTS);
|
BeginOp(B_PIC_CLEAR_CLIPPING_RECTS);
|
||||||
EndOp();
|
EndOp();
|
||||||
} catch (status_t &status) {
|
} catch (status_t& status) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
PictureDataWriter::WriteSetHighColor(const rgb_color &color)
|
PictureDataWriter::WriteSetHighColor(const rgb_color& color)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
BeginOp(B_PIC_SET_FORE_COLOR);
|
BeginOp(B_PIC_SET_FORE_COLOR);
|
||||||
Write<rgb_color>(color);
|
Write<rgb_color>(color);
|
||||||
EndOp();
|
EndOp();
|
||||||
} catch (status_t &status) {
|
} catch (status_t& status) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
PictureDataWriter::WriteSetLowColor(const rgb_color &color)
|
PictureDataWriter::WriteSetLowColor(const rgb_color& color)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
BeginOp(B_PIC_SET_BACK_COLOR);
|
BeginOp(B_PIC_SET_BACK_COLOR);
|
||||||
Write<rgb_color>(color);
|
Write<rgb_color>(color);
|
||||||
EndOp();
|
EndOp();
|
||||||
} catch (status_t &status) {
|
} catch (status_t& status) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
PictureDataWriter::WriteDrawRect(const BRect &rect,
|
PictureDataWriter::WriteDrawRect(const BRect& rect, const bool& fill)
|
||||||
const bool &fill)
|
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
BeginOp(fill ? B_PIC_FILL_RECT : B_PIC_STROKE_RECT);
|
BeginOp(fill ? B_PIC_FILL_RECT : B_PIC_STROKE_RECT);
|
||||||
Write<BRect>(rect);
|
Write<BRect>(rect);
|
||||||
EndOp();
|
EndOp();
|
||||||
} catch (status_t &status) {
|
} catch (status_t& status) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
PictureDataWriter::WriteDrawRoundRect(const BRect &rect,
|
PictureDataWriter::WriteDrawRoundRect(const BRect& rect, const BPoint& radius,
|
||||||
const BPoint &radius, const bool &fill)
|
const bool& fill)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
BeginOp(fill ? B_PIC_FILL_ROUND_RECT : B_PIC_STROKE_ROUND_RECT);
|
BeginOp(fill ? B_PIC_FILL_ROUND_RECT : B_PIC_STROKE_ROUND_RECT);
|
||||||
Write<BRect>(rect);
|
Write<BRect>(rect);
|
||||||
Write<BPoint>(radius);
|
Write<BPoint>(radius);
|
||||||
EndOp();
|
EndOp();
|
||||||
} catch (status_t &status) {
|
} catch (status_t& status) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
PictureDataWriter::WriteDrawEllipse(const BRect &rect, const bool &fill)
|
PictureDataWriter::WriteDrawEllipse(const BRect& rect, const bool& fill)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
BeginOp(fill ? B_PIC_FILL_ELLIPSE : B_PIC_STROKE_ELLIPSE);
|
BeginOp(fill ? B_PIC_FILL_ELLIPSE : B_PIC_STROKE_ELLIPSE);
|
||||||
Write<BRect>(rect);
|
Write<BRect>(rect);
|
||||||
EndOp();
|
EndOp();
|
||||||
} catch (status_t &status) {
|
} catch (status_t& status) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
PictureDataWriter::WriteDrawArc(const BPoint ¢er,
|
PictureDataWriter::WriteDrawArc(const BPoint& center, const BPoint& radius,
|
||||||
const BPoint &radius, const float &startTheta,
|
const float& startTheta, const float& arcTheta, const bool& fill)
|
||||||
const float &arcTheta, const bool &fill)
|
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
BeginOp(fill ? B_PIC_FILL_ARC : B_PIC_STROKE_ARC);
|
BeginOp(fill ? B_PIC_FILL_ARC : B_PIC_STROKE_ARC);
|
||||||
@@ -306,74 +322,78 @@ PictureDataWriter::WriteDrawArc(const BPoint ¢er,
|
|||||||
Write<float>(startTheta);
|
Write<float>(startTheta);
|
||||||
Write<float>(arcTheta);
|
Write<float>(arcTheta);
|
||||||
EndOp();
|
EndOp();
|
||||||
} catch (status_t &status) {
|
} catch (status_t& status) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
PictureDataWriter::WriteDrawPolygon(const int32 &numPoints,
|
PictureDataWriter::WriteDrawPolygon(const int32& numPoints, BPoint* points,
|
||||||
BPoint *points, const bool &isClosed, const bool &fill)
|
const bool& isClosed, const bool& fill)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
BeginOp(fill ? B_PIC_FILL_POLYGON : B_PIC_STROKE_POLYGON);
|
BeginOp(fill ? B_PIC_FILL_POLYGON : B_PIC_STROKE_POLYGON);
|
||||||
Write<int32>(numPoints);
|
Write<int32>(numPoints);
|
||||||
for (int32 i = 0; i < numPoints; i++)
|
for (int32 i = 0; i < numPoints; i++)
|
||||||
Write<BPoint>(points[i]);
|
Write<BPoint>(points[i]);
|
||||||
|
|
||||||
if (!fill)
|
if (!fill)
|
||||||
Write<uint8>((uint8)isClosed);
|
Write<uint8>((uint8)isClosed);
|
||||||
|
|
||||||
EndOp();
|
EndOp();
|
||||||
} catch (status_t &status) {
|
} catch (status_t& status) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
PictureDataWriter::WriteDrawBezier(const BPoint points[4],
|
PictureDataWriter::WriteDrawBezier(const BPoint points[4], const bool& fill)
|
||||||
const bool &fill)
|
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
BeginOp(fill ? B_PIC_FILL_BEZIER : B_PIC_STROKE_BEZIER);
|
BeginOp(fill ? B_PIC_FILL_BEZIER : B_PIC_STROKE_BEZIER);
|
||||||
for (int32 i = 0; i < 4; i++)
|
for (int32 i = 0; i < 4; i++)
|
||||||
Write<BPoint>(points[i]);
|
Write<BPoint>(points[i]);
|
||||||
|
|
||||||
EndOp();
|
EndOp();
|
||||||
} catch (status_t &status) {
|
} catch (status_t& status) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
PictureDataWriter::WriteStrokeLine(const BPoint &start,
|
PictureDataWriter::WriteStrokeLine(const BPoint& start, const BPoint& end)
|
||||||
const BPoint &end)
|
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
BeginOp(B_PIC_STROKE_LINE);
|
BeginOp(B_PIC_STROKE_LINE);
|
||||||
Write<BPoint>(start);
|
Write<BPoint>(start);
|
||||||
Write<BPoint>(end);
|
Write<BPoint>(end);
|
||||||
EndOp();
|
EndOp();
|
||||||
} catch (status_t &status) {
|
} catch (status_t& status) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
PictureDataWriter::WriteDrawString(const BPoint &where,
|
PictureDataWriter::WriteDrawString(const BPoint& where, const char* string,
|
||||||
const char *string, const int32 &length,
|
const int32& length, const escapement_delta& escapement)
|
||||||
const escapement_delta &escapement)
|
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
BeginOp(B_PIC_SET_PEN_LOCATION);
|
BeginOp(B_PIC_SET_PEN_LOCATION);
|
||||||
Write<BPoint>(where);
|
Write<BPoint>(where);
|
||||||
EndOp();
|
EndOp();
|
||||||
|
|
||||||
BeginOp(B_PIC_DRAW_STRING);
|
BeginOp(B_PIC_DRAW_STRING);
|
||||||
Write<float>(escapement.space);
|
Write<float>(escapement.space);
|
||||||
Write<float>(escapement.nonspace);
|
Write<float>(escapement.nonspace);
|
||||||
@@ -382,8 +402,8 @@ PictureDataWriter::WriteDrawString(const BPoint &where,
|
|||||||
WriteData(string, length);
|
WriteData(string, length);
|
||||||
Write<uint8>(0);
|
Write<uint8>(0);
|
||||||
EndOp();
|
EndOp();
|
||||||
} catch (status_t &status) {
|
} catch (status_t& status) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
@@ -391,9 +411,8 @@ PictureDataWriter::WriteDrawString(const BPoint &where,
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
PictureDataWriter::WriteDrawShape(const int32 &opCount,
|
PictureDataWriter::WriteDrawShape(const int32& opCount, const void* opList,
|
||||||
const void *opList, const int32 &ptCount, const void *ptList,
|
const int32& ptCount, const void* ptList, const bool& fill)
|
||||||
const bool &fill)
|
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
BeginOp(fill ? B_PIC_FILL_SHAPE : B_PIC_STROKE_SHAPE);
|
BeginOp(fill ? B_PIC_FILL_SHAPE : B_PIC_STROKE_SHAPE);
|
||||||
@@ -402,23 +421,23 @@ PictureDataWriter::WriteDrawShape(const int32 &opCount,
|
|||||||
WriteData(opList, opCount * sizeof(uint32));
|
WriteData(opList, opCount * sizeof(uint32));
|
||||||
WriteData(ptList, ptCount * sizeof(BPoint));
|
WriteData(ptList, ptCount * sizeof(BPoint));
|
||||||
EndOp();
|
EndOp();
|
||||||
} catch (status_t &status) {
|
} catch (status_t& status) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
PictureDataWriter::WriteDrawBitmap(const BRect &srcRect,
|
PictureDataWriter::WriteDrawBitmap(const BRect& srcRect, const BRect& dstRect,
|
||||||
const BRect &dstRect, const int32 &width, const int32 &height,
|
const int32& width, const int32& height, const int32& bytesPerRow,
|
||||||
const int32 &bytesPerRow, const int32 &colorSpace,
|
const int32& colorSpace, const int32& flags, const void* data,
|
||||||
const int32 &flags, const void *data, const int32 &length)
|
const int32& length)
|
||||||
{
|
{
|
||||||
if (length != height * bytesPerRow)
|
if (length != height * bytesPerRow)
|
||||||
debugger("PictureDataWriter::WriteDrawBitmap: invalid length");
|
debugger("PictureDataWriter::WriteDrawBitmap: invalid length");
|
||||||
try {
|
try {
|
||||||
BeginOp(B_PIC_DRAW_PIXELS);
|
BeginOp(B_PIC_DRAW_PIXELS);
|
||||||
Write<BRect>(srcRect);
|
Write<BRect>(srcRect);
|
||||||
Write<BRect>(dstRect);
|
Write<BRect>(dstRect);
|
||||||
@@ -429,16 +448,16 @@ PictureDataWriter::WriteDrawBitmap(const BRect &srcRect,
|
|||||||
Write<int32>(flags);
|
Write<int32>(flags);
|
||||||
WriteData(data, length);
|
WriteData(data, length);
|
||||||
EndOp();
|
EndOp();
|
||||||
} catch (status_t &status) {
|
} catch (status_t& status) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
PictureDataWriter::WriteDrawPicture(const BPoint &where,
|
PictureDataWriter::WriteDrawPicture(const BPoint& where, const int32& token)
|
||||||
const int32 &token)
|
|
||||||
{
|
{
|
||||||
// TODO: I'm not sure about this function. I think we need
|
// TODO: I'm not sure about this function. I think we need
|
||||||
// to attach the picture data too.
|
// to attach the picture data too.
|
||||||
@@ -447,11 +466,12 @@ PictureDataWriter::WriteDrawPicture(const BPoint &where,
|
|||||||
try {
|
try {
|
||||||
BeginOp(B_PIC_DRAW_PICTURE);
|
BeginOp(B_PIC_DRAW_PICTURE);
|
||||||
Write<BPoint>(where);
|
Write<BPoint>(where);
|
||||||
Write<int32>(token);
|
Write<int32>(token);
|
||||||
EndOp();
|
EndOp();
|
||||||
} catch (status_t &status) {
|
} catch (status_t& status) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -464,9 +484,10 @@ PictureDataWriter::WriteSetFontFamily(const font_family family)
|
|||||||
WriteData(family, strlen(family));
|
WriteData(family, strlen(family));
|
||||||
Write<uint8>(0);
|
Write<uint8>(0);
|
||||||
EndOp();
|
EndOp();
|
||||||
} catch (status_t &status) {
|
} catch (status_t& status) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -479,107 +500,115 @@ PictureDataWriter::WriteSetFontStyle(const font_style style)
|
|||||||
WriteData(style, strlen(style));
|
WriteData(style, strlen(style));
|
||||||
Write<uint8>(0);
|
Write<uint8>(0);
|
||||||
EndOp();
|
EndOp();
|
||||||
} catch (status_t &status) {
|
} catch (status_t& status) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
PictureDataWriter::WriteSetFontSpacing(const int32 &spacing)
|
PictureDataWriter::WriteSetFontSpacing(const int32& spacing)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
BeginOp(B_PIC_SET_FONT_SPACING);
|
BeginOp(B_PIC_SET_FONT_SPACING);
|
||||||
Write<int32>(spacing);
|
Write<int32>(spacing);
|
||||||
EndOp();
|
EndOp();
|
||||||
} catch (status_t &status) {
|
} catch (status_t& status) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
PictureDataWriter::WriteSetFontSize(const float &size)
|
PictureDataWriter::WriteSetFontSize(const float& size)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
BeginOp(B_PIC_SET_FONT_SIZE);
|
BeginOp(B_PIC_SET_FONT_SIZE);
|
||||||
Write<float>(size);
|
Write<float>(size);
|
||||||
EndOp();
|
EndOp();
|
||||||
} catch (status_t &status) {
|
} catch (status_t& status) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
PictureDataWriter::WriteSetFontRotation(const float &rotation)
|
PictureDataWriter::WriteSetFontRotation(const float& rotation)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
BeginOp(B_PIC_SET_FONT_ROTATE);
|
BeginOp(B_PIC_SET_FONT_ROTATE);
|
||||||
Write<float>(rotation);
|
Write<float>(rotation);
|
||||||
EndOp();
|
EndOp();
|
||||||
} catch (status_t &status) {
|
} catch (status_t& status) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
PictureDataWriter::WriteSetFontEncoding(const int32 &encoding)
|
PictureDataWriter::WriteSetFontEncoding(const int32& encoding)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
BeginOp(B_PIC_SET_FONT_ENCODING);
|
BeginOp(B_PIC_SET_FONT_ENCODING);
|
||||||
Write<int32>(encoding);
|
Write<int32>(encoding);
|
||||||
EndOp();
|
EndOp();
|
||||||
} catch (status_t &status) {
|
} catch (status_t& status) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
PictureDataWriter::WriteSetFontFlags(const int32 &flags)
|
PictureDataWriter::WriteSetFontFlags(const int32& flags)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
BeginOp(B_PIC_SET_FONT_FLAGS);
|
BeginOp(B_PIC_SET_FONT_FLAGS);
|
||||||
Write<int32>(flags);
|
Write<int32>(flags);
|
||||||
EndOp();
|
EndOp();
|
||||||
} catch (status_t &status) {
|
} catch (status_t& status) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
PictureDataWriter::WriteSetFontShear(const float &shear)
|
PictureDataWriter::WriteSetFontShear(const float& shear)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
BeginOp(B_PIC_SET_FONT_SHEAR);
|
BeginOp(B_PIC_SET_FONT_SHEAR);
|
||||||
Write<float>(shear);
|
Write<float>(shear);
|
||||||
EndOp();
|
EndOp();
|
||||||
} catch (status_t &status) {
|
} catch (status_t& status) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
PictureDataWriter::WriteSetFontFace(const int32 &face)
|
PictureDataWriter::WriteSetFontFace(const int32& face)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
BeginOp(B_PIC_SET_FONT_FACE);
|
BeginOp(B_PIC_SET_FONT_FACE);
|
||||||
Write<int32>(face);
|
Write<int32>(face);
|
||||||
EndOp();
|
EndOp();
|
||||||
} catch (status_t &status) {
|
} catch (status_t& status) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -590,9 +619,10 @@ PictureDataWriter::WritePushState()
|
|||||||
try {
|
try {
|
||||||
BeginOp(B_PIC_PUSH_STATE);
|
BeginOp(B_PIC_PUSH_STATE);
|
||||||
EndOp();
|
EndOp();
|
||||||
} catch (status_t &status) {
|
} catch (status_t& status) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -603,23 +633,24 @@ PictureDataWriter::WritePopState()
|
|||||||
try {
|
try {
|
||||||
BeginOp(B_PIC_POP_STATE);
|
BeginOp(B_PIC_POP_STATE);
|
||||||
EndOp();
|
EndOp();
|
||||||
} catch (status_t &status) {
|
} catch (status_t& status) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// private
|
// private
|
||||||
void
|
void
|
||||||
PictureDataWriter::BeginOp(const int16 &op)
|
PictureDataWriter::BeginOp(const int16& op)
|
||||||
{
|
{
|
||||||
if (fData == NULL)
|
if (fData == NULL)
|
||||||
THROW_ERROR(B_NO_INIT);
|
THROW_ERROR(B_NO_INIT);
|
||||||
|
|
||||||
fStack.push(fData->Position());
|
fStack.push(fData->Position());
|
||||||
fData->Write(&op, sizeof(op));
|
fData->Write(&op, sizeof(op));
|
||||||
|
|
||||||
// Init the size of the opcode block to 0
|
// Init the size of the opcode block to 0
|
||||||
int32 size = 0;
|
int32 size = 0;
|
||||||
fData->Write(&size, sizeof(size));
|
fData->Write(&size, sizeof(size));
|
||||||
@@ -635,7 +666,7 @@ PictureDataWriter::EndOp()
|
|||||||
off_t curPos = fData->Position();
|
off_t curPos = fData->Position();
|
||||||
off_t stackPos = fStack.top();
|
off_t stackPos = fStack.top();
|
||||||
fStack.pop();
|
fStack.pop();
|
||||||
|
|
||||||
// The size of the op is calculated like this:
|
// The size of the op is calculated like this:
|
||||||
// current position on the stream minus the position on the stack,
|
// current position on the stream minus the position on the stack,
|
||||||
// minus the space occupied by the op code itself (int16)
|
// minus the space occupied by the op code itself (int16)
|
||||||
@@ -651,11 +682,12 @@ PictureDataWriter::EndOp()
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PictureDataWriter::WriteData(const void *data, size_t size)
|
PictureDataWriter::WriteData(const void* data, size_t size)
|
||||||
{
|
{
|
||||||
ssize_t result = fData->Write(data, size);
|
ssize_t result = fData->Write(data, size);
|
||||||
if (result < 0)
|
if (result < 0)
|
||||||
THROW_ERROR(result);
|
THROW_ERROR(result);
|
||||||
|
|
||||||
if ((size_t)result != size)
|
if ((size_t)result != size)
|
||||||
THROW_ERROR(B_IO_ERROR);
|
THROW_ERROR(B_IO_ERROR);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user