Logo Search packages:      
Sourcecode: inkscape version File versions  Download package

guchar* cr_num_to_string ( CRNum a_this  ) 

Returns the string representation of the current instance of CRNum.

Parameters:
a_this the current instance of CRNum.
Returns:
the newly built string representation of the current instance of CRNum. The returned string is NULL terminated. The caller *must* free the returned string.

Definition at line 92 of file cr-num.c.

References _CRNum::type, and _CRNum::val.

Referenced by cr_style_num_prop_val_to_string(), and cr_term_to_string().

{
        gdouble test_val = 0.0;

        guchar *tmp_char1 = NULL,
                *tmp_char2 = NULL,
                *result = NULL;

        g_return_val_if_fail (a_this, NULL);

        test_val = a_this->val - (glong) a_this->val;

        if (!test_val) {
                tmp_char1 = (guchar *)g_strdup_printf ("%ld", (glong) a_this->val);
        } else {
                /* We can't use g_ascii_dtostr, because that sometimes uses
                   e notation (which wouldn't be a valid number in CSS). */
                size_t const buflen = 35;  /* fairly arbitrary. */
                tmp_char1 = (guchar *)g_malloc (buflen);
                g_ascii_formatd ((gchar *)tmp_char1, buflen, "%.17f", a_this->val);
        }

        g_return_val_if_fail (tmp_char1, NULL);

        switch (a_this->type) {
        case NUM_LENGTH_EM:
                tmp_char2 = (guchar *) "em";
                break;

        case NUM_LENGTH_EX:
                tmp_char2 = (guchar *) "ex";
                break;

        case NUM_LENGTH_PX:
                tmp_char2 = (guchar *) "px";
                break;

        case NUM_LENGTH_IN:
                tmp_char2 = (guchar *) "in";
                break;

        case NUM_LENGTH_CM:
                tmp_char2 = (guchar *) "cm";
                break;

        case NUM_LENGTH_MM:
                tmp_char2 = (guchar *) "mm";
                break;

        case NUM_LENGTH_PT:
                tmp_char2 = (guchar *) "pt";
                break;

        case NUM_LENGTH_PC:
                tmp_char2 = (guchar *) "pc";
                break;

        case NUM_ANGLE_DEG:
                tmp_char2 = (guchar *) "deg";
                break;

        case NUM_ANGLE_RAD:
                tmp_char2 = (guchar *) "rad";
                break;

        case NUM_ANGLE_GRAD:
                tmp_char2 = (guchar *) "grad";
                break;

        case NUM_TIME_MS:
                tmp_char2 = (guchar *) "ms";
                break;

        case NUM_TIME_S:
                tmp_char2 = (guchar *) "s";
                break;

        case NUM_FREQ_HZ:
                tmp_char2 = (guchar *) "Hz";
                break;

        case NUM_FREQ_KHZ:
                tmp_char2 = (guchar *) "KHz";
                break;

        case NUM_PERCENTAGE:
                tmp_char2 = (guchar *) "%";
                break;
        case NUM_INHERIT:
                tmp_char2 = (guchar *) "inherit";
                break ;
        case NUM_AUTO:
                tmp_char2 = (guchar *) "auto";
                break ;
        case NUM_GENERIC:
                tmp_char2 = NULL ;
                break ;
        default:
                tmp_char2 = (guchar *) "unknown";
                break;
        }

        if (tmp_char2) {
                result = (guchar *)g_strconcat (
                            (gchar *)tmp_char1, (gchar *)tmp_char2, NULL);
                g_free (tmp_char1);
        } else {
                result = tmp_char1;
        }

        return result;
}


Generated by  Doxygen 1.6.0   Back to index