Ejemplo n.º 1
0
        private void widthUnitsChanged(ListBox sender, TextBox target, units newUnit, units oldUnit)
        {
            if (conv.specs == null)
            {
                return;
            }
            double value = RenderSpecs.convertLengthUnits(conv.specs.width, newUnit, oldUnit);

            target.Text = Math.Truncate(value).ToString();
        }
Ejemplo n.º 2
0
        private static double parseDimToPoints(string dimArg)
        {
            string val;
            units  valUnit;

            if (dimArg.Contains(units.cm.ToString()))
            {
                valUnit = units.cm;
                val     = dimArg.Remove(dimArg.Length - units.cm.ToString().Length);
            }
            else if (dimArg.Contains(units.inches.ToString()))
            {
                valUnit = units.inches;
                val     = dimArg.Remove(dimArg.Length - units.inches.ToString().Length);
            }
            else if (dimArg.Contains(units.pts.ToString()))
            {
                valUnit = units.pts;
                val     = dimArg.Remove(dimArg.Length - units.pts.ToString().Length);
            }
            else
            {
                throw new Exception("The units passed to -dimensions{w,h} are incorrect. Please pass pts, inches or cm.");
            }
            try
            {
                double  value;
                Boolean parsed = Double.TryParse(val, out value);
                if (parsed)
                {
                    value = RenderSpecs.convertLengthUnits(value, units.pts, valUnit);
                    return(value);
                }
                else
                {
                    throw new Exception("The values for at least one of the dimensions could not be parsed.");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(0);
            }
        }