Click here to Skip to main content
15,885,278 members
Articles / Mobile Apps / Android

Android ImageView and Drawable with SVG Support

Rate me:
Please Sign up or sign in to vote.
4.75/5 (11 votes)
14 Dec 2010CPOL3 min read 154.9K   5.7K   33  
This article introduces custom classes SvgImageView and SvgDrawable which allow to use SVG image just like any other image.
/* svg_length.c: Data structures for SVG lengths
 
   Copyright � 2002 USC/Information Sciences Institute
  
   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public License as
   published by the Free Software Foundation; either version 2 of the
   License, or (at your option) any later version.
  
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.
  
   You should have received a copy of the GNU Library General Public
   License along with this program; if not, write to the
   Free Software Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.
  
   Author: Carl Worth <cworth@isi.edu>
*/

#include <string.h>

#include "svgint.h"

svg_status_t
_svg_length_init (svg_length_t *length, double value)
{
    return _svg_length_init_unit (length, value, SVG_LENGTH_UNIT_PX, SVG_LENGTH_ORIENTATION_OTHER);
}

svg_status_t
_svg_length_init_unit (svg_length_t		*length,
		       double			value,
		       svg_length_unit_t	unit,
		       svg_length_orientation_t orientation)
{
    length->value = value;
    length->unit = unit;
    length->orientation = orientation;

    return SVG_STATUS_SUCCESS;
}

svg_status_t
_svg_length_init_from_str (svg_length_t *length, const char *str)
{
    double value;
    svg_length_unit_t unit;
    const char *unit_str;

    value = _svg_ascii_strtod (str, &unit_str);

    if (unit_str == str)
	return SVG_STATUS_PARSE_ERROR;

    if (unit_str) {
	if (strcmp (unit_str, "px") == 0)
	    unit = SVG_LENGTH_UNIT_PX;
	else if (strcmp (unit_str, "pt") == 0)
	    unit = SVG_LENGTH_UNIT_PT;
	else if (strcmp (unit_str, "in") == 0)
	    unit = SVG_LENGTH_UNIT_IN;
	else if (strcmp (unit_str, "cm") == 0)
	    unit = SVG_LENGTH_UNIT_CM;
	else if (strcmp (unit_str, "mm") == 0)
	    unit = SVG_LENGTH_UNIT_MM;
	else if (strcmp (unit_str, "pc") == 0)
	    unit = SVG_LENGTH_UNIT_PC;
	else if (strcmp (unit_str, "em") == 0)
	    unit = SVG_LENGTH_UNIT_EM;
	else if (strcmp (unit_str, "ex") == 0)
	    unit = SVG_LENGTH_UNIT_EX;
	else if (strcmp (unit_str, "%") == 0)
	    unit = SVG_LENGTH_UNIT_PCT;
	else {
	    unit = SVG_LENGTH_UNIT_PX;
	}
    } else {
	unit = SVG_LENGTH_UNIT_PX;
    }

    return _svg_length_init_unit (length, value, unit, length->orientation);
}

svg_status_t
_svg_length_deinit (svg_length_t *length)
{
    length->value = 0.0;
    length->unit = SVG_LENGTH_UNIT_PX;

    return SVG_STATUS_SUCCESS;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Russian Federation Russian Federation
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions