/** * Fits drawing on page. Affects DXF variable $PINSBASE. */ bool RS_Graphic::fitToPage() { bool ret(true); double border = RS_Units::convert(25.0, RS2::Millimeter, getUnit()); RS_Vector ps = getPaperSize(); if(ps.x>border && ps.y>border) ps -= RS_Vector(border, border); RS_Vector s = getSize(); double fx = RS_MAXDOUBLE; double fy = RS_MAXDOUBLE; double fxy; //ps = RS_Units::convert(ps, getUnit(), RS2::Millimeter); // tin-pot 2011-12-30: TODO: can s.x < 0.0 (==> fx < 0.0) happen? if (fabs(s.x) > 1.0e-10) { fx = ps.x / s.x; } if (fabs(s.y) > 1.0e-10) { fy = ps.y / s.y; } fxy = std::min(fx, fy); if (fxy >= RS_MAXDOUBLE || fxy <= 1.0e-10) { setPaperSize( RS_Units::convert(RS_Vector(210.,297.) , RS2::Millimeter , getUnit() ) ); fitToPage(); ret=false; } setPaperScale(fxy); centerToPage(); return ret; }
/** * Sets the unit of this graphic to 'u' */ void RS_Graphic::setUnit(RS2::Unit u) { setPaperSize(RS_Units::convert(getPaperSize(), getUnit(), u)); addVariable("$INSUNITS", (int)u, 70); //unit = u; }
/** * Centers drawing on page. Affects DXF variable $PINSBASE. */ void RS_Graphic::centerToPage() { RS_Vector size = getPaperSize(); double scale = getPaperScale(); RS_Vector pinsbase = (size-getSize()*scale)/2.0 - getMin()*scale; setPaperInsertionBase(pinsbase); }
/** * @return Paper format. * This is determined by the variables "$PLIMMIN" and "$PLIMMAX". * * @param landscape will be set to true for landscape and false for portrait if not NULL. */ RS2::PaperFormat RS_Graphic::getPaperFormat(bool* landscape) { RS_Vector size = RS_Units::convert(getPaperSize(), getUnit(), RS2::Millimeter); if (landscape!=NULL) { *landscape = (size.x>size.y); } return RS_Units::paperSizeToFormat(size); }
/** * Centers drawing on page. Affects DXF variable $PINSBASE. */ void RS_Graphic::centerToPage() { RS_Vector size = getPaperSize(); double scale = getPaperScale(); auto&& s=getSize(); auto&& sMin=getMin(); /** avoid zero size, bug#3573158 */ if(fabs(s.x)<RS_TOLERANCE) { s.x=10.; sMin.x=-5.; } if(fabs(s.y)<RS_TOLERANCE) { s.y=10.; sMin.y=-5.; } RS_Vector pinsbase = (size-s*scale)/2.0 - sMin*scale; setPaperInsertionBase(pinsbase); }
/** * Fits drawing on page. Affects DXF variable $PINSBASE. */ void RS_Graphic::fitToPage() { double border = RS_Units::convert(25.0, RS2::Millimeter, getUnit()); RS_Vector ps = getPaperSize() - RS_Vector(border, border); RS_Vector s = getSize(); double fx = RS_MAXDOUBLE; double fy = RS_MAXDOUBLE; //double factor = 1.0; //ps = RS_Units::convert(ps, getUnit(), RS2::Millimeter); if (fabs(s.x)>1.0e-6) { fx = ps.x / s.x; } if (fabs(s.y)>1.0e-6) { fy = ps.y / s.y; } setPaperScale(std::min(fx, fy)); centerToPage(); }
void PageFormat::read(XmlReader& e, Score* score) { qreal _oddRightMargin = 0.0; qreal _evenRightMargin = 0.0; bool landscape = false; QString type; while (e.readNextStartElement()) { const QStringRef& tag(e.name()); if (tag == "pageFormat") // obsolete setSize(getPaperSize(e.readElementText())); else if (tag == "landscape") // obsolete landscape = e.readInt(); else if (tag == "page-margins") { type = e.attribute("type","both"); qreal lm = 0.0, rm = 0.0, tm = 0.0, bm = 0.0; while (e.readNextStartElement()) { const QStringRef& tag(e.name()); qreal val = e.readDouble() * 0.5 / PPI; if (tag == "left-margin") lm = val; else if (tag == "right-margin") rm = val; else if (tag == "top-margin") tm = val; else if (tag == "bottom-margin") bm = val; else e.unknown(); } _twosided = type == "odd" || type == "even"; if (type == "odd" || type == "both") { _oddLeftMargin = lm; _oddRightMargin = rm; _oddTopMargin = tm; _oddBottomMargin = bm; } if (type == "even" || type == "both") { _evenLeftMargin = lm; _evenRightMargin = rm; _evenTopMargin = tm; _evenBottomMargin = bm; } } else if (tag == "page-height") _size.rheight() = e.readDouble() * 0.5 / PPI; else if (tag == "page-width") _size.rwidth() = e.readDouble() * .5 / PPI; else if (tag == "page-offset") { // obsolete, moved to Score QString val(e.readElementText()); if(score) score->setPageNumberOffset(val.toInt()); } else e.unknown(); } if (landscape) _size.transpose(); qreal w1 = _size.width() - _oddLeftMargin - _oddRightMargin; qreal w2 = _size.width() - _evenLeftMargin - _evenRightMargin; _printableWidth = qMax(w1, w2); // silently adjust right margins }