private Rect GetImageBounds() { var result = new Rect(); if (ExecutionEngine.Instance.SelectedPaperFormat != null && !ExecutionEngine.Instance.SelectedPaperFormat.IsFree) { if ((ExecutionEngine.Context[Constants.OrderContextName] as Order).CropMode == Constants.ResizeToFitModeName) { result.Size = PhotoFrame.Inscribe(_photo.ImageSize, GetBorderSize()); result.X = (GetBorderSize().Width - result.Width) / 2; result.Y = (GetBorderSize().Height - result.Height) / 2; } else { result.Size = PhotoFrame.Describe(_photo.ImageSize, GetBorderSize()); double scale = Math.Min((result.Width - 2) / _photo.ImageSize.Width, (result.Height - 2) / _photo.ImageSize.Height); Rect r = _orderItem.GetCrop(ExecutionEngine.Instance.SelectedPaperFormat); result.X = r.X * -scale; result.Y = r.Y * -scale; } } else { result.Size = PhotoFrame.Inscribe(_photo.ImageSize, GetBorderSize()); result.X = 0; result.Y = 0; } result.Width -= 2; result.Height -= 2; return(result); }
private Size GetBorderSize() { Size imageSize = _photo.ImageSize; Size thumbSize = new Size(Width - 74 /* Margins + BorderThickness */, Height - 149 /* Margins + BorderThickness + bottom panel height */); if (ExecutionEngine.Instance.SelectedPaperFormat != null && !ExecutionEngine.Instance.SelectedPaperFormat.IsFree) { var result = new Size(); double ratio = (double)ExecutionEngine.Instance.SelectedPaperFormat.Width / (double)ExecutionEngine.Instance.SelectedPaperFormat.Height; if (_photo.ImageSize.Width < _photo.ImageSize.Height) { ratio = 1 / ratio; } result.Height = thumbSize.Height; result.Width = thumbSize.Height * ratio; if (result.Width > thumbSize.Width) { result.Width = thumbSize.Width; result.Height = thumbSize.Width / ratio; } return(result); } else { return(PhotoFrame.Inscribe(imageSize, thumbSize)); } }