[lasem] mathml_view: factorize apply_variant_to_font_description.
- From: Emmanuel Pacaud <emmanuel src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [lasem] mathml_view: factorize apply_variant_to_font_description.
- Date: Sun, 11 Dec 2011 14:20:11 +0000 (UTC)
commit 48148458e939bc3a2a61f7147b10d88b7068d45c
Author: Emmanuel Pacaud <emmanuel gnome org>
Date: Sun Dec 11 15:19:31 2011 +0100
mathml_view: factorize apply_variant_to_font_description.
src/lsmmathmlview.c | 93 +++++++++++++++++++++++----------------------------
1 files changed, 42 insertions(+), 51 deletions(-)
---
diff --git a/src/lsmmathmlview.c b/src/lsmmathmlview.c
index 93b0cb1..77cc273 100644
--- a/src/lsmmathmlview.c
+++ b/src/lsmmathmlview.c
@@ -56,8 +56,8 @@ static const struct {
{NULL, PANGO_STYLE_ITALIC, PANGO_WEIGHT_BOLD},
{LSM_MATHML_FONT_DOUBLE_STRUCK, PANGO_STYLE_NORMAL, PANGO_WEIGHT_NORMAL},
{NULL, PANGO_STYLE_NORMAL, PANGO_WEIGHT_NORMAL},
- {LSM_MATHML_FONT_SCRIPT, PANGO_STYLE_NORMAL, PANGO_WEIGHT_NORMAL},
- {LSM_MATHML_FONT_SCRIPT, PANGO_STYLE_NORMAL, PANGO_WEIGHT_BOLD},
+ {LSM_MATHML_FONT_SCRIPT, PANGO_STYLE_NORMAL, PANGO_WEIGHT_NORMAL},
+ {LSM_MATHML_FONT_SCRIPT, PANGO_STYLE_NORMAL, PANGO_WEIGHT_BOLD},
{NULL, PANGO_STYLE_NORMAL, PANGO_WEIGHT_NORMAL},
{LSM_MATHML_FONT_SANS, PANGO_STYLE_NORMAL, PANGO_WEIGHT_NORMAL},
{LSM_MATHML_FONT_SANS, PANGO_STYLE_NORMAL, PANGO_WEIGHT_BOLD},
@@ -69,13 +69,42 @@ static const struct {
static GObjectClass *parent_class;
static void
+lsm_mathml_view_apply_style_to_font_description (PangoFontDescription *font_description,
+ const LsmMathmlElementStyle *style,
+ gboolean set_family)
+{
+ g_return_if_fail (font_description != NULL);
+ g_return_if_fail (style != NULL);
+
+ if (style->math_variant < G_N_ELEMENTS (lsm_mathml_pango_options)) {
+ if (set_family) {
+ if (lsm_mathml_pango_options[style->math_variant].font == NULL)
+ pango_font_description_set_family (font_description, style->math_family);
+ else
+ pango_font_description_set_family (font_description,
+ lsm_mathml_pango_options[style->math_variant].font);
+ }
+ pango_font_description_set_style (font_description,
+ lsm_mathml_pango_options[style->math_variant].style);
+ pango_font_description_set_weight (font_description,
+ lsm_mathml_pango_options[style->math_variant].weight);
+ return;
+ }
+
+ if (set_family)
+ pango_font_description_set_family (font_description, style->math_family);
+ pango_font_description_set_style (font_description, PANGO_STYLE_NORMAL);
+ pango_font_description_set_weight (font_description, PANGO_WEIGHT_NORMAL);
+}
+
+static void
lsm_mathml_view_update_layout_for_text (LsmMathmlView *view,
- const LsmMathmlElementStyle *style,
- const char *text,
- PangoLayout *pango_layout,
- PangoRectangle *ink_rect,
- PangoRectangle *rect,
- int *baseline)
+ const LsmMathmlElementStyle *style,
+ const char *text,
+ PangoLayout *pango_layout,
+ PangoRectangle *ink_rect,
+ PangoRectangle *rect,
+ int *baseline)
{
PangoFontDescription *font_description;
@@ -94,21 +123,7 @@ lsm_mathml_view_update_layout_for_text (LsmMathmlView *view,
else
pango_font_description_set_weight (font_description, PANGO_WEIGHT_NORMAL);
} else {
- if (style->math_variant < G_N_ELEMENTS (lsm_mathml_pango_options)) {
- if (lsm_mathml_pango_options[style->math_variant].font == NULL)
- pango_font_description_set_family (font_description, style->math_family);
- else
- pango_font_description_set_family (font_description,
- lsm_mathml_pango_options[style->math_variant].font);
- pango_font_description_set_style (font_description,
- lsm_mathml_pango_options[style->math_variant].style);
- pango_font_description_set_weight (font_description,
- lsm_mathml_pango_options[style->math_variant].weight);
- } else {
- pango_font_description_set_family (font_description, style->math_family);
- pango_font_description_set_style (font_description, PANGO_STYLE_NORMAL);
- pango_font_description_set_weight (font_description, PANGO_WEIGHT_NORMAL);
- }
+ lsm_mathml_view_apply_style_to_font_description (font_description, style, TRUE);
}
pango_layout_set_text (pango_layout, text, -1);
pango_layout_set_font_description (pango_layout, font_description);
@@ -300,18 +315,10 @@ lsm_mathml_view_update_layout_for_operator (LsmMathmlView *view,
font_description = view->dom_view.font_description;
- pango_font_description_set_family (font_description, LSM_MATHML_FONT_SERIF);
pango_font_description_set_size (font_description,
style->math_size * PANGO_SCALE * (large ? LSM_MATHML_LARGE_OP_SCALE : 1.0));
- if (style->math_variant < G_N_ELEMENTS (lsm_mathml_pango_options)) {
- pango_font_description_set_style (font_description,
- lsm_mathml_pango_options[style->math_variant].style);
- pango_font_description_set_weight (font_description,
- lsm_mathml_pango_options[style->math_variant].weight);
- } else {
- pango_font_description_set_style (font_description, PANGO_STYLE_NORMAL);
- pango_font_description_set_weight (font_description, PANGO_WEIGHT_NORMAL);
- }
+ pango_font_description_set_family (font_description, LSM_MATHML_FONT_SERIF);
+ lsm_mathml_view_apply_style_to_font_description (font_description, style, FALSE);
pango_layout_set_text (pango_layout, text, -1);
pango_layout_set_font_description (pango_layout, font_description);
pango_layout_get_extents (pango_layout, ink_rect, rect);
@@ -391,15 +398,7 @@ lsm_mathml_view_measure_operator (LsmMathmlView *view,
for (; i < glyph->n_sized_glyphs; i++) {
font_name = lsm_mathml_font_names [glyph->sized_glyphs[i].font];
pango_font_description_set_family (font_description, font_name);
- if (style->math_variant < G_N_ELEMENTS (lsm_mathml_pango_options)) {
- pango_font_description_set_style (font_description,
- lsm_mathml_pango_options[style->math_variant].style);
- pango_font_description_set_weight (font_description,
- lsm_mathml_pango_options[style->math_variant].weight);
- } else {
- pango_font_description_set_style (font_description, PANGO_STYLE_NORMAL);
- pango_font_description_set_weight (font_description, PANGO_WEIGHT_NORMAL);
- }
+ lsm_mathml_view_apply_style_to_font_description (font_description, style, FALSE);
pango_layout_set_text (pango_layout, glyph->sized_glyphs[i].utf8, -1);
pango_layout_set_font_description (pango_layout, font_description);
pango_layout_get_extents (pango_layout, &ink_rect, NULL);
@@ -526,15 +525,7 @@ lsm_mathml_view_show_operator (LsmMathmlView *view,
for (; i < glyph->n_sized_glyphs; i++) {
font_name = lsm_mathml_font_names [glyph->sized_glyphs[i].font];
pango_font_description_set_family (font_description, font_name);
- if (style->math_variant < G_N_ELEMENTS (lsm_mathml_pango_options)) {
- pango_font_description_set_style (font_description,
- lsm_mathml_pango_options[style->math_variant].style);
- pango_font_description_set_weight (font_description,
- lsm_mathml_pango_options[style->math_variant].weight);
- } else {
- pango_font_description_set_style (font_description, PANGO_STYLE_NORMAL);
- pango_font_description_set_weight (font_description, PANGO_WEIGHT_NORMAL);
- }
+ lsm_mathml_view_apply_style_to_font_description (font_description, style, FALSE);
pango_layout_set_text (pango_layout, glyph->sized_glyphs[i].utf8, -1);
pango_layout_set_font_description (pango_layout, font_description);
pango_layout_get_extents (pango_layout, &ink_rect, NULL);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]