Exemplo n.º 1
0
SvgBox SvgText::bounding_box() const
{
    // Resuting box positions.
    double t, b, l, r;

    // Dimensions.
    auto fs = font.size;
    double width  = text.size() * fs / 1.8;
    double height = fs * 1.2;

    // Horizontal.
    if( anchor == Anchor::kEnd ) {
        l = position.x - width;

    } else if( anchor == Anchor::kMiddle ) {
        l = position.x - width / 2.0;

    } else {
        l = position.x;
    }
    r = l + width;

    // Vertical.
    // Allow for letters below the ground line.
    b = position.y + height * 0.3;
    t = b - height;

    return { SvgPoint( l, t ), SvgPoint( r, b ) };
}
Exemplo n.º 2
0
 /**
  * @brief Construct a gradient, with an ID and a vector determining its direction.
  *
  * The coordinates of the two points need to be in the range [ 0.0, 1.0 ], as they are
  * interpreted as percentages. This is what most SVG tools expect, so we stick to this
  * convention.
  *
  * By default, the points are set to a horizontal gradient spanning 0-100%.
  */
 SvgGradientLinear(
     std::string const& id,
     SvgPoint point_1 = SvgPoint( 0.0, 0.0 ),
     SvgPoint point_2 = SvgPoint( 1.0, 0.0 )
 )
     : id( id )
     , point_1( point_1 )
     , point_2( point_2 )
 {}
Exemplo n.º 3
0
vector<SvgPoint> SvgPolygon::getCoords(string pointString) {
	vector<SvgPoint> coords = vector<SvgPoint>();
	string tmp, x, y;

	pointString = boost::trim_copy(pointString).append("\n");
	int lfpos = pointString.find("\n");

	while (lfpos >= 0) {
		tmp = boost::trim_copy(pointString.substr(0, lfpos));
		pointString.erase(0, lfpos + 1);

		try {
			x = getSubstring(tmp, "", ","); //can throw a runtime_error
			y = tmp.substr(tmp.find(",") + 1);
			if (y.empty()) {
				throw runtime_error("");
			}
		} catch (runtime_error& e) {
			throw runtime_error("SvgPolygon::getCoords: cannot read coords.");
		}

		coords.push_back(SvgPoint(strtol(x.c_str(), NULL, 0), strtol(y.c_str(), NULL, 0)));
		lfpos = pointString.find("\n");
	}

	return coords;
}
Exemplo n.º 4
0
SvgImage::SvgImage(
    std::string const& href,
    double x, double y,
    double w, double h
)
    : href( href )
    , position( SvgPoint( x, y ) )
    , size( SvgSize( w, h ) )
{}