/// <summary> /// Low-level draw method used by other rendering methods. /// </summary> /// <param name="visitor">the draw visitor</param> /// <param name="bounds">a bound rendering element</param> /// <param name="zoom">if the diagram is zoomed at all</param> /// <param name="viewBounds">the view bounds - the root will be centered in the bounds</param> protected void Draw(IDrawVisitor visitor, double zoom, Bounds bounds, Rect viewBounds) { var modelScale = zoom * model.GetScale(); var zoomToFit = Math.Min(viewBounds.Width / (bounds.Width * modelScale), viewBounds.Height / (bounds.Height * modelScale)); var transform = Matrix.Identity; // setup up transform transform.TranslatePrepend(viewBounds.CenterX(), viewBounds.CenterY()); transform.ScalePrepend(modelScale, -modelScale); // default is shrink only unless specified if (model.GetFitToScreen() || zoomToFit < 1) { transform.ScalePrepend(zoomToFit, zoomToFit); } transform.TranslatePrepend(-(bounds.MinX + bounds.MaxX) / 2, -(bounds.MinY + bounds.MaxY) / 2); // not always needed var fontManager = new WPFFontManager { Zoom = zoomToFit }; visitor.RendererModel = model; visitor.FontManager = fontManager; visitor.Visit(bounds.Root, new MatrixTransform(transform)); }
private double CalcFitting(double margin, double padding, Dimensions required, string fmt) { if (dimensions == Dimensions.Automatic) { return(1); // no fitting } var targetDim = dimensions; targetDim = targetDim.Add(-2 * margin, -2 * margin).Add(-((nCol - 1) * padding), -((nRow - 1) * padding)); double resize = Math.Min(targetDim.width / required.width, targetDim.height / required.height); if (resize > 1 && !model.GetFitToScreen()) { resize = 1; } return(resize); }
private double CalcFitting(double margin, double padding, Dimensions mainRequired, Dimensions sideRequired, Dimensions titleRequired, double firstRowHeight, string fmt) { if (dimensions == Dimensions.Automatic) { return(1); // no fitting } var nSideCol = xOffsetSide.Length - 1; var nSideRow = yOffsetSide.Length - 1; // need padding in calculation var mainCompOffset = sideRequired.height > 0 ? sideRequired.height + (nSideRow * padding) - (firstRowHeight / 2) : 0; if (mainCompOffset < 0) { mainCompOffset = 0; } Dimensions required = mainRequired.Add(sideRequired.width, mainCompOffset) .Add(0, Math.Max(0, titleRequired.height)); // We take out the padding height of the side components but in reality // some of it overlaps, since reactions are normally wider then they are // tall we won't normally bit fitting by this parameter. If do fit by this // parameter we might make the depiction smaller then it needs to be but thats // better than cutting bits off var targetDim = dimensions; targetDim = targetDim.Add(-2 * margin, -2 * margin) .Add(-((nCol - 1) * padding), -((nRow - 1) * padding)) .Add(-(nSideCol - 1) * padding, -(nSideRow - 1) * padding) .Add(0, titleRequired.height > 0 ? -padding : 0); var resize = Math.Min(targetDim.width / required.width, targetDim.height / required.height); if (resize > 1 && !model.GetFitToScreen()) { resize = 1; } return(resize); }