Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

400 lines
16 KiB

  1. #ifndef _ANNOT_H_
  2. #define _ANNOT_H_
  3. #include <windows.h>
  4. #include <shlobj.h>
  5. #include <shlobjp.h>
  6. #include <commctrl.h>
  7. #include <comctrlp.h>
  8. #include <gdiplus.h>
  9. using namespace Gdiplus;
  10. #include <shimgdata.h>
  11. // This file defines classes used to render and edit TIFF 6.0 annotations.
  12. // These annotations are stored in tag #32932. The specification for these annotations
  13. // is defined by Eastman Software, the spec version is 1.00.06.
  14. #define ANNOTATION_IMAGE_TAG 32932
  15. // These structures define the in-file layout of the annotations.
  16. // Note that most of the structs are variable-sized.
  17. // The annotation parser reads the annotations into these structures, wraps them in a descriptor
  18. // and passes the descriptor to the annotation factory object to construct
  19. // CAnnotationMark-derived classes that implement
  20. // the rendering, editing, and saving of the different types of marks.
  21. // MT_* used in ANNOTATIONMARK::uType
  22. #define MT_IMAGEEMBED 1
  23. #define MT_IMAGEREF 2
  24. #define MT_STRAIGHTLINE 3
  25. #define MT_FREEHANDLINE 4
  26. #define MT_HOLLOWRECT 5
  27. #define MT_FILLRECT 6
  28. #define MT_TYPEDTEXT 7
  29. #define MT_FILETEXT 8
  30. #define MT_STAMP 9
  31. #define MT_ATTACHANOTE 10
  32. #define MT_FORM 11
  33. #define MT_OCR 12 // unsupported
  34. // ANNOTATIONMARK is fixed size and exists for every mark in the file
  35. // We only support files with 4 byte integers
  36. // this struct is not declared as UNALIGNED because we never typecast a variable
  37. // as this type.
  38. struct ANNOTATIONMARK
  39. {
  40. UINT uType; /* The type of the mark (or operation).
  41. This will be ignored for sets.*/
  42. RECT lrBounds; /* Rect in FULLSIZE units.
  43. This could be a rect or 2 points.*/
  44. RGBQUAD rgbColor1; /* This is the main color. (Example: This is the
  45. color of all lines, rects, and stand alone
  46. text.*/
  47. RGBQUAD rgbColor2; /* This is the secondary color. (Example: This
  48. is the color of the text of an ATTACH_A_NOTE.)*/
  49. BOOL bHighlighting; /* TRUE = The mark will be drawn highlighted.
  50. This attribute is currently only valid
  51. for lines, rectangles, and freehand.*/
  52. BOOL bTransparent; /* TRUE = The mark will be drawn transparent.
  53. If the mark is drawn transparent, then white
  54. pixels are not drawn (ie. there is nothing
  55. drawn for this mark where it contains white
  56. pixels. This attribute is currently only
  57. available for images. This attribute being
  58. set to TRUE will cause significant
  59. performance reduction.*/
  60. UINT uLineSize; /* The size of the line etc. This is passed
  61. onto Windows and is currently in logical
  62. pixels for lines and rectangles.*/
  63. UINT uStartingPoint; /* The shape put on the starting of a
  64. line (arrow, circle, square, etc).
  65. For this release, this must be set to 0.*/
  66. UINT uEndPoint; /* The shape put on the end of a
  67. line (arrow, circle, square, etc).
  68. For this release, this must be set to 0.*/
  69. LOGFONTA lfFont; /* The font information for the text. */
  70. BOOL bMinimizable; /* TRUE = This mark can be minimized
  71. by the user. This flag is only used for
  72. marks that have a minimizable
  73. characteristic such as ATTACH_A_NOTE.*/
  74. UINT Time; /* The time that the mark was first saved.
  75. in seconds from 00:00:00 1-1-1970 (GMT).*/
  76. BOOL bVisible; /* TRUE means that the layer is currently set
  77. to be visible.*/
  78. DWORD dwPermissions; /* Reserved. Must be set to 0x0ff83f */
  79. UINT lReserved[10]; /* Reserved for future expansion.
  80. For this release these must be set to 0.*/
  81. };
  82. // ANNOTATIONHEADER is the first 4 bytes of data in the annotation property.
  83. struct _ANNOTATIONHEADER
  84. {
  85. BYTE reserved[4];
  86. UINT IntIs32Bit;
  87. };
  88. typedef UNALIGNED struct _ANNOTATIONHEADER ANNOTATIONHEADER;
  89. //
  90. // for OiAnoDat
  91. //
  92. struct _ANPOINTS
  93. {
  94. int nMaxPoints;
  95. int nPoints;
  96. POINT ptPoint[1];
  97. };
  98. typedef UNALIGNED struct _ANPOINTS ANPOINTS;
  99. struct _ANROTATE
  100. {
  101. int rotation;
  102. int scale;
  103. int nHRes;
  104. int nVRes;
  105. int nOrigHRes;
  106. int nOrigVRes;
  107. BOOL bReserved1;
  108. BOOL bReserved2;
  109. int nReserved[6];
  110. };
  111. typedef UNALIGNED struct _ANROTATE ANROTATE;
  112. // for OiFilNam
  113. struct _ANNAME
  114. {
  115. char szName[1];
  116. };
  117. typedef UNALIGNED struct _ANNAME ANNAME;
  118. // for OiDIB
  119. struct _ANIMAGE
  120. {
  121. BYTE dibInfo[1]; // standard memory DIB
  122. };
  123. typedef UNALIGNED struct _ANIMAGE ANIMAGE;
  124. // for OiAnText
  125. struct _ANTEXTPRIVDATA
  126. {
  127. int nCurrentOrientation;
  128. UINT uReserved1; // always 1000 when writing, ignore when reading
  129. UINT uCreationScale; // always 72000 divided by the vertical resolution of the base image when writing.
  130. // Used to modify the Attributes.lfFont.lfHeight variable for display
  131. UINT uAnoTextLength; // 64k byte limit, except 255 byte limit for text stamp
  132. char szAnoText[1];
  133. };
  134. typedef UNALIGNED struct _ANTEXTPRIVDATA ANTEXTPRIVDATA;
  135. // These structures provide descriptors for the data read from the annotation property blob.
  136. // The extra data includes the size of each annotation structure
  137. // _NAMEDBLOCK is our in-memory representation
  138. struct _NAMEDBLOCK
  139. {
  140. UINT cbSize;
  141. char szType[9];
  142. BYTE data[1];
  143. };
  144. typedef UNALIGNED struct _NAMEDBLOCK NAMEDBLOCK;
  145. // _FILENAMEDBLOCK is what the namedblock looks like in the file
  146. struct _FILENAMEDBLOCK
  147. {
  148. char szType[8];
  149. UINT cbSize;
  150. BYTE data[1];
  151. };
  152. typedef UNALIGNED struct _FILENAMEDBLOCK FILENAMEDBLOCK;
  153. struct ANNOTATIONDESCRIPTOR
  154. {
  155. UINT cbSize;
  156. ANNOTATIONMARK mark;
  157. BYTE blocks[1];
  158. };
  159. // Define a base class for the various annotation types
  160. class CAnnotation
  161. {
  162. public:
  163. static CAnnotation* CreateAnnotation(UINT type, ULONG uCreationScale);
  164. static CAnnotation* CreateAnnotation(ANNOTATIONDESCRIPTOR *pDescriptor, ULONG uCreationScale);
  165. virtual ~CAnnotation();
  166. // render to the given rectangle in window client coordinates.
  167. virtual void Render(HDC hdc) { return; }
  168. // return the in-file representation of this annotation, as well as its total size
  169. HRESULT GetBlob(SIZE_T &cbSize, LPBYTE pBuffer, LPCSTR szDefaultGroup, LPCSTR szNextIndex);
  170. // return our image coordinates
  171. virtual void GetRect(RECT &rect) {rect = _mark.lrBounds;}
  172. // return the type of Annotation Mark used to change the selection handles for straight lines
  173. virtual UINT GetType() { return _mark.uType; }
  174. // moves the annotation on the page by the specified offset
  175. virtual void Move(SIZE sizeOffset) { OffsetRect(&_mark.lrBounds, sizeOffset.cx, sizeOffset.cy); }
  176. // return true if the object can be resized (true for every thing but freehand lines and images)
  177. virtual BOOL CanResize() { return true; }
  178. // resizes the annotation on the page to the new rect specified
  179. virtual void Resize(RECT rectNewSize);
  180. virtual void Rotate(int nNewImageWidth, int nNewImageHeight, BOOL bClockwise = TRUE);
  181. virtual BOOL HasWidth() { return true; }
  182. virtual UINT GetWidth() { return _mark.uLineSize; }
  183. virtual void SetWidth(UINT nWidth) { _mark.uLineSize = nWidth; }
  184. virtual BOOL HasTransparent() { return true; }
  185. virtual BOOL GetTransparent() { return _mark.bHighlighting; }
  186. virtual void SetTransparent(BOOL bTransparent) { _mark.bHighlighting = bTransparent; }
  187. virtual BOOL HasColor() { return true; }
  188. virtual COLORREF GetColor() { return RGB(_mark.rgbColor1.rgbRed, _mark.rgbColor1.rgbGreen, _mark.rgbColor1.rgbBlue); }
  189. virtual void SetColor(COLORREF crColor) { _mark.rgbColor1.rgbRed = GetRValue(crColor); _mark.rgbColor1.rgbGreen = GetGValue(crColor); _mark.rgbColor1.rgbBlue = GetBValue(crColor); }
  190. virtual BOOL HasFont() { return true; }
  191. virtual void GetFont(LOGFONTA& lfFont) { CopyMemory (&lfFont, &_mark.lfFont, sizeof(lfFont)); }
  192. virtual void GetFont(LOGFONTW& lfFont);
  193. virtual void SetFont(LOGFONTA& lfFont) { CopyMemory (&_mark.lfFont, &lfFont, sizeof(lfFont)); }
  194. virtual void SetFont(LOGFONTW& lfFont);
  195. virtual LONG GetFontHeight(HDC hdc) { return _mark.lfFont.lfHeight; }
  196. virtual COLORREF GetFontColor() { return RGB(_mark.rgbColor1.rgbRed, _mark.rgbColor1.rgbGreen, _mark.rgbColor1.rgbBlue); }
  197. virtual void SetFontColor(COLORREF crColor) { _mark.rgbColor1.rgbRed = GetRValue(crColor); _mark.rgbColor1.rgbGreen = GetGValue(crColor); _mark.rgbColor1.rgbBlue = GetBValue(crColor); }
  198. protected:
  199. CAnnotation(ANNOTATIONDESCRIPTOR *pDescriptor);
  200. NAMEDBLOCK *_FindNamedBlock (LPCSTR szName, ANNOTATIONDESCRIPTOR *pDesc);
  201. virtual HRESULT _WriteBlocks(SIZE_T &cbSize, LPBYTE pBuffer) {return E_NOTIMPL;};
  202. // define helper functions for writing the different named block types
  203. SIZE_T _WriteStringBlock(LPBYTE pBuffer, UINT uType, LPCSTR szName, LPCSTR szData, SIZE_T len);
  204. SIZE_T _WritePointsBlock(LPBYTE pBuffer, UINT uType, const POINT *ppts, int nPoints, int nMaxPoints);
  205. SIZE_T _WriteRotateBlock(LPBYTE pBuffer, UINT uType, const ANROTATE *pRotate);
  206. SIZE_T _WriteTextBlock(LPBYTE pBuffer, UINT uType, int nOrient, UINT uScale, LPCSTR szText, int nMaxLen);
  207. SIZE_T _WriteImageBlock(LPBYTE pBuffer, UINT uType, LPBYTE pDib, SIZE_T cbDib);
  208. ANNOTATIONMARK _mark;
  209. LPSTR _szGroup;
  210. FILENAMEDBLOCK * _pUGroup;
  211. };
  212. class CRectMark : public CAnnotation
  213. {
  214. public:
  215. CRectMark (ANNOTATIONDESCRIPTOR *pDescriptor);
  216. void Render (HDC hdc);
  217. virtual BOOL HasWidth() { return (_mark.uType == MT_HOLLOWRECT); }
  218. virtual BOOL HasFont() { return false; }
  219. };
  220. class CImageMark : public CAnnotation
  221. {
  222. public:
  223. CImageMark (ANNOTATIONDESCRIPTOR *pDescriptor, bool bEmbedded);
  224. ~CImageMark();
  225. void Render (HDC hdc);
  226. HRESULT _WriteBlocks(SIZE_T &cbSize, LPBYTE pBuffer);
  227. virtual BOOL CanResize() { return false; };
  228. virtual void Resize(RECT rectNewSize) { return; };
  229. private:
  230. HANDLE _hDibSection; // cached image for quicker render
  231. LPBYTE _pDib; // the DIB data from the annotation. If NULL, this is a reference mark
  232. ANROTATE _rotation; // rotation info
  233. LPSTR _szFilename; // image file name from the annotation
  234. bool _bRotate; //REVIEW_SDK: Shouldn't there just be a known blank rotation value? If I rotate something 0 degrees shouldn't just not write the rotation record?
  235. SIZE_T _cbDib;
  236. };
  237. class CLineMark : public CAnnotation
  238. {
  239. public:
  240. CLineMark(ANNOTATIONDESCRIPTOR *pDescriptor, bool bFreehand);
  241. ~CLineMark();
  242. void Render(HDC hdc);
  243. void GetRect(RECT &rect);
  244. void SetPoints(POINT* pPoints, int cPoints);
  245. void GetPointsRect(RECT &rect);
  246. virtual void Move(SIZE sizeOffset);
  247. virtual BOOL CanResize() { return (_nPoints == 2); };
  248. virtual void Resize(RECT rectNewSize);
  249. virtual void Rotate(int nNewImageWidth, int nNewImageHeight, BOOL bClockwise = TRUE);
  250. virtual BOOL HasFont() { return false; }
  251. HRESULT _WriteBlocks(SIZE_T &cbSize, LPBYTE pBuffer);
  252. private:
  253. int _iMaxPts;
  254. int _nPoints;
  255. POINT *_points; // 2 points for a straight line, more for a freehand line
  256. };
  257. // all text annotations render and initialize the same way so use a common base class
  258. class CTextAnnotation : public CAnnotation
  259. {
  260. public:
  261. CTextAnnotation(ANNOTATIONDESCRIPTOR *pDescriptor, ULONG uCreationScale, UINT nMaxText=65536, bool _bUseColor2=false);
  262. void Render(HDC hdc);
  263. virtual ~CTextAnnotation();
  264. HRESULT _WriteBlocks(SIZE_T &cbSize, LPBYTE pBuffer);
  265. virtual BOOL HasWidth() { return false; }
  266. virtual BOOL HasTransparent() { return false; }
  267. virtual BOOL HasColor() { return false; }
  268. virtual LONG GetFontHeight(HDC hdc);
  269. virtual int GetOrientation() { return _nCurrentOrientation; }
  270. BSTR GetText();
  271. void SetText(BSTR bstrText);
  272. virtual void Rotate(int nNewImageWidth, int nNewImageHeight, BOOL bClockwise = TRUE);
  273. private:
  274. int _nCurrentOrientation;
  275. UINT _uCreationScale;
  276. UINT _uAnoTextLength;
  277. UINT _nMaxText;
  278. LPSTR _szText;
  279. bool _bUseColor2;
  280. };
  281. class CTypedTextMark : public CTextAnnotation
  282. {
  283. public:
  284. CTypedTextMark(ANNOTATIONDESCRIPTOR *pDescriptor, ULONG uCreationScale);
  285. };
  286. class CFileTextMark : public CTextAnnotation
  287. {
  288. public:
  289. CFileTextMark(ANNOTATIONDESCRIPTOR *pDescriptor, ULONG uCreationScale);
  290. };
  291. class CTextStampMark : public CTextAnnotation
  292. {
  293. public:
  294. CTextStampMark(ANNOTATIONDESCRIPTOR *pDescriptor, ULONG uCreationScale);
  295. };
  296. class CAttachNoteMark : public CTextAnnotation
  297. {
  298. public:
  299. CAttachNoteMark (ANNOTATIONDESCRIPTOR *pDescriptor, ULONG uCreationScale);
  300. virtual BOOL HasColor() { return true; }
  301. virtual COLORREF GetFontColor() { return RGB(_mark.rgbColor2.rgbRed, _mark.rgbColor2.rgbGreen, _mark.rgbColor2.rgbBlue); }
  302. virtual void SetFontColor(COLORREF crColor) { _mark.rgbColor2.rgbRed = GetRValue(crColor); _mark.rgbColor2.rgbGreen = GetGValue(crColor); _mark.rgbColor2.rgbBlue = GetBValue(crColor); }
  303. };
  304. class CAnnotationSet
  305. {
  306. public:
  307. CAnnotationSet ();
  308. ~CAnnotationSet ();
  309. // Draw all the marks
  310. void RenderAllMarks (HDC hdc);
  311. // construct annotation set from raw data
  312. HRESULT BuildAllMarksFromData( LPVOID pData, UINT cbSize, ULONG xDPI, ULONG yDPI );
  313. // Return the annotation at this point in image coordinates
  314. CAnnotation* GetAnnotation (INT_PTR nIndex);
  315. // Add a new annotation to the list. Should only be called from a CAnnotation
  316. BOOL AddAnnotation(CAnnotation *pMark);
  317. // Remove an annotation from the list. Should only be called from a CAnnotation
  318. BOOL RemoveAnnotation (CAnnotation *pMark);
  319. // Save the current set of annotations to the image
  320. HRESULT CommitAnnotations (IShellImageData *pimg);
  321. // Forget our old annotations and load new ones
  322. void SetImageData (IShellImageData *pimg);
  323. INT_PTR GetCount ()
  324. {
  325. if (_dpaMarks)
  326. return DPA_GetPtrCount(_dpaMarks);
  327. return 0;
  328. };
  329. UINT GetCreationScale();
  330. void ClearAllMarks();
  331. private:
  332. HDPA _dpaMarks;
  333. LPBYTE _pDefaultData;
  334. SIZE_T _cbDefaultData;
  335. ULONG _xDPI;
  336. ULONG _yDPI;
  337. static int CALLBACK _FreeMarks(LPVOID pMark, LPVOID pUnused);
  338. void _ClearMarkList ();
  339. void _BuildMarkList (IShellImageData *pimg);
  340. void _BuildListFromData (LPVOID pData, UINT cbSize);
  341. INT _NamedBlockDataSize (UINT uType, LPBYTE pData, LPBYTE pEOD);
  342. LPBYTE _MakeAnnotationBlob ();
  343. HRESULT _SaveAnnotationProperty(IShellImageData *pimg, LPBYTE pData, SIZE_T cbBuffer);
  344. ANNOTATIONDESCRIPTOR *_ReadMark (LPBYTE pMark, LPBYTE *ppNext, LPBYTE pEOD);
  345. };
  346. #endif