public static double Convert(double value, CodecsRasterizeDocumentUnit sourceUnit, int resolution, CodecsRasterizeDocumentUnit destinationUnit) { double pixels = ConvertToPixels(value, sourceUnit, resolution); double result = ConvertFromPixels(pixels, destinationUnit, resolution); return(result); }
private void _unitComboBox_SelectedIndexChanged(object sender, EventArgs e) { // Save the old unit so we can do the converstion CodecsRasterizeDocumentUnit newUnit = Tools.ValueNameItem <CodecsRasterizeDocumentUnit> .GetSelectedItem(_unitComboBox.SelectedItem); int resolution = _resolution; if (resolution == 0) { resolution = Tools.Units.ScreenResolution; } // Re-calculate the width and height and margins with new units _pageWidth = Tools.Units.Convert(_pageWidth, _unit, resolution, newUnit); _pageHeight = Tools.Units.Convert(_pageHeight, _unit, resolution, newUnit); _leftMargin = Tools.Units.Convert(_leftMargin, _unit, resolution, newUnit); _topMargin = Tools.Units.Convert(_topMargin, _unit, resolution, newUnit); _rightMargin = Tools.Units.Convert(_rightMargin, _unit, resolution, newUnit); _bottomMargin = Tools.Units.Convert(_bottomMargin, _unit, resolution, newUnit); // Set the new unit and size _unit = newUnit; _pageWidthTextBox.Text = _pageWidth.ToString("0.00"); _pageHeightTextBox.Text = _pageHeight.ToString("0.00"); _leftMarginTextBox.Text = _leftMargin.ToString("0.00"); _topMarginTextBox.Text = _topMargin.ToString("0.00"); _rightMarginTextBox.Text = _rightMargin.ToString("0.00"); _bottomMarginTextBox.Text = _bottomMargin.ToString("0.00"); }
/// <summary> /// Called by the owner to initialize /// </summary> public void SetData(RasterCodecs rasterCodecsInstance) { // Set the state of the controls // Event hooks _pageWidthTextBox.PreviewKeyDown += new PreviewKeyDownEventHandler(_textBox_PreviewKeyDown); _pageWidthTextBox.LostFocus += new EventHandler(_textBox_LostFocus); _pageHeightTextBox.PreviewKeyDown += new PreviewKeyDownEventHandler(_textBox_PreviewKeyDown); _pageHeightTextBox.LostFocus += new EventHandler(_textBox_LostFocus); _leftMarginTextBox.PreviewKeyDown += new PreviewKeyDownEventHandler(_textBox_PreviewKeyDown); _leftMarginTextBox.LostFocus += new EventHandler(_textBox_LostFocus); _topMarginTextBox.PreviewKeyDown += new PreviewKeyDownEventHandler(_textBox_PreviewKeyDown); _topMarginTextBox.LostFocus += new EventHandler(_textBox_LostFocus); _rightMarginTextBox.PreviewKeyDown += new PreviewKeyDownEventHandler(_textBox_PreviewKeyDown); _rightMarginTextBox.LostFocus += new EventHandler(_textBox_LostFocus); _bottomMarginTextBox.PreviewKeyDown += new PreviewKeyDownEventHandler(_textBox_PreviewKeyDown); _bottomMarginTextBox.LostFocus += new EventHandler(_textBox_LostFocus); _resolutionComboBox.PreviewKeyDown += new PreviewKeyDownEventHandler(_textBox_PreviewKeyDown); _resolutionComboBox.LostFocus += new EventHandler(_resolutionComboBox_LostFocus); // Initialize the units _unitComboBox.Items.Add(new Tools.ValueNameItem <CodecsRasterizeDocumentUnit>(CodecsRasterizeDocumentUnit.Pixel, "Pixel")); _unitComboBox.Items.Add(new Tools.ValueNameItem <CodecsRasterizeDocumentUnit>(CodecsRasterizeDocumentUnit.Inch, "Inch")); _unitComboBox.Items.Add(new Tools.ValueNameItem <CodecsRasterizeDocumentUnit>(CodecsRasterizeDocumentUnit.Millimeter, "Millimeter")); _sizeModeComboBox.Items.Add(new Tools.ValueNameItem <CodecsRasterizeDocumentSizeMode>(CodecsRasterizeDocumentSizeMode.None, "None")); _sizeModeComboBox.Items.Add(new Tools.ValueNameItem <CodecsRasterizeDocumentSizeMode>(CodecsRasterizeDocumentSizeMode.Fit, "Fit")); _sizeModeComboBox.Items.Add(new Tools.ValueNameItem <CodecsRasterizeDocumentSizeMode>(CodecsRasterizeDocumentSizeMode.FitAlways, "Fit always")); _sizeModeComboBox.Items.Add(new Tools.ValueNameItem <CodecsRasterizeDocumentSizeMode>(CodecsRasterizeDocumentSizeMode.FitWidth, "Fit width")); _sizeModeComboBox.Items.Add(new Tools.ValueNameItem <CodecsRasterizeDocumentSizeMode>(CodecsRasterizeDocumentSizeMode.Stretch, "Stretch")); CodecsRasterizeDocumentLoadOptions rasterizeDocumentLoadOptions = rasterCodecsInstance.Options.RasterizeDocument.Load; // Get the temporary values _pageWidth = rasterizeDocumentLoadOptions.PageWidth; _pageHeight = rasterizeDocumentLoadOptions.PageHeight; _leftMargin = rasterizeDocumentLoadOptions.LeftMargin; _topMargin = rasterizeDocumentLoadOptions.TopMargin; _rightMargin = rasterizeDocumentLoadOptions.RightMargin; _bottomMargin = rasterizeDocumentLoadOptions.BottomMargin; _unit = rasterizeDocumentLoadOptions.Unit; _resolution = rasterizeDocumentLoadOptions.XResolution; _sizeMode = rasterizeDocumentLoadOptions.SizeMode; // Now set the current values UpdateControlsFromValues(); UpdateUIState(); }
public static string Format(double width, double height, CodecsRasterizeDocumentUnit unit) { if (unit == CodecsRasterizeDocumentUnit.Pixel) { return(string.Format("{0} x {1} {2}", (int)width, (int)height, _unitAbbreviations[(int)unit])); } else { return(string.Format("{0} x {1} {2}", width.ToString("0.00"), height.ToString("0.00"), _unitAbbreviations[(int)unit])); } }
private void _resetToDefaultsButton_Click(object sender, EventArgs e) { _pageWidth = 8.5; _pageHeight = 11; _leftMargin = 1.25; _topMargin = 1; _rightMargin = 1.25; _bottomMargin = 1; _unit = CodecsRasterizeDocumentUnit.Inch; _resolution = 0; _sizeMode = CodecsRasterizeDocumentSizeMode.None; UpdateControlsFromValues(); UpdateUIState(); }
private static double ConvertFromPixels(double value, CodecsRasterizeDocumentUnit unit, int resolution) { double ret; switch (unit) { case CodecsRasterizeDocumentUnit.Pixel: ret = value; break; case CodecsRasterizeDocumentUnit.Inch: ret = value / (double)resolution; break; case CodecsRasterizeDocumentUnit.Millimeter: ret = value * _mmRatio / (double)resolution; break; default: throw new InvalidOperationException(); } return(ret); }
/// <summary> /// Called by the owner to initialize /// </summary> public void SetData(CodecsImageInfo imageInfo, RasterCodecs rasterCodecsInstance) { // Set the state of the controls if (imageInfo != null) { // Get the index of the format in the DocumentFormats int index = Tools.DocumentFormats.GetFormatIndex(imageInfo.Format); CodecsRasterizeDocumentUnit viewUnit = rasterCodecsInstance.Options.RasterizeDocument.Load.Unit; double originalWidth; double originalHeight; CodecsRasterizeDocumentUnit originalUnit; if (index != -1) { // Document format _formatValueLabel.Text = string.Format("{0} ({1})", Tools.DocumentFormats.FormatFriendlyNames[index], Tools.DocumentFormats.Formats[index]); originalWidth = imageInfo.Document.PageWidth; originalHeight = imageInfo.Document.PageHeight; originalUnit = imageInfo.Document.Unit; _warningLabel.Visible = false; } else { // Raster format _formatValueLabel.Text = imageInfo.Format.ToString(); originalWidth = imageInfo.Width; originalHeight = imageInfo.Height; originalUnit = CodecsRasterizeDocumentUnit.Pixel; _warningLabel.Visible = true; } _pagesValueLabel.Text = imageInfo.TotalPages.ToString(); // Convert to the view unit originalWidth = Tools.Units.Convert(originalWidth, originalUnit, Tools.Units.ScreenResolution, viewUnit); originalHeight = Tools.Units.Convert(originalHeight, originalUnit, Tools.Units.ScreenResolution, viewUnit); _originalDocumentSizeValueLabel.Text = Tools.Units.Format(originalWidth, originalHeight, viewUnit); double loadWidth = Tools.Units.Convert(imageInfo.Width, CodecsRasterizeDocumentUnit.Pixel, imageInfo.XResolution, viewUnit); double loadHeight = Tools.Units.Convert(imageInfo.Height, CodecsRasterizeDocumentUnit.Pixel, imageInfo.YResolution, viewUnit); _loadDocumentSizeValueLabel.Text = Tools.Units.Format(loadWidth, loadHeight, viewUnit); _loadDocumentSizePixelsLabel.Text = string.Format("{0} at {1} pixels/inch", Tools.Units.Format(imageInfo.Width, imageInfo.Height, CodecsRasterizeDocumentUnit.Pixel), imageInfo.XResolution); // Show everything _formatValueLabel.Visible = true; _pagesValueLabel.Visible = true; _originalDocumentSizeValueLabel.Visible = true; _loadDocumentSizeValueLabel.Visible = true; _loadDocumentSizePixelsLabel.Visible = true; } else { // Hide everything _formatValueLabel.Visible = false; _pagesValueLabel.Visible = false; _originalDocumentSizeValueLabel.Visible = false; _loadDocumentSizeValueLabel.Visible = false; _loadDocumentSizePixelsLabel.Visible = false; _warningLabel.Visible = false; } }