fix build for --disable-gtk-doc
[swfdec.git] / swfdec / swfdec_text_attributes.c
blobc4739a8826d1022cfc5240c19ab712a5eede0f7a
1 /* Swfdec
2 * Copyright (C) 2007-2008 Benjamin Otte <otte@gnome.org>
3 * 2007 Pekka Lampila <pekka.lampila@iki.fi>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301 USA
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
25 #include <string.h>
26 #include "swfdec_text_attributes.h"
27 #include "swfdec_as_context.h"
28 #include "swfdec_as_strings.h"
29 #include "swfdec_debug.h"
31 void
32 swfdec_text_attributes_reset (SwfdecTextAttributes *attr)
34 g_free (attr->tab_stops);
36 attr->align = SWFDEC_TEXT_ALIGN_LEFT;
37 attr->block_indent = 0;
38 attr->bold = FALSE;
39 attr->bullet = FALSE;
40 attr->color = 0;
41 attr->display = SWFDEC_TEXT_DISPLAY_BLOCK;
42 attr->font = SWFDEC_AS_STR_Times_New_Roman;
43 attr->indent = 0;
44 attr->italic = FALSE;
45 attr->kerning = FALSE;
46 attr->leading = 0;
47 attr->left_margin = 0;
48 attr->letter_spacing = 0;
49 attr->right_margin = 0;
50 attr->size = 12;
51 attr->tab_stops = NULL;
52 attr->n_tab_stops = 0;
53 attr->target = SWFDEC_AS_STR_EMPTY;
54 attr->url = SWFDEC_AS_STR_EMPTY;
55 attr->underline = FALSE;
58 void
59 swfdec_text_attributes_copy (SwfdecTextAttributes *attr, const SwfdecTextAttributes *from,
60 guint flags)
62 if (SWFDEC_TEXT_ATTRIBUTE_IS_SET (flags, SWFDEC_TEXT_ATTRIBUTE_ALIGN))
63 attr->align = from->align;
64 if (SWFDEC_TEXT_ATTRIBUTE_IS_SET (flags, SWFDEC_TEXT_ATTRIBUTE_BLOCK_INDENT))
65 attr->block_indent = from->block_indent;
66 if (SWFDEC_TEXT_ATTRIBUTE_IS_SET (flags, SWFDEC_TEXT_ATTRIBUTE_BOLD))
67 attr->bold = from->bold;
68 if (SWFDEC_TEXT_ATTRIBUTE_IS_SET (flags, SWFDEC_TEXT_ATTRIBUTE_BULLET))
69 attr->bullet = from->bullet;
70 if (SWFDEC_TEXT_ATTRIBUTE_IS_SET (flags, SWFDEC_TEXT_ATTRIBUTE_COLOR))
71 attr->color = from->color;
72 if (SWFDEC_TEXT_ATTRIBUTE_IS_SET (flags, SWFDEC_TEXT_ATTRIBUTE_DISPLAY))
73 attr->display = from->display;
74 if (SWFDEC_TEXT_ATTRIBUTE_IS_SET (flags, SWFDEC_TEXT_ATTRIBUTE_FONT))
75 attr->font = from->font;
76 if (SWFDEC_TEXT_ATTRIBUTE_IS_SET (flags, SWFDEC_TEXT_ATTRIBUTE_INDENT))
77 attr->indent = from->indent;
78 if (SWFDEC_TEXT_ATTRIBUTE_IS_SET (flags, SWFDEC_TEXT_ATTRIBUTE_ITALIC))
79 attr->italic = from->italic;
80 if (SWFDEC_TEXT_ATTRIBUTE_IS_SET (flags, SWFDEC_TEXT_ATTRIBUTE_KERNING))
81 attr->kerning = from->kerning;
82 if (SWFDEC_TEXT_ATTRIBUTE_IS_SET (flags, SWFDEC_TEXT_ATTRIBUTE_LEADING))
83 attr->leading = from->leading;
84 if (SWFDEC_TEXT_ATTRIBUTE_IS_SET (flags, SWFDEC_TEXT_ATTRIBUTE_LEFT_MARGIN))
85 attr->left_margin = from->left_margin;
86 if (SWFDEC_TEXT_ATTRIBUTE_IS_SET (flags, SWFDEC_TEXT_ATTRIBUTE_LETTER_SPACING))
87 attr->letter_spacing = from->letter_spacing;
88 if (SWFDEC_TEXT_ATTRIBUTE_IS_SET (flags, SWFDEC_TEXT_ATTRIBUTE_RIGHT_MARGIN))
89 attr->right_margin = from->right_margin;
90 if (SWFDEC_TEXT_ATTRIBUTE_IS_SET (flags, SWFDEC_TEXT_ATTRIBUTE_SIZE))
91 attr->size = from->size;
92 if (SWFDEC_TEXT_ATTRIBUTE_IS_SET (flags, SWFDEC_TEXT_ATTRIBUTE_TAB_STOPS)) {
93 g_free (attr->tab_stops);
94 attr->tab_stops = g_memdup (from->tab_stops, sizeof (guint) * from->n_tab_stops);
95 attr->n_tab_stops = from->n_tab_stops;
97 if (SWFDEC_TEXT_ATTRIBUTE_IS_SET (flags, SWFDEC_TEXT_ATTRIBUTE_TARGET))
98 attr->target = from->target;
99 if (SWFDEC_TEXT_ATTRIBUTE_IS_SET (flags, SWFDEC_TEXT_ATTRIBUTE_UNDERLINE))
100 attr->underline = from->underline;
101 if (SWFDEC_TEXT_ATTRIBUTE_IS_SET (flags, SWFDEC_TEXT_ATTRIBUTE_URL))
102 attr->url = from->url;
105 void
106 swfdec_text_attributes_mark (SwfdecTextAttributes *attr)
108 swfdec_as_string_mark (attr->font);
109 swfdec_as_string_mark (attr->target);
110 swfdec_as_string_mark (attr->url);
113 guint
114 swfdec_text_attributes_diff (const SwfdecTextAttributes *a, const SwfdecTextAttributes *b)
116 guint result = 0;
118 if (a->align != b->align)
119 SWFDEC_TEXT_ATTRIBUTE_SET (result, SWFDEC_TEXT_ATTRIBUTE_ALIGN);
120 if (a->block_indent != b->block_indent)
121 SWFDEC_TEXT_ATTRIBUTE_SET (result, SWFDEC_TEXT_ATTRIBUTE_BLOCK_INDENT);
122 if (a->bold != b->bold)
123 SWFDEC_TEXT_ATTRIBUTE_SET (result, SWFDEC_TEXT_ATTRIBUTE_BOLD);
124 if (a->bullet != b->bullet)
125 SWFDEC_TEXT_ATTRIBUTE_SET (result, SWFDEC_TEXT_ATTRIBUTE_BULLET);
126 if (a->color != b->color)
127 SWFDEC_TEXT_ATTRIBUTE_SET (result, SWFDEC_TEXT_ATTRIBUTE_COLOR);
128 if (a->display != b->display)
129 SWFDEC_TEXT_ATTRIBUTE_SET (result, SWFDEC_TEXT_ATTRIBUTE_DISPLAY);
130 if (a->font != b->font)
131 SWFDEC_TEXT_ATTRIBUTE_SET (result, SWFDEC_TEXT_ATTRIBUTE_FONT);
132 if (a->indent != b->indent)
133 SWFDEC_TEXT_ATTRIBUTE_SET (result, SWFDEC_TEXT_ATTRIBUTE_INDENT);
134 if (a->italic != b->italic)
135 SWFDEC_TEXT_ATTRIBUTE_SET (result, SWFDEC_TEXT_ATTRIBUTE_ITALIC);
136 if (a->kerning != b->kerning)
137 SWFDEC_TEXT_ATTRIBUTE_SET (result, SWFDEC_TEXT_ATTRIBUTE_KERNING);
138 if (a->leading != b->leading)
139 SWFDEC_TEXT_ATTRIBUTE_SET (result, SWFDEC_TEXT_ATTRIBUTE_LEADING);
140 if (a->left_margin != b->left_margin)
141 SWFDEC_TEXT_ATTRIBUTE_SET (result, SWFDEC_TEXT_ATTRIBUTE_LEFT_MARGIN);
142 if (a->letter_spacing != b->letter_spacing)
143 SWFDEC_TEXT_ATTRIBUTE_SET (result, SWFDEC_TEXT_ATTRIBUTE_LETTER_SPACING);
144 if (a->right_margin != b->right_margin)
145 SWFDEC_TEXT_ATTRIBUTE_SET (result, SWFDEC_TEXT_ATTRIBUTE_RIGHT_MARGIN);
146 if (a->size != b->size)
147 SWFDEC_TEXT_ATTRIBUTE_SET (result, SWFDEC_TEXT_ATTRIBUTE_SIZE);
148 if (a->n_tab_stops != b->n_tab_stops)
149 SWFDEC_TEXT_ATTRIBUTE_SET (result, SWFDEC_TEXT_ATTRIBUTE_TAB_STOPS);
150 else if (a->n_tab_stops != 0 &&
151 memcmp (a->tab_stops, b->tab_stops, sizeof (guint) & a->n_tab_stops) != 0)
152 SWFDEC_TEXT_ATTRIBUTE_SET (result, SWFDEC_TEXT_ATTRIBUTE_TAB_STOPS);
153 if (a->target != b->target)
154 SWFDEC_TEXT_ATTRIBUTE_SET (result, SWFDEC_TEXT_ATTRIBUTE_TARGET);
155 if (a->underline != b->underline)
156 SWFDEC_TEXT_ATTRIBUTE_SET (result, SWFDEC_TEXT_ATTRIBUTE_UNDERLINE);
157 if (a->url != b->url)
158 SWFDEC_TEXT_ATTRIBUTE_SET (result, SWFDEC_TEXT_ATTRIBUTE_URL);
160 return result;