internal static Typeface TypefaceFor(IconChar iconChar, IconFont iconFont)
        {
            if (iconFont == IconFont.Auto)
            {
                return(TypefaceFor(iconChar));
            }
            var key = (int)iconFont;

            if (TypefaceForStyle.TryGetValue(key, out var typeFace))
            {
                return(typeFace);
            }
            if (!FontTitles.TryGetValue(key, out var name))
            {
                return(Throw($"No font loaded for style: {iconFont}"));
            }

            typeFace = Typefaces.FirstOrDefault(t => t.FontFamily.Source.EndsWith(name));
            if (typeFace == null)
            {
                return(Throw($"No font loaded for '{name}'"));
            }

            TypefaceForStyle.Add(key, typeFace);
            return(typeFace);
        }
Esempio n. 2
0
        /// <summary>
        /// Returns a bitmap for the specified font awesome style and icon
        /// </summary>
        /// <param name="icon">The icon</param>
        /// <param name="iconFont">The font awesome style / font to use</param>
        /// <param name="size">Size of destination bitmap in pixels</param>
        /// <param name="color">Icon color</param>
        /// <param name="rotation">Icon rotation in degrees</param>
        /// <param name="flip">Icon flip</param>
        /// <returns>The rendered bitmap</returns>
        public static Bitmap ToBitmap(this IconChar icon, IconFont iconFont = IconFont.Auto,
                                      int size        = DefaultSize, Color?color  = null,
                                      double rotation = 0.0, FlipOrientation flip = FlipOrientation.Normal)
        {
            var fontFamily = icon.FontFamilyFor(iconFont);

            return(fontFamily.ToBitmap(icon, size, color, rotation, flip));
        }
Esempio n. 3
0
 public static char Get(IconFont _if)
 {
     return(new Dictionary <IconFont, char>
     {
         { IconFont.favor_fill, '' },
         { IconFont.round_close_fill, '' },
         { IconFont.clock_fill, '' },
     }[_if]);
 }
Esempio n. 4
0
        public void LocatesIconWithKey(string key, string expectedGlyph)
        {
            var iconFont = new IconFont("Test.otf", "test", typeof(MockFontA));

            var glyph = iconFont.FindIconForKey(key);

            Assert.False(string.IsNullOrWhiteSpace(glyph));

            Assert.Equal(expectedGlyph, glyph);
        }
Esempio n. 5
0
        public void IconClassReturnsRegisteredIcons()
        {
            IEnumerable <RegisteredIcon> icons = null;

            var ex = Record.Exception(() => icons = IconFont.GetIcons(typeof(MockFontA)));

            Assert.Null(ex);
            Assert.NotNull(icons);
            Assert.Equal(2, icons.Count());
        }
 public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
 {
     if (value is IconType iconType)
     {
         return(IconFont.GetSource(iconType, Color.Black));
     }
     else
     {
         return(null);
     }
 }
        /// <summary>
        /// Renders an image for the specified font, style and icon
        /// </summary>
        /// <param name="iconChar">The icon to render</param>
        /// <param name="iconFont">The icon font style</param>
        /// <param name="brush">The icon brush / color</param>
        /// <param name="size">The icon size in pixels</param>
        /// <returns>The rendered image</returns>
        public static ImageSource ToImageSource(this IconChar iconChar, IconFont iconFont,
                                                Brush brush = null, double size = DefaultSize)
        {
            var typeface = TypefaceFor(iconChar, iconFont);

            if (typeface == null)
            {
                return(null);
            }
            return(typeface.TryFind(iconChar.UniCode(), out var gt, out var glyphIndex) ? ToImageSource(brush, size, gt, glyphIndex) : null);
        }
Esempio n. 8
0
        //protected override void OnLocationChanged(EventArgs e)
        //{
        //    // pick up the container's surface again.
        //    Visible = false;
        //    Visible = true;
        //}

        //protected override CreateParams CreateParams
        //{
        //    get
        //    {
        //        CreateParams cp = base.CreateParams;
        //        cp.ExStyle |= 0x00000020; //WS_EX_TRANSPARENT
        //        return cp;
        //    }
        //}
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaintBackground(e);

            Graphics g = e.Graphics;

            SetGDIHigh(g);

            _MouseRect = new Rectangle(0, 0, this.ClientRectangle.Width - BorderWidth, this.ClientRectangle.Height - BorderWidth);

            Color Fill   = FillColor;
            Color Border = BorderColor;

            if (_IsEnabled)
            {
                if (_MouseEnter)
                {
                    Fill = _MouseDown ? FillDownColor : FillEnterColor;
                }
            }
            else
            {
                Fill   = FillDisabledColor;
                Border = FillDisabledColor;
            }

            //绘制边线
            using (Pen pen = new Pen(Border, BorderWidth))
            {
                g.DrawEllipse(pen, _MouseRect);
            }

            //绘制填充圆
            using (Brush brush = new SolidBrush(Fill))
            {
                g.FillEllipse(brush, _MouseRect);
            }

            //绘制图标
            bool isShow = IconFlagAlways ? true : _MouseEnter;

            if (isShow && IconFlagCode > 0)
            {
                Rectangle iconRect = _MouseRect;
                int       iconSize = iconRect.Width / 5;
                iconRect.Inflate(-iconSize, -iconSize);
                Bitmap bmIcon = IconFont.GetImage(IconFont.GetFont(IconFlagCode), iconRect.Width, IconFlagColor);
                g.DrawImage(bmIcon, iconRect);
            }
            g.ResetClip();
        }
Esempio n. 9
0
        internal static FontFamily FontFamilyFor(this IconChar iconChar, IconFont iconFont)
        {
            if (iconFont == IconFont.Auto)
            {
                return(FontFamilyFor(iconChar));
            }
            var key = (int)iconFont;

            if (FontForStyle.TryGetValue(key, out var fontFamily))
            {
                return(fontFamily);
            }
            fontFamily = Fonts.Value.Families.FirstOrDefault(f =>
                                                             f.Name.IndexOf(iconFont.ToString(), StringComparison.InvariantCultureIgnoreCase) >= 0);
            FontForStyle.Add(key, fontFamily);
            return(fontFamily);
        }
Esempio n. 10
0
        public override SizeF PreferredSize(IGUIContext ctx, SizeF proposedSize)
        {
            if (CachedPreferredSize == SizeF.Empty)
            {
                float w = 0;
                float h = 0;

                if (!String.IsNullOrEmpty(Text) && DisplayStyle != ButtonDisplayStyles.Image)
                {
                    //SizeF sz = Font.MeasureMnemonicString (Text);
                    SizeF sz = Font.MeasureMnemonicString(Text);
                    //h = Font.Height * 1.5f;
                    h = sz.Height * 1.5f;
                    w = sz.Width;
                }

                if (Icon > 0 && IconFont != null && DisplayStyle != ButtonDisplayStyles.Text)
                {
                    SizeF sz = IconFont.Measure(Icon.ToString());

                    if (w > 0)
                    {
                        w += sz.Width * 1.42f;
                    }
                    //w += sz.Width.Ceil() * 1.5f;
                    else
                    {
                        w += sz.Width;
                    }
                    h = Math.Max(h, sz.Height);
                }

                if (w == 0 || h == 0)
                {
                    //CachedPreferredSize = base.PreferredSize (ctx, proposedSize);
                    CachedPreferredSize = SizeF.Empty;
                }
                else
                {
                    CachedPreferredSize = new SizeF((w + Padding.Width), (h + Padding.Height));
                }
            }

            return(CachedPreferredSize);
        }
Esempio n. 11
0
        public UpcomingDetails(int upcomingId)
        {
            BindingContext = new IconFont("\uf2d1", "\uf2d5");
            globalID       = (int)upcomingId;


            InitializeComponent();


            using (var webClient = new WebClient())

            {
                string s          = "https://api.themoviedb.org/3/movie/429617?api_key=f4b8e415cb9ab402e5c1d72176cab35b";
                string mid        = Convert.ToString(upcomingId);
                string jsonString = webClient.DownloadString("https://api.themoviedb.org/3/movie/" + mid + "?api_key=f4b8e415cb9ab402e5c1d72176cab35b");


                r = MUpcomingDetails.FromJson(jsonString);

                Title.Text = r.Title;

                MovieImage.Source = new UriImageSource()
                {
                    Uri = new Uri(r.FullBackPath)
                };
                OverView.Text = r.Overview;
                string concat = "";
                foreach (Genre g in r.Genres)
                {
                    concat += g.Name + " | ";
                }
                string sub = concat.Substring(0, concat.Length - 2);
                Genres.Text = sub;
                Status.Text = r.Status;
                checkIfFavourite();
            }
        }
Esempio n. 12
0
        private void LoadData()
        {
            StringBuilder sb = new StringBuilder();

            string iconName      = String.Empty;
            string iconClassName = "&nbsp;";

            sb.Append("<ul class=\"icons\">");
            foreach (string icon in Enum.GetNames(typeof(IconFont)))
            {
                IconFont iconType = (IconFont)Enum.Parse(typeof(IconFont), icon);

                if (iconType != IconFont.None)
                {
                    iconName      = IconFontHelper.GetName(iconType);
                    iconClassName = iconName;
                }

                sb.AppendFormat("<li class=\"ui-state-default\"><i class=\"ui-icon f-icon-{0}\"></i><div class=\"title\">{1}</div><div class=\"subtitle\">{2}</div></li>", iconName, icon, iconClassName);
            }
            sb.Append("</ul>");

            litIcons.Text = sb.ToString();
        }
Esempio n. 13
0
 public void OnEnable()
 {
     FontManager.instance.addFont(Resources.Load <Font>("fonts/PingFangHeiTC-W4"), "PingFang");
     FontManager.instance.addFont(Resources.Load <Font>("fonts/PingFangHeiTC-W6"), "PingFang", FontWeight.w500);
     IconFont.Load();
 }
Esempio n. 14
0
        public override void OnPaint(IGUIContext ctx, RectangleF bounds)
        {
            float x          = bounds.Left;
            float y          = Padding.Top;
            float line       = 0;
            float lineHeight = LineHeight;
            //int lineHeight = Bounds.Height;

            bool buildTree = false;

            if (lastBounds != bounds || Tree == null)
            {
                try {
                    lastBounds         = bounds;
                    Tree               = new QuadTree(bounds);
                    itemStartPositions = new float[Menu.Count];
                    buildTree          = true;
                } catch (Exception ex) {
                    ex.LogError();
                }
            }

            for (int i = 0; i < Menu.Children.Count; i++)
            {
                IGuiMenuItem item = Menu.Children [i];
                if (item == null || !item.Visible)
                {
                    continue;
                }

                float iconWidth = 0;
                float textWidth = 0;

                if (IconFont != null && item.ImageIndex > 0)
                {
                    iconWidth = IconFont.Measure(((char)item.ImageIndex).ToString()).Width;
                }

                if (Font != null)
                {
                    textWidth = Font.MeasureMnemonicString(item.Text).Width;
                    if (textWidth > 0)
                    {
                        iconWidth *= 1.35f;
                    }
                }

                float itemWidth = iconWidth + textWidth + Padding.Width;

                if (x + itemWidth > bounds.Width)
                {
                    line++;
                    x  = bounds.Left;
                    y += lineHeight;
                }

                RectangleF itemBounds = new RectangleF(x, y, itemWidth, lineHeight - Padding.Height);
                if (buildTree)
                {
                    try {
                        Tree.Add(new LayoutItem(itemBounds, item));
                        itemStartPositions[i] = itemBounds.X;
                    } catch (Exception ex) {
                        ex.LogError();
                    }
                }

                WidgetStates state = WidgetStates.Default;
                if (!item.Enabled)
                {
                    state = WidgetStates.Disabled;
                }
                else if (item == ActiveItem)
                {
                    if (IsFocused || Selected)
                    {
                        state = WidgetStates.Active;
                    }
                    else
                    {
                        state = WidgetStates.Selected;
                    }
                    ctx.FillRectangle(Styles.GetStyle(state).BackColorBrush,
                                      // irgendjemand scheint den mit bereits abgezogenem Padding aufzurufen, was falsch wäre
                                      new RectangleF(itemBounds.X, itemBounds.Y - Padding.Top, itemBounds.Width, itemBounds.Height + Padding.Height));
                }

                Brush brush = Styles.GetStyle(state).ForeColorBrush;

                itemBounds.Offset(Padding.Left, 1);
                itemBounds.Width -= Padding.Left;

                if (iconWidth > 0)
                {
                    ctx.DrawString(((char)item.ImageIndex).ToString(), IconFont, brush, itemBounds, FontFormat.DefaultIconFontFormatLeft);
                    itemBounds.Offset((int)iconWidth, 0);
                }

                if (textWidth > 0)
                {
                    ctx.DrawString(item.Text, Font, brush, itemBounds, FontFormat.DefaultMnemonicLine);
                }

                x += itemWidth;
                if (x > bounds.Width)
                {
                    line++;
                    x  = bounds.Left;
                    y += lineHeight;
                }
            }
        }
Esempio n. 15
0
 internal static FontFamily FontFor(IconChar iconChar, IconFont iconFont)
 {
     return(TypefaceFor(iconChar, iconFont)?.FontFamily);
 }