示例#1
0
 public RectangleD(PointD location, SizeD size)
 {
     x      = location.X;
     y      = location.Y;
     width  = size.Width;
     height = size.Height;
 }
        public virtual SizeD GetSize(PointD start)
        {
            SizeD contentsSize = AllocateSize(start);

            contentsSize.Width  = Math.Max(contentsSize.Width, calculatedSize.WidthValue);
            contentsSize.Height = Math.Max(contentsSize.Height, calculatedSize.HeightValue);

            return(contentsSize);
        }
        protected virtual SizeD GetContentsSize(PointD start)
        {
            PointD startOffset = GetContentStart();
            PointD endOffset   = GetContentEnd();

            SizeD contentsSize = AllocateSize(start);

            contentsSize.Width  -= startOffset.X + endOffset.X;
            contentsSize.Height -= startOffset.Y + endOffset.Y;

            return(contentsSize);
        }
        protected PointD GetContentStart(PointD start, SizeD visibleSize, SizeD contentsSize)
        {
            PointD startOffset = GetContentStart();
            PointD endOffset   = GetContentEnd();

            Cairo.Rectangle contentArea = new Cairo.Rectangle
                                          (
                start.X + startOffset.X,
                start.Y + startOffset.Y,
                visibleSize.Width - startOffset.X - endOffset.X,
                visibleSize.Height - startOffset.Y - endOffset.Y
                                          );

            HorizontalAlignment hAlign = distribution.GetColumnsUsed() > 1 ?
                                         HorizontalAlignment.Left : style.HAlign;
            VerticalAlignment vAlign = distribution.GetRowsUsed() > 1 ?
                                       VerticalAlignment.Top : style.VAlign;

            PointD ret = new PointD(0f, 0f);

            switch (hAlign)
            {
            case HorizontalAlignment.Right:
                ret.X = contentArea.X + (contentArea.Width - contentsSize.Width);
                break;

            case HorizontalAlignment.Center:
                ret.X = contentArea.X + (contentArea.Width - contentsSize.Width) / 2;
                break;

            default:
                ret.X = contentArea.X;
                break;
            }

            switch (vAlign)
            {
            case VerticalAlignment.Bottom:
                ret.Y = contentArea.Y + (contentArea.Height - contentsSize.Height);
                break;

            case VerticalAlignment.Center:
                ret.Y = contentArea.Y + (contentArea.Height - contentsSize.Height) / 2;
                break;

            default:
                ret.Y = contentArea.Y;
                break;
            }

            return(ret);
        }
示例#5
0
        protected override bool ResolveDistribution(PointD start, SizeD size)
        {
            bool ret = base.ResolveDistribution(start, size);

            if (ret)
            {
                QueueRedistributeDown();
                AllocateContentsSize(start);
                isDistributed = true;
            }

            return(ret);
        }
示例#6
0
        public override SizeD AllocateSize(PointD start)
        {
            bool  reallocating = !IsAllocated;
            SizeD size         = base.AllocateSize(start);

            if (reallocating && (Text == SEPARATOR || trimming != StringTrimming.None || wrap) &&
                allocatedSize.RelativeWidth == null)
            {
                allocatedSize.RelativeWidth = 100;
            }

            ResolveDistribution(start, allocatedSize.StaticSize);

            return(size);
        }
示例#7
0
        public override void Draw(PointD start, int pageNumber)
        {
            AllocateSize(start);

            base.Draw(start, pageNumber);

            start   = DocumentHelper.CurrentPageSettings.GetInPageDrawLocation(start);
            visSize = GetSize(start);
            SizeD  contSize  = GetContentsSize(start);
            PointD contStart = GetContentStart(start, visSize, contSize);

            DocumentHelper.DrawingProvider.DrawLine(
                contStart.X, contStart.Y,
                contStart.X + (horizontal ? LengthValue : 0f),
                contStart.Y + (horizontal ? 0f : LengthValue),
                Thickness, style.FgColor);
        }
示例#8
0
        protected override SizeD AllocateContentsSize(PointD start)
        {
            SizeD size = (Text == SEPARATOR) ?
                         new SizeD(10, 5) :
                         MeasureString(null);

            size.Width  = (float)Math.Ceiling(size.Width);
            size.Height = (float)Math.Ceiling(size.Height);

            if (trimming != StringTrimming.None || wrap)
            {
                return(new SizeD(10, size.Height));
            }

            return(calculatedSize.WidthValue > 0 ?
                   new SizeD(Math.Min(calculatedSize.WidthValue, size.Width), size.Height) :
                   size);
        }
示例#9
0
        private void GetImage(out bool formatError, out SizeD size, float requestedHeight)
        {
            formatError = false;
            settings.RequestedTotalHeight = requestedHeight;
            BarCodeGenerator barCodeGenerator = new BarCodeGenerator(settings);
            string           data             = settings.Data;

            if (barCodeGenerator.AssembleBarCode().Validate(ref data) == BarCodeFormatValidationResult.Success)
            {
                image = barCodeGenerator.GenerateImage(ComponentHelper.TopWindow.CreatePangoLayout(""));
                size  = new SizeD(image.Width, image.Height);
            }
            else
            {
                formatError = true;
                size        = SetSizeOnError();
            }
        }
示例#10
0
        public override bool OnSizeCalculated(PointD childPosition)
        {
            if (!wrap && trimming == StringTrimming.None)
            {
                if (Text == SEPARATOR)
                {
                    allocatedSize.Width  = calculatedSize.Width;
                    allocatedSize.Height = calculatedSize.Height;
                }
                return(true);
            }

            PointD contentStart = GetContentStart(GetContentEnd());
            SizeD  size         = MeasureString(wrap ? calculatedSize.Width - contentStart.X : null);

            size.Width  = (float)Math.Ceiling(size.Width) + contentStart.X;
            size.Height = (float)Math.Ceiling(size.Height) + contentStart.Y;
            if (!wrap)
            {
                allocatedSize.Width  = size.Width > calculatedSize.WidthValue ? calculatedSize.Width : size.Width;
                allocatedSize.Height = size.Height > calculatedSize.HeightValue ? calculatedSize.Height : size.Height;
                return(true);
            }

            // if the new calculated width is more than the last one recalculate to save height
            // if the new measured height is more than the calculated reallocate to gain height
            if (size.Width <= allocatedSize.Width &&
                size.Height <= calculatedSize.Height)
            {
                return(true);
            }

            allocatedSize.Width  = size.Width;
            allocatedSize.Height = size.Height;
            disableReallocate    = true;
            QueueAllocateUp(false);
            return(false);
        }
示例#11
0
        public override void Draw(PointD start, int pageNumber)
        {
            base.Draw(start, pageNumber);

            start   = DocumentHelper.CurrentPageSettings.GetInPageDrawLocation(start);
            visSize = GetSize(start);
            SizeD contSize = GetContentsSize(start);

            if (contSize.Width > visSize.Width)
            {
                contSize.Width = visSize.Width;
            }

            PointD contStart = GetContentStart(start, visSize, contSize);

            if (style.BgColorSpecified)
            {
                DocumentHelper.DrawingProvider.FillRectangle(
                    start.X, start.Y,
                    visSize.Width, visSize.Height, style.BgColor);
            }

            if (style.Border > 0f)
            {
                DocumentHelper.DrawingProvider.DrawInsetRectangle(
                    start.X, start.Y,
                    visSize.Width, visSize.Height, style.Border.Value, style.BorderColor);
            }

            if (Text == SEPARATOR)
            {
                DocumentHelper.DrawingProvider.DrawLine(contStart.X, contStart.Y, contStart.X + visSize.Width, contStart.Y, 1, style.FgColor);
            }
            else
            {
                DocumentHelper.DrawingProvider.DrawString(new RectangleD(contStart, contSize), Text, style.FgColor, font, trimming, style.HAlign, wrap);
            }
        }
示例#12
0
        private SizeD GetChildrenSize(PointD start, Func <FormDrawableObject, PointD, SizeD> function)
        {
            int   i;
            int   pageInd;
            int   lastPageInd;
            float offset;
            SizeD contentsSize = new SizeD(0f, 0f);
            SizeD childSize;

            start.X += allocatedHPageFill;
            start.Y += allocatedVPageFill;
            start    = GetContentStart(start);
            switch (ChildDistribution)
            {
            case ObjectStyle.ChildDistribution.Horizontal:
                offset      = GetInnerChildOffset();
                i           = 0;
                lastPageInd = 0;

                foreach (FormDrawableObject drawable in Children)
                {
                    PointD childStart = new PointD(start.X + contentsSize.Width, start.Y);
                    childSize = function(drawable, childStart);

                    contentsSize.Width += drawable.Style.XStart;
                    contentsSize.Width += drawable.AllocatedHPageFill;
                    contentsSize.Width += childSize.Width;
                    contentsSize.Height = Math.Max(contentsSize.Height, childSize.Height);

                    pageInd = drawable.Distribution.RightColumn;
                    if (lastPageInd != pageInd && drawable.Distribution.GetColumnsUsed() == 1 && i > 0)
                    {
                        contentsSize.Width += offset;
                    }

                    if (i < Children.Count - 1)
                    {
                        contentsSize.Width += offset;
                    }

                    lastPageInd = pageInd;
                    i++;
                }
                break;

            case ObjectStyle.ChildDistribution.Vertical:
                offset      = GetInnerChildOffset();
                i           = 0;
                lastPageInd = 0;

                foreach (FormDrawableObject drawable in Children)
                {
                    PointD childStart = new PointD(start.X, start.Y + contentsSize.Height);
                    childSize = function(drawable, childStart);

                    contentsSize.Width   = Math.Max(contentsSize.Width, childSize.Width);
                    contentsSize.Height += drawable.Style.YStart;
                    contentsSize.Height += drawable.AllocatedVPageFill;
                    contentsSize.Height += childSize.Height;

                    pageInd = drawable.Distribution.LowerRow;
                    if (lastPageInd != pageInd && drawable.Distribution.GetRowsUsed() == 1 && i > 0)
                    {
                        contentsSize.Height += offset;
                    }

                    if (i < Children.Count - 1)
                    {
                        contentsSize.Height += offset;
                    }

                    lastPageInd = pageInd;
                    i++;
                }
                break;

            case ObjectStyle.ChildDistribution.Mixed:
                foreach (FormDrawableObject drawable in Children)
                {
                    childSize = function(drawable, start);

                    contentsSize.Width  = Math.Max(contentsSize.Width, drawable.Style.XStart + childSize.Width + drawable.AllocatedHPageFill);
                    contentsSize.Height = Math.Max(contentsSize.Height, drawable.Style.YStart + childSize.Height + drawable.AllocatedVPageFill);
                }
                break;
            }

            return(contentsSize);
        }
        protected virtual bool ResolveDistribution(PointD start, SizeD size)
        {
            PageSettings pSettings = DocumentHelper.CurrentPageSettings;

            if (isDistributed || pSettings.Width.IsZero())
            {
                return(false);
            }

            SizeD startOffset = new SizeD();
            SizeD endOffset   = new SizeD();

            if (Parent != null)
            {
                FormDrawableContainer container = Parent as FormDrawableContainer;
                if (container == null)
                {
                    throw new Exception("The parent control is not a container.");
                }

                PointD contentStart = container.GetContentStart();
                startOffset.Width  = contentStart.X;
                startOffset.Height = contentStart.Y;

                // If this is not the last child in the parent object
                // add the inner offset else add the ending offset
                if (ParentPosition < container.Children.Count - 1)
                {
                    switch (container.ChildDistribution)
                    {
                    case ObjectStyle.ChildDistribution.Horizontal:
                        endOffset.Width = Math.Max(container.Style.InnerVerticalBorder ?? 0, container.Style.InnerHSpacing ?? 0);
                        break;

                    case ObjectStyle.ChildDistribution.Vertical:
                        endOffset.Height = Math.Max(container.Style.InnerHorizontalBorder ?? 0,
                                                    container.Style.InnerVSpacing ?? 0);
                        break;
                    }
                }
                else
                {
                    PointD contentEnd = container.GetContentEnd();
                    endOffset.Width  = contentEnd.X;
                    endOffset.Height = contentEnd.Y;
                }
            }

            bool ret = false;

            allocatedHPageFill       = 0f;
            distribution.LeftColumn  = Math.Max((int)start.X + 1, 0) / (int)pSettings.Width;
            distribution.RightColumn = Math.Max((int)(start.X + size.Width + endOffset.Width - 1), 0) / (int)pSettings.Width;
            if (distribution.LeftColumn != distribution.RightColumn && AllowHorizontalBreak && !style.AllowHBreak)
            {
                distribution.LeftColumn++;
                allocatedHPageFill = pSettings.Width - start.X % pSettings.Width;
                ret = true;
            }
            if (distribution.LeftColumn > distribution.RightColumn)
            {
                distribution.LeftColumn = distribution.RightColumn;
            }

            allocatedVPageFill    = 0f;
            distribution.UpperRow = Math.Max((int)start.Y + 1, 0) / (int)pSettings.Height;
            distribution.LowerRow = Math.Max((int)(start.Y + size.Height + endOffset.Height - 1), 0) / (int)pSettings.Height;
            if (distribution.UpperRow != distribution.LowerRow && AllowVerticalBreak && !style.AllowVBreak)
            {
                distribution.UpperRow++;
                allocatedVPageFill = pSettings.Height - start.Y % pSettings.Height;
                ret = true;
            }
            if (distribution.UpperRow > distribution.LowerRow)
            {
                distribution.UpperRow = distribution.LowerRow;
            }

            isDistributed = true;
            return(ret);
        }
        public virtual SizeD AllocateSize(PointD start)
        {
            if (!IsAllocated)
            {
                PointD startOffset  = GetContentStart(GetContentEnd());
                SizeD  contentsSize = new SizeD(-1f, -1f);

                int i;
                for (i = 0; i < 2; i++)
                {
                    if (i > 0)
                    {
                        bool savedReAllocating = reAllocating;
                        reAllocating = true;
                        contentsSize = AllocateContentsSize(start);
                        reAllocating = savedReAllocating;
                    }
                    else
                    {
                        contentsSize = AllocateContentsSize(start);
                    }

                    if (style.HFill == true || style.VFill == true)
                    {
                        if (style.HFill == false)
                        {
                            contentsSize.Width = 0f;
                        }

                        if (style.VFill == false)
                        {
                            contentsSize.Height = 0f;
                        }
                    }
                    else
                    {
                        contentsSize.Width  = 0f;
                        contentsSize.Height = 0f;
                    }

                    contentsSize.Width  += startOffset.X;
                    contentsSize.Height += startOffset.Y;

                    contentsSize.Width  = Math.Max(contentsSize.Width, minimalSize.WidthValue);
                    contentsSize.Height = Math.Max(contentsSize.Height, minimalSize.HeightValue);

                    if (i > 0)
                    {
                        break;
                    }

                    ResolveDistribution(start, contentsSize);

                    // If this object is moved to another page reallocate the children
                    if (allocatedHPageFill <= 0f && allocatedVPageFill <= 0f)
                    {
                        break;
                    }

                    start.X    += allocatedHPageFill;
                    start.Y    += allocatedVPageFill;
                    IsAllocated = true;
                    QueueAllocateDown();
                }

                allocatedSize.Width          = contentsSize.Width;
                allocatedSize.Height         = contentsSize.Height;
                allocatedSize.RelativeWidth  = minimalSize.RelativeWidth;
                allocatedSize.RelativeHeight = minimalSize.RelativeHeight;
            }
            else
            {
                ResolveDistribution(start, allocatedSize.StaticSize);
            }

            return(allocatedSize.StaticSize);
        }
示例#15
0
 public static SizeD Add(SizeD sz1, SizeD sz2)
 {
     return(new SizeD(sz1.Width + sz2.Width, sz1.Height + sz2.Height));
 }
示例#16
0
 public static SizeD Subtract(SizeD sz1, SizeD sz2)
 {
     return(new SizeD(sz1.Width - sz2.Width, sz1.Height - sz2.Height));
 }
示例#17
0
        public override void Draw(PointD start, int pageNumber)
        {
            base.Draw(start, pageNumber);

            start   = DocumentHelper.CurrentPageSettings.GetInPageDrawLocation(start);
            visSize = GetSize(start);

            PointD           contStart = GetContentStart(start);
            IDrawingProvider provider  = DocumentHelper.DrawingProvider;

            if (style.BgColorSpecified)
            {
                provider.FillRectangle(
                    start.X, start.Y,
                    visSize.Width, visSize.Height, style.BgColor);
            }

            SizeD scaledVisSize = new SizeD(
                visSize.Width * provider.DrawingScaleX,
                visSize.Height * provider.DrawingScaleY);

            bool  formatError;
            SizeD size;

            GetImage(out formatError, out size, (float)scaledVisSize.Height);

            if (formatError)
            {
                DrawError(contStart);
            }
            else
            {
                double targetWidth;
                if (image.Width > scaledVisSize.Width)
                {
                    targetWidth = scaledVisSize.Width;
                }
                else
                {
                    int expand = (int)(scaledVisSize.Width / image.Width);
                    if (expand > 1)
                    {
                        GetImage(out formatError, out size, (float)scaledVisSize.Height / expand);
                    }

                    // scale with whole factor lower the blurring
                    targetWidth = image.Width * expand;
                    // center the barcode in the new spot
                    contStart.X += (int)((scaledVisSize.Width - targetWidth) / (2 * provider.DrawingScaleX));
                }

                RectangleD target = new RectangleD(contStart, new SizeD(targetWidth / provider.DrawingScaleX, visSize.Height));
                RectangleD source = new RectangleD(0, 0, image.Width, image.Height);
                provider.DrawSurface(image.Surface, target, source, InterpType.Nearest);
            }

            if (style.Border > 0f)
            {
                provider.DrawInsetRectangle(
                    start.X, start.Y,
                    visSize.Width, visSize.Height, style.Border.Value, style.BorderColor);
            }
        }
示例#18
0
 protected virtual SizeD SetSizeOnError()
 {
     return(visSize = new SizeD(50, 50));
 }
示例#19
0
 public void Inflate(SizeD size)
 {
     Inflate(size.Width, size.Height);
 }
示例#20
0
 public bool Equals(SizeD other)
 {
     return(width.Equals(other.width) && height.Equals(other.height));
 }
示例#21
0
        public override void Draw(PointD start, int pageNumber)
        {
            CalculateChildSizes(start);

            visSize = GetSize(start);
            SizeD  contSize    = GetContentsSize(start);
            PointD contStart   = GetContentStart(start, visSize, contSize);
            PointD contOffset  = new PointD(contStart.X - start.X, contStart.Y - start.Y);
            float  innerOffset = GetInnerChildOffset();

            PointD drawStart = DocumentHelper.CurrentPageSettings.GetInPageDrawLocation(start);

            base.Draw(start, pageNumber);

            if (style.BgColorSpecified)
            {
                DocumentHelper.DrawingProvider.FillRectangle(
                    drawStart.X, drawStart.Y,
                    visSize.Width, visSize.Height, style.BgColor);
            }

            if (style.Border > 0f)
            {
                DocumentHelper.DrawingProvider.DrawInsetRectangle(
                    drawStart.X, drawStart.Y,
                    visSize.Width, visSize.Height, style.Border.Value, style.BorderColor);
            }

            bool clip = style.HFill == false || style.VFill == false;

            if (clip)
            {
                DocumentHelper.DrawingProvider.SaveClip();
                DocumentHelper.DrawingProvider.IntersectClip(new RectangleD(drawStart, visSize));
            }

            int i           = 0;
            int lastPageInd = 0;

            foreach (FormDrawableObject drawable in Children)
            {
                bool  drawThisObject = drawable.Distribution.IsInPage();
                SizeD childSize      = drawable.GetSize(contStart);

                int pageInd;
                switch (ChildDistribution)
                {
                case ObjectStyle.ChildDistribution.Horizontal:
                    pageInd = drawable.Distribution.RightColumn;
                    if (lastPageInd != pageInd && drawable.Distribution.GetColumnsUsed() == 1 && i > 0)
                    {
                        contStart.X += innerOffset;
                    }

                    contStart.X += drawable.CalculatedHPageFill;

                    if (drawThisObject)
                    {
                        drawable.Draw(contStart, pageNumber);
                    }

                    contStart.X += childSize.Width;

                    if (drawThisObject && style.InnerVerticalBorder > 0f)
                    {
                        drawStart = DocumentHelper.CurrentPageSettings.GetInPageDrawLocation(contStart);
                        // Draw a vertical border before this child
                        if (lastPageInd != pageInd && drawable.Distribution.GetColumnsUsed() == 1 && i > 0)
                        {
                            float xPos = (float)Math.Floor(drawStart.X + contOffset.X - childSize.Width - (innerOffset / 2));
                            DocumentHelper.DrawingProvider.DrawLine(xPos, drawStart.Y,
                                                                    xPos, drawStart.Y + visSize.Height,
                                                                    style.InnerVerticalBorder.Value, style.BorderColor);
                        }

                        // Draw a vertical border after this child
                        if (i < Children.Count - 1)
                        {
                            float xPos = (float)Math.Floor(drawStart.X + contOffset.X + (innerOffset / 2));
                            DocumentHelper.DrawingProvider.DrawLine(xPos, drawStart.Y,
                                                                    xPos, drawStart.Y + visSize.Height,
                                                                    style.InnerVerticalBorder.Value, style.BorderColor);
                        }
                    }

                    contStart.X += innerOffset;
                    lastPageInd  = pageInd;
                    break;

                case ObjectStyle.ChildDistribution.Vertical:
                    pageInd = drawable.Distribution.LowerRow;
                    if (lastPageInd != pageInd && drawable.Distribution.GetRowsUsed() == 1 && i > 0)
                    {
                        contStart.Y += innerOffset;
                    }

                    contStart.Y += drawable.CalculatedVPageFill;

                    if (drawThisObject)
                    {
                        drawable.Draw(contStart, pageNumber);
                    }

                    contStart.Y += childSize.Height;

                    if (drawThisObject && style.InnerHorizontalBorder > 0f)
                    {
                        drawStart = DocumentHelper.CurrentPageSettings.GetInPageDrawLocation(contStart);
                        // Draw a horizontal border before this child
                        if (lastPageInd != pageInd && drawable.Distribution.GetRowsUsed() == 1 && i > 0)
                        {
                            float yPos = (float)Math.Floor(drawStart.Y + contOffset.Y - childSize.Height - (innerOffset / 2));
                            DocumentHelper.DrawingProvider.DrawLine(drawStart.X, yPos,
                                                                    drawStart.X + visSize.Width, yPos,
                                                                    style.InnerHorizontalBorder.Value, style.BorderColor);
                        }

                        // Draw a horizontal border after this child
                        if (i < Children.Count - 1)
                        {
                            float yPos = (float)Math.Floor(drawStart.Y + contOffset.Y + (innerOffset / 2));
                            DocumentHelper.DrawingProvider.DrawLine(drawStart.X, yPos,
                                                                    drawStart.X + visSize.Width, yPos,
                                                                    style.InnerHorizontalBorder.Value, style.BorderColor);
                        }
                    }

                    contStart.Y += innerOffset;
                    lastPageInd  = pageInd;
                    break;

                default:
                    if (drawThisObject)
                    {
                        drawable.Draw(contStart, pageNumber);
                    }

                    break;
                }

                i++;
            }

            if (clip)
            {
                DocumentHelper.DrawingProvider.RestoreClip();
            }
        }
示例#22
0
        public override void Draw(PointD start, int pageNumber)
        {
            base.Draw(start, pageNumber);

            start   = DocumentHelper.CurrentPageSettings.GetInPageDrawLocation(start);
            visSize = GetSize(start);
            SizeD contSize = GetContentsSize(start);

            if (contSize.Width > visSize.Width)
            {
                contSize.Width = visSize.Width;
            }

            PointD contStart = GetContentStart(start, visSize, contSize);

            if (style.BgColorSpecified)
            {
                DocumentHelper.DrawingProvider.FillRectangle(
                    start.X, start.Y,
                    visSize.Width, visSize.Height, style.BgColor);
            }

            if (image != null && image.Width > 0 && image.Height > 0)
            {
                RectangleD targetArea = new RectangleD(contStart, visSize);
                RectangleD sourceArea = new RectangleD(new PointD(), new SizeD(image.Width, image.Height));

                SizeD  size;
                double width;
                switch (sizeMode)
                {
                case SizeMode.Stretch:
                    DocumentHelper.DrawingProvider.DrawImage(image, targetArea, sourceArea, sizeMode);
                    break;

                case SizeMode.Fit:
                    size  = targetArea.Size;
                    width = size.Height * image.Width / image.Height;
                    if (width > size.Width)
                    {
                        size.Height = size.Width * image.Height / image.Width;
                    }
                    else
                    {
                        size.Width = width;
                    }

                    PointD imageStart = contStart;
                    if (targetArea.Width > size.Width)
                    {
                        imageStart.X += (targetArea.Width - size.Width) / 2;
                    }

                    if (targetArea.Height > size.Height)
                    {
                        imageStart.Y += (targetArea.Height - size.Height) / 2;
                    }

                    DocumentHelper.DrawingProvider.DrawImage(image, new RectangleD(imageStart, size), sourceArea, sizeMode);
                    break;

                case SizeMode.Fill:
                    size  = targetArea.Size;
                    width = size.Height * image.Width / image.Height;
                    if (width > size.Width)
                    {
                        double scale = size.Height / image.Height;
                        sourceArea.X      = (width - size.Width) / (2 * scale);
                        sourceArea.Width -= sourceArea.X * 2;
                    }
                    else
                    {
                        double height = size.Width * image.Height / image.Width;
                        double scale  = size.Width / image.Width;
                        sourceArea.Y       = (height - size.Height) / (2 * scale);
                        sourceArea.Height -= sourceArea.Y * 2;
                    }

                    DocumentHelper.DrawingProvider.DrawImage(image, targetArea, sourceArea, sizeMode);
                    break;

                case SizeMode.Crop:
                    if (targetArea.Width > image.Width)
                    {
                        targetArea.X    += (targetArea.Width - image.Width) / 2;
                        targetArea.Width = image.Width;
                    }
                    else
                    {
                        sourceArea.X     = (image.Width - targetArea.Width) / 2;
                        sourceArea.Width = targetArea.Width;
                    }

                    if (targetArea.Height > image.Height)
                    {
                        targetArea.Y     += (targetArea.Height - image.Height) / 2;
                        targetArea.Height = image.Height;
                    }
                    else
                    {
                        sourceArea.Y      = (image.Height - targetArea.Height) / 2;
                        sourceArea.Height = targetArea.Height;
                    }

                    DocumentHelper.DrawingProvider.DrawImage(image, targetArea, sourceArea, sizeMode);
                    break;
                }
            }

            if (style.Border > 0f)
            {
                DocumentHelper.DrawingProvider.DrawInsetRectangle(
                    start.X, start.Y,
                    visSize.Width, visSize.Height, style.Border.Value, style.BorderColor);
            }
        }
示例#23
0
 public SizeD(SizeD size)
 {
     width  = size.width;
     height = size.height;
 }