htmltable.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /// @file
  2. /// @ingroup common_render
  3. /*************************************************************************
  4. * Copyright (c) 2011 AT&T Intellectual Property
  5. * All rights reserved. This program and the accompanying materials
  6. * are made available under the terms of the Eclipse Public License v1.0
  7. * which accompanies this distribution, and is available at
  8. * https://www.eclipse.org/legal/epl-v10.html
  9. *
  10. * Contributors: Details at https://graphviz.org
  11. *************************************************************************/
  12. #pragma once
  13. #include <cgraph/list.h>
  14. #include <stdbool.h>
  15. #include <stdint.h>
  16. #include <stdlib.h>
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. #define FIXED_FLAG 1
  21. #define HALIGN_RIGHT (1 << 1)
  22. #define HALIGN_LEFT (1 << 2)
  23. #define HALIGN_MASK (HALIGN_RIGHT | HALIGN_LEFT)
  24. #define HALIGN_TEXT HALIGN_MASK
  25. #define VALIGN_TOP (1 << 3)
  26. #define VALIGN_BOTTOM (1 << 4)
  27. #define VALIGN_MASK (VALIGN_TOP | VALIGN_BOTTOM)
  28. #define BORDER_SET (1 << 5)
  29. #define PAD_SET (1 << 6)
  30. #define SPACE_SET (1 << 7)
  31. #define BALIGN_RIGHT (1 << 8)
  32. #define BALIGN_LEFT (1 << 9)
  33. #define BALIGN_MASK (BALIGN_RIGHT | BALIGN_LEFT)
  34. #define BORDER_LEFT (1 << 10)
  35. #define BORDER_TOP (1 << 11)
  36. #define BORDER_RIGHT (1 << 12)
  37. #define BORDER_BOTTOM (1 << 13)
  38. #define BORDER_MASK (BORDER_LEFT|BORDER_TOP|BORDER_RIGHT|BORDER_BOTTOM)
  39. #define UNSET_ALIGN 0
  40. /* spans of text within a cell
  41. * NOTE: As required, the str field in span is utf-8.
  42. * This translation is done when libexpat scans the input.
  43. */
  44. /* line of textspan_t's */
  45. typedef struct {
  46. textspan_t *items;
  47. size_t nitems;
  48. char just;
  49. double size; /* width of span */
  50. double lfsize; /* offset from previous baseline to current one */
  51. } htextspan_t;
  52. typedef struct {
  53. htextspan_t *spans;
  54. size_t nspans;
  55. char simple;
  56. boxf box;
  57. } htmltxt_t;
  58. typedef struct {
  59. boxf box;
  60. char *src;
  61. char *scale;
  62. } htmlimg_t;
  63. typedef struct {
  64. bool radial: 1;
  65. bool rounded: 1;
  66. bool invisible: 1;
  67. bool dotted: 1;
  68. bool dashed: 1;
  69. } htmlstyle_t;
  70. typedef struct {
  71. char *href; /* pointer to an external resource */
  72. char *port;
  73. char *target;
  74. char *title;
  75. char *id;
  76. char *bgcolor;
  77. char *pencolor;
  78. int gradientangle;
  79. signed char space;
  80. unsigned char border;
  81. unsigned char pad;
  82. unsigned char sides; /* set of sides exposed to field */
  83. unsigned short flags;
  84. unsigned short width;
  85. unsigned short height;
  86. htmlstyle_t style;
  87. boxf box; /* its geometric placement in points */
  88. } htmldata_t;
  89. typedef enum { HTML_UNSET = 0, HTML_TBL, HTML_TEXT, HTML_IMAGE } label_type_t;
  90. typedef struct htmlcell_t htmlcell_t;
  91. typedef struct htmltbl_t htmltbl_t;
  92. /* During parsing, table contents are stored as rows of cells.
  93. * A row is a list of cells
  94. * Rows is a list of rows.
  95. */
  96. DEFINE_LIST(cells, htmlcell_t *)
  97. typedef struct {
  98. cells_t rp;
  99. bool ruled;
  100. } row_t;
  101. /// Free row. This closes and frees row’s list, then the item itself is freed.
  102. static inline void free_ritem(row_t *p) {
  103. cells_free(&p->rp);
  104. free (p);
  105. }
  106. DEFINE_LIST_WITH_DTOR(rows, row_t *, free_ritem)
  107. struct htmltbl_t {
  108. htmldata_t data;
  109. union {
  110. struct {
  111. htmlcell_t *parent; /* enclosing cell */
  112. htmlcell_t **cells; /* cells */
  113. } n;
  114. struct {
  115. htmltbl_t *prev; /* stack */
  116. rows_t rows; ///< cells
  117. } p;
  118. } u;
  119. int8_t cellborder;
  120. double *heights; ///< heights of the rows
  121. double *widths; ///< widths of the columns
  122. size_t row_count; ///< number of rows
  123. size_t column_count; ///< number of columns
  124. textfont_t *font; /* font info */
  125. bool hrule:1; ///< horizontal rule
  126. bool vrule:1; ///< vertical rule
  127. };
  128. struct htmllabel_t {
  129. union {
  130. htmltbl_t *tbl;
  131. htmltxt_t *txt;
  132. htmlimg_t *img;
  133. } u;
  134. label_type_t kind;
  135. };
  136. struct htmlcell_t {
  137. htmldata_t data;
  138. uint16_t colspan;
  139. uint16_t rowspan;
  140. uint16_t col;
  141. uint16_t row;
  142. htmllabel_t child;
  143. htmltbl_t *parent;
  144. bool vruled: 1; ///< vertically ruled?
  145. bool hruled: 1; ///< horizontally ruled?
  146. };
  147. typedef struct {
  148. pointf pos;
  149. textfont_t finfo;
  150. void *obj;
  151. graph_t *g;
  152. char *imgscale;
  153. char *objid;
  154. bool objid_set;
  155. } htmlenv_t;
  156. extern htmllabel_t *parseHTML(char *, int *, htmlenv_t *);
  157. extern int make_html_label(void *obj, textlabel_t * lp);
  158. extern void emit_html_label(GVJ_t * job, htmllabel_t * lp, textlabel_t *);
  159. extern void free_html_label(htmllabel_t *, int);
  160. extern void free_html_data(htmldata_t *);
  161. extern void free_html_text(htmltxt_t *);
  162. extern boxf *html_port(node_t *n, char *pname, unsigned char *sides);
  163. #ifdef __cplusplus
  164. }
  165. #endif