viewbox.cpp revision 81efba162b1fc851b6bf0a5ca33928c37effa779
/*
* viewBox helper class, common code used by root, symbol, marker, pattern, image, view
*
* Authors:
* Lauris Kaplinski <lauris@kaplinski.com> (code extracted from symbol.cpp)
* Tavmjong Bah <tavmjong@free.fr>
* Johan Engelen
*
* Copyright (C) 2013-2014 Tavmjong Bah, authors
*
* Released under GNU GPL, read the file 'COPYING' for more information
*
*/
#include "viewbox.h"
#include "attributes.h"
#include "enums.h"
#include "sp-item.h"
: viewBox_set(false)
, viewBox()
, aspect_set(false)
{
}
if (value) {
gchar *eptr = const_cast<gchar*>(value); // const-cast necessary because of const-incorrect interface definition of g_ascii_strtod
eptr++;
}
eptr++;
}
eptr++;
}
eptr++;
}
/* Set viewbox */
this->viewBox_set = true;
} else {
this->viewBox_set = false;
}
} else {
this->viewBox_set = false;
}
// The C++ way? -- not necessarily using iostreams
// std::string sv( value );
// std::replace( sv.begin(), sv.end(), ',', ' ');
// std::stringstream ss( sv );
// double x, y, width, height;
// ss >> x >> y >> width >> height;
}
/* Do setup before, so we can use break to escape */
this->aspect_set = false;
this->aspect_clip = SP_ASPECT_MEET;
if (value) {
while (*p && (*p == 32)) {
p += 1;
}
if (!*p) {
return;
}
const gchar *e = p;
while (*e && (*e != 32)) {
e += 1;
}
int len = e - p;
return;
}
gchar c[256];
c[len] = 0;
/* Now the actual part */
unsigned int align = SP_ASPECT_NONE;
if (!strcmp (c, "none")) {
} else if (!strcmp (c, "xMinYMin")) {
} else if (!strcmp (c, "xMidYMin")) {
} else if (!strcmp (c, "xMaxYMin")) {
} else if (!strcmp (c, "xMinYMid")) {
} else if (!strcmp (c, "xMidYMid")) {
} else if (!strcmp (c, "xMaxYMid")) {
} else if (!strcmp (c, "xMinYMax")) {
} else if (!strcmp (c, "xMidYMax")) {
} else if (!strcmp (c, "xMaxYMax")) {
} else {
return;
}
unsigned int clip = SP_ASPECT_MEET;
while (*e && (*e == 32)) {
e += 1;
}
if (*e) {
if (!strcmp (e, "meet")) {
} else if (!strcmp (e, "slice")) {
} else {
return;
}
}
this->aspect_set = true;
this->aspect_align = align;
this->aspect_clip = clip;
}
}
// Apply scaling from viewbox
/* Determine actual viewbox in viewport coordinates */
double x = 0.0;
double y = 0.0;
// scaling is already uniform, reduce numerical error
} else if (this->aspect_align != SP_ASPECT_NONE) {
// scaling is not uniform, but force it to be
/* Now place viewbox to requested position */
switch (this->aspect_align) {
case SP_ASPECT_XMIN_YMIN:
break;
case SP_ASPECT_XMID_YMIN:
break;
case SP_ASPECT_XMAX_YMIN:
break;
case SP_ASPECT_XMIN_YMID:
break;
case SP_ASPECT_XMID_YMID:
break;
case SP_ASPECT_XMAX_YMID:
break;
case SP_ASPECT_XMIN_YMAX:
break;
case SP_ASPECT_XMID_YMAX:
break;
case SP_ASPECT_XMAX_YMAX:
break;
default:
break;
}
}
/* Viewbox transform from scale and position */
q[0] = scalex;
q[1] = 0.0;
q[2] = 0.0;
q[3] = scaley;
// std::cout << " q\n" << q << std::endl;
/* Append viewbox transformation */
}
/* Create copy of item context */
/* Calculate child to parent transformation */
/* Apply parent translation (set up as viewport) */
if (this->viewBox_set) {
// Adjusts c2p for viewbox
}
/* If viewBox is set initialize child viewport */
/* Otherwise it is already correct */
if (this->viewBox_set) {
}
return rctx;
}
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-basic-offset:2
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=2:tabstop=8:softtabstop=2:fileencoding=utf-8:textwidth=99 :