1 /* 2 * Copyright 2006-2018 Haiku, Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Stefano Ceccherini, burton666@libero.it 7 * Julian Harnath, <julian.harnath@rwth-achen.de> 8 * Stephan Aßmus <superstippi@gmx.de> 9 */ 10 #ifndef _PICTURE_DATA_WRITER_H 11 #define _PICTURE_DATA_WRITER_H 12 13 14 #include <AffineTransform.h> 15 #include <InterfaceDefs.h> 16 #include <Font.h> 17 #include <OS.h> 18 19 #include <stack> 20 21 22 class Layer; 23 class BPositionIO; 24 class BRegion; 25 26 class PictureDataWriter { 27 public: 28 PictureDataWriter(); 29 PictureDataWriter(BPositionIO* data); 30 virtual ~PictureDataWriter(); 31 32 status_t SetTo(BPositionIO* data); 33 34 status_t WriteSetHighColor(const rgb_color& color); 35 status_t WriteSetLowColor(const rgb_color& color); 36 status_t WriteSetOrigin(const BPoint& point); 37 status_t WriteSetDrawingMode(const drawing_mode& mode); 38 status_t WriteSetPenLocation(const BPoint& point); 39 status_t WriteSetPenSize(const float& penSize); 40 status_t WriteSetLineMode(const cap_mode& cap, 41 const join_mode& join, 42 const float& miterLimit); 43 status_t WriteSetScale(const float& scale); 44 status_t WriteSetTransform(BAffineTransform transform); 45 status_t WriteTranslateBy(double x, double y); 46 status_t WriteScaleBy(double x, double y); 47 status_t WriteRotateBy(double angleRadians); 48 status_t WriteSetPattern(const ::pattern& pattern); 49 status_t WriteClipToPicture(int32 pictureToken, 50 const BPoint& origin, bool inverse); 51 status_t WriteSetClipping(const BRegion& region); 52 status_t WriteClearClipping(); 53 54 status_t WritePushState(); 55 status_t WritePopState(); 56 57 status_t WriteSetFontFamily(const font_family family); 58 status_t WriteSetFontStyle(const font_style style); 59 status_t WriteSetFontSpacing(const int32& spacing); 60 status_t WriteSetFontSize(const float& size); 61 status_t WriteSetFontRotation(const float& rotation); 62 status_t WriteSetFontEncoding(const int32& encoding); 63 status_t WriteSetFontFlags(const int32& flags); 64 status_t WriteSetFontShear(const float& shear); 65 status_t WriteSetFontFace(const int32& face); 66 67 status_t WriteStrokeLine(const BPoint& start, 68 const BPoint& end); 69 status_t WriteInvertRect(const BRect& rect); 70 status_t WriteDrawRect(const BRect& rect, 71 const bool& fill); 72 status_t WriteDrawRoundRect(const BRect& rect, 73 const BPoint& radius, const bool& fill); 74 status_t WriteDrawEllipse(const BRect& rect, 75 const bool& fill); 76 status_t WriteDrawArc(const BPoint& center, 77 const BPoint& radius, 78 const float& startTheta, 79 const float& arcTheta, const bool& fill); 80 status_t WriteDrawPolygon(const int32& numPoints, 81 BPoint* points, const bool& isClosed, 82 const bool& fill); 83 status_t WriteDrawBezier(const BPoint points[4], 84 const bool& fill); 85 status_t WriteDrawString(const BPoint& where, 86 const char* string, const int32& length, 87 const escapement_delta& delta); 88 status_t WriteDrawString(const char* string, 89 int32 length, const BPoint* locations, 90 int32 locationCount); 91 status_t WriteDrawShape(const int32& opCount, 92 const void* opList, const int32& ptCount, 93 const void* ptList, const bool& fill); 94 status_t WriteDrawBitmap(const BRect& srcRect, 95 const BRect& dstRect, const int32& width, 96 const int32& height, 97 const int32& bytesPerRow, 98 const int32& colorSpace, 99 const int32& flags, 100 const void* data, const int32& length); 101 102 status_t WriteDrawPicture(const BPoint& where, 103 const int32& token); 104 105 status_t WriteBlendLayer(Layer* layer); 106 status_t WriteClipToRect(const BRect& rect, 107 bool inverse); 108 status_t WriteClipToShape(int32 opCount, 109 const void* opList, int32 ptCount, 110 const void* ptList, bool inverse); 111 112 protected: 113 // throw a status_t on error 114 void BeginOp(const int16& op); 115 void EndOp(); 116 void WriteData(const void* data, size_t size); 117 template <typename T> void Write(const T& data) 118 { WriteData(&data, sizeof(data)); } 119 120 private: 121 BPositionIO* fData; 122 std::stack<off_t> fStack; 123 }; 124 125 126 #endif // _PICTURE_DATA_WRITER_H 127