Пример #1
0
wxSVGRect wxSVGLineElement::GetBBox(wxSVG_COORDINATES coordinates)
{
  wxSVGPoint p1 = wxSVGPoint(GetX1().GetAnimVal(), GetY1().GetAnimVal());
  wxSVGPoint p2 = wxSVGPoint(GetX2().GetAnimVal(), GetY2().GetAnimVal());
  if (coordinates != wxSVG_COORDINATES_USER)
  {
    wxSVGMatrix matrix = GetMatrix(coordinates);
    p1 = p1.MatrixTransform(matrix);
    p2 = p2.MatrixTransform(matrix);
  }
  
  double x1 = p1.GetX();
  double y1 = p1.GetY();
  double x2 = p2.GetX();
  double y2 = p2.GetY();

  wxSVGRect bbox(x1, y1, x2 - x1, y2 - y1);
  
  if (x1 > x2)
  {
	bbox.SetX(x2);
	bbox.SetWidth(x1 - x2);
  }
  
  if (y1 > y2)
  {
	bbox.SetY(y2);
	bbox.SetHeight(y1 - y2);
  }
  
  return bbox;
}
Пример #2
0
void wxSVGCtrlBase::MoveElement(wxSVGElement* elem, double Xposition, double Yposition) {
	if (elem->GetDtd() == wxSVG_RECT_ELEMENT) {
		double stroke_width = 0;
  		if (((wxSVGRectElement*)elem)->GetStroke().GetPaintType() != wxSVG_PAINTTYPE_NONE)
  			stroke_width = ((wxSVGRectElement*)elem)->GetStrokeWidth();
		wxSVGMatrix CTM = ((wxSVGRectElement*)elem)->GetCTM();
		double denom = CTM.GetB()*CTM.GetC() - CTM.GetA()*CTM.GetD();
		double x = (CTM.GetC()*(Yposition-CTM.GetF()) - CTM.GetD()*(Xposition-CTM.GetE())) / denom;
		double y = (CTM.GetB()*(Xposition-CTM.GetE()) - CTM.GetA()*(Yposition-CTM.GetF())) / denom;
		wxSVGLength Xvalue(x + stroke_width / 2);
		wxSVGLength Yvalue(y + stroke_width / 2);
		((wxSVGRectElement*)elem)->SetX(Xvalue);
		((wxSVGRectElement*)elem)->SetY(Yvalue);
	} else {
		wxSVGTransformable* element = wxSVGTransformable::GetSVGTransformable(*elem);
        wxSVGMatrix CTM = element->GetCTM();
		wxSVGTransformList transforms = element->GetTransform().GetBaseVal();
		wxSVGMatrix matrix = transforms[(int)transforms.Count()-1].GetMatrix();
		wxSVGRect bbox = element->GetResultBBox(wxSVG_COORDINATES_VIEWPORT);
		wxSVGPoint LeftUp = wxSVGPoint(bbox.GetX(), bbox.GetY());
		wxSVGMatrix new_matrix = wxSVGMatrix();
		new_matrix = new_matrix.Translate(Xposition - LeftUp.GetX(), Yposition - LeftUp.GetY());
		new_matrix = matrix.Multiply(CTM.Inverse().Multiply(new_matrix.Multiply(CTM)));
		transforms[transforms.Count()-1].SetMatrix(new_matrix);
		element->SetTransform(transforms);
	}
}
Пример #3
0
wxSVGRect wxSVGEllipseElement::GetBBox(wxSVG_COORDINATES coordinates) {
	if (coordinates == wxSVG_COORDINATES_USER)
		return wxSVGRect(GetCx().GetBaseVal() - GetRx().GetBaseVal(), GetCy().GetBaseVal() - GetRy().GetBaseVal(),
				2 * GetRx().GetBaseVal(), 2 * GetRy().GetBaseVal());

	wxSVGMatrix matrix = GetMatrix(coordinates);

	double angles[4];
	angles[0] = atan((GetRy().GetBaseVal() * matrix.GetC()) / (GetRx().GetBaseVal() * matrix.GetA()));
	angles[1] = atan((GetRy().GetBaseVal() * matrix.GetD()) / (GetRx().GetBaseVal() * matrix.GetB()));
	angles[2] = angles[0] + pi;
	angles[3] = angles[1] + pi;

	wxSVGPointList points = wxSVGPointList();
	for (int i = 0; i < 4; i++) {
		points.Add(wxSVGPoint(GetRx().GetBaseVal() * cos(angles[i]) + GetCx().GetBaseVal(),
				GetRy().GetBaseVal() * sin(angles[i]) + GetCy().GetBaseVal()));
	}

	wxSVGPoint p0 = points[0].MatrixTransform(matrix);
	wxSVGRect bbox(p0.GetX(), p0.GetY(), 0, 0);

	wxSVGPoint pi = wxSVGPoint();
	for (int i = 1; i < (int) points.Count(); i++) {
		pi = points[i].MatrixTransform(matrix);
		if (bbox.GetX() > pi.GetX()) {
			bbox.SetWidth(bbox.GetWidth() + bbox.GetX() - pi.GetX());
			bbox.SetX(pi.GetX());
		}
		if (bbox.GetY() > pi.GetY()) {
			bbox.SetHeight(bbox.GetHeight() + bbox.GetY() - pi.GetY());
			bbox.SetY(pi.GetY());
		}

		if (bbox.GetX() + bbox.GetWidth() < pi.GetX())
			bbox.SetWidth(pi.GetX() - bbox.GetX());
		if (bbox.GetY() + bbox.GetHeight() < pi.GetY())
			bbox.SetHeight(pi.GetY() - bbox.GetY());
	}

	return bbox;
}
Пример #4
0
wxSVGPoint wxSVGSVGElement::CreateSVGPoint() const {
    return wxSVGPoint();
}