aboutsummaryrefslogtreecommitdiff
path: root/src/wrap.h
blob: 2f46233641f3934fdad5ecd27c5f9cc75878d9ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
 * wrap.h
 *
 * Text wrapping, hyphenation, justification and shaping
 *
 * Copyright © 2014 Thomas White <taw@bitwiz.org.uk>
 *
 * This file is part of Colloquium.
 *
 * Colloquium is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#ifndef WRAP_H
#define WRAP_H

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include "frame.h"
#include "presentation.h"


enum wrap_box_type
{
	WRAP_BOX_NOTHING,
	WRAP_BOX_SENTINEL,
	WRAP_BOX_PANGO,
	WRAP_BOX_IMAGE,
	WRAP_BOX_SURFACE
};


/* Possible types of space following a wrap box */
enum wrap_box_space
{
	WRAP_SPACE_INTERWORD,  /* Normal inter-word space */
	WRAP_SPACE_NONE,       /* Box ends with an explicit hyphen or an SC
	                        * block boundary */
	WRAP_SPACE_EOP         /* End of paragraph */
	/* TODO: Space between sentences etc */
};


/* A wrap box is a run of content - could be text, an image or so one - that is
 * one logical unit as far as Colloquium is concerned.  It might consist of
 * multiple units, for example, in Pango's mind. */
struct wrap_box
{
	enum wrap_box_type type;
	int editable;

	SCBlock *scblock;
	int offs_char;  /* offset (in characters, not bytes) into scblock */

	/* Pango units */
	int width;
	int height;
	int ascent;

	enum wrap_box_space space;  /* Type of "space" following box */
	double sp;  /* Calculated space (Pango units) after box */

	/* For type == WRAP_BOX_PANGO */
	PangoGlyphString *glyphs;
	PangoItem *item;
	PangoFont *font;
	double col[4];  /* rgba colour */
	int len_chars;

	/* For type == WRAP_BOX_IMAGE */
	char *filename;

	/* For type == WRAP_BOX_SURFACE */
	cairo_surface_t *surf;
};


struct wrap_line
{
	int width;   /* Pango units */
	int height;  /* Pango units */
	int ascent;  /* Pango units */

	int n_boxes;
	int max_boxes;
	struct wrap_box *boxes;

	int overfull;
	int underfull;
	int last_line;
};


extern int wrap_contents(struct frame *fr);

extern void get_cursor_pos(struct wrap_box *box, int pos,
                           double *xposd, double *yposd, double *line_height);

extern void find_cursor(struct frame *fr, double xposd, double yposd,
                        int *line, int *box, int *pos);

extern void alloc_boxes(struct wrap_line *l);
extern void initialise_line(struct wrap_line *l);

extern void wrap_line_free(struct wrap_line *l);
extern void show_boxes(struct wrap_line *boxes);

#endif	/* WRAP_H */