Esempio n. 1
0
		public PdfViewController (NSUrl url) : base()
		{
			Url = url;
			View = new UIView ();
			View.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight | UIViewAutoresizing.FlexibleTopMargin | UIViewAutoresizing.FlexibleBottomMargin | UIViewAutoresizing.FlexibleLeftMargin | UIViewAutoresizing.FlexibleRightMargin;
			View.AutosizesSubviews = true;
			
			PdfDocument = CGPDFDocument.FromUrl (Url.ToString ());
			
			// For demo purposes, show first page only.
			PdfPage = PdfDocument.GetPage (1);
			PdfPageRect = PdfPage.GetBoxRect (CGPDFBox.Crop);
			
			// Setup tiled layer.
			TiledLayer = new CATiledLayer ();
			TiledLayer.Delegate = new TiledLayerDelegate (this);
			TiledLayer.TileSize = new SizeF (1024f, 1024f);
			TiledLayer.LevelsOfDetail = 5;
			TiledLayer.LevelsOfDetailBias = 5;
			TiledLayer.Frame = PdfPageRect;
			
			ContentView = new UIView (PdfPageRect);
			ContentView.Layer.AddSublayer (TiledLayer);
			
			// Prepare scroll view.
			ScrollView = new UIScrollView (View.Frame);
			ScrollView.AutoresizingMask = View.AutoresizingMask;
			ScrollView.Delegate = new ScrollViewDelegate (this);
			ScrollView.ContentSize = PdfPageRect.Size;
			ScrollView.MaximumZoomScale = 10f;
			ScrollView.MinimumZoomScale = 1f;
			ScrollView.ScrollEnabled = true;
			ScrollView.AddSubview (ContentView);
			View.AddSubview (ScrollView);
		}
Esempio n. 2
0
 public TiledPdfView(CGRect frame, nfloat scale)
     : base(frame)
 {
     tiledLayer = Layer as CATiledLayer;
     tiledLayer.LevelsOfDetail     = 4;
     tiledLayer.LevelsOfDetailBias = 3;
     tiledLayer.TileSize           = new CGSize(512f, 512f);
     MyScale = scale;
     tiledLayer.BackgroundColor = UIColor.LightGray.CGColor;
     tiledLayer.BorderWidth     = 5;
 }
Esempio n. 3
0
 public TiledPdfView(CGRect frame, nfloat scale)
     : base(frame)
 {
     tiledLayer = Layer as CATiledLayer;
     tiledLayer.LevelsOfDetail = 4;
     tiledLayer.LevelsOfDetailBias = 3;
     tiledLayer.TileSize = new CGSize (512f, 512f);
     MyScale = scale;
     tiledLayer.BackgroundColor = UIColor.LightGray.CGColor;
     tiledLayer.BorderWidth = 5;
 }
Esempio n. 4
0
		public TiledPdfView (RectangleF frame, float scale)
			: base (frame)
		{
			CATiledLayer tiledLayer = Layer as CATiledLayer;
			tiledLayer.LevelsOfDetail = 4;
			tiledLayer.LevelsOfDetailBias = 4;
			tiledLayer.TileSize = new SizeF (512, 512);
			// here we still need to implement the delegate
			tiledLayer.Delegate = new TiledLayerDelegate (this);
			Scale = scale;
		}
Esempio n. 5
0
        /// <summary>
        /// Create a new TiledPDFView with the desired frame and scale.
        /// </summary>
        public TiledPdfView(CGRect frame, nfloat scale) : base(frame)
        {
            tiledLayer = Layer as CATiledLayer;

            // levelsOfDetail and levelsOfDetailBias determine how the layer is rendered at different zoom levels.
            // This only matters while the view is zooming, because once the the view is done zooming a new TiledPDFView is created at the correct size and scale.
            tiledLayer.LevelsOfDetail     = 4;
            tiledLayer.LevelsOfDetailBias = 3;
            tiledLayer.TileSize           = new CGSize(512f, 512f);

            MyScale           = scale;
            Layer.BorderColor = UIColor.LightGray.CGColor;
            Layer.BorderWidth = 5;
        }
Esempio n. 6
0
        // Init method. Call this before adding the instance of the PDF_Manager to the View.
        public void Init(CGPDFDocument oPdfDoc, int page, PageTurnViewController mother_controller)
        {
            Console.WriteLine ("Rendering PDF Page Number: " + page);
            this.page_number = page;
            this.currentPDFdocument = oPdfDoc;

            currentPDFPage = this.currentPDFdocument.GetPage (page_number);

            RectangleF oPdfPageRect = this.currentPDFPage.GetBoxRect (CGPDFBox.Bleed);

            Console.WriteLine ("PDFRect : " + oPdfPageRect.ToString ());

            // Setup tiled layer.
            oTiledLayer = new CATiledLayer ();
            tiled_layer_delegate = new TiledLayerDelegate (this);
            oTiledLayer.Delegate = tiled_layer_delegate;
            oTiledLayer.TileSize = new SizeF (1024f, 1024f);
            oTiledLayer.LevelsOfDetail = 5;
            oTiledLayer.LevelsOfDetailBias = 5;
            oTiledLayer.Frame = oPdfPageRect;
            Console.WriteLine ("oTiledLayer.Frame : " + oTiledLayer.Frame.ToString ());

            this.oContentView = new UIView (oPdfPageRect);
            this.oContentView.Layer.AddSublayer (oTiledLayer);

            this.View.AutoresizingMask = mother_controller.View.AutoresizingMask;
            this.View.AutosizesSubviews = true;

            #if DEBUG
            this.View.Layer.BorderColor = UIColor.Red.CGColor;
            this.View.Layer.BorderWidth = 2f;
            #endif

            // Prepare scroll view.

            this.scroll_area.AutoresizingMask = mother_controller.View.AutoresizingMask;

            scroll_area_delegate = new ScrollViewDelegate (this);
            scroll_area.Delegate = scroll_area_delegate;

            scroll_area.ContentSize = oPdfPageRect.Size;
            scroll_area.MaximumZoomScale = 1000f;
            scroll_area.MinimumZoomScale = 0.1f;

            scroll_area.AddSubview (this.oContentView);
            scroll_area.SetZoomScale (this.View.Frame.Width / oContentView.Frame.Width, false);
        }
Esempio n. 7
0
        public MapRenderer(Mpq mpq, Chk chk)
        {
            this.mpq = mpq;
            this.chk = chk;

            pixel_width  = (ushort)(chk.Width * 32);
            pixel_height = (ushort)(chk.Height * 32);

            Stream cv5_fs = (Stream)mpq.GetResource(String.Format("tileset\\{0}.cv5", Util.TilesetNames[(int)chk.Tileset]));

            cv5 = new byte [cv5_fs.Length];
            cv5_fs.Read(cv5, 0, (int)cv5_fs.Length);
            cv5_fs.Close();

            Stream vx4_fs = (Stream)mpq.GetResource(String.Format("tileset\\{0}.vx4", Util.TilesetNames[(int)chk.Tileset]));

            vx4 = new byte [vx4_fs.Length];
            vx4_fs.Read(vx4, 0, (int)vx4_fs.Length);
            vx4_fs.Close();

            Stream vr4_fs = (Stream)mpq.GetResource(String.Format("tileset\\{0}.vr4", Util.TilesetNames[(int)chk.Tileset]));

            vr4 = new byte [vr4_fs.Length];
            vr4_fs.Read(vr4, 0, (int)vr4_fs.Length);
            vr4_fs.Close();

            Stream vf4_fs = (Stream)mpq.GetResource(String.Format("tileset\\{0}.vf4", Util.TilesetNames[(int)chk.Tileset]));

            vf4 = new byte [vf4_fs.Length];
            vf4_fs.Read(vf4, 0, (int)vf4_fs.Length);
            vf4_fs.Close();

            Stream wpe_fs = (Stream)mpq.GetResource(String.Format("tileset\\{0}.wpe", Util.TilesetNames[(int)chk.Tileset]));

            wpe = new byte [wpe_fs.Length];
            wpe_fs.Read(wpe, 0, (int)wpe_fs.Length);
            wpe_fs.Close();

            mapLayer             = (CATiledLayer)CATiledLayer.Create();
            mapLayer.TileSize    = new SizeF(32, 32);
            mapLayer.Bounds      = new RectangleF(0, 0, pixel_width, pixel_height);
            mapLayer.AnchorPoint = new PointF(0, 0);
            mapLayerDelegate     = new MapLayerDelegate(this);
            mapLayer.Delegate    = mapLayerDelegate;
            mapLayer.SetNeedsDisplay();
        }
Esempio n. 8
0
        public override void Draw(CGRect rect)
        {
            using (var context = UIGraphics.GetCurrentContext()) {
                // get the scale from the context by getting the current transform matrix, then asking for
                // its "a" component, which is one of the two scale components. We could also ask for "d".
                // This assumes (safely) that the view is being scaled equally in both dimensions.
                var          scale      = context.GetCTM().xx;
                CATiledLayer tiledLayer = (CATiledLayer)this.Layer;
                var          tileSize   = tiledLayer.TileSize;

                // Even at scales lower than 100%, we are drawing into a rect in the coordinate system of the full
                // image. One tile at 50% covers the width (in original image coordinates) of two tiles at 100%.
                // So at 50% we need to stretch our tiles to double the width and height; at 25% we need to stretch
                // them to quadruple the width and height; and so on.
                // (Note that this means that we are drawing very blurry images as the scale gets low. At 12.5%,
                // our lowest scale, we are stretching about 6 small tiles to fill the entire original image area.
                // But this is okay, because the big blurry image we're drawing here will be scaled way down before
                // it is displayed.)
                tileSize.Width  /= scale;
                tileSize.Height /= scale;

                // calculate the rows and columns of tiles that intersect the rect we have been asked to draw
                int firstCol = (int)Math.Floor(rect.GetMinX() / tileSize.Width);
                int lastCol  = (int)Math.Floor((rect.GetMaxX() - 1) / tileSize.Width);
                int firstRow = (int)Math.Floor(rect.GetMinY() / tileSize.Height);
                int lastRow  = (int)Math.Floor((rect.GetMaxY() - 1) / tileSize.Height);

                for (int row = firstRow; row <= lastRow; row++)
                {
                    for (int col = firstCol; col <= lastCol; col++)
                    {
                        UIImage tile     = TileForScale((float)scale, row, col);
                        var     tileRect = new CGRect(tileSize.Width * col, tileSize.Height * row, tileSize.Width, tileSize.Height);
                        // if the tile would stick outside of our bounds, we need to truncate it so as to avoid
                        // stretching out the partial tiles at the right and bottom edges
                        tileRect.Intersect(this.Bounds);
                        tile.Draw(tileRect);
                    }
                }
            }
        }
Esempio n. 9
0
		public override void ViewDidDisappear (bool animated)
		{
			base.ViewDidDisappear (animated);
			var page = PdfPage;
			var document = PdfDocument;
			var contentView = ContentView;
			var tiledLayer = TiledLayer;
			var scrollView = ScrollView;
			
			PdfPage = null;
			PdfDocument = null;
			ContentView = null;
			TiledLayer = null;
			ScrollView = null;
			
			scrollView.RemoveFromSuperview ();
			tiledLayer.RemoveFromSuperLayer ();
			page.Dispose ();
			document.Dispose ();
			contentView.Dispose ();
			scrollView.Dispose ();
			tiledLayer.Dispose ();
		}
Esempio n. 10
0
        protected override void Dispose(bool disposing)
        {
            if (oTiledLayer != null)
                oTiledLayer.RemoveFromSuperLayer ();

            if (oContentView != null)
                oContentView.RemoveFromSuperview ();

            if (scroll_area != null)
                scroll_area.RemoveFromSuperview();

            if (tiled_layer_delegate != null)
                tiled_layer_delegate.Dispose ();

            if (scroll_area_delegate != null)
                scroll_area_delegate.Dispose ();

            if (scroll_area != null)
                scroll_area.Delegate = null;

            if (oTiledLayer != null)
                oTiledLayer.Delegate = null;

            scroll_area_delegate = null;

            tiled_layer_delegate = null;

            if (currentPDFPage != null)
                currentPDFPage.Dispose ();

            currentPDFPage = null;

            if (oTiledLayer != null)
                oTiledLayer.Dispose ();

            oTiledLayer = null;

            base.Dispose (disposing);
        }