RichText.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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 paragraph;
  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 bool disable_space_before;
  78. public bool disable_space_after;
  79. public int left_indent;
  80. public int right_indent;
  81. public int first_line_indent;
  82. public LnSpcMult lnspcmult;
  83. public int pnstart; // Level of bullets/numbering. Zero for ordinary paragraph
  84. public Direction text_direction;
  85. public List<Run> list_id;
  86. public List<int> tab_positions;
  87. }
  88. #if READONLY_STRUCTS
  89. public readonly struct Run
  90. #else
  91. public struct Run
  92. #endif
  93. {
  94. public readonly string text;
  95. public readonly RunFormat format;
  96. public Run(string text, RunFormat format)
  97. {
  98. this.text = text;
  99. this.format = format;
  100. }
  101. }
  102. public struct RunFormat
  103. {
  104. public enum ScriptType { PlainText, Subscript, Superscript };
  105. public bool bold;
  106. public bool italic;
  107. public bool underline;
  108. public bool strike;
  109. public ScriptType script_type;
  110. public System.Drawing.Color color;
  111. public System.Drawing.Color BColor;
  112. public System.Drawing.Color FillColor;
  113. public uint font_idx;
  114. public int font_size;
  115. public void Assign(RunFormat rf)
  116. {
  117. bold = rf.bold;
  118. italic = rf.italic;
  119. underline = rf.underline;
  120. strike = rf.strike;
  121. script_type = rf.script_type;
  122. color = rf.color;
  123. BColor = rf.BColor;
  124. font_idx = rf.font_idx;
  125. FillColor = rf.FillColor;
  126. if (rf.font_size != 0)
  127. font_size = rf.font_size;
  128. }
  129. public bool IsSameAs(RunFormat rf)
  130. {
  131. return bold == rf.bold && italic == rf.italic && underline == rf.underline && script_type == rf.script_type &&
  132. color == rf.color && font_idx == rf.font_idx && font_size == rf.font_size && strike == rf.strike;
  133. }
  134. #if false
  135. internal ulong HashKey()
  136. {
  137. ulong key = 0;
  138. if (bold) key |= 1;
  139. if (italic) key |= 2;
  140. key |= (ulong)(color_idx << 2);
  141. key ^= (ulong)(font_idx << 10);
  142. return key;
  143. }
  144. #endif
  145. }
  146. public struct RFont
  147. {
  148. public enum Family { Nil, Rroman, Swiss, Modern, Script, Decor, Tech, Bidi }
  149. public uint font_id;
  150. public long charset;
  151. public Family family;
  152. public string FontName;
  153. }
  154. public struct BorderLine
  155. {
  156. public enum Style { Thin, Thick, Double, Dotted };
  157. public Style style;
  158. public uint width;
  159. public System.Drawing.Color color;
  160. }
  161. public struct Picture
  162. {
  163. public long size;
  164. public System.Drawing.Image image;
  165. public int width, height;
  166. public int scalex, scaley;
  167. public int desired_width, desired_height;
  168. public int crop_left;
  169. public int crop_top;
  170. public int crop_right;
  171. public int crop_bottom;
  172. public bool picprop; // Indicates that shape properties are applied to an inline picture.
  173. public int tag;
  174. public int units_per_inch;
  175. public ParagraphFormat.HorizontalAlign horizontalAlign;
  176. }
  177. public struct Column
  178. {
  179. public enum VertAlign { Top, Center, Bottom };
  180. public VertAlign valign;
  181. public System.Drawing.Color back_color;
  182. public bool verticallY_merged;
  183. public bool horizontally_merged;
  184. public BorderLine border_top;
  185. public BorderLine border_left;
  186. public BorderLine border_right;
  187. public BorderLine border_bottom;
  188. private uint width;
  189. public uint Width { get { return width; } set { width = value; } }
  190. }
  191. public struct TableRow
  192. {
  193. public long size;
  194. public int height;
  195. public uint trgaph; // Half the space between the cells of a table row in twips.
  196. public int default_pad_left;
  197. public int default_pad_right;
  198. public List<RichObjectSequence> cells;
  199. }
  200. public struct Table
  201. {
  202. public long size;
  203. public List<Column> columns;
  204. public List<TableRow> rows;
  205. }
  206. public struct Style
  207. {
  208. public int styledef;
  209. public ParagraphFormat paragraph_style;
  210. public RunFormat run_style;
  211. public string stylename;
  212. }
  213. #pragma warning restore 1591
  214. }