// Copyright (c) Dr. Dirk Lellinger. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Windows.Media;
namespace HtmlToFlowDocument.Rendering
{
///
/// Converts a relative size in percent to an absolute size. The relative size is given in the converter parameter,
/// the reference size is the property bound.
///
///
public class ImageToImageWidthConverter : IValueConverter
{
///
/// Gets an instance of .
///
///
/// The instance.
///
public static ImageToImageWidthConverter Instance { get; private set; } = new ImageToImageWidthConverter();
///
/// Converts a reference length and a percentage value to an absolute length.
///
/// The reference length. This value is produced by the binding source.
/// The type of the binding target property.
/// The percentage value. This value is from the converter parameter.
/// The culture to use in the converter.
///
/// The absolute length as referenceLength*100/percentageValue.
/// If the reference length was not set, a value of (1920/2) is used for the reference length.
///
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is System.Windows.Media.Imaging.BitmapImage bmpImage)
{
return bmpImage.PixelWidth;
}
else if (value is ImageSource imgSource)
{
return imgSource.Width;
}
else
{
return 16;
}
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}