void LoadFontAndGatherGlyphInfos(int unitSize, Action <List <GlyphInfo> > endHandler)
        {
            float scale = Window.BackingScaleFactor;

            Task.Factory.StartNew(() => {
                try {
                    Type typGlyphNames = typeof(FontAwesome.GlyphNames);
                    var memberinfos    = typGlyphNames.GetMembers(BindingFlags.Public | BindingFlags.Static | BindingFlags.GetProperty);

                    var ctFont = new CTFont(FontAwesomeUtil.Font, 20f, CGAffineTransform.MakeIdentity());

                    var list = memberinfos.Select((m) => {
                        var fieldInfo = typGlyphNames.GetField(m.Name);
                        var rawName   = (string)fieldInfo.GetValue(typGlyphNames);
                        var glyphval  = ctFont.GetGlyphWithName(rawName);
                        return(new GlyphInfo {
                            GlyphName = m.Name
                            , RawName = rawName
                            , GlyphImage = FontAwesomeUtil.GetImageForBarItem(rawName, unitSize, scale)
                            , GlyphId = glyphval
                        });
                    }).ToList();

                    if (endHandler != null)
                    {
                        endHandler(list);
                    }
                }
                catch (Exception ex) {
                    Console.WriteLine("Exception: " + ex);
                }
            });
        }
示例#2
0
        public override void AwakeFromNib()
        {
            base.AwakeFromNib();

            imgvwSmallGlyph.ImageFrameStyle = NSImageFrameStyle.None;
            imgvwLargeGlyph.ImageFrameStyle = NSImageFrameStyle.None;
            imgvwSmallGlyph.Image           = new NSImage(
                FontAwesomeUtil.GetImage(GlyphNames.Font, 20, 20, 12, new CGColor(0f, 1f), new CGColor(0f, 0f))
                , new SizeF(20f, 20f));
            imgvwLargeGlyph.Image = new NSImage(
                FontAwesomeUtil.GetImage(GlyphNames.Font, 20, 20, 18, new CGColor(0f, 1f), new CGColor(0f, 0f))
                , new SizeF(20f, 20f));
        }
示例#3
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // Perform any additional setup after loading the view, typically from a nib.
            actvw.HidesWhenStopped = true;

            // Pinch gesture to scale font
            var pinchGestureRecognizer = new UIPinchGestureRecognizer((recog) => {
                //Console.WriteLine ("recog.State={0}, scale={1}", recog.State, recog.Scale);
                if (recog.State == UIGestureRecognizerState.Began)
                {
                }
                else if (recog.State == UIGestureRecognizerState.Changed)
                {
                    int unitSize = (int)Math.Min(maxFontSize, Math.Max(minFontSize, this.unitFontSize * recog.Scale));
                    ShowProgressionLabel(String.Format("Size = {0}", unitSize));
                    _tableViewSource.SetHeightForRow(CalculateRowHeightFromUnitFontSize(unitSize));
                    tblvwGlyphList.ReloadData();
                }
                else if (recog.State == UIGestureRecognizerState.Recognized)
                {
                    int unitSize = (int)Math.Min(maxFontSize, Math.Max(minFontSize, this.unitFontSize * recog.Scale));
                    if (unitSize != unitFontSize)
                    {
                        this.unitFontSize = unitSize;
                        UpdateGlyphsWithCurrentFontSize();
                    }
                    DismissProgressionLabel();
                }
            });

            tblvwGlyphList.AddGestureRecognizer(pinchGestureRecognizer);

            #region Toolbar button to save every image to PNG

            var saveButton = new UIBarButtonItem(FontAwesomeUtil.GetUIImageForBarItem(GlyphNames.Save), UIBarButtonItemStyle.Plain
                                                 , (s, e) => {
                var alert               = new UIAlertView();
                alert.Title             = String.Format("{0}x{0} size of images are going to be generated.", this.unitFontSize);
                alert.Message           = "Clear any image in document folder before newly generate?";
                int nYesButton          = alert.AddButton("Clear");
                int nNoButton           = alert.AddButton("No");
                int nCancelButton       = alert.AddButton("Cancel");
                alert.CancelButtonIndex = nCancelButton;
                alert.Clicked          += (s2, e2) => {
                    if (nYesButton == e2.ButtonIndex)
                    {
                        DeleteAllPNGsInDocumentFolder();
                        SaveEveryImageToPNG();
                    }
                    else if (nNoButton == e2.ButtonIndex)
                    {
                        SaveEveryImageToPNG();
                    }
                };
                alert.Show();
            });
            SetToolbarItems(new UIBarButtonItem[] { saveButton }, false);
            #endregion

            UpdateGlyphsWithCurrentFontSize();
        }