units.cpp revision ef7137d766169bb285a4c0cc69ba1c387214512c
/*
* Inkscape Units
*
* Authors:
* Matthew Petroff <matthew@mpetroff.net>
*
* Copyright (C) 2013 Matthew Petroff
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <cmath>
#include <cerrno>
#include <iomanip>
#include <glib.h>
#include <glibmm/fileutils.h>
#include "path-prefix.h"
#include "streq.h"
namespace
{
/**
* A std::map that gives the data type value for the string version.
*
* Note that we'd normally not return a reference to an internal version, but
* for this constant case it allows us to check against getTypeMappings().end().
*/
/** @todo consider hiding map behind hasFoo() and getFoo() type functions.*/
{
static bool init = false;
if (!init)
{
init = true;
// Note that code was not yet handling LINEAR_SCALED, TIME, QTY and NONE
}
return typeMap;
}
} // namespace
namespace Inkscape {
namespace Util {
{
public:
virtual ~UnitParser() {}
protected:
public:
bool primary;
bool skip;
};
primary(false),
skip(false)
{
}
#define BUFSIZE (255)
factor(1.0),
name(),
name_plural(),
abbr(),
{
}
double factor,
{
}
{
*this = Unit();
}
int Unit::defaultDigits() const
{
if (factor_digits < 0) {
g_warning("factor_digits < 0 - returning 0");
factor_digits = 0;
}
return factor_digits;
}
{
// Percentages
return true;
}
// Other units with same type
return true;
}
// Different, incompatible types
return false;
}
{
static UnitTable unit_table;
}
{
}
{
}
{
return 1;
return 2;
return 3;
return 4;
return 5;
return 6;
return 7;
return 8;
return 9;
return 10;
return 0;
}
{
}
{
{
}
}
{
if (primary) {
}
}
{
} else {
return Unit();
}
}
{
switch(u) {
case 1:
u_str = "px"; break;
case 2:
u_str = "pt"; break;
case 3:
u_str = "pc"; break;
case 4:
u_str = "mm"; break;
case 5:
u_str = "cm"; break;
case 6:
u_str = "in"; break;
case 7:
u_str = "ft"; break;
case 8:
u_str = "em"; break;
case 9:
u_str = "ex"; break;
case 10:
u_str = "%"; break;
default:
u_str = "";
}
}
{
// Extract value
double value = 0;
Glib::RefPtr<Glib::Regex> value_regex = Glib::Regex::create("[-+]*[\\d+]*\\.*[\\d+]*[eE]*[-+]*\\d+");
}
// Extract unit abbreviation
}
}
{
bool deleted = false;
// Cannot delete the primary unit type since it's
// used for conversions
deleted = true;
}
}
return deleted;
}
{
}
{
}
}
return submap;
}
{
return _primary_unit[type];
}
UnitParser uparser(this);
try {
} catch (Glib::MarkupError const &e) {
return false;
}
return true;
}
g_warning("UnitTable::save(): not implemented");
return true;
}
{
if (name == "unit") {
// reset for next use
primary = false;
skip = false;
} else {
skip = true;
}
}
}
}
}
{
if (element == "name") {
} else if (element == "plural") {
} else if (element == "abbr") {
} else if (element == "factor") {
// TODO make sure we use the right conversion
} else if (element == "description") {
}
}
{
}
}
{
quantity = q;
}
{
quantity = q;
}
{
return unit->compatibleWith(u);
}
{
}
{
}
{
}
}
}
}
{
// Percentage
}
// Incompatible units
return -1;
}
// Compatible units
}
{
}
{
}
{
}
} // namespace Util
} // namespace Inkscape
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :