Welcome Guest! You need to login or register to make posts.

Notification

Icon
Error

Options
Go to last post Go to first unread
Chris Jones  
#1 Posted : Wednesday, June 15, 2016 7:15:41 AM(UTC)
Chris Jones

Rank: Advanced Member

Groups: Member
Joined: 6/9/2016(UTC)
Posts: 30

Thanks: 20 times
Firstly, Is it possible to specify the vertical alignment of text for example in PathText/BoundedText/PathBoundedText. I don't mean for vertical text but normal horizontal text that could be centered or placed at the bottom of the bounded area instead of at the top?

If it isn't possible, is this on the roadmap to be implemented at all?

Secondly, Is it possible to automatically fit text into an area, so the text size shrinks as the amount of text increases?

My use case for this is we need to specify an area in an image that we dynamically populate with text which will vary in size and we need to make it fit.

If it isn't possible, are there any workarounds for this? i've seen there is GetBlackBox() method for text which we may be able to use to see whether we need to reduce the font size but may no be very accurate.

Sorry for all the questions!
Thanks
Fedor  
#2 Posted : Wednesday, June 15, 2016 9:15:11 AM(UTC)
Fedor

Rank: Advanced Member

Groups: Member, Administration, Moderator
Joined: 7/28/2003(UTC)
Posts: 1,556

Thanks: 5 times
Was thanked: 62 time(s) in 61 post(s)
Quote:
Firstly, Is it possible to specify the vertical alignment of text for example in PathText/BoundedText/PathBoundedText. I don't mean for vertical text but normal horizontal text that could be centered or placed at the bottom of the bounded area instead of at the top?


It not possible to specify the vertical alignment of PathText as the position of text line is strictly specified by a path.

Unfortunately, it is not possible to specify the vertical alignment in BoundedText and PathBoundedText as well, but we plan to add it in the future releases (Aurigma Bug #0022275).

Currently, you can implement it in BoundedText using the following code:

Code:
using Aurigma.GraphicsMill;
using Aurigma.GraphicsMill.AdvancedDrawing;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Program
{
	public enum VerticalAlign
	{
		Top = 0,
		Middle = 1,
		Bottom = 2
	}

	static void Main(string[] args)
	{
		RenderText(VerticalAlign.Top);
		RenderText(VerticalAlign.Middle);
		RenderText(VerticalAlign.Bottom);
	}


	static void RenderText(VerticalAlign verticalAlign)
	{
		using (var bitmap = new Bitmap(400, 250, PixelFormat.Format24bppRgb, new RgbColor(255, 255, 255, 255)))
		using (var graphics = bitmap.GetAdvancedGraphics())
		{
			var brush = new SolidBrush(RgbColor.Red);
			var dummyText = @"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras elementum quam ac nisi varius gravida. Mauris ornare, dolor et scelerisque volutpat, enim urna commodo odio, consequat fermentum sem arcu sit amet nisl. Aliquam tincidunt id neque in gravida.";
			var boundedTextRect = new System.Drawing.RectangleF(20f, 20f, 360f, 210f);

			var boundedText = new BoundedText(dummyText, graphics.CreateFont("Verdana", 16f),
				brush, boundedTextRect);

			//Vertical align
			if (verticalAlign != VerticalAlign.Top)
			{
				var blackBox = boundedText.GetBlackBox();
				var r = boundedText.Rectangle;

				switch (verticalAlign)
				{ 
					case VerticalAlign.Middle:
						r.Offset(0, (boundedText.Rectangle.Height - blackBox.Height) / 2);
						break;
					case VerticalAlign.Bottom:
						r.Offset(0, boundedText.Rectangle.Height - blackBox.Height);
						break;
				}

				boundedText.Rectangle = r;
			}

			graphics.DrawText(boundedText);

			graphics.DrawRectangle(new Pen(RgbColor.Black), boundedTextRect);

			bitmap.Save(String.Format("../../../VerticlaAlign_{0}.png", verticalAlign));
		}
	}
}


Quote:
Secondly, Is it possible to automatically fit text into an area, so the text size shrinks as the amount of text increases?


Do you mean to get a result as on the attached image?

Edited by user Wednesday, June 15, 2016 7:31:30 PM(UTC)  | Reason: Not specified

Fedor attached the following image(s):
reduce-font-size.png
Best regards,
Fedor Skvortsov
Chris Jones  
#3 Posted : Thursday, June 16, 2016 1:31:58 AM(UTC)
Chris Jones

Rank: Advanced Member

Groups: Member
Joined: 6/9/2016(UTC)
Posts: 30

Thanks: 20 times
Thank you for the code sample, it will be good for support to be built in.

How can i view the logged bugs?

That text overflow/wrapping feature is really useful but i'm talking about automatically reducing the font size of the text (or being able to calculate the required font size) to use to make all the text fit inside the specified bounds. Preferably this would work with path bounded areas as well but our minimum requirement is to be able to do this for a rectangular area.

Example, in a 100x100 area, fitting 50 characters of text would use font size 20 to fit however if there was 100 characters of text it would reduce the font size to 10 so that it all fits in.

Thanks
Eugene Kosmin  
#4 Posted : Monday, June 20, 2016 3:03:08 AM(UTC)
Eugene Kosmin

Rank: Advanced Member

Groups: Member, Administration, Moderator
Joined: 9/19/2006(UTC)
Posts: 438

Was thanked: 22 time(s) in 22 post(s)
Hi Chris,

Quote:
That text overflow/wrapping feature is really useful but i'm talking about automatically reducing the font size of the text (or being able to calculate the required font size) to use to make all the text fit inside the specified bounds. Preferably this would work with path bounded areas as well but our minimum requirement is to be able to do this for a rectangular area.

Example, in a 100x100 area, fitting 50 characters of text would use font size 20 to fit however if there was 100 characters of text it would reduce the font size to 10 so that it all fits in.


Later we will implement this feature internally, but now you can use path object to estimate text filling. Please check TextAutofit sample.
Best regards,
Eugene Kosmin.
Aurigma Development Team
thanks 1 user thanked Eugene Kosmin for this useful post.
Chris Jones on 6/20/2016(UTC)
Fedor  
#5 Posted : Monday, June 20, 2016 3:12:18 AM(UTC)
Fedor

Rank: Advanced Member

Groups: Member, Administration, Moderator
Joined: 7/28/2003(UTC)
Posts: 1,556

Thanks: 5 times
Was thanked: 62 time(s) in 61 post(s)
Originally Posted by: Chris Jones Go to Quoted Post
How can i view the logged bugs?


Unfortunately, our bug system is for internal using only. Even though, we publish bug references on forums so we could update our customer when the bug is resolved.
Best regards,
Fedor Skvortsov
thanks 1 user thanked Fedor for this useful post.
Chris Jones on 6/20/2016(UTC)
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.