Ejemplo n.º 1
0
        public override ShapeEx Create(OpenXmlElement openXmlElement)
        {
            Check.NotNull(openXmlElement, nameof(openXmlElement));

            if (openXmlElement is P.GraphicFrame sdkGraphicFrame)
            {
                var grData = openXmlElement.GetFirstChild <A.Graphic>().GetFirstChild <A.GraphicData>();
                if (grData.Uri.Value.Equals(Uri))
                {
                    var spContext      = new ShapeContext(_preSettings, _sldFontService, openXmlElement, _sdkSldPart);
                    var innerTransform = _transformFactory.FromComposite(sdkGraphicFrame);
                    var ole            = new OleObject(sdkGraphicFrame);
                    var shape          = _shapeBuilder.WithOle(innerTransform, spContext, ole);

                    return(shape);
                }
            }

            if (Successor != null)
            {
                return(Successor.Create(openXmlElement));
            }

            return(null);
        }
Ejemplo n.º 2
0
    public ShapeContext shape()
    {
        ShapeContext _localctx = new ShapeContext(Context, State);

        EnterRule(_localctx, 6, RULE_shape);
        int _la;

        try {
            EnterOuterAlt(_localctx, 1);
            {
                State = 26;
                _la   = TokenStream.LA(1);
                if (!((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << BOX) | (1L << CIRCLE) | (1L << LINE))) != 0)))
                {
                    ErrorHandler.RecoverInline(this);
                }
                else
                {
                    ErrorHandler.ReportMatch(this);
                    Consume();
                }
            }
        }
        catch (RecognitionException re) {
            _localctx.exception = re;
            ErrorHandler.ReportError(this, re);
            ErrorHandler.Recover(this, re);
        }
        finally {
            ExitRule();
        }
        return(_localctx);
    }
Ejemplo n.º 3
0
            internal override CompositionShape?GetShapeRoot(TranslationContext context)
            {
                bool layerHasMasks = false;

#if !NoClipping
                layerHasMasks = _context.Layer.Masks.Any();
#endif
                if (layerHasMasks)
                {
                    throw new InvalidOperationException();
                }

                if (!Transforms.TryCreateContainerShapeTransformChain(_context, out var rootNode, out var contentsNode))
                {
                    // The layer is never visible.
                    return(null);
                }

                var shapeContext = new ShapeContext(_context);

                // Update the opacity from the transform. This is necessary to push the opacity
                // to the leaves (because CompositionShape does not support opacity).
                // Note: this is no longer used because we will not call GetShapeRoot if layer transform has
                // animated opacity, instead we will call GetVisualRoot. But let's keep it here
                // just in case we will change the logic of IsShape flag.
                shapeContext.UpdateOpacityFromTransform(_context, _context.Layer.Transform);
                contentsNode.Shapes.Add(TranslateShapeLayerContents(shapeContext, _context.Layer.Contents));

                return(rootNode);
            }
Ejemplo n.º 4
0
            internal override CompositionShape?GetShapeRoot(TranslationContext context)
            {
                bool layerHasMasks = false;

#if !NoClipping
                layerHasMasks = _context.Layer.Masks.Any();
#endif
                if (layerHasMasks)
                {
                    throw new InvalidOperationException();
                }

                if (!Transforms.TryCreateContainerShapeTransformChain(_context, out var rootNode, out var contentsNode))
                {
                    // The layer is never visible.
                    return(null);
                }

                var shapeContext = new ShapeContext(_context);

                // Update the opacity from the transform. This is necessary to push the opacity
                // to the leaves (because CompositionShape does not support opacity).
                shapeContext.UpdateOpacityFromTransform(_context, _context.Layer.Transform);
                contentsNode.Shapes.Add(TranslateShapeLayerContents(shapeContext, _context.Layer.Contents));

                return(rootNode);
            }
Ejemplo n.º 5
0
 internal SlideOLEObject(
     OpenXmlCompositeElement shapeTreeChild,
     ShapeContext spContext,
     SCSlide slide) : base(slide, shapeTreeChild)
 {
     ShapeTreeChild = shapeTreeChild;
     Context        = spContext;
 }
Ejemplo n.º 6
0
 internal SlidePicture(
     SCSlide slide,
     string blipRelateId,
     ShapeContext spContext,
     P.Picture pPicture) : base(slide, pPicture)
 {
     Image   = new SCImage(Slide.SlidePart, blipRelateId);
     Context = spContext;
 }
Ejemplo n.º 7
0
 internal SlideGroupShape(
     ILocation innerTransform,
     ShapeContext spContext,
     List <IShape> groupedShapes,
     OpenXmlCompositeElement pShapeTreeChild,
     SCSlide slide) : base(slide, pShapeTreeChild)
 {
     _innerTransform = innerTransform;
     Context         = spContext;
     Shapes          = groupedShapes;
 }
Ejemplo n.º 8
0
 internal SlideTable(
     OpenXmlCompositeElement pShapeTreeChild,
     ILocation innerTransform,
     ShapeContext spContext,
     SCSlide slide) : base(slide, pShapeTreeChild)
 {
     this.innerTransform = innerTransform;
     Context             = spContext;
     rowCollection       =
         new ResettableLazy <RowCollection>(() => RowCollection.Create(this, (P.GraphicFrame)PShapeTreeChild));
     pGraphicFrame = pShapeTreeChild as P.GraphicFrame;
 }
Ejemplo n.º 9
0
        public override IShape Create(OpenXmlCompositeElement pShapeTreeChild, SCSlide slide)
        {
            if (pShapeTreeChild is P.Shape pShape)
            {
                ShapeContext shapeContext   = _shapeContextBuilder.Build(pShapeTreeChild);
                ILocation    innerTransform = _transformFactory.FromComposite(pShape);
                var          autoShape      = new SlideAutoShape(innerTransform, shapeContext, pShape, slide);

                return(autoShape);
            }

            return(Successor?.Create(pShapeTreeChild, slide));
        }
Ejemplo n.º 10
0
        public override IShape Create(OpenXmlCompositeElement pShapeTreeChild, SCSlide slide)
        {
            if (pShapeTreeChild is P.GraphicFrame pGraphicFrame)
            {
                A.GraphicData graphicData = pShapeTreeChild.GetFirstChild <A.Graphic>().GetFirstChild <A.GraphicData>();
                if (graphicData.Uri.Value.Equals(Uri, StringComparison.Ordinal))
                {
                    ShapeContext spContext      = _shapeContextBuilder.Build(pShapeTreeChild);
                    ILocation    innerTransform = _transformFactory.FromComposite(pGraphicFrame);
                    var          table          = new SlideTable(pGraphicFrame, innerTransform, spContext, slide);

                    return(table);
                }
            }

            return(Successor?.Create(pShapeTreeChild, slide));
        }
Ejemplo n.º 11
0
        public override ShapeEx Create(OpenXmlElement openXmlElement)
        {
            Check.NotNull(openXmlElement, nameof(openXmlElement));

            if (openXmlElement is P.GroupShape sdkGroupShape)
            {
                var sdkShapeHandler      = new SdkShapeHandler(_preSettings, _sldPhFontService, _sdkSldPart, _transformFactory, _shapeBuilder);
                var sdkGroupShapeHandler = new SdkGroupShapeHandler(_preSettings, _sldPhFontService, _sdkSldPart, _transformFactory, _shapeBuilder);
                var oleGrFrameHandler    = new OleGraphicFrameHandler(_preSettings, _sldPhFontService, _sdkSldPart, _transformFactory, _shapeBuilder);
                var pictureHandler       = new PictureHandler(_preSettings, _sldPhFontService, _sdkSldPart, _transformFactory, _shapeBuilder);
                var chartGrFrameHandler  = new ChartGraphicFrameHandler(_preSettings, _sldPhFontService, _sdkSldPart, _transformFactory, _shapeBuilder);
                var tableGrFrameHandler  = new TableGraphicFrameHandler(_preSettings, _sldPhFontService, _sdkSldPart, _transformFactory, _shapeBuilder);

                sdkShapeHandler.Successor      = sdkGroupShapeHandler;
                sdkGroupShapeHandler.Successor = oleGrFrameHandler;
                // OLE objects handler must be before pictures handler, cause OLE container can contain p:pic elements, thereby OLE as a picture
                oleGrFrameHandler.Successor   = pictureHandler;
                pictureHandler.Successor      = chartGrFrameHandler;
                chartGrFrameHandler.Successor = tableGrFrameHandler;

                var groupedShapes = new List <ShapeEx>(sdkGroupShape.Count());
                foreach (var item in sdkGroupShape)
                {
                    var groupedShape = sdkShapeHandler.Create(item);
                    if (groupedShape != null)
                    {
                        groupedShapes.Add(groupedShape);
                    }
                }
                var spContext      = new ShapeContext(_preSettings, _sldPhFontService, sdkGroupShape, _sdkSldPart);
                var transformGroup = sdkGroupShape.GroupShapeProperties.TransformGroup;
                var innerTransform = new NonPlaceholderTransform(transformGroup); //TODO: use factory version instead
                var shape          = _shapeBuilder.WithGroup(innerTransform, spContext, groupedShapes);

                return(shape);
            }

            if (Successor != null)
            {
                return(Successor.Create(openXmlElement));
            }

            return(null);
        }
Ejemplo n.º 12
0
        public override ShapeEx Create(OpenXmlElement openXmlElement)
        {
            Check.NotNull(openXmlElement, nameof(openXmlElement));

            if (openXmlElement is P.Shape sdkShape)
            {
                var spContext      = new ShapeContext(_preSettings, _sldFontService, sdkShape, _sdkSldPart);
                var innerTransform = _transformFactory.FromComposite(sdkShape);
                var shape          = _shapeBuilder.WithAutoShape(innerTransform, spContext);

                return(shape);
            }

            if (Successor != null)
            {
                return(Successor.Create(openXmlElement));
            }

            return(null);
        }
Ejemplo n.º 13
0
            internal override Visual?GetVisualRoot(CompositionContext context)
            {
                bool layerHasMasks = false;

#if !NoClipping
                layerHasMasks = _context.Layer.Masks.Any();
#endif

                if (!Transforms.TryCreateShapeVisualTransformChain(_context, out var rootNode, out var contentsNode))
                {
                    // The layer is never visible.
                    return(null);
                }

                var shapeContext = new ShapeContext(_context);

                contentsNode.Shapes.Add(TranslateShapeLayerContents(shapeContext, _context.Layer.Contents));

                return(layerHasMasks
                    ? Masks.TranslateAndApplyMasksForLayer(_context, rootNode)
                    : rootNode);
            }
Ejemplo n.º 14
0
        public override ShapeEx Create(OpenXmlElement openXmlElement)
        {
            Check.NotNull(openXmlElement, nameof(openXmlElement));

            P.Picture sdkPicture;
            if (openXmlElement is P.Picture treePic)
            {
                sdkPicture = treePic;
            }
            else
            {
                var framePic = openXmlElement.Descendants <P.Picture>().FirstOrDefault();
                sdkPicture = framePic;
            }
            if (sdkPicture != null)
            {
                var pBlipFill    = sdkPicture.GetFirstChild <P.BlipFill>();
                var blipRelateId = pBlipFill?.Blip?.Embed?.Value;
                if (blipRelateId == null)
                {
                    return(null);
                }
                var pictureEx      = new PictureEx(_sdkSldPart, blipRelateId);
                var spContext      = new ShapeContext(_preSettings, _sldFontService, openXmlElement, _sdkSldPart);
                var innerTransform = _transformFactory.FromComposite(sdkPicture);
                var shape          = _shapeBuilder.WithPicture(innerTransform, spContext, pictureEx);

                return(shape);
            }

            if (Successor != null)
            {
                return(Successor.Create(openXmlElement));
            }

            return(null);
        }
Ejemplo n.º 15
0
            internal override Visual?GetVisualRoot(CompositionContext context)
            {
                bool layerHasMasks = false;

#if !NoClipping
                layerHasMasks = _context.Layer.Masks.Any();
#endif

                if (!Transforms.TryCreateShapeVisualTransformChain(_context, out var rootNode, out var contentsNode))
                {
                    // The layer is never visible.
                    return(null);
                }

                var shapeContext = new ShapeContext(_context);

                contentsNode.Shapes.Add(TranslateShapeLayerContents(shapeContext, _context.Layer.Contents));

                Visual result = layerHasMasks ? Masks.TranslateAndApplyMasksForLayer(_context, rootNode) : rootNode;

                var dropShadowEffect = _context.Effects.DropShadowEffect;

                if (dropShadowEffect is not null)
                {
                    result = Effects.ApplyDropShadow(_context, result, dropShadowEffect);
                }

                var gaussianBlurEffect = _context.Effects.GaussianBlurEffect;

                if (gaussianBlurEffect is not null)
                {
                    result = Effects.ApplyGaussianBlur(_context, result, gaussianBlurEffect);
                }

                return(result);
            }
Ejemplo n.º 16
0
        public Tuple <string, int> Recognize(Image <Gray, byte> challenge)
        {
            var list = challenge.getEdge().Sample(100);
            var sc   = ShapeContext.ComputeSC2(list);

            if (sc.Length < 100)
            {
                var tmp = new double[100][];
                for (int i = 0; i < 100; ++i)
                {
                    tmp[i] = new double[60];
                }
                for (int i = 0; i < sc.Length; ++i)
                {
                    Array.Copy(sc[i], tmp[i], 60);
                }
                sc = tmp;
            }

            #region 量化到shapeme
            int[] histogram = new int[100];
            for (int i = 0; i < 100; ++i)
            {
                double[] ds = new double[100];
                for (int j = 0; j < 100; ++j)
                {
                    ds[j] = ShapeContext.HistCost(sc[i], SC.shapemes[j]);
                }
                int id = ds.Select((v, idx) => new ValueIndexPair <double> {
                    Value = v, Index = idx
                })
                         .OrderBy(p => p.Value)
                         .First().Index;
                ++histogram[id];
            }
            #endregion
            #region 计算距离
            double[] dists = new double[SC.template_histograms.Length];
            for (int i = 0; i < SC.template_histograms.Length; ++i)
            {
                dists[i] = Jim.OCR.ShapeContext2D.ShapeContext.ChiSquareDistance(histogram, SC.template_histograms[i]);
                //dists[i] = Jim.OCR.ShapeContext2D.ShapeContext.HistCost(histogram.Cast<double>().ToArray(), templatehistograms[i].Cast<double>().ToArray());
            }
            #endregion

            #region 对结果排序
            var arr = dists.Select((d, i) => new ValueIndexPair <double> {
                Value = d, Index = i
            })
                      .OrderBy(p => p.Value)
                      .Select(p => new { Distance = p.Value, Char = SC.template_chars[p.Index] })
                      //.Where(p => "ABCDEFGHIJKLMNPQRSTUVWXYZ123456789".IndexOf(p.Char) != -1)
                      .Where(p => Filter.IndexOf(p.Char) != -1)
                      .ToArray();
            Dictionary <string, int> matchcount = new Dictionary <string, int>();
            foreach (var pair in arr.Take(Knn))
            {
                string ch = pair.Char;
                matchcount[ch] = matchcount.ContainsKey(ch) ? matchcount[ch] + 1 : 1;
            }
            var match = matchcount.Select(pair => new { Count = pair.Value, Ch = pair.Key })
                        .Where(v => v.Count > 0)
                        .OrderByDescending(v => v.Count).ToArray();
            //string result = "";
            //foreach (var m in match.Take(3)) {
            //    result += String.Format("Char:'{0}',Accuracy:{1}/{2}\t", m.Ch, m.Count, Knn);
            //}
            #endregion

            return(new Tuple <string, int> {
                First = match[0].Ch, Second = match[0].Count
            });
        }
Ejemplo n.º 17
0
        private void recognize_shapeme()
        {
            if (template_histograms == null)
            {
                MessageBox.Show("尚未读取模板。");
                return;
            }
            new Thread(new ThreadStart(() => {
                clearLog();
                showStatus("搜索中");
                foreach (var challenge in splitted_chars)
                {
                    timer.Restart();
                    var list = challenge.getEdge().Sample(100);
                    var sc   = ShapeContext.ComputeSC2(list);
                    if (sc.Length < 100)
                    {
                        var tmp = new double[100][];
                        for (int i = 0; i < 100; ++i)
                        {
                            tmp[i] = new double[60];
                        }
                        for (int i = 0; i < sc.Length; ++i)
                        {
                            Array.Copy(sc[i], tmp[i], 60);
                        }
                        sc = tmp;
                    }

                    #region 量化到shapeme
                    int[] histogram = new int[100];
                    for (int i = 0; i < 100; ++i)
                    {
                        double[] ds = new double[100];
                        for (int j = 0; j < 100; ++j)
                        {
                            ds[j] = ShapeContext.HistCost(sc[i], shapemes[j]);
                        }
                        int id = ds.Select((v, idx) => new ValueIndexPair <double> {
                            Value = v, Index = idx
                        })
                                 .OrderBy(p => p.Value)
                                 .First().Index;
                        ++histogram[id];
                    }
                    #endregion
                    #region 计算距离
                    double[] dists = new double[template_histograms.Length];
                    for (int i = 0; i < template_histograms.Length; ++i)
                    {
                        dists[i] = Jim.OCR.ShapeContext2D.ShapeContext.ChiSquareDistance(histogram, template_histograms[i]);
                        //dists[i] = Jim.OCR.ShapeContext2D.ShapeContext.HistCost(histogram.Cast<double>().ToArray(), templatehistograms[i].Cast<double>().ToArray());
                        showProgress((i + 1.0) / template_histograms.Length);
                    }
                    #endregion


                    #region 对结果排序
                    var arr = dists.Select((d, i) => new ValueIndexPair <double> {
                        Value = d, Index = i
                    })
                              .OrderBy(p => p.Value)
                              .Select(p => new { Distance = p.Value, Char = template_chars[p.Index] })
                              //.Where(p => "ABCDEFGHIJKLMNPQRSTUVWXYZ123456789".IndexOf(p.Char) != -1)
                              .ToArray();
                    Dictionary <string, int> matchcount = new Dictionary <string, int>();
                    int knn = 10;
                    foreach (var pair in arr.Take(knn))
                    {
                        string ch      = pair.Char;
                        matchcount[ch] = matchcount.ContainsKey(ch) ? matchcount[ch] + 1 : 1;
                    }
                    var match = matchcount.Select(pair => new { Count = pair.Value, Ch = pair.Key })
                                .Where(v => v.Count > 0)
                                .OrderByDescending(v => v.Count).ToArray();
                    string result = "";
                    foreach (var m in match.Take(3))
                    {
                        result += String.Format("Char:'{0}',Accuracy:{1}/{2}\t", m.Ch, m.Count, knn);
                    }
                    appendLine(result);
                    #endregion
                }
                appendLine("-----------------------------------------------------");
                showStatus("搜索完成,共用时{0}ms。", timer.Stop());
            })).Start();
        }
Ejemplo n.º 18
0
 public override void Handle(ShapeContext shapeContext)
 {
     //shapeContext.ChangeColor();
     shapeContext.ShapeState = new MovingState();
 }
Ejemplo n.º 19
0
 public override void Handle(ShapeContext shapeContext)
 {
     //shapeContext.ReturnBackColor();
     shapeContext.ShapeState = new RestState();
 }
Ejemplo n.º 20
0
 public abstract void Handle(ShapeContext shapeContext);