1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ 2 /* This file is part of the KDE libraries 3 * 4 * Copyright (C) 1997 Martin Jones (mjones@kde.org) 5 * Copyright (C) 1997 Torben Weis (weis@kde.org) 6 * Copyright (C) 1999, 2000, 2001 Helix Code, Inc. 7 * 8 * This library is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU Library General Public 10 * License as published by the Free Software Foundation; either 11 * version 2 of the License, or (at your option) any later version. 12 * 13 * This library is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 * Library General Public License for more details. 17 * 18 * You should have received a copy of the GNU Library General Public License 19 * along with this library; see the file COPYING.LIB. If not, write to 20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 21 * Boston, MA 02110-1301, USA. 22 */ 23 #ifndef _HTMLTEXT_H_ 24 #define _HTMLTEXT_H_ 25 26 #include "htmlobject.h" 27 28 #define HTML_TEXT(x) ((HTMLText *)(x)) 29 #define HTML_TEXT_CLASS(x) ((HTMLTextClass *)(x)) 30 #define HTML_IS_TEXT(x) (HTML_CHECK_TYPE ((x), HTML_TYPE_TEXT)) 31 32 struct _SpellError { 33 guint off; 34 guint len; 35 }; 36 37 struct _Link { 38 guint start_index; 39 guint end_index; 40 gint start_offset; 41 gint end_offset; 42 gchar *url; 43 gchar *target; 44 gboolean is_visited; 45 }; 46 47 struct _HTMLTextPangoInfoEntry { 48 PangoGlyphItem glyph_item; 49 PangoGlyphUnit *widths; 50 }; 51 52 struct _HTMLTextPangoInfo { 53 HTMLTextPangoInfoEntry *entries; 54 PangoLogAttr *attrs; 55 gint n; 56 57 gboolean have_font; 58 GtkHTMLFontStyle font_style; 59 HTMLFontFace *face; 60 }; 61 62 struct _HTMLPangoAttrFontSize { 63 PangoAttrInt attr_int; 64 GtkHTMLFontStyle style; 65 }; 66 67 struct _HTMLText { 68 HTMLObject object; 69 70 /* utf-8 encoded text */ 71 gchar *text; 72 73 /* text length in charactes */ 74 guint text_len; 75 76 /* text length in bytes */ 77 guint text_bytes; 78 79 PangoAttrList *attr_list; 80 PangoAttrList *extra_attr_list; 81 GtkHTMLFontStyle font_style; 82 HTMLFontFace *face; 83 HTMLColor *color; 84 85 guint select_start; 86 guint select_length; 87 88 GList *spell_errors; 89 90 HTMLTextPangoInfo *pi; 91 92 GSList *links; 93 gint focused_link_offset; 94 PangoDirection direction; 95 }; 96 97 struct _HTMLTextClass { 98 HTMLObjectClass object_class; 99 100 void (* queue_draw) (HTMLText *text, HTMLEngine *engine, 101 guint offset, guint len); 102 103 GtkHTMLFontStyle (* get_font_style) (const HTMLText *text); 104 void (* set_font_style) (HTMLText *text, HTMLEngine *engine, GtkHTMLFontStyle style); 105 }; 106 107 extern HTMLTextClass html_text_class; 108 109 void html_text_type_init (void); 110 void html_text_class_init (HTMLTextClass *klass, 111 HTMLType type, 112 guint object_size); 113 void html_text_init (HTMLText *text_object, 114 HTMLTextClass *klass, 115 const gchar *text, 116 gint len, 117 GtkHTMLFontStyle font_style, 118 HTMLColor *color); 119 HTMLObject *html_text_new (const gchar *text, 120 GtkHTMLFontStyle font_style, 121 HTMLColor *color); 122 HTMLObject *html_text_new_with_len (const gchar *text, 123 gint len, 124 GtkHTMLFontStyle font_style, 125 HTMLColor *color); 126 void html_text_change_set (HTMLText *text, 127 HTMLChangeFlags flags); 128 void html_text_queue_draw (HTMLText *text, 129 HTMLEngine *engine, 130 guint offset, 131 guint len); 132 GtkHTMLFontStyle html_text_get_font_style (const HTMLText *text); 133 void html_text_set_font_style (HTMLText *text, 134 HTMLEngine *engine, 135 GtkHTMLFontStyle style); 136 void html_text_append (HTMLText *text, 137 const gchar *str, 138 gint len); 139 void html_text_set_text (HTMLText *text, 140 const gchar *new_text); 141 void html_text_set_font_face (HTMLText *text, 142 HTMLFontFace *face); 143 gint html_text_get_nb_width (HTMLText *text, 144 HTMLPainter *painter, 145 gboolean begin); 146 guint html_text_get_bytes (HTMLText *text); 147 guint html_text_get_index (HTMLText *text, 148 guint offset); 149 gunichar html_text_get_char (HTMLText *text, 150 guint offset); 151 gchar *html_text_get_text (HTMLText *text, 152 guint offset); 153 GList *html_text_get_items (HTMLText *text, 154 HTMLPainter *painter); 155 void html_text_spell_errors_clear (HTMLText *text); 156 void html_text_spell_errors_clear_interval (HTMLText *text, 157 HTMLInterval *i); 158 void html_text_spell_errors_add (HTMLText *text, 159 guint off, 160 guint len); 161 gboolean html_text_magic_link (HTMLText *text, 162 HTMLEngine *engine, 163 guint offset); 164 gint html_text_trail_space_width (HTMLText *text, 165 HTMLPainter *painter); 166 gboolean html_text_convert_nbsp (HTMLText *text, 167 gboolean free_text); 168 gint html_text_get_line_offset (HTMLText *text, 169 HTMLPainter *painter, 170 gint offset); 171 gint html_text_text_line_length (const gchar *text, 172 gint *line_offset, 173 guint len, 174 gint *tabs); 175 gint html_text_calc_part_width (HTMLText *text, 176 HTMLPainter *painter, 177 gchar *start, 178 gint offset, 179 gint len, 180 gint *asc, 181 gint *dsc); 182 gint html_text_get_item_index (HTMLText *text, 183 HTMLPainter *painter, 184 gint offset, 185 gint *item_offset); 186 gboolean html_text_pi_backward (HTMLTextPangoInfo *pi, 187 gint *ii, 188 gint *io); 189 gboolean html_text_pi_forward (HTMLTextPangoInfo *pi, 190 gint *ii, 191 gint *io); 192 void html_text_free_attrs (GSList *attrs); 193 gint html_text_tail_white_space (HTMLText *text, 194 HTMLPainter *painter, 195 gint offset, 196 gint ii, 197 gint io, 198 gint *white_len, 199 gint line_offset, 200 gchar *s); 201 void html_text_append_link (HTMLText *text, 202 gchar *url, 203 gchar *target, 204 gint start_offset, 205 gint end_offset); 206 void html_text_append_link_full (HTMLText *text, 207 gchar *url, 208 gchar *target, 209 gint start_index, 210 gint end_index, 211 gint start_offset, 212 gint end_offset); 213 void html_text_add_link (HTMLText *text, 214 HTMLEngine *e, 215 gchar *url, 216 gchar *target, 217 gint start_offset, 218 gint end_offset); 219 void html_text_add_link_full (HTMLText *text, 220 HTMLEngine *e, 221 gchar *url, 222 gchar *target, 223 gint start_index, 224 gint end_index, 225 gint start_offset, 226 gint end_offset); 227 void html_text_set_link_visited (HTMLText *text, 228 gint offset, 229 HTMLEngine *engine, 230 gboolean is_visited); 231 void html_text_remove_links (HTMLText *text); 232 gboolean html_text_get_link_rectangle (HTMLText *text, 233 HTMLPainter *painter, 234 gint offset, 235 gint *x1, 236 gint *y1, 237 gint *x2, 238 gint *y2); 239 Link *html_text_get_link_at_offset (HTMLText *text, 240 gint offset); 241 HTMLTextSlave *html_text_get_slave_at_offset (HTMLText *text, 242 HTMLTextSlave *start, 243 gint offset); 244 Link *html_text_get_link_slaves_at_offset (HTMLText *text, 245 gint offset, 246 HTMLTextSlave **start, 247 HTMLTextSlave **end); 248 gboolean html_text_next_link_offset (HTMLText *text, 249 gint *offset); 250 gboolean html_text_prev_link_offset (HTMLText *text, 251 gint *offset); 252 gboolean html_text_first_link_offset (HTMLText *text, 253 gint *offset); 254 gboolean html_text_last_link_offset (HTMLText *text, 255 gint *offset); 256 gchar *html_text_get_link_text (HTMLText *text, 257 gint offset); 258 void html_text_calc_font_size (HTMLText *text, 259 HTMLEngine *e); 260 GtkHTMLFontStyle html_text_get_fontstyle_at_index (HTMLText *text, 261 gint index); 262 GtkHTMLFontStyle html_text_get_style_conflicts (HTMLText *text, 263 GtkHTMLFontStyle style, 264 gint start_index, 265 gint end_index); 266 void html_text_set_style_in_range (HTMLText *text, 267 GtkHTMLFontStyle style, 268 HTMLEngine *e, 269 gint start_index, 270 gint end_index); 271 void html_text_set_style (HTMLText *text, 272 GtkHTMLFontStyle style, 273 HTMLEngine *e); 274 void html_text_unset_style (HTMLText *text, 275 GtkHTMLFontStyle style); 276 HTMLColor *html_text_get_color_at_index (HTMLText *text, 277 HTMLEngine *e, 278 gint index); 279 HTMLColor *html_text_get_color (HTMLText *text, 280 HTMLEngine *e, 281 gint start_index); 282 void html_text_set_color_in_range (HTMLText *text, 283 HTMLColor *color, 284 gint start_index, 285 gint end_index); 286 void html_text_set_color (HTMLText *text, 287 HTMLColor *color); 288 289 gsize html_text_sanitize (const gchar *str_in, 290 gchar **str_out, 291 gint *len); 292 293 Link *html_link_new (gchar *url, 294 gchar *target, 295 guint start_index, 296 guint end_index, 297 gint start_offset, 298 gint end_offset, 299 gboolean is_visited); 300 Link *html_link_dup (Link *link); 301 void html_link_free (Link *link); 302 gboolean html_link_equal (Link *l1, 303 Link *l2); 304 void html_link_set_url_and_target (Link *link, 305 gchar *url, 306 gchar *target); 307 308 /* 309 * protected 310 */ 311 HTMLTextPangoInfo *html_text_pango_info_new (gint n); 312 void html_text_pango_info_destroy (HTMLTextPangoInfo *pi); 313 HTMLTextPangoInfo *html_text_get_pango_info (HTMLText *text, 314 HTMLPainter *painter); 315 gint html_text_pango_info_get_index (HTMLTextPangoInfo *pi, 316 gint byte_offset, 317 gint idx); 318 PangoAttribute *html_pango_attr_font_size_new (GtkHTMLFontStyle style); 319 void html_pango_attr_font_size_calc (HTMLPangoAttrFontSize *attr, 320 HTMLEngine *e); 321 PangoAttrList *html_text_get_attr_list (HTMLText *text, 322 gint start_index, 323 gint end_index); 324 void html_text_calc_text_size (HTMLText *t, 325 HTMLPainter *painter, 326 gint start_byte_offset, 327 guint len, 328 HTMLTextPangoInfo *pi, 329 GList *glyphs, 330 gint *line_offset, 331 gint *width, 332 gint *asc, 333 gint *dsc); 334 void html_text_change_attrs (PangoAttrList *attr_list, 335 GtkHTMLFontStyle style, 336 HTMLEngine *e, 337 gint start_index, 338 gint end_index, 339 gboolean avoid_default_size); 340 PangoDirection html_text_get_pango_direction (HTMLText *text); 341 HTMLDirection html_text_direction_pango_to_html (PangoDirection pdir); 342 343 gboolean html_text_is_line_break (PangoLogAttr attr); 344 void html_text_remove_unwanted_line_breaks (gchar *s, 345 gint len, 346 PangoLogAttr *attrs); 347 348 typedef HTMLObject * (* HTMLTextHelperFunc) (HTMLText *, gint begin, gint end); 349 HTMLObject *html_text_op_copy_helper (HTMLText *text, 350 GList *from, 351 GList *to, 352 guint *len); 353 HTMLObject *html_text_op_cut_helper (HTMLText *text, 354 HTMLEngine *e, 355 GList *from, 356 GList *to, 357 GList *left, 358 GList *right, 359 guint *len); 360 void 361 html_tmp_fix_pango_glyph_string_get_logical_widths (PangoGlyphString *glyphs, 362 const gchar *text, 363 gint length, 364 gint embedding_level, 365 gint *logical_widths); 366 367 PangoAttrList *html_text_prepare_attrs (HTMLText *text, 368 HTMLPainter *painter); 369 370 #endif /* _HTMLTEXT_H_ */ 371