예제 #1
0
        /// <summary>
        /// Go through all blocks above pending blocks and set them up to fall
        /// </summary>
        private void QueueDrops()
        {
            Block block;
            Block current;
            Group group;

            for (int i = 0; i < pendingBlocks.Count; i++)
            {
                block = pendingBlocks[i].GetTopAdjacent();

                //Iterate up and add all blocks
                while (block != null)
                {
                    //Check if block is grouped
                    if (block.IsGrouped())
                    {
                        group = block.GetGroup();
                        //Add all blocks in group to active blocks
                        for (int j = 0; j < group.blocks.Count; j++)
                        {
                            activeBlocks.Add(group.blocks[j]);
                        }

                        current = group.data.topLeft;

                        //Iterate through all blocks above the top row
                        while (current != null)
                        {
                            block = current;
                            block = block.GetTopAdjacent();
                            //Iterate up
                            while (block != null)
                            {
                                activeBlocks.Add(block);
                                block = block.GetTopAdjacent();
                            }
                            //Iterate right
                            current = current.GetRightAdjacent();
                        }
                    }
                    //Else if it's a normal block, just add it
                    else
                    {
                        activeBlocks.Add(block);
                        block = block.GetTopAdjacent();
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Spawn next blocks, (Spawn blocks and put them into nextBlock Set)
        /// </summary>
        public void SpawnNext()
        {
            Block block = Spawn(nextBlock1);

            SetupBlock(block, BlockSpawnPosition.center);
            activeBlocks.Add(block);

            Block block2 = Spawn(nextBlock2);

            SetupBlock(block2, BlockSpawnPosition.top);
            activeBlocks.Add(block2);

            nextBlock1 = null;
            nextBlock2 = null;
        }
예제 #3
0
        public BlockPage Process(BlockPage page)
        {
            var orange = page.AllBlocks.Cast <MarkLine>().Where(l => l.Color == MarkLine.ORANGE);
            var result = new BlockPage();

            result.AddRange(orange);

            bool overlap = HasTableOverlap(result);

            if (overlap)
            {
                PdfReaderException.Warning("MarkOrangeNoOverlap: Overlap");
                return(result);
            }

            // column
            var bset = new BlockSet <IBlock>();

            bset.Add(new BlockLine()
            {
                X = 1, H = 1, Width = 1, Height = 1, Text = "MarkOrange"
            });

            var almostEmpty = new BlockPage();

            almostEmpty.Add(bset);

            return(almostEmpty);
        }
예제 #4
0
 public void Setup()
 {
     blocks.ForEach(block =>
     {
         activeBlocks.Add(block);
     });
 }
예제 #5
0
    /**
     * DrawBlockSetEditor draws and handles the editing of the BlockSet
     */
    private static void DrawBlockSetEditor(BlockSet blockSet)
    {
        GUILayout.BeginVertical("box");
        selectedBlock = DrawBlockList(blockSet, selectedBlock, ref blockSetScrollPosition);
        EditorGUILayout.Separator();

        GUILayout.BeginHorizontal();
        if (GUILayout.Button("Add Cube"))
        {
            selectedBlock = blockSet.Add(new Cube("new Cube"));
        }
        if (GUILayout.Button("Add Cross"))
        {
            selectedBlock = blockSet.Add(new Cross("new Cross"));
        }
        GUILayout.EndHorizontal();
        if (GUILayout.Button("Remove") && blockSet.GetBlock(selectedBlock) != null)
        {
            Undo.RecordObject(blockSet, "Remove block");
            blockSet.Remove(selectedBlock);
            selectedBlock = Mathf.Clamp(selectedBlock, 0, blockSet.GetCount() - 1);
        }
        GUILayout.EndVertical();
    }
예제 #6
0
        public void EventOccurred(IEventData data, EventType type)
        {
            var image = data as ImageRenderInfo;

            if (image != null)
            {
                var name = image.GetImageResourceName().ToString();
                var ctm  = image.GetImageCtm();

                var x      = ctm.Get(6);
                var h      = ctm.Get(7);
                var width  = ctm.Get(0);
                var height = ctm.Get(4);

                // ensure we have a simple transformation matrix
                if ((ctm.Get(1) != 0) || (ctm.Get(2) != 0) || (ctm.Get(3) != 0) ||
                    (ctm.Get(5) != 0) || (ctm.Get(8) != 1))
                {
                    PdfReaderException.Warning("PreProcessImages: ensure we have a simple transformation matrix (CTM)");
                    return;
                }

                if (height < 0)
                {
                    h      = h + height;
                    height = -height;
                }

                var imageBlock = new ImageBlock()
                {
                    X            = x,
                    H            = h,
                    Width        = width,
                    Height       = height,
                    ResourceName = name
                };

                if (imageBlock.Width <= 0 || imageBlock.Height <= 0)
                {
                    PdfReaderException.AlwaysThrow("imageBlock.Width <= 0 || imageBlock.Height <= 0");
                }

                _blockSet.Add(imageBlock);
            }
        }
예제 #7
0
        BlockColumn CopyColumnMetadata(BlockPage2 blocksetInfo, BlockColumn column)
        {
            var columnInfo = new BlockColumn(blocksetInfo, column.ColumnType, column.X1, column.W);

            var block = new Block()
            {
                H      = column.GetH(),
                X      = column.GetX(),
                Height = column.GetHeight(),
                Width  = column.GetWidth(),
                Text   = $"Column [{columnInfo.ColumnType}:{columnInfo.X1}]"
            };
            var bset = new BlockSet <IBlock>(blocksetInfo);

            bset.Add(block);

            columnInfo.Add(bset);

            return(columnInfo);
        }
예제 #8
0
        BlockSet <IBlock> FindBlockCore(BlockSet <IBlock> blockset)
        {
            var blocks = blockset.ToList();

            int   total = blocks.Count - 1;
            float limit = blockset.GetWidth() / 2;

            int start = ScanBlock(i => blocks[i], blockset.GetX() + limit);
            int end   = ScanBlock(i => blocks[total - i], blockset.GetX() + limit);

            int ini = start;
            int tot = total + 1 - end;

            var core = new BlockSet <IBlock>();

            // get the core
            for (int i = start; i <= total - end; i++)
            {
                core.Add(blocks[i]);
            }

            return(core);
        }
예제 #9
0
        private void AddToSets()
        {
            allBlocks.Add(block);
            switch (block.data.type)
            {
            case BlockType.normal:
                normalBlocks.Add(block);
                break;

            case BlockType.breaker:
                breakerBlocks.Add(block);
                break;

            case BlockType.diamond:
                diamondBlocks.Add(block);
                break;
            }

            switch (block.data.color)
            {
            case BlockColor.blue:
                blueBlocks.Add(block);
                break;

            case BlockColor.green:
                greenBlocks.Add(block);
                break;

            case BlockColor.red:
                redBlocks.Add(block);
                break;

            case BlockColor.yellow:
                yellowBlocks.Add(block);
                break;
            }
        }
예제 #10
0
        public void EventOccurred(IEventData data, EventType type)
        {
            var line = data as PathRenderInfo;

            if (line != null)
            {
                int   op        = line.GetOperation();
                var   bgcolor   = (op == 2) ? GetBgColor(line.GetFillColor()) : 0;
                var   fgcolor   = GetColor(line.GetStrokeColor());
                float linewidth = line.GetLineWidth();
                var   path      = line.GetPath();
                var   subpaths  = path.GetSubpaths();
                int   count     = subpaths.Count;
                var   ctm       = line.GetCtm();
                var   dx        = ctm.Get(6);
                var   dy        = ctm.Get(7);

                if (op == 0)
                {
                    return;
                }

                var segs = subpaths
                           .SelectMany(p => p.GetSegments())
                           .SelectMany(s => s.GetBasePoints())
                           .ToArray();

                int segcount = segs.Length;

                float minerr = .5f;

                var sign_x = ctm.Get(0);
                var rot_x  = ctm.Get(1);
                var zero_x = ctm.Get(2);
                var rot_y  = ctm.Get(3);
                var sign_y = ctm.Get(4);
                var zero_y = ctm.Get(5);

                if (zero_x != 0 || zero_y != 0)
                {
                    throw new InvalidOperationException();
                }

                //float x1 = (float)segs.Min(s => s.x) - minerr;
                //float x2 = (float)segs.Max(s => s.x) + minerr;
                //float y1 = (float)segs.Min(s => sign_y * s.y) - minerr;
                //float y2 = (float)segs.Max(s => sign_y * s.y) + minerr;

                float x1 = (float)segs.Min(s => sign_x * s.x + rot_x * s.y) - minerr;
                float x2 = (float)segs.Max(s => sign_x * s.x + rot_x * s.y) + minerr;
                float y1 = (float)segs.Min(s => rot_y * s.x + sign_y * s.y) - minerr;
                float y2 = (float)segs.Max(s => rot_y * s.x + sign_y * s.y) + minerr;

                float translate_x = dx;
                float translate_y = dy;

                var tableCell = new TableCell()
                {
                    Op        = op,
                    X         = x1 + translate_x,
                    H         = y1 + translate_y,
                    Width     = x2 - x1,
                    Height    = y2 - y1,
                    LineWidth = linewidth,
                    BgColor   = (op == 1) ?  fgcolor : bgcolor
                };

                if (tableCell.Width < 0 || tableCell.Height < 0)
                {
                    PdfReaderException.AlwaysThrow("tableCell.Width < 0 || tableCell.Height < 0");
                }


                if (tableCell.X >= 0 || tableCell.H >= 0)
                {
                    if (tableCell.Op != 0)
                    {
                        _blockSet.Add(tableCell);
                    }
                }
                else
                {
                    // sometimes it draws a large rectangle to fill the background
                }
            }
        }
예제 #11
0
        public void EventOccurred(IEventData data, EventType type)
        {
            if (data is TextRenderInfo textInfo)
            {
                var baseline  = textInfo.GetBaseline().GetStartPoint();
                var descent   = textInfo.GetDescentLine().GetStartPoint();
                var ascent    = textInfo.GetAscentLine().GetEndPoint();
                var font      = textInfo.GetFont().GetFontProgram().GetFontNames();
                var fontName  = GetFontName(font);
                var fontStyle = GetFontStyle(font);

                // calculate font-size
                float ctm_y    = textInfo.GetTextMatrix().Get(4);
                float fontSize = textInfo.GetFontSize() * ctm_y;

                var block = new Block()
                {
                    Text         = textInfo.GetText(),
                    X            = descent.Get(0),
                    H            = descent.Get(1),
                    B            = baseline.Get(1),
                    Width        = ascent.Get(0) - descent.Get(0),
                    Height       = ascent.Get(1) - descent.Get(1),
                    Lower        = baseline.Get(1) - descent.Get(1),
                    FontFullName = font.GetFontName(),
                    FontName     = fontName,
                    FontStyle    = fontStyle,
                    FontSize     = fontSize,
                    IsBold       = (fontStyle == "Bold"),
                    IsItalic     = (fontStyle == "Italic"),
                    WordSpacing  = textInfo.GetWordSpacing()
                };

                if (ShouldRecalculateSpaces(block.Text))
                {
                    string newtext = RecalculateSpaces(textInfo);
                    if (newtext != block.Text)
                    {
                        block.Text = newtext;
                    }
                }

                if (block.Width <= 0 || block.Height <= 0)
                {
                    PdfReaderException.AlwaysThrow("block.Width <= 0 || block.Height <= 0");
                }

                if (block.FontSize <= 0)
                {
                    PdfReaderException.AlwaysThrow("block.FontSize <= 0");
                }

                // valuable log information: sometimes FontStyle is wrong!
                // var workfont = WorkFont(font);

                float dbgWordSpacing = textInfo.GetWordSpacing();

                if (dbgWordSpacing == 0)
                {
                    // why 0?
                }

                _blockSet.Add(block);
            }
        }
예제 #12
0
        BlockSet <IBlock>[] SplitBlock(BlockSet <IBlock> blockset)
        {
            var blocks = blockset.ToList();

            int   total = blocks.Count - 1;
            float limit = blockset.GetWidth() / 2;

            int start = ScanBlock(i => blocks[i], blockset.GetX() + limit);
            int end   = ScanBlock(i => blocks[total - i], blockset.GetX() + limit);

            // no split
            if (start == 0 && end == 0)
            {
                // VALIDATE
                //System.Diagnostics.Debugger.Break();

                return(new BlockSet <IBlock>[] { blockset });
            }

            // split into 2 pieces
            int middle = -1;

            // split into 2 pieces: there is a clear division
            middle = (start + end > total) ? (start) : middle;
            middle = (start == 0) ? (total - end + 1) : middle;
            middle = (end == 0) ? (start) : middle;

            if (middle > 0)
            {
                var blockA = new BlockSet <IBlock>();
                var blockB = new BlockSet <IBlock>();

                blockA.AddRange(blocks.Take(middle));
                blockB.AddRange(blocks.TakeLast(total - middle + 1));

                int count2 = blockA.Count() + blockB.Count();
                if (count2 != blocks.Count)
                {
                    PdfReaderException.AlwaysThrow("count2 != blocks.Count");
                }

                // VALIDATE
                //System.Diagnostics.Debugger.Break();

                return(new BlockSet <IBlock>[] { blockA, blockB });
            }

            // split into 3 pieces
            var topBlock    = new BlockSet <IBlock>();
            var coreBlock   = new BlockSet <IBlock>();
            var bottomBlock = new BlockSet <IBlock>();

            topBlock.AddRange(blocks.Take(start));

            for (int i = start; i <= total - end; i++)
            {
                coreBlock.Add(blocks[i]);
            }

            bottomBlock.AddRange(blocks.TakeLast(end));

            int count3 = topBlock.Count() + coreBlock.Count() + bottomBlock.Count();

            if (count3 != blocks.Count)
            {
                PdfReaderException.AlwaysThrow("count3 != blocks.Count");
            }

            // VALIDATE
            //System.Diagnostics.Debugger.Break();
            return(new BlockSet <IBlock>[] { topBlock, coreBlock, bottomBlock });
        }
예제 #13
0
        public void EventOccurred(IEventData data, EventType type)
        {
            var line = data as PathRenderInfo;

            if (line != null)
            {
                var   bgcolor  = line.GetFillColor();
                var   fgcolor  = line.GetStrokeColor();
                int   op       = line.GetOperation();
                float width    = line.GetLineWidth();
                var   path     = line.GetPath();
                var   subpaths = path.GetSubpaths();
                int   count    = subpaths.Count;
                var   ctm      = line.GetCtm();
                var   dx       = ctm.Get(6);
                var   dy       = ctm.Get(7);

                var segs = subpaths
                           .SelectMany(p => p.GetSegments())
                           .SelectMany(s => s.GetBasePoints())
                           .ToArray();

                foreach (var sub in subpaths)
                {
                    var segments = sub.GetSegments();

                    foreach (var s in segments)
                    {
                        var ps       = s.GetBasePoints();
                        var ps_count = ps.Count;

                        var ps2 = ps.Select(p => p.GetLocation()).ToArray();
                    }
                }

                float minerr = .5f;

                var sign_x = ctm.Get(0);
                var sign_y = ctm.Get(4);

                float x1 = (float)segs.Min(s => s.x) - minerr;
                float x2 = (float)segs.Max(s => s.x) + minerr;
                float y1 = (float)segs.Min(s => sign_y * s.y) - minerr;
                float y2 = (float)segs.Max(s => sign_y * s.y) + minerr;

                float translate_x = dx;
                float translate_y = dy;

                var tableCell = new TableCell()
                {
                    Op     = op,
                    X      = x1 + translate_x,
                    H      = y1 + translate_y,
                    Width  = x2 - x1,
                    Height = y2 - y1
                };

                if (tableCell.Width < 0 || tableCell.Height < 0)
                {
                    PdfReaderException.AlwaysThrow("tableCell.Width < 0 || tableCell.Height < 0");
                }

                if (tableCell.Op != 1)
                {
                    _blockSet.Add(tableCell);
                }
            }
        }
예제 #14
0
        public void EventOccurred(IEventData data, EventType type)
        {
            var line = data as PathRenderInfo;

            if (line != null)
            {
                int   op        = line.GetOperation();
                var   color     = GetColorNumber(line.GetStrokeColor());
                float linewidth = line.GetLineWidth();
                var   path      = line.GetPath();
                var   subpaths  = path.GetSubpaths();
                int   count     = subpaths.Count;

                // check for stroke
                if (op != 1)
                {
                    return;
                }

                if (color < 2)
                {
                    return;
                }

                // check the identity matrix (CTM)
                var ctm = line.GetCtm();

                var sign_x = ctm.Get(0);
                var rot_x  = ctm.Get(1);
                var zero_x = ctm.Get(2);
                var rot_y  = ctm.Get(3);
                var sign_y = ctm.Get(4);
                var zero_y = ctm.Get(5);

                if (zero_x != 0 || zero_y != 0 || rot_x != 0 || rot_y != 0)
                {
                    throw new InvalidOperationException();
                }

                if (sign_x != 1 || sign_y != 1)
                {
                    throw new InvalidOperationException();
                }

                foreach (var subp in subpaths)
                {
                    if (subp.IsEmpty() || subp.IsSinglePointOpen())
                    {
                        continue;
                    }

                    if (!subp.IsClosed())
                    {
                        PdfReaderException.AlwaysThrow("!subp.IsClosed()");
                    }

                    var segs = subp.GetSegments()
                               .SelectMany(s => s.GetBasePoints())
                               .ToArray();

                    float x1 = (float)segs.Min(s => s.x);
                    float x2 = (float)segs.Max(s => s.x);
                    float y1 = (float)segs.Min(s => s.y);
                    float y2 = (float)segs.Max(s => s.y);

                    float translate_x = ctm.Get(6);
                    float translate_y = ctm.Get(7);

                    var mark = new MarkLine()
                    {
                        X         = x1 + translate_x,
                        H         = y1 + translate_y,
                        Width     = x2 - x1,
                        Height    = y2 - y1,
                        LineWidth = linewidth,
                        Color     = color
                    };

                    if (color < 2)
                    {
                        PdfReaderException.AlwaysThrow("Invalid color");
                    }

                    if (mark.X < 0 || mark.H < 0)
                    {
                        PdfReaderException.AlwaysThrow("mark.X < 0 || mark.H < 0");
                    }

                    _blockSet.Add(mark);
                }
            }
        }