Example #1
0
        private void cbErrorLevel_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (!this.Visible)
            {
                return;
            }

            string errorString = cbErrorLevel.SelectedItem.ToString();

            if (string.Equals(errorString, I18N._("L"), StringComparison.CurrentCultureIgnoreCase))
            {
                errorLevel = ErrorCorrectionLevel.L;
            }
            else if (string.Equals(errorString, I18N._("M"), StringComparison.CurrentCultureIgnoreCase))
            {
                errorLevel = ErrorCorrectionLevel.M;
            }
            else if (string.Equals(errorString, I18N._("Q"), StringComparison.CurrentCultureIgnoreCase))
            {
                errorLevel = ErrorCorrectionLevel.Q;
            }
            else if (string.Equals(errorString, I18N._("H"), StringComparison.CurrentCultureIgnoreCase))
            {
                errorLevel = ErrorCorrectionLevel.H;
            }
            else
            {
                errorLevel = ErrorCorrectionLevel.Q;
            }
            appSection.Settings["ErrorCorrectionLevel"].Value = errorString;
            config.Save();
        }
Example #2
0
 private void btnLoadSolution_Click(object sender, EventArgs e)
 {
     LockUI();
     sln.Load(edSolution.Text);
     UnlockUI();
     StatusLabelState.Text = I18N._("Loaded");
 }
Example #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="items"></param>
        private void TranslateRibbonItems(RibbonItemCollection items)
        {
            if (items == null || items.Count <= 0)
            {
                return;
            }

            foreach (RibbonItem item in items)
            {
                item.Text         = I18N._(item.Text);
                item.ToolTip      = I18N._(item.ToolTip);
                item.ToolTipTitle = I18N._(item.ToolTipTitle);

                if (item.GetType().ToString().EndsWith("RibbonButton", StringComparison.CurrentCultureIgnoreCase))
                {
                    var btn = item as RibbonButton;
                    if (btn.Style != RibbonButtonStyle.Normal)
                    {
                        TranslateRibbonItems(btn.DropDownItems);
                    }
                }
                else if (item.GetType().ToString().EndsWith("RibbonButtonList", StringComparison.CurrentCultureIgnoreCase))
                {
                    TranslateRibbonItems(item as RibbonButtonList);
                }
                else if (item.GetType().ToString().EndsWith("RibbonButtonCollection", StringComparison.CurrentCultureIgnoreCase))
                {
                    //TranslateRibbonItems( (RibbonItemCollection) item. );
                }
            }
        }
Example #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="rib"></param>
        public void TranslateRibbon(Ribbon rib)
        {
            rib.Text = I18N._(rib.Text);

            #region Ribbon QuickAccessToolbar
            rib.QuickAcessToolbar.Text                        = I18N._(rib.QuickAcessToolbar.Text);
            rib.QuickAcessToolbar.ToolTip                     = I18N._(rib.QuickAcessToolbar.ToolTip);
            rib.QuickAcessToolbar.ToolTipTitle                = I18N._(rib.QuickAcessToolbar.ToolTipTitle);
            rib.QuickAcessToolbar.DropDownButton.Text         = I18N._(rib.QuickAcessToolbar.DropDownButton.Text);
            rib.QuickAcessToolbar.DropDownButton.ToolTip      = I18N._(rib.QuickAcessToolbar.DropDownButton.ToolTip);
            rib.QuickAcessToolbar.DropDownButton.ToolTipTitle = I18N._(rib.QuickAcessToolbar.DropDownButton.ToolTipTitle);
            TranslateRibbonItems(rib.QuickAcessToolbar.Items);
            //foreach ( RibbonItem item in rib.QuickAcessToolbar.Items )
            //{
            //    item.Text = I18N._( item.Text );
            //    item.ToolTip = I18N._( item.ToolTip );
            //    item.ToolTipTitle = I18N._( item.ToolTipTitle );
            //}
            TranslateRibbonItems(rib.QuickAcessToolbar.DropDownButtonItems);
            //foreach ( RibbonItem item in rib.QuickAcessToolbar.DropDownButtonItems )
            //{
            //    item.Text = I18N._( item.Text );
            //    item.ToolTip = I18N._( item.ToolTip );
            //    item.ToolTipTitle = I18N._( item.ToolTipTitle );
            //}
            #endregion

            #region Ribbon OrbDropDown
            rib.OrbDropDown.Text = I18N._(rib.QuickAcessToolbar.Text);
            TranslateRibbonItems(rib.OrbDropDown.MenuItems);
            TranslateRibbonItems(rib.OrbDropDown.OptionItems);

            rib.OrbDropDown.RecentItemsCaption = I18N._(rib.OrbDropDown.RecentItemsCaption);
            TranslateRibbonItems(rib.OrbDropDown.RecentItems);
            #endregion

            #region Ribbon Tabs
            foreach (RibbonTab tab in rib.Tabs)
            {
                tab.Text         = I18N._(tab.Text);
                tab.ToolTip      = I18N._(tab.ToolTip);
                tab.ToolTipTitle = I18N._(tab.ToolTipTitle);

                #region Ribbon Panel in Tab
                foreach (RibbonPanel panel in tab.Panels)
                {
                    panel.Text = I18N._(panel.Text);
                    foreach (RibbonItem item in panel.Items)
                    {
                        item.Text         = I18N._(item.Text);
                        item.ToolTip      = I18N._(item.ToolTip);
                        item.ToolTipTitle = I18N._(item.ToolTipTitle);
                    }
                }
                #endregion
            }
            #endregion
        }
Example #5
0
        public MainForm()
        {
            InitializeComponent();
            Application.EnableVisualStyles();
            Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath);

            I18N i10n = new I18N(null, this);

            status.Padding = new Padding(
                status.Padding.Left,
                status.Padding.Top,
                status.Padding.Left,
                status.Padding.Bottom
                );

            btnQRInput.Image = Icon.ToBitmap();

            edText.MaxLength = MAX_TEXT;

            colorDlg.Color         = Color.Cyan;
            picMaskColor.BackColor = Color.Red;

            if (cbBarFormat.Items.Count > 0)
            {
                cbBarFormat.SelectedIndex = 0;
            }

            loadSettings();

            KeysConverter kc   = new KeysConverter();
            var           sKey = Keys.Oemtilde;
            var           skn  = "~";// kc.ConvertToString(sKey);

            // register the event that is fired after the key press.
            hook.KeyPressed += new EventHandler <KeyPressedEventArgs>(hookKeyPressed);
            try
            {
                hook.RegisterHotKey(QRUtils.ModifierKeys.Win, sKey);
                statusLabelHotkey.Text = string.Format(I18N._("Hotkey: {0}"), $"Win + {skn}");
            }
            catch
            {
                MessageBox.Show(this, I18N._($"Failed to bind hotkey Win + {skn}!"), I18N._("Error"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                //status.Items[0]
                statusLabelHotkey.Text = string.Format(I18N._("Hotkey: {0}"), I18N._("None"));
            }

            // create properties
            //var properties = new Common.Logging.Configuration.NameValueCollection();
            //properties["showDateTime"] = "true";
            //LogManager.Adapter = new Common.Logging.Simple.ConsoleOutLoggerFactoryAdapter( properties );
        }
Example #6
0
 private void btnPatchFile_Click(object sender, EventArgs e)
 {
     if (sln.Loaded)
     {
         LockUI();
         sln.Patch();
         UnlockUI();
     }
     else
     {
         log(I18N._(strSolutionNotLoaded));
     }
 }
Example #7
0
 private void btnCreatePO_Click(object sender, EventArgs e)
 {
     if (sln.Loaded)
     {
         LockUI();
         sln.Process();
         UnlockUI();
     }
     else
     {
         log(I18N._(strSolutionNotLoaded));
     }
 }
Example #8
0
 private void btnOpenPO_Click(object sender, EventArgs e)
 {
     if (sln.Loaded)
     {
         LockUI();
         sln.EditPO(cbLanguage.Text);
         UnlockUI();
     }
     else
     {
         log(I18N._(strSolutionNotLoaded));
     }
 }
Example #9
0
 private void btnCreateLangDll_Click(object sender, EventArgs e)
 {
     if (sln.Loaded)
     {
         LockUI();
         sln.MakeLangMO(cbLanguage.Text);
         UnlockUI();
     }
     else
     {
         log(I18N._(strSolutionNotLoaded));
     }
 }
Example #10
0
        public Bitmap QREncode(string text)
        {
            var width  = 512;
            var height = 512;
            var margin = 0;

            if (string.IsNullOrEmpty(text))
            {
                return(new Bitmap(width, height));
            }

            string qrText = text;

            var bw = new BarcodeWriter();

            var ecl = errorLevel;

            if (chkOverLogo.Checked && ecl == ErrorCorrectionLevel.L)
            {
                ecl = ErrorCorrectionLevel.M;
            }

            bw.Options.Width       = width;
            bw.Options.Height      = height;
            bw.Options.PureBarcode = false;
            bw.Options.Hints.Add(EncodeHintType.ERROR_CORRECTION, ecl);
            bw.Options.Hints.Add(EncodeHintType.MARGIN, margin);
            bw.Options.Hints.Add(EncodeHintType.DISABLE_ECI, true);
            bw.Options.Hints.Add(EncodeHintType.CHARACTER_SET, "UTF-8");

            bw.Renderer = new BitmapRenderer();
            bw.Format   = BarcodeFormat.QR_CODE;
            if (qrText.Length > MAX_TEXT)
            {
                qrText = qrText.Substring(0, MAX_TEXT);
            }
            try
            {
                Bitmap qrBitmap = bw.Write(qrText);
                if (chkOverLogo.Checked)
                {
                    qrBitmap = drawOverlayLogo(qrBitmap, overlayLogoImage);
                }
                return(qrBitmap);
            }
            catch (WriterException)
            {
                MessageBox.Show(this, I18N._("Text too long!"), I18N._("Error"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(new Bitmap(width, height));
            }
        }
Example #11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="items"></param>
        private void TranslateRibbonItems(RibbonButtonList items)
        {
            if (items == null || items.Buttons.Count <= 0)
            {
                return;
            }

            foreach (RibbonButton item in items.Buttons)
            {
                item.Text         = I18N._(item.Text);
                item.ToolTip      = I18N._(item.ToolTip);
                item.ToolTipTitle = I18N._(item.ToolTipTitle);
            }
        }
Example #12
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="apps"></param>
        private void AddAddinApp(List <IAddin> apps)
        {
            RibTabMainApp.Items.Clear();
            CustomPanelApp.Clear();

            foreach (IAddin addin in apps)
            {
                RibbonButton btnAddin = new RibbonButton();
                RibTabMainApp.Items.Add(btnAddin);

                if (addin.LargeIcon != null)
                {
                    btnAddin.Image = addin.LargeIcon;
                }
                else
                {
                    btnAddin.Image = addins.LargeApplicationImage;
                }
                if (addin.SmallIcon != null)
                {
                    btnAddin.SmallImage = addin.SmallIcon;
                }
                else
                {
                    btnAddin.SmallImage = addins.SmallApplicationImage;
                }

                btnAddin.Text         = I18N._(addin.DisplayName);
                btnAddin.ToolTip      = I18N._(addin.Description);
                btnAddin.ToolTipTitle = I18N._(addin.Author);
                btnAddin.Value        = addin.Name;
                btnAddin.Click       += AddinAppClick;

                #region fetch subitems of addin
                object result = null;
                addin.Command(AddinCommand.SubItems, out result);
                if (result is Dictionary <string, object> )
                {
                    foreach (var item in (result as Dictionary <string, object>))
                    {
                        //var smi = new RibbonButton( item.Key );
                        //smi.SmallImage = item.Value.
                        //btnAddin.DropDownItems.Add( smi );
                        //b
                    }
                }
                #endregion
            }
        }
Example #13
0
        private string _(string t)
        {
            if (catalog == null)
            {
                catalog = GetCatalog();
            }

            if (catalog == null)
            {
                return(I18N._(t));
            }
            else
            {
                return(I18N._(catalog, t));
            }
        }
Example #14
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        protected internal string _(string t)
        {
            if (catalog == null)
            {
                catalog = GetCatalog();
            }

            if (catalog == null)
            {
                return(I18N._(t));
            }
            else
            {
                return(I18N._(catalog, t));
            }
        }
Example #15
0
        internal string InsecureMaskedPrompt(string forArgument)
        {
            Console.Write(String.Format(I18N._("PromptIfValueMissing_Prompt") + " ", forArgument));
            const int ENTER = 13, BACKSP = 8, CTRLBACKSP = 127;

            int[] FILTERED = { 0, 27, 9, 10 }; // const

            var builder = new StringBuilder();

            char chr = (char)0;

            while ((chr = Console.ReadKey(true).KeyChar) != ENTER)
            {
                if (((chr == BACKSP) || (chr == CTRLBACKSP)) &&
                    (builder.Length > 0))
                {
                    Console.Write("\b \b");
                    builder.Remove(builder.Length - 1, 1);
                }
                // Don't append * when length is 0 and backspace is selected
                else if (((chr == BACKSP) || (chr == CTRLBACKSP)) && (builder.Length == 0))
                {
                }

                // Don't append when a filtered char is detected
                else if (FILTERED.Count(x => chr == x) > 0)
                {
                }

                // Append and write * mask
                else
                {
                    builder.Append(chr);
                }
            }

            Console.WriteLine();
            return(builder.ToString());

            /*IntPtr ptr = new IntPtr();
             * ptr = Marshal.SecureStringToBSTR(securePass);
             * string plainPass = Marshal.PtrToStringBSTR(ptr);
             * Marshal.ZeroFreeBSTR(ptr);
             * return plainPass;*/
        }
Example #16
0
        private static ArgumentDisplay GetArgumentsForDisplay(List <string> names, IArgument attr)
        {
            if (!names.Any())
            {
                names.Add(attr.Name);
            }
            string localized = null;
            var    info      = attr.LocalizationInfo;

            if (info != null)
            {
                localized = I18N._(info.ResourceType, info.ResourceName);
            }
            return(new ArgumentDisplay
            {
                ArgumentNames = String.Join(", ", names.ToArray()),
                Description = localized ?? attr.Description ?? ""
            });
        }
Example #17
0
        private void btnQRDecode_Click(object sender, EventArgs e)
        {
            bool MULTI = chkMultiDecode.Checked; //true;

            //this.Hide();
            //Application.DoEvents();
            if (WindowState != FormWindowState.Minimized)
            {
                Opacity = 0.0f;
                System.Threading.Thread.Sleep(75);
            }
            if (MULTI)
            {
                edText.Clear();
                var results = QRDecodeMulti(getScreenSnapshot());
                foreach (var result in results)
                {
                    edText.Text += result + "\n\n";
                }
                //status.Items[2]
                statusLabelDecodeCount.Text = string.Format(I18N._("Code Found: {0}"), results.Count);
            }
            else
            {
                edText.Text = QRDecode(getScreenSnapshot());
                //status.Items[2]
                if (edText.Text.Length > 0)
                {
                    statusLabelDecodeCount.Text = string.Format("Code Found: {0}", 1);
                }
                else
                {
                    statusLabelDecodeCount.Text = string.Format("Code Found: {0}", 0);
                }
            }

            Opacity = 1.0f;
            //this.Show();
        }
Example #18
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cmdFileSave_Click(object sender, EventArgs e)
        {
            if (addins.CurrentApp is IAddin)
            {
                string fname = I18N._("NewFile");
                object fn    = fname;
                addins.CurrentApp.Command(AddinCommand.GetImageName, out fn);
                if (fn is string && !string.IsNullOrEmpty((string)fn))
                {
                    fname = Path.GetFileNameWithoutExtension((string)fn);
                }

                dlgSave.FileName = string.Format($"{fname}_{DateTime.Now.Ticks}.{dlgSave.DefaultExt}");
                if (dlgSave.ShowDialog() == DialogResult.OK)
                {
                    var result = AddinUtils.SaveImage(dlgSave.FileName, addins.CurrentApp.ImageData, new SaveOption());
                    if (result)
                    {
                        RecentItemAdd(dlgSave.FileName);
                    }
                }
            }
        }
Example #19
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="filters"></param>
        /// <param name="IsExt"></param>
        private void AddAddinEffect(List <IAddin> filters, bool IsExt = true)
        {
            RibTabEffectInternal.Items.Clear();
            RibTabEffectExternal.Items.Clear();

            #region Clear Custom Actions Panel
            foreach (var kv in CustomPanelEffect)
            {
                if (kv.Value is RibbonPanel)
                {
                    RibTabEffect.Panels.Remove(kv.Value);
                    kv.Value.Dispose();
                }
            }
            CustomPanelEffect.Clear();
            #endregion

            #region Add addin to Command Panels
            foreach (IAddin addin in filters)
            {
                if (!addin.Visible)
                {
                    continue;
                }

                RibbonPanel targetPanel = RibTabEffectExternal;
                if (!string.IsNullOrEmpty(addin.CategoryName))
                {
                    if (!CustomPanelEffect.ContainsKey(addin.CategoryName))
                    {
                        CustomPanelEffect.Add(addin.CategoryName, new RibbonPanel(I18N._(addin.DisplayCategoryName)));
                    }
                    targetPanel = CustomPanelEffect[addin.CategoryName];
                }
                else if (string.Equals(addin.Author, "netcharm", StringComparison.CurrentCultureIgnoreCase) ||
                         addin.Author.StartsWith("NetCharm ", StringComparison.CurrentCultureIgnoreCase))
                {
                    targetPanel = RibTabEffectInternal;
                }
                else
                {
                    targetPanel = RibTabEffectExternal;
                }

                RibbonButton btnAddin = new RibbonButton();
                targetPanel.Items.Add(btnAddin);

                if (addin.LargeIcon != null)
                {
                    btnAddin.Image = addin.LargeIcon;
                }
                else
                {
                    btnAddin.Image = addins.LargeEffectImage;
                }
                if (addin.SmallIcon != null)
                {
                    btnAddin.SmallImage = addin.SmallIcon;
                }
                else
                {
                    btnAddin.SmallImage = addins.SmallEffectImage;
                }

                btnAddin.Text          = I18N._(addin.DisplayName);
                btnAddin.ToolTip       = I18N._(addin.Description);
                btnAddin.ToolTipTitle  = I18N._(addin.Author);
                btnAddin.TextAlignment = RibbonItem.RibbonItemTextAlignment.Center;
                btnAddin.Value         = addin.Name;
                btnAddin.Click        += AddinEffectClick;

                #region fetch subitems of addin
                object result = null;
                addin.Command(AddinCommand.SubItems, out result);
                if (result is List <AddinSubItem> && (result as List <AddinSubItem>).Count > 0)
                {
                    foreach (var item in (result as List <AddinSubItem>))
                    {
                        var smi = new RibbonButton(item.Name);
                        smi.Text       = item.DisplayName;
                        smi.Image      = item.LargeIcon;
                        smi.SmallImage = item.SmallIcon;
                        smi.Value      = item.Name;
                        //smi.Click += AddinActionSubItemClick;

                        btnAddin.DropDownItems.Add(smi);
                    }
                    //btnAddin.DrawIconsBar = false;
                    btnAddin.Style = RibbonButtonStyle.SplitDropDown;
                    btnAddin.DropDownItemClicked += AddinEffectSubItemClick;
                }
                #endregion
            }
            #endregion

            #region Refresh Panels Visible state
            int c = 0;
            foreach (var kv in CustomPanelEffect)
            {
                RibTabEffect.Panels.Insert(c, kv.Value);
                c++;
            }
            if (RibTabEffectInternal.Items.Count == 0)
            {
                RibTabEffectInternal.Visible = false;
            }
            else
            {
                RibTabEffectInternal.Visible = true;
            }
            if (RibTabEffectExternal.Items.Count == 0)
            {
                RibTabEffectExternal.Visible = false;
            }
            else
            {
                RibTabEffectExternal.Visible = true;
            }
            #endregion
        }
Example #20
0
 internal string PromptNoMask(string forArgument)
 {
     Console.Write(String.Format(I18N._("PromptIfValueMissing_Prompt") + " ", forArgument));
     return(Console.ReadLine());
 }
Example #21
0
        private void loadSettings()
        {
            bool update = false;

            ///
            /// QR Detect indicator mask color
            ///
            try
            {
                maskColor = ColorTranslator.FromHtml(appSection.Settings["MaskColor"].Value);
            }
            catch
            {
                appSection.Settings.Add("MaskColor", ColorTranslator.ToHtml(maskColor));
                update = true;
            }
            colorDlg.Color         = maskColor;
            picMaskColor.BackColor = maskColor;

            ///
            /// Overlay Logo Icon
            ///
            try
            {
                overlayLogo = Convert.ToBoolean(appSection.Settings["OverlayLogo"].Value);
            }
            catch
            {
                appSection.Settings.Add("OverlayLogo", overlayLogo.ToString());
                update = true;
            }
            chkOverLogo.Checked = overlayLogo;

            try
            {
                overlayBGColor = ColorTranslator.FromHtml(appSection.Settings["OverlayBGColor"].Value);
            }
            catch
            {
                appSection.Settings.Add("OverlayBGColor", ColorTranslator.ToHtml(overlayBGColor));
                update = true;
            }

            try
            {
                overlayLogoImage = appSection.Settings["OverlayLogoImage"].Value;
            }
            catch
            {
                appSection.Settings.Add("OverlayLogoImage", overlayLogoImage);
                update = true;
            }

            ///
            /// QR Encode Error Level
            ///
            string errorString = "M";

            try
            {
                errorString = appSection.Settings["ErrorCorrectionLevel"].Value;
            }
            catch
            {
                appSection.Settings.Add("ErrorCorrectionLevel", errorString);
                update = true;
            }

            if (string.Equals(errorString, I18N._("L"), StringComparison.CurrentCultureIgnoreCase))
            {
                errorLevel = ErrorCorrectionLevel.L;
            }
            else if (string.Equals(errorString, I18N._("M"), StringComparison.CurrentCultureIgnoreCase))
            {
                errorLevel = ErrorCorrectionLevel.M;
            }
            else if (string.Equals(errorString, I18N._("Q"), StringComparison.CurrentCultureIgnoreCase))
            {
                errorLevel = ErrorCorrectionLevel.Q;
            }
            else if (string.Equals(errorString, I18N._("H"), StringComparison.CurrentCultureIgnoreCase))
            {
                errorLevel = ErrorCorrectionLevel.H;
            }
            else
            {
                errorLevel = ErrorCorrectionLevel.M;
            }
            cbErrorLevel.SelectedIndex = cbErrorLevel.Items.IndexOf(I18N._(errorString));

            ///
            /// QR Decode Options
            ///
            try
            {
                chkDecodeFormat1D.Checked = Convert.ToBoolean(appSection.Settings["DecodeFormat1D"].Value);
            }
            catch
            {
                appSection.Settings.Add("DecodeFormat1D", chkDecodeFormat1D.Checked.ToString());
                update = true;
            }

            try
            {
                chkDecodeFormatDM.Checked = Convert.ToBoolean(appSection.Settings["DecodeFormatDM"].Value);
            }
            catch
            {
                appSection.Settings.Add("DecodeFormatDM", chkDecodeFormatDM.Checked.ToString());
                update = true;
            }

            try
            {
                chkDecodeFormatQR.Checked = Convert.ToBoolean(appSection.Settings["DecodeFormatQR"].Value);
            }
            catch
            {
                appSection.Settings.Add("DecodeFormatQR", chkDecodeFormatQR.Checked.ToString());
                update = true;
            }

            if (update)
            {
                config.Save();
            }
        }
Example #22
0
 private void edText_TextChanged(object sender, EventArgs e)
 {
     //status.Items[1]
     statusLabelTextCount.Text = string.Format(I18N._("Text Count: {0}"), edText.Text.Length.ToString());
 }
Example #23
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="args"></param>
        private void OpenCmdArgs(string[] args)
        {
            string[] exts = new string[] { ".jpg", ".jpeg", ".png", ".tif", ".tiff", ".bmp", ".gif" };

            string[] flist  = args.Where(f => File.Exists(f) && exts.Contains(Path.GetExtension(f).ToLower())).ToArray();
            object   result = true;

            if (flist.Length == 1)
            {
                if (addins.CurrentApp is IAddin)
                {
                    addins.CurrentApp.Command(AddinCommand.Open, out result, flist);
                }
                else
                {
                    if (addins.Apps.ContainsKey("Editor"))
                    {
                        addins.CurrentApp = addins.Apps["Editor"];
                        addins.CurrentApp.Show(this, false);
                        addins.CurrentApp.Command(AddinCommand.Open, out result, flist);
                    }
                }
            }
            else if (flist.Length > 1)
            {
                if (addins.Apps.ContainsKey("Batch"))
                {
                    addins.CurrentApp = addins.Apps["Batch"];
                    addins.CurrentApp.Show(this, false);
                    addins.CurrentApp.Command(AddinCommand.Open, out result, flist);
                }
            }

            if (flist.Length > 0)
            {
                tssLabelImageName.Text        = Path.GetFileName(flist[0]);
                tssLabelImageName.ToolTipText = $"{I18N._( "Image File" )}: {flist[0]}";
                if (addins.CurrentApp.ImageData is Image)
                {
                    object imgSize   = new Size(0, 0);
                    object imgFormat = PixelFormat.Format32bppArgb;
                    addins.CurrentApp.Command(AddinCommand.GetImageSize, out imgSize);
                    addins.CurrentApp.Command(AddinCommand.GetImageColors, out imgFormat);

                    int bits = AddinUtils.GetColorDeep((PixelFormat)imgFormat);
                    tssLabelImageSize.Text = $"{( (Size) imgSize ).Width} x {( (Size) imgSize ).Height} x {bits}";

                    object zoomLevel = 100;
                    addins.CurrentApp.Command(AddinCommand.ZoomLevel, out zoomLevel);
                    tssLabelImageZoom.Text = $"{zoomLevel}%";

                    RecentItemAdd(flist[0]);
                }
            }
            else
            {
                tssLabelImageName.Text = I18N._("None");
                tssLabelImageSize.Text = I18N._("None");
                tssLabelImageZoom.Text = I18N._("None");
            }
            cmdFileApply.Visible    = addins.CurrentApp is IAddin ? addins.CurrentApp.SupportMultiFile : false;
            cmdFileApplyAll.Visible = addins.CurrentApp is IAddin ? addins.CurrentApp.SupportMultiFile : false;
            cmdFileSepApply.Visible = addins.CurrentApp is IAddin ? addins.CurrentApp.SupportMultiFile : false;

            PerformLayout();
            //FixedMdiSize();
        }
Example #24
0
        public Bitmap BarEncode(string text, BarcodeFormat barFormat = BarcodeFormat.CODE_128, bool isbn = false)
        {
            var width  = 256;
            var height = 128;
            var margin = 0;

            if (string.IsNullOrEmpty(text))
            {
                return(new Bitmap(width, height));
            }

            string barText = text;
            int    maxText = 16;

            switch (barFormat)
            {
            case BarcodeFormat.CODE_128:
                width   = 256;
                height  = 72;
                margin  = 7;
                maxText = 232;
                break;

            case BarcodeFormat.EAN_13:
                //height = (int) ( width * 25.93 / 37.29 );
                height = (int)(width * 26.26 / 37.29);
                if (isbn)
                {
                    string isbn13 = calcISBN_13(barText);
                    string isbn10 = calcISBN_10(barText);
                    if (string.IsNullOrEmpty(isbn13))
                    {
                        return(new Bitmap(width, height));
                    }
                    //if ( string.IsNullOrEmpty( isbn10 ) ) return ( new Bitmap( width, height ) );
                    barText = isbn13;
                }
                break;

            default:
                return(new Bitmap(width, height));
            }
            var bw = new BarcodeWriter();

            bw.Options.Width  = width;
            bw.Options.Height = height;
            //bw.Options.PureBarcode = false;
            bw.Options.Hints.Add(EncodeHintType.MARGIN, margin);
            bw.Options.Hints.Add(EncodeHintType.DISABLE_ECI, true);
            bw.Options.Hints.Add(EncodeHintType.CHARACTER_SET, "UTF-8");

            bw.Renderer = new BitmapRenderer();
            bw.Format   = barFormat;
            if (barText.Length > maxText)
            {
                barText = barText.Substring(0, maxText);
            }
            try
            {
                BitMatrix bm        = bw.Encode(barText);
                int[]     rectangle = bm.getEnclosingRectangle();
                var       bmW       = rectangle[2];
                var       bmH       = rectangle[3];
                //bw.Options.Width = ( bmW <= 256 ) ? ( bmW + 32 ) : (int)( bmW * ( 1 + 32 / 256 ) );
                bw.Options.Width = (int)(bmW * 1.25);

                Bitmap barcodeBitmap = bw.Write(barText);
                return(barcodeBitmap);
            }
            catch (WriterException)
            {
                MessageBox.Show(this, I18N._("Text data can not be encoded to barcode!"), I18N._("Error"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(new Bitmap(width, height));
            }
        }