示例#1
0
 private void CheckForValidRenderDimensionsForFont(IRenderDimensions renderDimensions)
 {
     if (renderDimensions == null || renderDimensions.FontSize <= 0)
     {
         throw new ArgumentException("A non null render device with a font size is required to calculate em or rem units.");
     }
 }
示例#2
0
 private void CheckForValidRenderDimensions(IRenderDimensions renderDimensions, RenderMode mode)
 {
     if (renderDimensions == null || mode == RenderMode.Undefined || (mode == RenderMode.Horizontal ? renderDimensions.RenderWidth : renderDimensions.RenderHeight) <= 0)
     {
         throw new ArgumentException("A non null render device with a font size is required to calculate em or rem units.");
     }
 }
示例#3
0
        /// <summary>
        /// Converts the length to the given unit, if possible. If the current
        /// or given unit is relative, then an exception will be thrown.
        /// </summary>
        /// <param name="unit">The unit to convert to.</param>
        /// <param name="renderDimensions">the render device used to calculate relative units, can be null if units are absolute.</param>
        /// <param name="mode">Signifies the axis the unit represents, use to calculate relative units where the axis matters.</param>
        /// <returns>The value in the given unit of the current length.</returns>
        public Double To(Unit unit, IRenderDimensions renderDimensions, RenderMode mode)
        {
            var value = ToPixel(renderDimensions, mode);

            switch (unit)
            {
            case Unit.In:     // 1 in = 2.54 cm
                return(value / 96.0);

            case Unit.Mm:     // 1 mm = 0.1 cm
                return(value * 127.0 / (5.0 * 96.0));

            case Unit.Pc:     // 1 pc = 12 pt
                return(value * 72.0 / (12.0 * 96.0));

            case Unit.Pt:     // 1 pt = 1/72 in
                return(value * 72.0 / 96.0);

            case Unit.Cm:     // 1 cm = 50/127 in
                return(value * 127.0 / (50.0 * 96.0));

            case Unit.Px:     // 1 px = 1/96 in
                return(value);

            case Unit.Percent:
                CheckForValidRenderDimensions(renderDimensions, mode);
                return(value / (mode == RenderMode.Horizontal ? renderDimensions.RenderWidth : renderDimensions.RenderHeight) * 100);

            case Unit.Em:
                CheckForValidRenderDimensionsForFont(renderDimensions);
                return(value / renderDimensions.FontSize);

            case Unit.Rem:
                // here we dont actually know the root font size but currently the only IRenderDimensions used is
                // the IRenderDevice meaning its always the root font size
                CheckForValidRenderDimensionsForFont(renderDimensions);
                return(value / renderDimensions.FontSize);

            case Unit.Vh:
                CheckForValidRenderDimensions(renderDimensions, RenderMode.Vertical);
                return(value / (0.01 * renderDimensions.RenderHeight));

            case Unit.Vw:
                CheckForValidRenderDimensions(renderDimensions, RenderMode.Horizontal);
                return(value / (0.01 * renderDimensions.RenderWidth));

            case Unit.Vmax:
                CheckForValidRenderDimensions(renderDimensions, RenderMode.Vertical);
                CheckForValidRenderDimensions(renderDimensions, RenderMode.Horizontal);
                return(value / (0.01 * Math.Max(renderDimensions.RenderHeight, renderDimensions.RenderWidth)));

            case Unit.Vmin:
                CheckForValidRenderDimensions(renderDimensions, RenderMode.Vertical);
                CheckForValidRenderDimensions(renderDimensions, RenderMode.Horizontal);
                return(value / (0.01 * Math.Min(renderDimensions.RenderHeight, renderDimensions.RenderWidth)));

            default:
                throw new InvalidOperationException("Unsupported unit cannot be converted.");
            }
        }
示例#4
0
        /// <summary>
        /// Computes the matrix for the given transformation.
        /// </summary>
        /// <returns>The transformation matrix representation.</returns>
        public TransformMatrix ComputeMatrix(IRenderDimensions renderDimensions)
        {
            var a = Math.Tan((_alpha as Angle ? ?? Angle.Zero).ToRadian());
            var b = Math.Tan((_beta as Angle? ?? Angle.Zero).ToRadian());

            return(new TransformMatrix(1.0, a, 0.0, b, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
        }
        /// <summary>
        /// Computes the matrix for the given transformation.
        /// </summary>
        /// <returns>The transformation matrix representation.</returns>
        public TransformMatrix ComputeMatrix(IRenderDimensions renderDimensions)
        {
            var x  = _x as Length? ?? Length.Zero;
            var y  = _y as Length? ?? Length.Zero;
            var z  = _z as Length? ?? Length.Zero;
            var dx = x.ToPixel(renderDimensions, RenderMode.Horizontal);
            var dy = y.ToPixel(renderDimensions, RenderMode.Vertical);
            var dz = z.ToPixel(renderDimensions, RenderMode.Undefined);

            return(new TransformMatrix(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, dx, dy, dz, 0.0, 0.0, 0.0));
        }
示例#6
0
        /// <summary>
        /// Computes the matrix for the given transformation.
        /// </summary>
        /// <returns>The transformation matrix representation.</returns>
        public TransformMatrix ComputeMatrix(IRenderDimensions renderDimensions)
        {
            var norm  = 1.0 / Math.Sqrt(_x * _x + _y * _y + _z * _z);
            var alpha = _angle as Angle ? ?? Values.Angle.Zero;
            var sina  = Math.Sin(alpha.ToRadian());
            var cosa  = Math.Cos(alpha.ToRadian());
            var l     = _x * norm;
            var m     = _y * norm;
            var n     = _z * norm;
            var omc   = (1.0 - cosa);

            return(new TransformMatrix(
                       l * l * omc + cosa, m * l * omc - n * sina, n * l * omc + m * sina,
                       l * m * omc + n * sina, m * m * omc + cosa, n * m * omc - l * sina,
                       l * n * omc - m * sina, m * n * omc + l * sina, n * n * omc + cosa,
                       0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
        }
示例#7
0
        /// <summary>
        /// Returns the stored matrix.
        /// </summary>
        /// <returns>The current transformation.</returns>
        public TransformMatrix ComputeMatrix(IRenderDimensions dimensions)
        {
            var values = _values;

            if (values.Length == 6)
            {
                values = new Double[]
                {
                    _values[0], _values[2], 0.0, _values[4],
                    _values[1], _values[3], 0.0, _values[5],
                    1.0, 0.0, 0.0, 0.0,
                    0.0, 0.0, 0.0, 1.0
                };
            }

            return(new TransformMatrix(values));
        }
        /// <summary>
        /// Computes the matrix for the given transformation.
        /// </summary>
        /// <returns>The transformation matrix representation.</returns>
        public TransformMatrix ComputeMatrix(IRenderDimensions renderDimensions)
        {
            var distance = _distance as Length? ?? Length.Zero;

            return(new TransformMatrix(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0 / distance.ToPixel(renderDimensions, RenderMode.Undefined)));
        }
示例#9
0
 /// <summary>
 /// Computes the matrix for the given transformation.
 /// </summary>
 /// <returns>The transformation matrix representation.</returns>
 public TransformMatrix ComputeMatrix(IRenderDimensions renderDimensions) =>
 new TransformMatrix(_sx, 0f, 0f, 0f, _sy, 0f, 0f, 0f, _sz, 0f, 0f, 0f, 0f, 0f, 0f);