RichText.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. //
  2. // FastReport RichText infrastructure
  3. //
  4. using System.Collections.Generic;
  5. namespace FastReport.RichTextParser
  6. {
  7. #pragma warning disable 1591
  8. /// <summary>
  9. /// Internal representation of RichText document
  10. /// </summary>
  11. public struct RichDocument
  12. {
  13. public long size;
  14. public List<Page> pages;
  15. // RTF header
  16. public List<RFont> font_list;
  17. public List<System.Drawing.Color> color_list;
  18. public List<Style> style_list;
  19. public long codepage;
  20. public long default_font;
  21. public long default_lang;
  22. // RTF body
  23. public long paper_width;
  24. public long paper_height;
  25. public long global_margin_left;
  26. public long global_margin_top;
  27. public long global_margin_right;
  28. public long global_margin_bottom;
  29. public long default_tab_width;
  30. public long view_kind;
  31. }
  32. public struct Page
  33. {
  34. public long size;
  35. public bool soft_break;
  36. public long page_width;
  37. public long page_heigh;
  38. public long margin_top;
  39. public long margin_left;
  40. public long margin_right;
  41. public long margin_bottom;
  42. public RichObjectSequence sequence;
  43. public RichObjectSequence header;
  44. public RichObjectSequence footer;
  45. }
  46. public struct RichObjectSequence
  47. {
  48. public long size;
  49. public List<RichObject> objects;
  50. }
  51. public struct RichObject
  52. {
  53. public enum Type { Paragraph, Table, Picture }
  54. public long size;
  55. public Type type;
  56. public Paragraph pargraph;
  57. public Table table;
  58. public Picture picture;
  59. }
  60. public struct Paragraph
  61. {
  62. public long size;
  63. public List<Run> runs;
  64. public ParagraphFormat format;
  65. }
  66. public struct ParagraphFormat
  67. {
  68. public enum VerticalAlign { Top, Center, Bottom }
  69. public enum HorizontalAlign { Centered, Justified, Left, Right, Distributed, Kashida, Thai }
  70. public enum LnSpcMult { Exactly, Multiply }
  71. public enum Direction { LeftToRight, RighgToLeft }
  72. public HorizontalAlign align;
  73. public VerticalAlign Valign;
  74. public int line_spacing;
  75. public int space_before;
  76. public int space_after;
  77. public int left_indent;
  78. public int right_indent;
  79. public int first_line_indent;
  80. public LnSpcMult lnspcmult;
  81. public int pnstart; // Level of bullets/numbering. Zero for ordinary paragraph
  82. public Direction text_direction;
  83. public List<Run> list_id;
  84. public List<int> tab_positions;
  85. }
  86. #if READONLY_STRUCTS
  87. public readonly struct Run
  88. #else
  89. public struct Run
  90. #endif
  91. {
  92. public readonly string text;
  93. public readonly RunFormat format;
  94. public Run(string text, RunFormat format)
  95. {
  96. this.text = text;
  97. this.format = format;
  98. }
  99. }
  100. public struct RunFormat
  101. {
  102. public enum ScriptType { PlainText, Subscript, Superscript };
  103. public bool bold;
  104. public bool italic;
  105. public bool underline;
  106. public bool strike;
  107. public ScriptType script_type;
  108. public System.Drawing.Color color;
  109. public System.Drawing.Color BColor;
  110. public System.Drawing.Color FillColor;
  111. public uint font_idx;
  112. public int font_size;
  113. public bool IsSameAs(RunFormat rf)
  114. {
  115. return bold == rf.bold && italic == rf.italic && underline == rf.underline && script_type == rf.script_type &&
  116. color == rf.color && font_idx == rf.font_idx && font_size == rf.font_size;
  117. }
  118. #if false
  119. internal ulong HashKey()
  120. {
  121. ulong key = 0;
  122. if (bold) key |= 1;
  123. if (italic) key |= 2;
  124. key |= (ulong)(color_idx << 2);
  125. key ^= (ulong)(font_idx << 10);
  126. return key;
  127. }
  128. #endif
  129. }
  130. public struct RFont
  131. {
  132. public enum Family { Nil, Rroman, Swiss, Modern, Script, Decor, Tech, Bidi }
  133. public uint font_id;
  134. public long charset;
  135. public Family family;
  136. public string FontName;
  137. }
  138. public struct BorderLine
  139. {
  140. public enum Style { Thin, Thick, Double, Dotted };
  141. public Style style;
  142. public uint width;
  143. public System.Drawing.Color color;
  144. }
  145. public struct Picture
  146. {
  147. public long size;
  148. public System.Drawing.Image image;
  149. public int width, height;
  150. public int scalex, scaley;
  151. public int desired_width, desired_height;
  152. public int crop_left;
  153. public int crop_top;
  154. public int crop_right;
  155. public int crop_bottom;
  156. public bool picprop; // Indicates that shape properties are applied to an inline picture.
  157. public int tag;
  158. public int units_per_inch;
  159. public ParagraphFormat.HorizontalAlign horizontalAlign;
  160. }
  161. public struct Column
  162. {
  163. public enum VertAlign { Top, Center, Bottom };
  164. public VertAlign valign;
  165. public System.Drawing.Color back_color;
  166. public bool verticallY_merged;
  167. public bool horizontally_merged;
  168. public BorderLine border_top;
  169. public BorderLine border_left;
  170. public BorderLine border_right;
  171. public BorderLine border_bottom;
  172. private uint width;
  173. public uint Width { get { return width; } set { width = value; } }
  174. }
  175. public struct TableRow
  176. {
  177. public long size;
  178. public int height;
  179. public uint trgaph; // Half the space between the cells of a table row in twips.
  180. public int default_pad_left;
  181. public int default_pad_right;
  182. public List<RichObjectSequence> cells;
  183. }
  184. public struct Table
  185. {
  186. public long size;
  187. public List<Column> columns;
  188. public List<TableRow> rows;
  189. }
  190. public struct Style
  191. {
  192. public int styledef;
  193. public ParagraphFormat paragraph_style;
  194. public RunFormat run_style;
  195. public string stylename;
  196. }
  197. #pragma warning restore 1591
  198. }