[lasem] mathml: linebreak trait implementation



commit a77c8ec3652b66a3d23c67d7bcdcb94855c2bd85
Author: Garen Torikian <gjtorikian gmail com>
Date:   Thu Jul 9 22:43:27 2015 +0200

    mathml: linebreak trait implementation
    
    Not actually used during rendering yet.

 src/lsmmathmlenums.c        |   24 ++++++++++++++++++++++++
 src/lsmmathmlenums.h        |   13 ++++++++++++-
 src/lsmmathmlspaceelement.c |   14 ++++++++++++++
 src/lsmmathmlspaceelement.h |    2 +-
 src/lsmmathmltraits.c       |   24 ++++++++++++++++++++++++
 src/lsmmathmltraits.h       |    1 +
 src/lsmtraits.c             |    1 -
 7 files changed, 76 insertions(+), 3 deletions(-)
---
diff --git a/src/lsmmathmlenums.c b/src/lsmmathmlenums.c
index 3dc6861..ee73d0b 100644
--- a/src/lsmmathmlenums.c
+++ b/src/lsmmathmlenums.c
@@ -470,3 +470,27 @@ lsm_mathml_notation_from_string     (const char *string)
        return lsm_enum_value_from_string (string, lsm_mathml_notation_strings,
                                           G_N_ELEMENTS (lsm_mathml_notation_strings));
 }
+
+static const char *lsm_mathml_linebreak_strings[] = {
+       "auto",
+       "newline",
+       "nobreak",
+       "goodbreak",
+       "badbreak"
+};
+
+const char *
+lsm_mathml_linebreak_to_string (LsmMathmlLinebreak linebreak)
+{
+       if (linebreak < 0 || linebreak > LSM_MATHML_LINEBREAK_BADBREAK)
+               return NULL;
+
+       return lsm_mathml_linebreak_strings[linebreak];
+}
+
+LsmMathmlLinebreak
+lsm_mathml_linebreak_from_string (const char *string)
+{
+       return lsm_enum_value_from_string (string, lsm_mathml_linebreak_strings,
+                                          G_N_ELEMENTS (lsm_mathml_linebreak_strings));
+}
diff --git a/src/lsmmathmlenums.h b/src/lsmmathmlenums.h
index b4d9768..6bd166d 100644
--- a/src/lsmmathmlenums.h
+++ b/src/lsmmathmlenums.h
@@ -207,7 +207,18 @@ typedef enum {
 const char *           lsm_mathml_notation_to_string           (LsmMathmlNotation notation);
 LsmMathmlNotation      lsm_mathml_notation_from_string         (const char *string);
 
+typedef enum {
+       LSM_MATHML_LINEBREAK_ERROR = -1,
+       LSM_MATHML_LINEBREAK_AUTO,
+       LSM_MATHML_LINEBREAK_NEWLINE,
+       LSM_MATHML_LINEBREAK_NOBREAK,
+       LSM_MATHML_LINEBREAK_GOODBREAK,
+       LSM_MATHML_LINEBREAK_BADBREAK
+} LsmMathmlLinebreak;
+
+const char *           lsm_mathml_linebreak_to_string          (LsmMathmlLinebreak linebreak);
+LsmMathmlLinebreak             lsm_mathml_linebreak_from_string                (const char *string);
+
 G_END_DECLS
 
 #endif
-
diff --git a/src/lsmmathmlspaceelement.c b/src/lsmmathmlspaceelement.c
index 5937c79..7ceede1 100644
--- a/src/lsmmathmlspaceelement.c
+++ b/src/lsmmathmlspaceelement.c
@@ -59,11 +59,17 @@ static const LsmMathmlBbox *
 lsm_mathml_space_element_measure (LsmMathmlElement *self, LsmMathmlView *view, const LsmMathmlBbox *bbox)
 {
        LsmMathmlSpaceElement *space_element = LSM_MATHML_SPACE_ELEMENT (self);
+       LsmMathmlLinebreak linebreak;
 
        self->bbox.width = space_element->width.value;
        self->bbox.height = space_element->height.value;
        self->bbox.depth = space_element->depth.value;
        self->bbox.is_defined = TRUE;
+       linebreak = space_element->linebreak.value;
+
+       if (linebreak == LSM_MATHML_LINEBREAK_NEWLINE) {
+
+       }
 
        return &self->bbox;
 }
@@ -85,6 +91,7 @@ lsm_mathml_space_element_new (void)
 
 static const LsmMathmlSpace space_default = {LSM_MATHML_SPACE_NAME_ERROR, {0.0, LSM_MATHML_UNIT_EM}};
 static const LsmMathmlLength length_default = {1.0, LSM_MATHML_UNIT_NONE};
+static const LsmMathmlLinebreak linebreak_default = LSM_MATHML_LINEBREAK_AUTO;
 
 static void
 lsm_mathml_space_element_init (LsmMathmlSpaceElement *self)
@@ -92,6 +99,7 @@ lsm_mathml_space_element_init (LsmMathmlSpaceElement *self)
        self->width.space = space_default;
        self->height.length = length_default;
        self->depth.length = length_default;
+       self->linebreak.value = linebreak_default;
 }
 
 /* LsmMathmlSpaceElement class */
@@ -114,6 +122,12 @@ static const LsmAttributeInfos _attribute_infos[] = {
                .attribute_offset = offsetof (LsmMathmlSpaceElement, height),
                .trait_class = &lsm_mathml_length_trait_class,
                .trait_default = &length_default
+       },
+       {
+               .name = "linebreak",
+               .attribute_offset = offsetof (LsmMathmlSpaceElement, linebreak),
+               .trait_class = &lsm_mathml_linebreak_trait_class,
+               .trait_default = &linebreak_default
        }
 };
 
diff --git a/src/lsmmathmlspaceelement.h b/src/lsmmathmlspaceelement.h
index 23421b2..d4cb367 100644
--- a/src/lsmmathmlspaceelement.h
+++ b/src/lsmmathmlspaceelement.h
@@ -44,6 +44,7 @@ struct _LsmMathmlSpaceElement {
        LsmMathmlSpaceAttribute width;
        LsmMathmlLengthAttribute height;
        LsmMathmlLengthAttribute depth;
+       LsmMathmlEnumAttribute linebreak;
 };
 
 struct _LsmMathmlSpaceElementClass {
@@ -57,4 +58,3 @@ LsmDomNode *  lsm_mathml_space_element_new    (void);
 G_END_DECLS
 
 #endif
-
diff --git a/src/lsmmathmltraits.c b/src/lsmmathmltraits.c
index f986099..de3e473 100644
--- a/src/lsmmathmltraits.c
+++ b/src/lsmmathmltraits.c
@@ -275,6 +275,30 @@ const LsmTraitClass lsm_mathml_notation_trait_class = {
        .to_string = lsm_mathml_notation_trait_to_string
 };
 
+static gboolean
+lsm_mathml_linebreak_trait_from_string (LsmTrait *abstract_trait, char *string)
+{
+       LsmMathmlLinebreak *value = (LsmMathmlLinebreak *) abstract_trait;
+
+       *value = lsm_mathml_linebreak_from_string (string);
+
+       return *value >= 0;
+}
+
+static char *
+lsm_mathml_linebreak_trait_to_string (LsmTrait *abstract_trait)
+{
+       LsmMathmlLinebreak *value = (LsmMathmlLinebreak *) abstract_trait;
+
+       return g_strdup (lsm_mathml_linebreak_to_string (*value));
+}
+
+const LsmTraitClass lsm_mathml_linebreak_trait_class = {
+       .size = sizeof (int),
+       .from_string = lsm_mathml_linebreak_trait_from_string,
+       .to_string = lsm_mathml_linebreak_trait_to_string
+};
+
 typedef int (*LsmMathmlEnumFromString) (const char *string);
 typedef char * (*LsmMathmlEnumToString) (unsigned int value);
 
diff --git a/src/lsmmathmltraits.h b/src/lsmmathmltraits.h
index 4a89778..8a11858 100644
--- a/src/lsmmathmltraits.h
+++ b/src/lsmmathmltraits.h
@@ -107,6 +107,7 @@ extern const LsmTraitClass lsm_mathml_font_weight_trait_class;
 extern const LsmTraitClass lsm_mathml_variant_trait_class;
 extern const LsmTraitClass lsm_mathml_form_trait_class;
 extern const LsmTraitClass lsm_mathml_notation_trait_class;
+extern const LsmTraitClass lsm_mathml_linebreak_trait_class;
 
 extern const LsmTraitClass lsm_mathml_row_align_list_trait_class;
 extern const LsmTraitClass lsm_mathml_column_align_list_trait_class;
diff --git a/src/lsmtraits.c b/src/lsmtraits.c
index 2922db1..ad46efb 100644
--- a/src/lsmtraits.c
+++ b/src/lsmtraits.c
@@ -116,4 +116,3 @@ lsm_enum_value_from_string (const char *string, const char **strings, unsigned i
 
        return -1;
 }
-


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]