示例#1
0
        internal void Initialize(FontFamily genericSansSerif, float size, FontStyle bold = FontStyle.Regular,
                                 GraphicsUnit pixel   = GraphicsUnit.Point, byte gdiCharSet = 0,
                                 bool gdiVerticalFont = false)
        {
            try {
                nativeFont = new SKPaint()
                {
                    Typeface  = SKTypeface.FromFamilyName(genericSansSerif?.Name), TextSize = size,
                    TextAlign = SKTextAlign.Left
                };

                FontFamily = new FontFamily()
                {
                    Name = nativeFont.Typeface.FamilyName
                };
                Name = nativeFont.Typeface.FamilyName;
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            Style = bold;
            Unit  = pixel;
            Size  = size;
        }
示例#2
0
        public void Render(SKCanvas canvas)
        {
            var paint = new SKPaint
            {
                Color       = _header.Color.ToSKColor(),
                TextSize    = _header.Font.TextSize,
                IsAntialias = true,
                Typeface    = SKTypeface.FromFamilyName(_header.Font.FontFamily),
            };

            if (_header.BorderWidth > 0)
            {
                SKPaint borderPaint = new SKPaint
                {
                    Color       = SKColors.FloralWhite,
                    StrokeWidth = 2,
                    Style       = SKPaintStyle.Fill,
                };

                canvas.DrawRect(_bounds, borderPaint);
            }

            RenderLeftText(paint, canvas);
            RenderCenterText(paint, canvas);
            RenderRightText(paint, canvas);
        }
示例#3
0
            static IntPtr DoWork()
            {
                var tf1 = SKTypeface.FromFamilyName("Times New Roman");
                var tf2 = SKTypeface.FromFamilyName("Times New Roman");

                Assert.Same(tf1, tf2);

                var tf3 = SKTypeface.FromFile(@"C:\Windows\Fonts\times.ttf");

                Assert.NotSame(tf1, tf3);

                tf1.Dispose();
                tf2.Dispose();
                tf3.Dispose();

                Assert.NotEqual(IntPtr.Zero, tf1.Handle);
                Assert.False(tf1.IsDisposed);

                Assert.NotEqual(IntPtr.Zero, tf2.Handle);
                Assert.False(tf2.IsDisposed);

                Assert.Equal(IntPtr.Zero, tf3.Handle);
                Assert.True(tf3.IsDisposed);

                return(tf1.Handle);
            }
示例#4
0
        public DrinkImage AddWatermark(DrinkImage imagen, string watermark)
        {
            using MemoryStream ms   = new MemoryStream(imagen.Bytes);
            using SKBitmap toBitmap = SKBitmap.Decode(ms);

            using SKCanvas canvas = new SKCanvas(toBitmap);

            using SKTypeface font = SKTypeface.FromFamilyName("Arial");
            using SKPaint brush   = new SKPaint
                  {
                      Typeface    = font,
                      TextSize    = toBitmap.Width * 3 / (watermark.Length * 2),
                      IsAntialias = true,
                      Color       = new SKColor(255, 255, 255, 255)
                  };
            canvas.DrawText(watermark, toBitmap.Width / 20, toBitmap.Height / 2, brush);

            canvas.Flush();

            using SKImage image = SKImage.FromBitmap(toBitmap);
            using SKData data   = image.Encode(SKEncodedImageFormat.Png, 90);

            return(new DrinkImage
            {
                Bytes = data.ToArray(),
                VerticalSize = imagen.VerticalSize,
                HorizontalSize = imagen.HorizontalSize,
                Watermark = watermark,
                ImageName = imagen.ImageName
            });
        }
        unsafe static SKTypeface GetTypeface(string name, FontKey key)
        {
            if (name == null)
            {
                name = "Arial";
            }

            Dictionary <FontKey, SKTypeface> entry;

            if (!Cache.TryGetValue(name, out entry))
            {
                Cache[name] = entry = new Dictionary <FontKey, SKTypeface>();
            }

            SKTypeface typeface = null;

            if (!entry.TryGetValue(key, out typeface))
            {
                typeface = SKTypeface.FromFamilyName(name, key.Weight, SKFontStyleWidth.Normal, key.Slant);

                if (typeface == null)
                {
                    typeface = SKTypeface.FromFamilyName(null, SKTypefaceStyle.Normal);
                }

                entry[key] = typeface;
            }

            return(typeface);
        }
        /// <summary>
        /// Paint text
        /// </summary>
        private void OnPaintText(SKPaintSurfaceEventArgs e)
        {
            SKPaint textPaint = new SKPaint();

            textPaint.Color       = AnimationUtils.ColorTransform(_toggledAnimationProcess, TextColor, ToggledTextColor).ToSKColor();
            textPaint.TextSize    = (float)FontSize * DeviceScale;
            textPaint.TextAlign   = SKTextAlign.Left;
            textPaint.IsAntialias = true;

            SKFontStyleSlant  slant      = SkiaUtils.ConvertToSKFontStyle(FontStyle);
            SKFontStyleWeight fontWeight = SkiaUtils.ConvertToSKFontWeight(FontWeight);

            textPaint.Typeface = SKTypeface.FromFamilyName(FontFamily, fontWeight, SKFontStyleWidth.Normal, slant);

            SKRect skTextBounds = new SKRect();

            textPaint.MeasureText(Text, ref skTextBounds);

            float skNegativePadding = (float)EllipseDiameter * DeviceScale;

            float xText = skNegativePadding - skTextBounds.Left + (float)(TextMargin.Left * DeviceScale);
            float yText = -skTextBounds.Top + (e.Info.Height - skTextBounds.Height) / 2;

            double checkBoxWidth = _selectionViewSize.Width;

            if (_selectionViewLocation == HorizontalLocations.Left)
            {
                xText += (float)(checkBoxWidth * DeviceScale);
            }

            float lineHeight       = (float)FontSize * DeviceScale;
            float skAvailableWidth = (float)(Width - checkBoxWidth - TextMargin.HorizontalThickness) * DeviceScale;

            SkiaUtils.DrawTextArea(e.Surface.Canvas, textPaint, xText, yText, skAvailableWidth, lineHeight, IsTextWrapping, Text);
        }
示例#7
0
        public static SKBitmap Create(LabelStyle style, string text)
        {
            using (var paint = new SKPaint())
            {
                paint.TextSize             = (float)style.Font.Size;
                paint.IsAntialias          = true;
                paint.Color                = style.ForeColor.ToSkia();
                paint.Typeface             = SKTypeface.FromFamilyName(style.Font.FontFamily);
                paint.IsStroke             = false;
                paint.FakeBoldText         = true;
                paint.IsEmbeddedBitmapText = true;

                var rect = new SKRect();
                paint.MeasureText(text, ref rect);

                var targetBitmap = new SKBitmap((int)Math.Ceiling(rect.Width), (int)Math.Ceiling(rect.Height));

                using (var targetGraphics = new SKCanvas(targetBitmap))
                {
                    targetGraphics.Clear((style.BackColor == null) ? new SKColor() : style.BackColor.Color.ToSkia());
                    targetGraphics.DrawText(text, -rect.Left, -rect.Top, paint);
                    return(targetBitmap);
                }
            }
        }
示例#8
0
        /// <summary></summary>
        /// <param name="info"></param>
        /// <param name="canvas"></param>
        private void DrawXLabels(SKImageInfo info, SKCanvas canvas)
        {
            // no data
            if (this.XLabels == null || this.XLabels.Count < 0)
            {
                return;
            }

            // x transform factor
            float xf = (this.GraphFrame.Width / (this.XMax - this.XMin));

            using (SKPaint textPaint = new SKPaint()
            {
                Color = this.LabelColor.ToSKColor(), TextSize = this.XLabelMetrics.FontSize
            })
            {
                textPaint.TextAlign   = SKTextAlign.Center;
                textPaint.IsAntialias = true;
                textPaint.IsStroke    = false;
                textPaint.Typeface    = SKTypeface.FromFamilyName(this.LabelFontFamily);

                foreach (LineLabel i in this.XLabels)
                {
                    if (String.IsNullOrWhiteSpace(i.Text))
                    {
                        continue;
                    }

                    float x = this.GraphFrame.Left + ((i.Location - this.XMin) * xf);

                    canvas.DrawText(i.Text, x, this.GraphFrame.Bottom + this.XLabelMetrics.Height - this.XLabelMetrics.Descent + this._xbreath, textPaint);
                }
            }
        }
示例#9
0
        public IGlyphTypefaceImpl CreateGlyphTypeface(Typeface typeface)
        {
            var skTypeface = SKTypeface.Default;

            if (typeface.FontFamily.Key == null)
            {
                foreach (var familyName in typeface.FontFamily.FamilyNames)
                {
                    skTypeface = SKTypeface.FromFamilyName(familyName, (SKFontStyleWeight)typeface.Weight,
                                                           SKFontStyleWidth.Normal, (SKFontStyleSlant)typeface.Style);

                    if (skTypeface == SKTypeface.Default)
                    {
                        continue;
                    }

                    break;
                }
            }
            else
            {
                var fontCollection = SKTypefaceCollectionCache.GetOrAddTypefaceCollection(typeface.FontFamily);

                skTypeface = fontCollection.Get(typeface.FontFamily, typeface.Weight, typeface.Style);
            }

            return(new GlyphTypefaceImpl(skTypeface));
        }
示例#10
0
        /// <summary>
        /// Вывести текст на изображение
        /// </summary>
        public byte[] TextOut(byte[] image, string text)
        {
            if (string.IsNullOrWhiteSpace(text))
            {
                return(image);
            }

            using (var bitmap = SKBitmap.Decode(image))
            {
                var canvas = new SKCanvas(bitmap);

                var rect = new SKRect();

                var font  = SKTypeface.FromFamilyName("Arial");
                var paint = new SKPaint
                {
                    Typeface    = font,
                    TextSize    = Convert.ToInt64(Device.GetNamedSize(NamedSize.Large, typeof(Label))),
                    IsAntialias = true,
                    Color       = new SKColor(255, 255, 255, 255),
                    TextAlign   = SKTextAlign.Center,
                    Style       = SKPaintStyle.StrokeAndFill
                };

                paint.MeasureText(text, ref rect);
                canvas.DrawText(text, bitmap.Width / 2, 5 + rect.Height, paint);

                var skImage = SKImage.FromBitmap(bitmap);
                var data    = skImage.Encode(SKEncodedImageFormat.Png, 100);
                return(data.ToArray());
            }
        }
示例#11
0
        //TODO
        //public float TextScaleX { get; set; }
        //public float TextSkewX { get; set; }

        protected override void Prepare(SKPaint paint)
        {
            base.Prepare(paint);

            if (FamilyName != null)
            {
                if (FontStyleWeight != null || FontStyleWidth != null || FontSlant != null)
                {
                    paint.Typeface = SKTypeface.FromFamilyName(
                        FamilyName,
                        FontStyleWeight ?? SKFontStyleWeight.Normal,
                        FontStyleWidth ?? SKFontStyleWidth.Normal,
                        FontSlant ?? SKFontStyleSlant.Upright);
                }
                else
                {
                    paint.Typeface = SKTypeface.FromFamilyName(
                        FamilyName,
                        TypefaceStyle ?? SKTypefaceStyle.Normal);
                }
            }
            if (TextSize != null)
            {
                paint.TextSize = (int)TextSize;
            }
            if (TextAlign != null)
            {
                paint.TextAlign = (SKTextAlign)TextAlign;
            }
        }
示例#12
0
        /// <summary>Draws the X axis labels</summary>
        private void DrawXLabels(SKImageInfo info, SKCanvas canvas)
        {
            // no data
            if (this.Entries == null || this.Entries.Count < 0)
            {
                return;
            }

            using (SKPaint textPaint = new SKPaint()
            {
                Color = this.XLabelColor.ToSKColor(), TextSize = this.XLabelMetrics.FontSize
            })
            {
                textPaint.TextAlign   = SKTextAlign.Center;
                textPaint.IsAntialias = true;
                textPaint.IsStroke    = false;
                textPaint.Typeface    = SKTypeface.FromFamilyName(this.XLabelFontFamily);

                foreach (ColumnEntry entry in this.Frames)
                {
                    if (entry.Entry == null || String.IsNullOrWhiteSpace(entry.Entry.Label))
                    {
                        continue;
                    }

                    SKRect rect = entry.LabelFrame;
                    canvas.DrawText(entry.Entry.Label, rect.Left + (rect.Width / 2.0F), rect.Bottom - this.XLabelMetrics.Descent, textPaint);
                }
            }
        }
示例#13
0
        public static TypefaceCollectionEntry Get(FontFamily fontFamily, FontWeight fontWeight, FontStyle fontStyle)
        {
            if (fontFamily.Key != null)
            {
                return(SKTypefaceCollectionCache.GetOrAddTypefaceCollection(fontFamily)
                       .Get(fontFamily.Name, fontWeight, fontStyle));
            }

            var typefaceCollection = s_cache.GetOrAdd(fontFamily.Name, new ConcurrentDictionary <FontKey, TypefaceCollectionEntry>());

            var key = new FontKey(fontWeight, fontStyle);

            if (typefaceCollection.TryGetValue(key, out var entry))
            {
                return(entry);
            }

            var skTypeface = SKTypeface.FromFamilyName(fontFamily.Name, (SKFontStyleWeight)fontWeight,
                                                       SKFontStyleWidth.Normal, (SKFontStyleSlant)fontStyle) ?? SKTypeface.Default;

            var typeface = new Typeface(fontFamily.Name, fontWeight, fontStyle);

            entry = new TypefaceCollectionEntry(typeface, skTypeface);

            typefaceCollection[key] = entry;

            return(entry);
        }
示例#14
0
        public GlobularTextPage()
        {
            Title = "Globular Text";

            canvasView = new SKCanvasView();
            canvasView.PaintSurface += OnCanvasViewPaintSurface;
            Content = canvasView;

            using (SKPaint textPaint = new SKPaint())
            {
                textPaint.Typeface = SKTypeface.FromFamilyName("Times New Roman");
                textPaint.TextSize = 100;

                using (SKPath textPath = textPaint.GetTextPath("HELLO", 0, 0))
                {
                    SKRect textPathBounds;
                    textPath.GetBounds(out textPathBounds);

                    globePath = textPath.CloneWithTransform((SKPoint pt) =>
                    {
                        double longitude = (Math.PI / textPathBounds.Width) * (pt.X - textPathBounds.Left) - Math.PI / 2;
                        double latitude  = (Math.PI / textPathBounds.Height) * (pt.Y - textPathBounds.Top) - Math.PI / 2;

                        longitude *= 0.75;
                        latitude  *= 0.75;

                        float x = (float)(Math.Cos(latitude) * Math.Sin(longitude));
                        float y = (float)Math.Sin(latitude);

                        return(new SKPoint(x, y));
                    });
                }
            }
        }
示例#15
0
        private static MemoryStream CreateCallbackImage(City city)
        {
            using var paint = new SKPaint
                  {
                      Color    = new SKColor((byte)Random.Next(0, 256), (byte)Random.Next(0, 256), (byte)Random.Next(0, 256)),
                      Typeface = SKTypeface.FromFamilyName(null, SKFontStyleWeight.Bold, SKFontStyleWidth.Normal,
                                                           SKFontStyleSlant.Upright),
                      TextSize = 20
                  };

            SKRect bounds;

            using (var textPath = paint.GetTextPath(city.Name, 0, 0))
            {
                // Set transform to center and enlarge clip path to window height
                textPath.GetTightBounds(out bounds);
            }

            using (var bitmap = new SKBitmap((int)(bounds.Width + 1), (int)(bounds.Height + 1)))
                using (var canvas = new SKCanvas(bitmap))
                {
                    canvas.Clear();
                    canvas.DrawText(city.Name, -bounds.Left, -bounds.Top, paint);
                    var memStream = new MemoryStream();
                    using (var wStream = new SKManagedWStream(memStream))
                    {
                        bitmap.Encode(wStream, SKEncodedImageFormat.Png, 100);
                    }
                    return(memStream);
                }
        }
示例#16
0
        private void OnRenderFrame(object sender, FrameEventArgs e)
        {
            var renderCanvas = renderSurface.Canvas;

            renderCanvas.Clear(SKColors.CornflowerBlue);

            using (var paint = new SKPaint {
                IsAntialias = true, TextSize = 100, TextAlign = SKTextAlign.Center
            })
            {
                renderCanvas.DrawText("Hello World!", renderDesc.Width / 2, 150, paint);
            }
            using (var paint = new SKPaint {
                IsAntialias = true, TextSize = 24, Typeface = SKTypeface.FromFamilyName(null, SKTypefaceStyle.Italic)
            })
            {
                renderCanvas.DrawText($"V-Sync: {VSync}", 16, 16 + paint.TextSize, paint);
                renderCanvas.DrawText($"FPS: {1f / e.Time:0}", 16, 16 + paint.TextSize + 8 + paint.TextSize, paint);
            }

            renderCanvas.DrawSurface(textureSurface, (renderDesc.Width - textureDesc.Width) / 2, 200);

            context.Flush();

            SwapBuffers();
        }
示例#17
0
        public void Paint(SKImageInfo info, SKSurface surface)
        {
            //// find center point of the screen
            float centerX = info.Width / 2;
            float centerY = info.Height / 2;

            var canvas = surface.Canvas;

            //// clear the screen
            canvas.Clear(new SKColor(184, 3, 255));

            //// draw text (from text variable)
            canvas.DrawText(text, centerX, centerY, new SKPaint()
            {
                Color    = new SKColor(255, 255, 255),
                Typeface = SKTypeface.FromFamilyName("DejaVu")
            });

            //// let's draw a square of one inch length
            var dpi = engine.GetDeviceInfo().DPI;

            canvas.DrawRect(100, 100, dpi, dpi, new SKPaint()
            {
                Color = SKColor.Parse("0d0")
            });

            this.manager.Draw(canvas);

            //// flush draw actions to canvas
            canvas.Flush();
        }
示例#18
0
    public void Render(SKSurface surface)
    {
        string message = $"Rendered in {ElapsedMilliseconds:0.000} ms ({1e3 / ElapsedMilliseconds:N0} FPS)";

        using SKPaint paint = new()
              {
                  IsAntialias = true,
                  Typeface    = SKTypeface.FromFamilyName("consolas")
              };

        PixelSize textSize = Drawing.MeasureString(message, paint);
        float     margin   = 5;
        SKRect    textRect = new(
            left : Axes.DataRect.Left + margin,
            top : Axes.DataRect.Bottom - paint.TextSize * .9f - 5 - margin,
            right : Axes.DataRect.Left + 5 * 2 + textSize.Width + margin,
            bottom : Axes.DataRect.Bottom - margin);

        paint.Color    = SKColors.Yellow;
        paint.IsStroke = false;
        surface.Canvas.DrawRect(textRect, paint);

        paint.Color    = SKColors.Black;
        paint.IsStroke = true;
        surface.Canvas.DrawRect(textRect, paint);

        paint.Color    = SKColors.Black;
        paint.IsStroke = false;
        surface.Canvas.DrawText(
            text: message,
            x: Axes.DataRect.Left + 4 + margin,
            y: Axes.DataRect.Bottom - 4 - margin,
            paint: paint);
    }
}
示例#19
0
        public SKTypeface GetTypeface(string name)
        {
            if (string.IsNullOrEmpty(name))
            {
                name = _systemFontName;
            }

            if (!_typeFaces.TryGetValue(name, out var typeface))
            {
                try
                {
                    typeface = SKTypeface.FromFamilyName(name);

                    if (typeface != null)
                    {
                        _typeFaces[name] = typeface;
                    }
                }
                catch (Exception exc)
                {
                    typeface = SKTypeface.FromFamilyName(_systemFontName);
                    Logger.Info("Unable to load typeface [{0}]" + name, exc);
                }
            }

            return(typeface);
        }
示例#20
0
        public Font FindFont(string familyName, float fontSize, FontWeight fontWeight, bool italic)
        {
            var fd = new FontDesc
            {
                Typeface = new TypefaceDesc
                {
                    FamilyName = familyName,
                    Weight     = fontWeight,
                    Italic     = italic
                },
                Size = (int)(fontSize * 10)
            };

            if (!fonts.TryGetValue(fd, out var font))
            {
                if (!MatchTypeface(fd.Typeface, out SKTypeface typeface))
                {
                    typeface = SKTypeface.FromFamilyName(familyName, fontWeight.ToSkia(), SKFontStyleWidth.Normal, italic ? SKFontStyleSlant.Italic : SKFontStyleSlant.Upright);
                }

                var skFont = typeface.ToFont(fontSize);
                font = new SkiaFont(skFont);
                if (fontWeight == FontWeight.Bold && typeface.FontWeight < (int)SKFontStyleWeight.SemiBold)
                {
                    font.SKPaint.FakeBoldText = true;
                }

                fonts.Add(fd, font);
            }

            return(font);
        }
示例#21
0
        private void ChangeFont(object sender, EventArgs e)
        {
            chartType = (chartType + 1) % ChartTypes.Length;
            var type = this.ChartTypes[chartType];

            this.chart.Chart          = Activator.CreateInstance(type) as Chart;
            this.chart.Chart.MinValue = -1000;
            this.chart.Chart.MaxValue = 1000;

            Random r        = new Random();
            int    rInt     = r.Next(0, 3);
            var    fontName = string.Empty;

            switch (rInt)
            {
            case 0:
                fontName = "Avenir";
                break;

            case 1:
                fontName = "Noteworthy";
                break;

            case 2:
                fontName = "Helvetica";
                break;

            default:
                fontName = string.Empty;     // test if empty
                break;
            }
            this.chart.Chart.Typeface = SKTypeface.FromFamilyName(fontName);
            GenerateData(null, null);
        }
示例#22
0
        unsafe static SKTypeface GetTypeface(string name, SKTypefaceStyle style)
        {
            if (name == null)
            {
                name = "Arial";
            }

            Dictionary <SKTypefaceStyle, SKTypeface> entry;

            if (!Cache.TryGetValue(name, out entry))
            {
                Cache[name] = entry = new Dictionary <SKTypefaceStyle, SKTypeface>();
            }

            SKTypeface typeface = null;

            if (!entry.TryGetValue(style, out typeface))
            {
                typeface = SKTypeface.FromFamilyName(name, style);
                if (typeface == null)
                {
                    typeface = SKTypeface.FromFamilyName(null, style);
                }
                entry[style] = typeface;
            }
            return(typeface);
        }
示例#23
0
        void OnPainting(object sender, SKPaintSurfaceEventArgs e)
        {
            var surface = e.Surface;

            var canvas = surface.Canvas;

            canvas.Clear();

            var circleFill = new SKPaint
            {
                IsAntialias = true,
                Style       = SKPaintStyle.Fill,
                Color       = GetColorForText()
            };

            canvas.DrawCircle((float)Height, (float)Height, (float)Height, circleFill);

            var textPaint = new SKPaint
            {
                IsAntialias = true,
                Style       = SKPaintStyle.Fill,
                Color       = SKColors.White,
                TextSize    = (float)Height / TextOffset,
                TextAlign   = SKTextAlign.Center,
                Typeface    = SKTypeface.FromFamilyName(FontFamily)
            };

            canvas.DrawText(Text, (float)Height, (float)Height * TextOffset, textPaint);
        }
示例#24
0
        private SKTypeface GetTypeface()
        {
            if (_typeFace == null || _typeFaceFontFamily != FontFamily || _typeFaceFontAttributes != FontAttributes)
            {
                SKTypefaceStyle style = SKTypefaceStyle.Normal;

                switch (FontAttributes)
                {
                case FontAttributes.None:
                    style = SKTypefaceStyle.Normal;
                    break;

                case FontAttributes.Bold:
                    style = SKTypefaceStyle.Bold;
                    break;

                case FontAttributes.Italic:
                    style = SKTypefaceStyle.Italic;
                    break;
                }

                _typeFace = SKTypeface.FromFamilyName(FontFamily == null ? Device.OnPlatform("Helvetica", "sans-serif", "Arial") : FontFamily, style);

                _typeFaceFontFamily     = FontFamily;
                _typeFaceFontAttributes = FontAttributes;
            }

            return(_typeFace);
        }
        public AnimatedBloodConnector(float _dpi)
        {
            dpi = _dpi;

            circleOut = new SKPaint()
            {
                Style       = SKPaintStyle.Stroke,
                IsAntialias = true,
                Color       = SKColors.Orange,
                StrokeWidth = 5,
            };


            paint = new SKPaint()
            {
                Style = SKPaintStyle.Fill,
                Color = SKColors.BlanchedAlmond,

                StrokeWidth = 10
            };

            textPaint = new SKPaint
            {
                Typeface     = SKTypeface.FromFamilyName("Arial Bold"),
                FakeBoldText = true,
                Style        = SKPaintStyle.Fill,
                IsAntialias  = true,
                Color        = SKColors.White,
                IsStroke     = false,
                TextSize     = 14f * dpi
            };

            Width = 30 * dpi;
        }
示例#26
0
        public TextPresenter(BaseWidget owner)
        {
            Owner = owner;

            SelectionBackground = new SKPaint
            {
                Color       = Color.Blue,
                IsAntialias = true,
            };

            SelectionForeground = new SKPaint
            {
                Color       = Color.White,
                IsAntialias = true,
                TextSize    = owner.Style.TextSize,
                Typeface    = SKTypeface.FromFamilyName(owner.Style.FontFamily ?? "Arial")
            };

            Foreground = new SKPaint
            {
                Color       = owner.Style.TextColor,
                IsAntialias = true,
                TextSize    = owner.Style.TextSize,
                Typeface    = SKTypeface.FromFamilyName(owner.Style.FontFamily ?? "Arial")
            };

            ShowCaret = false;
        }
示例#27
0
        public unsafe void FromFamilyReturnsSameObject()
        {
            var tf1 = SKTypeface.FromFamilyName(DefaultFontFamily);
            var tf2 = SKTypeface.FromFamilyName(DefaultFontFamily);

            Assert.Same(tf1, tf2);
        }
示例#28
0
        internal void Initialize(FontFamily genericSansSerif, float size, FontStyle bold = FontStyle.Regular,
                                 GraphicsUnit pixel   = GraphicsUnit.Point, byte gdiCharSet = 0,
                                 bool gdiVerticalFont = false)
        {
            nativeFont = new SKPaint()
            {
                Typeface  = SKTypeface.FromFamilyName(genericSansSerif?.Name), TextSize = Size,
                TextAlign = SKTextAlign.Left
            };

            FontFamily = new FontFamily()
            {
                Name = nativeFont.Typeface.FamilyName
            };
            Name  = nativeFont.Typeface.FamilyName;
            Style = bold;
            Unit  = GraphicsUnit.Pixel;

            if (pixel == GraphicsUnit.Pixel)
            {
                Size = size;
            }
            if (pixel == GraphicsUnit.Point)
            {
                Size = size * 1;
            }
        }
示例#29
0
        public void NonAntiAliasedTextOnScaledCanvasIsCorrect()
        {
            using (var bitmap = new SKBitmap(new SKImageInfo(200, 200)))
                using (var canvas = new SKCanvas(bitmap))
                    using (var tf = SKTypeface.FromFamilyName(DefaultFontFamily))
                        using (var paint = new SKPaint {
                            TextSize = 50, IsAntialias = true, Typeface = tf
                        })
                        {
                            canvas.Clear(SKColors.White);
                            canvas.Scale(1, 2);
                            canvas.DrawText("Skia", 10, 60, paint);

                            Assert.Equal(SKColors.Black, bitmap.GetPixel(49, 92));
                            Assert.Equal(SKColors.White, bitmap.GetPixel(73, 63));
                            Assert.Equal(SKColors.Black, bitmap.GetPixel(100, 89));
                        }

            using (var bitmap = new SKBitmap(new SKImageInfo(200, 200)))
                using (var canvas = new SKCanvas(bitmap))
                    using (var tf = SKTypeface.FromFamilyName(DefaultFontFamily))
                        using (var paint = new SKPaint {
                            TextSize = 50, Typeface = tf
                        })
                        {
                            canvas.Clear(SKColors.White);
                            canvas.Scale(1, 2);
                            canvas.DrawText("Skia", 10, 60, paint);

                            Assert.Equal(SKColors.Black, bitmap.GetPixel(49, 92));
                            Assert.Equal(SKColors.White, bitmap.GetPixel(73, 63));
                            Assert.Equal(SKColors.Black, bitmap.GetPixel(100, 89));
                        }
        }
示例#30
0
        private void DrawConsole(SKCanvas g, Model model, float startX, float startY, float xResize = 1, float yWidth = 16, float yResize = 1, float fontSize = 16)
        {
            var currentX = startX;
            var currentY = startY - yWidth * yResize;
            var font     = new SKPaint
            {
                Typeface = SKTypeface.FromFamilyName("Courier New"),
                TextSize = fontSize
            };

            for (var i = 0; i < model.TileNames.Length; i++)
            {
                if (i % model.LineLength == 0)
                {
                    currentX  = startX;
                    currentY += yWidth * yResize;
                }
                else
                {
                    currentX += yWidth * xResize;
                }

                g.WriteCharacter(model.TileNames[i], font, currentX, currentY, model.HighlightColors[i], 3);
            }
        }