Print Library, Svg Library, Utils Library, XYPlots
This commit is contained in:
@@ -1,9 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Volian.Svg.Library
|
||||
@@ -57,24 +53,24 @@ namespace Volian.Svg.Library
|
||||
public SvgMeasurement() { ;}
|
||||
public SvgMeasurement(int value)
|
||||
{
|
||||
_Value = Convert.ToSingle(value);
|
||||
Value = Convert.ToSingle(value);
|
||||
_Units = E_MeasurementUnits.PX;
|
||||
}
|
||||
public SvgMeasurement(float value)
|
||||
{
|
||||
_Value = value;
|
||||
Value = value;
|
||||
_Units = E_MeasurementUnits.PX;
|
||||
}
|
||||
public SvgMeasurement(float value, E_MeasurementUnits units)
|
||||
{
|
||||
_Value = value;
|
||||
Value = value;
|
||||
_Units = units;
|
||||
}
|
||||
public SvgMeasurement(string val)
|
||||
{
|
||||
val = val.Replace("{size}", "10");// B2020-145 BWD SAMG TSG-6 Fix for Base Format {size} parameter rather than font size
|
||||
MatchCollection mc = Regex.Matches(val.ToLower(), "([+-]?[.0-9]+)|(in|cm|mm|em|ex|pc|pt|px|percentage)");
|
||||
_Value = Convert.ToSingle(mc[0].Value);
|
||||
Value = Convert.ToSingle(mc[0].Value);
|
||||
if (mc.Count == 2)
|
||||
{
|
||||
//Console.WriteLine("{0} - '{1}'", val, mc[1].Value.ToUpper());
|
||||
@@ -93,108 +89,55 @@ namespace Volian.Svg.Library
|
||||
{
|
||||
float tmp = GetSizeInPoints(DPI);
|
||||
_Units = value;
|
||||
_Value *= (tmp / GetSizeInPoints(DPI));
|
||||
Value *= (tmp / GetSizeInPoints(DPI));
|
||||
}
|
||||
}
|
||||
private float _Value;
|
||||
public float Value
|
||||
{
|
||||
get { return _Value; }
|
||||
set { _Value = value; }
|
||||
}
|
||||
#endregion
|
||||
#region ToString
|
||||
public override string ToString()
|
||||
|
||||
public float Value { get; set; }
|
||||
#endregion
|
||||
#region ToString
|
||||
public override string ToString()
|
||||
{
|
||||
switch (_Units)
|
||||
{
|
||||
case E_MeasurementUnits.PX: // Default
|
||||
return string.Format("{0}", _Value);
|
||||
return string.Format("{0}", Value);
|
||||
case E_MeasurementUnits.PERCENTAGE: // Precentage is preceded by a space
|
||||
return string.Format("{0} {1}", _Value, _Units);
|
||||
return string.Format("{0} {1}", Value, _Units);
|
||||
}
|
||||
return string.Format("{0}{1}", _Value, _Units);
|
||||
return string.Format("{0}{1}", Value, _Units);
|
||||
}
|
||||
#endregion
|
||||
//public float SizeInPixels
|
||||
//{
|
||||
// get
|
||||
// {
|
||||
// switch (_Units)
|
||||
// {
|
||||
// case E_MeasurementUnits.PT: //Points - 72 per inch
|
||||
// return _Value * DPI / 72F;
|
||||
// case E_MeasurementUnits.PC: //Picas - 6 per inch
|
||||
// return _Value * DPI / 6F;
|
||||
// case E_MeasurementUnits.IN: //inches
|
||||
// return _Value * DPI;
|
||||
// case E_MeasurementUnits.CM: // Centimeter
|
||||
// return _Value * DPI / 2.54F;
|
||||
// case E_MeasurementUnits.MM: // Millimeter
|
||||
// return _Value * DPI / 25.4F;
|
||||
// case E_MeasurementUnits.EM: // EMs
|
||||
// return _Value * DPI / 8;
|
||||
// case E_MeasurementUnits.EX: // EXs
|
||||
// return _Value * DPI / 16;
|
||||
// default:
|
||||
// return _Value;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
public float GetSizeInPoints(float myDPI)
|
||||
{
|
||||
switch (_Units)
|
||||
{
|
||||
case E_MeasurementUnits.PX: //Pixels myDPI per inch
|
||||
return _Value * 72F / myDPI;
|
||||
return Value * 72F / myDPI;
|
||||
case E_MeasurementUnits.PC: //Picas - 6 per inch
|
||||
return _Value * 72F / 6F;
|
||||
return Value * 72F / 6F;
|
||||
case E_MeasurementUnits.IN: //inches
|
||||
return _Value * 72F;
|
||||
return Value * 72F;
|
||||
case E_MeasurementUnits.CM: // Centimeter
|
||||
return _Value * 72F / 2.54F;
|
||||
return Value * 72F / 2.54F;
|
||||
case E_MeasurementUnits.MM: // Millimeter
|
||||
return _Value * 72F / 25.4F;
|
||||
return Value * 72F / 25.4F;
|
||||
case E_MeasurementUnits.EM: // EMs
|
||||
return _Value * 72F / 8;
|
||||
return Value * 72F / 8;
|
||||
case E_MeasurementUnits.EX: // EXs
|
||||
return _Value * 72F / 16;
|
||||
return Value * 72F / 16;
|
||||
default: // Points
|
||||
return _Value;
|
||||
return Value;
|
||||
}
|
||||
}
|
||||
//public float SizeInPoints
|
||||
//{ get { return SizeInPixels * 72 / DPI; } }
|
||||
//public float SizeInInches
|
||||
//{ get { return SizeInPixels / DPI; } }
|
||||
//public float SizeInCentimeters
|
||||
//{ get { return SizeInPixels * 2.54F / DPI; } }
|
||||
//public float SizeInMillimeters
|
||||
//{ get { return SizeInPixels * 25.4F / DPI; } }
|
||||
//public float SizeInEms
|
||||
//{ get { return SizeInPixels * 5 / (6 * DPI); } }
|
||||
//public float SizeInExs
|
||||
//{ get { return SizeInPixels * 5 / (6 * DPI); } }
|
||||
//public float SizeInPicas
|
||||
//{ get { return SizeInPixels * 6 / DPI; } }
|
||||
//public Unit SizeInUnits
|
||||
//{ get { return new Unit((double)SizeInPoints, UnitTypeEnum.Point); } }
|
||||
public float GetSizeInPixels(float myDPI)
|
||||
{ return GetSizeInPoints(myDPI) * myDPI / 72F;}
|
||||
public float GetSizeInInches(float myDPI)
|
||||
{ return GetSizeInPoints(myDPI) / 72F; }
|
||||
public float GetSizeInCentimeters(float myDPI)
|
||||
{ return GetSizeInPoints(myDPI) * 2.54F / 72F; }
|
||||
public float GetSizeInMillimeters(float myDPI)
|
||||
{ return GetSizeInPoints(myDPI) * 25.4F / 72F; }
|
||||
public float GetSizeInEms(float myDPI)
|
||||
{ return GetSizeInPoints(myDPI) * 5 / (6 * 72F); }
|
||||
public float GetSizeInExs(float myDPI)
|
||||
{ return GetSizeInPoints(myDPI) * 5 / (6 * 72F); }
|
||||
public float GetSizeInPicas(float myDPI)
|
||||
{ return GetSizeInPoints(myDPI) * 6 / 72F; }
|
||||
//public Unit GetSizeInUnits(float myDPI)
|
||||
//{ return new Unit((double)GetSizeInPoints(myDPI), UnitTypeEnum.Point); }
|
||||
public float GetSizeInPixels(float myDPI) => GetSizeInPoints(myDPI) * myDPI / 72F;
|
||||
public float GetSizeInInches(float myDPI) => GetSizeInPoints(myDPI) / 72F;
|
||||
public float GetSizeInCentimeters(float myDPI) => GetSizeInPoints(myDPI) * 2.54F / 72F;
|
||||
public float GetSizeInMillimeters(float myDPI) => GetSizeInPoints(myDPI) * 25.4F / 72F;
|
||||
public float GetSizeInEms(float myDPI) => GetSizeInPoints(myDPI) * 5 / (6 * 72F);
|
||||
public float GetSizeInExs(float myDPI) => GetSizeInPoints(myDPI) * 5 / (6 * 72F);
|
||||
public float GetSizeInPicas(float myDPI) => GetSizeInPoints(myDPI) * 6 / 72F;
|
||||
|
||||
public static float StringToPoints(string value)
|
||||
{
|
||||
SvgMeasurement tmp = new SvgMeasurement(value);
|
||||
@@ -226,26 +169,9 @@ namespace Volian.Svg.Library
|
||||
}
|
||||
public class MeasurementTypeConverter : ExpandableObjectConverter
|
||||
{
|
||||
public override bool CanConvertTo(ITypeDescriptorContext context, Type t)
|
||||
{
|
||||
return t == typeof(String);
|
||||
}
|
||||
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
|
||||
{
|
||||
if (destType == typeof(string) && value is SvgMeasurement)
|
||||
{
|
||||
return value.ToString();
|
||||
}
|
||||
return base.ConvertTo(context, culture, value, destType);
|
||||
}
|
||||
public override bool CanConvertFrom(ITypeDescriptorContext context, Type t)
|
||||
{
|
||||
return t == typeof(String);
|
||||
}
|
||||
public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object val)
|
||||
{
|
||||
SvgMeasurement measurement = new SvgMeasurement((string)val);
|
||||
return measurement;
|
||||
}
|
||||
}
|
||||
public override bool CanConvertTo(ITypeDescriptorContext context, Type t) => t == typeof(String);
|
||||
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) => destType == typeof(string) && value is SvgMeasurement ? value.ToString() : base.ConvertTo(context, culture, value, destType);
|
||||
public override bool CanConvertFrom(ITypeDescriptorContext context, Type t) => t == typeof(String);
|
||||
public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object val) => new SvgMeasurement((string)val);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user