summaryrefslogtreecommitdiffstats
path: root/DHTMLX.Export.PDF/Resizer.cs
blob: 4f9ef0ea8d3dc9682cd2be70fa3c5f99ee82ab7e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using PdfSharp.Drawing;
using PdfSharp;


namespace DHTMLX.Export.PDF
{
    internal class Resizer
    {
        private double _xRatio = 1;
        private double _yRatio = 1;
        public PageOrientation Orient { get; set; }
        private bool _keep = true;
        private void _CalcRatio(Orientation actual, Orientation desired)
        {
            if (desired == Orientation.Default || actual == desired)
                return;

            _keep = false;

            _yRatio = 1.0 / _xRatio;
        }

        public Resizer(PageOrientation from, Orientation to)
        {
            _CalcRatio(ToDHXOrient(from), to);
            if (_keep)
                Orient = from;
            else
                Orient = ToPDFOrient(to);
        }

        public PageOrientation ToPDFOrient(Orientation orient)
        {
            return orient == Orientation.Landscape ? PageOrientation.Landscape : PageOrientation.Portrait;
        }

        public Orientation ToDHXOrient(PageOrientation orient)
        {
            return orient == PageOrientation.Landscape ? Orientation.Landscape : Orientation.Portrait;
        }

        public XPoint Point(double x, double y)
        {
            return new XPoint(ResizeX(x), ResizeY(y));
        }

        public double ResizeX(double x)
        {
            if (_keep)
                return x;

            return x * _xRatio;
        }

        public double ResizeY(double y)
        {
            if (_keep)
                return y;

            return y * _yRatio;
        }

        public XRect Rect(double x, double y, double width, double height)
        {
            return new XRect(ResizeX(x), ResizeY(y), ResizeX(width), ResizeY(height));
        }
    }
}