public EncapsulatedPostScriptRenderer(ISizeCalculation iSize, GColor darkColor, GColor lightColor)
        {
#endif
            m_iSize            = iSize;
            m_DarkColor        = darkColor;
            m_LightColor       = lightColor;
            m_DrawingTechnique = EpsModuleDrawingTechnique.Squares;
        }
Пример #2
0
        public SVGRenderer(ISizeCalculation isize, GColor darkcolor, GColor lightcolor)
        {
#endif

            m_iSize      = isize;
            m_DarkColor  = darkcolor;
            m_LightColor = lightcolor;
        }
Пример #3
0
        private static double Luminance(GColor color)
        {
#endif

            double r, g, b;
            r = Colorspace(color.R);
            g = Colorspace(color.G);
            b = Colorspace(color.B);

            return(0.2126 * r + 0.7152 * g + 0.0722 * b);
        }
Пример #4
0
        internal static string BackgroundStyle(GColor color)
        {
#endif

            double alpha = ConvertAlpha(color.A);
            return(string.Format(CultureInfo.InvariantCulture.NumberFormat,
                                 "style=\"background-color:rgb({0},{1},{2});background-color:rgba({0},{1},{2},{3});\"",
                                 color.R,
                                 color.G,
                                 color.B,
                                 alpha));
        }
Пример #5
0
        public static Contrast GetContrast(GColor backGround, GColor frontColor)
        {
            GColor back  = new FormColor(Color.FromArgb(backGround.A, backGround.R, backGround.G, backGround.B));
            GColor front = new FormColor(Color.FromArgb(frontColor.A, frontColor.R, frontColor.G, frontColor.B));
#endif

            if (back.A == 255)
            {
                if (front.A < 255)
                {
                    front = OverlayOn(front, back);
                }
                double l1    = Luminance(back) + 0.05;
                double l2    = Luminance(front) + 0.05;
                double ratio = l2 > l1 ? l2 / l1 : l1 / l2;

                ratio = Math.Round(ratio, 1);
                return(new Contrast()
                {
                    Ratio = ratio,
                    Error = 0,
                    Min = ratio,
                    Max = ratio,
                    Closet = null,
                    Farthest = null
                });
            }

            double onBlack = GetContrast(OverlayOn(back, Black), front).Ratio;
            double onWhite = GetContrast(OverlayOn(back, White), front).Ratio;

            double max = Math.Max(onBlack, onWhite);

#if NETFX_CORE || SILVERLIGHT
            Color closest = Closest(backGround, frontColor);
#else
            GColor closest = Closest(backGround, frontColor);
#endif
            double min = GetContrast(OverlayOn(back, closest), front).Ratio;

            return(new Contrast()
            {
                Ratio = Math.Round((max + min) / 2, 2),
                Error = Math.Round((max - min) / 2, 2),
                Min = min,
                Max = max,
                Closet = closest,
                Farthest = onWhite == max ? White : Black
            });
        }
Пример #6
0
        private static GColor Closest(GColor backGround, GColor frontColor)
        {
#endif
            double alpha = Convert.ToDouble(backGround.A) / Convert.ToDouble(byte.MaxValue);
#if NETFX_CORE || SILVERLIGHT
            return(Color.FromArgb(byte.MaxValue,
                                  ConvertByte((Convert.ToDouble(frontColor.R) - Convert.ToDouble(backGround.R) * alpha) / (1 - alpha)),
                                  ConvertByte((Convert.ToDouble(frontColor.G) - Convert.ToDouble(backGround.G) * alpha) / (1 - alpha)),
                                  ConvertByte((Convert.ToDouble(frontColor.B) - Convert.ToDouble(backGround.B) * alpha) / (1 - alpha))));
#else
            return(new FormColor(Color.FromArgb(byte.MaxValue,
                                                ConvertByte((Convert.ToDouble(frontColor.R) - Convert.ToDouble(backGround.R) * alpha) / (1 - alpha)),
                                                ConvertByte((Convert.ToDouble(frontColor.G) - Convert.ToDouble(backGround.G) * alpha) / (1 - alpha)),
                                                ConvertByte((Convert.ToDouble(frontColor.B) - Convert.ToDouble(backGround.B) * alpha) / (1 - alpha)))));
#endif
        }
Пример #7
0
        private static GColor OverlayOn(this GColor color, GColor backGround)
        {
#endif
            byte   r, g, b, a;
            double alpha, bAlpha;
            if (color.A == 255)
#if NETFX_CORE || SILVERLIGHT
            { return(Color.FromArgb(color.A, color.R, color.G, color.B)); }
#else
            { return(new FormColor(Color.FromArgb(color.A, color.R, color.G, color.B))); }
#endif
            alpha  = Convert.ToDouble(color.A) / Convert.ToDouble(byte.MaxValue);
            bAlpha = Convert.ToDouble(backGround.A) / Convert.ToDouble(byte.MaxValue);
            r      = ConvertByte(Convert.ToDouble(color.R) * alpha + Convert.ToDouble(backGround.R) * bAlpha * (1 - alpha));
            g      = ConvertByte(Convert.ToDouble(color.G) * alpha + Convert.ToDouble(backGround.G) * bAlpha * (1 - alpha));
            b      = ConvertByte(Convert.ToDouble(color.B) * alpha + Convert.ToDouble(backGround.B) * bAlpha * (1 - alpha));

            a = backGround.A == byte.MaxValue ? byte.MaxValue : ConvertByte((alpha + bAlpha * (1 - alpha)) * Convert.ToDouble(byte.MaxValue));
#if NETFX_CORE || SILVERLIGHT
            return(Color.FromArgb(a, r, g, b));
#else
            return(new FormColor(Color.FromArgb(a, r, g, b)));
#endif
        }
Пример #8
0
        internal static StringBuilder AppendSVGTag(this StringBuilder sb, MatrixPoint displaysize, MatrixPoint viewboxSize, GColor background, GColor fill)
        {
#endif


            if (displaysize.X <= 0 || displaysize.Y <= 0)
            {
                return(sb.Append(string.Format(CultureInfo.InvariantCulture.NumberFormat,
                                               "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.2\" baseProfile=\"tiny\" viewBox=\"0 0 {0} {1}\" viewport-fill=\"rgb({2}, {3}, {4})\" viewport-fill-opacity=\"{5}\" fill=\"rgb({6}, {7}, {8})\" fill-opacity=\"{9}\" {10}>",
                                               viewboxSize.X,
                                               viewboxSize.Y,
                                               background.R,
                                               background.G,
                                               background.B,
                                               ConvertAlpha(background.A),
                                               fill.R,
                                               fill.G,
                                               fill.B,
                                               ConvertAlpha(fill.A),
                                               BackgroundStyle(background)
                                               )));
            }
            else
            {
                return(sb.Append(string.Format(CultureInfo.InvariantCulture.NumberFormat,
                                               "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.2\" baseProfile=\"tiny\" viewBox=\"0 0 {0} {1}\" viewport-fill=\"rgb({2}, {3}, {4})\" viewport-fill-opacity=\"{5}\" fill=\"rgb({6}, {7}, {8})\" fill-opacity=\"{9}\" {10} width=\"{11}\" height=\"{12}\">",
                                               viewboxSize.X,
                                               viewboxSize.Y,
                                               background.R,
                                               background.G,
                                               background.B,
                                               ConvertAlpha(background.A),
                                               fill.R,
                                               fill.G,
                                               fill.B,
                                               ConvertAlpha(fill.A),
                                               BackgroundStyle(background),
                                               displaysize.X,
                                               displaysize.Y)));
            }
        }
Пример #9
0
        private static GColor InverseColor(GColor color)
        {
            Color result = Color.FromArgb(color.A, byte.MaxValue - color.R, byte.MaxValue - color.G, byte.MaxValue - color.B);

            return(new FormColor(result));
        }