mathematical 0.6.2 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +48 -12
  3. data/Rakefile +3 -2
  4. data/ext/mathematical/cairo_callbacks.c +25 -0
  5. data/ext/mathematical/cairo_callbacks.h +7 -0
  6. data/ext/mathematical/extconf.rb +11 -11
  7. data/ext/mathematical/lasem/src/lsmmathmldocument.c +3 -0
  8. data/ext/mathematical/lasem/src/lsmmathmlencloseelement.c +142 -0
  9. data/ext/mathematical/lasem/src/lsmmathmlencloseelement.h +64 -0
  10. data/ext/mathematical/lasem/src/lsmmathmlenums.c +35 -0
  11. data/ext/mathematical/lasem/src/lsmmathmlenums.h +25 -1
  12. data/ext/mathematical/lasem/src/lsmmathmlpaddedelement.c +79 -0
  13. data/ext/mathematical/lasem/src/lsmmathmlpaddedelement.h +5 -0
  14. data/ext/mathematical/lasem/src/lsmmathmlstyleelement.c +6 -0
  15. data/ext/mathematical/lasem/src/lsmmathmltableelement.c +5 -5
  16. data/ext/mathematical/lasem/src/lsmmathmltraits.c +24 -0
  17. data/ext/mathematical/lasem/src/lsmmathmltraits.h +1 -0
  18. data/ext/mathematical/lasem/src/lsmmathmltypes.h +1 -0
  19. data/ext/mathematical/lasem/src/lsmmathmlutils.h +9 -2
  20. data/ext/mathematical/lasem/src/lsmmathmlview.c +283 -11
  21. data/ext/mathematical/lasem/src/lsmmathmlview.h +13 -0
  22. data/ext/mathematical/lasem_overrides.c +40 -0
  23. data/ext/mathematical/lasem_overrides.h +23 -0
  24. data/ext/mathematical/mathematical.c +119 -127
  25. data/ext/mathematical/mathematical.h +24 -0
  26. data/ext/mathematical/mtex2MML/ext/extconf.rb +1 -1
  27. data/ext/mathematical/mtex2MML/src/lex.yy.c +4488 -4032
  28. data/ext/mathematical/mtex2MML/src/mtex2MML.h +3 -0
  29. data/ext/mathematical/mtex2MML/src/parse_extras.c +14 -5
  30. data/ext/mathematical/mtex2MML/src/parse_extras.h +3 -1
  31. data/ext/mathematical/mtex2MML/src/string_extras.c +39 -0
  32. data/ext/mathematical/mtex2MML/src/string_extras.h +7 -0
  33. data/ext/mathematical/mtex2MML/src/y.tab.c +4408 -3175
  34. data/ext/mathematical/mtex2MML/src/y.tab.h +500 -422
  35. data/lib/mathematical.rb +112 -2
  36. data/lib/mathematical/corrections.rb +2 -2
  37. data/lib/mathematical/version.rb +2 -2
  38. data/mathematical.gemspec +4 -4
  39. data/test/mathematical/basic_test.rb +1 -1
  40. data/test/mathematical/corrections_test.rb +1 -1
  41. data/test/mathematical/fixtures/png/numeric_test_1.png +0 -0
  42. data/test/mathematical/fixtures/png/numeric_test_2.png +0 -0
  43. data/test/mathematical/fixtures/png/numeric_test_3.png +0 -0
  44. data/test/mathematical/fixtures_test.rb +7 -7
  45. data/test/mathematical/maliciousness_test.rb +44 -17
  46. data/test/mathematical/mathjax_test.rb +5 -13
  47. data/test/mathematical/mathml_test.rb +3 -3
  48. data/test/mathematical/multiples_test.rb +68 -0
  49. data/test/mathematical/performance_test.rb +2 -2
  50. data/test/mathematical/png_test.rb +5 -5
  51. data/test/test_helper.rb +36 -1
  52. metadata +26 -11
  53. data/lib/mathematical/render.rb +0 -74
@@ -166,7 +166,7 @@ typedef enum {
166
166
  LSM_MATHML_LINE_DASHED
167
167
  } LsmMathmlLine;
168
168
 
169
- const char * lsm_mathml_line_to_string (LsmMathmlLine line);
169
+ const char * lsm_mathml_line_to_string (LsmMathmlLine line);
170
170
  LsmMathmlLine lsm_mathml_line_from_string (const char *string);
171
171
 
172
172
  typedef enum {
@@ -176,6 +176,30 @@ typedef enum {
176
176
  LSM_MATHML_SCRIPT_LEVEL_SIGN_MINUS
177
177
  } LsmMathmlScriptLevelSign;
178
178
 
179
+ typedef enum {
180
+ LSM_MATHML_NOTATION_ERROR = -1,
181
+ LSM_MATHML_NOTATION_LONGDIV,
182
+ LSM_MATHML_NOTATION_ACTUARIAL,
183
+ LSM_MATHML_NOTATION_RADICAL,
184
+ LSM_MATHML_NOTATION_BOX,
185
+ LSM_MATHML_NOTATION_ROUNDED_BOX,
186
+ LSM_MATHML_NOTATION_CIRCLE,
187
+ LSM_MATHML_NOTATION_LEFT,
188
+ LSM_MATHML_NOTATION_RIGHT,
189
+ LSM_MATHML_NOTATION_TOP,
190
+ LSM_MATHML_NOTATION_BOTTOM,
191
+ LSM_MATHML_NOTATION_UP_DIAGONAL_STRIKE,
192
+ LSM_MATHML_NOTATION_DOWN_DIAGONAL_STRIKE,
193
+ LSM_MATHML_NOTATION_VERTICAL_STRIKE,
194
+ LSM_MATHML_NOTATION_HORIZONTAL_STRIKE,
195
+ LSM_MATHML_NOTATION_MADRUWB,
196
+ LSM_MATHML_NOTATION_UP_DIAGONAL_ARROW,
197
+ LSM_MATHML_NOTATION_LAST
198
+ } LsmMathmlNotation;
199
+
200
+ const char * lsm_mathml_notation_to_string (LsmMathmlNotation notation);
201
+ LsmMathmlNotation lsm_mathml_notation_from_string (const char *string);
202
+
179
203
  G_END_DECLS
180
204
 
181
205
  #endif
@@ -23,6 +23,8 @@
23
23
 
24
24
  #include <lsmmathmlpaddedelement.h>
25
25
 
26
+ static GObjectClass *parent_class;
27
+
26
28
  /* LsmDomNode implementation */
27
29
 
28
30
  static const char *
@@ -31,6 +33,44 @@ lsm_mathml_padded_element_get_node_name (LsmDomNode *node)
31
33
  return "mpadded";
32
34
  }
33
35
 
36
+ /* LsmMathmlElement implementation */
37
+
38
+ static const LsmMathmlLength length_default = {0.0, LSM_MATHML_UNIT_PT};
39
+
40
+ static void
41
+ _update (LsmMathmlElement *self, LsmMathmlStyle *style)
42
+ {
43
+ LsmMathmlPaddedElement *padded = LSM_MATHML_PADDED_ELEMENT (self);
44
+
45
+ lsm_mathml_length_attribute_normalize (&padded->height, 0.0, &length_default, style);
46
+ lsm_mathml_length_attribute_normalize (&padded->depth, 0.0, &length_default, style);
47
+ lsm_mathml_length_attribute_normalize (&padded->width, 0.0, &length_default, style);
48
+ lsm_mathml_length_attribute_normalize (&padded->left_space, 0.0, &length_default, style);
49
+ }
50
+
51
+ static const LsmMathmlBbox *
52
+ _measure (LsmMathmlElement *self, LsmMathmlView *view, const LsmMathmlBbox *bbox)
53
+ {
54
+ LsmMathmlPaddedElement *padded = LSM_MATHML_PADDED_ELEMENT (self);
55
+
56
+ LSM_MATHML_ELEMENT_CLASS (parent_class)->measure (self, view, bbox);
57
+
58
+ self->bbox.height += padded->height.value;
59
+ self->bbox.depth += padded->depth.value;
60
+ self->bbox.width += padded->width.value + padded->left_space.value;
61
+
62
+ return &self->bbox;
63
+ }
64
+
65
+ static void
66
+ _layout (LsmMathmlElement *self, LsmMathmlView *view,
67
+ double x, double y, const LsmMathmlBbox *bbox)
68
+ {
69
+ LsmMathmlPaddedElement *padded = LSM_MATHML_PADDED_ELEMENT (self);
70
+
71
+ LSM_MATHML_ELEMENT_CLASS (parent_class)->layout (self, view, x + padded->left_space.value, y, bbox);
72
+ }
73
+
34
74
  /* LsmMathmlPaddedElement implementation */
35
75
 
36
76
  LsmDomNode *
@@ -46,12 +86,51 @@ lsm_mathml_padded_element_init (LsmMathmlPaddedElement *element)
46
86
 
47
87
  /* LsmMathmlPaddedElement class */
48
88
 
89
+ static const LsmAttributeInfos _attribute_infos[] = {
90
+ {
91
+ .name = "height",
92
+ .attribute_offset = offsetof (LsmMathmlPaddedElement, height),
93
+ .trait_class = &lsm_mathml_length_trait_class,
94
+ .trait_default = &length_default
95
+ },
96
+ {
97
+ .name = "depth",
98
+ .attribute_offset = offsetof (LsmMathmlPaddedElement, depth),
99
+ .trait_class = &lsm_mathml_length_trait_class,
100
+ .trait_default = &length_default
101
+ },
102
+ {
103
+ .name = "width",
104
+ .attribute_offset = offsetof (LsmMathmlPaddedElement, width),
105
+ .trait_class = &lsm_mathml_length_trait_class,
106
+ .trait_default = &length_default
107
+ },
108
+ {
109
+ .name = "lspace",
110
+ .attribute_offset = offsetof (LsmMathmlPaddedElement, left_space),
111
+ .trait_class = &lsm_mathml_length_trait_class,
112
+ .trait_default = &length_default
113
+ }
114
+ };
115
+
49
116
  static void
50
117
  lsm_mathml_padded_element_class_init (LsmMathmlPaddedElementClass *klass)
51
118
  {
52
119
  LsmDomNodeClass *d_node_class = LSM_DOM_NODE_CLASS (klass);
120
+ LsmMathmlElementClass *m_element_class = LSM_MATHML_ELEMENT_CLASS (klass);
121
+
122
+ parent_class = g_type_class_peek_parent (klass);
53
123
 
54
124
  d_node_class->get_node_name = lsm_mathml_padded_element_get_node_name;
125
+
126
+ m_element_class->attribute_manager = lsm_attribute_manager_duplicate (m_element_class->attribute_manager);
127
+ m_element_class->update = _update;
128
+ m_element_class->measure = _measure;
129
+ m_element_class->layout = _layout;
130
+
131
+ lsm_attribute_manager_add_attributes (m_element_class->attribute_manager,
132
+ G_N_ELEMENTS (_attribute_infos),
133
+ _attribute_infos);
55
134
  }
56
135
 
57
136
  G_DEFINE_TYPE (LsmMathmlPaddedElement, lsm_mathml_padded_element, LSM_TYPE_MATHML_PRESENTATION_CONTAINER)
@@ -40,6 +40,11 @@ typedef struct _LsmMathmlPaddedElementClass LsmMathmlPaddedElementClass;
40
40
 
41
41
  struct _LsmMathmlPaddedElement {
42
42
  LsmMathmlPresentationContainer presentation_container;
43
+
44
+ LsmMathmlLengthAttribute height;
45
+ LsmMathmlLengthAttribute depth;
46
+ LsmMathmlLengthAttribute width;
47
+ LsmMathmlLengthAttribute left_space;
43
48
  };
44
49
 
45
50
  struct _LsmMathmlPaddedElementClass {
@@ -262,6 +262,12 @@ static const LsmAttributeInfos _attribute_infos[] = {
262
262
  .attribute_offset = offsetof (LsmMathmlStyleElement, math_family),
263
263
  .trait_class = &lsm_mathml_string_trait_class
264
264
  },
265
+ {
266
+ .name = "fontsize",
267
+ .attribute_offset = offsetof (LsmMathmlStyleElement, math_size),
268
+ .trait_class = &lsm_mathml_length_trait_class,
269
+ .trait_default = &length_default
270
+ },
265
271
  {
266
272
  .name = "fontstyle",
267
273
  .attribute_offset = offsetof (LsmMathmlStyleElement, font_style),
@@ -390,11 +390,11 @@ lsm_mathml_table_element_render (LsmMathmlElement *self, LsmMathmlView *view)
390
390
  spacing = table->column_spacing.values[MIN (i, table->column_spacing.n_values - 1)];
391
391
  x = position + 0.5 * (spacing + table->line_width);
392
392
  lsm_mathml_view_show_line (view, &self->style,
393
- x, y0, x, y1,
394
- table->column_lines.enum_list.values[MIN (i,
395
- table->column_lines.enum_list.n_values
396
- - 1)],
397
- table->line_width);
393
+ x, y0, x, y1,
394
+ table->column_lines.enum_list.values[MIN (i,
395
+ table->column_lines.enum_list.n_values
396
+ - 1)],
397
+ table->line_width);
398
398
  position += spacing + table->line_width;
399
399
  }
400
400
 
@@ -251,6 +251,30 @@ const LsmTraitClass lsm_mathml_form_trait_class = {
251
251
  .to_string = lsm_mathml_form_trait_to_string
252
252
  };
253
253
 
254
+ static gboolean
255
+ lsm_mathml_notation_trait_from_string (LsmTrait *abstract_trait, char *string)
256
+ {
257
+ LsmMathmlNotation *value = (LsmMathmlNotation *) abstract_trait;
258
+
259
+ *value = lsm_mathml_notation_from_string (string);
260
+
261
+ return *value >= 0;
262
+ }
263
+
264
+ static char *
265
+ lsm_mathml_notation_trait_to_string (LsmTrait *abstract_trait)
266
+ {
267
+ LsmMathmlNotation *value = (LsmMathmlNotation *) abstract_trait;
268
+
269
+ return g_strdup (lsm_mathml_notation_to_string (*value));
270
+ }
271
+
272
+ const LsmTraitClass lsm_mathml_notation_trait_class = {
273
+ .size = sizeof (int),
274
+ .from_string = lsm_mathml_notation_trait_from_string,
275
+ .to_string = lsm_mathml_notation_trait_to_string
276
+ };
277
+
254
278
  typedef int (*LsmMathmlEnumFromString) (const char *string);
255
279
  typedef char * (*LsmMathmlEnumToString) (unsigned int value);
256
280
 
@@ -98,6 +98,7 @@ extern const LsmTraitClass lsm_mathml_font_style_trait_class;
98
98
  extern const LsmTraitClass lsm_mathml_font_weight_trait_class;
99
99
  extern const LsmTraitClass lsm_mathml_variant_trait_class;
100
100
  extern const LsmTraitClass lsm_mathml_form_trait_class;
101
+ extern const LsmTraitClass lsm_mathml_notation_trait_class;
101
102
 
102
103
  extern const LsmTraitClass lsm_mathml_row_align_list_trait_class;
103
104
  extern const LsmTraitClass lsm_mathml_column_align_list_trait_class;
@@ -48,6 +48,7 @@ typedef struct _LsmMathmlStringElement LsmMathmlStringElement;
48
48
  typedef struct _LsmMathmlPresentationContainer LsmMathmlPresentationContainer;
49
49
  typedef struct _LsmMathmlStyleElement LsmMathmlStyleElement;
50
50
  typedef struct _LsmMathmlRowElement LsmMathmlRowElement;
51
+ typedef struct _LsmMathmlEncloseElement LsmMathmlEncloseElement;
51
52
  typedef struct _LsmMathmlFencedElement LsmMathmlFencedElement;
52
53
  typedef struct _LsmMathmlPaddedElement LsmMathmlPaddedElement;
53
54
  typedef struct _LsmMathmlErrorElement LsmMathmlErrorElement;
@@ -35,15 +35,22 @@ typedef struct {
35
35
  gboolean is_defined;
36
36
  } LsmMathmlBbox;
37
37
 
38
+ typedef struct {
39
+ double left;
40
+ double right;
41
+ double top;
42
+ double bottom;
43
+ } LsmMathmlPadding;
44
+
38
45
  extern const LsmMathmlBbox lsm_mathml_bbox_null;
39
46
 
40
47
  void lsm_mathml_bbox_add_horizontally (LsmMathmlBbox *bbox, const LsmMathmlBbox *new_bbox);
41
48
  void lsm_mathml_bbox_add_over (LsmMathmlBbox *self, const LsmMathmlBbox *bbox);
42
49
  void lsm_mathml_bbox_add_under (LsmMathmlBbox *self, const LsmMathmlBbox *bbox);
43
50
  void lsm_mathml_bbox_merge_vertically (LsmMathmlBbox *self, const LsmMathmlBbox *bbox, double offset);
44
- void lsm_mathml_bbox_stretch (LsmMathmlBbox *self, const LsmMathmlBbox *bbox);
51
+ void lsm_mathml_bbox_stretch (LsmMathmlBbox *self, const LsmMathmlBbox *bbox);
45
52
  void lsm_mathml_bbox_stretch_vertically (LsmMathmlBbox *self, const LsmMathmlBbox *bbox);
46
- void lsm_mathml_bbox_stretch_horizontally (LsmMathmlBbox *self, const LsmMathmlBbox *bbox);
53
+ void lsm_mathml_bbox_stretch_horizontally (LsmMathmlBbox *self, const LsmMathmlBbox *bbox);
47
54
 
48
55
  G_END_DECLS
49
56
 
@@ -33,6 +33,13 @@
33
33
  #include <math.h>
34
34
  #include <string.h>
35
35
 
36
+ typedef enum {
37
+ _GMATHML_STROKE_WIDTH_EVEN,
38
+ _GMATHML_STROKE_WIDTH_ODD,
39
+ _GMATHML_STROKE_WIDTH_NULL,
40
+ _GMATHML_STROKE_WIDTH_VECTOR
41
+ } _LsmMathmlStrokeWidth;
42
+
36
43
  #define LSM_MATHML_LARGE_OP_SCALE 1.6
37
44
 
38
45
  static const char *lsm_mathml_font_names[] = {
@@ -68,6 +75,26 @@ static const struct {
68
75
 
69
76
  static GObjectClass *parent_class;
70
77
 
78
+ static void
79
+ _debug_element_style (const char *format, const LsmMathmlElementStyle *style) {
80
+ if (lsm_debug_check (&lsm_debug_category_render, LSM_DEBUG_LEVEL_DEBUG)) {
81
+ char *string;
82
+
83
+ string = g_strdup_printf ("%s %s %gpt (c:%02X%02X%02X b:%02X%02X%02X)",
84
+ style->math_family,
85
+ lsm_mathml_variant_to_string (style->math_variant),
86
+ style->math_size,
87
+ (int) (255.0 * style->math_color.red),
88
+ (int) (255.0 * style->math_color.green),
89
+ (int) (255.0 * style->math_color.blue),
90
+ (int) (255.0 * style->math_background.red),
91
+ (int) (255.0 * style->math_background.green),
92
+ (int) (255.0 * style->math_background.blue));
93
+ lsm_debug_render ("[LsmMathmlView::render] Show notation %s", string);
94
+ g_free (string);
95
+ }
96
+ }
97
+
71
98
  static void
72
99
  lsm_mathml_view_apply_style_to_font_description (PangoFontDescription *font_description,
73
100
  const LsmMathmlElementStyle *style,
@@ -610,9 +637,9 @@ lsm_mathml_view_get_operator_slant (LsmMathmlView *view,
610
637
 
611
638
  void
612
639
  lsm_mathml_view_measure_radical (LsmMathmlView *view,
613
- const LsmMathmlElementStyle *style,
614
- const LsmMathmlBbox *stretch_bbox,
615
- LsmMathmlBbox *bbox, double *x_offset, double *y_offset)
640
+ const LsmMathmlElementStyle *style,
641
+ const LsmMathmlBbox *stretch_bbox,
642
+ LsmMathmlBbox *bbox, double *x_offset, double *y_offset)
616
643
  {
617
644
  LsmMathmlBbox radical_stretch_bbox;
618
645
  double thickness;
@@ -631,7 +658,7 @@ lsm_mathml_view_measure_radical (LsmMathmlView *view,
631
658
  radical_stretch_bbox.depth += LSM_MATHML_SPACE_EM_THICK * style->math_size;
632
659
 
633
660
  lsm_mathml_view_measure_operator (view, style, LSM_MATHML_RADICAL_UTF8,
634
- FALSE, FALSE, 0.0, &radical_stretch_bbox, bbox);
661
+ FALSE, FALSE, 0.0, &radical_stretch_bbox, bbox);
635
662
 
636
663
  if (x_offset != NULL) {
637
664
  *x_offset = bbox->width * LSM_MATHML_RADICAL_ORDER_X_OFFSET;
@@ -715,13 +742,6 @@ lsm_mathml_view_show_radical (LsmMathmlView *view,
715
742
  cairo_restore (cairo);
716
743
  }
717
744
 
718
- typedef enum {
719
- _GMATHML_STROKE_WIDTH_EVEN,
720
- _GMATHML_STROKE_WIDTH_ODD,
721
- _GMATHML_STROKE_WIDTH_NULL,
722
- _GMATHML_STROKE_WIDTH_VECTOR
723
- } _LsmMathmlStrokeWidth;
724
-
725
745
  static void
726
746
  _round_rectangle_coordinates (cairo_t *cairo,
727
747
  _LsmMathmlStrokeWidth stroke_width,
@@ -809,6 +829,256 @@ _emit_stroke_attributes (LsmMathmlView *view, LsmMathmlLine line, double line_wi
809
829
  return stroke_width;
810
830
  }
811
831
 
832
+ const LsmMathmlPadding notation_padding[] = {
833
+ { .left = 0.0, .right = 0.0, .top = 1.0, .bottom = 0.0 }, /* longdiv */
834
+ { .left = 1.0, .right = 1.0, .top = 1.0, .bottom = 1.0 }, /* actuarial */
835
+ { .left = 0.0, .right = 0.0, .top = 0.0, .bottom = 0.0 }, /* radical */
836
+ { .left = 1.0, .right = 1.0, .top = 1.0, .bottom = 1.0 }, /* box */
837
+ { .left = 1.0, .right = 1.0, .top = 1.0, .bottom = 1.0 }, /* boundedbox */
838
+ { .left = 2.0, .right = 2.0, .top = 2.0, .bottom = 2.0 }, /* circle */
839
+ { .left = 1.0, .right = 0.0, .top = 1.0, .bottom = 1.0 }, /* left */
840
+ { .left = 0.0, .right = 1.0, .top = 1.0, .bottom = 1.0 }, /* right */
841
+ { .left = 1.0, .right = 1.0, .top = 1.0, .bottom = 0.0 }, /* top */
842
+ { .left = 1.0, .right = 1.0, .top = 0.0, .bottom = 1.0 }, /* bottom */
843
+ { .left = 0.0, .right = 0.0, .top = 1.0, .bottom = 1.0 }, /* updiagonalstrike */
844
+ { .left = 0.0, .right = 0.0, .top = 1.0, .bottom = 1.0 }, /* downdiagonalstrike */
845
+ { .left = 0.0, .right = 0.0, .top = 1.0, .bottom = 1.0 }, /* verticalstrike */
846
+ { .left = 1.0, .right = 1.0, .top = 0.0, .bottom = 0.0 }, /* horizontalstrike */
847
+ { .left = 1.0, .right = 1.0, .top = 1.0, .bottom = 1.0 }, /* madruwb */
848
+ { .left = 0.0, .right = 5.0, .top = 1.0, .bottom = 1.0 } /* updiagonalarrow */
849
+ };
850
+
851
+ void
852
+ lsm_mathml_view_measure_notation (LsmMathmlView *view,
853
+ const LsmMathmlElementStyle *style,
854
+ LsmMathmlNotation notation,
855
+ const LsmMathmlBbox *stretch_bbox,
856
+ LsmMathmlBbox *bbox,
857
+ double *x_child_offset)
858
+ {
859
+ LsmMathmlLength padding_x = {.value = 0.5, .unit = LSM_MATHML_UNIT_EX};
860
+ LsmMathmlLength padding_y = {.value = 0.4, .unit = LSM_MATHML_UNIT_EM};
861
+ double base_x;
862
+ double base_y;
863
+
864
+ g_return_if_fail (LSM_IS_MATHML_VIEW (view));
865
+ g_return_if_fail (style != NULL);
866
+ g_return_if_fail (stretch_bbox != NULL);
867
+ g_return_if_fail (bbox != NULL);
868
+
869
+ if (notation == LSM_MATHML_NOTATION_RADICAL) {
870
+ lsm_mathml_view_measure_radical (view, style, stretch_bbox, bbox, NULL, NULL);
871
+ if (x_child_offset != NULL)
872
+ *x_child_offset = bbox->width;
873
+ lsm_mathml_bbox_add_horizontally (bbox, stretch_bbox);
874
+ return;
875
+ }
876
+
877
+ base_x = lsm_mathml_length_normalize (&padding_x, 0.0, style->math_size);
878
+ base_y = lsm_mathml_length_normalize (&padding_y, 0.0, style->math_size);
879
+
880
+ *bbox = *stretch_bbox;
881
+
882
+ if (notation >= 0 && notation < LSM_MATHML_NOTATION_LAST) {
883
+ bbox->width += base_x * (notation_padding[notation].left + notation_padding[notation].right);
884
+ bbox->height += base_y * notation_padding[notation].top;
885
+ bbox->depth += base_y * notation_padding[notation].bottom;
886
+
887
+ if (notation == LSM_MATHML_NOTATION_LONGDIV) {
888
+ bbox->width += bbox->height / 2.0;
889
+ if (x_child_offset != NULL)
890
+ *x_child_offset = bbox->height / 2.0;
891
+ } else {
892
+ if (x_child_offset != NULL)
893
+ *x_child_offset = base_x * notation_padding[notation].left;
894
+ }
895
+ } else {
896
+ if (x_child_offset != NULL)
897
+ *x_child_offset = 0;
898
+ }
899
+ }
900
+
901
+ static void
902
+ _cairo_arrow (cairo_t *cairo, double scale, double x0, double y0, double x1, double y1)
903
+ {
904
+ double angle;
905
+ double x2, y2;
906
+
907
+ if ((y1 - y0) == 0 && (x1 - x0) == 0)
908
+ return;
909
+
910
+ angle = atan2 (y1 - y0, x1 - x0);
911
+ x2 = x1 - scale * cos (angle) / 2.0;
912
+ y2 = y1 - scale * sin (angle) / 2.0;
913
+
914
+ cairo_move_to (cairo, x0, y0);
915
+ cairo_line_to (cairo, x2, y2);
916
+ cairo_stroke (cairo);
917
+
918
+ cairo_save (cairo);
919
+
920
+ cairo_translate (cairo, x1, y1);
921
+ cairo_scale (cairo, scale, scale);
922
+ cairo_rotate (cairo, angle);
923
+
924
+ cairo_move_to (cairo, -1.0, 0.3);
925
+ cairo_line_to (cairo, 0.0, 0.0);
926
+ cairo_line_to (cairo, -1.0, -0.3);
927
+ cairo_line_to (cairo, -0.9, 0.0);
928
+ cairo_close_path (cairo);
929
+
930
+ cairo_restore (cairo);
931
+
932
+ cairo_fill (cairo);
933
+ }
934
+
935
+ static void
936
+ _cairo_rounded_rectangle (cairo_t *cairo, double radius, double x0, double y0, double x1, double y1)
937
+ {
938
+ cairo_new_path (cairo);
939
+
940
+ cairo_arc (cairo, x0 + radius, y0 - radius, radius, M_PI / 2.0, -M_PI);
941
+ cairo_arc (cairo, x0 + radius, y1 + radius, radius, M_PI, -M_PI / 2.0);
942
+ cairo_arc (cairo, x1 - radius, y1 + radius, radius, -M_PI / 2.0, 0.0);
943
+ cairo_arc (cairo, x1 - radius, y0 - radius, radius, 0.0, M_PI / 2.0);
944
+ cairo_close_path (cairo);
945
+
946
+ cairo_stroke (cairo);
947
+ }
948
+
949
+ void
950
+ lsm_mathml_view_show_notation (LsmMathmlView *view,
951
+ const LsmMathmlElementStyle *style,
952
+ LsmMathmlNotation notation,
953
+ double x, double y,
954
+ const LsmMathmlBbox *bbox,
955
+ double x_child_offset)
956
+ {
957
+ LsmMathmlBbox stretch_bbox;
958
+ LsmMathmlLength padding_x = {.value = 0.5, .unit = LSM_MATHML_UNIT_EX};
959
+ _LsmMathmlStrokeWidth stroke_width;
960
+ cairo_t *cairo;
961
+ double x1, y1;
962
+ double base_x;
963
+
964
+ g_return_if_fail (LSM_IS_MATHML_VIEW (view));
965
+ g_return_if_fail (style != NULL);
966
+ g_return_if_fail (bbox != NULL);
967
+
968
+ stroke_width = _emit_stroke_attributes (view, LSM_MATHML_LINE_SOLID, 1.0, &style->math_color);
969
+
970
+ _debug_element_style ("[LsmMathmlView::render] Show notation %s", style);
971
+
972
+ if (stroke_width == _GMATHML_STROKE_WIDTH_NULL)
973
+ return;
974
+
975
+ base_x = lsm_mathml_length_normalize (&padding_x, 0.0, style->math_size);
976
+
977
+ y = y + bbox->depth;
978
+ x1 = x + bbox->width;
979
+ y1 = y - bbox->height - bbox->depth;
980
+
981
+ cairo = view->dom_view.cairo;
982
+
983
+ _round_rectangle_coordinates (cairo, stroke_width, &x, &y, &x1, &y1);
984
+
985
+ cairo_new_path (cairo);
986
+
987
+ switch (notation) {
988
+ case LSM_MATHML_NOTATION_ACTUARIAL:
989
+ cairo_move_to (cairo, x, y1);
990
+ cairo_line_to (cairo, x1, y1);
991
+ cairo_line_to (cairo, x1, y);
992
+ cairo_stroke (cairo);
993
+ break;
994
+ case LSM_MATHML_NOTATION_RADICAL:
995
+ stretch_bbox = *bbox;
996
+ stretch_bbox.width = x_child_offset;
997
+ lsm_mathml_view_show_radical (view, style, x, y - bbox->depth,
998
+ bbox->width - x_child_offset, &stretch_bbox);
999
+ break;
1000
+ case LSM_MATHML_NOTATION_BOX:
1001
+ cairo_move_to (cairo, x, y);
1002
+ cairo_line_to (cairo, x, y1);
1003
+ cairo_line_to (cairo, x1, y1);
1004
+ cairo_line_to (cairo, x1, y);
1005
+ cairo_close_path (cairo);
1006
+ cairo_stroke (cairo);
1007
+ break;
1008
+ case LSM_MATHML_NOTATION_ROUNDED_BOX:
1009
+ _cairo_rounded_rectangle (cairo, base_x, x, y, x1, y1);
1010
+ break;
1011
+ case LSM_MATHML_NOTATION_CIRCLE:
1012
+ cairo_save (cairo);
1013
+ cairo_translate (cairo, (x + x1) / 2.0, (y + y1) / 2.0);
1014
+ cairo_scale (cairo, (x - x1) / 2.0, (y - y1) / 2.0);
1015
+ cairo_arc (cairo, 0., 0., 1., 0., 2 * M_PI);
1016
+ cairo_restore (cairo);
1017
+ cairo_stroke (cairo);
1018
+ break;
1019
+ case LSM_MATHML_NOTATION_LEFT:
1020
+ cairo_move_to (cairo, x, y);
1021
+ cairo_line_to (cairo, x, y1);
1022
+ cairo_stroke (cairo);
1023
+ break;
1024
+ case LSM_MATHML_NOTATION_RIGHT:
1025
+ cairo_move_to (cairo, x1, y);
1026
+ cairo_line_to (cairo, x1, y1);
1027
+ cairo_stroke (cairo);
1028
+ break;
1029
+ case LSM_MATHML_NOTATION_TOP:
1030
+ cairo_move_to (cairo, x, y1);
1031
+ cairo_line_to (cairo, x1, y1);
1032
+ cairo_stroke (cairo);
1033
+ break;
1034
+ case LSM_MATHML_NOTATION_BOTTOM:
1035
+ cairo_move_to (cairo, x, y);
1036
+ cairo_line_to (cairo, x1, y);
1037
+ cairo_stroke (cairo);
1038
+ break;
1039
+ case LSM_MATHML_NOTATION_UP_DIAGONAL_STRIKE:
1040
+ cairo_move_to (cairo, x, y);
1041
+ cairo_line_to (cairo, x1, y1);
1042
+ cairo_stroke (cairo);
1043
+ break;
1044
+ case LSM_MATHML_NOTATION_DOWN_DIAGONAL_STRIKE:
1045
+ cairo_move_to (cairo, x, y1);
1046
+ cairo_line_to (cairo, x1, y);
1047
+ cairo_stroke (cairo);
1048
+ break;
1049
+ case LSM_MATHML_NOTATION_HORIZONTAL_STRIKE:
1050
+ cairo_move_to (cairo, x, (y + y1) / 2.0);
1051
+ cairo_line_to (cairo, x1,(y + y1) / 2.0);
1052
+ cairo_stroke (cairo);
1053
+ break;
1054
+ case LSM_MATHML_NOTATION_VERTICAL_STRIKE:
1055
+ cairo_move_to (cairo, (x + x1) / 2.0, y);
1056
+ cairo_line_to (cairo, (x + x1) / 2.0, y1);
1057
+ cairo_stroke (cairo);
1058
+ break;
1059
+ case LSM_MATHML_NOTATION_MADRUWB:
1060
+ cairo_move_to (cairo, x, y);
1061
+ cairo_line_to (cairo, x1, y);
1062
+ cairo_line_to (cairo, x1, y1);
1063
+ cairo_stroke (cairo);
1064
+ break;
1065
+ case LSM_MATHML_NOTATION_UP_DIAGONAL_ARROW:
1066
+ _cairo_arrow (cairo, 4.0 * base_x, x, y, x1, y1);
1067
+ break;
1068
+ case LSM_MATHML_NOTATION_ERROR:
1069
+ case LSM_MATHML_NOTATION_LONGDIV:
1070
+ default:
1071
+ cairo_move_to (cairo, x, y);
1072
+ cairo_curve_to (cairo,
1073
+ x + bbox->height / 4.0, y - bbox->height / 4.0,
1074
+ x + bbox->height / 4.0, y1 + bbox->height / 4.0,
1075
+ x, y1);
1076
+ cairo_line_to (cairo, x1, y1);
1077
+ cairo_stroke (cairo);
1078
+ break;
1079
+ }
1080
+ }
1081
+
812
1082
  void
813
1083
  lsm_mathml_view_show_background (LsmMathmlView *view,
814
1084
  const LsmMathmlElementStyle *style,
@@ -928,6 +1198,8 @@ lsm_mathml_view_show_fraction_line (LsmMathmlView *view,
928
1198
 
929
1199
  stroke_width = _emit_stroke_attributes (view, LSM_MATHML_LINE_SOLID, thickness, &style->math_color);
930
1200
 
1201
+ _debug_element_style ("[LsmMathmlView::render] Show fraction line %s", style);
1202
+
931
1203
  if (stroke_width == _GMATHML_STROKE_WIDTH_NULL)
932
1204
  return;
933
1205