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