Exemplo n.º 1
0
		public void SetPage (Page p)
		{
			if (page != p) {
				page = p;
				UpdatePage ();
			}
		}
Exemplo n.º 2
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;
			}
		}
Exemplo n.º 3
0
		public UIImage RenderPagePreview (Page page, SizeF size)
		{
			UIGraphics.BeginImageContextWithOptions (size, true, 0.0f);

			var scale = CGAffineTransform.MakeScale (0.5f, 0.5f);
			UIGraphics.GetCurrentContext ().ConcatCTM (scale);

			RenderPage (page, new SizeF (1024, 768), false);

			var ret = UIGraphics.GetImageFromCurrentImageContext ();

			UIGraphics.EndImageContext ();

			return ret;
		}