UnitsConverter.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Drawing;
  5. using System.Drawing.Drawing2D;
  6. using FastReport.Barcode;
  7. using FastReport.Map;
  8. using FastReport.Data;
  9. namespace FastReport.Design.ExportPlugins.FR3
  10. {
  11. /// <summary>
  12. /// The FR3 units converter.
  13. /// </summary>
  14. public static class UnitsConverter
  15. {
  16. #region Public Methods
  17. /// <summary>
  18. /// Converts Color to TColor.
  19. /// </summary>
  20. /// <param name="color">Color value.</param>
  21. /// <returns>String that contains TColor value.</returns>
  22. public static string ColorToTColor(Color color)
  23. {
  24. return (color.B << 16 | color.G << 8 | color.R).ToString();
  25. }
  26. /// <summary>
  27. /// Converts font style.
  28. /// </summary>
  29. /// <param name="fontStyle">FontStyle value.</param>
  30. /// <returns>String that contains converted value.</returns>
  31. public static string ConvertFontStyle(FontStyle fontStyle)
  32. {
  33. int fs = 0;
  34. if (FontStyle.Bold == (fontStyle & FontStyle.Bold))
  35. {
  36. fs = 1;
  37. }
  38. if (FontStyle.Italic == (fontStyle & FontStyle.Italic))
  39. {
  40. fs = fs | 2;
  41. }
  42. if (FontStyle.Underline == (fontStyle & FontStyle.Underline))
  43. {
  44. fs = fs | 4;
  45. }
  46. if (FontStyle.Strikeout == (fontStyle & FontStyle.Strikeout))
  47. {
  48. fs = fs | 8;
  49. }
  50. return fs.ToString();
  51. }
  52. /// <summary>
  53. /// Converts horizontal alignment of text.
  54. /// </summary>
  55. /// <param name="ha">HorzAlign value.</param>
  56. /// <returns>String that contains converted value.</returns>
  57. public static string ConvertHorzAlign(HorzAlign ha)
  58. {
  59. string result = "";
  60. switch (ha)
  61. {
  62. case HorzAlign.Left:
  63. result = "haLeft";
  64. break;
  65. case HorzAlign.Center:
  66. result = "haCenter";
  67. break;
  68. case HorzAlign.Right:
  69. result = "haRight";
  70. break;
  71. case HorzAlign.Justify:
  72. result = "haBlock";
  73. break;
  74. default:
  75. result = "haLeft";
  76. break;
  77. }
  78. return result;
  79. }
  80. /// <summary>
  81. /// Converts vertical alignment of text.
  82. /// </summary>
  83. /// <param name="va">VertAlign value.</param>
  84. /// <returns>String that contains coverted value.</returns>
  85. public static string ConvertVertAlign(VertAlign va)
  86. {
  87. string result = "";
  88. switch (va)
  89. {
  90. case VertAlign.Top:
  91. result = "vaTop";
  92. break;
  93. case VertAlign.Center:
  94. result = "vaCenter";
  95. break;
  96. case VertAlign.Bottom:
  97. result = "vaBottom";
  98. break;
  99. default:
  100. result = "vaTop";
  101. break;
  102. }
  103. return result;
  104. }
  105. /// <summary>
  106. /// Converts font size to delphi font height.
  107. /// </summary>
  108. /// <param name="size">Font size value.</param>
  109. /// <returns>String that contains font height value.</returns>
  110. public static string ConvertFontSize(float size)
  111. {
  112. return ((int)(-Math.Round(size * 96 / 72, 0))).ToString();
  113. }
  114. /// <summary>
  115. /// Convert line style to frame style.
  116. /// </summary>
  117. /// <param name="style">Line style value.</param>
  118. /// <returns>String that contains converted value.</returns>
  119. public static string ConvertLineStyle(LineStyle style)
  120. {
  121. string result = "";
  122. switch (style)
  123. {
  124. case LineStyle.Solid:
  125. result = "fsSolid";
  126. break;
  127. case LineStyle.Dash:
  128. result = "fsDash";
  129. break;
  130. case LineStyle.DashDot:
  131. result = "fsDashDot";
  132. break;
  133. case LineStyle.DashDotDot:
  134. result = "fsDashDotDot";
  135. break;
  136. case LineStyle.Dot:
  137. result = "fsDot";
  138. break;
  139. case LineStyle.Double:
  140. result = "fsDouble";
  141. break;
  142. default:
  143. result = "fsSolid";
  144. break;
  145. }
  146. return result;
  147. }
  148. /// <summary>
  149. /// Converts barcode type.
  150. /// </summary>
  151. /// <param name="barcode">BarcodeBase instance.</param>
  152. /// <returns>String that contains converted value.</returns>
  153. public static string ConvertBarcodeType(BarcodeBase barcode)
  154. {
  155. string result = "bcCode128";
  156. if (barcode is Barcode128)
  157. {
  158. result = "bcCode128";
  159. }
  160. else if (barcode is Barcode2of5Industrial)
  161. {
  162. result = "bcCode_2_5_industrial";
  163. }
  164. else if (barcode is Barcode2of5Interleaved)
  165. {
  166. result = "bcCode_2_5_interleaved";
  167. }
  168. else if (barcode is Barcode2of5Matrix)
  169. {
  170. result = "bcCode_2_5_matrix";
  171. }
  172. else if (barcode is Barcode39)
  173. {
  174. result = "bcCode39";
  175. }
  176. else if (barcode is Barcode39Extended)
  177. {
  178. result = "bcCode39Extended";
  179. }
  180. else if (barcode is Barcode93)
  181. {
  182. result = "bcCode93";
  183. }
  184. else if (barcode is Barcode93Extended)
  185. {
  186. result = "bcCode93Extended";
  187. }
  188. else if (barcode is BarcodeAztec)
  189. {
  190. result = "bcCodeAztec";
  191. }
  192. else if (barcode is BarcodeCodabar)
  193. {
  194. result = "bcCodeCodabar";
  195. }
  196. else if (barcode is BarcodeDatamatrix)
  197. {
  198. result = "bcCodeDataMatrix";
  199. }
  200. //else if (barcode is BarcodeEAN)
  201. //{
  202. // result = "";
  203. //}
  204. else if (barcode is BarcodeEAN128)
  205. {
  206. result = "bcCodeEAN128";
  207. }
  208. else if (barcode is BarcodeEAN13)
  209. {
  210. result = "bcCodeEAN13";
  211. }
  212. else if (barcode is BarcodeEAN8)
  213. {
  214. result = "bcCodeEAN8";
  215. }
  216. else if (barcode is BarcodeIntelligentMail)
  217. {
  218. result = "bcCodeUSPSIntelligentMail";
  219. }
  220. else if (barcode is BarcodeMaxiCode)
  221. {
  222. result = "bcCodeMaxiCode";
  223. }
  224. else if (barcode is BarcodeMSI)
  225. {
  226. result = "bcCodeMSI";
  227. }
  228. else if (barcode is BarcodePDF417)
  229. {
  230. result = "bcCodePDF417";
  231. }
  232. //else if (barcode is BarcodePharmacode)
  233. //{
  234. // result = "";
  235. //}
  236. //else if (barcode is BarcodePlessey)
  237. //{
  238. // result = "";
  239. //}
  240. else if (barcode is BarcodePostNet)
  241. {
  242. result = "bcCodePostNet";
  243. }
  244. else if (barcode is BarcodeQR)
  245. {
  246. result = "bcCodeQR";
  247. }
  248. else if (barcode is BarcodeSupplement2)
  249. {
  250. result = "bcCodeUPC_Supp2";
  251. }
  252. else if (barcode is BarcodeSupplement5)
  253. {
  254. result = "bcCodeUPC_Supp5";
  255. }
  256. else if (barcode is BarcodeUPC_A)
  257. {
  258. result = "bcCodeUPC_A";
  259. }
  260. else if (barcode is BarcodeUPC_E0)
  261. {
  262. result = "bcCodeUPC_E0";
  263. }
  264. else if (barcode is BarcodeUPC_E1)
  265. {
  266. result = "bcCodeUPC_E1";
  267. }
  268. return result;
  269. }
  270. /// <summary>
  271. /// Converts BorderLines value.
  272. /// </summary>
  273. /// <param name="lines">BorderLines instance.</param>
  274. /// <returns>String that contains converted value.</returns>
  275. public static string ConvertBorderLines(BorderLines lines)
  276. {
  277. return ((int)lines).ToString();
  278. }
  279. /// <summary>
  280. /// Converts CheckedSymbol value.
  281. /// </summary>
  282. /// <param name="symbol">CheckeSymbol instance.</param>
  283. /// <returns>String that contains converted value.</returns>
  284. public static string ConvertCheckedSymbol(CheckedSymbol symbol)
  285. {
  286. string result = "csCheck";
  287. if (symbol == CheckedSymbol.Cross)
  288. {
  289. result = "csCross";
  290. }
  291. else if (symbol == CheckedSymbol.Plus)
  292. {
  293. result = "csPlus";
  294. }
  295. return result;
  296. }
  297. /// <summary>
  298. /// Converts ScaleDock value.
  299. /// </summary>
  300. /// <param name="dock">ScaleDock instance.</param>
  301. /// <returns>String that contains converted value.</returns>
  302. public static string ConvertScaleDock(ScaleDock dock)
  303. {
  304. string result = "sdTopLeft";
  305. switch (dock)
  306. {
  307. case ScaleDock.BottomCenter:
  308. result = "sdBottomCenter";
  309. break;
  310. case ScaleDock.BottomLeft:
  311. result = "sdBottomLeft";
  312. break;
  313. case ScaleDock.BottomRight:
  314. result = "sdBottomRight";
  315. break;
  316. case ScaleDock.MiddleLeft:
  317. result = "sdMiddleLeft";
  318. break;
  319. case ScaleDock.MiddleRight:
  320. result = "sdMiddleRight";
  321. break;
  322. case ScaleDock.TopCenter:
  323. result = "sdTopCenter";
  324. break;
  325. case ScaleDock.TopLeft:
  326. result = "sdTopLeft";
  327. break;
  328. case ScaleDock.TopRight:
  329. result = "sdTopRight";
  330. break;
  331. default:
  332. result = "sdTopLeft";
  333. break;
  334. }
  335. return result;
  336. }
  337. /// <summary>
  338. /// Converts DashStyle value.
  339. /// </summary>
  340. /// <param name="ds">DashStyle instance.</param>
  341. /// <returns>String that contains converted value.</returns>
  342. public static string ConvertDashStyle(DashStyle ds)
  343. {
  344. string result = "psSolid";
  345. switch (ds)
  346. {
  347. case DashStyle.Solid:
  348. result = "psSolid";
  349. break;
  350. case DashStyle.Dash:
  351. result = "psDash";
  352. break;
  353. case DashStyle.DashDot:
  354. result = "psDashDot";
  355. break;
  356. case DashStyle.DashDotDot:
  357. result = "psDashDotDot";
  358. break;
  359. case DashStyle.Dot:
  360. result = "psDot";
  361. break;
  362. default:
  363. result = "psSolid";
  364. break;
  365. }
  366. return result;
  367. }
  368. /// <summary>
  369. /// Converts TotalType value.
  370. /// </summary>
  371. /// <param name="tt">TotalType instance.</param>
  372. /// <returns>String that contains converted value.</returns>
  373. public static string ConvertTotalType(TotalType tt)
  374. {
  375. string result = "opSum";
  376. switch (tt)
  377. {
  378. case TotalType.Avg:
  379. result = "opAverage";
  380. break;
  381. case TotalType.Count:
  382. result = "opCount";
  383. break;
  384. case TotalType.Max:
  385. result = "opMax";
  386. break;
  387. case TotalType.Min:
  388. result = "opMin";
  389. break;
  390. case TotalType.Sum:
  391. result = "opSum";
  392. break;
  393. default:
  394. result = "opSum";
  395. break;
  396. }
  397. return result;
  398. }
  399. /// <summary>
  400. /// Converts MapLabelKind value.
  401. /// </summary>
  402. /// <param name="kind">MapLabelKind instance.</param>
  403. /// <returns>String that contains converted value.</returns>
  404. public static string ConvertMapLabelKind(MapLabelKind kind)
  405. {
  406. string result = "mlName";
  407. switch (kind)
  408. {
  409. case MapLabelKind.Name:
  410. result = "mlName";
  411. break;
  412. case MapLabelKind.NameAndValue:
  413. result = "mlNameAndValue";
  414. break;
  415. case MapLabelKind.None:
  416. result = "mlNone";
  417. break;
  418. case MapLabelKind.Value:
  419. result = "mlValue";
  420. break;
  421. default:
  422. result = "mlName";
  423. break;
  424. }
  425. return result;
  426. }
  427. /// <summary>
  428. /// Converts MapPalette value.
  429. /// </summary>
  430. /// <param name="palette">MapPalette instance.</param>
  431. /// <returns>String that contains converted value.</returns>
  432. public static string ConvertMapPalette(MapPalette palette)
  433. {
  434. string result = "mpBrightPastel";
  435. switch (palette)
  436. {
  437. case MapPalette.BrightPastel:
  438. result = "mpBrightPastel";
  439. break;
  440. case MapPalette.Earth:
  441. result = "mpEarth";
  442. break;
  443. case MapPalette.Grayscale:
  444. result = "mpGrayScale";
  445. break;
  446. case MapPalette.Light:
  447. result = "mpLight";
  448. break;
  449. case MapPalette.None:
  450. result = "mpNone";
  451. break;
  452. case MapPalette.Pastel:
  453. result = "mpPastel";
  454. break;
  455. case MapPalette.Sea:
  456. result = "mpSea";
  457. break;
  458. default:
  459. result = "mpBrightPastel";
  460. break;
  461. }
  462. return result;
  463. }
  464. /// <summary>
  465. /// Converts ShapeKind value.
  466. /// </summary>
  467. /// <param name="sk">ShapeKind instance.</param>
  468. /// <returns>String that contains coverted value.</returns>
  469. public static string ConvertShapeKind(ShapeKind sk)
  470. {
  471. string result = "skRectangle";
  472. switch (sk)
  473. {
  474. case ShapeKind.Rectangle:
  475. result = "skRectangle";
  476. break;
  477. case ShapeKind.Diamond:
  478. result = "skDiamond";
  479. break;
  480. case ShapeKind.Ellipse:
  481. result = "skEllipse";
  482. break;
  483. case ShapeKind.RoundRectangle:
  484. result = "skRoundRectangle";
  485. break;
  486. case ShapeKind.Triangle:
  487. result = "skTriangle";
  488. break;
  489. default:
  490. result = "skRectangle";
  491. break;
  492. }
  493. return result;
  494. }
  495. #endregion // Public Methods
  496. }
  497. }