Ejemplo n.º 1
0
        internal static Rectangle GetLetterCropping(string indexFile, string repository, string glyph, Dictionary <Property, object> languageSettings)
        {
            Rectangle rr = GetLetterMargins(indexFile, repository, glyph, languageSettings);

            //List<string> lines = File.ReadAllLines(indexFile).ToList<string>();
            //IEnumerable<string> temp = lines.Where(x => x.StartsWith("‡" + glyph + ";"));
            //if (temp.Count() > 0)
            if (!rr.Equals(new Rectangle(0, 0, 500, 500)))
            {
                //string line = temp.First();
                //List<int> points = line.Trim().Substring(line.IndexOf(";") + 1).Split(',').Select(x => Int32.Parse(x)).ToList();


                Rectangle  r = new Rectangle();
                CropAspect c = (CropAspect)languageSettings[Property.CropAspect];
                if ((Kerning)languageSettings[Property.Kerning] != Kerning.Monospace)
                {
                    if (c == CropAspect.Vertical || c == CropAspect.Both)
                    {
                        r = new Rectangle(0, rr.Y, 500, rr.Width);
                    }
                    else if (c == CropAspect.Horizontal || c == CropAspect.Both)
                    {
                        r = new Rectangle(rr.Width, 0, rr.Width, 500);
                    }
                    else if (c == CropAspect.Both)
                    {
                        r = new Rectangle(rr.X, rr.Y, rr.Width, rr.Height);
                    }
                    else if (c == CropAspect.MatchedToWord)
                    {
                        if (languageSettings[Property.WordDirection].Equals(FlowDirection.TopDown) ||
                            languageSettings[Property.WordDirection].Equals(FlowDirection.BottomUp))
                        {
                            r = new Rectangle(0, rr.Y, 500, rr.Height);
                        }
                        else
                        {
                            r = new Rectangle(rr.X, 0, rr.Width, 500);
                        }
                    }

                    return(r);
                }
                else
                {
                    return(rr);
                }
            }
            else
            {
                return(rr);
            }
        }
Ejemplo n.º 2
0
        internal static Rectangle GetLetterCropping(string line, Dictionary <Property, object> languageSettings)
        {
            Rectangle rr = GetLetterMargins(line);

            if (!rr.Equals(new Rectangle(0, 0, 500, 500)))
            {
                Rectangle  r = new Rectangle();
                CropAspect c = (CropAspect)languageSettings[Property.CropAspect];
                if ((Kerning)languageSettings[Property.Kerning] != Kerning.Monospace)
                {
                    if (c == CropAspect.Vertical || c == CropAspect.Both)
                    {
                        r = new Rectangle(0, rr.Y, 500, rr.Width);
                    }
                    else if (c == CropAspect.Horizontal || c == CropAspect.Both)
                    {
                        r = new Rectangle(rr.Width, 0, rr.Width, 500);
                    }
                    else if (c == CropAspect.Both)
                    {
                        r = new Rectangle(rr.X, rr.Y, rr.Width, rr.Height);
                    }
                    else if (c == CropAspect.MatchedToWord)
                    {
                        if (languageSettings[Property.WordDirection].Equals(FlowDirection.TopDown) ||
                            languageSettings[Property.WordDirection].Equals(FlowDirection.BottomUp))
                        {
                            r = new Rectangle(0, rr.Y, 500, rr.Height);
                        }
                        else
                        {
                            r = new Rectangle(rr.X, 0, rr.Width, 500);
                        }
                    }

                    return(r);
                }
                else
                {
                    return(rr);
                }
            }
            else
            {
                return(rr);
            }
        }
        public Task <byte[]> CropImageFromOriginalToBytes(string filePath, CropAspect aspect = CropAspect.Custom)
        {
            var id = GetRequestId();

            var ntcs = new TaskCompletionSource <byte[]> (id);

            if (Interlocked.CompareExchange(ref _completionSource, ntcs, null) != null)
            {
#if DEBUG
                throw new InvalidOperationException("Only one operation can be active at a time");
#else
                return(null);
#endif
            }

            var intent = new Intent(CrossCurrentActivity.Current.Activity, typeof(CropImageActivity));
            intent.PutExtra("image-path", filePath);
            intent.PutExtra("scale", true);

            switch (aspect)
            {
            case CropAspect.Square:
                intent.PutExtra("aspectX", 1);
                intent.PutExtra("aspectY", 1);
                break;
            }

            //event
            EventHandler <XViewEventArgs> handler = null;
            handler = (s, e) => {
                var tcs = Interlocked.Exchange(ref _completionSource, null);

                CropImageActivity.MediaCroped -= handler;
                tcs.SetResult((e.CastObject as Bitmap)?.BitmapToBytes());
            };

            CropImageActivity.MediaCroped += handler;
            CrossCurrentActivity.Current.Activity.StartActivity(intent);

            return(_completionSource.Task);
        }
Ejemplo n.º 4
0
        public Task <byte[]> CropImageFromOriginalToBytes(string filePath, CropAspect aspect = CropAspect.Custom)
        {
            var image = UIImage.FromFile(filePath);

            //crop image
            var viewController = new TOCropViewController(TOCropViewCroppingStyle.Default, image);
            var ndelegate      = new CropVcDelegate(viewController);

            switch (aspect)
            {
            case CropAspect.Square:
                viewController.AspectRatioLockEnabled        = true;
                viewController.AspectRatioPickerButtonHidden = true;
                viewController.AspectRatioPreset             = TOCropViewControllerAspectRatioPreset.Square;
                break;
            }

            viewController.Delegate = ndelegate;
            //show
            viewController.PresentUsingRootViewController();
            var result = ndelegate.Task.ContinueWith(t => t).Unwrap();

            return(result);
        }
Ejemplo n.º 5
0
        private void textBoxInput_TextChanged(object sender, EventArgs e)
        {
            textBoxBreakdown.Clear();
            panelOutput.Controls.Clear();

            string regCol = String.Join("|", headersCol);
            string regRow = String.Join("|", headersRow);

            List <string> output = new List <string>();

            foreach (string block in Regex.Matches(textBoxInput.Text, "[^|\\b].*?\\b|.").OfType <Match>().Where(x => x.Value != " ").Select(x => x.Value))
            {
                if (Regex.Matches(block, "\\W").Count > 0)
                {
                    if (block != " ")
                    {
                        output.Add(block);
                    }
                }
                else
                {
                    MatchCollection match = Regex.Matches(block, String.Format("([{0}]\\d?[{1}]\\d?)|([{1}]\\d?[{0}]\\d?)", regCol, regRow));
                    List <string>   l     = match.OfType <Match>().Select(x => x.Value).ToList();
                    output.Add("(" + String.Join("-", l) + ")");

                    ///This whole flowPanel thing might be better done with calculations and drawing straight to the canvas
                    ///It would allow for glyph overlaps but more calcs will be needed for wrapping

                    FlowLayoutPanel flowPanel = new FlowLayoutPanel();
                    //for not foreach because of importance of glyph position

                    for (int i = 0; i < l.Count; i++)
                    {
                        object tag = FormType.Isolated;
                        string fil = String.Format("{0}\\{1}.png", repository, l[i]);

                        if (languageSettings[Property.CharacterForms].Equals(CharacterForms.Multiple))
                        {
                            if (l.Count != 1)
                            {
                                if (i == 0)
                                {
                                    if (File.Exists(String.Format("{0}\\{1}_initial.png", repository, l[i])))
                                    {
                                        fil = String.Format("{0}\\{1}_initial.png", repository, l[i]);
                                        tag = FormType.Initial;
                                    }
                                }
                                else if (i == l.Count - 1)
                                {
                                    if (File.Exists(String.Format("{0}\\{1}_final.png", repository, l[i])))
                                    {
                                        fil = String.Format("{0}\\{1}_final.png", repository, l[i]);
                                        tag = FormType.Final;
                                    }
                                }
                                else
                                {
                                    if (File.Exists(String.Format("{0}\\{1}_medial.png", repository, l[i])))
                                    {
                                        fil = String.Format("{0}\\{1}_medial.png", repository, l[i]);
                                        tag = FormType.Medial;
                                    }
                                }
                            }
                        }

                        if (File.Exists(fil) || (bool)languageSettings[Property.FillBlanks])
                        {
                            Size s = (Size)languageSettings[Property.Sizing];

                            Bitmap im;
                            if (File.Exists(fil))
                            {
                                using (Image image = Image.FromFile(fil))
                                {
                                    im = (Bitmap)image.GetThumbnailImage(500, 500, null, IntPtr.Zero);
                                }
                            }
                            else
                            {
                                im = nullimage;
                            }
                            Size characterSize = (Size)languageSettings[Property.Sizing];

                            //get crop data
                            Kerning k = (Kerning)languageSettings[Property.Kerning];

                            string extender = tag.Equals(FormType.Isolated) ? "" : "_" + tag.ToString().ToLower();
                            string glyph    = l[i] + extender;
                            string line     = languageInfo.Where(x => x.StartsWith("‡" + glyph + ";")).FirstOrDefault();
                            if (line != null && k != Kerning.Monospace)
                            {
                                Rectangle r = GetLetterCropping(line, languageSettings);

                                Bitmap cropped = new Bitmap(r.Width, r.Height);

                                using (Graphics g = Graphics.FromImage(cropped))
                                {
                                    g.DrawImage(im, new Rectangle(0, 0, r.Width, r.Height), r, GraphicsUnit.Pixel);
                                }
                                im = cropped;
                            }
                            im.MakeTransparent(Color.White);
                            Panel p = new Panel()
                            {
                                BackgroundImage = im, BackgroundImageLayout = ImageLayout.Zoom, Size = characterSize, Tag = tag
                            };
                            /// future feature - on hover, highlight original in text box ///

                            if (k != Kerning.Monospace)
                            {
                                FlowDirection f = (FlowDirection)languageSettings[Property.WordDirection];
                                if (f == FlowDirection.LeftToRight || f == FlowDirection.RightToLeft)
                                {
                                    p.Margin = new Padding((int)k / 2, 3, (int)k / 2, 3);
                                }
                                else
                                {
                                    p.Margin = new Padding(3, (int)k / 2, 3, (int)k / 2);
                                }

                                CropAspect aspect = (CropAspect)languageSettings[Property.CropAspect];
                                if (aspect != CropAspect.None)
                                {
                                    //v,b, or ttb
                                    if (aspect == CropAspect.Vertical || aspect == CropAspect.Both || (aspect == CropAspect.MatchedToWord && p.Margin.Left == 3))
                                    {
                                        p.Height = (int)(p.Height * p.BackgroundImage.Height / 500f);
                                    }
                                    if (aspect == CropAspect.Horizontal || aspect == CropAspect.Both || (aspect == CropAspect.MatchedToWord && p.Margin.Left != 3))
                                    {
                                        p.Width = (int)(p.Width * p.BackgroundImage.Width / 500f);
                                    }
                                }
                            }
                            flowPanel.Controls.Add(p);
                        }
                    }
                    FlowPanelDirection((FlowDirection)languageSettings[Property.WordDirection], flowPanel);
                    panelOutput.Controls.Add(flowPanel);
                }
            }
            textBoxBreakdown.Text = String.Join(" ", output);
        }