offset fixes, admit to textline, proper updating of height/font at attr set,
[dia.git] / lib / font.h
blobe6c8ca1a646662e6c506549881afceab4fb8ec7e
1 /* Dia -- an diagram creation/manipulation program
2 * Copyright (C) 1998 Alexander Larsson
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 #ifndef FONT_H
19 #define FONT_H
21 #include "diatypes.h"
22 #include <glib.h>
23 #include <glib-object.h>
24 #include <pango/pango.h>
25 #include "dia-enums.h"
26 #include "geometry.h"
27 #include "diavar.h"
29 /* Do NOT put these strings through the .po mechanism. If you need to add
30 non-Roman alternatives, please insert them in the list */
31 #define BASIC_SANS_FONT "arial, helvetica, helv, sans"
32 #define BASIC_SERIF_FONT "times new roman, times, serif"
33 #define BASIC_MONOSPACE_FONT "courier new, courier, monospace, fixed"
36 /**
37 * In a goodly selection of fonts, 500 is very common, yet Pango doesn't name it.
38 * I am calling 500 'medium' and 600 'demibold'.
39 * We should really have a more flexible system where 300 or 400 is normal,
40 * the next one up bold, or something. But this will do for now.
41 * We should probably store the actual weight...
44 /* We are having DIA_FONT_WEIGHT_NORMAL be 0 to avoid having to do
45 * DIA_FONT_MONOSPACE | DIA_FONT_WEIGHT_NORMAL all over the place.
46 * This introduces a few hacks in font.c and widgets.c, but not too
47 * many.
50 /* storing different style info like
51 * (DIA_FONT_SANS | DIA_FONT_ITALIC | DIA_FONT_BOLD)
53 typedef guint DiaFontStyle;
55 typedef enum
57 DIA_FONT_FAMILY_ANY = 0,
58 DIA_FONT_SANS = 1,
59 DIA_FONT_SERIF = 2,
60 DIA_FONT_MONOSPACE = 3
61 } DiaFontFamily;
63 typedef enum
65 DIA_FONT_NORMAL = (0<<2),
66 DIA_FONT_OBLIQUE = (1<<2),
67 DIA_FONT_ITALIC = (2<<2)
68 } DiaFontSlant;
70 typedef enum
72 DIA_FONT_ULTRALIGHT = (1<<4),
73 DIA_FONT_LIGHT = (2<<4),
74 DIA_FONT_WEIGHT_NORMAL = (0<<4), /* Deliberately 0 for DIA_FONT_NORMAL */
75 DIA_FONT_MEDIUM = (3<<4),
76 DIA_FONT_DEMIBOLD = (4<<4),
77 DIA_FONT_BOLD = (5<<4),
78 DIA_FONT_ULTRABOLD = (6<<4),
79 DIA_FONT_HEAVY = (7<<4)
80 } DiaFontWeight;
82 /* macros to get a specific style info */
83 #define DIA_FONT_STYLE_GET_FAMILY(st) ((st) & (0x3))
84 #define DIA_FONT_STYLE_GET_SLANT(st) ((st) & (0x3<<2))
85 #define DIA_FONT_STYLE_GET_WEIGHT(st) ((st) & (0x7<<4))
87 GType dia_font_get_type(void) G_GNUC_CONST;
89 #define DIA_TYPE_FONT (dia_font_get_type())
91 #define DIA_FONT(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), \
92 DIA_TYPE_FONT, \
93 DiaFont))
94 #define DIA_FONT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), \
95 DIA_TYPE_FONT, \
96 DiaFontClass))
98 struct _DiaFontClass {
99 GObjectClass parent_class;
102 /* Set the PangoContext used to render text.
104 void dia_font_init(PangoContext* pcontext);
105 /* Start using a new context (for AA rendering) */
106 void dia_font_push_context(PangoContext *pcontext);
107 /* Go back to using the old context */
108 void dia_font_pop_context(void);
109 /* Retrieve the current context (used for the font widget) */
110 PangoContext *dia_font_get_context(void);
113 /* Get a font matching family,style,height. MUST be freed with
114 dia_font_unref(). */
115 DiaFont* dia_font_new(const char *family, DiaFontStyle style,
116 real height);
118 /* Get a font matching style. This is the preferred method to
119 * create default fonts within objects. */
120 DiaFont* dia_font_new_from_style(DiaFontStyle style, real height);
122 /* Get a font from a legacy font name */
123 DiaFont* dia_font_new_from_legacy_name(const char *name);
125 /* Get a simple font name from a font.
126 Name will be valid for the duration of the DiaFont* lifetime. */
127 G_CONST_RETURN char* dia_font_get_legacy_name(const DiaFont* font);
129 /* Same attributes */
130 DiaFont *dia_font_copy(const DiaFont* font);
132 DiaFont* dia_font_ref(DiaFont* font);
133 void dia_font_unref(DiaFont* font);
135 /* Retrieves the style of the font */
136 DiaFontStyle dia_font_get_style(const DiaFont* font);
138 /* Retrieves the family of the font. Caller must NOT free. */
139 G_CONST_RETURN char* dia_font_get_family(const DiaFont* font);
140 /* Acessor for the PangoFontDescription */
141 G_CONST_RETURN PangoFontDescription *dia_font_get_description (const DiaFont* font);
143 /* Retrieves the height of the font */
144 real dia_font_get_height(const DiaFont* font);
145 /* Change the height inside a font record. */
146 void dia_font_set_height(DiaFont* font, real height);
148 /* Changes the slant of an existing font */
149 void dia_font_set_slant(DiaFont* font, DiaFontSlant slant);
150 /* Changes the weight of an existing font */
151 void dia_font_set_weight(DiaFont* font, DiaFontWeight weight);
152 /* Changes the family of an existing font to one of the three standard
153 families */
154 void dia_font_set_family(DiaFont* font, DiaFontFamily family);
155 /* Changes the family of an existing font to any family, but the name could
156 be system-dependent. */
157 void dia_font_set_any_family(DiaFont* font, const char* family);
159 /* FIXME: what do we do with this, actually ?
160 Name lives for as long as the DiaFont lives. */
161 G_CONST_RETURN char *dia_font_get_psfontname(const DiaFont *font);
163 /* returns a static string suitable for SVG */
164 G_CONST_RETURN char *dia_font_get_weight_string(const DiaFont* font);
166 /* returns a static string suitable for SVG */
167 G_CONST_RETURN char *dia_font_get_slant_string(const DiaFont* font);
169 /* uses an SVG style string */
170 void dia_font_set_weight_from_string(DiaFont* font, const char* weight);
172 /* uses an SVG style string */
173 void dia_font_set_slant_from_string(DiaFont* font, const char* slant);
175 /* -------- Font and string functions - unscaled versions.
176 Use these version in Objects, primarily. */
178 /* Get the width of the string with the given font in cm */
179 real dia_font_string_width(const char* string, DiaFont* font,
180 real height);
181 /* Get the ascent of this string in cm (a positive number). */
182 real dia_font_ascent(const char* string, DiaFont* font, real height);
183 /* Get the descent of the font in cm (a positive number) */
184 real dia_font_descent(const char* string, DiaFont* font, real height);
186 /* prepares a layout of the text, in font 'font'. */
187 PangoLayout* dia_font_build_layout(const char* string, DiaFont* font,
188 real height);
189 /* prepares a layout of the text, in font 'font' scaled by matrix. */
190 PangoLayout* dia_font_build_layout_with_matrix(const char* string,
191 DiaFont* font,
192 real height,
193 PangoMatrix *matrix);
195 real* dia_font_get_sizes(const char* string, DiaFont *font, real height,
196 real* width, real* ascent, real* descent,
197 int *n_offsets, PangoLayoutLine **layout_offsets);
199 /* -------- Font and string functions - scaled versions.
200 Use these version in Renderers, exclusively. */
202 /* Call once at the beginning of a rendering pass, to let dia know
203 what is 1:1 scale. zoom_factor will then be divided by size_one. */
204 void dia_font_set_nominal_zoom_factor(real size_one);
207 #endif /* FONT_H */