Пример #1
0
        public void ApplyLayerStyle(RasterizeLayer layer, RasterizeLayerStyleDefinition layerStyleDef)
        {
            switch (layer)
            {
            case RasterizeLayer.OuterGlow:
                StyleDefinition.OuterGlow = layerStyleDef;
                break;

            case RasterizeLayer.InnerGlow:
                StyleDefinition.InnerGlow = layerStyleDef;
                break;

            case RasterizeLayer.Foreground:
                StyleDefinition.Foreground = layerStyleDef;
                break;

            case RasterizeLayer.Background:
                StyleDefinition.Background = layerStyleDef;
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(layer), layer, null);
            }
            Style = StyleDefinition.Scale(Dim.SvgScale);
        }
        /// <summary>
        /// Renders a given layer on a surface and caches it.
        /// </summary>
        /// <param name="setting">Display setting</param>
        /// <param name="layer">Which layer is it we're rendering</param>
        /// <param name="layerStyleDef">Style definition</param>
        /// <param name="layerStyle">Style to render</param>
        /// <param name="segments">Which segments to render</param>
        /// <param name="skewAngle">How much to skew</param>
        public void RasterizeLayer(DisplaySetting setting, RasterizeLayer layer, RasterizeLayerStyleDefinition layerStyleDef, RasterizeLayerStyle layerStyle, IEnumerable <int> segments, float skewAngle)
        {
            var source = _svgs[setting.SegmentType][setting.StyleDefinition.SegmentWeight];

            //Logger.Info("Rasterizing {0} segments of layer {1} on display {2} segment size = {3}x{4}", setting.SegmentType, layer, setting.Display, setting.Dim.SvgWidth, setting.Dim.SvgHeight);
            using (var paint = new SKPaint()) {
                ApplyFilters(paint, layerStyleDef, layerStyle);
                foreach (var i in segments)
                {
                    var initialKey = new RasterCacheKey(InitialCache, layer, setting.SegmentType, setting.StyleDefinition.SegmentWeight, i);
                    var cacheKey   = new RasterCacheKey(setting.Display, layer, setting.SegmentType, setting.StyleDefinition.SegmentWeight, i);
                    if (!_rasterCache.ContainsKey(initialKey))
                    {
                        _rasterCache[initialKey] = RasterizeSegment(source[i].Picture, setting.Dim, skewAngle, paint);
                    }
                    else
                    {
                        if (_rasterCache.ContainsKey(cacheKey))
                        {
                            _rasterCache[cacheKey]?.Dispose();
                        }
                        _rasterCache[cacheKey] = RasterizeSegment(source[i].Picture, setting.Dim, skewAngle, paint);
                    }
                }
            }
        }
Пример #3
0
 protected bool Equals(RasterizeLayerStyleDefinition other)
 {
     return(IsEnabled == other.IsEnabled &&
            IsBlurEnabled == other.IsBlurEnabled &&
            IsDilateEnabled == other.IsDilateEnabled &&
            Color.Equals(other.Color) &&
            Blur.Equals(other.Blur) &&
            Dilate.Equals(other.Dilate));
 }
 private void ApplyFilters(SKPaint paint, RasterizeLayerStyleDefinition layerStyleDef, RasterizeLayerStyle layerStyle)
 {
     paint.ColorFilter = SKColorFilter.CreateBlendMode(layerStyleDef.Color, SKBlendMode.SrcIn);
     if (layerStyleDef.IsBlurEnabled && layerStyleDef.IsDilateEnabled)
     {
         paint.ImageFilter = SKImageFilter.CreateBlur(layerStyle.Blur.X, layerStyle.Blur.Y,
                                                      SKImageFilter.CreateDilate((int)layerStyle.Dilate.X, (int)layerStyle.Dilate.Y));
     }
     else if (layerStyleDef.IsBlurEnabled)
     {
         paint.ImageFilter = SKImageFilter.CreateBlur(layerStyle.Blur.X, layerStyle.Blur.Y);
     }
     else if (layerStyleDef.IsDilateEnabled)
     {
         paint.ImageFilter = SKImageFilter.CreateDilate((int)layerStyle.Dilate.X, (int)layerStyle.Dilate.Y);
     }
 }