WmfGdi.cs 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace WMFConverter.Wmf
  7. {
  8. /// <summary>
  9. /// Windows Metafile - Represents WMF of GDI object.
  10. /// </summary>
  11. public class WmfGdi : Gdi.IGdi
  12. {
  13. #region Local Variables
  14. private byte[] _placeableHeader;
  15. private byte[] _header;
  16. private List<WMFConverter.Gdi.IGdiObject> _objects = new List<WMFConverter.Gdi.IGdiObject>();
  17. private List<byte[]> _records = new List<byte[]>();
  18. #endregion
  19. #region Constructors
  20. /// <summary>
  21. /// Default constructor.
  22. /// </summary>
  23. public WmfGdi()
  24. {
  25. }
  26. #endregion
  27. #region Public Methods
  28. /// <summary>
  29. /// Writes the document in the stream.
  30. /// </summary>
  31. /// <param name="output"></param>
  32. public void Write(System.IO.Stream output)
  33. {
  34. Footer();
  35. if (_placeableHeader != null)
  36. output.Write(_placeableHeader,0,_placeableHeader.Length);
  37. if (_header != null)
  38. output.Write(_header,0,_placeableHeader.Length);
  39. foreach(var item in _records)
  40. output.Write(item,0,_placeableHeader.Length);
  41. output.Flush();
  42. }
  43. /// <summary>
  44. /// Defines header document.
  45. /// </summary>
  46. /// <param name="vsx"></param>
  47. /// <param name="vsy"></param>
  48. /// <param name="vex"></param>
  49. /// <param name="vey"></param>
  50. /// <param name="dpi"></param>
  51. public void PlaceableHeader(int vsx, int vsy, int vex, int vey, int dpi)
  52. {
  53. byte[] record = new byte[22];
  54. int pos = 0;
  55. pos = SetUint32(record, pos, 0x9AC6CDD7);
  56. pos = SetInt16(record, pos, 0x0000);
  57. pos = SetInt16(record, pos, vsx);
  58. pos = SetInt16(record, pos, vsy);
  59. pos = SetInt16(record, pos, vex);
  60. pos = SetInt16(record, pos, vey);
  61. pos = SetUint16(record, pos, dpi);
  62. pos = SetUint32(record, pos, 0x00000000);
  63. int checksum = 0;
  64. for (int i = 0; i < record.Length - 2; i += 2)
  65. checksum ^= (0xFF & record[i]) | ((0xFF & record[i + 1]) << 8);
  66. pos = SetUint16(record, pos, checksum);
  67. _placeableHeader = record;
  68. }
  69. /// <summary>
  70. /// Defines header document.
  71. /// </summary>
  72. public void Header()
  73. {
  74. byte[] record = new byte[18];
  75. int pos = 0;
  76. pos = SetUint16(record, pos, 0x0001);
  77. pos = SetUint16(record, pos, 0x0009);
  78. pos = SetUint16(record, pos, 0x0300);
  79. pos = SetUint32(record, pos, 0x0000); // dummy size
  80. pos = SetUint16(record, pos, 0x0000); // dummy noObjects
  81. pos = SetUint32(record, pos, 0x0000); // dummy maxRecords
  82. pos = SetUint16(record, pos, 0x0000);
  83. _header = record;
  84. }
  85. /// <summary>
  86. /// Replaces entries in the specified logical palette.
  87. /// </summary>
  88. /// <param name="palette"></param>
  89. /// <param name="startIndex"></param>
  90. /// <param name="entries"></param>
  91. public void AnimatePalette(WMFConverter.Gdi.IGdiPalette palette, int startIndex, int[] entries)
  92. {
  93. byte[] record = new byte[22];
  94. int pos = 0;
  95. pos = SetUint32(record, pos, record.Length/2);
  96. pos = SetUint16(record, pos, (int)WmfConstants.RECORD_ANIMATE_PALETTE);
  97. pos = SetUint16(record, pos, entries.Length);
  98. pos = SetUint16(record, pos, startIndex);
  99. pos = SetUint16(record, pos, ((WmfPalette)palette).Id);
  100. for (int i = 0; i < entries.Length; i++)
  101. pos = SetInt32(record, pos, entries[i]);
  102. _records.Add(record);
  103. }
  104. /// <summary>
  105. /// Draws an elliptical arc.
  106. /// </summary>
  107. /// <param name="sxr"></param>
  108. /// <param name="syr"></param>
  109. /// <param name="exr"></param>
  110. /// <param name="eyr"></param>
  111. /// <param name="sxa"></param>
  112. /// <param name="sya"></param>
  113. /// <param name="exa"></param>
  114. /// <param name="eya"></param>
  115. public void Arc(int sxr, int syr, int exr, int eyr, int sxa, int sya, int exa, int eya)
  116. {
  117. byte[] record = new byte[22];
  118. int pos = 0;
  119. pos = SetUint32(record, pos, record.Length/2);
  120. pos = SetUint16(record, pos, (int)WmfConstants.RECORD_ARC);
  121. pos = SetInt16(record, pos, eya);
  122. pos = SetInt16(record, pos, exa);
  123. pos = SetInt16(record, pos, sya);
  124. pos = SetInt16(record, pos, sxa);
  125. pos = SetInt16(record, pos, eyr);
  126. pos = SetInt16(record, pos, exr);
  127. pos = SetInt16(record, pos, syr);
  128. pos = SetInt16(record, pos, sxr);
  129. _records.Add(record);
  130. }
  131. /// <summary>
  132. /// Execute a bit-block transfer of the color data corresponding to a rectangle of pixels from the specified source device context into a destination device context.
  133. /// </summary>
  134. /// <param name="image"></param>
  135. /// <param name="dx"></param>
  136. /// <param name="dy"></param>
  137. /// <param name="dw"></param>
  138. /// <param name="dh"></param>
  139. /// <param name="sx"></param>
  140. /// <param name="sy"></param>
  141. /// <param name="rop"></param>
  142. public void BitBlt(byte[] image, int dx, int dy, int dw, int dh, int sx, int sy, long rop)
  143. {
  144. byte[] record = new byte[22 + (image.Length + image.Length%2)];
  145. int pos = 0;
  146. pos = SetUint32(record, pos, record.Length/2);
  147. pos = SetUint16(record, pos, (int)WmfConstants.RECORD_BIT_BLT);
  148. pos = SetUint32(record, pos, rop);
  149. pos = SetInt16(record, pos, sy);
  150. pos = SetInt16(record, pos, sx);
  151. pos = SetInt16(record, pos, dw);
  152. pos = SetInt16(record, pos, dh);
  153. pos = SetInt16(record, pos, dy);
  154. pos = SetInt16(record, pos, dx);
  155. pos = SetBytes(record, pos, image);
  156. if (image.Length%2 == 1)
  157. pos = SetByte(record, pos, 0);
  158. _records.Add(record);
  159. }
  160. /// <summary>
  161. /// Draws a chord (a region bounded by the intersection of an ellipse and a line segment, called a secant).
  162. /// The chord is outlined by using the current pen and filled by using the current brush.
  163. /// </summary>
  164. /// <param name="sxr"></param>
  165. /// <param name="syr"></param>
  166. /// <param name="exr"></param>
  167. /// <param name="eyr"></param>
  168. /// <param name="sxa"></param>
  169. /// <param name="sya"></param>
  170. /// <param name="exa"></param>
  171. /// <param name="eya"></param>
  172. public void Chord(int sxr, int syr, int exr, int eyr, int sxa, int sya, int exa, int eya)
  173. {
  174. byte[] record = new byte[22];
  175. int pos = 0;
  176. pos = SetUint32(record, pos, record.Length/2);
  177. pos = SetUint16(record, pos, (int)WmfConstants.RECORD_CHORD);
  178. pos = SetInt16(record, pos, eya);
  179. pos = SetInt16(record, pos, exa);
  180. pos = SetInt16(record, pos, sya);
  181. pos = SetInt16(record, pos, sxa);
  182. pos = SetInt16(record, pos, eyr);
  183. pos = SetInt16(record, pos, exr);
  184. pos = SetInt16(record, pos, syr);
  185. pos = SetInt16(record, pos, sxr);
  186. _records.Add(record);
  187. }
  188. /// <summary>
  189. /// Creates a logical brush that has the specified style, color, and pattern.
  190. /// </summary>
  191. /// <param name="style"></param>
  192. /// <param name="color"></param>
  193. /// <param name="hatch"></param>
  194. /// <returns></returns>
  195. public WMFConverter.Gdi.IGdiBrush CreateBrushIndirect(int style, int color, int hatch)
  196. {
  197. byte[] record = new byte[14];
  198. int pos = 0;
  199. pos = SetUint32(record, pos, record.Length/2);
  200. pos = SetUint16(record, pos, (int)WmfConstants.RECORD_CREATE_BRUSH_INDIRECT);
  201. pos = SetUint16(record, pos, style);
  202. pos = SetInt32(record, pos, color);
  203. pos = SetUint16(record, pos, hatch);
  204. _records.Add(record);
  205. WmfBrush brush = new WmfBrush(_objects.Count(), style, color, hatch);
  206. _objects.Add(brush);
  207. return brush;
  208. }
  209. /// <summary>
  210. /// Creates a logical font that has the specified characteristics.
  211. /// The font can subsequently be selected as the current font for any device context.
  212. /// </summary>
  213. /// <param name="height"></param>
  214. /// <param name="width"></param>
  215. /// <param name="escapement"></param>
  216. /// <param name="orientation"></param>
  217. /// <param name="weight"></param>
  218. /// <param name="italic"></param>
  219. /// <param name="underline"></param>
  220. /// <param name="strikeout"></param>
  221. /// <param name="charset"></param>
  222. /// <param name="outPrecision"></param>
  223. /// <param name="clipPrecision"></param>
  224. /// <param name="quality"></param>
  225. /// <param name="pitchAndFamily"></param>
  226. /// <param name="faceName"></param>
  227. /// <returns></returns>
  228. public WMFConverter.Gdi.IGdiFont CreateFontIndirect(int height, int width, int escapement,
  229. int orientation, int weight, bool italic, bool underline,
  230. bool strikeout, int charset, int outPrecision,
  231. int clipPrecision, int quality, int pitchAndFamily, byte[] faceName)
  232. {
  233. byte[] record = new byte[24 + (faceName.Length + faceName.Length%2)];
  234. int pos = 0;
  235. pos = SetUint32(record, pos, record.Length/2);
  236. pos = SetUint16(record, pos, (int)WmfConstants.RECORD_CREATE_FONT_INDIRECT);
  237. pos = SetInt16(record, pos, height);
  238. pos = SetInt16(record, pos, width);
  239. pos = SetInt16(record, pos, escapement);
  240. pos = SetInt16(record, pos, orientation);
  241. pos = SetInt16(record, pos, weight);
  242. pos = SetByte(record, pos, (italic) ? 0x01 : 0x00);
  243. pos = SetByte(record, pos, (underline) ? 0x01 : 0x00);
  244. pos = SetByte(record, pos, (strikeout) ? 0x01 : 0x00);
  245. pos = SetByte(record, pos, charset);
  246. pos = SetByte(record, pos, outPrecision);
  247. pos = SetByte(record, pos, clipPrecision);
  248. pos = SetByte(record, pos, quality);
  249. pos = SetByte(record, pos, pitchAndFamily);
  250. pos = SetBytes(record, pos, faceName);
  251. if (faceName.Length%2 == 1)
  252. pos = SetByte(record, pos, 0);
  253. _records.Add(record);
  254. WmfFont font = new WmfFont(_objects.Count(), height, width, escapement,
  255. orientation, weight, italic, underline, strikeout, charset, outPrecision,
  256. clipPrecision, quality, pitchAndFamily, faceName);
  257. _objects.Add(font);
  258. return font;
  259. }
  260. /// <summary>
  261. /// Creates a logical palette.
  262. /// </summary>
  263. /// <param name="version"></param>
  264. /// <param name="entries"></param>
  265. /// <returns></returns>
  266. public WMFConverter.Gdi.IGdiPalette CreatePalette(int version, int[] entries)
  267. {
  268. byte[] record = new byte[10 + entries.Length * 4];
  269. int pos = 0;
  270. pos = SetUint32(record, pos, record.Length/2);
  271. pos = SetUint16(record, pos, (int)WmfConstants.RECORD_CREATE_PALETTE);
  272. pos = SetUint16(record, pos, version);
  273. pos = SetUint16(record, pos, entries.Length);
  274. for (int i = 0; i < entries.Length; i++)
  275. pos = SetInt32(record, pos, entries[i]);
  276. _records.Add(record);
  277. WMFConverter.Gdi.IGdiPalette palette = new WmfPalette(_objects.Count(), version, entries);
  278. _objects.Add(palette);
  279. return palette;
  280. }
  281. /// <summary>
  282. /// Creates a logical brush with the specified bitmap pattern.
  283. /// The bitmap can be a DIB section bitmap, which is created by the CreateDIBSection function, or it can be a device-dependent bitmap.
  284. /// </summary>
  285. /// <param name="image"></param>
  286. /// <returns></returns>
  287. public WMFConverter.Gdi.IGdiPatternBrush CreatePatternBrush(byte[] image)
  288. {
  289. byte[] record = new byte[6 + (image.Length + image.Length%2)];
  290. int pos = 0;
  291. pos = SetUint32(record, pos, record.Length/2);
  292. pos = SetUint16(record, pos, (int)WmfConstants.RECORD_CREATE_PATTERN_BRUSH);
  293. pos = SetBytes(record, pos, image);
  294. if (image.Length%2 == 1) pos = SetByte(record, pos, 0);
  295. _records.Add(record);
  296. WMFConverter.Gdi.IGdiPatternBrush brush = new WmfPatternBrush(_objects.Count(), image);
  297. _objects.Add(brush);
  298. return brush;
  299. }
  300. /// <summary>
  301. /// Creates a logical cosmetic pen that has the style, width, and color specified in a structure.
  302. /// </summary>
  303. /// <param name="style"></param>
  304. /// <param name="width"></param>
  305. /// <param name="color"></param>
  306. /// <returns></returns>
  307. public WMFConverter.Gdi.IGdiPen CreatePenIndirect(int style, int width, int color)
  308. {
  309. byte[] record = new byte[16];
  310. int pos = 0;
  311. pos = SetUint32(record, pos, record.Length/2);
  312. pos = SetUint16(record, pos, (int)WmfConstants.RECORD_CREATE_PEN_INDIRECT);
  313. pos = SetUint16(record, pos, style);
  314. pos = SetInt16(record, pos, width);
  315. pos = SetInt16(record, pos, 0);
  316. pos = SetInt32(record, pos, color);
  317. _records.Add(record);
  318. WmfPen pen = new WmfPen(_objects.Count(), style, width, color);
  319. _objects.Add(pen);
  320. return pen;
  321. }
  322. /// <summary>
  323. /// Creates a rectangular region.
  324. /// </summary>
  325. /// <param name="left"></param>
  326. /// <param name="top"></param>
  327. /// <param name="right"></param>
  328. /// <param name="bottom"></param>
  329. /// <returns></returns>
  330. public WMFConverter.Gdi.IGdiRegion CreateRectRgn(int left, int top, int right, int bottom)
  331. {
  332. byte[] record = new byte[14];
  333. int pos = 0;
  334. pos = SetUint32(record, pos, record.Length/2);
  335. pos = SetUint16(record, pos, (int)WmfConstants.RECORD_CREATE_RECT_RGN);
  336. pos = SetInt16(record, pos, bottom);
  337. pos = SetInt16(record, pos, right);
  338. pos = SetInt16(record, pos, top);
  339. pos = SetInt16(record, pos, left);
  340. _records.Add(record);
  341. WmfRectRegion rgn = new WmfRectRegion(_objects.Count(), left, top, right, bottom);
  342. _objects.Add(rgn);
  343. return rgn;
  344. }
  345. /// <summary>
  346. /// Deletes a logical pen, brush, font, bitmap, region, or palette, freeing all system resources associated with the object.
  347. /// After the object is deleted, the specified handle is no longer valid.
  348. /// </summary>
  349. /// <param name="obj"></param>
  350. public void DeleteObject(WMFConverter.Gdi.IGdiObject obj)
  351. {
  352. byte[] record = new byte[8];
  353. int pos = 0;
  354. pos = SetUint32(record, pos, record.Length/2);
  355. pos = SetUint16(record, pos, (int)WmfConstants.RECORD_DELETE_OBJECT);
  356. pos = SetUint16(record, pos, ((WmfObject)obj).Id);
  357. _records.Add(record);
  358. _objects.Remove((WmfObject)obj);
  359. }
  360. /// <summary>
  361. /// Function performs a bit-block transfer of the color data corresponding to a rectangle of pixels from the specified source device context into a destination device context.
  362. /// </summary>
  363. /// <param name="image"></param>
  364. /// <param name="dx"></param>
  365. /// <param name="dy"></param>
  366. /// <param name="dw"></param>
  367. /// <param name="dh"></param>
  368. /// <param name="sx"></param>
  369. /// <param name="sy"></param>
  370. /// <param name="rop"></param>
  371. public void DibBitBlt(byte[] image, int dx, int dy, int dw, int dh, int sx, int sy, long rop)
  372. {
  373. byte[] record = new byte[22 + (image.Length + image.Length%2)];
  374. int pos = 0;
  375. pos = SetUint32(record, pos, record.Length/2);
  376. pos = SetUint16(record, pos, (int)WmfConstants.RECORD_DIB_BIT_BLT);
  377. pos = SetUint32(record, pos, rop);
  378. pos = SetInt16(record, pos, sy);
  379. pos = SetInt16(record, pos, sx);
  380. pos = SetInt16(record, pos, dw);
  381. pos = SetInt16(record, pos, dh);
  382. pos = SetInt16(record, pos, dy);
  383. pos = SetInt16(record, pos, dx);
  384. pos = SetBytes(record, pos, image);
  385. if (image.Length%2 == 1)
  386. pos = SetByte(record, pos, 0);
  387. _records.Add(record);
  388. }
  389. /// <summary>
  390. /// Create Dib Pattern Brush object instance.
  391. /// </summary>
  392. /// <param name="image"></param>
  393. /// <param name="usage"></param>
  394. /// <returns></returns>
  395. public WMFConverter.Gdi.IGdiPatternBrush DibCreatePatternBrush(byte[] image, int usage)
  396. {
  397. byte[] record = new byte[10 + (image.Length + image.Length%2)];
  398. int pos = 0;
  399. pos = SetUint32(record, pos, record.Length/2);
  400. pos = SetUint16(record, pos, (int)WmfConstants.RECORD_DIB_CREATE_PATTERN_BRUSH);
  401. pos = SetInt32(record, pos, usage);
  402. pos = SetBytes(record, pos, image);
  403. if (image.Length%2 == 1)
  404. pos = SetByte(record, pos, 0);
  405. _records.Add(record);
  406. // TODO usage
  407. WMFConverter.Gdi.IGdiPatternBrush brush = new WmfPatternBrush(_objects.Count(), image);
  408. _objects.Add(brush);
  409. return brush;
  410. }
  411. /// <summary>
  412. /// Copies a bitmap from a source rectangle into a destination rectangle, stretching or compressing the bitmap to fit the dimensions of the destination rectangle, if necessary.
  413. /// The system stretches or compresses the bitmap according to the stretching mode currently set in the destination device context.
  414. /// </summary>
  415. /// <param name="image"></param>
  416. /// <param name="dx"></param>
  417. /// <param name="dy"></param>
  418. /// <param name="dw"></param>
  419. /// <param name="dh"></param>
  420. /// <param name="sx"></param>
  421. /// <param name="sy"></param>
  422. /// <param name="sw"></param>
  423. /// <param name="sh"></param>
  424. /// <param name="rop"></param>
  425. public void DibStretchBlt(byte[] image, int dx, int dy, int dw, int dh,
  426. int sx, int sy, int sw, int sh, long rop)
  427. {
  428. byte[] record = new byte[26 + (image.Length + image.Length%2)];
  429. int pos = 0;
  430. pos = SetUint32(record, pos, record.Length/2);
  431. pos = SetUint16(record, pos, (int)WmfConstants.RECORD_DIB_STRETCH_BLT);
  432. pos = SetUint32(record, pos, rop);
  433. pos = SetInt16(record, pos, sh);
  434. pos = SetInt16(record, pos, sw);
  435. pos = SetInt16(record, pos, sy);
  436. pos = SetInt16(record, pos, sx);
  437. pos = SetInt16(record, pos, dw);
  438. pos = SetInt16(record, pos, dh);
  439. pos = SetInt16(record, pos, dy);
  440. pos = SetInt16(record, pos, dx);
  441. pos = SetBytes(record, pos, image);
  442. if (image.Length%2 == 1)
  443. pos = SetByte(record, pos, 0);
  444. _records.Add(record);
  445. }
  446. /// <summary>
  447. /// Draws an ellipse.
  448. /// The center of the ellipse is the center of the specified bounding rectangle.
  449. /// The ellipse is outlined by using the current pen and is filled by using the current brush.
  450. /// </summary>
  451. /// <param name="sx"></param>
  452. /// <param name="sy"></param>
  453. /// <param name="ex"></param>
  454. /// <param name="ey"></param>
  455. public void Ellipse(int sx, int sy, int ex, int ey)
  456. {
  457. byte[] record = new byte[14];
  458. int pos = 0;
  459. pos = SetUint32(record, pos, record.Length/2);
  460. pos = SetUint16(record, pos, (int)WmfConstants.RECORD_ELLIPSE);
  461. pos = SetInt16(record, pos, ey);
  462. pos = SetInt16(record, pos, ex);
  463. pos = SetInt16(record, pos, sy);
  464. pos = SetInt16(record, pos, sx);
  465. _records.Add(record);
  466. }
  467. /// <summary>
  468. /// Enables an application to access the system-defined device capabilities that are not available through GDI.
  469. /// Escape calls made by an application are translated and sent to the driver.
  470. /// </summary>
  471. /// <param name="data"></param>
  472. public void Escape(byte[] data)
  473. {
  474. byte[] record = new byte[10 + (data.Length + data.Length%2)];
  475. int pos = 0;
  476. pos = SetUint32(record, pos, record.Length/2);
  477. pos = SetUint16(record, pos, (int)WmfConstants.RECORD_ESCAPE);
  478. pos = SetBytes(record, pos, data);
  479. if (data.Length%2 == 1)
  480. pos = SetByte(record, pos, 0);
  481. _records.Add(record);
  482. }
  483. /// <summary>
  484. /// Creates a new clipping region that consists of the existing clipping region minus the specified rectangle.
  485. /// </summary>
  486. /// <param name="left"></param>
  487. /// <param name="top"></param>
  488. /// <param name="right"></param>
  489. /// <param name="bottom"></param>
  490. /// <returns></returns>
  491. public int ExcludeClipRect(int left, int top, int right, int bottom)
  492. {
  493. byte[] record = new byte[14];
  494. int pos = 0;
  495. pos = SetUint32(record, pos, record.Length/2);
  496. pos = SetUint16(record, pos, (int)WmfConstants.RECORD_EXCLUDE_CLIP_RECT);
  497. pos = SetInt16(record, pos, bottom);
  498. pos = SetInt16(record, pos, right);
  499. pos = SetInt16(record, pos, top);
  500. pos = SetInt16(record, pos, left);
  501. _records.Add(record);
  502. // TODO
  503. return (int)WMFConverter.Gdi.RegionEnum.COMPLEXREGION;
  504. }
  505. /// <summary>
  506. /// Fills an area of the display surface with the current brush.
  507. /// </summary>
  508. /// <param name="x"></param>
  509. /// <param name="y"></param>
  510. /// <param name="color"></param>
  511. /// <param name="type"></param>
  512. public void ExtFloodFill(int x, int y, int color, int type)
  513. {
  514. byte[] record = new byte[16];
  515. int pos = 0;
  516. pos = SetUint32(record, pos, record.Length/2);
  517. pos = SetUint16(record, pos, (int)WmfConstants.RECORD_EXT_FLOOD_FILL);
  518. pos = SetUint16(record, pos, type);
  519. pos = SetInt32(record, pos, color);
  520. pos = SetInt16(record, pos, y);
  521. pos = SetInt16(record, pos, x);
  522. _records.Add(record);
  523. }
  524. /// <summary>
  525. /// Draws text using the currently selected font, background color, and text color.
  526. /// You can optionally provide dimensions to be used for clipping, opaquing, or both.
  527. /// </summary>
  528. /// <param name="x"></param>
  529. /// <param name="y"></param>
  530. /// <param name="options"></param>
  531. /// <param name="rect"></param>
  532. /// <param name="text"></param>
  533. /// <param name="lpdx"></param>
  534. public void ExtTextOut(int x, int y, int options, int[] rect, byte[] text, int[] lpdx)
  535. {
  536. if (rect != null && rect.Length != 4)
  537. throw new ArgumentException("rect must be 4 length.");
  538. byte[] record = new byte[14 + ((rect != null) ? 8 : 0) + (text.Length + text.Length%2) + (lpdx.Length * 2)];
  539. int pos = 0;
  540. pos = SetUint32(record, pos, record.Length/2);
  541. pos = SetUint16(record, pos, (int)WmfConstants.RECORD_EXT_TEXT_OUT);
  542. pos = SetInt16(record, pos, y);
  543. pos = SetInt16(record, pos, x);
  544. pos = SetInt16(record, pos, text.Length);
  545. pos = SetInt16(record, pos, options);
  546. if (rect != null)
  547. {
  548. pos = SetInt16(record, pos, rect[0]);
  549. pos = SetInt16(record, pos, rect[1]);
  550. pos = SetInt16(record, pos, rect[2]);
  551. pos = SetInt16(record, pos, rect[3]);
  552. }
  553. pos = SetBytes(record, pos, text);
  554. if (text.Length%2 == 1) pos = SetByte(record, pos, 0);
  555. for (int i = 0; i < lpdx.Length; i++)
  556. pos = SetInt16(record, pos, lpdx[i]);
  557. _records.Add(record);
  558. }
  559. /// <summary>
  560. /// Fills a region by using the specified brush.
  561. /// </summary>
  562. /// <param name="rgn"></param>
  563. /// <param name="brush"></param>
  564. public void FillRgn(WMFConverter.Gdi.IGdiRegion rgn, WMFConverter.Gdi.IGdiBrush brush)
  565. {
  566. byte[] record = new byte[10];
  567. int pos = 0;
  568. pos = SetUint32(record, pos, record.Length/2);
  569. pos = SetUint16(record, pos, (int)WmfConstants.RECORD_FLOOD_FILL);
  570. pos = SetUint16(record, pos, ((WmfBrush)brush).Id);
  571. pos = SetUint16(record, pos, ((WmfRegion)rgn).Id);
  572. _records.Add(record);
  573. }
  574. /// <summary>
  575. /// Fills an area of the display surface with the current brush.
  576. /// The area is assumed to be bounded as specified by the crFill parameter.
  577. /// </summary>
  578. /// <param name="x"></param>
  579. /// <param name="y"></param>
  580. /// <param name="color"></param>
  581. public void FloodFill(int x, int y, int color)
  582. {
  583. byte[] record = new byte[16];
  584. int pos = 0;
  585. pos = SetUint32(record, pos, record.Length/2);
  586. pos = SetUint16(record, pos, (int)WmfConstants.RECORD_FLOOD_FILL);
  587. pos = SetInt32(record, pos, color);
  588. pos = SetInt16(record, pos, y);
  589. pos = SetInt16(record, pos, x);
  590. _records.Add(record);
  591. }
  592. /// <summary>
  593. /// Draws a border around the specified region by using the specified brush.
  594. /// </summary>
  595. /// <param name="rgn"></param>
  596. /// <param name="brush"></param>
  597. /// <param name="w"></param>
  598. /// <param name="h"></param>
  599. public void FrameRgn(WMFConverter.Gdi.IGdiRegion rgn, WMFConverter.Gdi.IGdiBrush brush, int w, int h)
  600. {
  601. byte[] record = new byte[14];
  602. int pos = 0;
  603. pos = SetUint32(record, pos, record.Length/2);
  604. pos = SetUint16(record, pos, (int)WmfConstants.RECORD_FRAME_RGN);
  605. pos = SetInt16(record, pos, h);
  606. pos = SetInt16(record, pos, w);
  607. pos = SetUint16(record, pos, ((WmfBrush)brush).Id);
  608. pos = SetUint16(record, pos, ((WmfRegion)rgn).Id);
  609. _records.Add(record);
  610. }
  611. /// <summary>
  612. /// Creates a new clipping region from the intersection of the current clipping region and the specified rectangle.
  613. /// </summary>
  614. /// <param name="left"></param>
  615. /// <param name="top"></param>
  616. /// <param name="right"></param>
  617. /// <param name="bottom"></param>
  618. public void IntersectClipRect(int left, int top, int right, int bottom)
  619. {
  620. byte[] record = new byte[16];
  621. int pos = 0;
  622. pos = SetUint32(record, pos, record.Length/2);
  623. pos = SetUint16(record, pos, (int)WmfConstants.RECORD_INTERSECT_CLIP_RECT);
  624. pos = SetInt16(record, pos, bottom);
  625. pos = SetInt16(record, pos, right);
  626. pos = SetInt16(record, pos, top);
  627. pos = SetInt16(record, pos, left);
  628. _records.Add(record);
  629. }
  630. /// <summary>
  631. /// Inverts the colors in the specified region.
  632. /// </summary>
  633. /// <param name="rgn"></param>
  634. public void InvertRgn(WMFConverter.Gdi.IGdiRegion rgn)
  635. {
  636. byte[] record = new byte[8];
  637. int pos = 0;
  638. pos = SetUint32(record, pos, record.Length/2);
  639. pos = SetUint16(record, pos, (int)WmfConstants.RECORD_INVERT_RGN);
  640. pos = SetUint16(record, pos, ((WmfRegion)rgn).Id);
  641. _records.Add(record);
  642. }
  643. /// <summary>
  644. /// Draws a line from the current position up to, but not including, the specified point.
  645. /// </summary>
  646. /// <param name="ex"></param>
  647. /// <param name="ey"></param>
  648. public void LineTo(int ex, int ey)
  649. {
  650. byte[] record = new byte[10];
  651. int pos = 0;
  652. pos = SetUint32(record, pos, record.Length/2);
  653. pos = SetUint16(record, pos, (int)WmfConstants.RECORD_LINE_TO);
  654. pos = SetInt16(record, pos, ey);
  655. pos = SetInt16(record, pos, ex);
  656. _records.Add(record);
  657. }
  658. /// <summary>
  659. /// Updates the current position to the specified point and optionally returns the previous position.
  660. /// </summary>
  661. /// <param name="x"></param>
  662. /// <param name="y"></param>
  663. /// <param name="old"></param>
  664. public void MoveToEx(int x, int y, WMFConverter.Gdi.Point old)
  665. {
  666. byte[] record = new byte[10];
  667. int pos = 0;
  668. pos = SetUint32(record, pos, record.Length/2);
  669. pos = SetUint16(record, pos, (int)WmfConstants.RECORD_MOVE_TO_EX);
  670. pos = SetInt16(record, pos, y);
  671. pos = SetInt16(record, pos, x);
  672. //TODO old
  673. _records.Add(record);
  674. }
  675. /// <summary>
  676. /// Moves the clipping region of a device context by the specified offsets.
  677. /// </summary>
  678. /// <param name="x"></param>
  679. /// <param name="y"></param>
  680. public void OffsetClipRgn(int x, int y)
  681. {
  682. byte[] record = new byte[10];
  683. int pos = 0;
  684. pos = SetUint32(record, pos, record.Length/2);
  685. pos = SetUint16(record, pos, (int)WmfConstants.RECORD_OFFSET_CLIP_RGN);
  686. pos = SetInt16(record, pos, y);
  687. pos = SetInt16(record, pos, x);
  688. _records.Add(record);
  689. }
  690. /// <summary>
  691. /// Modifies the viewport origin for a device context using the specified horizontal and vertical offsets.
  692. /// </summary>
  693. /// <param name="x"></param>
  694. /// <param name="y"></param>
  695. /// <param name="point"></param>
  696. public void OffsetViewportOrgEx(int x, int y, WMFConverter.Gdi.Point point)
  697. {
  698. byte[] record = new byte[10];
  699. int pos = 0;
  700. pos = SetUint32(record, pos, record.Length/2);
  701. pos = SetUint16(record, pos, (int)WmfConstants.RECORD_OFFSET_VIEWPORT_ORG_EX);
  702. pos = SetInt16(record, pos, y);
  703. pos = SetInt16(record, pos, x);
  704. // TODO
  705. _records.Add(record);
  706. }
  707. /// <summary>
  708. /// Modifies the window origin for a device context using the specified horizontal and vertical offsets.
  709. /// </summary>
  710. /// <param name="x"></param>
  711. /// <param name="y"></param>
  712. /// <param name="point"></param>
  713. public void OffsetWindowOrgEx(int x, int y, WMFConverter.Gdi.Point point)
  714. {
  715. byte[] record = new byte[10];
  716. int pos = 0;
  717. pos = SetUint32(record, pos, record.Length/2);
  718. pos = SetUint16(record, pos, (int)WmfConstants.RECORD_OFFSET_WINDOW_ORG_EX);
  719. pos = SetInt16(record, pos, y);
  720. pos = SetInt16(record, pos, x);
  721. // TODO
  722. _records.Add(record);
  723. }
  724. /// <summary>
  725. /// Paints the specified region by using the brush currently selected into the device context.
  726. /// </summary>
  727. /// <param name="rgn"></param>
  728. public void PaintRgn(WMFConverter.Gdi.IGdiRegion rgn)
  729. {
  730. byte[] record = new byte[8];
  731. int pos = 0;
  732. pos = SetUint32(record, pos, record.Length/2);
  733. pos = SetUint16(record, pos, (int)WmfConstants.RECORD_PAINT_RGN);
  734. pos = SetUint16(record, pos, ((WmfRegion)rgn).Id);
  735. _records.Add(record);
  736. }
  737. /// <summary>
  738. /// Paints the specified rectangle using the brush that is currently selected into the specified device context.
  739. /// The brush color and the surface color or colors are combined by using the specified raster operation.
  740. /// </summary>
  741. /// <param name="x"></param>
  742. /// <param name="y"></param>
  743. /// <param name="width"></param>
  744. /// <param name="height"></param>
  745. /// <param name="rop"></param>
  746. public void PatBlt(int x, int y, int width, int height, long rop)
  747. {
  748. byte[] record = new byte[18];
  749. int pos = 0;
  750. pos = SetUint32(record, pos, record.Length/2);
  751. pos = SetUint16(record, pos, (int)WmfConstants.RECORD_PAT_BLT);
  752. pos = SetUint32(record, pos, rop);
  753. pos = SetInt16(record, pos, height);
  754. pos = SetInt16(record, pos, width);
  755. pos = SetInt16(record, pos, y);
  756. pos = SetInt16(record, pos, x);
  757. _records.Add(record);
  758. }
  759. /// <summary>
  760. /// Draws a pie-shaped wedge bounded by the intersection of an ellipse and two radials.
  761. /// The pie is outlined by using the current pen and filled by using the current brush.
  762. /// </summary>
  763. /// <param name="sx"></param>
  764. /// <param name="sy"></param>
  765. /// <param name="ex"></param>
  766. /// <param name="ey"></param>
  767. /// <param name="sxr"></param>
  768. /// <param name="syr"></param>
  769. /// <param name="exr"></param>
  770. /// <param name="eyr"></param>
  771. public void Pie(int sx, int sy, int ex, int ey, int sxr, int syr, int exr, int eyr)
  772. {
  773. byte[] record = new byte[22];
  774. int pos = 0;
  775. pos = SetUint32(record, pos, record.Length/2);
  776. pos = SetUint16(record, pos, (int)WmfConstants.RECORD_PIE);
  777. pos = SetInt16(record, pos, eyr);
  778. pos = SetInt16(record, pos, exr);
  779. pos = SetInt16(record, pos, syr);
  780. pos = SetInt16(record, pos, sxr);
  781. pos = SetInt16(record, pos, ey);
  782. pos = SetInt16(record, pos, ex);
  783. pos = SetInt16(record, pos, sy);
  784. pos = SetInt16(record, pos, sx);
  785. _records.Add(record);
  786. }
  787. /// <summary>
  788. /// Draws a polygon consisting of two or more vertices connected by straight lines.
  789. /// The polygon is outlined by using the current pen and filled by using the current brush and polygon fill mode.
  790. /// </summary>
  791. /// <param name="points"></param>
  792. public void Polygon(WMFConverter.Gdi.Point[] points)
  793. {
  794. byte[] record = new byte[8 + points.Length * 4];
  795. int pos = 0;
  796. pos = SetUint32(record, pos, record.Length/2);
  797. pos = SetUint16(record, pos, (int)WmfConstants.RECORD_POLYGON);
  798. pos = SetInt16(record, pos, points.Length);
  799. for (int i = 0; i < points.Length; i++)
  800. {
  801. pos = SetInt16(record, pos, points[i].X);
  802. pos = SetInt16(record, pos, points[i].Y);
  803. }
  804. _records.Add(record);
  805. }
  806. /// <summary>
  807. /// Element is an SVG basic shape that creates straight lines connecting several points.
  808. /// Typically a polyline is used to create open shapes as the last point doesn't have to be connected to the first point.
  809. /// </summary>
  810. /// <param name="points"></param>
  811. public void Polyline(WMFConverter.Gdi.Point[] points)
  812. {
  813. byte[] record = new byte[8 + points.Length * 4];
  814. int pos = 0;
  815. pos = SetUint32(record, pos, record.Length/2);
  816. pos = SetUint16(record, pos, (int)WmfConstants.RECORD_POLYLINE);
  817. pos = SetInt16(record, pos, points.Length);
  818. for (int i = 0; i < points.Length; i++)
  819. {
  820. pos = SetInt16(record, pos, points[i].X);
  821. pos = SetInt16(record, pos, points[i].Y);
  822. }
  823. _records.Add(record);
  824. }
  825. /// <summary>
  826. /// Draws a series of closed polygons.
  827. /// Each polygon is outlined by using the current pen and filled by using the current brush and polygon fill mode.
  828. /// The polygons drawn by this function can overlap.
  829. /// </summary>
  830. /// <param name="points"></param>
  831. public void PolyPolygon(WMFConverter.Gdi.Point[][] points)
  832. {
  833. int length = 8;
  834. for (int i = 0; i < points.Length; i++)
  835. length += 2 + points[i].Length * 4;
  836. byte[] record = new byte[length];
  837. int pos = 0;
  838. pos = SetUint32(record, pos, record.Length/2);
  839. pos = SetUint16(record, pos, (int)WmfConstants.RECORD_POLYLINE);
  840. pos = SetInt16(record, pos, points.Length);
  841. for (int i = 0; i < points.Length; i++)
  842. pos = SetInt16(record, pos, points[i].Length);
  843. for (int i = 0; i < points.Length; i++)
  844. {
  845. for (int j = 0; j < points[i].Length; j++)
  846. {
  847. pos = SetInt16(record, pos, points[i][j].X);
  848. pos = SetInt16(record, pos, points[i][j].Y);
  849. }
  850. }
  851. _records.Add(record);
  852. }
  853. /// <summary>
  854. /// Maps palette entries from the current logical palette to the system palette.
  855. /// </summary>
  856. public void RealizePalette()
  857. {
  858. byte[] record = new byte[6];
  859. int pos = 0;
  860. pos = SetUint32(record, pos, record.Length/2);
  861. pos = SetUint16(record, pos, (int)WmfConstants.RECORD_REALIZE_PALETTE);
  862. _records.Add(record);
  863. }
  864. /// <summary>
  865. /// Restores a device context (DC) to the specified state.
  866. /// The DC is restored by popping state information off a stack created by earlier calls to the SaveDC function.
  867. /// </summary>
  868. /// <param name="savedDC"></param>
  869. public void RestoreDC(int savedDC)
  870. {
  871. byte[] record = new byte[8];
  872. int pos = 0;
  873. pos = SetUint32(record, pos, record.Length/2);
  874. pos = SetUint16(record, pos, (int)WmfConstants.RECORD_RESTORE_DC);
  875. pos = SetInt16(record, pos, savedDC);
  876. _records.Add(record);
  877. }
  878. /// <summary>
  879. /// Draws a rectangle.
  880. /// The rectangle is outlined by using the current pen and filled by using the current brush.
  881. /// </summary>
  882. /// <param name="sx"></param>
  883. /// <param name="sy"></param>
  884. /// <param name="ex"></param>
  885. /// <param name="ey"></param>
  886. public void Rectangle(int sx, int sy, int ex, int ey)
  887. {
  888. byte[] record = new byte[14];
  889. int pos = 0;
  890. pos = SetUint32(record, pos, record.Length/2);
  891. pos = SetUint16(record, pos, (int)WmfConstants.RECORD_RECTANGLE);
  892. pos = SetInt16(record, pos, ey);
  893. pos = SetInt16(record, pos, ex);
  894. pos = SetInt16(record, pos, sy);
  895. pos = SetInt16(record, pos, sx);
  896. _records.Add(record);
  897. }
  898. /// <summary>
  899. /// Increases or decreases the size of a logical palette based on the specified value.
  900. /// </summary>
  901. /// <param name="palette"></param>
  902. public void ResizePalette(WMFConverter.Gdi.IGdiPalette palette)
  903. {
  904. byte[] record = new byte[8];
  905. int pos = 0;
  906. pos = SetUint32(record, pos, record.Length/2);
  907. pos = SetUint16(record, pos, (int)WmfConstants.RECORD_REALIZE_PALETTE);
  908. pos = SetUint16(record, pos, ((WmfPalette)palette).Id);
  909. _records.Add(record);
  910. }
  911. /// <summary>
  912. /// Draws a rectangle with rounded corners.
  913. /// The rectangle is outlined by using the current pen and filled by using the current brush.
  914. /// </summary>
  915. /// <param name="sx"></param>
  916. /// <param name="sy"></param>
  917. /// <param name="ex"></param>
  918. /// <param name="ey"></param>
  919. /// <param name="rw"></param>
  920. /// <param name="rh"></param>
  921. public void RoundRect(int sx, int sy, int ex, int ey, int rw, int rh)
  922. {
  923. byte[] record = new byte[18];
  924. int pos = 0;
  925. pos = SetUint32(record, pos, record.Length/2);
  926. pos = SetUint16(record, pos, (int)WmfConstants.RECORD_ROUND_RECT);
  927. pos = SetInt16(record, pos, rh);
  928. pos = SetInt16(record, pos, rw);
  929. pos = SetInt16(record, pos, ey);
  930. pos = SetInt16(record, pos, ex);
  931. pos = SetInt16(record, pos, sy);
  932. pos = SetInt16(record, pos, sx);
  933. _records.Add(record);
  934. }
  935. /// <summary>
  936. /// Save device context (DC).
  937. /// </summary>
  938. public void SeveDC()
  939. {
  940. byte[] record = new byte[6];
  941. int pos = 0;
  942. pos = SetUint32(record, pos, record.Length/2);
  943. pos = SetUint16(record, pos, (int)WmfConstants.RECORD_SAVE_DC);
  944. _records.Add(record);
  945. }
  946. /// <summary>
  947. /// Modifies the viewport for a device context using the ratios formed by the specified multiplicands and divisors.
  948. /// </summary>
  949. /// <param name="x"></param>
  950. /// <param name="xd"></param>
  951. /// <param name="y"></param>
  952. /// <param name="yd"></param>
  953. /// <param name="old"></param>
  954. public void ScaleViewportExtEx(int x, int xd, int y, int yd, WMFConverter.Gdi.Size old)
  955. {
  956. byte[] record = new byte[14];
  957. int pos = 0;
  958. pos = SetUint32(record, pos, record.Length/2);
  959. pos = SetUint16(record, pos, (int)WmfConstants.RECORD_SCALE_VIEWPORT_EXT_EX);
  960. pos = SetInt16(record, pos, yd);
  961. pos = SetInt16(record, pos, y);
  962. pos = SetInt16(record, pos, xd);
  963. pos = SetInt16(record, pos, x);
  964. // TODO
  965. _records.Add(record);
  966. }
  967. /// <summary>
  968. /// Modifies the window for a device context using the ratios formed by the specified multiplicands and divisors.
  969. /// </summary>
  970. /// <param name="x"></param>
  971. /// <param name="xd"></param>
  972. /// <param name="y"></param>
  973. /// <param name="yd"></param>
  974. /// <param name="old"></param>
  975. public void ScaleWindowExtEx(int x, int xd, int y, int yd, WMFConverter.Gdi.Size old)
  976. {
  977. byte[] record = new byte[14];
  978. int pos = 0;
  979. pos = SetUint32(record, pos, record.Length/2);
  980. pos = SetUint16(record, pos, (int)WmfConstants.RECORD_SCALE_WINDOW_EXT_EX);
  981. pos = SetInt16(record, pos, yd);
  982. pos = SetInt16(record, pos, y);
  983. pos = SetInt16(record, pos, xd);
  984. pos = SetInt16(record, pos, x);
  985. // TODO
  986. _records.Add(record);
  987. }
  988. /// <summary>
  989. /// Selects a region as the current clipping region for the specified device context.
  990. /// </summary>
  991. /// <param name="rgn"></param>
  992. public void SelectClipRgn(WMFConverter.Gdi.IGdiRegion rgn)
  993. {
  994. byte[] record = new byte[8];
  995. int pos = 0;
  996. pos = SetUint32(record, pos, record.Length/2);
  997. pos = SetUint16(record, pos, (int)WmfConstants.RECORD_SELECT_CLIP_RGN);
  998. pos = SetUint16(record, pos, ((WmfRegion)rgn).Id);
  999. _records.Add(record);
  1000. }
  1001. /// <summary>
  1002. /// Selects an object into the specified device context (DC). The new object replaces the previous object of the same type.
  1003. /// </summary>
  1004. /// <param name="obj"></param>
  1005. public void SelectObject(WMFConverter.Gdi.IGdiObject obj)
  1006. {
  1007. byte[] record = new byte[8];
  1008. int pos = 0;
  1009. pos = SetUint32(record, pos, record.Length/2);
  1010. pos = SetUint16(record, pos, (int)WmfConstants.RECORD_SELECT_OBJECT);
  1011. pos = SetUint16(record, pos, ((WmfObject)obj).Id);
  1012. _records.Add(record);
  1013. }
  1014. /// <summary>
  1015. /// Selects the specified logical palette into a device context.
  1016. /// </summary>
  1017. /// <param name="palette"></param>
  1018. /// <param name="mode"></param>
  1019. public void SelectPalette(WMFConverter.Gdi.IGdiPalette palette, bool mode)
  1020. {
  1021. byte[] record = new byte[8];
  1022. int pos = 0;
  1023. pos = SetUint32(record, pos, record.Length/2);
  1024. pos = SetUint16(record, pos, (int)WmfConstants.RECORD_SELECT_PALETTE);
  1025. pos = SetInt16(record, pos, mode ? 1 : 0);
  1026. pos = SetUint16(record, pos, ((WmfPalette)palette).Id);
  1027. _records.Add(record);
  1028. }
  1029. /// <summary>
  1030. /// Sets the current background color to the specified color value, or to the nearest physical color if the device cannot represent the specified color value.
  1031. /// </summary>
  1032. /// <param name="color"></param>
  1033. public void SetBkColor(int color)
  1034. {
  1035. byte[] record = new byte[10];
  1036. int pos = 0;
  1037. pos = SetUint32(record, pos, record.Length/2);
  1038. pos = SetUint16(record, pos, (int)WmfConstants.RECORD_SET_BK_COLOR);
  1039. pos = SetInt32(record, pos, color);
  1040. _records.Add(record);
  1041. }
  1042. /// <summary>
  1043. /// Sets the background mix mode of the specified device context.
  1044. /// The background mix mode is used with text, hatched brushes, and pen styles that are not solid lines.
  1045. /// </summary>
  1046. /// <param name="mode"></param>
  1047. public void SetBkMode(int mode)
  1048. {
  1049. byte[] record = new byte[8];
  1050. int pos = 0;
  1051. pos = SetUint32(record, pos, record.Length/2);
  1052. pos = SetUint16(record, pos, (int)WmfConstants.RECORD_SET_BK_MODE);
  1053. pos = SetInt16(record, pos, mode);
  1054. _records.Add(record);
  1055. }
  1056. /// <summary>
  1057. /// Sets the pixels in the specified rectangle on the device that is associated with the destination device context using color data from a DIB, JPEG, or PNG image.
  1058. /// </summary>
  1059. /// <param name="dx"></param>
  1060. /// <param name="dy"></param>
  1061. /// <param name="dw"></param>
  1062. /// <param name="dh"></param>
  1063. /// <param name="sx"></param>
  1064. /// <param name="sy"></param>
  1065. /// <param name="startscan"></param>
  1066. /// <param name="scanlines"></param>
  1067. /// <param name="image"></param>
  1068. /// <param name="colorUse"></param>
  1069. public void SetDIBitsToDevice(int dx, int dy, int dw, int dh, int sx,
  1070. int sy, int startscan, int scanlines, byte[] image, int colorUse)
  1071. {
  1072. byte[] record = new byte[24 + (image.Length + image.Length%2)];
  1073. int pos = 0;
  1074. pos = SetUint32(record, pos, record.Length/2);
  1075. pos = SetUint16(record, pos, (int)WmfConstants.RECORD_SET_DIBITS_TO_DEVICE);
  1076. pos = SetUint16(record, pos, colorUse);
  1077. pos = SetUint16(record, pos, scanlines);
  1078. pos = SetUint16(record, pos, startscan);
  1079. pos = SetInt16(record, pos, sy);
  1080. pos = SetInt16(record, pos, sx);
  1081. pos = SetInt16(record, pos, dw);
  1082. pos = SetInt16(record, pos, dh);
  1083. pos = SetInt16(record, pos, dy);
  1084. pos = SetInt16(record, pos, dx);
  1085. pos = SetBytes(record, pos, image);
  1086. if (image.Length%2 == 1)
  1087. pos = SetByte(record, pos, 0);
  1088. _records.Add(record);
  1089. }
  1090. /// <summary>
  1091. /// Changes the layout of a device context (DC).
  1092. /// </summary>
  1093. /// <param name="layout"></param>
  1094. public void SetLayout(long layout)
  1095. {
  1096. byte[] record = new byte[10];
  1097. int pos = 0;
  1098. pos = SetUint32(record, pos, record.Length/2);
  1099. pos = SetUint16(record, pos, (int)WmfConstants.RECORD_SET_LAYOUT);
  1100. pos = SetUint32(record, pos, layout);
  1101. _records.Add(record);
  1102. }
  1103. /// <summary>
  1104. /// Sets the mapping mode of the specified device context.
  1105. /// The mapping mode defines the unit of measure used to transform page-space units into device-space units, and also defines the orientation of the device's x and y axes.
  1106. /// </summary>
  1107. /// <param name="mode"></param>
  1108. public void SetMapMode(int mode)
  1109. {
  1110. byte[] record = new byte[8];
  1111. int pos = 0;
  1112. pos = SetUint32(record, pos, record.Length/2);
  1113. pos = SetUint16(record, pos, (int)WmfConstants.RECORD_SET_MAP_MODE);
  1114. pos = SetInt16(record, pos, mode);
  1115. _records.Add(record);
  1116. }
  1117. /// <summary>
  1118. /// Alters the algorithm the font mapper uses when it maps logical fonts to physical fonts.
  1119. /// </summary>
  1120. /// <param name="flags"></param>
  1121. public void SetMapperFlags(long flags)
  1122. {
  1123. byte[] record = new byte[10];
  1124. int pos = 0;
  1125. pos = SetUint32(record, pos, record.Length/2);
  1126. pos = SetUint16(record, pos, (int)WmfConstants.RECORD_SET_MAPPER_FLAGS);
  1127. pos = SetUint32(record, pos, flags);
  1128. _records.Add(record);
  1129. }
  1130. /// <summary>
  1131. /// Sets RGB (red, green, blue) color values and flags in a range of entries in a logical palette.
  1132. /// </summary>
  1133. /// <param name="palette"></param>
  1134. /// <param name="startIndex"></param>
  1135. /// <param name="entries"></param>
  1136. public void SetPaletteEntries(WMFConverter.Gdi.IGdiPalette palette, int startIndex, int[] entries)
  1137. {
  1138. byte[] record = new byte[6 + entries.Length * 4];
  1139. int pos = 0;
  1140. pos = SetUint32(record, pos, record.Length/2);
  1141. pos = SetUint16(record, pos, (int)WmfConstants.RECORD_SET_PALETTE_ENTRIES);
  1142. pos = SetUint16(record, pos, ((WmfPalette)palette).Id);
  1143. pos = SetUint16(record, pos, entries.Length);
  1144. pos = SetUint16(record, pos, startIndex);
  1145. for (int i = 0; i < entries.Length; i++)
  1146. pos = SetInt32(record, pos, entries[i]);
  1147. _records.Add(record);
  1148. }
  1149. /// <summary>
  1150. /// Sets the pixel at the specified coordinates to the specified color.
  1151. /// </summary>
  1152. /// <param name="x"></param>
  1153. /// <param name="y"></param>
  1154. /// <param name="color"></param>
  1155. public void SetPixel(int x, int y, int color)
  1156. {
  1157. byte[] record = new byte[14];
  1158. int pos = 0;
  1159. pos = SetUint32(record, pos, record.Length/2);
  1160. pos = SetUint16(record, pos, (int)WmfConstants.RECORD_SET_PIXEL);
  1161. pos = SetInt32(record, pos, color);
  1162. pos = SetInt16(record, pos, y);
  1163. pos = SetInt16(record, pos, x);
  1164. _records.Add(record);
  1165. }
  1166. /// <summary>
  1167. /// Sets the polygon fill mode for functions that fill polygons.
  1168. /// </summary>
  1169. /// <param name="mode"></param>
  1170. public void SetPolyFillMode(int mode)
  1171. {
  1172. byte[] record = new byte[8];
  1173. int pos = 0;
  1174. pos = SetUint32(record, pos, record.Length/2);
  1175. pos = SetUint16(record, pos, (int)WmfConstants.RECORD_SET_POLY_FILL_MODE);
  1176. pos = SetInt16(record, pos, mode);
  1177. _records.Add(record);
  1178. }
  1179. /// <summary>
  1180. ///
  1181. /// </summary>
  1182. /// <param name="mode"></param>
  1183. public void SetRelAbs(int mode)
  1184. {
  1185. byte[] record = new byte[8];
  1186. int pos = 0;
  1187. pos = SetUint32(record, pos, record.Length/2);
  1188. pos = SetUint16(record, pos, (int)WmfConstants.RECORD_SET_REL_ABS);
  1189. pos = SetInt16(record, pos, mode);
  1190. _records.Add(record);
  1191. }
  1192. /// <summary>
  1193. /// Sets the current foreground mix mode.
  1194. /// GDI uses the foreground mix mode to combine pens and interiors of filled objects with the colors already on the screen.
  1195. /// The foreground mix mode defines how colors from the brush or pen and the colors in the existing image are to be combined.
  1196. /// </summary>
  1197. /// <param name="mode"></param>
  1198. public void SetROP2(int mode)
  1199. {
  1200. byte[] record = new byte[8];
  1201. int pos = 0;
  1202. pos = SetUint32(record, pos, record.Length/2);
  1203. pos = SetUint16(record, pos, (int)WmfConstants.RECORD_SET_ROP2);
  1204. pos = SetInt16(record, pos, mode);
  1205. _records.Add(record);
  1206. }
  1207. /// <summary>
  1208. /// Sets the bitmap stretching mode in the specified device context.
  1209. /// </summary>
  1210. /// <param name="mode"></param>
  1211. public void SetStretchBltMode(int mode)
  1212. {
  1213. byte[] record = new byte[8];
  1214. int pos = 0;
  1215. pos = SetUint32(record, pos, record.Length/2);
  1216. pos = SetUint16(record, pos, (int)WmfConstants.RECORD_SET_STRETCH_BLT_MODE);
  1217. pos = SetInt16(record, pos, mode);
  1218. _records.Add(record);
  1219. }
  1220. /// <summary>
  1221. /// Sets the text-alignment flags for the specified device context.
  1222. /// </summary>
  1223. /// <param name="align"></param>
  1224. public void SetTextAlign(int align)
  1225. {
  1226. byte[] record = new byte[8];
  1227. int pos = 0;
  1228. pos = SetUint32(record, pos, record.Length/2);
  1229. pos = SetUint16(record, pos, (int)WmfConstants.RECORD_SET_TEXT_ALIGN);
  1230. pos = SetInt16(record, pos, align);
  1231. _records.Add(record);
  1232. }
  1233. /// <summary>
  1234. /// Sets the intercharacter spacing.
  1235. /// Intercharacter spacing is added to each character, including break characters, when the system writes a line of text.
  1236. /// </summary>
  1237. /// <param name="extra"></param>
  1238. public void SetTextCharacterExtra(int extra)
  1239. {
  1240. byte[] record = new byte[8];
  1241. int pos = 0;
  1242. pos = SetUint32(record, pos, record.Length/2);
  1243. pos = SetUint16(record, pos, (int)WmfConstants.RECORD_SET_TEXT_CHARACTER_EXTRA);
  1244. pos = SetInt16(record, pos, extra);
  1245. _records.Add(record);
  1246. }
  1247. /// <summary>
  1248. /// Sets the text color for the specified device context to the specified color.
  1249. /// </summary>
  1250. /// <param name="color"></param>
  1251. public void SetTextColor(int color)
  1252. {
  1253. byte[] record = new byte[10];
  1254. int pos = 0;
  1255. pos = SetUint32(record, pos, record.Length/2);
  1256. pos = SetUint16(record, pos, (int)WmfConstants.RECORD_SET_TEXT_COLOR);
  1257. pos = SetInt32(record, pos, color);
  1258. _records.Add(record);
  1259. }
  1260. /// <summary>
  1261. /// Specifies the amount of space the system should add to the break characters in a string of text.
  1262. /// The space is added when an application calls the TextOut or ExtTextOut functions.
  1263. /// </summary>
  1264. /// <param name="breakExtra"></param>
  1265. /// <param name="breakCount"></param>
  1266. public void SetTextJustification(int breakExtra, int breakCount)
  1267. {
  1268. byte[] record = new byte[10];
  1269. int pos = 0;
  1270. pos = SetUint32(record, pos, record.Length/2);
  1271. pos = SetUint16(record, pos, (int)WmfConstants.RECORD_SET_TEXT_COLOR);
  1272. pos = SetInt16(record, pos, breakCount);
  1273. pos = SetInt16(record, pos, breakExtra);
  1274. _records.Add(record);
  1275. }
  1276. /// <summary>
  1277. /// Sets the horizontal and vertical extents of the viewport for a device context by using the specified values.
  1278. /// </summary>
  1279. /// <param name="x"></param>
  1280. /// <param name="y"></param>
  1281. /// <param name="old"></param>
  1282. public void SetViewportExtEx(int x, int y, WMFConverter.Gdi.Size old)
  1283. {
  1284. byte[] record = new byte[10];
  1285. int pos = 0;
  1286. pos = SetUint32(record, pos, record.Length/2);
  1287. pos = SetUint16(record, pos, (int)WmfConstants.RECORD_SET_VIEWPORT_EXT_EX);
  1288. pos = SetInt16(record, pos, y);
  1289. pos = SetInt16(record, pos, x);
  1290. _records.Add(record);
  1291. }
  1292. /// <summary>
  1293. /// Specifies which device point maps to the window origin (0,0).
  1294. /// </summary>
  1295. /// <param name="x"></param>
  1296. /// <param name="y"></param>
  1297. /// <param name="old"></param>
  1298. public void SetViewportOrgEx(int x, int y, WMFConverter.Gdi.Point old)
  1299. {
  1300. byte[] record = new byte[10];
  1301. int pos = 0;
  1302. pos = SetUint32(record, pos, record.Length/2);
  1303. pos = SetUint16(record, pos, (int)WmfConstants.RECORD_SET_VIEWPORT_ORG_EX);
  1304. pos = SetInt16(record, pos, y);
  1305. pos = SetInt16(record, pos, x);
  1306. _records.Add(record);
  1307. }
  1308. /// <summary>
  1309. /// Sets the horizontal and vertical extents of the window for a device context by using the specified values.
  1310. /// </summary>
  1311. /// <param name="width"></param>
  1312. /// <param name="height"></param>
  1313. /// <param name="old"></param>
  1314. public void SetWindowExtEx(int width, int height, WMFConverter.Gdi.Size old)
  1315. {
  1316. byte[] record = new byte[10];
  1317. int pos = 0;
  1318. pos = SetUint32(record, pos, record.Length/2);
  1319. pos = SetUint16(record, pos, (int)WmfConstants.RECORD_SET_WINDOW_EXT_EX);
  1320. pos = SetInt16(record, pos, height);
  1321. pos = SetInt16(record, pos, width);
  1322. _records.Add(record);
  1323. }
  1324. /// <summary>
  1325. /// Specifies which window point maps to the viewport origin (0,0).
  1326. /// </summary>
  1327. /// <param name="x"></param>
  1328. /// <param name="y"></param>
  1329. /// <param name="old"></param>
  1330. public void SetWindowOrgEx(int x, int y, WMFConverter.Gdi.Point old)
  1331. {
  1332. byte[] record = new byte[10];
  1333. int pos = 0;
  1334. pos = SetUint32(record, pos, record.Length/2);
  1335. pos = SetUint16(record, pos, (int)WmfConstants.RECORD_SET_WINDOW_ORG_EX);
  1336. pos = SetInt16(record, pos, y);
  1337. pos = SetInt16(record, pos, x);
  1338. _records.Add(record);
  1339. }
  1340. /// <summary>
  1341. /// Copies a bitmap from a source rectangle into a destination rectangle, stretching or compressing the bitmap to fit the dimensions of the destination rectangle, if necessary.
  1342. /// The system stretches or compresses the bitmap according to the stretching mode currently set in the destination device context.
  1343. /// </summary>
  1344. /// <param name="image"></param>
  1345. /// <param name="dx"></param>
  1346. /// <param name="dy"></param>
  1347. /// <param name="dw"></param>
  1348. /// <param name="dh"></param>
  1349. /// <param name="sx"></param>
  1350. /// <param name="sy"></param>
  1351. /// <param name="sw"></param>
  1352. /// <param name="sh"></param>
  1353. /// <param name="rop"></param>
  1354. public void StretchBlt(byte[] image, int dx, int dy, int dw, int dh,
  1355. int sx, int sy, int sw, int sh, long rop)
  1356. {
  1357. byte[] record = new byte[26 + (image.Length + image.Length%2)];
  1358. int pos = 0;
  1359. pos = SetUint32(record, pos, record.Length/2);
  1360. pos = SetUint16(record, pos, (int)WmfConstants.RECORD_STRETCH_BLT);
  1361. pos = SetUint32(record, pos, rop);
  1362. pos = SetInt16(record, pos, sh);
  1363. pos = SetInt16(record, pos, sw);
  1364. pos = SetInt16(record, pos, sy);
  1365. pos = SetInt16(record, pos, sx);
  1366. pos = SetInt16(record, pos, dw);
  1367. pos = SetInt16(record, pos, dh);
  1368. pos = SetInt16(record, pos, dy);
  1369. pos = SetInt16(record, pos, dx);
  1370. pos = SetBytes(record, pos, image);
  1371. if (image.Length%2 == 1)
  1372. pos = SetByte(record, pos, 0);
  1373. _records.Add(record);
  1374. }
  1375. /// <summary>
  1376. /// Copies the color data for a rectangle of pixels in a DIB, JPEG, or PNG image to the specified destination rectangle.
  1377. /// If the destination rectangle is larger than the source rectangle, this function stretches the rows and columns of color data to fit the destination rectangle. If the destination rectangle is smaller than the source rectangle, this function compresses the rows and columns by using the specified raster operation.
  1378. /// </summary>
  1379. /// <param name="dx"></param>
  1380. /// <param name="dy"></param>
  1381. /// <param name="dw"></param>
  1382. /// <param name="dh"></param>
  1383. /// <param name="sx"></param>
  1384. /// <param name="sy"></param>
  1385. /// <param name="sw"></param>
  1386. /// <param name="sh"></param>
  1387. /// <param name="image"></param>
  1388. /// <param name="usage"></param>
  1389. /// <param name="rop"></param>
  1390. public void StretchDIBits(int dx, int dy, int dw, int dh, int sx, int sy,
  1391. int sw, int sh, byte[] image, int usage, long rop)
  1392. {
  1393. byte[] record = new byte[26 + (image.Length + image.Length%2)];
  1394. int pos = 0;
  1395. pos = SetUint32(record, pos, record.Length/2);
  1396. pos = SetUint16(record, pos, (int)WmfConstants.RECORD_STRETCH_DIBITS);
  1397. pos = SetUint32(record, pos, rop);
  1398. pos = SetUint16(record, pos, usage);
  1399. pos = SetInt16(record, pos, sh);
  1400. pos = SetInt16(record, pos, sw);
  1401. pos = SetInt16(record, pos, sy);
  1402. pos = SetInt16(record, pos, sx);
  1403. pos = SetInt16(record, pos, dw);
  1404. pos = SetInt16(record, pos, dh);
  1405. pos = SetInt16(record, pos, dy);
  1406. pos = SetInt16(record, pos, dx);
  1407. pos = SetBytes(record, pos, image);
  1408. if (image.Length%2 == 1)
  1409. pos = SetByte(record, pos, 0);
  1410. _records.Add(record);
  1411. }
  1412. /// <summary>
  1413. /// Writes a character string at the specified location, using the currently selected font, background color, and text color.
  1414. /// </summary>
  1415. /// <param name="x"></param>
  1416. /// <param name="y"></param>
  1417. /// <param name="text"></param>
  1418. public void TextOut(int x, int y, byte[] text)
  1419. {
  1420. byte[] record = new byte[10 + text.Length + text.Length%2];
  1421. int pos = 0;
  1422. pos = SetUint32(record, pos, record.Length/2);
  1423. pos = SetUint16(record, pos, (int)WmfConstants.RECORD_TEXT_OUT);
  1424. pos = SetInt16(record, pos, text.Length);
  1425. pos = SetBytes(record, pos, text);
  1426. if (text.Length%2 == 1) pos = SetByte(record, pos, 0);
  1427. pos = SetInt16(record, pos, y);
  1428. pos = SetInt16(record, pos, x);
  1429. _records.Add(record);
  1430. }
  1431. /// <summary>
  1432. ///
  1433. /// </summary>
  1434. public void Footer()
  1435. {
  1436. int pos = 0;
  1437. if (_header != null)
  1438. {
  1439. long size = _header.Length;
  1440. long maxRecordSize = 0;
  1441. foreach(var item in _records)
  1442. {
  1443. size += item.Length;
  1444. if (item.Length > maxRecordSize)
  1445. maxRecordSize = item.Length;
  1446. }
  1447. pos = SetUint32(_header, 6, size/2);
  1448. pos = SetUint16(_header, pos, _objects.Count());
  1449. pos = SetUint32(_header, pos, maxRecordSize / 2);
  1450. }
  1451. byte[] record = new byte[6];
  1452. pos = 0;
  1453. pos = SetUint32(record, pos, record.Length/2);
  1454. pos = SetUint16(record, pos, 0x0000);
  1455. _records.Add(record);
  1456. }
  1457. /// <summary>
  1458. ///
  1459. /// </summary>
  1460. /// <param name="output"></param>
  1461. /// <param name="pos"></param>
  1462. /// <param name="value"></param>
  1463. /// <returns></returns>
  1464. private int SetByte(byte[] output, int pos, int value)
  1465. {
  1466. output[pos] = (byte)(0xFF & value);
  1467. return pos + 1;
  1468. }
  1469. /// <summary>
  1470. ///
  1471. /// </summary>
  1472. /// <param name="output"></param>
  1473. /// <param name="pos"></param>
  1474. /// <param name="data"></param>
  1475. /// <returns></returns>
  1476. private int SetBytes(byte[] output, int pos, byte[] data)
  1477. {
  1478. Array.Copy(data, 0, output, pos, data.Length);
  1479. return pos + data.Length;
  1480. }
  1481. /// <summary>
  1482. /// Sets two bytes as a signed 16-bit integer.
  1483. /// </summary>
  1484. /// <param name="output"></param>
  1485. /// <param name="pos"></param>
  1486. /// <param name="value"></param>
  1487. /// <returns></returns>
  1488. private int SetInt16(byte[] output, int pos, int value)
  1489. {
  1490. output[pos] = (byte)(0xFF & value);
  1491. output[pos+1] = (byte)(0xFF & (value >> 8));
  1492. return pos + 2;
  1493. }
  1494. /// <summary>
  1495. /// Sets four bytes as a signed 32-bit integer.
  1496. /// </summary>
  1497. /// <param name="output"></param>
  1498. /// <param name="pos"></param>
  1499. /// <param name="value"></param>
  1500. /// <returns></returns>
  1501. private int SetInt32(byte[] output, int pos, int value)
  1502. {
  1503. output[pos] = (byte)(0xFF & value);
  1504. output[pos+1] = (byte)(0xFF & (value >> 8));
  1505. output[pos+2] = (byte)(0xFF & (value >> 16));
  1506. output[pos+3] = (byte)(0xFF & (value >> 24));
  1507. return pos + 4;
  1508. }
  1509. /// <summary>
  1510. /// Sets two bytes as a unsigned 16-bit integer.
  1511. /// </summary>
  1512. /// <param name="output"></param>
  1513. /// <param name="pos"></param>
  1514. /// <param name="value"></param>
  1515. /// <returns></returns>
  1516. private int SetUint16(byte[] output, int pos, int value)
  1517. {
  1518. output[pos] = (byte)(0xFF & value);
  1519. output[pos+1] = (byte)(0xFF & (value >> 8));
  1520. return pos + 2;
  1521. }
  1522. /// <summary>
  1523. /// Sets four bytes as a unsigned 32-bit integer.
  1524. /// </summary>
  1525. /// <param name="output"></param>
  1526. /// <param name="pos"></param>
  1527. /// <param name="value"></param>
  1528. /// <returns></returns>
  1529. private int SetUint32(byte[] output, int pos, long value)
  1530. {
  1531. output[pos] = (byte)(0xFF & value);
  1532. output[pos+1] = (byte)(0xFF & (value >> 8));
  1533. output[pos+2] = (byte)(0xFF & (value >> 16));
  1534. output[pos + 3] = (byte)(0xFF & (value >> 24));
  1535. return pos + 4;
  1536. }
  1537. #endregion
  1538. }
  1539. }