Returns a rectangle with canvas-relative coordinates. A callback is required to calculate the actual size of the content based on the specified bounds. The callback may be passed double.NaN for one or more paramters to indicate that they are not specified.
189 else if (
"canvas".Equals(
RelativeTo, StringComparison.OrdinalIgnoreCase))
190 cont =
new RectangleF(
new PointF(), s.
destSize);
192 cont = PolygonMath.GetBoundingBox(s.layout[
"image"]);
195 RectangleF rect =
new RectangleF();
198 double left = Resolve(
Left, cont.X, cont.Width,
false);
199 double top = Resolve(
Top, cont.Y, cont.Height,
false);
200 double right = Resolve(
Right, cont.Right, cont.Width,
true);
201 double bottom = Resolve(
Bottom, cont.Bottom, cont.Height,
true);
202 double width = Resolve(
Width, 0, cont.Width,
false);
203 double height = Resolve(
Height, 0, cont.Height,
false);
206 if (forceInsideCanvas) {
207 SizeF canvas = s.destSize;
208 if (!
double.IsNaN(left)) left = Math.Min(Math.Max(0, left), canvas.Width);
209 if (!
double.IsNaN(right)) right = Math.Min(Math.Max(0, right), canvas.Width);
210 if (!
double.IsNaN(width)) width = Math.Min(Math.Max(0, width), canvas.Width);
211 if (!
double.IsNaN(bottom)) bottom = Math.Min(Math.Max(0, bottom), canvas.Height);
212 if (!
double.IsNaN(top)) top = Math.Min(Math.Max(0, top), canvas.Height);
213 if (!
double.IsNaN(height)) height = Math.Min(Math.Max(0, height), canvas.Height);
217 if (!
double.IsNaN(left) && !
double.IsNaN(right) && right < left) left = right = ((left + right) / 2);
218 if (!
double.IsNaN(top) && !double.IsNaN(bottom) && bottom < top) bottom = top = ((bottom + top) / 2);
222 if (!
double.IsNaN(left) && !double.IsNaN(right) &&
double.IsNaN(width)) width = Math.Max(right - left,0);
223 if (!
double.IsNaN(top) && !
double.IsNaN(bottom) &&
double.IsNaN(height)) height = Math.Max(bottom - top,0);
227 SizeF normalSize = actualSizeCalculator((
double.IsNaN(width) &&
Fill) ? cont.Width : width, (
double.IsNaN(height) &&
Fill) ? cont.Height : height);
228 if (
double.IsNaN(width) || width > normalSize.Width) width = normalSize.Width;
229 if (
double.IsNaN(height) || height > normalSize.Height) height = normalSize.Height;
234 if (
double.IsNaN(left) &&
double.IsNaN(right)) { left = cont.X; right = cont.Right; }
235 if (
double.IsNaN(top) &&
double.IsNaN(bottom)) { top = cont.X; bottom = cont.Bottom; }
239 if (!
double.IsNaN(left) && !
double.IsNaN(right) && !
double.IsNaN(width)) {
240 if (width > right - left) width = right - left;
242 if (
Align == ContentAlignment.BottomLeft ||
Align == ContentAlignment.MiddleLeft ||
Align == ContentAlignment.TopLeft)
243 right = left + width;
244 if (
Align == ContentAlignment.BottomCenter ||
Align == ContentAlignment.MiddleCenter ||
Align == ContentAlignment.TopCenter){
245 left += (right-left-width) /2;
246 right = left + width;
248 if (
Align == ContentAlignment.BottomRight ||
Align == ContentAlignment.MiddleRight ||
Align == ContentAlignment.TopRight)
249 left = right - width;
254 if (!
double.IsNaN(top) && !double.IsNaN(bottom) && !
double.IsNaN(height)) {
255 if (height > bottom - top) height = bottom - top;
257 if (
Align == ContentAlignment.TopLeft ||
Align == ContentAlignment.TopCenter ||
Align == ContentAlignment.TopRight)
258 bottom = top + height;
259 if (
Align == ContentAlignment.MiddleLeft ||
Align == ContentAlignment.MiddleCenter ||
Align == ContentAlignment.MiddleRight) {
260 top += (bottom - top - height) / 2;
261 bottom = top + height;
263 if (
Align == ContentAlignment.BottomLeft ||
Align == ContentAlignment.BottomCenter ||
Align == ContentAlignment.BottomRight)
264 top = bottom - height;
270 if (
double.IsNaN(left)) left = right - width;
271 if (
double.IsNaN(top)) top = bottom - height;
274 if (
double.IsNaN(right)) right = left + width;
275 if (
double.IsNaN(bottom)) bottom = top + height;
278 return new RectangleF((
float)left, (
float)top, (
float)width, (
float)height);
bool Fill
(defaults false). When true, the image or text will attempt to fill 1 of the layer's bounds...
DistanceUnit Left
The offset from the left of the container. Percentages are relative to the container width...
DistanceUnit Height
The height of the layer. If used with both Top and Bottom, the smaller result wins. I.e, with a 100px container, height=50, top=30, top=30, the resulting height will be 40. If null, Top and Bottom will be used to calcuate the value. If both Top and Bottom are not specified, the natural height of the layer's contents will be used. Percentages are relative to the container height.
ContentAlignment Align
The alignment to use when (a) all 3 horizontal or vertical values are specified, and they need to be ...
Size destSize
The size of the target bitmap image. Set after all sizing operations have completed.
Defines a collection of utility functions for manipulating polygons. These functions may be (re)moved...
static RectangleF GetBoundingBox(PointF[] points)
Returns a bounding box for the specified set of points.
DistanceUnit Bottom
The offset relative to the bottom of the container. Percentages are relative to the container height...
LayoutBuilder layout
The layout object. Used for calculated and flowing the layout of the various rings around the image (...
string RelativeTo
Specifies the container that the position values (top,left,right,bottom,width,heght) are relative to...
DistanceUnit Width
The width of the layer. If used with both Left and Right, the smaller result wins. I.e, with a 100px container, width=50, left=30, right=30, the resulting width will be 40. If null, Left and Right will be used to calcuate the value. If both Left and Right are not specified, the natural width of the layer's contents will be used. Percentages are relative to the container width.
DistanceUnit Top
The offset from the top of the container. Percentages are relative to the container height...
DistanceUnit Right
The offset relative to the right side of the container. Percentages are relative to the container wid...