예제 #1
0
        public App()
        {
            InitializeComponent();

            FontRegistry.RegisterFonts(
                FontAwesomeBrands.Font,
                FontAwesomeRegular.Font,
                FontAwesomeSolid.Font);

            var tabbed  = new TabbedPage();
            var main    = new WebClasses();
            var mainTab = new NavigationPage(main)
            {
                BindingContext = main
            };
            var mappings    = new Mappings();
            var mappingsTab = new NavigationPage(mappings)
            {
                BindingContext = mappings
            };

            mainTab.SetBinding(Page.TitleProperty, "Title");
            mainTab.SetBinding(Page.IconImageSourceProperty, "IconImageSource");
            mappingsTab.SetBinding(Page.TitleProperty, "Title");
            mappingsTab.SetBinding(Page.IconImageSourceProperty, "IconImageSource");
            tabbed.Children.Add(mainTab);
            tabbed.Children.Add(mappingsTab);
            tabbed.Children.Add(new InfoPage());
            MainPage = tabbed;
        }
예제 #2
0
        protected override async void OnAttached()
        {
            ImageSource source;

            if (!string.IsNullOrWhiteSpace(Effect.Icon) && FontRegistry.HasFont(Effect.Icon, out _))
            {
                source = new IconImageSource
                {
                    Color = Effect.LineColor,
                    Name  = Effect.Icon,
                    Size  = Effect.ImageWidth
                };
            }
            else if (Effect.ImageSource != null)
            {
                source = Effect.ImageSource;
            }
            else
            {
                return;
            }

            var handler = Xamarin.Forms.Internals.Registrar.Registered.GetHandlerForObject <IImageSourceHandler>(source);

            if (handler != null)
            {
                SetImage(await handler.LoadImageAsync(source));
            }
        }
        public static TElement SetIcon <TElement>(this TElement element, string icon, Color?color = null)
            where TElement : Element, IFontElement
        {
            if (!FontRegistry.HasFont(icon, out var font))
            {
                return(element);
            }

            var glyphColor = color ?? Color.Default;
            var glyph      = font.GetGlyph(icon);

            switch (element)
            {
            case Label label:
                SetIcon(label, font.FontFileName, glyph, glyphColor);
                break;

            case Span span:
                SetIcon(span, font.FontFileName, glyph, glyphColor);
                break;

            case Editor editor:
                SetIcon(editor, font.FontFileName, glyph, glyphColor);
                break;

            case Button button:
                SetIcon(button, font.FontFileName, glyph, glyphColor);
                break;

            case SearchBar searchBar:
                SetIcon(searchBar, font.FontFileName, glyph, glyphColor);
                break;
            }
            return(element);
        }
예제 #4
0
 private static void OnGlyphNameChanged(BindableObject bindable, object oldValue, object newValue)
 {
     if (bindable is IconSpan span && FontRegistry.HasFont(span.GlyphName, out var font))
     {
         span.FontFamily = font.FontFileName;
         span.Text       = font.GetGlyph(span.GlyphName);
     }
예제 #5
0
        private Bitmap LoadImage(ImageSource imagesource, Context context)
        {
            Bitmap image = null;

            if (imagesource is IconImageSource iconsource && FontRegistry.HasFont(iconsource.Name, out var font))
            {
                var paint = new Paint
                {
                    TextSize  = TypedValue.ApplyDimension(ComplexUnitType.Dip, (float)iconsource.Size, context.Resources.DisplayMetrics),
                    Color     = (iconsource.Color != Color.Default ? iconsource.Color : Color.White).ToAndroid(),
                    TextAlign = Paint.Align.Left,
                    AntiAlias = true,
                };

                using (var typeface = Typeface.CreateFromAsset(context.ApplicationContext.Assets, font.FontFileName))
                    paint.SetTypeface(typeface);

                paint.SetTypeface(font.Alias.ToTypeFace());

                var glyph    = font.GetGlyph(iconsource.Name);
                var width    = (int)(paint.MeasureText(glyph) + .5f);
                var baseline = (int)(-paint.Ascent() + .5f);
                var height   = (int)(baseline + paint.Descent() + .5f);
                image = Bitmap.CreateBitmap(width, height, Bitmap.Config.Argb8888);
                var canvas = new Canvas(image);
                canvas.DrawText(glyph, 0, baseline, paint);
            }

            return(image);
        }
예제 #6
0
        public Task <UIImage> LoadImageAsync(ImageSource imagesource, CancellationToken cancelationToken = default, float scale = 1)
        {
            UIImage image = null;

            if (imagesource is IconImageSource iconsource && FontRegistry.HasFont(iconsource.Name, out var font))
            {
                // This will allow lookup from the Embedded Fonts
                var glyph        = font.GetGlyph(iconsource.Name);
                var cleansedname = FontExtensions.CleanseFontName(font.Alias);
                var uifont       = UIFont.FromName(cleansedname ?? string.Empty, (float)iconsource.Size) ??
                                   UIFont.SystemFontOfSize((float)iconsource.Size);
                var iconcolor = iconsource.Color.IsDefault ? _defaultColor : iconsource.Color;
                var attString = new NSAttributedString(glyph, font: uifont, foregroundColor: iconcolor.ToUIColor());
                var imagesize = ((NSString)glyph).GetSizeUsingAttributes(attString.GetUIKitAttributes(0, out _));

                UIGraphics.BeginImageContextWithOptions(imagesize, false, 0f);
                var ctx          = new NSStringDrawingContext();
                var boundingRect = attString.GetBoundingRect(imagesize, (NSStringDrawingOptions)0, ctx);
                attString.DrawString(new RectangleF(
                                         (imagesize.Width / 2) - (boundingRect.Size.Width / 2),
                                         (imagesize.Height / 2) - (boundingRect.Size.Height / 2),
                                         imagesize.Width,
                                         imagesize.Height));
                image = UIGraphics.GetImageFromCurrentImageContext();
                UIGraphics.EndImageContext();

                if (image != null && iconcolor != _defaultColor)
                {
                    image = image.ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal);
                }
            }
            return(Task.FromResult(image));
        }
        public void Paint(Graphics g, Rectangle rect)
        {
            if (rect.Width <= 0 || rect.Height <= 0)
            {
                return;
            }

            HighlightColor lineNumberPainterColor = Shared.TEP.LineNumbersColor;
            int            fontHeight             = TextArea.TextView.FontHeight;
            Brush          fillBrush = TextArea.Enabled ? BrushRegistry.GetBrush(lineNumberPainterColor.BackgroundColor) : SystemBrushes.InactiveBorder;
            Brush          drawBrush = BrushRegistry.GetBrush(lineNumberPainterColor.Color);

            for (int y = 0; y < (DrawingPosition.Height + TextArea.TextView.VisibleLineDrawingRemainder) / fontHeight + 1; ++y)
            {
                int       ypos = DrawingPosition.Y + fontHeight * y - TextArea.TextView.VisibleLineDrawingRemainder;
                Rectangle backgroundRectangle = new Rectangle(DrawingPosition.X, ypos, DrawingPosition.Width, fontHeight);
                if (rect.IntersectsWith(backgroundRectangle))
                {
                    g.FillRectangle(fillBrush, backgroundRectangle);
                    int curLine = TextArea.Document.GetFirstLogicalLine(TextArea.Document.GetVisibleLine(TextArea.TextView.FirstVisibleLine) + y);

                    if (curLine < TextArea.Document.TotalNumberOfLines)
                    {
                        g.DrawString((curLine + 1).ToString(),
                                     FontRegistry.GetFont(lineNumberPainterColor.Bold, lineNumberPainterColor.Italic),
                                     drawBrush,
                                     backgroundRectangle,
                                     _numberStringFormat);
                    }
                }
            }
        }
예제 #8
0
        protected override async void OnInitialized()
        {
            InitializeComponent();

            FontRegistry.RegisterFonts(
                FontAwesomeSolid.Font);
            var result = await NavigationService.NavigateAsync("Page2");
        }
예제 #9
0
 private static void OnSelectorChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs args)
 {
     if (!string.IsNullOrEmpty((string)args.NewValue) &&
         FontRegistry.HasFont((string)args.NewValue, out var font) &&
         dependencyObject is IconBlock iconBlock)
     {
     }
 }
        public void RegistryReturnsExpectedChar(string icon, string expectedGlyph)
        {
            Assert.True(FontRegistry.HasFont(icon, out var font));
            var glyph = font.GetGlyph(icon);

            Assert.False(string.IsNullOrEmpty(glyph));
            Assert.Equal(expectedGlyph, glyph);
        }
예제 #11
0
        protected void ReturnsCorrectFontInternal(string selector)
        {
            var expectedFont = Font;
            var font         = FontRegistry.LocateFont(selector);

            Assert.Equal(expectedFont.Alias, font.Alias);
            Assert.Equal(expectedFont.FontFileName, font.FontFileName);
            Assert.Equal(expectedFont.GetGlyph(selector), font.GetGlyph(selector));
        }
예제 #12
0
        public Task <WindowsImageSource> LoadImageAsync(ImageSource imagesource, CancellationToken cancellationToken = default)
        {
            if (!(imagesource is IconImageSource iconsource) || !FontRegistry.HasFont(iconsource.Name, out var font))
            {
                return(Task.FromResult(default(WindowsImageSource)));
            }

            return(new FontImageSourceHandler().LoadImageAsync(iconsource.ToFontImageSource(font), cancellationToken));
        }
        public static FontImageSource SetIcon(this FontImageSource imageSource, string icon, Color?color = null)
        {
            if (FontRegistry.HasFont(icon, out var font))
            {
                imageSource.Glyph      = font.GetGlyph(icon);
                imageSource.FontFamily = font.FontFileName;
                imageSource.Color      = color ?? Color.Default;
            }

            return(imageSource);
        }
        public Task <Bitmap> LoadImageAsync(ImageSource imagesource, Context context, CancellationToken cancelationToken = default)
        {
            Bitmap image = null;

            if (imagesource is IconImageSource iconsource && FontRegistry.HasFont(iconsource.Name, out var font))
            {
                return(new FontImageSourceHandler().LoadImageAsync(iconsource.ToFontImageSource(font), context, cancelationToken));
            }

            return(Task.FromResult(image));
        }
예제 #15
0
        public App()
        {
            InitializeComponent();

            FontRegistry.RegisterFonts(
                FontAwesomeBrands.Font,
                FontAwesomeRegular.Font,
                FontAwesomeSolid.Font);

            MainPage = new MainPage();
        }
예제 #16
0
        public App()
        {
            //ExperimentalFeatures.Enable("SwipeView_Experimental");

            InitializeComponent();

            DbSetup();
            FontRegistry.RegisterFonts(FontAwesomeSolid.Font);

            MainPage = new AppShell();
            Routing.RegisterRoute("calendar/manageDay", typeof(ManageDayPage));
            Routing.RegisterRoute("calendar/manageSubscription", typeof(ManageSubscriptionPage));
            Routing.RegisterRoute("settings/backups", typeof(ManageBackupsPage));
        }
예제 #17
0
 public FontImplementation()
 {
     FontRegistry.Clear();
     Xamarin.Forms.Mocks.MockForms.Init();
     FontRegistry.RegisterFonts(
         DevIcons.Font,
         FontAwesomeBrands.Font,
         FontAwesomeRegular.Font,
         FontAwesomeSolid.Font,
         MaterialIcons.Font,
         MaterialIconsOutlined.Font,
         MaterialIconsRound.Font,
         MaterialIconsSharp.Font);
 }
        public Task <UIImage> LoadImageAsync(
            ImageSource imagesource,
            CancellationToken cancelationToken = default(CancellationToken),
            float scale = 1f)
        {
            UIImage image = null;

            if (imagesource is IconImageSource iconsource && FontRegistry.HasFont(iconsource.Name, out var font))
            {
                return(new FontImageSourceHandler().LoadImageAsync(iconsource.ToFontImageSource(font), cancelationToken, scale));
            }

            return(Task.FromResult(image));
        }
예제 #19
0
        protected override async void OnInitialized()
        {
            InitializeComponent();

            FontRegistry.RegisterFonts(FontAwesomeBrands.Font, FontAwesomeRegular.Font, FontAwesomeSolid.Font);

            var result = await NavigationService.NavigateAsync("MainPage/NavigationPage/HomePage");

            if (!result.Success)
            {
                MainPage = result.Exception.ToErrorPage();
                System.Diagnostics.Debugger.Break();
            }
        }
예제 #20
0
        protected void MapsToGlyphInternal(string mapping, string expectedGlyph)
        {
            var font  = FontRegistry.LocateFont(mapping);
            var glyph = font.GetGlyph(mapping);

            Assert.Equal(expectedGlyph, glyph);

            var parts = mapping.Split(' ');

            Assert.Equal(2, parts.Length);

            var glyph2 = font.GetGlyph(parts[1]);

            Assert.Equal(glyph, glyph2);
        }
예제 #21
0
        public void InstallFont(string fontFilePath)
        {
            var callback = OperationContext.Current.GetCallbackChannel <IFontInstallerCallbackService>();

            try
            {
                FontRegistry.RegisterFont(fontFilePath);
                callback.FontInstalledCallback(true, "");
                _log.WriteEntry("Font installed: " + fontFilePath, EventLogEntryType.Information);
            }
            catch (Exception e)
            {
                callback.FontInstalledCallback(false, e.Message);
            }
        }
예제 #22
0
 private void InstallFont(string fontFileName)
 {
     if (FontRegistry.IsValidFont(fontFileName))
     {
         WriteToLog("Found font file: " + fontFileName);
         WriteToLog("Starting install");
         var t = Task.Run(() =>
         {
             (new FontInstallerGUIService(new Logger(this, InstallLog))).InstallFont(fontFileName);
         });
     }
     else
     {
         WriteToLog("Invalid or unknown font file: " + fontFileName);
     }
 }
예제 #23
0
        private void RegisterLocalFont(string filename)
        {
            string   psName;
            FontInfo fontInfo;

            lock (FontRegistry)
            {
                try
                {
                    psName = FontRegistry.Add(filename);
                }
                catch (Exception e)
                {
                    Logger.Warning(string.Format("Unable to load custom font {0}", filename), e);
                    return;
                }

                fontInfo = FontRegistry.Fonts.First(fi => fi.PostscriptName == psName);
            }

            IList <FontData> familyFonts;

            if (!LocalFonts.TryGetValue(fontInfo.Family, out familyFonts))
            {
                familyFonts = LocalFonts[fontInfo.Family] = new List <FontData>();
            }

            var fontData = familyFonts.FirstOrDefault(f =>
                                                      f.PostScriptName.Equals(psName, StringComparison.InvariantCultureIgnoreCase) &&
                                                      f.Style.Equals(psName, StringComparison.InvariantCultureIgnoreCase));

            if (fontData == null)
            {
                fontData = new FontData
                {
                    PostScriptName = psName,
                    Style          = fontInfo.Style,
                    Family         = fontInfo.Family,
                    FullName       = fontInfo.FullName
                }
            }
            ;

            fontData.FileNames.Add(filename);

            familyFonts.Add(fontData);
        }
예제 #24
0
        public void LookupFromRegistry(string selector, string expectedGlyph, string fontAlias)
        {
            lock (lockobject)
            {
                FontRegistry.Clear();
                FontRegistry.RegisterFonts(SampleFontAwesomeRegular.Font, SampleFontAwesomeSolid.Font);

                var font = FontRegistry.LocateFont(selector);

                Assert.NotNull(font);

                Assert.Equal(fontAlias, font.Alias);

                var locatedGlyph = font.GetGlyph(selector);

                Assert.False(string.IsNullOrWhiteSpace(locatedGlyph));
                Assert.Equal(expectedGlyph, locatedGlyph);
            }
        }
예제 #25
0
        private WindowsImageSource LoadImage(ImageSource imagesource)
        {
            if (!(imagesource is IconImageSource iconsource) || !FontRegistry.HasFont(iconsource.Name, out var icon))
            {
                return(null);
            }

            var device = CanvasDevice.GetSharedDevice();
            var dpi    = Math.Max(_minimumDpi, Windows.Graphics.Display.DisplayInformation.GetForCurrentView().LogicalDpi);

            var textFormat = new CanvasTextFormat
            {
                FontFamily          = icon.FontFileName,
                FontSize            = (float)iconsource.Size,
                HorizontalAlignment = CanvasHorizontalAlignment.Center,
                VerticalAlignment   = CanvasVerticalAlignment.Center,
                Options             = CanvasDrawTextOptions.Default
            };

            var glyph = icon.GetGlyph(iconsource.Name);

            using (var layout = new CanvasTextLayout(device, glyph, textFormat, (float)iconsource.Size, (float)iconsource.Size))
            {
                var canvasWidth  = (float)layout.LayoutBounds.Width + 2;
                var canvasHeight = (float)layout.LayoutBounds.Height + 2;

                var imageSource = new CanvasImageSource(device, canvasWidth, canvasHeight, dpi);
                using (var ds = imageSource.CreateDrawingSession(Windows.UI.Colors.Transparent))
                {
                    var iconcolor = (iconsource.Color != Color.Default ? iconsource.Color : Color.White).ToWindowsColor();

                    // offset by 1 as we added a 1 inset
                    var x = (float)layout.DrawBounds.X * -1;

                    ds.DrawTextLayout(layout, x, 1f, iconcolor);
                }

                return(imageSource);
            }
        }
예제 #26
0
        private static void OnIconChanged(BindableObject bindable, object oldValue, object newValue)
        {
            string fontFamily = null;
            string glyph      = null;
            string selector   = (string)bindable.GetValue(IconProperty);

            if (!string.IsNullOrEmpty(selector) && FontRegistry.HasFont(selector, out var font))
            {
                fontFamily = font.FontFileName;
                glyph      = font.GetGlyph(selector);
            }

            switch (bindable)
            {
            case Label label:
                label.Text       = glyph;
                label.FontFamily = fontFamily;
                break;

            case Button btn:
                btn.Text       = glyph;
                btn.FontFamily = fontFamily;
                break;

            case Span span:
                span.Text       = glyph;
                span.FontFamily = fontFamily;
                break;

            case MenuItem menuItem:
                menuItem.IconImageSource = CreateIconImageSource(bindable, selector);
                break;

            default:
                FontRegistry.OnChanged?.Invoke(bindable, selector, glyph, fontFamily);
                break;
            }
        }
예제 #27
0
        public string ProvideValue(IServiceProvider serviceProvider)
        {
            if (serviceProvider is null)
            {
                throw new ArgumentNullException("The IconGlyphExtension requires a ServiceProvider");
            }

            if (FontRegistry.HasFont(IconName, out var font))
            {
                var provideValueTarget = serviceProvider.GetService(typeof(IProvideValueTarget)) as IProvideValueTarget;
                var element            = provideValueTarget.TargetObject;
                var elementType        = element.GetType();
                var fontFamilyProperty = elementType.GetProperty("FontFamily");
                if (fontFamilyProperty is null)
                {
                    throw new NotSupportedException($"The target element {elementType.FullName} does not have a property for the FontFamily. This element is not supported for Icon Glyphs");
                }

                fontFamilyProperty.SetValue(element, font.FontFileName);
                return(font.GetGlyph(IconName));
            }

            return("Unknown Icon");
        }
예제 #28
0
 public virtual Font GetFont()
 {
     return(FontRegistry.GetFont(SyntaxColor.Bold, SyntaxColor.Italic));
 }
 public FontRegistrySetup()
 {
     FontRegistry.Clear();
     Xamarin.Forms.Mocks.MockForms.Init();
     FontRegistry.RegisterFonts(MockFont.Font);
 }
 public void Dispose()
 {
     FontRegistry.Clear();
 }