public static DialogResult ShowFontDialog()
        {
            DialogResult result = DialogResult.Cancel;

            try
            {
                FontDialog fDialog = new FontDialog
                {
                    ShowColor = true
                };
                try
                {
                    fDialog.Color = XMLSettings.DeserializeColor(Engine.conf.WatermarkFontColor);
                    fDialog.Font  = XMLSettings.DeserializeFont(Engine.conf.WatermarkFont);
                }
                catch (Exception err)
                {
                    FileSystem.AppendDebug("Error while initializing Font and Color", err);
                }

                result = fDialog.ShowDialog();
                if (result == DialogResult.OK)
                {
                    Engine.conf.WatermarkFont      = XMLSettings.SerializeFont(fDialog.Font);
                    Engine.conf.WatermarkFontColor = XMLSettings.SerializeColor(fDialog.Color);
                }
            }
            catch (Exception ex)
            {
                FileSystem.AppendDebug("Error while setting Watermark Font", ex);
            }
            return(result);
        }
Пример #2
0
        public static void LoadSettings(string fp = null)
        {
            LoggerTimer timer = EngineLogger.StartTimer("LoadSettings started");

            Thread threadOptions = new Thread(() =>
            {
                Engine.ConfigOptions = ZScreenOptions.Read(OptionsFilePath);
            });

            Thread threadMainFormSettings = new Thread(() =>
            {
                if (string.IsNullOrEmpty(fp))
                {
                    Engine.ConfigUI = XMLSettings.Read();
                }
                else
                {
                    Engine.ConfigUI = XMLSettings.Read(fp);
                }
            });

            Thread threadWorkflow = new Thread(() =>
            {
                Engine.ConfigWorkflow = Workflow.Read(WorkflowConfigPath);
            });

            Thread threadUploadersConfig = new Thread(() =>
            {
                Engine.ConfigUploaders = UploadersConfig.Load(UploadersConfigPath);
            });

            Thread threadGt = new Thread(() =>
            {
                Engine.ConfigGT = GoogleTranslatorConfig.Read(GoogleTranslateConfigPath);
            });

            threadOptions.Start();
            threadMainFormSettings.Start();
            threadGt.Start();
            threadWorkflow.Start();
            threadUploadersConfig.Start();

            threadMainFormSettings.Join();
            threadWorkflow.Join();
            threadUploadersConfig.Join();

            timer.WriteLineTime("LoadSettings finished");

            Engine.InitializeFiles();

            // Use Configuration Wizard Settings if applied
            if (RunConfig)
            {
                Engine.ConfigUI.ConfOutputs = Engine.ConfigApp.AppOutputs;
                Engine.ConfigUI.ConfClipboardContent = Engine.ConfigApp.ClipboardContent;
                Engine.ConfigUI.MyImageUploaders = Engine.ConfigApp.ImageUploaders;
                Engine.ConfigUI.MyTextUploaders = Engine.ConfigApp.TextUploaders;
                Engine.ConfigUI.MyFileUploaders = Engine.ConfigApp.FileUploaders;
                Engine.ConfigUI.MyURLShorteners = Engine.ConfigApp.LinkUploaders;
            }

            // Portable then we don't need PreferSystemFolders to be true
            if (IsPortable)
            {
                Engine.ConfigApp.PreferSystemFolders = false;
            }
        }
        private static Image DrawWatermark(Image img, string drawText)
        {
            if (!string.IsNullOrEmpty(drawText))
            {
                if (0 == Engine.conf.WatermarkFont.Size)
                {
                    Adapter.ShowFontDialog();
                }
                try
                {
                    int   offset        = (int)Engine.conf.WatermarkOffset;
                    Font  font          = XMLSettings.DeserializeFont(Engine.conf.WatermarkFont);
                    Size  textSize      = TextRenderer.MeasureText(drawText, font);
                    Size  labelSize     = new Size(textSize.Width + 10, textSize.Height + 10);
                    Point labelPosition = FindPosition(Engine.conf.WatermarkPositionMode, offset, img.Size,
                                                       new Size(textSize.Width + 10, textSize.Height + 10), 1);
                    if (Engine.conf.WatermarkAutoHide && ((img.Width < labelSize.Width + offset) ||
                                                          (img.Height < labelSize.Height + offset)))
                    {
                        return(img);
                        //throw new Exception("Image size smaller than watermark size.");
                    }
                    Rectangle    labelRectangle = new Rectangle(Point.Empty, labelSize);
                    GraphicsPath gPath          = RoundedRectangle.Create(labelRectangle, (int)Engine.conf.WatermarkCornerRadius);

                    int      backTrans = (int)Engine.conf.WatermarkBackTrans;
                    int      fontTrans = (int)Engine.conf.WatermarkFontTrans;
                    Color    fontColor = XMLSettings.DeserializeColor(Engine.conf.WatermarkFontColor);
                    Bitmap   bmp       = new Bitmap(labelRectangle.Width + 1, labelRectangle.Height + 1);
                    Graphics g         = Graphics.FromImage(bmp);
                    g.SmoothingMode     = SmoothingMode.HighQuality;
                    g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
                    LinearGradientBrush brush;
                    if (Engine.conf.WatermarkUseCustomGradient)
                    {
                        brush = GradientMaker.CreateGradientBrush(labelRectangle.Size, Engine.conf.GradientMakerOptions.GetBrushDataActive());
                    }
                    else
                    {
                        brush = new LinearGradientBrush(labelRectangle, Color.FromArgb(backTrans, XMLSettings.DeserializeColor(Engine.conf.WatermarkGradient1)),
                                                        Color.FromArgb(backTrans, XMLSettings.DeserializeColor(Engine.conf.WatermarkGradient2)), Engine.conf.WatermarkGradientType);
                    }
                    g.FillPath(brush, gPath);
                    g.DrawPath(new Pen(Color.FromArgb(backTrans, XMLSettings.DeserializeColor(Engine.conf.WatermarkBorderColor))), gPath);
                    StringFormat sf = new StringFormat {
                        Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center
                    };
                    g.DrawString(drawText, font, new SolidBrush(Color.FromArgb(fontTrans, fontColor)), bmp.Width / 2, bmp.Height / 2, sf);
                    Graphics gImg = Graphics.FromImage(img);
                    gImg.SmoothingMode = SmoothingMode.HighQuality;
                    gImg.DrawImage(bmp, labelPosition);
                    if (Engine.conf.WatermarkAddReflection)
                    {
                        Bitmap bmp2 = AddReflection(bmp, 50, 200);
                        gImg.DrawImage(bmp2, new Rectangle(labelPosition.X, labelPosition.Y + bmp.Height - 1, bmp2.Width, bmp2.Height));
                    }
                }
                catch (Exception ex)
                {
                    FileSystem.AppendDebug("Errow while drawing watermark", ex);
                }
            }

            return(img);
        }
        public static void LoadSettings(string fp = null)
        {
            LoggerTimer timer = EngineLogger.StartTimer("LoadSettings started");

            Thread threadOptions = new Thread(() =>
            {
                Engine.ConfigOptions = ZScreenOptions.Read(OptionsFilePath);
            });

            Thread threadMainFormSettings = new Thread(() =>
            {
                if (string.IsNullOrEmpty(fp))
                {
                    Engine.ConfigUI = XMLSettings.Read();
                }
                else
                {
                    Engine.ConfigUI = XMLSettings.Read(fp);
                }
            });

            Thread threadWorkflow = new Thread(() =>
            {
                Engine.ConfigWorkflow = Workflow.Read(WorkflowConfigPath);
            });

            Thread threadUploadersConfig = new Thread(() =>
            {
                Engine.ConfigUploaders = UploadersConfig.Load(UploadersConfigPath);
            });

            Thread threadGt = new Thread(() =>
            {
                Engine.ConfigGT = GoogleTranslatorConfig.Read(GoogleTranslateConfigPath);
            });

            threadOptions.Start();
            threadMainFormSettings.Start();
            threadGt.Start();
            threadWorkflow.Start();
            threadUploadersConfig.Start();

            threadMainFormSettings.Join();
            threadWorkflow.Join();
            threadUploadersConfig.Join();

            timer.WriteLineTime("LoadSettings finished");

            Engine.InitializeFiles();

            // Use Configuration Wizard Settings if applied
            if (RunConfig)
            {
                Engine.ConfigUI.ConfOutputs          = Engine.ConfigApp.AppOutputs;
                Engine.ConfigUI.ConfClipboardContent = Engine.ConfigApp.ClipboardContent;
                Engine.ConfigUI.MyImageUploaders     = Engine.ConfigApp.ImageUploaders;
                Engine.ConfigUI.MyTextUploaders      = Engine.ConfigApp.TextUploaders;
                Engine.ConfigUI.MyFileUploaders      = Engine.ConfigApp.FileUploaders;
                Engine.ConfigUI.MyURLShorteners      = Engine.ConfigApp.LinkUploaders;
            }

            // Portable then we don't need PreferSystemFolders to be true
            if (IsPortable)
            {
                Engine.ConfigApp.PreferSystemFolders = false;
            }
        }