summaryrefslogtreecommitdiff
path: root/include/gmathcairo.h
blob: 2f5cd79ccf82d396486f6d972fd8c227166ed149 (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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/*
 * gMathLib, mathematic expressions handling library
 *
 *  # Pango/Cairo renderer header
 *
 * Author : Guillaume Seguin
 * Email : guillaume@segu.in
 *
 * Copyright (c) 2007 Guillaume Seguin <guillaume@segu.in>
 *
 * This program 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 2
 * 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, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA  02110-1301, USA.
 */

#ifndef _GMATHCAIRO_H
#define _GMATHCAIRO_H

#include <gmathlib.h>

#include <pango/pangocairo.h>
#include <cairo.h>

#define DEFAULT_FONT_SIZE   16.0f
#define DEFAULT_FONT_FAMILY "Sans"
#define EMPTY_LINE_WIDTH    2

typedef struct _GMathCairoContext GMathCairoContext;
typedef struct _GMathBox          GMathBox;
typedef struct _GMathBoxed        GMathBoxed;

typedef GMathBoxed* (*GMathCairoRenderProc) (GMathCairoContext *ccontext,
                                             GMathSymbol *symbol,
                                             float size);

struct _GMathCairoContext
{
    GMathContext    *context; /* Associated GMathContext */
    PangoContext    *pcr;     /* Pango context for text rendering */

    PangoFontDescription    *font_desc; /* Text font description */
    float                   main_size; /* Maximum size of the main symbols */

    GHashTable      *renderers; /* Symbol renderers */
    GHashTable      *chars_map; /* Special characters map */

    bool            editor_mode; /* Viewer/Editor mode switch */
};

struct _GMathBox
{
    int             width;
    int             height;
    int             x;
    int             y;
};

struct _GMathBoxed
{
    GMathSymbol     *symbol;
    GMathBoxed      *parent;
    GMathBox        box;
    GSList          *children;

    cairo_surface_t *surface;
};

/* GMathCairoContext methods */
GMathCairoContext*
gmathcairocontext_new (GMathContext *context);

void
gmathcairocontext_free (GMathCairoContext *ccontext);

bool
gmathcairocontext_register_renderer (GMathCairoContext *ccontext, gchar *name,
                                     GMathCairoRenderProc renderer);

bool
gmathcairocontext_register_special_char (GMathCairoContext *ccontext,
                                         gchar *name, gchar *value);

bool
gmathcairocontext_supported (GMathCairoContext *ccontext, gchar *name);

void
gmathcairocontext_set_main_size (GMathCairoContext *ccontext, float size);

void
gmathcairocontext_set_editor_mode (GMathCairoContext *ccontext,
                                   gboolean editor_mode);

/* Rendering methods */
GMathBoxed*
gmathcairo_render_symbol (GMathCairoContext *ccontext,
                          GMathSymbol *symbol,
                          float size);

cairo_surface_t*
gmathcairo_render (GMathCairoContext *ccontext, GMathFormula *formula);

GMathBoxed*
gmathcairo_render_boxed (GMathCairoContext *ccontext, GMathFormula *formula);

/* Helpers */
PangoLayout*
gmathcairo_make_layout (GMathCairoContext *ccontext, gchar *data, float size);

void
gmathcairo_get_layout_and_size (GMathCairoContext *ccontext,
                                gchar *data, float size,
                                PangoLayout **layout, int *width, int *height);

GMathBoxed**
gmathcairo_render_children_at_size (GMathCairoContext *ccontext,
                                    GMathSymbol *symbol, float size);

void
gmathcairo_get_surface_size (cairo_surface_t *surface, int *width, int *height);

GMathBoxed*
gmathcairo_render_cross_symbol (GMathCairoContext *ccontext, gchar *value,
                                GMathSymbol *lsymbol, GMathSymbol *rsymbol,
                                GMathSymbol *tsymbol, GMathSymbol *bsymbol,
                                float size, GMathSymbol *symbol);

GMathBoxed*
gmathcairo_render_empty (GMathCairoContext *ccontext, GMathSymbol *symbol,
                         float size);

/* GMathBoxed methods */
GMathBoxed*
gmathboxed_new (GMathSymbol *symbol);

void
gmathboxed_free (GMathBoxed *boxed);

void
gmathboxed_destroy_surface (GMathBoxed *boxed);

void
gmathboxed_resize (GMathBoxed *boxed, int width, int height);

void
gmathboxed_offset (GMathBoxed *boxed, int x, int y);

void
gmathboxed_add_child (GMathBoxed *boxed, GMathBoxed *child, int x, int y);

void
gmathboxed_rec_offset (GMathBoxed *boxed, int x, int y);

bool
gmathboxed_in (GMathBoxed *boxed, int x, int y);

bool
gmathboxed_inside (GMathBoxed *boxed, int x, int y, int width, int height);

GMathBoxed*
gmathboxed_find_smallest_container (GMathBoxed *boxed,
                                    int x, int y, int width, int height);


/* Internal methods */
void
gmathcairo_register_renderers (GMathCairoContext *ccontext);
void
gmathcairo_register_special_chars (GMathCairoContext *ccontext);

#endif