Exemple #1
0
        /*
         * Render the page here: we assume we are already in a normalized coordinate system which maps
         *  our standard aspect ratio (3:4) to (1:1)
         * The reason why we do this is to reuse the same drawing code for both the preview and the
         *  full screen; for full screen rendering, we map the whole view, whereas the preview maps
         *  the whole preview image to a quarter of the page.
         * */
        public RectangleF [] RenderPage(Page page, SizeF size, bool unstyledDrawing)
        {
            var pageRect        = new RectangleF(0, 0, size.Width, size.Height);
            var paragraphBounds = new RectangleF [page.Paragraphs.Count];

            using (var ctxt = UIGraphics.GetCurrentContext()) {
                // fill background
                ctxt.SetFillColor(UIColor.FromHSBA(0.11f, 0.2f, 1, 1).CGColor);
                ctxt.FillRect(pageRect);

                pageRect = pageRect.Inset(20, 20);

                int i = 0;
                foreach (var p in page.Paragraphs)
                {
                    var bounds = new RectangleF(pageRect.X, pageRect.Y, 0, 0);

                    if (UnstyledDrawing)
                    {
                        var text = new NSString(page.StringForParagraph(p));

                        var font = UIFont.FromName("HoeflerText-Regular", 24);

                        // draw text with the old legacy path, setting the font color to black.
                        ctxt.SetFillColor(UIColor.Black.CGColor);
                        bounds.Size = text.DrawString(pageRect, font);
                    }
                    else
                    {
                        // TODO: draw attributed text with new string drawing
                        var text        = page.AttributedStringForParagraph(p);
                        var textContext = new NSStringDrawingContext();

                        text.DrawString(pageRect, NSStringDrawingOptions.UsesLineFragmentOrigin, textContext);

                        bounds = textContext.TotalBounds;
                        bounds.Offset(pageRect.X, pageRect.Y);
                    }

                    paragraphBounds [i++] = bounds;

                    pageRect.Y += bounds.Height;
                }

                return(paragraphBounds);
            }
        }
		/*
		 * Render the page here: we assume we are already in a normalized coordinate system which maps 
		 * 	our standard aspect ratio (3:4) to (1:1)
		 * The reason why we do this is to reuse the same drawing code for both the preview and the 
		 * 	full screen; for full screen rendering, we map the whole view, whereas the preview maps
		 * 	the whole preview image to a quarter of the page.
		 * */
		public RectangleF [] RenderPage (Page page, SizeF size, bool unstyledDrawing)
		{
			var pageRect = new RectangleF (0, 0, size.Width, size.Height);
			var paragraphBounds = new RectangleF [page.Paragraphs.Count];

			using (var ctxt = UIGraphics.GetCurrentContext ()) {
				// fill background
				ctxt.SetFillColor (UIColor.FromHSBA (0.11f, 0.2f, 1, 1).CGColor);
				ctxt.FillRect (pageRect);

				pageRect = pageRect.Inset (20, 20);

				int i = 0;
				foreach (var p in page.Paragraphs) {
					var bounds = new RectangleF (pageRect.X, pageRect.Y, 0, 0);

					if (UnstyledDrawing) {

						var text = new NSString (page.StringForParagraph (p));
	
						var font = UIFont.FromName ("HoeflerText-Regular", 24);

						// draw text with the old legacy path, setting the font color to black.
						ctxt.SetFillColor (UIColor.Black.CGColor);
						bounds.Size = text.DrawString (pageRect, font);

					} else {

						// TODO: draw attributed text with new string drawing
						var text = page.AttributedStringForParagraph (p);
						var textContext = new NSStringDrawingContext ();

						text.DrawString (pageRect, NSStringDrawingOptions.UsesLineFragmentOrigin, textContext);

						bounds = textContext.TotalBounds;
						bounds.Offset (pageRect.X, pageRect.Y);
					}

					paragraphBounds [i++] = bounds;

					pageRect.Y += bounds.Height;
				}

				return paragraphBounds;
			}
		}